Skip to content

Commit 1bba54b

Browse files
committed
return new_frame_notifier and log_id from shared_wal
1 parent aaddf60 commit 1bba54b

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

libsql-wal/src/segment/current.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use fst::MapBuilder;
1414
use parking_lot::{Mutex, RwLock};
1515
use roaring::RoaringBitmap;
1616
use tokio_stream::Stream;
17+
use uuid::Uuid;
1718
use zerocopy::little_endian::U32;
1819
use zerocopy::{AsBytes, FromZeroes};
1920

@@ -54,6 +55,7 @@ impl<F> CurrentSegment<F> {
5455
db_size: u32,
5556
tail: Arc<SegmentList<SealedSegment<F>>>,
5657
salt: u32,
58+
log_id: Uuid,
5759
) -> Result<Self>
5860
where
5961
F: FileExt,
@@ -70,6 +72,7 @@ impl<F> CurrentSegment<F> {
7072
version: LIBSQL_WAL_VERSION.into(),
7173
salt: salt.into(),
7274
page_size: LIBSQL_PAGE_SIZE.into(),
75+
log_id: log_id.as_u128().into(),
7376
};
7477

7578
header.recompute_checksum();
@@ -88,6 +91,10 @@ impl<F> CurrentSegment<F> {
8891
})
8992
}
9093

94+
pub fn log_id(&self) -> Uuid {
95+
Uuid::from_u128(self.header.lock().log_id.get())
96+
}
97+
9198
pub fn is_empty(&self) -> bool {
9299
self.count_committed() == 0
93100
}

libsql-wal/src/segment/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::mem::size_of;
1515
use std::num::NonZeroU64;
1616
use std::sync::Arc;
1717

18-
use zerocopy::byteorder::little_endian::{U16, U32, U64};
18+
use zerocopy::byteorder::little_endian::{U128, U16, U32, U64};
1919
use zerocopy::AsBytes;
2020

2121
use crate::error::{Error, Result};
@@ -63,6 +63,7 @@ pub struct SegmentHeader {
6363
/// right now we only support 4096, but if se decided to support other sizes,
6464
/// we could do it without changing the header
6565
pub page_size: U16,
66+
pub log_id: U128,
6667

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

libsql-wal/src/shared_wal.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use std::collections::BTreeMap;
2-
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
2+
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering};
33
use std::sync::Arc;
44
use std::time::Instant;
55

66
use arc_swap::ArcSwap;
77
use crossbeam::deque::Injector;
88
use crossbeam::sync::Unparker;
99
use parking_lot::{Mutex, MutexGuard};
10-
use tokio::sync::mpsc;
10+
use tokio::sync::{mpsc, watch};
11+
use uuid::Uuid;
1112

1213
use crate::checkpointer::CheckpointMessage;
1314
use crate::error::{Error, Result};
@@ -83,10 +84,18 @@ impl<IO: Io> SharedWal<IO> {
8384
Ok(())
8485
}
8586

87+
pub fn new_frame_notifier(&self) -> watch::Receiver<u64> {
88+
self.new_frame_notifier.subscribe()
89+
}
90+
8691
pub fn db_size(&self) -> u32 {
8792
self.current.load().db_size()
8893
}
8994

95+
pub fn log_id(&self) -> Uuid {
96+
self.current.load().log_id()
97+
}
98+
9099
#[tracing::instrument(skip_all)]
91100
pub fn begin_read(&self, conn_id: u64) -> ReadTransaction<IO::File> {
92101
// FIXME: this is not enough to just increment the counter, we must make sure that the segment

0 commit comments

Comments
 (0)