Skip to content

Commit 0279bd9

Browse files
authored
Libsql checkpoint only full (#2062)
Replace `libsql-checkpoint-callback-on-any-frame-written` feature (introduced in #2054) with `libsql-checkpoint-only-full` which will force checkpoint to either abort immediately or transfer whole WAL file to the DB.
2 parents e3904f9 + c0e7241 commit 0279bd9

File tree

5 files changed

+35
-24
lines changed

5 files changed

+35
-24
lines changed

libsql-ffi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ sqlean-extensions = [
4848
"sqlean-extension-text",
4949
]
5050
libsql-disable-checkpoint-downgrade = []
51-
libsql-checkpoint-callback-on-any-frame-written = []
51+
libsql-checkpoint-only-full= []

libsql-ffi/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ 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");
279+
if cfg!(feature = "libsql-checkpoint-only-full") {
280+
cfg.flag("-DLIBSQL_CHECKPOINT_ONLY_FULL=1");
281281
}
282282

283283
if cfg!(feature = "bundled-sqlcipher") {

libsql-ffi/bundled/bindings/bindgen.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern "C" {
2323
) -> ::std::os::raw::c_int;
2424
}
2525

26+
pub const __GNUC_VA_LIST: i32 = 1;
2627
pub const SQLITE_VERSION: &[u8; 7] = b"3.45.1\0";
2728
pub const SQLITE_VERSION_NUMBER: i32 = 3045001;
2829
pub const SQLITE_SOURCE_ID: &[u8; 85] =
@@ -501,8 +502,8 @@ pub const FTS5_TOKENIZE_DOCUMENT: i32 = 4;
501502
pub const FTS5_TOKENIZE_AUX: i32 = 8;
502503
pub const FTS5_TOKEN_COLOCATED: i32 = 1;
503504
pub const WAL_SAVEPOINT_NDATA: i32 = 4;
504-
pub type __gnuc_va_list = __builtin_va_list;
505505
pub type va_list = __builtin_va_list;
506+
pub type __gnuc_va_list = __builtin_va_list;
506507
extern "C" {
507508
pub static sqlite3_version: [::std::os::raw::c_char; 0usize];
508509
}
@@ -939,7 +940,7 @@ extern "C" {
939940
extern "C" {
940941
pub fn sqlite3_vmprintf(
941942
arg1: *const ::std::os::raw::c_char,
942-
arg2: va_list,
943+
arg2: *mut __va_list_tag,
943944
) -> *mut ::std::os::raw::c_char;
944945
}
945946
extern "C" {
@@ -955,7 +956,7 @@ extern "C" {
955956
arg1: ::std::os::raw::c_int,
956957
arg2: *mut ::std::os::raw::c_char,
957958
arg3: *const ::std::os::raw::c_char,
958-
arg4: va_list,
959+
arg4: *mut __va_list_tag,
959960
) -> *mut ::std::os::raw::c_char;
960961
}
961962
extern "C" {
@@ -2505,7 +2506,7 @@ extern "C" {
25052506
pub fn sqlite3_str_vappendf(
25062507
arg1: *mut sqlite3_str,
25072508
zFormat: *const ::std::os::raw::c_char,
2508-
arg2: va_list,
2509+
arg2: *mut __va_list_tag,
25092510
);
25102511
}
25112512
extern "C" {
@@ -3573,4 +3574,12 @@ extern "C" {
35733574
extern "C" {
35743575
pub static sqlite3_wal_manager: libsql_wal_manager;
35753576
}
3576-
pub type __builtin_va_list = *mut ::std::os::raw::c_char;
3577+
pub type __builtin_va_list = [__va_list_tag; 1usize];
3578+
#[repr(C)]
3579+
#[derive(Debug, Copy, Clone)]
3580+
pub struct __va_list_tag {
3581+
pub gp_offset: ::std::os::raw::c_uint,
3582+
pub fp_offset: ::std::os::raw::c_uint,
3583+
pub overflow_arg_area: *mut ::std::os::raw::c_void,
3584+
pub reg_save_area: *mut ::std::os::raw::c_void,
3585+
}

libsql-ffi/bundled/src/sqlite3.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67613,6 +67613,15 @@ static int walCheckpoint(
6761367613
}
6761467614
}
6761567615

67616+
67617+
#ifdef LIBSQL_CHECKPOINT_ONLY_FULL
67618+
// in case of LIBSQL_CHECKPOINT_ONLY_FULL option we want to either checkpoint whole WAL or quickly abort the checkpoint
67619+
if( mxSafeFrame!=walIndexHdr(pWal)->mxFrame ){
67620+
rc = SQLITE_BUSY;
67621+
goto walcheckpoint_out;
67622+
}
67623+
#endif
67624+
6761667625
/* Allocate the iterator */
6761767626
if( pInfo->nBackfill<mxSafeFrame ){
6761867627
rc = walIteratorRevInit(pWal, pInfo->nBackfill, &pIter, mxSafeFrame, xCb == NULL);
@@ -67677,18 +67686,10 @@ static int walCheckpoint(
6767767686

6767867687
/* If work was actually accomplished... */
6767967688
if( rc==SQLITE_OK ){
67680-
#ifdef LIBSQL_CHECKPOINT_CALLBACK_ON_ANY_FRAME_WRITTEN
67681-
if (xCb) {
67682-
rc = (xCb)(pCbData, mxSafeFrame, NULL, 0, 0, 0);
67683-
}
67684-
#endif
67685-
6768667689
if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
67687-
#ifndef LIBSQL_CHECKPOINT_CALLBACK_ON_ANY_FRAME_WRITTEN
6768867690
if (xCb) {
6768967691
rc = (xCb)(pCbData, mxSafeFrame, NULL, 0, 0, 0);
6769067692
}
67691-
#endif
6769267693
if( rc==SQLITE_OK ){
6769367694
i64 szDb = pWal->hdr.nPage*(i64)szPage;
6769467695
testcase( IS_BIG_INT(szDb) );

libsql-sqlite3/src/wal.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,15 @@ static int walCheckpoint(
20662066
}
20672067
}
20682068

2069+
2070+
#ifdef LIBSQL_CHECKPOINT_ONLY_FULL
2071+
// in case of LIBSQL_CHECKPOINT_ONLY_FULL option we want to either checkpoint whole WAL or quickly abort the checkpoint
2072+
if( mxSafeFrame!=walIndexHdr(pWal)->mxFrame ){
2073+
rc = SQLITE_BUSY;
2074+
goto walcheckpoint_out;
2075+
}
2076+
#endif
2077+
20692078
/* Allocate the iterator */
20702079
if( pInfo->nBackfill<mxSafeFrame ){
20712080
rc = walIteratorRevInit(pWal, pInfo->nBackfill, &pIter, mxSafeFrame, xCb == NULL);
@@ -2130,18 +2139,10 @@ static int walCheckpoint(
21302139

21312140
/* If work was actually accomplished... */
21322141
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-
21392142
if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
2140-
#ifndef LIBSQL_CHECKPOINT_CALLBACK_ON_ANY_FRAME_WRITTEN
21412143
if (xCb) {
21422144
rc = (xCb)(pCbData, mxSafeFrame, NULL, 0, 0, 0);
21432145
}
2144-
#endif
21452146
if( rc==SQLITE_OK ){
21462147
i64 szDb = pWal->hdr.nPage*(i64)szPage;
21472148
testcase( IS_BIG_INT(szDb) );

0 commit comments

Comments
 (0)