Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Ignore the *-wal2 file if the *-wal file is zero bytes in size. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | wal2 |
Files: | files | file ages | folders |
SHA3-256: |
f7360fad51f224f347bb7d263eb89056 |
User & Date: | dan 2017-10-07 19:55:37.322 |
Context
2017-10-09
| ||
19:49 | Add a header comment to wal.c describing the differences between wal and wal2 mode. (check-in: 9c80cd202f user: dan tags: wal2) | |
2017-10-07
| ||
19:55 | Ignore the *-wal2 file if the *-wal file is zero bytes in size. (check-in: f7360fad51 user: dan tags: wal2) | |
13:37 | Check in test file wal2simple.test. (check-in: 8932b2f1d7 user: dan tags: wal2) | |
Changes
Changes to src/wal.c.
︙ | ︙ | |||
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 | int rc = SQLITE_OK; if( !isOpen(pWal->apWalFd[1]) ){ int f = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL); rc = sqlite3OsOpen(pWal->pVfs, pWal->zWalName2, pWal->apWalFd[1], f, &f); } return rc; } /* ** Recover the wal-index by reading the write-ahead log file. ** ** This routine first tries to establish an exclusive lock on the ** wal-index to prevent other threads/processes from doing anything ** with the WAL or wal-index while recovery is running. The | > > > > > > > > > > > > > > > | 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 | int rc = SQLITE_OK; if( !isOpen(pWal->apWalFd[1]) ){ int f = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL); rc = sqlite3OsOpen(pWal->pVfs, pWal->zWalName2, pWal->apWalFd[1], f, &f); } return rc; } static int walTruncateWal2(Wal *pWal){ int bIs; int rc; assert( !isOpen(pWal->apWalFd[1]) ); rc = sqlite3OsAccess(pWal->pVfs, pWal->zWalName2, SQLITE_ACCESS_EXISTS, &bIs); if( rc==SQLITE_OK && bIs ){ rc = walOpenWal2(pWal); if( rc==SQLITE_OK ){ rc = sqlite3OsTruncate(pWal->apWalFd[1], 0); sqlite3OsClose(pWal->apWalFd[1]); } } return rc; } /* ** Recover the wal-index by reading the write-ahead log file. ** ** This routine first tries to establish an exclusive lock on the ** wal-index to prevent other threads/processes from doing anything ** with the WAL or wal-index while recovery is running. The |
︙ | ︙ | |||
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 | ** pWal->hdr is already populated. */ rc = walIndexRecoverOne(pWal, 0, &nCkpt1, &bZero); assert( pWal->hdr.iVersion==0 || pWal->hdr.iVersion==WAL_VERSION1 || pWal->hdr.iVersion==WAL_VERSION2 ); if( rc==SQLITE_OK && pWal->hdr.iVersion!=WAL_VERSION1 ){ int bOpen = 1; sqlite3_vfs *pVfs = pWal->pVfs; if( pWal->hdr.iVersion==0 && pWal->bWal2==0 ){ rc = sqlite3OsAccess(pVfs, pWal->zWalName2, SQLITE_ACCESS_EXISTS, &bOpen); } if( rc==SQLITE_OK && bOpen ){ | > > > | 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 | ** pWal->hdr is already populated. */ rc = walIndexRecoverOne(pWal, 0, &nCkpt1, &bZero); assert( pWal->hdr.iVersion==0 || pWal->hdr.iVersion==WAL_VERSION1 || pWal->hdr.iVersion==WAL_VERSION2 ); if( rc==SQLITE_OK && bZero ){ rc = walTruncateWal2(pWal); } if( rc==SQLITE_OK && pWal->hdr.iVersion!=WAL_VERSION1 ){ int bOpen = 1; sqlite3_vfs *pVfs = pWal->pVfs; if( pWal->hdr.iVersion==0 && pWal->bWal2==0 ){ rc = sqlite3OsAccess(pVfs, pWal->zWalName2, SQLITE_ACCESS_EXISTS, &bOpen); } if( rc==SQLITE_OK && bOpen ){ |
︙ | ︙ | |||
1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 | }else /* Fallback */ if( nCkpt1<=nCkpt2 ){ pWal->hdr = hdr; }else{ walidxSetFile(&pWal->hdr, 1); } pWal->hdr.iVersion = WAL_VERSION2; }else{ pWal->hdr.iVersion = WAL_VERSION1; } walIndexWriteHdr(pWal); | > > | 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 | }else /* Fallback */ if( nCkpt1<=nCkpt2 ){ pWal->hdr = hdr; }else{ walidxSetFile(&pWal->hdr, 1); walidxSetMxFrame(&pWal->hdr, 1, pWal->hdr.mxFrame); walidxSetMxFrame(&pWal->hdr, 0, 0); } pWal->hdr.iVersion = WAL_VERSION2; }else{ pWal->hdr.iVersion = WAL_VERSION1; } walIndexWriteHdr(pWal); |
︙ | ︙ |
Changes to test/wal2simple.test.
︙ | ︙ | |||
224 225 226 227 228 229 230 231 232 233 | } [list ok $NROW $nTotal] db2 close } } finish_test | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | } [list ok $NROW $nTotal] db2 close } } #------------------------------------------------------------------------- reset_db do_execsql_test 6.0 { CREATE TABLE tx(x); PRAGMA journal_mode = wal2; PRAGMA journal_size_limit = 3500; } {wal2 3500} do_test 6.1 { for {set i 0} {$i < 10} {incr i} { execsql "CREATE TABLE t$i (x);" } } {} puts "[file size test.db-wal] [file size test.db-wal2]" do_test 6.2.1 { foreach f [glob -nocomplain test.db2*] { forcedelete $f } forcecopy test.db-wal2 test.db2-wal2 sqlite3 db2 test.db2 db2 eval { SELECT * FROM sqlite_master } } {} do_test 6.2.2 { db2 eval { PRAGMA journal_mode = wal2; SELECT * FROM sqlite_master; } } {wal2} do_test 6.3.1 { db2 close foreach f [glob -nocomplain test.db2*] { forcedelete $f } forcecopy test.db-wal2 test.db2-wal2 forcecopy test.db test.db2 sqlite3 db2 test.db2 db2 eval { SELECT * FROM sqlite_master } } {table tx tx 2 {CREATE TABLE tx(x)}} do_test 6.3.2 { db2 eval { PRAGMA journal_mode = wal2; SELECT * FROM sqlite_master; } } {wal2 table tx tx 2 {CREATE TABLE tx(x)}} do_test 6.4.1 { db2 close foreach f [glob -nocomplain test.db2*] { forcedelete $f } forcecopy test.db-wal2 test.db2-wal2 forcecopy test.db-wal test.db2-wal sqlite3 db2 test.db2 db2 eval { SELECT * FROM sqlite_master } } {} do_test 6.4.2 { db2 eval { PRAGMA journal_mode = wal2; SELECT * FROM sqlite_master; } } {wal2} db2 close finish_test |