Fossil SCM

New version of tmstmpvfs.c that names log files using ISO8601 names instead of hexadecimal milliseconds since 1970.

drh 2026-01-08 19:17 timestamp-vfs
Commit eb9f1c6d5a9089bbe35c36f16fe1779920f78134a68b311577cb2560ed8998b2
1 file changed +44 -10
+44 -10
--- extsrc/tmstmpvfs.c
+++ extsrc/tmstmpvfs.c
@@ -19,14 +19,14 @@
1919
** The VFS also tries to generate log-files with names of the form:
2020
**
2121
** $(DATABASE)-tmstmp/$(TIME)-$(PID)-$(ID)
2222
**
2323
** Log files are only generated if directory $(DATABASE)-tmstmp exists.
24
-** The name of each log file is the current unix-epoch time in millisecond,
24
+** The name of each log file is the current ISO8601 time in milliseconds,
2525
** the process ID, and a random 32-bit value (to disambiguate multiple
26
-** connections from the same process) separated by spaces. The log file
27
-** contains one 16-byte record for various events, such as opening or close
26
+** connections from the same process) separated by dashes. The log file
27
+** contains 16-bytes records for various events, such as opening or close
2828
** of the database or WAL file, writes to the WAL file, checkpoints, and
2929
** similar. The logfile is only generated if the connection attempts to
3030
** modify the database. There is a separate log file for each open database
3131
** connection.
3232
**
@@ -131,13 +131,13 @@
131131
** will create a log file if a directory name $(DATABASE)-tmstmp exists.
132132
** The name of the log file is:
133133
**
134134
** $(TIME)-$(PID)-$(RANDOM)
135135
**
136
-** Where TIME is the number of milliseconds since 1970, PID is the process
137
-** ID, and RANDOM is a 32-bit random number. All values are expressed
138
-** in hexadecimal.
136
+** Where TIME is an ISO 8601 date in milliseconds with no punctuation,
137
+** PID is the process ID, and RANDOM is a 32-bit random number expressed
138
+** as hexadecimal.
139139
**
140140
** The log consists of 16-byte records. Each record consists of five
141141
** unsigned integers:
142142
**
143143
** 1 1 6 4 4 <--- bytes
@@ -759,15 +759,31 @@
759759
if( pDb!=0 ){
760760
p->isWal = 1;
761761
p->pPartner = pDb;
762762
pDb->pPartner = p;
763763
}else{
764
- sqlite3_uint64 r1;
765764
u32 r2;
766765
u32 pid;
767766
TmstmpLog *pLog;
768
-
767
+ sqlite3_uint64 r1; /* Milliseconds since 1970-01-01 */
768
+ sqlite3_uint64 days; /* Days since 1970-01-01 */
769
+ sqlite3_uint64 sod; /* Start of date specified by ms */
770
+ sqlite3_uint64 z; /* Days since 0000-03-01 */
771
+ sqlite3_uint64 era; /* 400-year era */
772
+ int h; /* hour */
773
+ int m; /* minute */
774
+ int s; /* second */
775
+ int f; /* millisecond */
776
+ int Y; /* year */
777
+ int M; /* month */
778
+ int D; /* day */
779
+ int y; /* year assuming March is first month */
780
+ unsigned int doe; /* day of 400-year era */
781
+ unsigned int yoe; /* year of 400-year era */
782
+ unsigned int doy; /* day of year */
783
+ unsigned int mp; /* month with March==0 */
784
+
769785
p->isDb = 1;
770786
r1 = 0;
771787
pLog = sqlite3_malloc64( sizeof(TmstmpLog) );
772788
if( pLog==0 ){
773789
return SQLITE_NOMEM;
@@ -774,14 +790,32 @@
774790
}
775791
memset(pLog, 0, sizeof(pLog[0]));
776792
p->pLog = pLog;
777793
p->pSubVfs->xCurrentTimeInt64(p->pSubVfs, (sqlite3_int64*)&r1);
778794
r1 -= 210866760000000LL;
795
+ days = r1/86400000;
796
+ sod = (r1%86400000)/1000;
797
+ f = (int)(r1%1000);
798
+
799
+ h = sod/3600;
800
+ m = (sod%3600)/60;
801
+ s = sod%60;
802
+ z = days + 719468;
803
+ era = z/147097;
804
+ doe = (unsigned)(z - era*146097);
805
+ yoe = (doe - doe/1460 + doe/36524 - doe/146096)/365;
806
+ y = (int)yoe + era*400;
807
+ doy = doe - (365*yoe + yoe/4 - yoe/100);
808
+ mp = (5*doy + 2)/153;
809
+ D = doy - (153*mp + 2)/5 + 1;
810
+ M = mp + (mp<10 ? 3 : -9);
811
+ Y = y + (M <=2);
779812
sqlite3_randomness(sizeof(r2), &r2);
780813
pid = GETPID;
781
- pLog->zLogname = sqlite3_mprintf("%s-tmstmp/%llx-%08x-%08x",
782
- zName, r1, pid, r2);
814
+ pLog->zLogname = sqlite3_mprintf(
815
+ "%s-tmstmp/%04d%02d%02dT%02d%02d%02d%03d-%08d-%08x",
816
+ zName, Y, M, D, h, m, s, f, pid, r2);
783817
}
784818
tmstmpEvent(p, p->isWal ? ELOG_OPEN_WAL : ELOG_OPEN_DB, 0, GETPID, 0);
785819
786820
tmstmp_open_done:
787821
if( rc ) pFile->pMethods = 0;
788822
--- extsrc/tmstmpvfs.c
+++ extsrc/tmstmpvfs.c
@@ -19,14 +19,14 @@
19 ** The VFS also tries to generate log-files with names of the form:
20 **
21 ** $(DATABASE)-tmstmp/$(TIME)-$(PID)-$(ID)
22 **
23 ** Log files are only generated if directory $(DATABASE)-tmstmp exists.
24 ** The name of each log file is the current unix-epoch time in millisecond,
25 ** the process ID, and a random 32-bit value (to disambiguate multiple
26 ** connections from the same process) separated by spaces. The log file
27 ** contains one 16-byte record for various events, such as opening or close
28 ** of the database or WAL file, writes to the WAL file, checkpoints, and
29 ** similar. The logfile is only generated if the connection attempts to
30 ** modify the database. There is a separate log file for each open database
31 ** connection.
32 **
@@ -131,13 +131,13 @@
131 ** will create a log file if a directory name $(DATABASE)-tmstmp exists.
132 ** The name of the log file is:
133 **
134 ** $(TIME)-$(PID)-$(RANDOM)
135 **
136 ** Where TIME is the number of milliseconds since 1970, PID is the process
137 ** ID, and RANDOM is a 32-bit random number. All values are expressed
138 ** in hexadecimal.
139 **
140 ** The log consists of 16-byte records. Each record consists of five
141 ** unsigned integers:
142 **
143 ** 1 1 6 4 4 <--- bytes
@@ -759,15 +759,31 @@
759 if( pDb!=0 ){
760 p->isWal = 1;
761 p->pPartner = pDb;
762 pDb->pPartner = p;
763 }else{
764 sqlite3_uint64 r1;
765 u32 r2;
766 u32 pid;
767 TmstmpLog *pLog;
768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
769 p->isDb = 1;
770 r1 = 0;
771 pLog = sqlite3_malloc64( sizeof(TmstmpLog) );
772 if( pLog==0 ){
773 return SQLITE_NOMEM;
@@ -774,14 +790,32 @@
774 }
775 memset(pLog, 0, sizeof(pLog[0]));
776 p->pLog = pLog;
777 p->pSubVfs->xCurrentTimeInt64(p->pSubVfs, (sqlite3_int64*)&r1);
778 r1 -= 210866760000000LL;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
779 sqlite3_randomness(sizeof(r2), &r2);
780 pid = GETPID;
781 pLog->zLogname = sqlite3_mprintf("%s-tmstmp/%llx-%08x-%08x",
782 zName, r1, pid, r2);
 
783 }
784 tmstmpEvent(p, p->isWal ? ELOG_OPEN_WAL : ELOG_OPEN_DB, 0, GETPID, 0);
785
786 tmstmp_open_done:
787 if( rc ) pFile->pMethods = 0;
788
--- extsrc/tmstmpvfs.c
+++ extsrc/tmstmpvfs.c
@@ -19,14 +19,14 @@
19 ** The VFS also tries to generate log-files with names of the form:
20 **
21 ** $(DATABASE)-tmstmp/$(TIME)-$(PID)-$(ID)
22 **
23 ** Log files are only generated if directory $(DATABASE)-tmstmp exists.
24 ** The name of each log file is the current ISO8601 time in milliseconds,
25 ** the process ID, and a random 32-bit value (to disambiguate multiple
26 ** connections from the same process) separated by dashes. The log file
27 ** contains 16-bytes records for various events, such as opening or close
28 ** of the database or WAL file, writes to the WAL file, checkpoints, and
29 ** similar. The logfile is only generated if the connection attempts to
30 ** modify the database. There is a separate log file for each open database
31 ** connection.
32 **
@@ -131,13 +131,13 @@
131 ** will create a log file if a directory name $(DATABASE)-tmstmp exists.
132 ** The name of the log file is:
133 **
134 ** $(TIME)-$(PID)-$(RANDOM)
135 **
136 ** Where TIME is an ISO 8601 date in milliseconds with no punctuation,
137 ** PID is the process ID, and RANDOM is a 32-bit random number expressed
138 ** as hexadecimal.
139 **
140 ** The log consists of 16-byte records. Each record consists of five
141 ** unsigned integers:
142 **
143 ** 1 1 6 4 4 <--- bytes
@@ -759,15 +759,31 @@
759 if( pDb!=0 ){
760 p->isWal = 1;
761 p->pPartner = pDb;
762 pDb->pPartner = p;
763 }else{
 
764 u32 r2;
765 u32 pid;
766 TmstmpLog *pLog;
767 sqlite3_uint64 r1; /* Milliseconds since 1970-01-01 */
768 sqlite3_uint64 days; /* Days since 1970-01-01 */
769 sqlite3_uint64 sod; /* Start of date specified by ms */
770 sqlite3_uint64 z; /* Days since 0000-03-01 */
771 sqlite3_uint64 era; /* 400-year era */
772 int h; /* hour */
773 int m; /* minute */
774 int s; /* second */
775 int f; /* millisecond */
776 int Y; /* year */
777 int M; /* month */
778 int D; /* day */
779 int y; /* year assuming March is first month */
780 unsigned int doe; /* day of 400-year era */
781 unsigned int yoe; /* year of 400-year era */
782 unsigned int doy; /* day of year */
783 unsigned int mp; /* month with March==0 */
784
785 p->isDb = 1;
786 r1 = 0;
787 pLog = sqlite3_malloc64( sizeof(TmstmpLog) );
788 if( pLog==0 ){
789 return SQLITE_NOMEM;
@@ -774,14 +790,32 @@
790 }
791 memset(pLog, 0, sizeof(pLog[0]));
792 p->pLog = pLog;
793 p->pSubVfs->xCurrentTimeInt64(p->pSubVfs, (sqlite3_int64*)&r1);
794 r1 -= 210866760000000LL;
795 days = r1/86400000;
796 sod = (r1%86400000)/1000;
797 f = (int)(r1%1000);
798
799 h = sod/3600;
800 m = (sod%3600)/60;
801 s = sod%60;
802 z = days + 719468;
803 era = z/147097;
804 doe = (unsigned)(z - era*146097);
805 yoe = (doe - doe/1460 + doe/36524 - doe/146096)/365;
806 y = (int)yoe + era*400;
807 doy = doe - (365*yoe + yoe/4 - yoe/100);
808 mp = (5*doy + 2)/153;
809 D = doy - (153*mp + 2)/5 + 1;
810 M = mp + (mp<10 ? 3 : -9);
811 Y = y + (M <=2);
812 sqlite3_randomness(sizeof(r2), &r2);
813 pid = GETPID;
814 pLog->zLogname = sqlite3_mprintf(
815 "%s-tmstmp/%04d%02d%02dT%02d%02d%02d%03d-%08d-%08x",
816 zName, Y, M, D, h, m, s, f, pid, r2);
817 }
818 tmstmpEvent(p, p->isWal ? ELOG_OPEN_WAL : ELOG_OPEN_DB, 0, GETPID, 0);
819
820 tmstmp_open_done:
821 if( rc ) pFile->pMethods = 0;
822

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button