From 09ea9d7d7d13dafbad3b11a96ba8c56bb1c02642 Mon Sep 17 00:00:00 2001 From: Peilun Li Date: Thu, 22 Aug 2024 14:25:06 +0800 Subject: [PATCH] Fix test. --- node/file_location_cache/src/file_location_cache.rs | 1 + node/sync/src/controllers/mod.rs | 9 ++++++--- node/sync/src/controllers/serial.rs | 2 +- node/sync/src/service.rs | 8 ++++---- tests/test_framework/zgs_node.py | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/node/file_location_cache/src/file_location_cache.rs b/node/file_location_cache/src/file_location_cache.rs index 6e278d6..73dd941 100644 --- a/node/file_location_cache/src/file_location_cache.rs +++ b/node/file_location_cache/src/file_location_cache.rs @@ -8,6 +8,7 @@ use shared_types::{timestamp_now, TxID}; use std::cmp::Reverse; use std::collections::HashMap; use storage::config::ShardConfig; +use tracing::debug; /// Caches limited announcements of specified file from different peers. struct AnnouncementCache { diff --git a/node/sync/src/controllers/mod.rs b/node/sync/src/controllers/mod.rs index ad2374f..1b838df 100644 --- a/node/sync/src/controllers/mod.rs +++ b/node/sync/src/controllers/mod.rs @@ -17,10 +17,12 @@ pub struct FileSyncGoal { pub index_start: u64, /// Chunk index to sync to (exclusive). pub index_end: u64, + /// `true` if we are syncing all the needed data of this file. + pub all_chunks: bool, } impl FileSyncGoal { - pub fn new(num_chunks: u64, index_start: u64, index_end: u64) -> Self { + pub fn new(num_chunks: u64, index_start: u64, index_end: u64, all_chunks: bool) -> Self { assert!( index_start < index_end && index_end <= num_chunks, "invalid index_end" @@ -29,15 +31,16 @@ impl FileSyncGoal { num_chunks, index_start, index_end, + all_chunks, } } pub fn new_file(num_chunks: u64) -> Self { - Self::new(num_chunks, 0, num_chunks) + Self::new(num_chunks, 0, num_chunks, true) } pub fn is_all_chunks(&self) -> bool { - self.index_start == 0 && self.index_end == self.num_chunks + self.all_chunks } } diff --git a/node/sync/src/controllers/serial.rs b/node/sync/src/controllers/serial.rs index 2fe0452..e3869f3 100644 --- a/node/sync/src/controllers/serial.rs +++ b/node/sync/src/controllers/serial.rs @@ -139,7 +139,7 @@ impl SerialSyncController { if let Some((start, end)) = maybe_range { // Sync new chunks regardless of previously downloaded file or chunks. // It's up to client to avoid duplicated chunks sync. - self.goal = FileSyncGoal::new(self.goal.num_chunks, start, end); + self.goal = FileSyncGoal::new(self.goal.num_chunks, start, end, false); self.next_chunk = start; } else if self.goal.is_all_chunks() { // retry the failed file sync at break point diff --git a/node/sync/src/service.rs b/node/sync/src/service.rs index c72b52a..5c41f2a 100644 --- a/node/sync/src/service.rs +++ b/node/sync/src/service.rs @@ -635,8 +635,8 @@ impl SyncService { bail!("File already exists"); } - let (index_start, index_end) = match maybe_range { - Some((start, end)) => (start, end), + let (index_start, index_end, all_chunks) = match maybe_range { + Some((start, end)) => (start, end, false), None => { let start = match Self::tx_sync_start_index(&self.store, &tx).await? { Some(s) => s, @@ -646,7 +646,7 @@ impl SyncService { return Ok(()); } }; - (start, num_chunks) + (start, num_chunks, true) } }; @@ -658,7 +658,7 @@ impl SyncService { self.config, tx.id(), tx.start_entry_index(), - FileSyncGoal::new(num_chunks, index_start, index_end), + FileSyncGoal::new(num_chunks, index_start, index_end, all_chunks), self.ctx.clone(), self.store.clone(), self.file_location_cache.clone(), diff --git a/tests/test_framework/zgs_node.py b/tests/test_framework/zgs_node.py index 06e3c0c..8ea9122 100644 --- a/tests/test_framework/zgs_node.py +++ b/tests/test_framework/zgs_node.py @@ -68,7 +68,7 @@ class ZgsNode(TestNode): os.mkdir(self.data_dir) log_config_path = os.path.join(self.data_dir, self.config["log_config_file"]) with open(log_config_path, "w") as f: - f.write("debug,hyper=info,h2=info") + f.write("trace,hyper=info,h2=info") initialize_toml_config(self.config_file, self.config)