Skip to content

Commit

Permalink
filter out singletons in table fragments 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 85ca081 commit 4acc6a8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion proto/meta.proto
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ message ListTableFragmentStatesResponse {
uint32 table_id = 1;
TableFragments.State state = 2;
TableParallelism parallelism = 3;
uint32 max_vnode_count = 4;
uint32 max_parallelism = 4;
}
repeated TableFragmentState states = 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +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,
max_parallelism: state.max_parallelism as i32,
}
})
.collect())
Expand Down
4 changes: 2 additions & 2 deletions src/meta/service/src/stream_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +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 _,
max_parallelism: tf.max_parallelism() as _,
},
)
.collect_vec()
Expand All @@ -293,7 +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`
max_parallelism: 0, // TODO(var-vnode): write query to obtain this from `fragment`
}
})
.collect_vec()
Expand Down
12 changes: 6 additions & 6 deletions src/meta/src/model/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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;
use risingwave_pb::meta::table_fragments::fragment::FragmentDistributionType;
use risingwave_pb::meta::table_fragments::{ActorStatus, Fragment, State};
use risingwave_pb::meta::table_parallelism::{
FixedParallelism, Parallelism, PbAdaptiveParallelism, PbCustomParallelism, PbFixedParallelism,
Expand Down Expand Up @@ -282,16 +283,15 @@ 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 {
/// Returns the maximum value of the `vnode_count` of all hash-distributed fragments.
/// Returns 1 if all fragments are singleton.
pub fn max_parallelism(&self) -> usize {
self.fragments
.values()
.filter(|f| matches!(f.distribution_type(), FragmentDistributionType::Hash))
.map(|f| f.vnode_count())
.max()
.expect("should be at least one fragment")
.unwrap_or(1) // if all fragments are singleton, return 1
}

/// Returns whether the table fragments is in `Created` state.
Expand Down

0 comments on commit 4acc6a8

Please sign in to comment.