risingwave_meta_model/
streaming_job.rs

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