Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions libsql/src/database/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,14 @@ cfg_sync! {
let mut bg_abort: Option<std::sync::Arc<crate::sync::DropAbort>> = None;

if let Some(sync_interval) = sync_interval {
let sync_span = tracing::debug_span!("sync_interval");
let _enter = sync_span.enter();

let sync_ctx = db.sync_ctx.as_ref().unwrap().clone();
{
let mut ctx = sync_ctx.lock().await;
crate::sync::bootstrap_db(&mut ctx).await?;
tracing::debug!("finished bootstrap with sync interval");
}

// db.connect creates a local db file, so it is important that we always call
Expand All @@ -657,8 +661,13 @@ cfg_sync! {
let conn = db.connect()?;
let jh = tokio::spawn(
async move {
let mut interval = tokio::time::interval(sync_interval);

loop {
tracing::trace!("trying to sync");
tracing::info!("trying to sync");
Comment thread
levydsa marked this conversation as resolved.
Outdated

interval.tick().await;
Comment thread
levydsa marked this conversation as resolved.
Outdated

let mut ctx = sync_ctx.lock().await;
if remote_writes {
if let Err(e) = crate::sync::try_pull(&mut ctx, &conn).await {
Expand All @@ -669,10 +678,9 @@ cfg_sync! {
tracing::error!("sync error: {}", e);
}
}
tokio::time::sleep(sync_interval).await;
}
}
.instrument(tracing::info_span!("sync_interval")),
.instrument(tracing::debug_span!("sync interval thread")),
);

bg_abort.replace(std::sync::Arc::new(crate::sync::DropAbort(jh.abort_handle())));
Expand Down
4 changes: 4 additions & 0 deletions libsql/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,8 @@ async fn try_push(

let mut frame_no = start_frame_no;
while frame_no <= end_frame_no {
tokio::task::yield_now().await;

let batch_size = sync_ctx.push_batch_size.min(end_frame_no - frame_no + 1);
let mut frames = conn.wal_get_frame(frame_no, page_size)?;
if batch_size > 1 {
Expand Down Expand Up @@ -893,6 +895,8 @@ pub async fn try_pull(
let mut err = None;

loop {
tokio::task::yield_now().await;
Comment thread
PThorpe92 marked this conversation as resolved.
Outdated

let generation = sync_ctx.durable_generation();
let frame_no = sync_ctx.durable_frame_num() + 1;
match sync_ctx.pull_one_frame(generation, frame_no).await {
Expand Down
Loading