1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Ensure the master journal directory is synced. Also, change the master journal

format to store journal file names. (CVS 1583)

FossilOrigin-Name: 73cd0aabb24f7b663c8b55cf5e8fcb34fd48c032
This commit is contained in:
danielk1977
2004-06-14 06:03:57 +00:00
parent aa5ccdf5b8
commit 5865e3d54f
7 changed files with 89 additions and 47 deletions

View File

@@ -1,5 +1,5 @@
C Update\sthe\sfile\schange\scounter\sjust\sbefore\seach\stransaction\sis\scommitted.\s(CVS\s1582) C Ensure\sthe\smaster\sjournal\sdirectory\sis\ssynced.\sAlso,\schange\sthe\smaster\sjournal\nformat\sto\sstore\sjournal\sfile\snames.\s(CVS\s1583)
D 2004-06-14T05:10:43 D 2004-06-14T06:03:57
F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -26,8 +26,8 @@ F sqlite.def fc4f5734786fe4743cfe2aa98eb2da4b089edb5f
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2 F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
F src/attach.c 93b8ecec4a8d7b4e9f2479e2327d90c9d01765e8 F src/attach.c 93b8ecec4a8d7b4e9f2479e2327d90c9d01765e8
F src/auth.c 5c2f0bea4729c98c2be3b69d6b466fc51448fe79 F src/auth.c 5c2f0bea4729c98c2be3b69d6b466fc51448fe79
F src/btree.c 5591068c5ed0e5d65938d41ac9e3fe6f461fdb07 F src/btree.c 1bed18993e54483de8ff869142e82c48847e1d50
F src/btree.h 589427ac13bb544d298cd99726e2572a6fe4bdaa F src/btree.h 32f96abef464cf8765b23ca669acfe90d191fcc5
F src/build.c 916a84fa5f8bfd44dbe14c3d7c923dd07ee7373f F src/build.c 916a84fa5f8bfd44dbe14c3d7c923dd07ee7373f
F src/date.c 65b483caeb0e4dd663667d2f927caa058168ebff F src/date.c 65b483caeb0e4dd663667d2f927caa058168ebff
F src/delete.c 911221aadb35d610c84fadb32e71c52990827e58 F src/delete.c 911221aadb35d610c84fadb32e71c52990827e58
@@ -48,8 +48,8 @@ F src/os_unix.c 7ece785e36c4ecb57c73db8d374b56912d742c4a
F src/os_unix.h 1cd6133cf66dea704b8646b70b2dfdcbdd9b3738 F src/os_unix.h 1cd6133cf66dea704b8646b70b2dfdcbdd9b3738
F src/os_win.c d4009586dfd0543ca8956ff0be30f9d23e2cbbdd F src/os_win.c d4009586dfd0543ca8956ff0be30f9d23e2cbbdd
F src/os_win.h 004eec47b1780fcaf07420ddc2072294b698d48c F src/os_win.h 004eec47b1780fcaf07420ddc2072294b698d48c
F src/pager.c feb44bd0279f77319079c1fddf9be927b052d028 F src/pager.c d42af374b23b50805b42c08cbba5bd70dd73964f
F src/pager.h ca8f293e1d623a7c628a1c5e0c6cf43d5bbb80bf F src/pager.h bc58d32a9dee464f7268fb68652c130a4216e438
F src/parse.y 097438674976355a10cf177bd97326c548820b86 F src/parse.y 097438674976355a10cf177bd97326c548820b86
F src/pragma.c e288bd122d3ca41ec2032475abde1ff5fa3095f4 F src/pragma.c e288bd122d3ca41ec2032475abde1ff5fa3095f4
F src/printf.c 63b15f1ea9fe3daa066bb7430fd20d4a2d717dc8 F src/printf.c 63b15f1ea9fe3daa066bb7430fd20d4a2d717dc8
@@ -75,7 +75,7 @@ F src/vdbe.c e6b6702fb2c2e2702e312f52c2cc08353c580736
F src/vdbe.h 46f74444a213129bc4b5ce40124dd8ed613b0cde F src/vdbe.h 46f74444a213129bc4b5ce40124dd8ed613b0cde
F src/vdbeInt.h ffc7b8ed911c5bf804796a768fdb6f0568010fa2 F src/vdbeInt.h ffc7b8ed911c5bf804796a768fdb6f0568010fa2
F src/vdbeapi.c ee350b552fc4c1c695b760f914f69e9c5556e829 F src/vdbeapi.c ee350b552fc4c1c695b760f914f69e9c5556e829
F src/vdbeaux.c 7b45d4934cddcf0fb79feac13c3399165774d35c F src/vdbeaux.c d792de3b042ffc49c344e147543af6cf2a3dc5de
F src/vdbemem.c 34f59988831ea032b7f526c2c73175f9f4c0f3ad F src/vdbemem.c 34f59988831ea032b7f526c2c73175f9f4c0f3ad
F src/where.c dda77afaa593cd54e5955ec433076de18faf62f6 F src/where.c dda77afaa593cd54e5955ec433076de18faf62f6
F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242 F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
@@ -223,7 +223,7 @@ F www/support.tcl 1801397edd271cc39a2aadd54e701184b5181248
F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075 F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075
F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
P 77c5eaa10a9d2e2bb8f89b7434d6e6efbacf35e9 P 4649abcbfd032836b196b5d690ef66e4aa494c45
R 728fa94fee79e66b965ca32e2cd56d1b R b61789483f3e3746f567ebdec2a394da
U danielk1977 U danielk1977
Z 982942d9d284a3b9c20e3e9aaf713011 Z cb4dbe83de3608a128ac6ced61032939

