correctly handle compaction

Signed-off-by: Alex Chi Z <chi@neon.tech>
This commit is contained in:
Alex Chi Z
2023-06-28 14:40:41 -04:00
parent 6cb149e3c3
commit 4db4f42dec
2 changed files with 13 additions and 9 deletions

View File

@@ -23,8 +23,8 @@ pub fn start_background_loops(
) {
let tenant_id = tenant.tenant_id;
// start two compaction threads
let range = if ENABLE_TIERED_COMPACTION { 0..2 } else { 0..1 };
for _ in range {
let range = if ENABLE_TIERED_COMPACTION { 0..4 } else { 0..1 };
for cpt_id in range {
task_mgr::spawn(
BACKGROUND_RUNTIME.handle(),
TaskKind::Compaction,
@@ -42,7 +42,9 @@ pub fn start_background_loops(
_ = completion::Barrier::maybe_wait(background_jobs_can_start) => {}
};
compaction_loop(tenant, cancel)
.instrument(info_span!("compaction_loop", tenant_id = %tenant_id))
.instrument(
info_span!("compaction_loop", tenant_id = %tenant_id, cpt_id = %cpt_id),
)
.await;
Ok(())
}

View File

@@ -79,7 +79,7 @@ use self::eviction_task::EvictionTaskTimelineState;
use self::walreceiver::{WalReceiver, WalReceiverConf};
use super::config::TenantConf;
use super::layer_cache::{DeleteGuardRead, LayerCache, DeleteGuardWrite};
use super::layer_cache::{DeleteGuardRead, DeleteGuardWrite, LayerCache};
use super::layer_map::BatchedUpdates;
use super::remote_timeline_client::index::IndexPart;
use super::remote_timeline_client::RemoteTimelineClient;
@@ -4200,11 +4200,6 @@ impl Timeline {
drop(all_keys_iter); // So that deltas_to_compact is no longer borrowed
let mut compacting_tiers = self.compacting.lock().unwrap();
for &tier in &tier_to_compact {
compacting_tiers.remove(&tier);
}
Ok(Some(CompactTieredPhase1Result {
new_layers,
new_tier_at: *tier_to_compact.last().unwrap(),
@@ -4318,6 +4313,13 @@ impl Timeline {
println!("after compaction:");
layers.dump(false, ctx)?;
let mut compacting_tiers = self.compacting.lock().unwrap();
for &tier in &removed_tiers {
compacting_tiers.remove(&tier);
}
info!("compaction complete, removed_tiers = {removed_tiers:?}, new_tier_at = {new_tier_at}");
drop_wlock(guard);
// Also schedule the deletions in remote storage