]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Allocate a buffer containing the full path-name to the associated WAL file when a...
authordan <dan@noemail.net>
Mon, 5 Jul 2010 19:03:35 +0000 (19:03 +0000)
committerdan <dan@noemail.net>
Mon, 5 Jul 2010 19:03:35 +0000 (19:03 +0000)
FossilOrigin-Name: 3053a4ad15343a56efa430503797b77bb6d1e770

manifest
manifest.uuid
src/pager.c
src/wal.c

index 4a70add3a237a76e12b1e54e7e04a94099992948..09e5cf6d6a81250775b4cd91d0eda4479b841095 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,5 @@
------BEGIN PGP SIGNED MESSAGE-----
-Hash: SHA1
-
-C When\srolling\sback\spage\s1\sfrom\sa\sjournal,\srestore\sthe\s"nReserve"\ssetting\nin\scase\sit\shas\sbeen\scorrupted\sby\sa\sprior\scrash.
-D 2010-07-05T17:43:32
+C Allocate\sa\sbuffer\scontaining\sthe\sfull\spath-name\sto\sthe\sassociated\sWAL\sfile\swhen\sa\spager\sis\screated.\sThis\ssaves\shaving\sto\sconstruct\sa\snew\sbuffer\seach\stime\sa\snew\sread-transaction\sis\sopened\sand\sSQLite\schecks\sfor\sthe\sexistance\sof\sa\sWAL\sfile.
+D 2010-07-05T19:03:36
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -159,7 +156,7 @@ F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
 F src/os_os2.c 665876d5eec7585226b0a1cf5e18098de2b2da19
 F src/os_unix.c c6112f0ae34f23ae5ca0189a685e084befbdcf26
 F src/os_win.c 883caa09d8cf7c4dfdef6eba6930466cb8a8275c
-F src/pager.c 14ec8ea3d27cf4c8b7b6a6139c150b50dd28df3e
+F src/pager.c d6454d37992882904ac0cdc1fd12887d1eecf434
 F src/pager.h 879fdde5a102d2f21a3135d6f647530b21c2796c
 F src/parse.y ace5c7a125d9f2a410e431ee3209034105045f7e
 F src/pcache.c 1e9aa2dbc0845b52e1b51cc39753b6d1e041cb07
@@ -229,7 +226,7 @@ F src/vdbeblob.c 258a6010ba7a82b72b327fb24c55790655689256
 F src/vdbemem.c 5e579abf6532001dfbee0e640dc34eae897a9807
 F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
 F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
-F src/wal.c 737408e8e6f2386e6318cd01dfaa534c45ffe3ed
+F src/wal.c 585f37237e2621ddd32676bc577b995856267ac2
 F src/wal.h 906c85760598b18584921fe08008435aa4eeeeb2
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
 F src/where.c 926c83c6394e132a1c62b6b12ceeba7d55a34c19
@@ -833,14 +830,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P ea80b21c881fabaec1da788588c35c6c9782dcbd
-R 5de919a3a55f2a8c35bbb58047acd345
-U drh
-Z aa2a677064258d9e6322a258f0100e48
------BEGIN PGP SIGNATURE-----
-Version: GnuPG v1.4.6 (GNU/Linux)
-
-iD8DBQFMMhnIoxKgR168RlERAv13AJ0RezR75fN7II4WYQ+k2k88YWRNwgCeOLx/
-tAjj2vuEc4/BCzTdXBrdXV8=
-=hcXV
------END PGP SIGNATURE-----
+P c0d124da88e84e68679c2f3f4b2b35c03aecc916
+R cd5e60ea3770ef2152f9ff5f3bc6b29a
+U dan
+Z 3d489137870470f4068fe7324b7dadaf
index 04aaee85d4a89415f178608f81435f5b4bb33ccc..7c5571c81fbdd3daef8784a186da3cf662508c30 100644 (file)
@@ -1 +1 @@
-c0d124da88e84e68679c2f3f4b2b35c03aecc916
\ No newline at end of file
+3053a4ad15343a56efa430503797b77bb6d1e770
\ No newline at end of file
index 038a87fd7632073796b1164a5d51b6610b8d27b1..0f634dd382669a907b3517eed30d8f63cc291b41 100644 (file)
@@ -407,6 +407,7 @@ struct Pager {
   sqlite3_backup *pBackup;    /* Pointer to list of ongoing backup processes */
 #ifndef SQLITE_OMIT_WAL
   Wal *pWal;                  /* Write-ahead log used by "journal_mode=wal" */
+  char *zWal;                 /* File name for write-ahead log */
 #endif
 };
 
