Skip to content

Commit d569e2a

Browse files
committed
add sealed_at_timestamp field to SegmentHeader
1 parent 8a1ba79 commit d569e2a

4 files changed

Lines changed: 8 additions & 3 deletions

File tree

libsql-wal/src/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ where
542542
)?;
543543
// sealing must the last fallible operation, because we don't want to end up in a situation
544544
// where the current log is sealed and it wasn't swapped.
545-
if let Some(sealed) = current.seal()? {
545+
if let Some(sealed) = current.seal(self.io.now())? {
546546
new.tail().push(sealed.clone());
547547
maybe_store_segment(
548548
self.storage.as_ref(),

libsql-wal/src/segment/current.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::sync::{
99
Arc,
1010
};
1111

12+
use chrono::{DateTime, Utc};
1213
use crossbeam_skiplist::SkipMap;
1314
use fst::MapBuilder;
1415
use parking_lot::{Mutex, RwLock};
@@ -74,6 +75,7 @@ impl<F> CurrentSegment<F> {
7475
page_size: LIBSQL_PAGE_SIZE.into(),
7576
log_id: log_id.as_u128().into(),
7677
frame_count: 0.into(),
78+
sealed_at_timestamp: 0.into(),
7779
};
7880

7981
header.recompute_checksum();
@@ -408,7 +410,7 @@ impl<F> CurrentSegment<F> {
408410

409411
/// It is expected that sealing is performed under a write lock
410412
#[tracing::instrument(skip_all)]
411-
pub fn seal(&self) -> Result<Option<SealedSegment<F>>>
413+
pub fn seal(&self, now: DateTime<Utc>) -> Result<Option<SealedSegment<F>>>
412414
where
413415
F: FileExt,
414416
{
@@ -442,6 +444,7 @@ impl<F> CurrentSegment<F> {
442444
header.index_size = index_size.into();
443445
let flags = header.flags();
444446
header.set_flags(flags | SegmentFlags::SEALED);
447+
header.sealed_at_timestamp = (now.timestamp_millis() as u64).into();
445448
header.recompute_checksum();
446449
self.file.write_all_at(header.as_bytes(), 0)?;
447450

libsql-wal/src/segment/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ pub struct SegmentHeader {
6666
/// we could do it without changing the header
6767
pub page_size: U16,
6868
pub log_id: U128,
69+
/// ms, from unix epoch
70+
pub sealed_at_timestamp: U64,
6971

7072
/// checksum of the header fields, excluding the checksum itself. This field must be the last
7173
pub header_cheksum: U32,

libsql-wal/src/shared_wal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<IO: Io> SharedWal<IO> {
7979
}
8080
// The current segment will not be used anymore. It's empty, but we still seal it so that
8181
// the next startup doesn't find an unsealed segment.
82-
self.current.load().seal()?;
82+
self.current.load().seal(self.io.now())?;
8383
tracing::info!("namespace shutdown");
8484
Ok(())
8585
}

0 commit comments

Comments
 (0)