1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Optionally support shared-memory in /dev/shm or other tmpfs directory

using an unsupported compile-time option.

FossilOrigin-Name: 534aab837e5a34fd58963ab2b505bfbb9da2e8ee
This commit is contained in:
drh
2010-07-15 18:32:40 +00:00
parent 1e5de5a13d
commit a4ced195db
3 changed files with 52 additions and 25 deletions

View File

@@ -1,5 +1,8 @@
C Changes\sto\swal.c\sso\sthat\sSQLite\scan\sread\seven\sif\sthe\sWAL\sfile\sis\sopened\sread-only,\sprovided\sthe\swal-index\s(shm\sfile)\sis\sopened\sread/write. -----BEGIN PGP SIGNED MESSAGE-----
D 2010-07-15T18:20:54 Hash: SHA1
C Optionally\ssupport\sshared-memory\sin\s/dev/shm\sor\sother\stmpfs\sdirectory\nusing\san\sunsupported\scompile-time\soption.
D 2010-07-15T18:32:41
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -154,7 +157,7 @@ F src/os.c 60178f518c4d6c0dcb59f7292232281d7bea2dcf
F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9 F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9
F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
F src/os_os2.c 665876d5eec7585226b0a1cf5e18098de2b2da19 F src/os_os2.c 665876d5eec7585226b0a1cf5e18098de2b2da19
F src/os_unix.c 73cce1696c0c9e27a6277946b016e4f2077e365e F src/os_unix.c d27404c02d3947737f8650ca4586afa7c1bec32a
F src/os_win.c 61734aad7f50b28f3c76eb4b19b63472f6d825d9 F src/os_win.c 61734aad7f50b28f3c76eb4b19b63472f6d825d9
F src/pager.c 78ca1e1f3315c8227431c403c04d791dccf242fb F src/pager.c 78ca1e1f3315c8227431c403c04d791dccf242fb
F src/pager.h 879fdde5a102d2f21a3135d6f647530b21c2796c F src/pager.h 879fdde5a102d2f21a3135d6f647530b21c2796c
@@ -836,7 +839,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 75f5354876c4300a8e53fe551dc837dd383d1e38 P 932d19da73c9673cdd4cc01289b17761c23d23cb
R 5fdef461b56aef5e86f35d4620ab20d6 R fdcb07e29996e92060dad2eee68d833c
U dan U drh
Z 679f6331e7be3f40e18fcb4456a4e594 Z 26a418d4204c9feaabc8860a4e746939
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFMP1RMoxKgR168RlERAhh6AJ4umgQHctPd2gEiJRrgEectm89sNQCZAbaB
OhN8MrDeGSxCC/JtQI6sM68=
=f3eu
-----END PGP SIGNATURE-----

View File

@@ -1 +1 @@
932d19da73c9673cdd4cc01289b17761c23d23cb 534aab837e5a34fd58963ab2b505bfbb9da2e8ee

View File

