Skip to content

Commit 88664fd

Browse files
committed
Small touchups
1 parent 4ee7faf commit 88664fd

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

crates/commitlog/src/commitlog.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88
};
99

1010
use itertools::Itertools;
11-
use log::{debug, info, trace, warn};
11+
use log::{debug, error, info, trace, warn};
1212

1313
use crate::{
1414
commit::StoredCommit,
@@ -320,7 +320,7 @@ impl<R: Repo, T: Encode> Generic<R, T> {
320320
let writer = &mut self.head;
321321
let committed = writer.commit(transactions)?;
322322
if writer.len() >= self.opts.max_segment_size {
323-
self.flush().expect("failed to flush segment");
323+
self.flush().expect("failed to flush segment upon rotation");
324324
self.sync();
325325
self.start_new_segment()?;
326326
}
@@ -371,7 +371,7 @@ impl<R: Repo, T> Drop for Generic<R, T> {
371371
fn drop(&mut self) {
372372
if !self.panicked {
373373
if let Err(e) = self.flush_and_sync() {
374-
warn!("failed to flush on drop: {e:#}");
374+
error!("failed to flush on drop: {e:#}");
375375
}
376376
}
377377
}

crates/durability/src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,8 @@ pub type Close = BoxFuture<'static, Option<TxOffset>>;
9595
///
9696
/// NOTE: This is a preliminary definition, still under consideration.
9797
///
98-
/// A durability implementation accepts one or more [Transaction]s to be made
99-
/// durable via [Durability::commit] in a non-blocking fashion.
100-
///
101-
/// A batch of transactions is eventually made durable atomically.
102-
/// Note that this means that a torn write can render the whole batch
103-
/// inaccessible, so small batches are usually preferable.
98+
/// A durability implementation accepts a [Transaction] to be made durable via
99+
/// the [Durability::append_tx] method in a non-blocking fashion.
104100
///
105101
/// Once a transaction becomes durable, the [DurableOffset] is updated.
106102
/// What durable means depends on the implementation, informally it can be
@@ -115,6 +111,16 @@ pub trait Durability: Send + Sync {
115111
/// cannot be made durable immediately.
116112
///
117113
/// Errors may be signalled by panicking.
114+
//
115+
// TODO: Support batches of txs, i.e. commits.
116+
//
117+
// The commitlog supports this, but allocation overhead in the durability
118+
// API is too high given we don't make any use of it.
119+
//
120+
// We don't make any use of it because a commit is an atomic unit of storage
121+
// (i.e. a torn write will corrupt all transactions contained in it), and it
122+
// is very unclear when it is both correct and beneficial to bundle more
123+
// than a single transaction into a commit.
118124
fn append_tx(&self, tx: Transaction<Self::TxData>);
119125

120126
/// Obtain a handle to the [DurableOffset].

crates/durability/tests/io/fallocate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ async fn local_durability_crashes_on_new_segment_if_not_enough_space() {
9999
new_segment_rx.borrow_and_update();
100100
// Write past available space.
101101
for offset in 0..256 {
102-
durability.commit([(offset, txdata.clone()).into()].into());
102+
durability.append_tx((offset, txdata.clone()).into());
103103
}
104104
// Ensure new segment is created.
105105
new_segment_rx.changed().await?;
106106
// Yield to give fallocate a chance to run (and fail).
107107
sleep(Duration::from_millis(5)).await;
108108
// Durability actor should have crashed, so this should panic.
109109
info!("trying append on crashed durability");
110-
durability.commit([(256, txdata.clone()).into()].into());
110+
durability.append_tx((256, txdata.clone()).into());
111111
}
112112

113113
Ok(())

0 commit comments

Comments
 (0)