/ Check-in [6d7f94fa]
Login

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

Overview
Comment:Change the name of SQLITE_READONLY_CANTLOCK to SQLITE_READONLY_CANTINIT.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | readonly-wal-recovery
Files: files | file ages | folders
SHA3-256: 6d7f94faa7e6de62f82bc6cac019508a9c1ffd6fa1d14f52fa93e9c06afdd32f
User & Date: drh 2017-11-08 17:32:12
Context
2017-11-08
17:51
Turns out that SQLITE_READONLY_CANTLOCK is an historical name that must be preserved. So make a new SQLITE_READLOCK_CANTINIT name instead. check-in: 04974a8b user: drh tags: readonly-wal-recovery
17:32
Change the name of SQLITE_READONLY_CANTLOCK to SQLITE_READONLY_CANTINIT. check-in: 6d7f94fa user: drh tags: readonly-wal-recovery
2017-11-07
21:25
Update an assert in wal.c. check-in: 94527b89 user: dan tags: readonly-wal-recovery
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

  1310   1310         case SQLITE_BUSY_RECOVERY:      zName = "SQLITE_BUSY_RECOVERY";     break;
  1311   1311         case SQLITE_BUSY_SNAPSHOT:      zName = "SQLITE_BUSY_SNAPSHOT";     break;
  1312   1312         case SQLITE_LOCKED:             zName = "SQLITE_LOCKED";            break;
  1313   1313         case SQLITE_LOCKED_SHAREDCACHE: zName = "SQLITE_LOCKED_SHAREDCACHE";break;
  1314   1314         case SQLITE_NOMEM:              zName = "SQLITE_NOMEM";             break;
  1315   1315         case SQLITE_READONLY:           zName = "SQLITE_READONLY";          break;
  1316   1316         case SQLITE_READONLY_RECOVERY:  zName = "SQLITE_READONLY_RECOVERY"; break;
  1317         -      case SQLITE_READONLY_CANTLOCK:  zName = "SQLITE_READONLY_CANTLOCK"; break;
         1317  +      case SQLITE_READONLY_CANTINIT:  zName = "SQLITE_READONLY_CANTINIT"; break;
  1318   1318         case SQLITE_READONLY_ROLLBACK:  zName = "SQLITE_READONLY_ROLLBACK"; break;
  1319   1319         case SQLITE_READONLY_DBMOVED:   zName = "SQLITE_READONLY_DBMOVED";  break;
  1320   1320         case SQLITE_INTERRUPT:          zName = "SQLITE_INTERRUPT";         break;
  1321   1321         case SQLITE_IOERR:              zName = "SQLITE_IOERR";             break;
  1322   1322         case SQLITE_IOERR_READ:         zName = "SQLITE_IOERR_READ";        break;
  1323   1323         case SQLITE_IOERR_SHORT_READ:   zName = "SQLITE_IOERR_SHORT_READ";  break;
  1324   1324         case SQLITE_IOERR_WRITE:        zName = "SQLITE_IOERR_WRITE";       break;

Changes to src/os_unix.c.

  4274   4274   /*
  4275   4275   ** The DMS lock has not yet been taken on shm file pShmNode. Attempt to
  4276   4276   ** take it now. Return SQLITE_OK if successful, or an SQLite error
  4277   4277   ** code otherwise.
  4278   4278   **
  4279   4279   ** If the DMS cannot be locked because this is a readonly_shm=1 
  4280   4280   ** connection and no other process already holds a lock, return
  4281         -** SQLITE_READONLY_CANTLOCK and set pShmNode->isUnlocked=1.
         4281  +** SQLITE_READONLY_CANTINIT and set pShmNode->isUnlocked=1.
  4282   4282   */
  4283   4283   static int unixLockSharedMemory(unixFile *pDbFd, unixShmNode *pShmNode){
  4284   4284     struct flock lock;
  4285   4285     int rc = SQLITE_OK;
  4286   4286   
  4287   4287     /* Use F_GETLK to determine the locks other processes are holding
  4288   4288     ** on the DMS byte. If it indicates that another process is holding
................................................................................
  4307   4307     lock.l_len = 1;
  4308   4308     lock.l_type = F_WRLCK;
  4309   4309     if( osFcntl(pShmNode->h, F_GETLK, &lock)!=0 ) {
  4310   4310       rc = SQLITE_IOERR_LOCK;
  4311   4311     }else if( lock.l_type==F_UNLCK ){
  4312   4312       if( pShmNode->isReadonly ){
  4313   4313         pShmNode->isUnlocked = 1;
  4314         -      rc = SQLITE_READONLY_CANTLOCK;
         4314  +      rc = SQLITE_READONLY_CANTINIT;
  4315   4315       }else{
  4316   4316         rc = unixShmSystemLock(pDbFd, F_WRLCK, UNIX_SHM_DMS, 1);
  4317   4317         if( rc==SQLITE_OK && robust_ftruncate(pShmNode->h, 0) ){
  4318   4318           rc = unixLogError(SQLITE_IOERR_SHMOPEN,"ftruncate",pShmNode->zFilename);
  4319   4319         }
  4320   4320       }
  4321   4321     }else if( lock.l_type==F_WRLCK ){
................................................................................
  4446   4446         /* If this process is running as root, make sure that the SHM file
  4447   4447         ** is owned by the same user that owns the original database.  Otherwise,
  4448   4448         ** the original owner will not be able to connect.
  4449   4449         */
  4450   4450         robustFchown(pShmNode->h, sStat.st_uid, sStat.st_gid);
  4451   4451   
  4452   4452         rc = unixLockSharedMemory(pDbFd, pShmNode);
  4453         -      if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTLOCK ) goto shm_open_err;
         4453  +      if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err;
  4454   4454       }
  4455   4455     }
  4456   4456   
  4457   4457     /* Make the new connection a child of the unixShmNode */
  4458   4458     p->pShmNode = pShmNode;
  4459   4459   #ifdef SQLITE_DEBUG
  4460   4460     p->id = pShmNode->nextShmId++;

