From 8ba6454e21834061cdc90986e71690d64cbabbe0 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 25 Mar 2025 13:11:11 +0100 Subject: [PATCH] reduce anti-entropy interval for fullcopy tables --- src/table/replication/fullcopy.rs | 7 +++++++ src/table/replication/parameters.rs | 4 ++++ src/table/replication/sharded.rs | 4 ++++ src/table/sync.rs | 5 +---- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/table/replication/fullcopy.rs b/src/table/replication/fullcopy.rs index 938fe954..63ca5181 100644 --- a/src/table/replication/fullcopy.rs +++ b/src/table/replication/fullcopy.rs @@ -1,4 +1,5 @@ use std::sync::Arc; +use std::time::Duration; use garage_rpc::layout::*; use garage_rpc::system::System; @@ -26,6 +27,12 @@ pub struct TableFullReplication { impl TableReplication for TableFullReplication { type WriteSets = Vec>; + // Do anti-entropy every 10 seconds. + // Compared to sharded tables, anti-entropy is much less costly as there is + // a single partition hash to exchange. + // Also, it's generally a much bigger problem for fullcopy tables to be out of sync. + const ANTI_ENTROPY_INTERVAL: Duration = Duration::from_secs(10); + fn storage_nodes(&self, _hash: &Hash) -> Vec { self.system.cluster_layout().all_nodes().to_vec() } diff --git a/src/table/replication/parameters.rs b/src/table/replication/parameters.rs index 3649fad3..327f2cbf 100644 --- a/src/table/replication/parameters.rs +++ b/src/table/replication/parameters.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use garage_rpc::layout::*; use garage_util::data::*; @@ -5,6 +7,8 @@ use garage_util::data::*; pub trait TableReplication: Send + Sync + 'static { type WriteSets: AsRef>> + AsMut>> + Send + Sync + 'static; + const ANTI_ENTROPY_INTERVAL: Duration; + // See examples in table_sharded.rs and table_fullcopy.rs // To understand various replication methods diff --git a/src/table/replication/sharded.rs b/src/table/replication/sharded.rs index 17a848fe..e1041174 100644 --- a/src/table/replication/sharded.rs +++ b/src/table/replication/sharded.rs @@ -1,4 +1,5 @@ use std::sync::Arc; +use std::time::Duration; use garage_rpc::layout::*; use garage_rpc::system::System; @@ -25,6 +26,9 @@ pub struct TableShardedReplication { } impl TableReplication for TableShardedReplication { + // Do anti-entropy every 10 minutes + const ANTI_ENTROPY_INTERVAL: Duration = Duration::from_secs(10 * 60); + type WriteSets = WriteLock>>; fn storage_nodes(&self, hash: &Hash) -> Vec { diff --git a/src/table/sync.rs b/src/table/sync.rs index 2d43b9fc..6c8ddb1d 100644 --- a/src/table/sync.rs +++ b/src/table/sync.rs @@ -27,9 +27,6 @@ use crate::merkle::*; use crate::replication::*; use crate::*; -// Do anti-entropy every 10 minutes -const ANTI_ENTROPY_INTERVAL: Duration = Duration::from_secs(10 * 60); - pub struct TableSyncer { system: Arc, data: Arc>, @@ -514,7 +511,7 @@ impl SyncWorker { partitions.partitions.shuffle(&mut thread_rng()); self.todo = Some(partitions); - self.next_full_sync = Instant::now() + ANTI_ENTROPY_INTERVAL; + self.next_full_sync = Instant::now() + R::ANTI_ENTROPY_INTERVAL; } }