-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cherry-pick(2.0): feat: introduce cluster limit (#18383)
- Loading branch information
Showing
21 changed files
with
439 additions
and
12 deletions.
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.