Change the behavior of the sqlite3_wal_hook() callback. It should now return
SQLITE_OK or an error code and the error code is propagated back up the stack. If a checkpoint is desired, the callback should invoke sqlite3_wal_callback() itself. FossilOrigin-Name: 1b14195e05fe5551992a39246ec3bcf6a33bbfac
This commit is contained in:
parent
ccd13d1f80
commit
5def0843f1
28
manifest
28
manifest
@ -1,8 +1,8 @@
|
||||
-----BEGIN PGP SIGNED MESSAGE-----
|
||||
Hash: SHA1
|
||||
|
||||
C Further\ssimplifications\sto\sthe\sSHM\slocking\slogic.\s\sRemove\sthe\sSQLITE_SHM_QUERY\noption.\s\sUnify\sthe\sWRITE\sto\sREAD\sand\sRECOVER\sto\sREAD\stransitions.
|
||||
D 2010-05-05T19:09:49
|
||||
C Change\sthe\sbehavior\sof\sthe\ssqlite3_wal_hook()\scallback.\s\sIt\sshould\snow\sreturn\nSQLITE_OK\sor\san\serror\scode\sand\sthe\serror\scode\sis\spropagated\sback\sup\sthe\s\nstack.\s\sIf\sa\scheckpoint\sis\sdesired,\sthe\scallback\sshould\sinvoke\nsqlite3_wal_callback()\sitself.
|
||||
D 2010-05-05T20:00:26
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@ -134,7 +134,7 @@ F src/journal.c b0ea6b70b532961118ab70301c00a33089f9315c
|
||||
F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f
|
||||
F src/lempar.c 7f026423f4d71d989e719a743f98a1cbd4e6d99e
|
||||
F src/loadext.c 1c7a61ce1281041f437333f366a96aa0d29bb581
|
||||
F src/main.c 23c51a3c67da0c1cceab38f3575fff2f2ae49464
|
||||
F src/main.c cc62a14dd4a4e4f95ea21e762c87da14fe72e63c
|
||||
F src/malloc.c a08f16d134f0bfab6b20c3cd142ebf3e58235a6a
|
||||
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
|
||||
F src/mem1.c 89d4ea8d5cdd55635cbaa48ad53132af6294cbb2
|
||||
@ -169,13 +169,13 @@ F src/resolve.c ac5f1a713cd1ae77f08b83cc69581e11bf5ae6f9
|
||||
F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
|
||||
F src/select.c c03d8a0565febcde8c6a12c5d77d065fddae889b
|
||||
F src/shell.c c40427c7245535a04a9cb4a417b6cc05c022e6a4
|
||||
F src/sqlite.h.in e6ead287be496055ade50424b7799f84475da7d7
|
||||
F src/sqlite.h.in c68d5a6c13c04812b2873bb93d2132d1f5d3ccf8
|
||||
F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
|
||||
F src/sqliteInt.h 9819b45610abeca390176243a9a31758c1f0ac7a
|
||||
F src/sqliteLimit.h 196e2f83c3b444c4548fc1874f52f84fdbda40f3
|
||||
F src/status.c 4df6fe7dce2d256130b905847c6c60055882bdbe
|
||||
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
|
||||
F src/tclsqlite.c a6d69438c21e89c26dc791bfa4c5ba6da9dbb515
|
||||
F src/tclsqlite.c 6bc5fbde634b9cb42b3d29d674fa6cd0c22c0881
|
||||
F src/test1.c ff95ca772d1df51618f9f1ef7ea432cdf851f97b
|
||||
F src/test2.c 31f1b9d076b4774a22d2605d0af1f34e14a9a7bd
|
||||
F src/test3.c 4c21700c73a890a47fc685c1097bfb661346ac94
|
||||
@ -219,7 +219,7 @@ F src/vacuum.c 90a32e098cf06c5524c76b21027ee7520a821065
|
||||
F src/vdbe.c 8be37a1b18786b5c026adcb2e9edc93e3a940885
|
||||
F src/vdbe.h 471f6a3dcec4817ca33596fe7f6654d56c0e75f3
|
||||
F src/vdbeInt.h 19ebc8c2a2e938340051ee65af3f377fb99102d1
|
||||
F src/vdbeapi.c f2da22e5dcb1943ce6605614636e6bf32158640d
|
||||
F src/vdbeapi.c dc3138f10afbc95ed3c21dd25abb154504b1db9d
|
||||
F src/vdbeaux.c 395d21a1617553ea9b9f4abe0d302449d8549e1d
|
||||
F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e
|
||||
F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
|
||||
@ -766,10 +766,10 @@ F test/wal.test f0b331017a12a31dd4bbb20aee9c179fbfdd5921
|
||||
F test/walbak.test a0e45187c7d8928df035dfea29b99b016b21ca3c
|
||||
F test/walcrash.test f6d5fb2bb108876f04848720a488065d9deef69f
|
||||
F test/walfault.test 9146e22807d6c75885614f623f5c8b1272c8488e
|
||||
F test/walhook.test 5f18e0fc8787f1f8889d7a9971af18f334f83786
|
||||
F test/walhook.test a1c375ae791d5d7d511c166159729230791c574d
|
||||
F test/walmode.test bac6f06544a8554588a1543def996bbe2fc41792
|
||||
F test/walslow.test d21625e2e99e11c032ce949e8a94661576548933
|
||||
F test/walthread.test 08f553f38b99ad0fb96d188c175808df9dc5f790
|
||||
F test/walthread.test 1a8c55cd9e3272ba0caa028d8f0ead04989a3378
|
||||
F test/where.test de337a3fe0a459ec7c93db16a519657a90552330
|
||||
F test/where2.test 43d4becaf5a5df854e6c21d624a1cb84c6904554
|
||||
F test/where3.test aa44a9b29e8c9f3d7bb94a3bb3a95b31627d520d
|
||||
@ -813,14 +813,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
P 72663123d6be2b194cad7a6057d0f20dd0d9fe05
|
||||
R a9b4a745dd84e1e6c5aa687e7866b305
|
||||
P e9bfa6e4ce7d1edc6be8b9173ac3b6bfd180632a
|
||||
R e9fe5c9efad10446aa83b71914d33765
|
||||
U drh
|
||||
Z ba8b9550144dbde8add352394fc13a1f
|
||||
Z b26c7b5452be96cecc1a35cb38e6299b
|
||||
-----BEGIN PGP SIGNATURE-----
|
||||
Version: GnuPG v1.4.6 (GNU/Linux)
|
||||
|
||||
iD8DBQFL4cJ/oxKgR168RlERAn5HAJ9H9/xHH78dGiXt8tKDpcuSc8tO9QCfaUiX
|
||||
yaPexQIPM4/rd4uKeZ+hs2w=
|
||||
=FoJP
|
||||
iD8DBQFL4c5doxKgR168RlERAuadAJ9ImhZl3Q6JfaSg2/LCnbmOP58sywCfTv4N
|
||||
Ru+croJcME10MvNF9/ygcGg=
|
||||
=+Gfk
|
||||
-----END PGP SIGNATURE-----
|
||||
|
@ -1 +1 @@
|
||||
e9bfa6e4ce7d1edc6be8b9173ac3b6bfd180632a
|
||||
1b14195e05fe5551992a39246ec3bcf6a33bbfac
|
17
src/main.c
17
src/main.c
@ -1189,19 +1189,20 @@ void *sqlite3_rollback_hook(
|
||||
#ifndef SQLITE_OMIT_WAL
|
||||
/*
|
||||
** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint().
|
||||
** Return non-zero, indicating to the caller that a checkpoint should be run,
|
||||
** if the number of frames in the log file is greater than
|
||||
** sqlite3.pWalArg cast to an integer (the value configured by
|
||||
** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
|
||||
** is greater than sqlite3.pWalArg cast to an integer (the value configured by
|
||||
** wal_autocheckpoint()).
|
||||
*/
|
||||
int sqlite3WalDefaultHook(
|
||||
void *p, /* Argument */
|
||||
void *pClientData, /* Argument */
|
||||
sqlite3 *db, /* Connection */
|
||||
const char *zNotUsed, /* Database */
|
||||
const char *zDb, /* Database */
|
||||
int nFrame /* Size of WAL */
|
||||
){
|
||||
UNUSED_PARAMETER(zNotUsed);
|
||||
return ( nFrame>=SQLITE_PTR_TO_INT(p));
|
||||
if( nFrame>=SQLITE_PTR_TO_INT(pClientData) ){
|
||||
sqlite3_wal_checkpoint(db, zDb);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_WAL */
|
||||
|
||||
@ -1218,13 +1219,11 @@ int sqlite3WalDefaultHook(
|
||||
*/
|
||||
int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
|
||||
#ifndef SQLITE_OMIT_WAL
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
if( nFrame>0 ){
|
||||
sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
|
||||
}else{
|
||||
sqlite3_wal_hook(db, 0, 0);
|
||||
}
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
#endif
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
@ -5780,9 +5780,10 @@ void sqlite3_log(int iErrCode, const char *zFormat, ...);
|
||||
** is the number of pages currently in the log file, including those that
|
||||
** were just committed.
|
||||
**
|
||||
** If an invocation of the callback function returns non-zero, then a
|
||||
** checkpoint is automatically run on the database. If zero is returned,
|
||||
** no special action is taken.
|
||||
** The callback function should normally return SQLITE_OK. If an error
|
||||
** code is returned, that error will propagate back up through the
|
||||
** SQLite code base to cause the statement that provoked the callback
|
||||
** to fail.
|
||||
**
|
||||
** A single database handle may have at most a single log callback
|
||||
** registered at one time. Calling [sqlite3_wal_hook()] replaces any
|
||||
|
@ -123,7 +123,7 @@ struct SqliteDb {
|
||||
SqlFunc *pFunc; /* List of SQL functions */
|
||||
Tcl_Obj *pUpdateHook; /* Update hook script (if any) */
|
||||
Tcl_Obj *pRollbackHook; /* Rollback hook script (if any) */
|
||||
Tcl_Obj *pLogHook; /* WAL hook script (if any) */
|
||||
Tcl_Obj *pWalHook; /* WAL hook script (if any) */
|
||||
Tcl_Obj *pUnlockNotify; /* Unlock notify script (if any) */
|
||||
SqlCollate *pCollate; /* List of SQL collation functions */
|
||||
int rc; /* Return code of most recent sqlite3_exec() */
|
||||
@ -486,8 +486,8 @@ static void DbDeleteCmd(void *db){
|
||||
if( pDb->pRollbackHook ){
|
||||
Tcl_DecrRefCount(pDb->pRollbackHook);
|
||||
}
|
||||
if( pDb->pLogHook ){
|
||||
Tcl_DecrRefCount(pDb->pLogHook);
|
||||
if( pDb->pWalHook ){
|
||||
Tcl_DecrRefCount(pDb->pWalHook);
|
||||
}
|
||||
if( pDb->pCollateNeeded ){
|
||||
Tcl_DecrRefCount(pDb->pCollateNeeded);
|
||||
@ -593,19 +593,22 @@ static void DbRollbackHandler(void *clientData){
|
||||
}
|
||||
}
|
||||
|
||||
static int DbLogHandler(
|
||||
/*
|
||||
** This procedure handles wal_hook callbacks.
|
||||
*/
|
||||
static int DbWalHandler(
|
||||
void *clientData,
|
||||
sqlite3 *db,
|
||||
const char *zDb,
|
||||
int nEntry
|
||||
){
|
||||
int ret = 0;
|
||||
int ret = SQLITE_OK;
|
||||
Tcl_Obj *p;
|
||||
SqliteDb *pDb = (SqliteDb*)clientData;
|
||||
Tcl_Interp *interp = pDb->interp;
|
||||
assert(pDb->pLogHook);
|
||||
assert(pDb->pWalHook);
|
||||
|
||||
p = Tcl_DuplicateObj(pDb->pLogHook);
|
||||
p = Tcl_DuplicateObj(pDb->pWalHook);
|
||||
Tcl_IncrRefCount(p);
|
||||
Tcl_ListObjAppendElement(interp, p, Tcl_NewStringObj(zDb, -1));
|
||||
Tcl_ListObjAppendElement(interp, p, Tcl_NewIntObj(nEntry));
|
||||
@ -2775,7 +2778,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
if( choice==DB_UPDATE_HOOK ){
|
||||
ppHook = &pDb->pUpdateHook;
|
||||
}else if( choice==DB_WAL_HOOK ){
|
||||
ppHook = &pDb->pLogHook;
|
||||
ppHook = &pDb->pWalHook;
|
||||
}else{
|
||||
ppHook = &pDb->pRollbackHook;
|
||||
}
|
||||
@ -2801,7 +2804,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
|
||||
sqlite3_update_hook(pDb->db, (pDb->pUpdateHook?DbUpdateHandler:0), pDb);
|
||||
sqlite3_rollback_hook(pDb->db,(pDb->pRollbackHook?DbRollbackHandler:0),pDb);
|
||||
sqlite3_wal_hook(pDb->db,(pDb->pLogHook?DbLogHandler:0),pDb);
|
||||
sqlite3_wal_hook(pDb->db,(pDb->pWalHook?DbWalHandler:0),pDb);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -318,10 +318,8 @@ static int doWalCallbacks(sqlite3 *db){
|
||||
Btree *pBt = db->aDb[i].pBt;
|
||||
if( pBt ){
|
||||
int nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
|
||||
if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK
|
||||
&& db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry)
|
||||
){
|
||||
rc = sqlite3Checkpoint(db, i);
|
||||
if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
|
||||
rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ do_test walhook-1.2 {
|
||||
set ::wal_hook
|
||||
} {main 5}
|
||||
do_test walhook-1.3 {
|
||||
proc wal_hook {args} { return 1 }
|
||||
proc wal_hook {args} { db eval {PRAGMA wal_checkpoint}; return 0 }
|
||||
execsql { INSERT INTO t1 VALUES(2, 'two') }
|
||||
file size test.db
|
||||
} [expr 3*1024]
|
||||
|
@ -390,7 +390,7 @@ do_thread_test walthread-3 -seconds $seconds(walthread-3) -init {
|
||||
set nextwrite $E(pid)
|
||||
|
||||
proc wal_hook {zDb nEntry} {
|
||||
if {$nEntry>10} { return 1 }
|
||||
if {$nEntry>10} {db eval {PRAGMA wal_checkpoint}}
|
||||
return 0
|
||||
}
|
||||
db wal_hook wal_hook
|
||||
@ -443,7 +443,7 @@ do_thread_test2 walthread-4 -seconds $seconds(walthread-4) -init {
|
||||
} -thread w 1 {
|
||||
|
||||
proc wal_hook {zDb nEntry} {
|
||||
if {$nEntry>15} { return 1 }
|
||||
if {$nEntry>15} {db eval {PRAGMA wal_checkpoint}}
|
||||
return 0
|
||||
}
|
||||
db wal_hook wal_hook
|
||||
|
Loading…
x
Reference in New Issue
Block a user