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

Fix a problem with hot-journal rollback. SQLITE_CANTOPEN was being returned if the hot-journal file contained a pointer to a master journal file that did not exist. (CVS 5775)

FossilOrigin-Name: 22d1feb9b20b8fd9c86066b94e4220cf8929b043
This commit is contained in:
danielk1977
2008-10-07 11:51:20 +00:00
parent 4281bd4204
commit c56774e234
4 changed files with 70 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
C Initial\ssupport\sfor\sLIMIT\sclause\son\sDELETEs\sand\sUPDATEs.\s\sChanges\slikely\swith\smore\stesting.\s\sThe\scode\scan\sbe\somitted\swith\sthe\sdefine\sSQLITE_OMIT_UPDATE_DELETE_LIMIT.\s(CVS\s5774)
D 2008-10-07T05:27:11
C Fix\sa\sproblem\swith\shot-journal\srollback.\sSQLITE_CANTOPEN\swas\sbeing\sreturned\sif\sthe\shot-journal\sfile\scontained\sa\spointer\sto\sa\smaster\sjournal\sfile\sthat\sdid\snot\sexist.\s(CVS\s5775)
D 2008-10-07T11:51:20
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in e4ab842f9a64ef61d57093539a8aab76b12810db
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -137,7 +137,7 @@ F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60
F src/os_os2.c e391fc95adc744bbdcefd4d11e3066998185a0a0
F src/os_unix.c f33b69d8a85372b270fe37ee664a4c2140a5217d
F src/os_win.c 04033a86a39f49cb8e348f515eb0116aa9d36678
F src/pager.c 44eba010e81dcc9b772401b90d6a1c61ec24345b
F src/pager.c d98f56128e849083f2f612196efebd982c491fea
F src/pager.h 9c1917be28fff58118e1fe0ddbc7adfb8dd4f44d
F src/parse.y 85d57c1dba3098da736a0c2ff8917c3d02a3a5f8
F src/pcache.c f8d7beceba164a34441ac37e88abb3a404f968a7
@@ -465,7 +465,7 @@ F test/quick.test bbaa1fbdac766cab2219d5599e9cd5bc2614d01e
F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6
F test/rdonly.test bd054831f8a3078e765a0657e247182486f0cb47
F test/reindex.test 44edd3966b474468b823d481eafef0c305022254
F test/rollback.test 0bd29070ba2f76da939347773fbda53337ebd61c
F test/rollback.test e57717812fab712cf93422f7b7301293674bdd0b
F test/rowid.test 1c8fc43c60d273e6ea44dfb992db587f3164312c
F test/rtree.test b85fd4f0861a40ca366ac195e363be2528dcfadf
F test/safety.test b69e2b2dd5d52a3f78e216967086884bbc1a09c6
@@ -640,7 +640,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 486b1124f76bcf0505b6be908f2a3e988ad6e05d
R d465119c99c45922a96415b5f4873654
U shane
Z 57d43f78fc0572634b2aa36caa16bd30
P 9c8b132e34bc6024bc9898182f8f93127ca52ac9
R 2d56feb5b3db0390dce74ef956d676c6
U danielk1977
Z c027ab0e5ec1d7fd629c680bded3838f

View File

@@ -1 +1 @@
9c8b132e34bc6024bc9898182f8f93127ca52ac9
22d1feb9b20b8fd9c86066b94e4220cf8929b043

View File

@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.496 2008/09/29 11:49:48 danielk1977 Exp $
** @(#) $Id: pager.c,v 1.497 2008/10/07 11:51:20 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
@@ -1517,7 +1517,7 @@ end_playback:
if( rc==SQLITE_OK ){
rc = pager_end_transaction(pPager, zMaster[0]!='\0');
}
if( rc==SQLITE_OK && zMaster[0] ){
if( rc==SQLITE_OK && zMaster[0] && res ){
/* If there was a master journal and this routine will return success,
** see if it is possible to delete the master journal.
*/

View File

@@ -13,7 +13,7 @@
# caused by an ON CONFLICT ROLLBACK clause aborts any other pending
# statements.
#
# $Id: rollback.test,v 1.6 2007/09/12 17:01:45 danielk1977 Exp $
# $Id: rollback.test,v 1.7 2008/10/07 11:51:20 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -79,4 +79,62 @@ do_test rollback-1.9 {
sqlite3_finalize $STMT
} {SQLITE_OK}
if {$tcl_platform(platform) == "unix"} {
do_test rollback-2.1 {
execsql {
BEGIN;
INSERT INTO t3 VALUES('hello world');
}
file copy -force test.db testA.db
file copy -force test.db-journal testA.db-journal
execsql {
COMMIT;
}
} {}
# At this point files testA.db and testA.db-journal are present in the
# file system. This block adds a master-journal file pointer to the
# end of testA.db-journal. The master-journal file does not exist.
#
set mj [file normalize testA.db-mj-123]
binary scan $mj c* a
set cksum 0
foreach i $a { incr cksum $i }
set mj_pgno [expr $sqlite_pending_byte / 1024]
set zAppend [binary format Ia*IIa8 $mj_pgno $mj [string length $mj] $cksum \
"\xd9\xd5\x05\xf9\x20\xa1\x63\xd7"
]
set iOffset [expr (([file size testA.db-journal] + 511)/512)*512]
set fd [open testA.db-journal a+]
fconfigure $fd -encoding binary -translation binary
seek $fd $iOffset
puts -nonewline $fd $zAppend
close $fd
# Open a handle on testA.db and use it to query the database. At one
# point the first query would attempt a hot rollback, attempt to open
# the master-journal file and return SQLITE_CANTOPEN when it could not
# be opened. This is incorrect, it should simply delete the journal
# file and proceed with the query.
#
do_test rollback-2.2 {
sqlite3 db2 testA.db
execsql {
SELECT distinct tbl_name FROM sqlite_master;
} db2
} {t1 t3}
do_test rollback-2.3 {
file exists testA.db-journal
} 0
do_test rollback-2.4 {
execsql {
SELECT distinct tbl_name FROM sqlite_master;
} db2
} {t1 t3}
db2 close
}
finish_test