Skip to content

Commit 2d0c679

Browse files
committed
determine whether segment should be stored based on durable frame_no
instead of a segment property
1 parent ee7a4ed commit 2d0c679

4 files changed

Lines changed: 7 additions & 25 deletions

File tree

libsql-wal/src/registry.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn maybe_store_segment<S: Storage>(
119119
durable_frame_no: &Arc<Mutex<u64>>,
120120
seg: S::Segment,
121121
) {
122-
if seg.is_storable() {
122+
if seg.last_committed() > *durable_frame_no.lock() {
123123
let cb: OnStoreCallback = Box::new({
124124
let notifier = notifier.clone();
125125
let durable_frame_no = durable_frame_no.clone();
@@ -134,7 +134,7 @@ fn maybe_store_segment<S: Storage>(
134134
} else {
135135
// segment can be checkpointed right away.
136136
let _ = notifier.blocking_send(CheckpointMessage::Namespace(namespace.clone()));
137-
tracing::debug!("segment marked as not storable; skipping");
137+
tracing::debug!(segment_end = seg.last_committed(), durable_frame_no = *durable_frame_no.lock(), "segment doesn't contain any new data");
138138
}
139139
}
140140

@@ -269,7 +269,7 @@ where
269269
let file = self.io.open(false, true, true, entry.path())?;
270270

271271
if let Some(sealed) =
272-
SealedSegment::open(file.into(), entry.path().to_path_buf(), Default::default())?
272+
SealedSegment::open(file.into(), entry.path().to_path_buf(), Default::default(), self.io.now())?
273273
{
274274
list.push(sealed.clone());
275275
maybe_store_segment(
@@ -401,6 +401,8 @@ where
401401
match self.opened.insert(namespace.clone(), Slot::Tombstone) {
402402
Some(Slot::Tombstone) => None,
403403
Some(Slot::Building(_, _)) => {
404+
// FIXME: that could happen is someone removed it and immediately reopenned the
405+
// wal. fix by retrying in a loop
404406
unreachable!("already waited for ns to open")
405407
}
406408
Some(Slot::Wal(wal)) => Some(wal),
@@ -558,8 +560,8 @@ where
558560
Ok(())
559561
}
560562

561-
pub fn storage(&self) -> &S {
562-
&self.storage
563+
pub fn storage(&self) -> Arc<S> {
564+
self.storage.clone()
563565
}
564566
}
565567

libsql-wal/src/segment/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ pub trait Segment: Send + Sync + 'static {
163163
fn start_frame_no(&self) -> u64;
164164
fn last_committed(&self) -> u64;
165165
fn index(&self) -> &fst::Map<Arc<[u8]>>;
166-
fn is_storable(&self) -> bool;
167166
fn read_page(&self, page_no: u32, max_frame_no: u64, buf: &mut [u8]) -> io::Result<bool>;
168167
/// returns the number of readers currently holding a reference to this log.
169168
/// The read count must monotonically decrease.
@@ -199,10 +198,6 @@ impl<T: Segment> Segment for Arc<T> {
199198
self.as_ref().index()
200199
}
201200

202-
fn is_storable(&self) -> bool {
203-
self.as_ref().is_storable()
204-
}
205-
206201
fn read_page(&self, page_no: u32, max_frame_no: u64, buf: &mut [u8]) -> io::Result<bool> {
207202
self.as_ref().read_page(page_no, max_frame_no, buf)
208203
}

libsql-wal/src/segment/sealed.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,6 @@ where
157157
&self.index
158158
}
159159

160-
fn is_storable(&self) -> bool {
161-
// we don't store unordered segments, since they only happen in two cases:
162-
// - in a replica: no need for storage
163-
// - in a primary, on recovery from storage: we don't want to override remote
164-
// segment.
165-
!self
166-
.header()
167-
.flags()
168-
.contains(SegmentFlags::FRAME_UNORDERED)
169-
}
170-
171160
fn read_page(&self, page_no: u32, max_frame_no: u64, buf: &mut [u8]) -> std::io::Result<bool> {
172161
if self.header().start_frame_no.get() > max_frame_no {
173162
return Ok(false);

libsql-wal/src/storage/job.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ mod test {
176176
async move { todo!() }
177177
}
178178

179-
fn is_storable(&self) -> bool {
180-
true
181-
}
182-
183179
fn timestamp(&self) -> DateTime<Utc> {
184180
Utc::now()
185181
}

0 commit comments

Comments
 (0)