]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Change the SHM interface so that it does not take the name of the shared
authordrh <drh@noemail.net>
Sat, 1 May 2010 20:17:30 +0000 (20:17 +0000)
committerdrh <drh@noemail.net>
Sat, 1 May 2010 20:17:30 +0000 (20:17 +0000)
object but rather the name of the WAL file and derives its own name from
that.  Remove the xShmDelete method from the VFS and replace it with a
delete flag on xShmClose.

FossilOrigin-Name: 94dea5f9c11a68564220cec76ac3fae2ba90e907

manifest
manifest.uuid
src/os_unix.c
src/sqlite.h.in
src/test_devsym.c
src/wal.c

index 0679f724b6aa4673b698d74d422375c8c595ae2e..cd86dfff2495e156b8f8cdbd0992770d393f0809 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,8 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-C Remove\sthe\sxShmPush\sand\sxShmPull\smethods\sfrom\sthe\sVFS.
-D 2010-05-01T18:23:09
+C Change\sthe\sSHM\sinterface\sso\sthat\sit\sdoes\snot\stake\sthe\sname\sof\sthe\sshared\nobject\sbut\srather\sthe\sname\sof\sthe\sWAL\sfile\sand\sderives\sits\sown\sname\sfrom\nthat.\s\sRemove\sthe\sxShmDelete\smethod\sfrom\sthe\sVFS\sand\sreplace\sit\swith\sa\ndelete\sflag\son\sxShmClose.
+D 2010-05-01T20:17:31
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -153,7 +153,7 @@ F src/os.c 8bc63cf91e9802e2b807198e54e50227fa889306
 F src/os.h 534b082c3cb349ad05fa6fa0b06087e022af282c
 F src/os_common.h 0d6ee583b6ee3185eb9d951f890c6dd03021a08d
 F src/os_os2.c 8ad77a418630d7dee91d1bb04f79c2096301d3a0
-F src/os_unix.c d003631afe10f2cbbf0f4eb4ea72122e0522bbc7
+F src/os_unix.c 5c821e4eb04093102d901c22f40341bc1d30aef0
 F src/os_win.c a8fc01d8483be472e495793c01064fd87e56a5c1
 F src/pager.c e9c7fe979b32a3c5bf4216d8fbe1cf8beff8a1b8
 F src/pager.h 934b598583a9d936bb13c37d62a2fe68ac48781c
@@ -169,7 +169,7 @@ F src/resolve.c ac5f1a713cd1ae77f08b83cc69581e11bf5ae6f9
 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
 F src/select.c c03d8a0565febcde8c6a12c5d77d065fddae889b
 F src/shell.c c40427c7245535a04a9cb4a417b6cc05c022e6a4
-F src/sqlite.h.in fdf272c7bb095633d3f5f916cf7384c4faa505e5
+F src/sqlite.h.in 50df638fd31ae342d280582af8fc9d232b588dfe
 F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
 F src/sqliteInt.h 3eb613c8ba7f5159be0acf3fc148d41ec49add86
 F src/sqliteLimit.h 3afab2291762b5d09ae20c18feb8e9fa935a60a6
@@ -191,7 +191,7 @@ F src/test_backup.c c129c91127e9b46e335715ae2e75756e25ba27de
 F src/test_btree.c 47cd771250f09cdc6e12dda5bc71bc0b3abc96e2
 F src/test_config.c 6210f501d358bde619ae761f06f123529c6ba24f
 F src/test_demovfs.c da81a5f7785bb352bda7911c332a983ec4f17f27
-F src/test_devsym.c c05024cd179603181cde66d0ff83ce81e146f6de
+F src/test_devsym.c 84b80966ee2aa72fdd0b42eaa90406478f390b03
 F src/test_func.c 13b582345fb1185a93e46c53310fae8547dcce20
 F src/test_hexio.c 1237f000ec7a491009b1233f5c626ea71bce1ea2
 F src/test_init.c 5d624ffd0409d424cf9adbfe1f056b200270077c
@@ -224,7 +224,7 @@ F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e
 F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
 F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
 F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
-F src/wal.c 4a9b7fb028059992dfe51d23f0ced78064459c84
+F src/wal.c dadd533e0103883f72bf541eaf1ef34adb4e3c99
 F src/wal.h d6d4a6809151e30bed5b01dd05cf27858f5a7bc8
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
 F src/where.c 75fee9e255b62f773fcadd1d1f25b6f63ac7a356
