Skip to content

Commit b551a60

Browse files
committed
fix: yield back to executor for abortion
1 parent 41eae61 commit b551a60

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

libsql/src/database/builder.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,10 +645,14 @@ cfg_sync! {
645645
let mut bg_abort: Option<std::sync::Arc<crate::sync::DropAbort>> = None;
646646

647647
if let Some(sync_interval) = sync_interval {
648+
let sync_span = tracing::debug_span!("sync_interval");
649+
let _enter = sync_span.enter();
650+
648651
let sync_ctx = db.sync_ctx.as_ref().unwrap().clone();
649652
{
650653
let mut ctx = sync_ctx.lock().await;
651654
crate::sync::bootstrap_db(&mut ctx).await?;
655+
tracing::debug!("finished bootstrap with sync interval");
652656
}
653657

654658
// db.connect creates a local db file, so it is important that we always call
@@ -657,8 +661,13 @@ cfg_sync! {
657661
let conn = db.connect()?;
658662
let jh = tokio::spawn(
659663
async move {
664+
let mut interval = tokio::time::interval(sync_interval);
665+
660666
loop {
661-
tracing::trace!("trying to sync");
667+
tracing::info!("trying to sync");
668+
669+
interval.tick().await;
670+
662671
let mut ctx = sync_ctx.lock().await;
663672
if remote_writes {
664673
if let Err(e) = crate::sync::try_pull(&mut ctx, &conn).await {
@@ -669,10 +678,9 @@ cfg_sync! {
669678
tracing::error!("sync error: {}", e);
670679
}
671680
}
672-
tokio::time::sleep(sync_interval).await;
673681
}
674682
}
675-
.instrument(tracing::info_span!("sync_interval")),
683+
.instrument(tracing::debug_span!("sync interval thread")),
676684
);
677685

678686
bg_abort.replace(std::sync::Arc::new(crate::sync::DropAbort(jh.abort_handle())));

libsql/src/sync.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,8 @@ async fn try_push(
846846

847847
let mut frame_no = start_frame_no;
848848
while frame_no <= end_frame_no {
849+
tokio::task::yield_now().await;
850+
849851
let batch_size = sync_ctx.push_batch_size.min(end_frame_no - frame_no + 1);
850852
let mut frames = conn.wal_get_frame(frame_no, page_size)?;
851853
if batch_size > 1 {
@@ -893,6 +895,8 @@ pub async fn try_pull(
893895
let mut err = None;
894896

895897
loop {
898+
tokio::task::yield_now().await;
899+
896900
let generation = sync_ctx.durable_generation();
897901
let frame_no = sync_ctx.durable_frame_num() + 1;
898902
match sync_ctx.pull_one_frame(generation, frame_no).await {

0 commit comments

Comments
 (0)