risingwave_meta_model/
streaming_job.rs

1// Copyright 2024 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::collections::HashMap;
16
17use risingwave_common::id::JobId;
18use risingwave_pb::id::FragmentId;
19use sea_orm::FromJsonQueryResult;
20use sea_orm::entity::prelude::*;
21use serde::{Deserialize, Serialize};
22
23use crate::{CreateType, JobStatus, StreamingParallelism, derive_from_json_struct};
24
25#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
26#[sea_orm(table_name = "streaming_job")]
27pub struct Model {
28    #[sea_orm(primary_key, auto_increment = false)]
29    pub job_id: JobId,
30    pub job_status: JobStatus,
31    pub create_type: CreateType,
32    pub timezone: Option<String>,
33    // Here `NULL` is equivalent to an empty config override string.
34    pub config_override: Option<String>,
35    pub parallelism: StreamingParallelism,
36    pub backfill_parallelism: Option<StreamingParallelism>,
37    #[sea_orm(column_type = "JsonBinary", nullable)]
38    pub backfill_orders: Option<BackfillOrders>,
39    pub max_parallelism: i32,
40    pub specific_resource_group: Option<String>,
41    pub is_serverless_backfill: bool,
42}
43
44// This data structure contains an adjacency list of backfill nodes.
45// Each edge represents a backfill order.
46// For instance, given:
47// `BackfillOrders[1] = [2, 3, 4]`
48// It means that node 1 must be backfilled before nodes 2, 3, and 4.
49// Concretely, these node ids are the fragment ids.
50// This is because each fragment will only have 1 stream scan,
51// and stream scan corresponds to a backfill node.
52derive_from_json_struct!(BackfillOrders, HashMap<FragmentId, Vec<FragmentId>>);
53
54#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
55pub enum Relation {
56    #[sea_orm(
57        belongs_to = "super::object::Entity",
58        from = "Column::JobId",
59        to = "super::object::Column::Oid",
60        on_update = "NoAction",
61        on_delete = "Cascade"
62    )]
63    Object,
64}
65
66impl Related<super::object::Entity> for Entity {
67    fn to() -> RelationDef {
68        Relation::Object.def()
69    }
70}
71
72impl ActiveModelBehavior for ActiveModel {}