View File

@@ -1 +1 @@
4649abcbfd032836b196b5d690ef66e4aa494c45 73cd0aabb24f7b663c8b55cf5e8fcb34fd48c032

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give. ** May you share freely, never taking more than you give.
** **
************************************************************************* *************************************************************************
** $Id: btree.c,v 1.165 2004/06/13 23:07:04 drh Exp $ ** $Id: btree.c,v 1.166 2004/06/14 06:03:57 danielk1977 Exp $
** **
** This file implements a external (disk-based) database using BTrees. ** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to ** For a detailed discussion of BTrees, refer to
@@ -4196,6 +4196,24 @@ const char *sqlite3BtreeGetFilename(Btree *pBt){
return sqlite3pager_filename(pBt->pPager); return sqlite3pager_filename(pBt->pPager);
} }
/*
** Return the pathname of the directory that contains the database file.
*/
const char *sqlite3BtreeGetDirname(Btree *pBt){
assert( pBt->pPager!=0 );
return sqlite3pager_dirname(pBt->pPager);
}
/*
** Return the pathname of the journal file for this database. The return
** value of this routine is the same regardless of whether the journal file
** has been created or not.
*/
const char *sqlite3BtreeGetJournalname(Btree *pBt){
assert( pBt->pPager!=0 );
return sqlite3pager_journalname(pBt->pPager);
}
/* /*
** Copy the complete content of pBtFrom into pBtTo. A transaction ** Copy the complete content of pBtFrom into pBtTo. A transaction
** must be active for both files. ** must be active for both files.

View File

@@ -13,7 +13,7 @@
** subsystem. See comments in the source code for a detailed description ** subsystem. See comments in the source code for a detailed description
** of what each interface routine does. ** of what each interface routine does.
** **
** @(#) $Id: btree.h,v 1.53 2004/06/04 06:22:01 danielk1977 Exp $ ** @(#) $Id: btree.h,v 1.54 2004/06/14 06:03:57 danielk1977 Exp $
*/ */
#ifndef _BTREE_H_ #ifndef _BTREE_H_
#define _BTREE_H_ #define _BTREE_H_
@@ -59,6 +59,8 @@ int sqlite3BtreeIsInStmt(Btree*);
int sqlite3BtreeSync(Btree*, const char *zMaster); int sqlite3BtreeSync(Btree*, const char *zMaster);
const char *sqlite3BtreeGetFilename(Btree *); const char *sqlite3BtreeGetFilename(Btree *);
const char *sqlite3BtreeGetDirname(Btree *);
const char *sqlite3BtreeGetJournalname(Btree *);
int sqlite3BtreeCopyFile(Btree *, Btree *); int sqlite3BtreeCopyFile(Btree *, Btree *);
/* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR

View File

@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while ** file simultaneously, or one process from reading the database while
** another is writing. ** another is writing.
** **
** @(#) $Id: pager.c,v 1.125 2004/06/14 05:10:43 danielk1977 Exp $ ** @(#) $Id: pager.c,v 1.126 2004/06/14 06:03:57 danielk1977 Exp $
*/ */
#include "os.h" /* Must be first to enable large file support */ #include "os.h" /* Must be first to enable large file support */
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -615,30 +615,33 @@ static int pager_delmaster(const char *zMaster){
rc = sqlite3OsOpenExclusive(zMaster, &master, 0); rc = sqlite3OsOpenExclusive(zMaster, &master, 0);
if( rc!=SQLITE_OK ) goto delmaster_out; if( rc!=SQLITE_OK ) goto delmaster_out;
master_open = 1; master_open = 1;
rc = sqlite3OsFileSize(&master, &nMasterJournal); rc = sqlite3OsFileSize(&master, &nMasterJournal);
if( rc!=SQLITE_OK ) goto delmaster_out; if( rc!=SQLITE_OK ) goto delmaster_out;
if( nMasterJournal>0 ){ if( nMasterJournal>0 ){
char *zDb; char *zJournal;
zMasterJournal = (char *)sqliteMalloc(nMasterJournal); char *zMasterPtr;
int nMasterPtr; /* Number of bytes allocated at zMasterPtr */
/* Load the entire master journal file into space obtained from
** sqliteMalloc() and pointed to by zMasterJournal.
**
** Also allocate an extra (strlen(zMaster)+1) bytes. This space is used
** to load a master-journal filename from some other journal file to
** check if it points at this master journal file.
*/
nMasterPtr = strlen(zMaster) + 1;
zMasterJournal = (char *)sqliteMalloc(nMasterJournal) + nMasterPtr;
if( !zMasterJournal ){ if( !zMasterJournal ){
rc = SQLITE_NOMEM; rc = SQLITE_NOMEM;
goto delmaster_out; goto delmaster_out;
} }
zMasterPtr = &zMasterJournal[nMasterJournal];
rc = sqlite3OsRead(&master, zMasterJournal, nMasterJournal); rc = sqlite3OsRead(&master, zMasterJournal, nMasterJournal);
if( rc!=SQLITE_OK ) goto delmaster_out; if( rc!=SQLITE_OK ) goto delmaster_out;
zDb = zMasterJournal; zJournal = zMasterJournal;
while( (zDb-zMasterJournal)<nMasterJournal ){ while( (zJournal-zMasterJournal)<nMasterJournal ){
char *zJournal = 0;
/*** FIX ME: Store the full journal name in the master journal,
**** not just the base database name. ***/
sqlite3SetString(&zJournal, zDb, "-journal", 0);
if( !zJournal ){
rc = SQLITE_NOMEM;
goto delmaster_out;
}
if( sqlite3OsFileExists(zJournal) ){ if( sqlite3OsFileExists(zJournal) ){
/* One of the journals pointed to by the master journal exists. /* One of the journals pointed to by the master journal exists.
** Open it and check if it points at the master journal. If ** Open it and check if it points at the master journal. If
@@ -649,7 +652,6 @@ static int pager_delmaster(const char *zMaster){
off_t jsz; off_t jsz;
rc = sqlite3OsOpenReadOnly(zJournal, &journal); rc = sqlite3OsOpenReadOnly(zJournal, &journal);
sqliteFree(zJournal);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
sqlite3OsClose(&journal); sqlite3OsClose(&journal);
goto delmaster_out; goto delmaster_out;
@@ -676,26 +678,18 @@ static int pager_delmaster(const char *zMaster){
if( rc!=SQLITE_OK ) goto delmaster_out; if( rc!=SQLITE_OK ) goto delmaster_out;
rc = read32bits(&journal, (u32*)&nMaster); rc = read32bits(&journal, (u32*)&nMaster);
if( rc!=SQLITE_OK ) goto delmaster_out; if( rc!=SQLITE_OK ) goto delmaster_out;
if( nMaster>0 && nMaster>=strlen(zMaster)+1 ){ if( nMaster>=nMasterPtr ){
/*** FIX ME: Consider allocating this space at the same time rc = sqlite3OsRead(&journal, zMasterPtr, nMasterPtr);
**** space is allocated for holding the text of the master journal */
char *zMasterPtr = (char *)sqliteMalloc(nMaster);
if( !zMasterPtr ){
rc = SQLITE_NOMEM;
}
rc = sqlite3OsRead(&journal, zMasterPtr, nMaster);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
sqliteFree(zMasterPtr);
goto delmaster_out; goto delmaster_out;
} }
if( 0==strncmp(zMasterPtr, zMaster, nMaster) ){ if( zMasterPtr[nMasterPtr-1]=='\0' && !strcmp(zMasterPtr, zMaster) ){
/* We have a match. Do not delete the master journal file. */ /* We have a match. Do not delete the master journal file. */
sqliteFree(zMasterPtr);
goto delmaster_out; goto delmaster_out;
} }
} }
} }
zDb += (strlen(zDb)+1); zJournal += (strlen(zJournal)+1);
} }
} }
@@ -2634,6 +2628,20 @@ const char *sqlite3pager_filename(Pager *pPager){
return pPager->zFilename; return pPager->zFilename;
} }
/*
** Return the directory of the database file.
*/
const char *sqlite3pager_dirname(Pager *pPager){
return pPager->zDirectory;
}
/*
** Return the full pathname of the journal file.
*/
const char *sqlite3pager_journalname(Pager *pPager){
return pPager->zJournal;
}
/* /*
** Set the codec for this pager ** Set the codec for this pager
*/ */

