-
Notifications
You must be signed in to change notification settings - Fork 589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: introduce cluster limit #18383
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
de9f1cc
feat: introduce cluster limit
hzxa21 a060b0d
cleanup
hzxa21 1e65fc8
address CI issues
hzxa21 2c3b93d
polish notice messages
hzxa21 08e84d0
polish limit message
hzxa21 0612955
fix error log
hzxa21 e32944b
remove unused codes
hzxa21 b456b82
fix error log
hzxa21 e2fec45
fix error log
hzxa21 54f80c6
fix error log
hzxa21 52df3b8
fix test_builtin_view_definition
hzxa21 ba37b36
address comment on proto
hzxa21 6dfbf5f
donot differentiate paid and free tier
hzxa21 88ff9ee
fix check
hzxa21 3e7d5c2
fix newline
hzxa21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// Copyright 2024 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::collections::HashMap; | ||
use std::fmt::{self, Display, Formatter}; | ||
|
||
use risingwave_pb::meta::actor_count_per_parallelism::PbWorkerActorCount; | ||
use risingwave_pb::meta::cluster_limit::PbLimit; | ||
use risingwave_pb::meta::{PbActorCountPerParallelism, PbClusterLimit}; | ||
pub enum ClusterLimit { | ||
ActorCount(ActorCountPerParallelism), | ||
} | ||
|
||
impl From<ClusterLimit> for PbClusterLimit { | ||
fn from(limit: ClusterLimit) -> Self { | ||
match limit { | ||
ClusterLimit::ActorCount(actor_count_per_parallelism) => PbClusterLimit { | ||
limit: Some(PbLimit::ActorCount(actor_count_per_parallelism.into())), | ||
}, | ||
} | ||
} | ||
} | ||
|
||
impl From<PbClusterLimit> for ClusterLimit { | ||
fn from(pb_limit: PbClusterLimit) -> Self { | ||
match pb_limit.limit.unwrap() { | ||
PbLimit::ActorCount(actor_count_per_parallelism) => { | ||
ClusterLimit::ActorCount(actor_count_per_parallelism.into()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct WorkerActorCount { | ||
pub actor_count: usize, | ||
pub parallelism: usize, | ||
} | ||
|
||
impl From<WorkerActorCount> for PbWorkerActorCount { | ||
fn from(worker_actor_count: WorkerActorCount) -> Self { | ||
PbWorkerActorCount { | ||
actor_count: worker_actor_count.actor_count as u64, | ||
parallelism: worker_actor_count.parallelism as u64, | ||
} | ||
} | ||
} | ||
|
||
impl From<PbWorkerActorCount> for WorkerActorCount { | ||
fn from(pb_worker_actor_count: PbWorkerActorCount) -> Self { | ||
WorkerActorCount { | ||
actor_count: pb_worker_actor_count.actor_count as usize, | ||
parallelism: pb_worker_actor_count.parallelism as usize, | ||
} | ||
} | ||
} | ||
|
||
pub struct ActorCountPerParallelism { | ||
pub worker_id_to_actor_count: HashMap<u32, WorkerActorCount>, | ||
pub hard_limit: usize, | ||
pub soft_limit: usize, | ||
} | ||
|
||
impl From<ActorCountPerParallelism> for PbActorCountPerParallelism { | ||
fn from(actor_count_per_parallelism: ActorCountPerParallelism) -> Self { | ||
PbActorCountPerParallelism { | ||
worker_id_to_actor_count: actor_count_per_parallelism | ||
.worker_id_to_actor_count | ||
.into_iter() | ||
.map(|(k, v)| (k, v.into())) | ||
.collect(), | ||
hard_limit: actor_count_per_parallelism.hard_limit as u64, | ||
soft_limit: actor_count_per_parallelism.soft_limit as u64, | ||
} | ||
} | ||
} | ||
|
||
impl From<PbActorCountPerParallelism> for ActorCountPerParallelism { | ||
fn from(pb_actor_count_per_parallelism: PbActorCountPerParallelism) -> Self { | ||
ActorCountPerParallelism { | ||
worker_id_to_actor_count: pb_actor_count_per_parallelism | ||
.worker_id_to_actor_count | ||
.into_iter() | ||
.map(|(k, v)| (k, v.into())) | ||
.collect(), | ||
hard_limit: pb_actor_count_per_parallelism.hard_limit as usize, | ||
soft_limit: pb_actor_count_per_parallelism.soft_limit as usize, | ||
} | ||
} | ||
} | ||
|
||
impl ActorCountPerParallelism { | ||
pub fn exceed_hard_limit(&self) -> bool { | ||
self.worker_id_to_actor_count | ||
.values() | ||
.any(|v| v.actor_count > self.hard_limit.saturating_mul(v.parallelism)) | ||
} | ||
|
||
pub fn exceed_soft_limit(&self) -> bool { | ||
self.worker_id_to_actor_count | ||
.values() | ||
.any(|v| v.actor_count > self.soft_limit.saturating_mul(v.parallelism)) | ||
} | ||
|
||
pub fn exceed_limit(&self) -> bool { | ||
self.exceed_soft_limit() || self.exceed_hard_limit() | ||
} | ||
} | ||
|
||
impl Display for ActorCountPerParallelism { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
let worker_id_to_actor_count_str: Vec<_> = self | ||
.worker_id_to_actor_count | ||
.iter() | ||
.map(|(k, v)| format!("{} -> {:?}", k, v)) | ||
.collect(); | ||
write!( | ||
f, | ||
"ActorCountPerParallelism {{ critical limit: {:?}, recommended limit: {:?}. worker_id_to_actor_count: {:?} }}", | ||
self.hard_limit, self.soft_limit, worker_id_to_actor_count_str | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,4 @@ pub mod tracing; | |
pub mod value_encoding; | ||
pub mod worker_util; | ||
pub use tokio_util; | ||
pub mod cluster_limit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,4 @@ mod rw_worker_nodes; | |
|
||
mod rw_actor_id_to_ddl; | ||
mod rw_fragment_id_to_ddl; | ||
mod rw_worker_actor_count; |
31 changes: 31 additions & 0 deletions
31
src/frontend/src/catalog/system_catalog/rw_catalog/rw_worker_actor_count.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2024 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use risingwave_common::types::Fields; | ||
use risingwave_frontend_macro::system_catalog; | ||
|
||
#[system_catalog( | ||
view, | ||
"rw_catalog.rw_worker_actor_count", | ||
"SELECT t2.id as worker_id, parallelism, count(*) as actor_count | ||
FROM rw_actors t1, rw_worker_nodes t2 | ||
where t1.worker_id = t2.id | ||
GROUP BY t2.id, t2.parallelism;" | ||
)] | ||
#[derive(Fields)] | ||
struct RwWorkerActorCount { | ||
worker_id: i32, | ||
parallelism: i32, | ||
actor_count: i64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure they are either-or relation?