Skip to content

Commit 1ec3aa0

Browse files
committed
fixup! store segment timestamp in SegmentKey
1 parent 838ed03 commit 1ec3aa0

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

libsql-server/src/wal_toolkit.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
33
use anyhow::Context as _;
44
use aws_config::{retry::RetryConfig, BehaviorVersion, Region};
55
use aws_sdk_s3::config::{Credentials, SharedCredentialsProvider};
6+
use chrono::DateTime;
67
use libsql_wal::io::StdIO;
78
use libsql_wal::storage::backend::s3::S3Backend;
89
use libsql_wal::storage::compaction::strategy::identity::IdentityStrategy;
@@ -80,11 +81,11 @@ impl WalToolkit {
8081
if let Some((first, last)) = compactor.get_segment_range(&namespace)? {
8182
println!(
8283
"- oldest segment: {}-{} ({})",
83-
first.key.start_frame_no, first.key.end_frame_no, first.created_at
84+
first.key.start_frame_no, first.key.end_frame_no, DateTime::from_timestamp_millis(first.key.timestamp as _).unwrap()
8485
);
8586
println!(
8687
"- most recent segment: {}-{} ({})",
87-
last.key.start_frame_no, last.key.end_frame_no, last.created_at
88+
last.key.start_frame_no, last.key.end_frame_no, DateTime::from_timestamp_millis(last.key.timestamp as _).unwrap()
8889
);
8990
}
9091

@@ -93,7 +94,7 @@ impl WalToolkit {
9394
compactor.list_all(&namespace, |info| {
9495
println!(
9596
"- {}-{} ({})",
96-
info.key.start_frame_no, info.key.end_frame_no, info.created_at
97+
info.key.start_frame_no, info.key.end_frame_no, DateTime::from_timestamp_millis(info.key.timestamp as _).unwrap()
9798
);
9899
})?;
99100
}

libsql-wal/src/storage/mod.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::BTreeMap;
2+
use std::fmt::Debug;
23
use std::path::{Path, PathBuf};
34
use std::pin::Pin;
45
use std::str::FromStr;
@@ -60,13 +61,23 @@ pub enum RestoreOptions {
6061
/// map.range(format!("{:020}", u64::MAX - 101)..).next();
6162
/// map.range(format!("{:020}", u64::MAX - 5000)..).next();
6263
/// ```
63-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
64+
#[derive(Clone, Copy, PartialEq, Eq)]
6465
pub struct SegmentKey {
6566
pub start_frame_no: u64,
6667
pub end_frame_no: u64,
6768
pub timestamp: u64,
6869
}
6970

71+
impl Debug for SegmentKey {
72+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73+
f.debug_struct("SegmentKey")
74+
.field("start_frame_no", &self.start_frame_no)
75+
.field("end_frame_no", &self.end_frame_no)
76+
.field("timestamp", &self.timestamp())
77+
.finish()
78+
}
79+
}
80+
7081
impl PartialOrd for SegmentKey {
7182
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
7283
match self.start_frame_no.partial_cmp(&other.start_frame_no) {
@@ -109,6 +120,12 @@ impl SegmentKey {
109120

110121
Some(key)
111122
}
123+
124+
fn timestamp(&self) -> DateTime<Utc> {
125+
DateTime::from_timestamp_millis(self.timestamp as _)
126+
.unwrap()
127+
.to_utc()
128+
}
112129
}
113130

114131
impl From<&SegmentMeta> for SegmentKey {
@@ -629,9 +646,9 @@ pub struct StoreSegmentRequest<S, C> {
629646
on_store_callback: OnStoreCallback,
630647
}
631648

632-
impl<S, C> fmt::Debug for StoreSegmentRequest<S, C>
649+
impl<S, C> Debug for StoreSegmentRequest<S, C>
633650
where
634-
S: fmt::Debug,
651+
S: Debug,
635652
{
636653
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
637654
f.debug_struct("StoreSegmentRequest")

0 commit comments

Comments
 (0)