/ Check-in [39069941]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:In lsm, attempt to unmap the database file before truncating it when disconnecting. A mapped file may not be truncated on win32.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:39069941e98605bc8c7c736819781761760ee2b83363471ceb6f19e5eb06b13a
User & Date: dan 2017-07-11 20:36:35
Context
2017-07-12
12:19
Compile cleanly with SQLITE_OMIT_UTF16. check-in: 783100b8 user: drh tags: trunk
2017-07-11
20:36
In lsm, attempt to unmap the database file before truncating it when disconnecting. A mapped file may not be truncated on win32. check-in: 39069941 user: dan tags: trunk
19:55
Simplify the way in which the database file is truncated when the last connection disconnects. Also ignore the error code from the xTruncate call - as truncating a database file is always optional. check-in: b0a49d90 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/lsm1/lsmInt.h.

   691    691   /**************************************************************************
   692    692   ** Start of functions from "lsm_file.c".
   693    693   */
   694    694   int lsmFsOpen(lsm_db *, const char *, int);
   695    695   int lsmFsOpenLog(lsm_db *, int *);
   696    696   void lsmFsCloseLog(lsm_db *);
   697    697   void lsmFsClose(FileSystem *);
          698  +
          699  +int lsmFsUnmap(FileSystem *);
   698    700   
   699    701   int lsmFsConfigure(lsm_db *db);
   700    702   
   701    703   int lsmFsBlockSize(FileSystem *);
   702    704   void lsmFsSetBlockSize(FileSystem *, int);
   703    705   int lsmFsMoveBlock(FileSystem *pFS, Segment *pSeg, int iTo, int iFrom);
   704    706   

Changes to ext/lsm1/lsm_file.c.

  1145   1145           pFix->aData += iOff;
  1146   1146         }
  1147   1147         lsmSortedRemap(pFS->pDb);
  1148   1148       }
  1149   1149       *pRc = rc;
  1150   1150     }
  1151   1151   }
         1152  +
         1153  +/*
         1154  +** If it is mapped, unmap the database file.
         1155  +*/
         1156  +int lsmFsUnmap(FileSystem *pFS){
         1157  +  int rc = LSM_OK;
         1158  +  if( pFS ){
         1159  +    rc = lsmEnvRemap(pFS->pEnv, pFS->fdDb, -1, &pFS->pMap, &pFS->nMap);
         1160  +  }
         1161  +  return rc;
         1162  +}
  1152   1163   
  1153   1164   /*
  1154   1165   ** fsync() the database file.
  1155   1166   */
  1156   1167   int lsmFsSyncDb(FileSystem *pFS, int nBlock){
  1157   1168     return lsmEnvSync(pFS->pEnv, pFS->fdDb);
  1158   1169   }

Changes to ext/lsm1/lsm_shared.c.

   308    308             if( rc==LSM_OK && bRotrans==0 ){
   309    309               lsmFsCloseAndDeleteLog(pDb->pFS);
   310    310             }
   311    311   
   312    312             /* The database may only be truncated if there exist no read-only
   313    313             ** clients - either connected or running rotrans transactions. */
   314    314             if( bReadonly==0 && bRotrans==0 ){
          315  +            lsmFsUnmap(pDb->pFS);
   315    316               dbTruncateFile(pDb);
   316    317               if( p->pFile && p->bMultiProc ){
   317    318                 lsmEnvShmUnmap(pDb->pEnv, p->pFile, 1);
   318    319               }
   319    320             }
   320    321           }
   321    322         }
................................................................................
   564    565     if( p ){
   565    566       lsm_db **ppDb;
   566    567   
   567    568       if( pDb->pShmhdr ){
   568    569         doDbDisconnect(pDb);
   569    570       }
   570    571   
          572  +    lsmFsUnmap(pDb->pFS);
   571    573       lsmMutexEnter(pDb->pEnv, p->pClientMutex);
   572    574       for(ppDb=&p->pConn; *ppDb!=pDb; ppDb=&((*ppDb)->pNext));
   573    575       *ppDb = pDb->pNext;
   574    576       dbDeferClose(pDb);
   575    577       lsmMutexLeave(pDb->pEnv, p->pClientMutex);
   576    578   
   577    579       enterGlobalMutex(pDb->pEnv);