risingwave_meta_model/
actor.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 risingwave_pb::meta::table_fragments::actor_status::PbActorState;
16use sea_orm::entity::prelude::*;
17use serde::{Deserialize, Serialize};
18
19use crate::{
20    ActorId, ActorUpstreamActors, ConnectorSplits, ExprContext, FragmentId, VnodeBitmap, WorkerId,
21};
22
23#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
24#[sea_orm(rs_type = "String", db_type = "string(None)")]
25pub enum ActorStatus {
26    #[sea_orm(string_value = "INACTIVE")]
27    Inactive,
28    #[sea_orm(string_value = "RUNNING")]
29    Running,
30}
31
32impl From<PbActorState> for ActorStatus {
33    fn from(val: PbActorState) -> Self {
34        match val {
35            PbActorState::Unspecified => unreachable!(),
36            PbActorState::Inactive => ActorStatus::Inactive,
37            PbActorState::Running => ActorStatus::Running,
38        }
39    }
40}
41
42impl From<ActorStatus> for PbActorState {
43    fn from(val: ActorStatus) -> Self {
44        match val {
45            ActorStatus::Inactive => PbActorState::Inactive,
46            ActorStatus::Running => PbActorState::Running,
47        }
48    }
49}
50
51#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
52#[sea_orm(table_name = "actor")]
53pub struct Model {
54    #[sea_orm(primary_key)]
55    pub actor_id: ActorId,
56    pub fragment_id: FragmentId,
57    pub status: ActorStatus,
58    pub splits: Option<ConnectorSplits>,
59    pub worker_id: WorkerId,
60    #[deprecated]
61    pub upstream_actor_ids: ActorUpstreamActors,
62    pub vnode_bitmap: Option<VnodeBitmap>,
63    pub expr_context: ExprContext,
64}
65
66#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
67pub enum Relation {
68    #[sea_orm(
69        belongs_to = "super::fragment::Entity",
70        from = "Column::FragmentId",
71        to = "super::fragment::Column::FragmentId",
72        on_update = "NoAction",
73        on_delete = "Cascade"
74    )]
75    Fragment,
76}
77
78impl Related<super::fragment::Entity> for Entity {
79    fn to() -> RelationDef {
80        Relation::Fragment.def()
81    }
82}
83
84impl ActiveModelBehavior for ActiveModel {}