@@ -811,14 +811,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 6af2dca75b8139134ea394c1d71aefc6523f02e9
-R 9c99ea4eb3e50a401439b06a40f3fab6
+P 69e07fdbde5054593de948b76dfac157cf5d4058
+R c9705329895ad0e28623e29f2274d0f1
 U drh
-Z cd290cf28dda9654fd31e687004b2a61
+Z 6445a2aee9bd8de55a45628ec7b23c47
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (GNU/Linux)
 
-iD8DBQFL3HGQoxKgR168RlERAlVgAJ49vhn/g4iu17//PQ8uRvfsTGbduwCfWA3t
-4QBB9V7wP5NNoershsjx378=
-=2IGM
+iD8DBQFL3IxeoxKgR168RlERAtmWAJ9fbAccfEA031KC3xWSzcIzuGnUqQCfVHJO
+hXR2b742paRdI5uwLVma/eQ=
+=uRJQ
 -----END PGP SIGNATURE-----
index ee21ebcc71aa8ae8cec2c274060ce2b7992b07ef..d26027c4404be04ac70d492e4362db7488a68d4f 100644 (file)
@@ -1 +1 @@
-69e07fdbde5054593de948b76dfac157cf5d4058
\ No newline at end of file
+94dea5f9c11a68564220cec76ac3fae2ba90e907
\ No newline at end of file
index 314ad9dd77bd68d611df0e0da85206e074d1ea8f..986963a1842a83caddac29eafa02ffa4de93d06b 100644 (file)
@@ -4923,7 +4923,15 @@ static void unixShmPurge(void){
 }
 
 /*
-** Open a shared-memory area.  This implementation uses mmapped files.
+** Open a shared-memory area.  This particular implementation uses
+** mmapped files.
+**
+** zName is a filename used to identify the shared-memory area.  The
+** implementation does not (and perhaps should not) use this name
+** directly, but rather use it as a template for finding an appropriate
+** name for the shared-memory storage.  In this implementation, the
+** string "-index" is appended to zName and used as the name of the
+** mmapped file.
 **
 ** When opening a new shared-memory file, if no other instances of that
 ** file are currently open, in this process or in other processes, then
@@ -4931,25 +4939,38 @@ static void unixShmPurge(void){
 */
 static int unixShmOpen(
   sqlite3_vfs *pVfs,    /* The VFS */
-  const char *zName,    /* Name of file to mmap */
+  const char *zName,    /* Base name of file to mmap */
   sqlite3_shm **pShm    /* Write the unixShm object created here */
 ){
   struct unixShm *p = 0;             /* The connection to be opened */
   struct unixShmFile *pFile = 0;     /* The underlying mmapped file */
   int rc;                            /* Result code */
   struct unixFileId fid;             /* Unix file identifier */
+  struct unixShmFile *pNew;          /* Newly allocated pFile */
   struct stat sStat;                 /* Result from stat() an fstat() */
+  int nName;                         /* Size of zName in bytes */
 
-  /* Allocate space for the new sqlite3_shm object */
+  /* Allocate space for the new sqlite3_shm object.  Also speculatively
+  ** allocate space for a new unixShmFile and filename.
+  */
   p = sqlite3_malloc( sizeof(*p) );
   if( p==0 ) return SQLITE_NOMEM;
   memset(p, 0, sizeof(*p));
+  nName = strlen(zName);
+  pNew = sqlite3_malloc( sizeof(*pFile) + nName + 10 );
+  if( pNew==0 ){
+    rc = SQLITE_NOMEM;
+    goto shm_open_err;
+  }
+  memset(pNew, 0, sizeof(*pNew));
+  pNew->zFilename = (char*)&pNew[1];
+  sqlite3_snprintf(nName+10, pNew->zFilename, "%s-index", zName);
 
   /* Look to see if there is an existing unixShmFile that can be used.
   ** If no matching unixShmFile currently exists, create a new one.
   */
   unixEnterMutex();
-  rc = stat(zName, &sStat);
+  rc = stat(pNew->zFilename, &sStat);
   if( rc==0 ){
     memset(&fid, 0, sizeof(fid));
     fid.dev = sStat.st_dev;
@@ -4958,16 +4979,11 @@ static int unixShmOpen(
       if( memcmp(&pFile->fid, &fid, sizeof(fid))==0 ) break;
     }
   }
-  if( pFile==0 ){
-    int nName = strlen(zName);
-    pFile = sqlite3_malloc( sizeof(*pFile) + nName + 1 );
-    if( pFile==0 ){
-      rc = SQLITE_NOMEM;
-      goto shm_open_err;
-    }
-    memset(pFile, 0, sizeof(*pFile));
-    pFile->zFilename = (char*)&pFile[1];
-    memcpy(pFile->zFilename, zName, nName+1);
+  if( pFile ){
+    sqlite3_free(pNew);
+  }else{
+    pFile = pNew;
+    pNew = 0;
     pFile->h = -1;
     pFile->pNext = unixShmFileList;
     unixShmFileList = pFile;
@@ -4983,7 +4999,7 @@ static int unixShmOpen(
       goto shm_open_err;
     }
 
-    pFile->h = open(zName, O_RDWR|O_CREAT, 0664);
+    pFile->h = open(pFile->zFilename, O_RDWR|O_CREAT, 0664);
     if( pFile->h<0 ){
       rc = SQLITE_CANTOPEN_BKPT;
       goto shm_open_err;
@@ -5033,15 +5049,17 @@ shm_open_err:
   unixShmPurge();
   sqlite3_free(p);
   sqlite3_free(pFile);
+  sqlite3_free(pNew);
   *pShm = 0;
   unixLeaveMutex();
   return rc;
 }
 
 /*
-** Close a connectioon to shared-memory.
+** Close a connection to shared-memory.  Delete the underlying 
+** storage if deleteFlag is true.
 */
-static int unixShmClose(sqlite3_shm *pSharedMem){
+static int unixShmClose(sqlite3_shm *pSharedMem, int deleteFlag){
   unixShm *p;            /* The connection to be closed */
   unixShmFile *pFile;    /* The underlying shared-memory file */
   unixShm **pp;          /* For looping over sibling connections */
@@ -5069,6 +5087,7 @@ static int unixShmClose(sqlite3_shm *pSharedMem){
   assert( pFile->nRef>0 );
   pFile->nRef--;
   if( pFile->nRef==0 ){
+    if( deleteFlag ) unlink(pFile->zFilename);
     unixShmPurge();
   }
   unixLeaveMutex();
@@ -5348,13 +5367,6 @@ static int unixShmLock(
   return rc;
 }
 
-/*
-** Delete a shared-memory segment from the system.
-*/
-static int unixShmDelete(sqlite3_vfs *pVfs, const char *zName){
-  return pVfs->xDelete(pVfs, zName, 0);
-}
-
 #else
 # define unixShmOpen    0
 # define unixShmSize    0
@@ -5362,7 +5374,6 @@ static int unixShmDelete(sqlite3_vfs *pVfs, const char *zName){
 # define unixShmRelease 0
 # define unixShmLock    0
 # define unixShmClose   0
-# define unixShmDelete  0
 #endif /* #ifndef SQLITE_OMIT_WAL */
 
 /*
@@ -6589,7 +6600,6 @@ int sqlite3_os_init(void){
     unixShmRelease,       /* xShmRelease */                 \
     unixShmLock,          /* xShmLock */                    \
     unixShmClose,         /* xShmClose */                   \
-    unixShmDelete,        /* xShmDelete */                  \
     0,                    /* xRename */                     \
     0,                    /* xCurrentTimeInt64 */           \
   }
index 175141227fcf3a84e647bc1895fd8cd10a20cbe9..60984d6e57efc100cf88c72897d68de2f7ba903f 100644 (file)
@@ -848,8 +848,7 @@ struct sqlite3_vfs {
   int (*xShmGet)(sqlite3_shm*, int reqMapSize, int *pMapSize, void**);
   int (*xShmRelease)(sqlite3_shm*);
   int (*xShmLock)(sqlite3_shm*, int desiredLock, int *gotLock);
-  int (*xShmClose)(sqlite3_shm*);
-  int (*xShmDelete)(sqlite3_vfs*, const char *zName);
+  int (*xShmClose)(sqlite3_shm*, int deleteFlag);
   int (*xRename)(sqlite3_vfs*, const char *zOld, const char *zNew, int dirSync);
   int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
   /*
index dff7b98803193f5d4043938f49dcfa7353b93fd9..6420731077b82409b8613ae6422a41ff0ebfa84b 100644 (file)
@@ -73,8 +73,7 @@ static int devsymShmSize(sqlite3_shm *, int , int *);
 static int devsymShmGet(sqlite3_shm *, int , int *, void **);
 static int devsymShmRelease(sqlite3_shm *);
 static int devsymShmLock(sqlite3_shm *, int , int *);
-static int devsymShmClose(sqlite3_shm *);
-static int devsymShmDelete(sqlite3_vfs *, const char *);
+static int devsymShmClose(sqlite3_shm *, int);
 
 static sqlite3_vfs devsym_vfs = {
   2,                     /* iVersion */
@@ -110,7 +109,6 @@ static sqlite3_vfs devsym_vfs = {
   0,
   devsymShmLock,
   devsymShmClose,
-  devsymShmDelete,
   0,
   0,
 };
@@ -378,11 +376,8 @@ static int devsymShmRelease(sqlite3_shm *p){
 static int devsymShmLock(sqlite3_shm *p, int desiredLock, int *gotLock){
   return g.pVfs->xShmLock(p, desiredLock, gotLock);
 }
-static int devsymShmClose(sqlite3_shm *p){
-  return g.pVfs->xShmClose(p);
-}
-static int devsymShmDelete(sqlite3_vfs *pVfs, const char *zName){
-  return g.pVfs->xShmDelete(g.pVfs, zName);
+static int devsymShmClose(sqlite3_shm *p, int deleteFlag){
+  return g.pVfs->xShmClose(p, deleteFlag);
 }
 
 /*
@@ -400,7 +395,6 @@ void devsym_register(int iDeviceChar, int iSectorSize){
     devsym_vfs.xShmRelease = (g.pVfs->xShmRelease ? devsymShmRelease : 0);
     devsym_vfs.xShmLock = (g.pVfs->xShmLock ? devsymShmLock : 0);
     devsym_vfs.xShmClose = (g.pVfs->xShmClose ? devsymShmClose : 0);
-    devsym_vfs.xShmDelete = (g.pVfs->xShmDelete ? devsymShmDelete : 0);
     sqlite3_vfs_register(&devsym_vfs, 0);
   }
   if( iDeviceChar>=0 ){
index 146675ad6b0519f66a496f9c97eec25286353ba2..071521001fa3e7d861ca1f28fc414e3a48f03910 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -133,6 +133,7 @@ struct Wal {
   u8 lockState;              /* SQLITE_SHM_xxxx constant showing lock state */
   u8 readerType;             /* SQLITE_SHM_READ or SQLITE_SHM_READ_FULL */
   WalIndexHdr hdr;           /* Wal-index for current snapshot */
+  char *zName;               /* Name of underlying storage */
 };
 
 
@@ -590,24 +591,23 @@ int sqlite3WalOpen(
   /* Allocate an instance of struct Wal to return. */
   *ppWal = 0;
   nWal = strlen(zDb);
-  pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile + nWal+11);
+  pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile + nWal+5);
   if( !pRet ) goto wal_open_out;
   pRet->pVfs = pVfs;
   pRet->pFd = (sqlite3_file *)&pRet[1];
-  zWal = pVfs->szOsFile + (char*)pRet->pFd;
-  sqlite3_snprintf(nWal+11, zWal, "%s-wal-index", zDb);
+  pRet->zName = zWal = pVfs->szOsFile + (char*)pRet->pFd;
+  sqlite3_snprintf(nWal+5, zWal, "%s-wal", zDb);
   rc = pVfs->xShmOpen(pVfs, zWal, &pRet->pWIndex);
   if( rc ) goto wal_open_out;
 
   /* Open file handle on the write-ahead log file. */
-  zWal[nWal+4] = 0;
   flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_JOURNAL);
   rc = sqlite3OsOpen(pVfs, zWal, pRet->pFd, flags, &flags);
 
 wal_open_out:
   if( rc!=SQLITE_OK ){
     if( pRet ){
-      pVfs->xShmClose(pRet->pWIndex);
+      pVfs->xShmClose(pRet->pWIndex, 0);
       sqlite3OsClose(pRet->pFd);
       sqlite3_free(pRet);
     }
@@ -805,15 +805,10 @@ int sqlite3WalClose(
       walIndexUnmap(pWal);
     }
 
-    pWal->pVfs->xShmClose(pWal->pWIndex);
+    pWal->pVfs->xShmClose(pWal->pWIndex, isDelete);
     sqlite3OsClose(pWal->pFd);
     if( isDelete ){
-      int nWal;
-      char *zWal = &((char *)pWal->pFd)[pWal->pVfs->szOsFile];
-      sqlite3OsDelete(pWal->pVfs, zWal, 0);
-      nWal = sqlite3Strlen30(zWal);
-      memcpy(&zWal[nWal], "-index", 7);
-      pWal->pVfs->xShmDelete(pWal->pVfs, zWal);
+      sqlite3OsDelete(pWal->pVfs, pWal->zName, 0);
     }
     sqlite3_free(pWal);
   }