Skip to content

Commit 6a68e88

Browse files
committed
checkpoint in the background
1 parent f0169ed commit 6a68e88

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/database.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,28 @@ impl Database {
319319
version > 0 && version % 40 == 0
320320
};
321321

322-
// Checkpoint outside the write lock if needed
322+
// Checkpoint in the background if needed
323323
if should_checkpoint {
324-
// Take a read lock for checkpointing
325-
let table = table_ref.read().await;
326-
let version = table.version();
327-
info!("Checkpointing Delta table at version {}", version);
328-
checkpoints::create_checkpoint(&table, None).await?;
324+
// Clone the necessary resources for the background task
325+
let table_ref_clone = Arc::clone(&table_ref);
326+
327+
// Spawn a background task to perform checkpointing
328+
tokio::spawn(async move {
329+
// Take a read lock for checkpointing
330+
let result = async {
331+
let table = table_ref_clone.read().await;
332+
let version = table.version();
333+
info!("Starting background checkpointing for Delta table at version {}", version);
334+
checkpoints::create_checkpoint(&table, None).await
335+
}.await;
336+
337+
match result {
338+
Ok(_) => info!("Background checkpointing completed successfully"),
339+
Err(e) => error!("Background checkpointing failed: {}", e),
340+
}
341+
});
342+
343+
info!("Checkpoint scheduled in background");
329344
}
330345

331346
Ok(())

0 commit comments

Comments
 (0)