SQLite

Check-in [34a0483605]
Login

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

Overview
Comment:Make sure the antipenultimate character of master-journal filenames is a "9" in order to avoid collisions with other files in 8+3 filename mode. Also, limit the number of attempts at finding a unique master-journal filename.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | nx-devkit
Files: files | file ages | folders
SHA1: 34a0483605d36e6cf03065ed0df33fb1f7c8a272
User & Date: drh 2011-12-16 00:33:04.352
Context
2011-12-16
01:21
A better solution to being unable to find a unique master-journal filename: just delete an existing master-journal and reuse it. (check-in: 2685c2b949 user: drh tags: nx-devkit)
00:33
Make sure the antipenultimate character of master-journal filenames is a "9" in order to avoid collisions with other files in 8+3 filename mode. Also, limit the number of attempts at finding a unique master-journal filename. (check-in: 34a0483605 user: drh tags: nx-devkit)
2011-12-15
17:00
When deleting a file with the multiplexor VFS, also delete any overflow files that exist. (check-in: 3af1feaa35 user: dan tags: nx-devkit)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/util.c.
1165
1166
1167
1168
1169
1170
1171

1172
1173
1174
1175
1176
1177
1178
** do the suffix shortening regardless of URI parameter.
**
** Examples:
**
**     test.db-journal    =>   test.nal
**     test.db-wal        =>   test.wal
**     test.db-shm        =>   test.shm

*/
void sqlite3FileSuffix3(const char *zBaseFilename, char *z){
#if SQLITE_ENABLE_8_3_NAMES<2
  const char *zOk;
  zOk = sqlite3_uri_parameter(zBaseFilename, "8_3_names");
  if( zOk && sqlite3GetBoolean(zOk) )
#endif







>







1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
** do the suffix shortening regardless of URI parameter.
**
** Examples:
**
**     test.db-journal    =>   test.nal
**     test.db-wal        =>   test.wal
**     test.db-shm        =>   test.shm
**     test.db-mj7f3319fa =>   test.9fa
*/
void sqlite3FileSuffix3(const char *zBaseFilename, char *z){
#if SQLITE_ENABLE_8_3_NAMES<2
  const char *zOk;
  zOk = sqlite3_uri_parameter(zBaseFilename, "8_3_names");
  if( zOk && sqlite3GetBoolean(zOk) )
#endif
Changes to src/vdbeaux.c.
1820
1821
1822
1823
1824
1825
1826

1827
1828
1829
1830





1831
1832
1833

1834
1835
1836



1837
1838
1839
1840
1841
1842
1843
    sqlite3_vfs *pVfs = db->pVfs;
    int needSync = 0;
    char *zMaster = 0;   /* File-name for the master journal */
    char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
    sqlite3_file *pMaster = 0;
    i64 offset = 0;
    int res;


    /* Select a master journal file name */
    do {
      u32 iRandom;





      sqlite3DbFree(db, zMaster);
      sqlite3_randomness(sizeof(iRandom), &iRandom);
      zMaster = sqlite3MPrintf(db, "%s-mj%08X", zMainFile, iRandom&0x7fffffff);

      if( !zMaster ){
        return SQLITE_NOMEM;
      }



      sqlite3FileSuffix3(zMainFile, zMaster);
      rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res);
    }while( rc==SQLITE_OK && res );
    if( rc==SQLITE_OK ){
      /* Open the master journal. */
      rc = sqlite3OsOpenMalloc(pVfs, zMaster, &pMaster, 
          SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|







>




>
>
>
>
>


|
>



>
>
>







1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
    sqlite3_vfs *pVfs = db->pVfs;
    int needSync = 0;
    char *zMaster = 0;   /* File-name for the master journal */
    char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
    sqlite3_file *pMaster = 0;
    i64 offset = 0;
    int res;
    int retryCount = 0;

    /* Select a master journal file name */
    do {
      u32 iRandom;
      if( retryCount++>100 ){
        sqlite3_log(SQLITE_FULL, "cannot create a master journal filename");
        rc = SQLITE_FULL;
        break;
      }
      sqlite3DbFree(db, zMaster);
      sqlite3_randomness(sizeof(iRandom), &iRandom);
      zMaster = sqlite3MPrintf(db, "%s-mj%06X9%02X", zMainFile,
                               (iRandom>>8)&0xffffff, iRandom&0xff);
      if( !zMaster ){
        return SQLITE_NOMEM;
      }
      /* The antipenultimate character of the master journal name must
      ** be "9" to avoid name collisions when using 8+3 filenames. */
      assert( zMaster[strlen(zMaster)-3]=='9' );
      sqlite3FileSuffix3(zMainFile, zMaster);
      rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res);
    }while( rc==SQLITE_OK && res );
    if( rc==SQLITE_OK ){
      /* Open the master journal. */
      rc = sqlite3OsOpenMalloc(pVfs, zMaster, &pMaster, 
          SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|