Skip to content

Commit 856fb21

Browse files
committed
feature to move checkpoint callback if any frames is written
Currently we report a checkpoint is finished only when `mxSafeFrame == mxFrame` in wal it is useful to have finish callback to be triggered in case any work moving frames was accomplished.
1 parent 8145962 commit 856fb21

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

libsql-ffi/Cargo.toml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ license.workspace = true
77
repository.workspace = true
88
description = "Native bindings to libSQL"
99
build = "build.rs"
10-
exclude = ["bundled/SQLite3MultipleCiphers/build", "bundled/SQLite3MultipleCiphers/test"]
10+
exclude = [
11+
"bundled/SQLite3MultipleCiphers/build",
12+
"bundled/SQLite3MultipleCiphers/test",
13+
]
1114

1215
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1316

@@ -37,11 +40,12 @@ sqlean-extension-math = []
3740
sqlean-extension-stats = []
3841
sqlean-extension-text = []
3942
sqlean-extensions = [
40-
"sqlean-extension-uuid",
41-
"sqlean-extension-crypto",
42-
"sqlean-extension-fuzzy",
43-
"sqlean-extension-math",
44-
"sqlean-extension-stats",
45-
"sqlean-extension-text"
43+
"sqlean-extension-uuid",
44+
"sqlean-extension-crypto",
45+
"sqlean-extension-fuzzy",
46+
"sqlean-extension-math",
47+
"sqlean-extension-stats",
48+
"sqlean-extension-text",
4649
]
4750
libsql-disable-checkpoint-downgrade = []
51+
libsql-checkpoint-callback-on-any-frame-written = []

libsql-ffi/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ pub fn build_bundled(out_dir: &str, out_path: &Path) {
276276
if cfg!(feature = "libsql-disable-checkpoint-downgrade") {
277277
cfg.flag("-DLIBSQL_DISABLE_CHECKPOINT_DOWNGRADE=1");
278278
}
279+
if cfg!(feature = "libsql-checkpoint-callback-on-any-frame-written") {
280+
cfg.flag("-DLIBSQL_CHECKPOINT_CALLBACK_ON_ANY_FRAME_WRITTEN=1");
281+
}
279282

280283
if cfg!(feature = "bundled-sqlcipher") {
281284
cfg.flag("-DSQLITE_HAS_CODEC").flag("-DSQLITE_TEMP_STORE=2");

libsql-sqlite3/src/wal.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,10 +2130,18 @@ static int walCheckpoint(
21302130

21312131
/* If work was actually accomplished... */
21322132
if( rc==SQLITE_OK ){
2133+
#ifdef LIBSQL_CHECKPOINT_CALLBACK_ON_ANY_FRAME_WRITTEN
2134+
if (xCb) {
2135+
rc = (xCb)(pCbData, mxSafeFrame, NULL, 0, 0, 0);
2136+
}
2137+
#endif
2138+
21332139
if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
2140+
#ifndef LIBSQL_CHECKPOINT_CALLBACK_ON_ANY_FRAME_WRITTEN
21342141
if (xCb) {
21352142
rc = (xCb)(pCbData, mxSafeFrame, NULL, 0, 0, 0);
21362143
}
2144+
#endif
21372145
if( rc==SQLITE_OK ){
21382146
i64 szDb = pWal->hdr.nPage*(i64)szPage;
21392147
testcase( IS_BIG_INT(szDb) );

0 commit comments

Comments
 (0)