Skip to content

Commit 137b523

Browse files
authored
fix(meta): export should log large chunk of snapshot cache data (#18469)
1 parent 65240a4 commit 137b523

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/meta/types/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ tonic-build = { workspace = true }
3535

3636
[dev-dependencies]
3737
anyhow = { workspace = true }
38+
tempfile = { workspace = true }
3839

3940
[package.metadata.cargo-machete]
4041
ignored = ["num-derive", "prost"]

src/meta/types/src/snapshot_db.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::fmt;
1516
use std::fs;
1617
use std::io;
1718
use std::io::BufReader;
@@ -28,7 +29,7 @@ use crate::raft_types::SnapshotMeta;
2829
use crate::sys_data::SysData;
2930

3031
/// A readonly leveled map that owns the data.
31-
#[derive(Debug, Clone)]
32+
#[derive(Clone)]
3233
pub struct DB {
3334
pub storage_path: String,
3435
pub rel_path: String,
@@ -37,6 +38,17 @@ pub struct DB {
3738
pub rotbl: Arc<Rotbl>,
3839
}
3940

41+
impl fmt::Debug for DB {
42+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43+
f.debug_struct("DB")
44+
.field("storage_path", &self.storage_path)
45+
.field("rel_path", &self.rel_path)
46+
.field("meta", &self.meta)
47+
.field("sys_data", &self.sys_data)
48+
.finish()
49+
}
50+
}
51+
4052
impl AsRef<SysData> for DB {
4153
fn as_ref(&self) -> &SysData {
4254
&self.sys_data
@@ -163,3 +175,37 @@ pub struct DBStat {
163175
/// Total number of read block from disk.
164176
pub read_block_from_disk: u64,
165177
}
178+
179+
#[cfg(test)]
180+
mod tests {
181+
182+
use rotbl::storage::impls::fs::FsStorage;
183+
use rotbl::v001::Config;
184+
use rotbl::v001::RotblMeta;
185+
186+
use super::*;
187+
188+
/// Debug should not output db cache data.
189+
#[test]
190+
fn test_db_debug() {
191+
let tmp_dir = tempfile::tempdir().unwrap();
192+
let storage = FsStorage::new(tmp_dir.path().to_path_buf());
193+
let config = Config::default();
194+
let path = "test_rotbl";
195+
let rotbl =
196+
Rotbl::create_table(storage, config, path, RotblMeta::new(1, "foo"), []).unwrap();
197+
198+
let db = DB {
199+
storage_path: "a".to_string(),
200+
rel_path: "b".to_string(),
201+
meta: Default::default(),
202+
sys_data: Default::default(),
203+
rotbl: Arc::new(rotbl),
204+
};
205+
206+
assert_eq!(
207+
format!("{:?}", db),
208+
r#"DB { storage_path: "a", rel_path: "b", meta: SnapshotMeta { last_log_id: None, last_membership: StoredMembership { log_id: None, membership: Membership { configs: [], nodes: {} } }, snapshot_id: "" }, sys_data: SysData { last_applied: None, last_membership: StoredMembership { log_id: None, membership: Membership { configs: [], nodes: {} } }, nodes: {}, sequence: 0, key_counts: {}, sm_features: {} } }"#
209+
);
210+
}
211+
}

0 commit comments

Comments
 (0)