OLD | NEW |
1 # 2010 April 13 | 1 # 2010 April 13 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 do_test wal3-1.$i.3 { | 87 do_test wal3-1.$i.3 { |
88 execsql { SELECT x FROM t1 WHERE rowid = $i } | 88 execsql { SELECT x FROM t1 WHERE rowid = $i } |
89 } $str | 89 } $str |
90 do_test wal3-1.$i.4 { | 90 do_test wal3-1.$i.4 { |
91 execsql { PRAGMA integrity_check } db2 | 91 execsql { PRAGMA integrity_check } db2 |
92 } {ok} | 92 } {ok} |
93 db2 close | 93 db2 close |
94 | 94 |
95 # Check that the file-system in its current state can be recovered. | 95 # Check that the file-system in its current state can be recovered. |
96 # | 96 # |
97 file copy -force test.db test2.db | 97 forcecopy test.db test2.db |
98 file copy -force test.db-wal test2.db-wal | 98 forcecopy test.db-wal test2.db-wal |
99 file delete -force test2.db-journal | 99 forcedelete test2.db-journal |
100 sqlite3 db2 test2.db | 100 sqlite3 db2 test2.db |
101 do_test wal3-1.$i.5 { | 101 do_test wal3-1.$i.5 { |
102 execsql { SELECT count(*) FROM t1 } db2 | 102 execsql { SELECT count(*) FROM t1 } db2 |
103 } 4018 | 103 } 4018 |
104 do_test wal3-1.$i.6 { | 104 do_test wal3-1.$i.6 { |
105 execsql { SELECT x FROM t1 WHERE rowid = $i } | 105 execsql { SELECT x FROM t1 WHERE rowid = $i } |
106 } $str | 106 } $str |
107 do_test wal3-1.$i.7 { | 107 do_test wal3-1.$i.7 { |
108 execsql { PRAGMA integrity_check } db2 | 108 execsql { PRAGMA integrity_check } db2 |
109 } {ok} | 109 } {ok} |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 {test.db-wal normal test.db normal} | 201 {test.db-wal normal test.db normal} |
202 3 full | 202 3 full |
203 {test.db-wal normal test.db-wal normal test.db-wal normal test.db normal} | 203 {test.db-wal normal test.db-wal normal test.db-wal normal test.db normal} |
204 } { | 204 } { |
205 | 205 |
206 proc sync_counter {args} { | 206 proc sync_counter {args} { |
207 foreach {method filename id flags} $args break | 207 foreach {method filename id flags} $args break |
208 lappend ::syncs [file tail $filename] $flags | 208 lappend ::syncs [file tail $filename] $flags |
209 } | 209 } |
210 do_test wal3-3.$tn { | 210 do_test wal3-3.$tn { |
211 file delete -force test.db test.db-wal test.db-journal | 211 forcedelete test.db test.db-wal test.db-journal |
212 | 212 |
213 testvfs T | 213 testvfs T |
214 T filter {} | 214 T filter {} |
215 T script sync_counter | 215 T script sync_counter |
216 sqlite3 db test.db -vfs T | 216 sqlite3 db test.db -vfs T |
217 | 217 |
218 execsql "PRAGMA synchronous = $syncmode" | 218 execsql "PRAGMA synchronous = $syncmode" |
219 execsql { PRAGMA journal_mode = WAL } | 219 execsql { PRAGMA journal_mode = WAL } |
| 220 execsql { CREATE TABLE filler(a,b,c); } |
220 | 221 |
221 set ::syncs [list] | 222 set ::syncs [list] |
222 T filter xSync | 223 T filter xSync |
223 execsql { | 224 execsql { |
224 CREATE TABLE x(y); | 225 CREATE TABLE x(y); |
225 INSERT INTO x VALUES('z'); | 226 INSERT INTO x VALUES('z'); |
226 PRAGMA wal_checkpoint; | 227 PRAGMA wal_checkpoint; |
227 } | 228 } |
228 T filter {} | 229 T filter {} |
229 set ::syncs | 230 set ::syncs |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 # acquire a different read-lock (not aReadMark[0]) and read the new | 405 # acquire a different read-lock (not aReadMark[0]) and read the new |
405 # snapshot. | 406 # snapshot. |
406 # | 407 # |
407 # + The attempt to obtain the lock on aReadMark[0] fails with SQLITE_BUSY. | 408 # + The attempt to obtain the lock on aReadMark[0] fails with SQLITE_BUSY. |
408 # This can happen if a checkpoint is ongoing. In this case also simply | 409 # This can happen if a checkpoint is ongoing. In this case also simply |
409 # obtain a different read-lock. | 410 # obtain a different read-lock. |
410 # | 411 # |
411 catch {db close} | 412 catch {db close} |
412 testvfs T -default 1 | 413 testvfs T -default 1 |
413 do_test wal3-6.1.1 { | 414 do_test wal3-6.1.1 { |
414 file delete -force test.db test.db-journal test.db wal | 415 forcedelete test.db test.db-journal test.db wal |
415 sqlite3 db test.db | 416 sqlite3 db test.db |
416 execsql { PRAGMA auto_vacuum = off } | 417 execsql { PRAGMA auto_vacuum = off } |
417 execsql { PRAGMA journal_mode = WAL } | 418 execsql { PRAGMA journal_mode = WAL } |
418 execsql { | 419 execsql { |
419 CREATE TABLE t1(a, b); | 420 CREATE TABLE t1(a, b); |
420 INSERT INTO t1 VALUES('o', 't'); | 421 INSERT INTO t1 VALUES('o', 't'); |
421 INSERT INTO t1 VALUES('t', 'f'); | 422 INSERT INTO t1 VALUES('t', 'f'); |
422 } | 423 } |
423 } {} | 424 } {} |
424 do_test wal3-6.1.2 { | 425 do_test wal3-6.1.2 { |
425 sqlite3 db2 test.db | 426 sqlite3 db2 test.db |
426 sqlite3 db3 test.db | 427 sqlite3 db3 test.db |
427 execsql { BEGIN ; SELECT * FROM t1 } db3 | 428 execsql { BEGIN ; SELECT * FROM t1 } db3 |
428 } {o t t f} | 429 } {o t t f} |
429 do_test wal3-6.1.3 { | 430 do_test wal3-6.1.3 { |
430 execsql { PRAGMA wal_checkpoint } db2 | 431 execsql { PRAGMA wal_checkpoint } db2 |
431 } {0 7 7} | 432 } {0 4 4} |
432 | 433 |
433 # At this point the log file has been fully checkpointed. However, | 434 # At this point the log file has been fully checkpointed. However, |
434 # connection [db3] holds a lock that prevents the log from being wrapped. | 435 # connection [db3] holds a lock that prevents the log from being wrapped. |
435 # Test case 3.6.1.4 has [db] attempt a read-lock on aReadMark[0]. But | 436 # Test case 3.6.1.4 has [db] attempt a read-lock on aReadMark[0]. But |
436 # as it is obtaining the lock, [db2] appends to the log file. | 437 # as it is obtaining the lock, [db2] appends to the log file. |
437 # | 438 # |
438 T filter xShmLock | 439 T filter xShmLock |
439 T script lock_callback | 440 T script lock_callback |
440 proc lock_callback {method file handle spec} { | 441 proc lock_callback {method file handle spec} { |
441 if {$spec == "3 1 lock shared"} { | 442 if {$spec == "3 1 lock shared"} { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 db2 eval { INSERT INTO t1 VALUES('n', 't') } | 486 db2 eval { INSERT INTO t1 VALUES('n', 't') } |
486 set sz2 [file size test.db-wal] | 487 set sz2 [file size test.db-wal] |
487 expr {$sz2==$sz1} | 488 expr {$sz2==$sz1} |
488 } {1} | 489 } {1} |
489 | 490 |
490 db3 close | 491 db3 close |
491 db2 close | 492 db2 close |
492 db close | 493 db close |
493 | 494 |
494 do_test wal3-6.2.1 { | 495 do_test wal3-6.2.1 { |
495 file delete -force test.db test.db-journal test.db wal | 496 forcedelete test.db test.db-journal test.db wal |
496 sqlite3 db test.db | 497 sqlite3 db test.db |
497 sqlite3 db2 test.db | 498 sqlite3 db2 test.db |
498 execsql { PRAGMA auto_vacuum = off } | 499 execsql { PRAGMA auto_vacuum = off } |
499 execsql { PRAGMA journal_mode = WAL } | 500 execsql { PRAGMA journal_mode = WAL } |
500 execsql { | 501 execsql { |
501 CREATE TABLE t1(a, b); | 502 CREATE TABLE t1(a, b); |
502 INSERT INTO t1 VALUES('h', 'h'); | 503 INSERT INTO t1 VALUES('h', 'h'); |
503 INSERT INTO t1 VALUES('l', 'b'); | 504 INSERT INTO t1 VALUES('l', 'b'); |
504 } | 505 } |
505 } {} | 506 } {} |
506 | 507 |
507 T filter xShmLock | 508 T filter xShmLock |
508 T script lock_callback | 509 T script lock_callback |
509 proc lock_callback {method file handle spec} { | 510 proc lock_callback {method file handle spec} { |
510 if {$spec == "3 1 unlock exclusive"} { | 511 if {$spec == "3 1 unlock exclusive"} { |
511 T filter {} | 512 T filter {} |
512 set ::R [db2 eval { | 513 set ::R [db2 eval { |
513 BEGIN; | 514 BEGIN; |
514 SELECT * FROM t1; | 515 SELECT * FROM t1; |
515 }] | 516 }] |
516 } | 517 } |
517 } | 518 } |
518 do_test wal3-6.2.2 { | 519 do_test wal3-6.2.2 { |
519 execsql { PRAGMA wal_checkpoint } | 520 execsql { PRAGMA wal_checkpoint } |
520 } {0 7 7} | 521 } {0 4 4} |
521 do_test wal3-6.2.3 { | 522 do_test wal3-6.2.3 { |
522 set ::R | 523 set ::R |
523 } {h h l b} | 524 } {h h l b} |
524 do_test wal3-6.2.4 { | 525 do_test wal3-6.2.4 { |
525 set sz1 [file size test.db-wal] | 526 set sz1 [file size test.db-wal] |
526 execsql { INSERT INTO t1 VALUES('b', 'c'); } | 527 execsql { INSERT INTO t1 VALUES('b', 'c'); } |
527 set sz2 [file size test.db-wal] | 528 set sz2 [file size test.db-wal] |
528 expr {$sz2 > $sz1} | 529 expr {$sz2 > $sz1} |
529 } {1} | 530 } {1} |
530 do_test wal3-6.2.5 { | 531 do_test wal3-6.2.5 { |
(...skipping 20 matching lines...) Expand all Loading... |
551 # written to the log. In this case the reader should re-read the | 552 # written to the log. In this case the reader should re-read the |
552 # wal-index header and lock a snapshot corresponding to the new | 553 # wal-index header and lock a snapshot corresponding to the new |
553 # header. | 554 # header. |
554 # | 555 # |
555 # + The value in the aReadMark[x] slot has been modified since it was | 556 # + The value in the aReadMark[x] slot has been modified since it was |
556 # read. | 557 # read. |
557 # | 558 # |
558 catch {db close} | 559 catch {db close} |
559 testvfs T -default 1 | 560 testvfs T -default 1 |
560 do_test wal3-7.1.1 { | 561 do_test wal3-7.1.1 { |
561 file delete -force test.db test.db-journal test.db wal | 562 forcedelete test.db test.db-journal test.db wal |
562 sqlite3 db test.db | 563 sqlite3 db test.db |
563 execsql { | 564 execsql { |
564 PRAGMA journal_mode = WAL; | 565 PRAGMA journal_mode = WAL; |
565 CREATE TABLE blue(red PRIMARY KEY, green); | 566 CREATE TABLE blue(red PRIMARY KEY, green); |
566 } | 567 } |
567 } {wal} | 568 } {wal} |
568 | 569 |
569 T script method_callback | 570 T script method_callback |
570 T filter xOpen | 571 T filter xOpen |
571 proc method_callback {method args} { | 572 proc method_callback {method args} { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 set ::locks | 609 set ::locks |
609 } {{5 1 lock shared} {5 1 unlock shared} {4 1 lock shared} {4 1 unlock shared}} | 610 } {{5 1 lock shared} {5 1 unlock shared} {4 1 lock shared} {4 1 unlock shared}} |
610 | 611 |
611 db close | 612 db close |
612 db2 close | 613 db2 close |
613 T delete | 614 T delete |
614 | 615 |
615 #------------------------------------------------------------------------- | 616 #------------------------------------------------------------------------- |
616 # | 617 # |
617 do_test wal3-8.1 { | 618 do_test wal3-8.1 { |
618 file delete -force test.db test.db-journal test.db wal | 619 forcedelete test.db test.db-journal test.db wal |
619 sqlite3 db test.db | 620 sqlite3 db test.db |
620 sqlite3 db2 test.db | 621 sqlite3 db2 test.db |
621 execsql { | 622 execsql { |
622 PRAGMA auto_vacuum = off; | 623 PRAGMA auto_vacuum = off; |
623 PRAGMA journal_mode = WAL; | 624 PRAGMA journal_mode = WAL; |
624 CREATE TABLE b(c); | 625 CREATE TABLE b(c); |
625 INSERT INTO b VALUES('Tehran'); | 626 INSERT INTO b VALUES('Tehran'); |
626 INSERT INTO b VALUES('Qom'); | 627 INSERT INTO b VALUES('Qom'); |
627 INSERT INTO b VALUES('Markazi'); | 628 INSERT INTO b VALUES('Markazi'); |
628 PRAGMA wal_checkpoint; | 629 PRAGMA wal_checkpoint; |
629 } | 630 } |
630 } {wal 0 9 9} | 631 } {wal 0 5 5} |
631 do_test wal3-8.2 { | 632 do_test wal3-8.2 { |
632 execsql { SELECT * FROM b } | 633 execsql { SELECT * FROM b } |
633 } {Tehran Qom Markazi} | 634 } {Tehran Qom Markazi} |
634 do_test wal3-8.3 { | 635 do_test wal3-8.3 { |
635 db eval { SELECT * FROM b } { | 636 db eval { SELECT * FROM b } { |
636 db eval { INSERT INTO b VALUES('Qazvin') } | 637 db eval { INSERT INTO b VALUES('Qazvin') } |
637 set r [db2 eval { SELECT * FROM b }] | 638 set r [db2 eval { SELECT * FROM b }] |
638 break | 639 break |
639 } | 640 } |
640 set r | 641 set r |
641 } {Tehran Qom Markazi Qazvin} | 642 } {Tehran Qom Markazi Qazvin} |
642 do_test wal3-8.4 { | 643 do_test wal3-8.4 { |
643 execsql { | 644 execsql { |
644 INSERT INTO b VALUES('Gilan'); | 645 INSERT INTO b VALUES('Gilan'); |
645 INSERT INTO b VALUES('Ardabil'); | 646 INSERT INTO b VALUES('Ardabil'); |
646 } | 647 } |
647 } {} | 648 } {} |
648 db2 close | 649 db2 close |
649 | 650 |
650 faultsim_save_and_close | 651 faultsim_save_and_close |
651 testvfs T -default 1 | 652 testvfs T -default 1 |
652 faultsim_restore_and_reopen | 653 faultsim_restore_and_reopen |
653 T filter xShmLock | 654 T filter xShmLock |
654 T script lock_callback | 655 T script lock_callback |
655 | 656 |
656 proc lock_callback {method file handle spec} { | 657 proc lock_callback {method file handle spec} { |
657 if {$spec == "4 1 unlock exclusive"} { | 658 if {$spec == "1 7 unlock exclusive"} { |
658 T filter {} | 659 T filter {} |
659 set ::r [catchsql { SELECT * FROM b } db2] | 660 set ::r [catchsql { SELECT * FROM b } db2] |
660 } | 661 } |
661 } | 662 } |
662 sqlite3 db test.db | 663 sqlite3 db test.db |
663 sqlite3 db2 test.db | 664 sqlite3 db2 test.db |
664 do_test wal3-8.5 { | 665 do_test wal3-8.5 { |
665 execsql { SELECT * FROM b } | 666 execsql { SELECT * FROM b } |
666 } {Tehran Qom Markazi Qazvin Gilan Ardabil} | 667 } {Tehran Qom Markazi Qazvin Gilan Ardabil} |
667 do_test wal3-8.6 { | 668 do_test wal3-8.6 { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 # exclusive lock on an aReadMark[] slot for the purposes of modifying | 701 # exclusive lock on an aReadMark[] slot for the purposes of modifying |
701 # the value, then drops back to a shared-lock for the duration of the | 702 # the value, then drops back to a shared-lock for the duration of the |
702 # transaction. | 703 # transaction. |
703 # | 704 # |
704 # This test case verifies that if an exclusive lock cannot be obtained | 705 # This test case verifies that if an exclusive lock cannot be obtained |
705 # on any aReadMark[] slot (because there are already several readers), | 706 # on any aReadMark[] slot (because there are already several readers), |
706 # the client takes a shared-lock on a slot without modifying the value | 707 # the client takes a shared-lock on a slot without modifying the value |
707 # and continues. | 708 # and continues. |
708 # | 709 # |
709 set nConn 50 | 710 set nConn 50 |
710 if { [string match *BSD $tcl_platform(os)] } { set nConn 35 } | 711 if { [string match *BSD $tcl_platform(os)] } { set nConn 25 } |
711 do_test wal3-9.0 { | 712 do_test wal3-9.0 { |
712 file delete -force test.db test.db-journal test.db wal | 713 forcedelete test.db test.db-journal test.db wal |
713 sqlite3 db test.db | 714 sqlite3 db test.db |
714 execsql { | 715 execsql { |
715 PRAGMA page_size = 1024; | 716 PRAGMA page_size = 1024; |
716 PRAGMA journal_mode = WAL; | 717 PRAGMA journal_mode = WAL; |
717 CREATE TABLE whoami(x); | 718 CREATE TABLE whoami(x); |
718 INSERT INTO whoami VALUES('nobody'); | 719 INSERT INTO whoami VALUES('nobody'); |
719 } | 720 } |
720 } {wal} | 721 } {wal} |
721 for {set i 0} {$i < $nConn} {incr i} { | 722 for {set i 0} {$i < $nConn} {incr i} { |
722 set c db$i | 723 set c db$i |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 | 778 |
778 expr {[file size test.db-wal] > [expr 1032*9000]} | 779 expr {[file size test.db-wal] > [expr 1032*9000]} |
779 } 1 | 780 } 1 |
780 | 781 |
781 do_test wal3-10.$tn.2 { | 782 do_test wal3-10.$tn.2 { |
782 sql2 {PRAGMA integrity_check} | 783 sql2 {PRAGMA integrity_check} |
783 } {ok} | 784 } {ok} |
784 } | 785 } |
785 | 786 |
786 finish_test | 787 finish_test |
787 | |
OLD | NEW |