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 sea_orm::FromJsonQueryResult;
19use sea_orm::entity::prelude::*;
20use serde::{Deserialize, Serialize};
21
22use crate::{CreateType, JobStatus, StreamingParallelism};
23
24#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
25#[sea_orm(table_name = "streaming_job")]
26pub struct Model {
27    #[sea_orm(primary_key, auto_increment = false)]
28    pub job_id: JobId,
29    pub job_status: JobStatus,
30    pub create_type: CreateType,
31    pub timezone: Option<String>,
32    // Here `NULL` is equivalent to an empty config override string.
33    pub config_override: Option<String>,
34    pub parallelism: StreamingParallelism,
35    pub backfill_parallelism: Option<StreamingParallelism>,
36    pub max_parallelism: i32,
37    pub specific_resource_group: Option<String>,
38}
39
40/// This data structure contains an adjacency list of
41/// backfill nodes.
42/// Each edge represents a backfill order.
43/// For instance, given:
44/// `BackfillOrders[1] = [2, 3, 4]`
45/// It means that node 1 must be backfilled before nodes 2, 3, and 4.
46/// Concretely, these node ids are the fragment ids.
47/// This is because each fragment will only have 1 stream scan,
48/// and stream scan corresponds to a backfill node.
49#[derive(Clone, Debug, PartialEq, Eq, FromJsonQueryResult, Serialize, Deserialize, Default)]
50pub struct BackfillOrders(pub HashMap<u32, Vec<u32>>);
51
52#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
53pub enum Relation {
54    #[sea_orm(
55        belongs_to = "super::object::Entity",
56        from = "Column::JobId",
57        to = "super::object::Column::Oid",
58        on_update = "NoAction",
59        on_delete = "Cascade"
60    )]
61    Object,
62}
63
64impl Related<super::object::Entity> for Entity {
65    fn to() -> RelationDef {
66        Relation::Object.def()
67    }
68}
69
70impl ActiveModelBehavior for ActiveModel {}