From cab1e9cddd1deec4066378088fab91a39040b475 Mon Sep 17 00:00:00 2001 From: Liu Hongyang Date: Mon, 19 May 2025 18:04:11 +0800 Subject: [PATCH] binlog bugfix: add dbpath to callback Signed-off-by: Liu Hongyang --- include/sqlite3sym.h | 4 +-- patch/0007-Support-Binlog.patch | 41 ++++++++++++++++++----------- patch/0008-BugFix-CurrVersion.patch | 6 ++--- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/include/sqlite3sym.h b/include/sqlite3sym.h index 9e35c33..59893ff 100644 --- a/include/sqlite3sym.h +++ b/include/sqlite3sym.h @@ -41,8 +41,8 @@ typedef struct Sqlite3BinlogConfig { Sqlite3BinlogMode mode; unsigned short fullCallbackThreshold; unsigned int maxFileSize; - void (*xErrorCallback)(void *pCtx, int errNo, char *errMsg); - void (*xLogFullCallback)(void *pCtx, unsigned short currentCount); + void (*xErrorCallback)(void *pCtx, int errNo, char *errMsg, const char *dbPath); + void (*xLogFullCallback)(void *pCtx, unsigned short currentCount, const char *dbPath); void *callbackCtx; } Sqlite3BinlogConfig; /* diff --git a/patch/0007-Support-Binlog.patch b/patch/0007-Support-Binlog.patch index ce43a74..a763526 100644 --- a/patch/0007-Support-Binlog.patch +++ b/patch/0007-Support-Binlog.patch @@ -1,14 +1,14 @@ -From bd1f40f6fa41ab9470436efbe641e1f1c2ac9b33 Mon Sep 17 00:00:00 2001 +From f5b85d48f4ea016ed63eed8f7e5e1d569121a282 Mon Sep 17 00:00:00 2001 From: Liu Hongyang -Date: Fri, 16 May 2025 17:27:13 +0800 +Date: Mon, 19 May 2025 17:38:02 +0800 Subject: [PATCH] Support-Binlog --- - src/sqlite3.c | 1288 ++++++++++++++++++++++++++++++++++++++++++++++++- - 1 file changed, 1279 insertions(+), 9 deletions(-) + src/sqlite3.c | 1299 ++++++++++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 1290 insertions(+), 9 deletions(-) diff --git a/src/sqlite3.c b/src/sqlite3.c -index c82804c..8dddbf6 100644 +index c82804c..37a3ea6 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -2839,7 +2839,9 @@ SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); @@ -62,8 +62,8 @@ index c82804c..8dddbf6 100644 +} BinlogErrnoE; + +typedef int BinlogErrno; -+typedef void (*BinlogOnErrorFuncT)(void *pCtx, BinlogErrno errNo, char *errMsg); -+typedef void (*BinlogOnLogFullFuncT)(void *pCtx, u16 currentCount); ++typedef void (*BinlogOnErrorFuncT)(void *pCtx, BinlogErrno errNo, char *errMsg, const char *dbPath); ++typedef void (*BinlogOnLogFullFuncT)(void *pCtx, u16 currentCount, const char *dbPath); +typedef int (*BinlogOnErrnoTransFuncT)(BinlogErrno errNo); + +typedef struct BinlogConfig { @@ -135,8 +135,8 @@ index c82804c..8dddbf6 100644 + Sqlite3BinlogMode mode; + u16 fullCallbackThreshold; + u32 maxFileSize; -+ void (*xErrorCallback)(void *pCtx, int errNo, char *errMsg); -+ void (*xLogFullCallback)(void *pCtx, u16 currentCount); ++ void (*xErrorCallback)(void *pCtx, int errNo, char *errMsg, const char *dbPath); ++ void (*xLogFullCallback)(void *pCtx, u16 currentCount, const char *dbPath); + void *callbackCtx; +} Sqlite3BinlogConfig; + @@ -173,8 +173,8 @@ index c82804c..8dddbf6 100644 + void *callbackCtx; + u64 flags; + u8 xTid[SQLITE_UUID_BLOB_LENGTH]; -+ void (*xErrorCallback)(void *pCtx, int errNo, char *errMsg); -+ void (*xLogFullCallback)(void *pCtx, u16 currentCount); ++ void (*xErrorCallback)(void *pCtx, int errNo, char *errMsg, const char *dbPath); ++ void (*xLogFullCallback)(void *pCtx, u16 currentCount, const char *dbPath); + BinlogInstanceT *binlogConn; + BinlogApi binlogApi; +} Sqlite3BinlogHandle; @@ -637,7 +637,7 @@ index c82804c..8dddbf6 100644 *ppDb = db; #ifdef SQLITE_ENABLE_SQLLOG if( sqlite3GlobalConfig.xSqllog ){ -@@ -247520,6 +247901,883 @@ static void walLogCheckpointInfo(Wal *pWal, sqlite3 *db, sqlite3_int64 startTime +@@ -247520,6 +247901,894 @@ static void walLogCheckpointInfo(Wal *pWal, sqlite3 *db, sqlite3_int64 startTime } } #endif @@ -1455,7 +1455,11 @@ index c82804c..8dddbf6 100644 + } + int res = + sqlite3TransferBinlogErrno(srcDb->xBinlogHandle.binlogApi.binlogLockReadApi(srcDb->xBinlogHandle.binlogConn)); ++ if (res == SQLITE_BUSY) { ++ return res; ++ } + if (res != SQLITE_OK) { ++ sqlite3BinlogClose(srcDb); + return res; + } + do { @@ -1513,7 +1517,14 @@ index c82804c..8dddbf6 100644 + if (db == NULL || db->xBinlogHandle.xErrorCallback == NULL) { + return; + } -+ db->xBinlogHandle.xErrorCallback(db->xBinlogHandle.callbackCtx, errNo, errMsg); ++ ++ const char *zFile = sqlite3_db_filename(db, 0); ++ if (zFile == NULL || (db->xBinlogHandle.flags & BINLOG_FLAG_ENABLE)) { ++ sqlite3_log(SQLITE_ERROR, "binlog db has no file path"); ++ return; ++ } ++ db->xBinlogHandle.xErrorCallback(db->xBinlogHandle.callbackCtx, errNo, errMsg, zFile); ++ +} +/************** End of binlog implement ************************************/ +#endif /* SQLITE_ENABLE_BINLOG */ @@ -1521,7 +1532,7 @@ index c82804c..8dddbf6 100644 // hw export the symbols #ifdef SQLITE_EXPORT_SYMBOLS #ifndef SQLITE_CKSUMVFS_STATIC -@@ -247550,6 +248808,9 @@ struct sqlite3_api_routines_hw { +@@ -247550,6 +248819,9 @@ struct sqlite3_api_routines_hw { int (*key_v2)(sqlite3*,const char*,const void*,int); int (*rekey)(sqlite3*,const void*,int); int (*rekey_v2)(sqlite3*,const char*,const void*,int); @@ -1531,7 +1542,7 @@ index c82804c..8dddbf6 100644 }; typedef struct sqlite3_api_routines_hw sqlite3_api_routines_hw; -@@ -247560,13 +248821,22 @@ static const sqlite3_api_routines_hw sqlite3HwApis = { +@@ -247560,13 +248832,22 @@ static const sqlite3_api_routines_hw sqlite3HwApis = { sqlite3_key, sqlite3_key_v2, sqlite3_rekey, diff --git a/patch/0008-BugFix-CurrVersion.patch b/patch/0008-BugFix-CurrVersion.patch index 2060234..a819605 100644 --- a/patch/0008-BugFix-CurrVersion.patch +++ b/patch/0008-BugFix-CurrVersion.patch @@ -1,6 +1,6 @@ -From f8ebccc3bc248e080e1343315fa5b9d0b399dab8 Mon Sep 17 00:00:00 2001 +From e62f982b90abfb4568e51bda0b8109a7fb345976 Mon Sep 17 00:00:00 2001 From: Liu Hongyang -Date: Sat, 17 May 2025 16:04:21 +0800 +Date: Mon, 19 May 2025 18:02:00 +0800 Subject: [PATCH] BugFix-CurrVersion --- @@ -8,7 +8,7 @@ Subject: [PATCH] BugFix-CurrVersion 1 file changed, 72 insertions(+), 35 deletions(-) diff --git a/src/sqlite3.c b/src/sqlite3.c -index 8dddbf6..777d1b1 100644 +index 37a3ea6..6c0e955 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -43480,6 +43480,9 @@ static int unixOpen( -- Gitee