@@ -2452,19 +2453,13 @@ static int pagerBeginReadTransaction(Pager *pPager){
 */
 static int pagerCheckForOrDeleteWAL(Pager *pPager, int *pExists){
   int rc;                         /* Return code */
-  char *zWal;                     /* Name of the WAL file */
+  char *zWal = pPager->zWal;      /* Name of the WAL file */
 
   assert( !pPager->tempFile );
-  zWal = sqlite3_mprintf("%s-wal", pPager->zFilename);
-  if( !zWal ){
-    rc = SQLITE_NOMEM;
+  if( pExists ){
+    rc = sqlite3OsAccess(pPager->pVfs, zWal, SQLITE_ACCESS_EXISTS, pExists);
   }else{
-    if( pExists ){
-      rc = sqlite3OsAccess(pPager->pVfs, zWal, SQLITE_ACCESS_EXISTS, pExists);
-    }else{
-      rc = sqlite3OsDelete(pPager->pVfs, zWal, 0);
-    }
-    sqlite3_free(zWal);
+    rc = sqlite3OsDelete(pPager->pVfs, zWal, 0);
   }
   return rc;
 }
@@ -3765,6 +3760,9 @@ int sqlite3PagerOpen(
     journalFileSize * 2 +          /* The two journal files */ 
     nPathname + 1 +                /* zFilename */
     nPathname + 8 + 1              /* zJournal */
+#ifndef SQLITE_OMIT_WAL
+    + nPathname + 4 + 1              /* zWal */
+#endif
   );
   assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
   if( !pPtr ){
@@ -3785,7 +3783,16 @@ int sqlite3PagerOpen(
     memcpy(pPager->zFilename, zPathname, nPathname);
     memcpy(pPager->zJournal, zPathname, nPathname);
     memcpy(&pPager->zJournal[nPathname], "-journal", 8);
-    if( pPager->zFilename[0]==0 ) pPager->zJournal[0] = 0;
+    if( pPager->zFilename[0]==0 ){
+      pPager->zJournal[0] = 0;
+    }
+#ifndef SQLITE_OMIT_WAL
+    else{
+      pPager->zWal = &pPager->zJournal[nPathname+8+1];
+      memcpy(pPager->zWal, zPathname, nPathname);
+      memcpy(&pPager->zWal[nPathname], "-wal", 4);
+    }
+#endif
     sqlite3_free(zPathname);
   }
   pPager->pVfs = pVfs;
@@ -6078,7 +6085,7 @@ int sqlite3PagerOpenWal(
     ** return an error code.
     */
     rc = sqlite3WalOpen(pPager->pVfs, pPager->fd,
-                        pPager->zFilename, &pPager->pWal);
+                        pPager->zWal, &pPager->pWal);
     if( rc==SQLITE_OK ){
       pPager->journalMode = PAGER_JOURNALMODE_WAL;
     }
@@ -6115,7 +6122,7 @@ int sqlite3PagerCloseWal(Pager *pPager){
     }
     if( rc==SQLITE_OK && logexists ){
       rc = sqlite3WalOpen(pPager->pVfs, pPager->fd,
-                          pPager->zFilename, &pPager->pWal);
+                          pPager->zWal, &pPager->pWal);
     }
   }
     
index 1c0d2ddc81c77cff9c73ef80d63916f9a96792b4..3e799d20602da30c0307ff61c298849545ef39c0 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -417,7 +417,7 @@ struct Wal {
   u8 writeLock;              /* True if in a write transaction */
   u8 ckptLock;               /* True if holding a checkpoint lock */
   WalIndexHdr hdr;           /* Wal-index header for current transaction */
-  char *zWalName;            /* Name of WAL file */
+  const char *zWalName;      /* Name of WAL file */
   u32 nCkpt;                 /* Checkpoint sequence counter in the wal-header */
 #ifdef SQLITE_DEBUG
   u8 lockError;              /* True if a locking error has occurred */
@@ -1172,8 +1172,9 @@ static void walIndexClose(Wal *pWal, int isDelete){
 }
 
 /* 
-** Open a connection to the WAL file associated with database zDbName.
-** The database file must already be opened on connection pDbFd.
+** Open a connection to the WAL file zWalName. The database file must 
+** already be opened on connection pDbFd. The buffer that zWalName points
+** to must remain valid for the lifetime of the returned Wal* handle.
 **
 ** A SHARED lock should be held on the database file when this function
 ** is called. The purpose of this SHARED lock is to prevent any other
@@ -1188,16 +1189,14 @@ static void walIndexClose(Wal *pWal, int isDelete){
 int sqlite3WalOpen(
   sqlite3_vfs *pVfs,              /* vfs module to open wal and wal-index */
   sqlite3_file *pDbFd,            /* The open database file */
-  const char *zDbName,            /* Name of the database file */
+  const char *zWalName,           /* Name of the WAL file */
   Wal **ppWal                     /* OUT: Allocated Wal handle */
 ){
   int rc;                         /* Return Code */
   Wal *pRet;                      /* Object to allocate and return */
   int flags;                      /* Flags passed to OsOpen() */
-  char *zWal;                     /* Name of write-ahead log file */
-  int nWal;                       /* Length of zWal in bytes */
 
-  assert( zDbName && zDbName[0] );
+  assert( zWalName && zWalName[0] );
   assert( pDbFd );
 
   /* In the amalgamation, the os_unix.c and os_win.c source files come before
@@ -1214,8 +1213,7 @@ int sqlite3WalOpen(
 
   /* Allocate an instance of struct Wal to return. */
   *ppWal = 0;
-  nWal = sqlite3Strlen30(zDbName) + 5;
-  pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile + nWal);
+  pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile);
   if( !pRet ){
     return SQLITE_NOMEM;
   }
@@ -1225,15 +1223,14 @@ int sqlite3WalOpen(
   pRet->pDbFd = pDbFd;
   pRet->readLock = -1;
   sqlite3_randomness(8, &pRet->hdr.aSalt);
-  pRet->zWalName = zWal = pVfs->szOsFile + (char*)pRet->pWalFd;
-  sqlite3_snprintf(nWal, zWal, "%s-wal", zDbName);
+  pRet->zWalName = zWalName;
   rc = sqlite3OsShmOpen(pDbFd);
 
   /* Open file handle on the write-ahead log file. */
   if( rc==SQLITE_OK ){
     pRet->isWIndexOpen = 1;
     flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_JOURNAL);
-    rc = sqlite3OsOpen(pVfs, zWal, pRet->pWalFd, flags, &flags);
+    rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
   }
 
   if( rc!=SQLITE_OK ){