Skip to content
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

chore(storage): upgrade write limit #12658

Merged
merged 7 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/meta/src/hummock/manager/compaction_group_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,9 @@ impl HummockManager {
&self,
compaction_group_ids: &[CompactionGroupId],
config_to_update: &[MutableConfig],
) -> Result<()> {
self.compaction_group_manager
) -> Result<Vec<CompactionGroup>> {
let result = self
.compaction_group_manager
.write()
.await
.update_compaction_config(
Expand All @@ -402,7 +403,7 @@ impl HummockManager {
{
self.try_update_write_limits(compaction_group_ids).await;
}
Ok(())
Ok(result)
}

/// Gets complete compaction group info.
Expand Down Expand Up @@ -801,13 +802,14 @@ impl CompactionGroupManager {
self.default_config.clone()
}

async fn update_compaction_config<S: MetaStore>(
pub async fn update_compaction_config<S: MetaStore>(
&mut self,
compaction_group_ids: &[CompactionGroupId],
config_to_update: &[MutableConfig],
meta_store: &S,
) -> Result<()> {
) -> Result<Vec<CompactionGroup>> {
let mut compaction_groups = BTreeMapTransaction::new(&mut self.compaction_groups);
let mut result = Vec::with_capacity(compaction_group_ids.len());
for compaction_group_id in compaction_group_ids.iter().unique() {
let group = compaction_groups.get(compaction_group_id).ok_or_else(|| {
Error::CompactionGroup(format!("invalid group {}", *compaction_group_id))
Expand All @@ -819,14 +821,15 @@ impl CompactionGroupManager {
}
let mut new_group = group.clone();
new_group.compaction_config = Arc::new(config);
compaction_groups.insert(*compaction_group_id, new_group);
compaction_groups.insert(*compaction_group_id, new_group.clone());
result.push(new_group);
}

let mut trx = Transaction::default();
compaction_groups.apply_to_txn(&mut trx)?;
meta_store.txn(trx).await?;
compaction_groups.commit();
Ok(())
Ok(result)
}

/// Initializes the config for a group.
Expand Down
40 changes: 39 additions & 1 deletion src/meta/src/hummock/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use futures::stream::{BoxStream, FuturesUnordered};
use futures::{FutureExt, StreamExt};
use itertools::Itertools;
use parking_lot::Mutex;
use risingwave_common::config::default::compaction_config;
use risingwave_common::monitor::rwlock::MonitoredRwLock;
use risingwave_common::util::epoch::{Epoch, INVALID_EPOCH};
use risingwave_common::util::{pending_on_none, select_all};
Expand All @@ -44,6 +45,7 @@ use risingwave_hummock_sdk::{
};
use risingwave_pb::hummock::compact_task::{self, TaskStatus, TaskType};
use risingwave_pb::hummock::group_delta::DeltaType;
use risingwave_pb::hummock::rise_ctl_update_compaction_config_request::mutable_config;
use risingwave_pb::hummock::subscribe_compaction_event_request::{
Event as RequestEvent, HeartBeat, PullTask, ReportTask,
};
Expand Down Expand Up @@ -511,7 +513,7 @@ impl HummockManager {
versioning_guard.mark_objects_for_deletion();

let all_group_ids = get_compaction_group_ids(&versioning_guard.current_version);
let configs = self
let mut configs = self
.compaction_group_manager
.write()
.await
Expand All @@ -520,6 +522,42 @@ impl HummockManager {
self.env.meta_store(),
)
.await?;

// We've already lowered the default limit for write limit in PR-12183, and to prevent older clusters from continuing to use the outdated configuration, we've introduced a new logic to rewrite it in a uniform way.
let mut rewrite_cg_ids = vec![];
for (cg_id, compaction_group_config) in &mut configs {
// update write limit
let relaxed_default_write_stop_level_count = 1000;
if compaction_group_config
.compaction_config
.level0_sub_level_compact_level_count
== relaxed_default_write_stop_level_count
{
rewrite_cg_ids.push(*cg_id);
}
}

// update meta store
let result = self
.compaction_group_manager
.write()
.await
.update_compaction_config(
&rewrite_cg_ids,
&[
mutable_config::MutableConfig::Level0StopWriteThresholdSubLevelNumber(
compaction_config::level0_stop_write_threshold_sub_level_number(),
),
],
self.env.meta_store(),
)
.await?;

// update memory
for new_config in result {
configs.insert(new_config.group_id(), new_config);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we log the cg id and the updated config when the rewrite happens?


versioning_guard.write_limit =
calc_new_write_limits(configs, HashMap::new(), &versioning_guard.current_version);
trigger_write_stop_stats(&self.metrics, &versioning_guard.write_limit);
Expand Down
Loading