1818** separate file. This file contains only code for the core SQLite library.
1919**
2020** The content in this amalgamation comes from Fossil check-in
21- ** 1f0cf66a7851fdb878e3d8cac13c5baba3d7 with changes in files:
21+ ** e3af311bdeb6d86480858e5084471807ec71 with changes in files:
2222**
2323**
2424*/
@@ -476,10 +476,10 @@ extern "C" {
476476*/
477477#define SQLITE_VERSION "3.52.0"
478478#define SQLITE_VERSION_NUMBER 3052000
479- #define SQLITE_SOURCE_ID "2026-02-13 11:07:58 1f0cf66a7851fdb878e3d8cac13c5baba3d7c73212ea8f1a19c2f6cbccfb9e9f "
479+ #define SQLITE_SOURCE_ID "2026-03-04 19:30:52 e3af311bdeb6d86480858e5084471807ec714a9f193c7bef10f0cc82f3e2d471 "
480480#define SQLITE_SCM_BRANCH "hctree-bedrock"
481481#define SQLITE_SCM_TAGS ""
482- #define SQLITE_SCM_DATETIME "2026-02-13T11:07:58.070Z "
482+ #define SQLITE_SCM_DATETIME "2026-03-04T19:30:52.802Z "
483483
484484/*
485485** CAPI3REF: Run-Time Library Version Numbers
@@ -25293,7 +25293,7 @@ SQLITE_API int sqlite3_db_status64(
2529325293 sqlite3BtreeEnterAll(db);
2529425294 for(i=0; i<db->nDb; i++){
2529525295 Btree *pBt = db->aDb[i].pBt;
25296- if( pBt ){
25296+ if( pBt && 0==sqlite3IsHct(pBt) ){
2529725297 Pager *pPager = sqlite3BtreePager(pBt);
2529825298 int nByte = sqlite3PagerMemUsed(pPager);
2529925299 if( op==SQLITE_DBSTATUS_CACHE_USED_SHARED ){
@@ -89599,8 +89599,8 @@ struct HBtree {
8959989599 HctMainStats stats;
8960089600
8960189601#ifdef HCT_ENABLE_COMMIT_TIMERS
89602- i64 aCommitTimer[HCT_COMMIT_N_TIMER];
8960389602 i64 iCommitHwTime;
89603+ i64 iCommitUsTime;
8960489604 HctMainStats savedstats;
8960589605 struct rusage savedusage;
8960689606#endif
@@ -89621,16 +89621,8 @@ static i64 hctDbGetUs(){
8962189621 return ((i64)tv.tv_sec * 1000000 + (i64)tv.tv_usec);
8962289622}
8962389623
89624- #define HCT_COMMIT_START 0
89625- #define HCT_COMMIT_AFTER_TREE_RELEASE 1
89626- #define HCT_COMMIT_AFTER_WRITE_LOG 2
89627- #define HCT_COMMIT_AFTER_FLUSH_DATA 3
89628- #define HCT_COMMIT_AFTER_VALIDATION 4
89629- #define HCT_COMMIT_AFTER_ZERO_LOG 5
89630- #define HCT_COMMIT_AFTER_TREE_CLEAR 6
89631- #define HCT_COMMIT_AFTER_END_READ 7
89632-
89633- SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void);
89624+ SQLITE_PRIVATE sqlite3_uint64 sqlite3Hwtime(void);
89625+ # ifdef SQLITE_AMALGAMATION
8963489626/************** Include hwtime.h in the middle of hctree.c *******************/
8963589627/************** Begin file hwtime.h ******************************************/
8963689628/*
@@ -89720,14 +89712,15 @@ SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
8972089712
8972189713/************** End of hwtime.h **********************************************/
8972289714/************** Continuing where we left off in hctree.c *********************/
89715+ # endif
8972389716
8972489717/*
8972589718** Save statistics in case this is a slow commit.
8972689719*/
8972789720static void hctCommitTimerSaveStats(HBtree *p){
89728- memset(p->aCommitTimer, 0, sizeof(i64) * HCT_COMMIT_N_TIMER);
8972989721 p->savedstats = p->stats;
8973089722 p->iCommitHwTime = sqlite3Hwtime();
89723+ p->iCommitUsTime = hctDbGetUs();
8973189724 if( p->pHctDb ){
8973289725 sqlite3HctDbSaveStats(p->pHctDb);
8973389726 sqlite3HctFileSaveStats(sqlite3HctDbFile(p->pHctDb));
@@ -89740,10 +89733,9 @@ static i64 hctTimevalDiff(struct timeval *p1, struct timeval *p2){
8974089733}
8974189734
8974289735static void hctCommitTimerLog(HBtree *p){
89743- i64 *aTimer = p->aCommitTimer;
89744- if( aTimer[0] ){
89745- i64 nUs = aTimer[HCT_COMMIT_N_TIMER-1] - aTimer[0];
89746- if( nUs>HCT_COMMIT_TIMER_THRESHOLD_US ){
89736+ if( p->iCommitHwTime ){
89737+ i64 iNow = hctDbGetUs();
89738+ if( (iNow - p->iCommitUsTime)>HCT_COMMIT_TIMER_THRESHOLD_US ){
8974789739 char *zMainStats = 0;
8974889740 char *zDbStats = 0;
8974989741 char *zFileStats = 0;
@@ -89779,17 +89771,10 @@ static void hctCommitTimerLog(HBtree *p){
8977989771 );
8978089772
8978189773 sqlite3_log(SQLITE_WARNING,
89782- "hctree: slow commit v3: hwtime=%lld"
89783- "(%lld, %lld, %lld, %lld, %lld, %lld, %lld) "
89774+ "hctree: slow commit v3: ms=%lld hwtime=%lld"
8978489775 "(%s %s %s) [%s]",
89776+ (iNow - p->iCommitUsTime),
8978589777 iHwTime,
89786- (aTimer[1] ? (aTimer[1] - aTimer[0]) : 0),
89787- (aTimer[2] ? (aTimer[2] - aTimer[0]) : 0),
89788- (aTimer[3] ? (aTimer[3] - aTimer[0]) : 0),
89789- (aTimer[4] ? (aTimer[4] - aTimer[0]) : 0),
89790- (aTimer[5] ? (aTimer[5] - aTimer[0]) : 0),
89791- (aTimer[6] ? (aTimer[6] - aTimer[0]) : 0),
89792- (aTimer[7] ? (aTimer[7] - aTimer[0]) : 0),
8979389778 zMainStats,
8979489779 zDbStats,
8979589780 zFileStats,
@@ -89804,14 +89789,9 @@ static void hctCommitTimerLog(HBtree *p){
8980489789 }
8980589790}
8980689791
89807- static void hctCommitTimerSet(i64 *aTimer, int eTimer){
89808- aTimer[eTimer] = hctDbGetUs();
89809- }
89810-
8981189792#else /* HCT_ENABLE_COMMIT_TIMERS */
8981289793# define hctCommitTimerSaveStats(p)
8981389794# define hctCommitTimerLog(p)
89814- # define hctCommitTimerSet(aTimer, eTimer)
8981589795#endif
8981689796
8981789797
@@ -91481,17 +91461,13 @@ static int btreeFlushToDisk(HBtree *p){
9148191461 }
9148291462 }
9148391463
91484- hctCommitTimerSet(p->aCommitTimer, HCT_COMMIT_AFTER_WRITE_LOG);
91485-
9148691464 /* Write all the new database entries to the database. Any write/write
9148791465 ** conflicts are detected here - SQLITE_BUSY is returned in that case. */
9148891466 p->nRollbackOp = 0;
9148991467 if( rc==SQLITE_OK ){
9149091468 rc = btreeFlushData(p, 0);
9149191469 }
9149291470
91493- hctCommitTimerSet(p->aCommitTimer, HCT_COMMIT_AFTER_FLUSH_DATA);
91494-
9149591471 /* Assuming the data has been flushed to disk without error or a
9149691472 ** write/write conflict, allocate a CID and validate the transaction. */
9149791473 if( rc==SQLITE_OK ){
@@ -91537,8 +91513,6 @@ static int btreeFlushToDisk(HBtree *p){
9153791513 }
9153891514 }
9153991515
91540- hctCommitTimerSet(p->aCommitTimer, HCT_COMMIT_AFTER_VALIDATION);
91541-
9154291516 /* If conflicts have been detected, roll back the transaction */
9154391517 assert( rc!=SQLITE_BUSY );
9154491518 if( rc==SQLITE_BUSY_SNAPSHOT ){
@@ -91568,8 +91542,6 @@ static int btreeFlushToDisk(HBtree *p){
9156891542 }
9156991543 sqlite3HctDbTMapScan(p->pHctDb);
9157091544
91571- hctCommitTimerSet(p->aCommitTimer, HCT_COMMIT_AFTER_ZERO_LOG);
91572-
9157391545 return (rc==SQLITE_OK ? rcok : rc);
9157491546}
9157591547
@@ -91677,16 +91649,13 @@ static int hctreeRollbackSchema(HBtree *p, int iSavepoint){
9167791649*/
9167891650SQLITE_PRIVATE int sqlite3HctBtreeCommitPhaseTwo(Btree *pBt, int bCleanup){
9167991651 HBtree *const p = (HBtree*)pBt;
91680- const i64 nKeyOp = p->stats.nKeyOp;
9168191652 int rc = SQLITE_OK;
9168291653
9168391654 if( p->eTrans==SQLITE_TXN_ERROR ) return SQLITE_BUSY_SNAPSHOT;
9168491655
9168591656 hctCommitTimerSaveStats(p);
9168691657 if( p->eTrans==SQLITE_TXN_WRITE ){
9168791658
91688- hctCommitTimerSet(p->aCommitTimer, HCT_COMMIT_START);
91689-
9169091659 if( sqlite3HctJrnlCommitOk(p->pHctJrnl)==0 ){
9169191660 /* This case is when a straight COMMIT is run in FOLLOWER or
9169291661 ** LEADER mode. */
@@ -91705,7 +91674,6 @@ SQLITE_PRIVATE int sqlite3HctBtreeCommitPhaseTwo(Btree *pBt, int bCleanup){
9170591674
9170691675 /* Do the equivalent of RELEASE on any existing savepoints. */
9170791676 sqlite3HctTreeRelease(p->pHctTree, 0);
91708- hctCommitTimerSet(p->aCommitTimer, HCT_COMMIT_AFTER_TREE_RELEASE);
9170991677
9171091678 if( p->pHctDb ){
9171191679 rc = btreeFlushToDisk(p);
@@ -91716,13 +91684,11 @@ SQLITE_PRIVATE int sqlite3HctBtreeCommitPhaseTwo(Btree *pBt, int bCleanup){
9171691684 p->nSchemaOp = 0;
9171791685 }
9171891686 p->eTrans = SQLITE_TXN_READ;
91719- hctCommitTimerSet(p->aCommitTimer, HCT_COMMIT_AFTER_TREE_CLEAR);
9172091687 }
9172191688 }
9172291689
9172391690 if( rc==SQLITE_OK ){
9172491691 hctEndTransaction(p);
91725- hctCommitTimerSet(p->aCommitTimer, HCT_COMMIT_AFTER_END_READ);
9172691692 hctCommitTimerLog(p);
9172791693 }else{
9172891694 p->eTrans = SQLITE_TXN_ERROR;
@@ -270488,7 +270454,7 @@ static void fts5SourceIdFunc(
270488270454){
270489270455 assert( nArg==0 );
270490270456 UNUSED_PARAM2(nArg, apUnused);
270491- sqlite3_result_text(pCtx, "fts5: 2026-02-13 11:07:58 1f0cf66a7851fdb878e3d8cac13c5baba3d7c73212ea8f1a19c2f6cbccfb9e9f ", -1, SQLITE_TRANSIENT);
270457+ sqlite3_result_text(pCtx, "fts5: 2026-03-04 19:30:52 e3af311bdeb6d86480858e5084471807ec714a9f193c7bef10f0cc82f3e2d471 ", -1, SQLITE_TRANSIENT);
270492270458}
270493270459
270494270460/*
@@ -276116,6 +276082,8 @@ struct HctPManFreePg {
276116276082 i64 iTid; /* TID of transaction that freed page */
276117276083};
276118276084
276085+ #define PAGESET_FREEPGSET_MAX (4*1024)
276086+
276119276087struct HctPManFreePgSet {
276120276088 HctPManFreePg *aPg; /* Page buffer */
276121276089 int nAlloc; /* Allocated size of aPg[] */
@@ -276622,8 +276590,12 @@ static int hctPManMakeSpace(
276622276590 int rc = SQLITE_OK;
276623276591 HctPManFreePgSet *pSet = &pClient->aPgSet[bLogical];
276624276592
276593+ if( pSet->nPg>=PAGESET_FREEPGSET_MAX ){
276594+ hctPManHandback(pClient, bLogical, pClient->aPgSet[bLogical].nPg);
276595+ }
276596+
276625276597 if( (pSet->nAlloc-pSet->nPg)<nPg ){
276626- int nNew = pSet->nPg + nPg;
276598+ int nNew = pSet->nPg + MAX( nPg, 1024) ;
276627276599 int nByte = nNew * sizeof(HctPManFreePg);
276628276600 HctPManFreePg *aNew = (HctPManFreePg*)sqlite3_realloc(pSet->aPg, nByte);
276629276601
@@ -278911,6 +278883,8 @@ struct HctFileStats {
278911278883 i64 nIncrFail;
278912278884 i64 nMutex;
278913278885 i64 nMutexBlock;
278886+ i64 nGetPage;
278887+ i64 nGetPhysical;
278914278888};
278915278889
278916278890/*
@@ -278944,6 +278918,7 @@ struct HctFile {
278944278918 /* Event counters used by the hctstats virtual table */
278945278919 HctFileStats stats;
278946278920 HctFileStats savedstats;
278921+ u64 nSavedPageAlloc;
278947278922};
278948278923
278949278924static int hctLog2(int n){
@@ -280253,14 +280228,6 @@ static int hctFilePagemapGetGrow32(HctFile *pFile, u32 iSlot, u32 *piVal){
280253280228}
280254280229
280255280230
280256- static int hctFilePagemapPtr(HctFile *pFile, u32 iPg, u8 **paData){
280257- int rc = hctFileGrowMapping(pFile, 1+(iPg>>pFile->pMapping->mapShift));
280258- if( rc==SQLITE_OK ){
280259- *paData = hctPagePtr(pFile->pMapping, iPg);
280260- }
280261- return rc;
280262- }
280263-
280264280231#define HCT_GROW_MAPPING(iPg) { \
280265280232 int iGrowMappingChunk = (iPg >> pMapping->mapShift); \
280266280233 if( iGrowMappingChunk>=pMapping->nChunk ){ \
@@ -280272,6 +280239,7 @@ static int hctFilePagemapPtr(HctFile *pFile, u32 iPg, u8 **paData){
280272280239
280273280240SQLITE_PRIVATE int sqlite3HctFilePageGet(HctFile *pFile, u32 iPg, HctFilePage *pPg){
280274280241 int rc;
280242+ pFile->stats.nGetPage++;
280275280243 memset(pPg, 0, sizeof(*pPg));
280276280244 if( inject_page_failure() ){
280277280245 rc = SQLITE_IOERR_READ;
@@ -280302,6 +280270,7 @@ SQLITE_PRIVATE u32 sqlite3HctFilePageMapping(HctFile *pFile, u32 iLogical, int *
280302280270*/
280303280271SQLITE_PRIVATE int sqlite3HctFilePageGetPhysical(HctFile *pFile, u32 iPg, HctFilePage *pPg){
280304280272 int rc;
280273+ pFile->stats.nGetPhysical++;
280305280274 memset(pPg, 0, sizeof(*pPg));
280306280275 if( inject_page_failure() ){
280307280276 rc = SQLITE_IOERR_READ;
@@ -281055,6 +281024,7 @@ SQLITE_PRIVATE i64 sqlite3HctFileStats(sqlite3 *db, int iStat, const char **pzSt
281055281024}
281056281025SQLITE_PRIVATE void sqlite3HctFileSaveStats(HctFile *pFile){
281057281026 pFile->savedstats = pFile->stats;
281027+ pFile->nSavedPageAlloc = pFile->nPageAlloc;
281058281028}
281059281029
281060281030/*
@@ -281066,13 +281036,17 @@ SQLITE_PRIVATE char *sqlite3HctFileStatsString(HctFile *pFile){
281066281036 return sqlite3HctMprintf(
281067281037 "cas_attempt=%lld cas_fail=%lld "
281068281038 "incr_attempt=%lld incr_fail=%lld "
281069- "mutex=%lld mutex_block=%lld",
281039+ "mutex=%lld mutex_block=%lld "
281040+ "nPageAlloc=%lld nGetPage=%lld nGetPhysical=%lld",
281070281041 pFile->stats.nCasAttempt - pFile->savedstats.nCasAttempt,
281071281042 pFile->stats.nCasFail - pFile->savedstats.nCasFail,
281072281043 pFile->stats.nIncrAttempt - pFile->savedstats.nIncrAttempt,
281073281044 pFile->stats.nIncrFail - pFile->savedstats.nIncrFail,
281074281045 pFile->stats.nMutex - pFile->savedstats.nMutex,
281075- pFile->stats.nMutexBlock - pFile->savedstats.nMutexBlock
281046+ pFile->stats.nMutexBlock - pFile->savedstats.nMutexBlock,
281047+ pFile->nPageAlloc - pFile->nSavedPageAlloc,
281048+ pFile->stats.nGetPage - pFile->savedstats.nGetPage,
281049+ pFile->stats.nGetPhysical - pFile->savedstats.nGetPhysical
281076281050 );
281077281051}
281078281052
0 commit comments