Skip to content

Commit 8af0600

Browse files
committed
replicator returns Box<Frame>
1 parent b7ffb05 commit 8af0600

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

libsql-wal/src/replication/injector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ mod test {
9797
primary_shared.last_committed_frame_no();
9898
for _ in 0..2 {
9999
let frame = stream.next().await.unwrap().unwrap();
100-
injector.insert_frame(Box::new(frame)).await.unwrap();
100+
injector.insert_frame(frame).await.unwrap();
101101
}
102102

103103
replica_conn
@@ -118,7 +118,7 @@ mod test {
118118
.unwrap();
119119

120120
let frame = stream.next().await.unwrap().unwrap();
121-
injector.insert_frame(Box::new(frame)).await.unwrap();
121+
injector.insert_frame(frame).await.unwrap();
122122

123123
replica_conn
124124
.query_row("select count(*) from test", (), |r| {

libsql-wal/src/replication/replicator.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ use roaring::RoaringBitmap;
44
use tokio::sync::watch;
55
use tokio_stream::{Stream, StreamExt};
66

7-
use crate::error::Result;
87
use crate::io::Io;
8+
use crate::replication::Error;
99
use crate::segment::Frame;
1010
use crate::shared_wal::SharedWal;
1111

12+
use super::Result;
13+
1214
pub struct Replicator<IO: Io> {
1315
shared: Arc<SharedWal<IO>>,
1416
new_frame_notifier: watch::Receiver<u64>,
@@ -38,7 +40,7 @@ impl<IO: Io> Replicator<IO> {
3840
///
3941
/// In a single replication step, the replicator guarantees that a minimal set of frames is
4042
/// sent to the replica.
41-
pub fn frame_stream(&mut self) -> impl Stream<Item = Result<Frame>> + '_ {
43+
pub fn frame_stream(&mut self) -> impl Stream<Item = Result<Box<Frame>>> + '_ {
4244
async_stream::try_stream! {
4345
loop {
4446
let most_recent_frame_no = *self
@@ -54,6 +56,7 @@ impl<IO: Io> Replicator<IO> {
5456
let (stream, replicated_until, size_after) = current.frame_stream_from(self.next_frame_no, &mut seen);
5557
let should_replicate_from_tail = replicated_until != self.next_frame_no;
5658

59+
5760
// replicate from current
5861
{
5962
tokio::pin!(stream);
@@ -62,7 +65,7 @@ impl<IO: Io> Replicator<IO> {
6265

6366
loop {
6467
let Some(frame) = stream.next().await else { break };
65-
let mut frame = frame?;
68+
let mut frame = frame.map_err(|e| Error::CurrentSegment(e.into()))?;
6669
commit_frame_no = frame.header().frame_no().max(commit_frame_no);
6770
if stream.peek().await.is_none() && !should_replicate_from_tail {
6871
frame.header_mut().set_size_after(size_after);

0 commit comments

Comments
 (0)