View File

@@ -13,7 +13,7 @@
** subsystem. The page cache subsystem reads and writes a file a page ** subsystem. The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback. ** at a time and provides a journal for rollback.
** **
** @(#) $Id: pager.h,v 1.33 2004/06/09 17:37:28 drh Exp $ ** @(#) $Id: pager.h,v 1.34 2004/06/14 06:03:57 danielk1977 Exp $
*/ */
/* /*
@@ -99,6 +99,8 @@ void sqlite3pager_dont_write(Pager*, Pgno);
int *sqlite3pager_stats(Pager*); int *sqlite3pager_stats(Pager*);
void sqlite3pager_set_safety_level(Pager*,int); void sqlite3pager_set_safety_level(Pager*,int);
const char *sqlite3pager_filename(Pager*); const char *sqlite3pager_filename(Pager*);
const char *sqlite3pager_dirname(Pager*);
const char *sqlite3pager_journalname(Pager*);
int sqlite3pager_rename(Pager*, const char *zNewName); int sqlite3pager_rename(Pager*, const char *zNewName);
void sqlite3pager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*); void sqlite3pager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*);

View File

@@ -1061,7 +1061,7 @@ static int vdbeCommit(sqlite *db){
Btree *pBt = db->aDb[i].pBt; Btree *pBt = db->aDb[i].pBt;
if( i==1 ) continue; /* Ignore the TEMP database */ if( i==1 ) continue; /* Ignore the TEMP database */
if( pBt && sqlite3BtreeIsInTrans(pBt) ){ if( pBt && sqlite3BtreeIsInTrans(pBt) ){
char const *zFile = sqlite3BtreeGetFilename(pBt); char const *zFile = sqlite3BtreeGetJournalname(pBt);
if( zFile[0]==0 ) continue; /* Ignore :memory: databases */ if( zFile[0]==0 ) continue; /* Ignore :memory: databases */
rc = sqlite3OsWrite(&master, zFile, strlen(zFile)+1); rc = sqlite3OsWrite(&master, zFile, strlen(zFile)+1);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
@@ -1073,12 +1073,24 @@ static int vdbeCommit(sqlite *db){
} }
} }
/* Sync the master journal file */
rc = sqlite3OsSync(&master);
sqlite3OsClose(&master);
/* FIXME: Sync the directory that contains the master journal to /* Sync the master journal file. Before doing this, open the directory
** make sure the i-node is up to date. */ ** the master journal file is store in so that it gets synced too.
*/
zMainFile = sqlite3BtreeGetDirname(db->aDb[0].pBt);
rc = sqlite3OsOpenDirectory(zMainFile, &master);
if( rc!=SQLITE_OK ){
sqlite3OsClose(&master);
sqlite3OsDelete(zMaster);
sqliteFree(zMaster);
return rc;
}
rc = sqlite3OsSync(&master);
if( rc!=SQLITE_OK ){
sqliteFree(zMaster);
return rc;
}
sqlite3OsClose(&master);
/* Sync all the db files involved in the transaction. The same call /* Sync all the db files involved in the transaction. The same call
** sets the master journal pointer in each individual journal. If ** sets the master journal pointer in each individual journal. If