Changes to src/sqlite.h.in.

   507    507   #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
   508    508   #define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
   509    509   #define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
   510    510   #define SQLITE_CANTOPEN_CONVPATH       (SQLITE_CANTOPEN | (4<<8))
   511    511   #define SQLITE_CANTOPEN_DIRTYWAL       (SQLITE_CANTOPEN | (5<<8))
   512    512   #define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
   513    513   #define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
   514         -#define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
          514  +#define SQLITE_READONLY_CANTINIT       (SQLITE_READONLY | (2<<8))
   515    515   #define SQLITE_READONLY_ROLLBACK       (SQLITE_READONLY | (3<<8))
   516    516   #define SQLITE_READONLY_DBMOVED        (SQLITE_READONLY | (4<<8))
   517    517   #define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
   518    518   #define SQLITE_CONSTRAINT_CHECK        (SQLITE_CONSTRAINT | (1<<8))
   519    519   #define SQLITE_CONSTRAINT_COMMITHOOK   (SQLITE_CONSTRAINT | (2<<8))
   520    520   #define SQLITE_CONSTRAINT_FOREIGNKEY   (SQLITE_CONSTRAINT | (3<<8))
   521    521   #define SQLITE_CONSTRAINT_FUNCTION     (SQLITE_CONSTRAINT | (4<<8))

Changes to src/wal.c.

  2095   2095     volatile u32 *page0;            /* Chunk of wal-index containing header */
  2096   2096   
  2097   2097     /* Ensure that page 0 of the wal-index (the page that contains the 
  2098   2098     ** wal-index header) is mapped. Return early if an error occurs here.
  2099   2099     */
  2100   2100     assert( pChanged );
  2101   2101     rc = walIndexPage(pWal, 0, &page0);
  2102         -  if( rc==SQLITE_READONLY_CANTLOCK ){
         2102  +  if( rc==SQLITE_READONLY_CANTINIT ){
  2103   2103       assert( page0==0 && pWal->writeLock==0 );
  2104   2104       pWal->bUnlocked = 1;
  2105   2105       pWal->exclusiveMode = WAL_HEAPMEMORY_MODE;
  2106   2106       *pChanged = 1;
  2107   2107     }else
  2108   2108     if( rc!=SQLITE_OK ){
  2109   2109       return rc;
................................................................................
  2215   2215     ** from taking place. But it does not prevent the wal from being wrapped
  2216   2216     ** if a checkpoint has already taken place. This means that if another
  2217   2217     ** client is connected at this point, it may have already checkpointed 
  2218   2218     ** the entire wal. In that case it would not be safe to continue with
  2219   2219     ** the unlocked transaction, as the other client may overwrite wal 
  2220   2220     ** frames that this client is still using.  */
  2221   2221     rc = sqlite3OsShmMap(pWal->pDbFd, 0, WALINDEX_PGSZ, 0, &pDummy);
  2222         -  if( rc!=SQLITE_READONLY_CANTLOCK ){
         2222  +  if( rc!=SQLITE_READONLY_CANTINIT ){
  2223   2223       assert( rc!=SQLITE_OK );
  2224   2224       rc = (rc==SQLITE_READONLY ? WAL_RETRY : rc);
  2225   2225       goto begin_unlocked_out;
  2226   2226     }
  2227   2227   
  2228   2228     memcpy(&pWal->hdr, (void*)walIndexHdr(pWal), sizeof(WalIndexHdr));
  2229   2229     rc = sqlite3OsFileSize(pWal->pWalFd, &szWal);
................................................................................
  2505   2505         }else if( rc!=SQLITE_BUSY ){
  2506   2506           return rc;
  2507   2507         }
  2508   2508       }
  2509   2509     }
  2510   2510     if( mxI==0 ){
  2511   2511       assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 );
  2512         -    return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTLOCK;
         2512  +    return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTINIT;
  2513   2513     }
  2514   2514   
  2515   2515     rc = walLockShared(pWal, WAL_READ_LOCK(mxI));
  2516   2516     if( rc ){
  2517   2517       return rc==SQLITE_BUSY ? WAL_RETRY : rc;
  2518   2518     }
  2519   2519     /* Now that the read-lock has been obtained, check that neither the