@@ -3282,13 +3282,22 @@ static void unixShmPurge(unixFile *pFd){
** as the open database file and has the same name as the open database ** as the open database file and has the same name as the open database
** file with the "-shm" suffix added. For example, if the database file ** file with the "-shm" suffix added. For example, if the database file
** is "/home/user1/config.db" then the file that is created and mmapped ** is "/home/user1/config.db" then the file that is created and mmapped
** for shared memory will be called "/home/user1/config.db-shm". We ** for shared memory will be called "/home/user1/config.db-shm".
** experimented with using files in /dev/tmp or an some other tmpfs mount. **
** But if a file in a different directory from the database file is used, ** Another approach to is to use files in /dev/shm or /dev/tmp or an
** then differing access permissions or a chroot() might cause two different ** some other tmpfs mount. But if a file in a different directory
** processes on the same database to end up using different files for ** from the database file is used, then differing access permissions
** shared memory - meaning that their memory would not really be shared - ** or a chroot() might cause two different processes on the same
** resulting in database corruption. ** database to end up using different files for shared memory -
** meaning that their memory would not really be shared - resulting
** in database corruption. Nevertheless, this tmpfs file usage
** can be enabled at compile-time using -DSQLITE_SHM_DIRECTORY="/dev/shm"
** or the equivalent. The use of the SQLITE_SHM_DIRECTORY compile-time
** option results in an incompatible build of SQLite; builds of SQLite
** that with differing SQLITE_SHM_DIRECTORY settings attempt to use the
** same database file at the same time, database corruption will likely
** result. The SQLITE_SHM_DIRECTORY compile-time option is considered
** "unsupported" and may go away in a future SQLite release.
** **
** When opening a new shared-memory file, if no other instances of that ** 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 ** file are currently open, in this process or in other processes, then
@@ -3327,7 +3336,11 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
goto shm_open_err; goto shm_open_err;
} }
#ifdef SQLITE_SHM_DIRECTORY
nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 30;
#else
nShmFilename = 5 + (int)strlen(pDbFd->zPath); nShmFilename = 5 + (int)strlen(pDbFd->zPath);
#endif
pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename ); pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
if( pShmNode==0 ){ if( pShmNode==0 ){
rc = SQLITE_NOMEM; rc = SQLITE_NOMEM;
@@ -3335,7 +3348,13 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
} }
memset(pShmNode, 0, sizeof(*pShmNode)); memset(pShmNode, 0, sizeof(*pShmNode));
zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1]; zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1];
#ifdef SQLITE_SHM_DIRECTORY
sqlite3_snprintf(nShmFilename, zShmFilename,
SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
(u32)sStat.st_ino, (u32)sStat.st_dev);
#else
sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath); sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath);
#endif
pShmNode->h = -1; pShmNode->h = -1;
pDbFd->pInode->pShmNode = pShmNode; pDbFd->pInode->pShmNode = pShmNode;
pShmNode->pInode = pDbFd->pInode; pShmNode->pInode = pDbFd->pInode;
@@ -4311,14 +4330,13 @@ static UnixUnusedFd *findReusableFd(const char *zPath, int flags){
** **
** If the file being opened is a temporary file, it is always created with ** If the file being opened is a temporary file, it is always created with
** the octal permissions 0600 (read/writable by owner only). If the file ** the octal permissions 0600 (read/writable by owner only). If the file
** is a database or master journal file, it is created with the permissions ** is a database, journal or master journal file, it is created with the
** mask SQLITE_DEFAULT_FILE_PERMISSIONS. ** permissions mask SQLITE_DEFAULT_FILE_PERMISSIONS.
** **
** Finally, if the file being opened is a WAL or regular journal file, then ** Finally, if the file being opened is a WAL file, then this function
** this function queries the file-system for the permissions on the ** queries the file-system for the permissions on the corresponding database
** corresponding database file and sets *pMode to this value. Whenever ** file and sets *pMode to this value. Whenever possible, WAL files are
** possible, WAL and journal files are created using the same permissions ** created using the same permissions as the associated database file.
** as the associated database file.
*/ */
static int findCreateFileMode( static int findCreateFileMode(
const char *zPath, /* Path of file (possibly) being created */ const char *zPath, /* Path of file (possibly) being created */
@@ -4326,12 +4344,12 @@ static int findCreateFileMode(
mode_t *pMode /* OUT: Permissions to open file with */ mode_t *pMode /* OUT: Permissions to open file with */
){ ){
int rc = SQLITE_OK; /* Return Code */ int rc = SQLITE_OK; /* Return Code */
if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){ if( flags & SQLITE_OPEN_WAL ){
char zDb[MAX_PATHNAME+1]; /* Database file path */ char zDb[MAX_PATHNAME+1]; /* Database file path */
int nDb; /* Number of valid bytes in zDb */ int nDb; /* Number of valid bytes in zDb */
struct stat sStat; /* Output of stat() on database file */ struct stat sStat; /* Output of stat() on database file */
nDb = sqlite3Strlen30(zPath) - ((flags & SQLITE_OPEN_WAL) ? 4 : 8); nDb = sqlite3Strlen30(zPath) - 4;
memcpy(zDb, zPath, nDb); memcpy(zDb, zPath, nDb);
zDb[nDb] = '\0'; zDb[nDb] = '\0';
if( 0==stat(zDb, &sStat) ){ if( 0==stat(zDb, &sStat) ){
@@ -4474,7 +4492,6 @@ static int unixOpen(
rc = findCreateFileMode(zName, flags, &openMode); rc = findCreateFileMode(zName, flags, &openMode);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
assert( !p->pUnused ); assert( !p->pUnused );
assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL );
return rc; return rc;
} }
fd = open(zName, openFlags, openMode); fd = open(zName, openFlags, openMode);