From e17a469d7449693967bee492867dffdaeb1863d1 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 26 Jan 2026 21:20:28 +0000 Subject: [PATCH] Enhancements to tmstmpvfs.c: (1) Use the exact same timestamp on logfile entries as on the pages that control, where appropriate. (2) Include the WAL frame number in ELOG_CKPT_PAGE logfile entries. FossilOrigin-Name: fcf16297850abf5186b0d414b4f31d4b515925ef5cca5e7d7d84984c26160d00 --- ext/misc/tmstmpvfs.c | 34 +++++++++++++++++++++++----------- manifest | 16 ++++++++-------- manifest.uuid | 2 +- tool/showtmlog.c | 2 +- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/ext/misc/tmstmpvfs.c b/ext/misc/tmstmpvfs.c index c82292f2ee..9d84a7e6b3 100644 --- a/ext/misc/tmstmpvfs.c +++ b/ext/misc/tmstmpvfs.c @@ -192,6 +192,7 @@ ** ELOG_CKPT_PAGE "Page xfer from WAL to database" ** op = 0x06 ** a2 = database page number +** a3 = frame number in the WAL file ** ** ELOG_CKPT_END "Start of a checkpoint operation" ** op = 0x07 @@ -269,7 +270,7 @@ struct TmstmpLog { unsigned char a[16*6]; /* Buffered header for the log */ }; -/* An open WAL file */ +/* An open WAL or DB file */ struct TmstmpFile { sqlite3_file base; /* IO methods */ u32 uMagic; /* Magic number for sanity checking */ @@ -455,7 +456,8 @@ static void tmstmpEvent( u8 op, u8 a1, u32 a2, - u32 a3 + u32 a3, + u8 *pTS ){ unsigned char *a; TmstmpLog *pLog; @@ -472,7 +474,11 @@ static void tmstmpEvent( a = pLog->a + pLog->n; a[0] = op; a[1] = a1; - tmstmpPutTS(p, a+2); + if( pTS ){ + memcpy(a+2, pTS, 6); + }else{ + tmstmpPutTS(p, a+2); + } tmstmpPutU32(a2, a+8); tmstmpPutU32(a3, a+12); pLog->n += 16; @@ -487,7 +493,7 @@ static void tmstmpEvent( static int tmstmpClose(sqlite3_file *pFile){ TmstmpFile *p = (TmstmpFile *)pFile; if( p->hasCorrectReserve ){ - tmstmpEvent(p, p->isDb ? ELOG_CLOSE_DB : ELOG_CLOSE_WAL, 0, 0, 0); + tmstmpEvent(p, p->isDb ? ELOG_CLOSE_DB : ELOG_CLOSE_WAL, 0, 0, 0, 0); } tmstmpLogFree(p->pLog); if( p->pPartner ){ @@ -526,6 +532,12 @@ static int tmstmpRead( p->pPartner->pgsz = p->pgsz; } } + if( p->isWal + && p->inCkpt + && iAmt>=512 && iAmt<=65535 && (iAmt&(iAmt-1))==0 + ){ + p->pPartner->iFrame = (iOfst - 8)/(p->pgsz + 48) + 1; + } return rc; } @@ -560,14 +572,14 @@ static int tmstmpWrite( tmstmpPutU32(p->iFrame, s+8); tmstmpPutU32(p->salt1, s+12); s[12] = p->isCommit ? 1 : 0; - tmstmpEvent(p, ELOG_WAL_PAGE, s[12], p->pgno, p->iFrame); + tmstmpEvent(p, ELOG_WAL_PAGE, s[12], p->pgno, p->iFrame, s+2); }else if( iAmt==32 && iOfst==0 ){ u32 salt1 = tmstmpGetU32(((const u8*)zBuf)+16); - tmstmpEvent(p, ELOG_WAL_RESET, 0, 0, salt1); + tmstmpEvent(p, ELOG_WAL_RESET, 0, 0, salt1, 0); } }else if( p->inCkpt ){ assert( p->pgsz>0 ); - tmstmpEvent(p, ELOG_CKPT_PAGE, 0, (iOfst/p->pgsz)+1, 0); + tmstmpEvent(p, ELOG_CKPT_PAGE, 0, (iOfst/p->pgsz)+1, p->iFrame, 0); }else if( p->pPartner==0 ){ /* Writing into a database in rollback mode */ unsigned char *s = (unsigned char*)zBuf+iAmt-TMSTMP_RESERVE; @@ -575,7 +587,7 @@ static int tmstmpWrite( tmstmpPutTS(p, s+2); s[12] = 2; assert( p->pgsz>0 ); - tmstmpEvent(p, ELOG_DB_PAGE, 0, (u32)(iOfst/p->pgsz), 0); + tmstmpEvent(p, ELOG_DB_PAGE, 0, (u32)(iOfst/p->pgsz), 0, s+2); } return pSub->pMethods->xWrite(pSub,zBuf,iAmt,iOfst); } @@ -650,7 +662,7 @@ static int tmstmpFileControl(sqlite3_file *pFile, int op, void *pArg){ assert( p->pPartner!=0 ); p->pPartner->inCkpt = 1; if( p->hasCorrectReserve ){ - tmstmpEvent(p, ELOG_CKPT_START, 0, 0, 0); + tmstmpEvent(p, ELOG_CKPT_START, 0, 0, 0, 0); } rc = SQLITE_OK; break; @@ -661,7 +673,7 @@ static int tmstmpFileControl(sqlite3_file *pFile, int op, void *pArg){ assert( p->pPartner!=0 ); p->pPartner->inCkpt = 0; if( p->hasCorrectReserve ){ - tmstmpEvent(p, ELOG_CKPT_DONE, 0, 0, 0); + tmstmpEvent(p, ELOG_CKPT_DONE, 0, 0, 0, 0); } rc = SQLITE_OK; break; @@ -836,7 +848,7 @@ static int tmstmpOpen( "%s-tmstmp/%04d%02d%02dT%02d%02d%02d%03d-%08d-%08x", zName, Y, M, D, h, m, s, f, pid, r2); } - tmstmpEvent(p, p->isWal ? ELOG_OPEN_WAL : ELOG_OPEN_DB, 0, GETPID, 0); + tmstmpEvent(p, p->isWal ? ELOG_OPEN_WAL : ELOG_OPEN_DB, 0, GETPID, 0, 0); tmstmp_open_done: if( rc ) pFile->pMethods = 0; diff --git a/manifest b/manifest index 9bc42fea2a..eb1427c061 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stest\sfor\sfts3\scompress=\sand\suncompress=\soptions. -D 2026-01-26T20:17:10.707 +C Enhancements\sto\stmstmpvfs.c:\s\s(1)\sUse\sthe\sexact\ssame\stimestamp\son\slogfile\nentries\sas\son\sthe\spages\sthat\scontrol,\swhere\sappropriate.\s\s(2)\sInclude\sthe\nWAL\sframe\snumber\sin\sELOG_CKPT_PAGE\slogfile\sentries. +D 2026-01-26T21:20:28.044 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -403,7 +403,7 @@ F ext/misc/sqlite3_stdio.h 27a4ecea47e61bc9574ccdf2806f468afe23af2f95028c9b689bf F ext/misc/stmt.c b090086cd6bd6281c21271d38d576eeffe662f0e6b67536352ce32bbaa438321 F ext/misc/stmtrand.c 59cffa5d8e158943ff1ce078956d8e208e8c04e67307e8f249dece2436dcb7fc F ext/misc/templatevtab.c 10f15b165b95423ddef593bc5dcb915ec4eb5e0f1066d585e5435a368b8bc22b -F ext/misc/tmstmpvfs.c 3446d4a769ff05265cca4affc6533010b382bc33437b21476b792e95a32798e4 +F ext/misc/tmstmpvfs.c 38729ed49c8c861d00039c739e49fcbf106999715301034293d6c5d5ad93d4b0 F ext/misc/totype.c ba11aac3c0b52c685bd25aa4e0f80c41c624fb1cc5ab763250e09ddc762bc3a8 F ext/misc/uint.c 327afc166058acf566f33a15bf47c869d2d3564612644d9ff81a23efc8b36039 F ext/misc/unionvtab.c 716d385256d5fb4beea31b0efede640807e423e85c9784d21d22f0cce010a785 @@ -2166,7 +2166,7 @@ F tool/showjournal.c 5bad7ae8784a43d2b270d953060423b8bd480818 F tool/showlocks.c 9cc5e66d4ebbf2d194f39db2527ece92077e86ae627ddd233ee48e16e8142564 F tool/showshm.c a0ab6ec32dd1f11218ca2a4018f8fb875b59414801ab8ceed8b2e69b7b45a809 F tool/showstat4.c b706fcbc4cd1a6e4a73ac32549afc4b460479d650402d64b23e8d813516e8de4 -F tool/showtmlog.c 2ee3cfe698f64256419b2c2beacd504f24b020d6e2a91115f872a28ede188aa1 +F tool/showtmlog.c c31b358b802d4522c84c3fb44cf2f5838c7a84a244dd41f1c8d2573b5dc1bb78 F tool/showwal.c 11eca547980a066b081f512636151233350ac679f29ecf4ebfce7f4530230b3d F tool/soak1.tcl a3892082ed1079671565c044e93b55c3c7f38829aedf53cc597c65d23ffdaddf F tool/spaceanal.tcl 1f83962090a6b60e1d7bf92495d643e622bef9fe82ea3f2d22350dcbce9a12d0 @@ -2193,8 +2193,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c -P 4468c9e1a262d3d7efd8edff19e22e13b64ebed606ce2f18c9cabce93ef257d3 -R dd521bf1fe7458e258d3cdab4a0b84ba -U dan -Z c038d80545b5e1ae4728eba6d366053e +P bace9de67db426017d98f31685da1fc6ab10c7755681a41ca978cc97cb2ad5df +R bbdfd6a9f2325eda1b10caf330c1cb97 +U drh +Z ce744164aacfa3eae592a40fba323d9b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0816004614..b1bf11cc32 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bace9de67db426017d98f31685da1fc6ab10c7755681a41ca978cc97cb2ad5df +fcf16297850abf5186b0d414b4f31d4b515925ef5cca5e7d7d84984c26160d00 diff --git a/tool/showtmlog.c b/tool/showtmlog.c index eb11f4bd01..1892532791 100644 --- a/tool/showtmlog.c +++ b/tool/showtmlog.c @@ -104,7 +104,7 @@ int main(int argc, char **argv){ break; } case 0x06: { - printf("ckpt-page pgno %-8u\n", a2); + printf("ckpt-page pgno %-8u frame %-8u\n", a2, a3); break; } case 0x07: { -- 2.47.3