SQLite

Check-in [2685c2b949]
Login

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

Overview
Comment:A better solution to being unable to find a unique master-journal filename: just delete an existing master-journal and reuse it.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | nx-devkit
Files: files | file ages | folders
SHA1: 2685c2b949061f18bf6a4940eac8c8148873abb6
User & Date: drh 2011-12-16 01:21:31.882
Context
2011-12-16
01:30
Call sqlite3_log() with an appropriate message if unable to find a unique master-journal filename. (check-in: e9177f7d4e user: drh tags: nx-devkit)
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)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vdbeaux.c.
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
    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|







>


>
>
>



|
<


<

|

<
<
<


|







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
    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;
    int nMainFile;

    /* Select a master journal file name */
    nMainFile = sqlite3Strlen30(zMainFile);
    zMaster = sqlite3MPrintf(db, "%s-mjXXXXXX9XX", zMainFile);
    if( zMaster==0 ) return SQLITE_NOMEM;
    do {
      u32 iRandom;
      if( retryCount++>100 ){
        sqlite3OsDelete(pVfs, zMaster, 0);

        break;
      }

      sqlite3_randomness(sizeof(iRandom), &iRandom);
      sqlite3_snprintf(13, &zMaster[nMainFile], "-mj%06X9%02X",
                               (iRandom>>8)&0xffffff, iRandom&0xff);



      /* The antipenultimate character of the master journal name must
      ** be "9" to avoid name collisions when using 8+3 filenames. */
      assert( zMaster[sqlite3Strlen30(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|