If an SQLITE_IOERR error is encountered as part of an atomic commit on an F2FS
file-system, retry the commit in legacy journal mode. FossilOrigin-Name: 1c41250f67ac5de423b0426ef2ab8fe3303278a270225920033933ca9609592a
This commit is contained in:
parent
2f69b5c5d0
commit
140a59874b
18
manifest
18
manifest
@ -1,5 +1,5 @@
|
||||
C Remove\san\sunused\sfunction\sdeclaration\sfrom\sfts5.
|
||||
D 2018-07-13T20:28:54.141
|
||||
C If\san\sSQLITE_IOERR\serror\sis\sencountered\sas\spart\sof\san\satomic\scommit\son\san\sF2FS\nfile-system,\sretry\sthe\scommit\sin\slegacy\sjournal\smode.
|
||||
D 2018-07-14T20:25:13.305
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F Makefile.in 0a3a6c81e6fcb969ff9106e882f0a08547014ba463cb6beca4c4efaecc924ee6
|
||||
@ -483,7 +483,7 @@ F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586
|
||||
F src/os_unix.c c230a7a24766320d8414afd087edcd43e499fb45e86361f6f4f464f343d965a9
|
||||
F src/os_win.c ac29c25cde4cfb4adacc59cdec4aa45698ca0e29164ea127859585ccd9faa354
|
||||
F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
|
||||
F src/pager.c 1bb6a57fa0465296a4d6109a1a64610a0e7adde1f3acf3ef539a9d972908ce8f
|
||||
F src/pager.c 26959078356a658e152de9faf0cd870a36d881e92666c1b80a75938e30a29964
|
||||
F src/pager.h c571b064df842ec8f2e90855dead9acf4cbe0d1b2c05afe0ef0d0145f7fd0388
|
||||
F src/parse.y 3bd43415ea974b9921b0ff2c0bd3e9100f6e501ede0b6d3b90cca2ab6af25485
|
||||
F src/pcache.c 135ef0bc6fb2e3b7178d49ab5c9176254c8a691832c1bceb1156b2fbdd0869bd
|
||||
@ -552,7 +552,7 @@ F src/test_syscall.c 1073306ba2e9bfc886771871a13d3de281ed3939
|
||||
F src/test_tclsh.c 06317648b0d85a85fd823f7973b55535c59a3156c1ef59394fe511f932cfa78d
|
||||
F src/test_tclvar.c 33ff42149494a39c5fbb0df3d25d6fafb2f668888e41c0688d07273dcb268dfc
|
||||
F src/test_thread.c 911d15fb14e19c0c542bdc8aabf981c2f10a4858
|
||||
F src/test_vfs.c f0186261a24de2671d080bcd8050732f0cb64f6e
|
||||
F src/test_vfs.c 112f1f9271c33c211812e0e681830a84262dac065da58579ff49f9cefec97d4f
|
||||
F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698
|
||||
F src/test_windirent.c a895e2c068a06644eef91a7f0a32182445a893b9a0f33d0cdb4283dca2486ac1
|
||||
F src/test_windirent.h 90dfbe95442c9762357fe128dc7ae3dc199d006de93eb33ba3972e0a90484215
|
||||
@ -621,6 +621,7 @@ F test/async4.test 1787e3952128aa10238bf39945126de7ca23685a
|
||||
F test/async5.test 383ab533fdb9f7ad228cc99ee66e1acb34cc0dc0
|
||||
F test/atof1.test ff0b0156fd705b67c506e1f2bfe9e26102bea9bd
|
||||
F test/atomic.test 065a453dde33c77ff586d91ccaa6ed419829d492dbb1a5694b8a09f3f9d7d061
|
||||
F test/atomic2.test b6863b4aa552543874f80b42fb3063f1c8c2e3d8e56b6562f00a3cc347b5c1da
|
||||
F test/attach.test f4b8918ba2f3e88e6883b8452340545f10a1388af808343c37fc5c577be8281c
|
||||
F test/attach2.test 256bd240da1835fb8408dd59fb7ef71f8358c7a756c46662434d11d07ba3a0ce
|
||||
F test/attach3.test c59d92791070c59272e00183b7353eeb94915976
|
||||
@ -1747,7 +1748,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 80d2b9e635e3100f90cffdcffa5b5038da6fbbfccc9f5777c59a4ae760d4cb62
|
||||
R 81cc2fe2a6c094c9b67be82b05d8bc76
|
||||
P 148d9b61471a874a16a9ec9c9603da03cadb3a40662fb550af51cb36212426b1
|
||||
R 49a0ed84c0ce130af574e6c49ed456cc
|
||||
T *branch * exp-retry-atomic-commit
|
||||
T *sym-exp-retry-atomic-commit *
|
||||
T -sym-trunk *
|
||||
U dan
|
||||
Z 27c2f249d1d32a1646d5c8126ba109c2
|
||||
Z b2768f20163b2f8528694b9d7a295551
|
||||
|
@ -1 +1 @@
|
||||
148d9b61471a874a16a9ec9c9603da03cadb3a40662fb550af51cb36212426b1
|
||||
1c41250f67ac5de423b0426ef2ab8fe3303278a270225920033933ca9609592a
|
42
src/pager.c
42
src/pager.c
@ -6382,9 +6382,10 @@ int sqlite3PagerCommitPhaseOne(
|
||||
** backup in progress needs to be restarted. */
|
||||
sqlite3BackupRestart(pPager->pBackup);
|
||||
}else{
|
||||
PgHdr *pList;
|
||||
if( pagerUseWal(pPager) ){
|
||||
PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
|
||||
PgHdr *pPageOne = 0;
|
||||
pList = sqlite3PcacheDirtyList(pPager->pPCache);
|
||||
if( pList==0 ){
|
||||
/* Must have at least one page for the WAL commit flag.
|
||||
** Ticket [2d1a5c67dfc2363e44f29d9bbd57f] 2011-05-18 */
|
||||
@ -6407,7 +6408,7 @@ int sqlite3PagerCommitPhaseOne(
|
||||
*/
|
||||
sqlite3_file *fd = pPager->fd;
|
||||
#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
|
||||
const int bBatch = zMaster==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */
|
||||
int bBatch = zMaster==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */
|
||||
&& (sqlite3OsDeviceCharacteristics(fd) & SQLITE_IOCAP_BATCH_ATOMIC)
|
||||
&& !pPager->noSync
|
||||
&& sqlite3JournalIsInMemory(pPager->jfd);
|
||||
@ -6464,15 +6465,16 @@ int sqlite3PagerCommitPhaseOne(
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
#else /* SQLITE_ENABLE_ATOMIC_WRITE */
|
||||
#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
|
||||
if( zMaster ){
|
||||
rc = sqlite3JournalCreate(pPager->jfd);
|
||||
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
|
||||
assert( bBatch==0 );
|
||||
}
|
||||
#endif
|
||||
rc = pager_incr_changecounter(pPager, 0);
|
||||
#endif
|
||||
#endif /* !SQLITE_ENABLE_ATOMIC_WRITE */
|
||||
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
|
||||
|
||||
/* Write the master journal name into the journal file. If a master
|
||||
@ -6496,24 +6498,34 @@ int sqlite3PagerCommitPhaseOne(
|
||||
rc = syncJournal(pPager, 0);
|
||||
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
|
||||
|
||||
pList = sqlite3PcacheDirtyList(pPager->pPCache);
|
||||
if( bBatch ){
|
||||
/* The pager is now in DBMOD state. But regardless of what happens
|
||||
** next, attempting to play the journal back into the database would
|
||||
** be unsafe. Close it now to make sure that does not happen. */
|
||||
sqlite3OsClose(pPager->jfd);
|
||||
rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, 0);
|
||||
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
|
||||
}
|
||||
rc = pager_write_pagelist(pPager,sqlite3PcacheDirtyList(pPager->pPCache));
|
||||
if( bBatch ){
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, 0);
|
||||
rc = pager_write_pagelist(pPager, pList);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, 0);
|
||||
}
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3OsFileControlHint(fd, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, 0);
|
||||
}
|
||||
}
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3OsFileControlHint(fd, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, 0);
|
||||
|
||||
if( (rc&0xFF)==SQLITE_IOERR && rc!=SQLITE_IOERR_NOMEM ){
|
||||
rc = sqlite3JournalCreate(pPager->jfd);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3OsClose(pPager->jfd);
|
||||
}
|
||||
bBatch = 0;
|
||||
}else{
|
||||
sqlite3OsClose(pPager->jfd);
|
||||
}
|
||||
}
|
||||
|
||||
if( bBatch==0 && rc==SQLITE_OK ){
|
||||
rc = pager_write_pagelist(pPager, pList);
|
||||
}
|
||||
|
||||
if( rc!=SQLITE_OK ){
|
||||
assert( rc!=SQLITE_IOERR_BLOCKED );
|
||||
goto commit_phase_one_exit;
|
||||
|
@ -133,8 +133,9 @@ struct Testvfs {
|
||||
#define TESTVFS_UNLOCK_MASK 0x00020000
|
||||
#define TESTVFS_LOCK_MASK 0x00040000
|
||||
#define TESTVFS_CKLOCK_MASK 0x00080000
|
||||
#define TESTVFS_FCNTL_MASK 0x00100000
|
||||
|
||||
#define TESTVFS_ALL_MASK 0x000FFFFF
|
||||
#define TESTVFS_ALL_MASK 0x001FFFFF
|
||||
|
||||
|
||||
#define TESTVFS_MAX_PAGES 1024
|
||||
@ -517,7 +518,8 @@ static int tvfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){
|
||||
** File control method. For custom operations on an tvfs-file.
|
||||
*/
|
||||
static int tvfsFileControl(sqlite3_file *pFile, int op, void *pArg){
|
||||
TestvfsFd *p = tvfsGetFd(pFile);
|
||||
TestvfsFd *pFd = tvfsGetFd(pFile);
|
||||
Testvfs *p = (Testvfs *)pFd->pVfs->pAppData;
|
||||
if( op==SQLITE_FCNTL_PRAGMA ){
|
||||
char **argv = (char**)pArg;
|
||||
if( sqlite3_stricmp(argv[1],"error")==0 ){
|
||||
@ -535,11 +537,34 @@ static int tvfsFileControl(sqlite3_file *pFile, int op, void *pArg){
|
||||
return rc;
|
||||
}
|
||||
if( sqlite3_stricmp(argv[1], "filename")==0 ){
|
||||
argv[0] = sqlite3_mprintf("%s", p->zFilename);
|
||||
argv[0] = sqlite3_mprintf("%s", pFd->zFilename);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
return sqlite3OsFileControl(p->pReal, op, pArg);
|
||||
if( p->pScript && (p->mask&TESTVFS_FCNTL_MASK) ){
|
||||
struct Fcntl {
|
||||
int iFnctl;
|
||||
const char *zFnctl;
|
||||
} aF[] = {
|
||||
{ SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, "BEGIN_ATOMIC_WRITE" },
|
||||
{ SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, "COMMIT_ATOMIC_WRITE" },
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(aF)/sizeof(aF[0]); i++){
|
||||
if( op==aF[i].iFnctl ) break;
|
||||
}
|
||||
if( i<sizeof(aF)/sizeof(aF[0]) ){
|
||||
int rc = 0;
|
||||
tvfsExecTcl(p, "xFileControl",
|
||||
Tcl_NewStringObj(pFd->zFilename, -1),
|
||||
Tcl_NewStringObj(aF[i].zFnctl, -1),
|
||||
0, 0
|
||||
);
|
||||
tvfsResultCode(p, &rc);
|
||||
if( rc ) return rc;
|
||||
}
|
||||
}
|
||||
return sqlite3OsFileControl(pFd->pReal, op, pArg);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1160,6 +1185,7 @@ static int SQLITE_TCLAPI testvfs_obj_cmd(
|
||||
{ "xUnlock", TESTVFS_UNLOCK_MASK },
|
||||
{ "xLock", TESTVFS_LOCK_MASK },
|
||||
{ "xCheckReservedLock", TESTVFS_CKLOCK_MASK },
|
||||
{ "xFileControl", TESTVFS_FCNTL_MASK },
|
||||
};
|
||||
Tcl_Obj **apElem = 0;
|
||||
int nElem = 0;
|
||||
|
95
test/atomic2.test
Normal file
95
test/atomic2.test
Normal file
@ -0,0 +1,95 @@
|
||||
# 2018-07-15
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing that if an IO error is encountered
|
||||
# as part of an atomic F2FS commit, an attempt is made to commit the
|
||||
# transaction using a legacy journal commit.
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
source $testdir/malloc_common.tcl
|
||||
set ::testprefix atomic2
|
||||
|
||||
db close
|
||||
if {[atomic_batch_write test.db]==0} {
|
||||
puts "No f2fs atomic-batch-write support. Skipping tests..."
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
reset_db
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(x, y);
|
||||
CREATE INDEX i1x ON t1(x);
|
||||
CREATE INDEX i2x ON t1(y);
|
||||
|
||||
WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100 )
|
||||
INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM s;
|
||||
}
|
||||
|
||||
set setup [list \
|
||||
-injectstart at_injectstart \
|
||||
-injectstop at_injectstop \
|
||||
]
|
||||
|
||||
set ::at_fail 0
|
||||
set ::at_nfail 0
|
||||
|
||||
proc at_injectstart {iFail} {
|
||||
set ::at_fail $iFail
|
||||
set ::at_nfail 0
|
||||
}
|
||||
proc at_injectstop {} {
|
||||
set ::at_fail 0
|
||||
return $::at_nfail
|
||||
}
|
||||
|
||||
proc at_vfs_callback {method file z args} {
|
||||
if {$::at_fail>0} {
|
||||
incr ::at_fail -1
|
||||
if {$::at_fail==0} {
|
||||
incr ::at_nfail
|
||||
return SQLITE_IOERR
|
||||
} elseif {$method=="xFileControl" && $z=="COMMIT_ATOMIC_WRITE"} {
|
||||
set ::at_fail 0
|
||||
}
|
||||
}
|
||||
return SQLITE_OK
|
||||
}
|
||||
|
||||
testvfs tvfs -default 1
|
||||
tvfs script at_vfs_callback
|
||||
tvfs filter {xFileControl xWrite}
|
||||
|
||||
faultsim_save_and_close
|
||||
|
||||
do_one_faultsim_test 2.0 {*}$setup -prep {
|
||||
faultsim_restore_and_reopen
|
||||
} -body {
|
||||
execsql {
|
||||
WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100 )
|
||||
INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM s;
|
||||
}
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
|
||||
set res [execsql {SELECT count(*) FROM t1; PRAGMA integrity_check}]
|
||||
if {$res!="200 ok"} {
|
||||
error "expected {200 ok}, got $res"
|
||||
}
|
||||
}
|
||||
|
||||
db close
|
||||
tvfs delete
|
||||
|
||||
finish_test
|
Loading…
Reference in New Issue
Block a user