Skip to content

Commit

Permalink
table max parallelism
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao committed Sep 26, 2024
1 parent c13e90f commit 85ca081
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions proto/meta.proto
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ message ListTableFragmentStatesResponse {
uint32 table_id = 1;
TableFragments.State state = 2;
TableParallelism parallelism = 3;
uint32 max_vnode_count = 4;
}
repeated TableFragmentState states = 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ use risingwave_frontend_macro::system_catalog;
job.id,
job.name,
job.relation_type,
tf.parallelism
tf.parallelism,
tf.max_parallelism
FROM all_streaming_jobs job
INNER JOIN rw_table_fragments tf ON job.id = tf.table_id
ORDER BY job.id"
Expand All @@ -42,4 +43,5 @@ struct RwStreamingParallelism {
name: String,
relation_type: String,
parallelism: String,
max_parallelism: i32,
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct RwTableFragment {
table_id: i32,
status: String,
parallelism: String,
max_parallelism: i32,
}

#[system_catalog(table, "rw_catalog.rw_table_fragments")]
Expand All @@ -40,6 +41,7 @@ async fn read_rw_table_fragments_info(
table_id: state.table_id as i32,
status: state.state().as_str_name().into(),
parallelism: parallelism.to_uppercase(),
max_parallelism: state.max_vnode_count as i32,
}
})
.collect())
Expand Down
2 changes: 2 additions & 0 deletions src/meta/service/src/stream_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ impl StreamManagerService for StreamServiceImpl {
table_id: tf.table_id().table_id,
state: tf.state() as i32,
parallelism: Some(tf.assigned_parallelism.into()),
max_vnode_count: tf.max_vnode_count() as _,
},
)
.collect_vec()
Expand All @@ -292,6 +293,7 @@ impl StreamManagerService for StreamServiceImpl {
table_id: table_id as _,
state: PbState::from(state) as _,
parallelism: Some(parallelism.into()),
max_vnode_count: 0, // TODO(var-vnode): write query to obtain this from `fragment`
}
})
.collect_vec()
Expand Down
14 changes: 13 additions & 1 deletion src/meta/src/model/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::ops::AddAssign;

use itertools::Itertools;
use risingwave_common::catalog::TableId;
use risingwave_common::hash::{VirtualNode, WorkerSlotId};
use risingwave_common::hash::{VirtualNode, VnodeCountCompat, WorkerSlotId};
use risingwave_connector::source::SplitImpl;
use risingwave_pb::common::PbActorLocation;
use risingwave_pb::meta::table_fragments::actor_status::ActorState;
Expand Down Expand Up @@ -282,6 +282,18 @@ impl TableFragments {
self.ctx.timezone.clone()
}

/// Returns the max vnode count of all fragments in the table.
///
/// Setting the parallelism of a streaming job to a value greater than this will result in
/// an error, as there won't be any fragment that fits that value.
pub fn max_vnode_count(&self) -> usize {
self.fragments
.values()
.map(|f| f.vnode_count())
.max()
.expect("should be at least one fragment")
}

/// Returns whether the table fragments is in `Created` state.
pub fn is_created(&self) -> bool {
self.state == State::Created
Expand Down

0 comments on commit 85ca081

Please sign in to comment.