| 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 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 } [list 3 [wal_file_size 32 1024]] | 705 } [list 3 [wal_file_size 32 1024]] |
| 706 do_test wal-11.5 { | 706 do_test wal-11.5 { |
| 707 execsql { | 707 execsql { |
| 708 SELECT count(*) FROM t1; | 708 SELECT count(*) FROM t1; |
| 709 PRAGMA integrity_check; | 709 PRAGMA integrity_check; |
| 710 } | 710 } |
| 711 } {16 ok} | 711 } {16 ok} |
| 712 do_test wal-11.6 { | 712 do_test wal-11.6 { |
| 713 execsql COMMIT | 713 execsql COMMIT |
| 714 list [expr [file size test.db]/1024] [file size test.db-wal] | 714 list [expr [file size test.db]/1024] [file size test.db-wal] |
| 715 } [list 3 [wal_file_size 41 1024]] | 715 } [list 3 [wal_file_size 40 1024]] |
| 716 do_test wal-11.7 { | 716 do_test wal-11.7 { |
| 717 execsql { | 717 execsql { |
| 718 SELECT count(*) FROM t1; | 718 SELECT count(*) FROM t1; |
| 719 PRAGMA integrity_check; | 719 PRAGMA integrity_check; |
| 720 } | 720 } |
| 721 } {16 ok} | 721 } {16 ok} |
| 722 do_test wal-11.8 { | 722 do_test wal-11.8 { |
| 723 execsql { PRAGMA wal_checkpoint } | 723 execsql { PRAGMA wal_checkpoint } |
| 724 list [expr [file size test.db]/1024] [file size test.db-wal] | 724 list [expr [file size test.db]/1024] [file size test.db-wal] |
| 725 } [list 37 [wal_file_size 41 1024]] | 725 } [list 37 [wal_file_size 40 1024]] |
| 726 do_test wal-11.9 { | 726 do_test wal-11.9 { |
| 727 db close | 727 db close |
| 728 list [expr [file size test.db]/1024] [log_deleted test.db-wal] | 728 list [expr [file size test.db]/1024] [log_deleted test.db-wal] |
| 729 } {37 1} | 729 } {37 1} |
| 730 sqlite3_wal db test.db | 730 sqlite3_wal db test.db |
| 731 set nWal 39 | 731 |
| 732 if {[permutation]!="mmap"} {set nWal 37} | 732 # After adding the capability of WAL to overwrite prior uncommitted |
| 733 ifcapable !mmap {set nWal 37} | 733 # frame in the WAL-file with revised content, the size of the WAL file |
| 734 # following cache-spill is smaller. |
| 735 # |
| 736 #set nWal 39 |
| 737 #if {[permutation]!="mmap"} {set nWal 37} |
| 738 #ifcapable !mmap {set nWal 37} |
| 739 set nWal 34 |
| 740 |
| 734 do_test wal-11.10 { | 741 do_test wal-11.10 { |
| 735 execsql { | 742 execsql { |
| 736 PRAGMA cache_size = 10; | 743 PRAGMA cache_size = 10; |
| 737 BEGIN; | 744 BEGIN; |
| 738 INSERT INTO t1 SELECT blob(900) FROM t1; -- 32 | 745 INSERT INTO t1 SELECT blob(900) FROM t1; -- 32 |
| 739 SELECT count(*) FROM t1; | 746 SELECT count(*) FROM t1; |
| 740 } | 747 } |
| 741 list [expr [file size test.db]/1024] [file size test.db-wal] | 748 list [expr [file size test.db]/1024] [file size test.db-wal] |
| 742 } [list 37 [wal_file_size $nWal 1024]] | 749 } [list 37 [wal_file_size $nWal 1024]] |
| 743 do_test wal-11.11 { | 750 do_test wal-11.11 { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 do_test wal-12.6 { | 818 do_test wal-12.6 { |
| 812 forcecopy test.db test2.db | 819 forcecopy test.db test2.db |
| 813 forcecopy test.db-wal test2.db-wal | 820 forcecopy test.db-wal test2.db-wal |
| 814 sqlite3_wal db2 test2.db | 821 sqlite3_wal db2 test2.db |
| 815 execsql { SELECT * FROM t2 } db2 | 822 execsql { SELECT * FROM t2 } db2 |
| 816 } {B 2} | 823 } {B 2} |
| 817 db2 close | 824 db2 close |
| 818 db close | 825 db close |
| 819 | 826 |
| 820 #------------------------------------------------------------------------- | 827 #------------------------------------------------------------------------- |
| 821 # Test large log summaries. | |
| 822 # | |
| 823 # In this case "large" usually means a log file that requires a wal-index | |
| 824 # mapping larger than 64KB (the default initial allocation). A 64KB wal-index | |
| 825 # is large enough for a log file that contains approximately 13100 frames. | |
| 826 # So the following tests create logs containing at least this many frames. | |
| 827 # | |
| 828 # wal-13.1.*: This test case creates a very large log file within the | |
| 829 # file-system (around 200MB). The log file does not contain | |
| 830 # any valid frames. Test that the database file can still be | |
| 831 # opened and queried, and that the invalid log file causes no | |
| 832 # problems. | |
| 833 # | |
| 834 # wal-13.2.*: Test that a process may create a large log file and query | |
| 835 # the database (including the log file that it itself created). | |
| 836 # | |
| 837 # wal-13.3.*: Test that if a very large log file is created, and then a | |
| 838 # second connection is opened on the database file, it is possible | |
| 839 # to query the database (and the very large log) using the | |
| 840 # second connection. | |
| 841 # | |
| 842 # wal-13.4.*: Same test as wal-13.3.*. Except in this case the second | |
| 843 # connection is opened by an external process. | |
| 844 # | |
| 845 do_test wal-13.1.1 { | |
| 846 list [file exists test.db] [file exists test.db-wal] | |
| 847 } {1 0} | |
| 848 do_test wal-13.1.2 { | |
| 849 set fd [open test.db-wal w] | |
| 850 seek $fd [expr 200*1024*1024] | |
| 851 puts $fd "" | |
| 852 close $fd | |
| 853 sqlite3 db test.db | |
| 854 execsql { SELECT * FROM t2 } | |
| 855 } {B 2} | |
| 856 do_test wal-13.1.3 { | |
| 857 db close | |
| 858 file exists test.db-wal | |
| 859 } {0} | |
| 860 | |
| 861 do_test wal-13.2.1 { | |
| 862 sqlite3 db test.db | |
| 863 execsql { SELECT count(*) FROM t2 } | |
| 864 } {1} | |
| 865 do_test wal-13.2.2 { | |
| 866 db function blob blob | |
| 867 for {set i 0} {$i < 16} {incr i} { | |
| 868 execsql { INSERT INTO t2 SELECT blob(400), blob(400) FROM t2 } | |
| 869 } | |
| 870 execsql { SELECT count(*) FROM t2 } | |
| 871 } [expr int(pow(2, 16))] | |
| 872 do_test wal-13.2.3 { | |
| 873 expr [file size test.db-wal] > [wal_file_size 33000 1024] | |
| 874 } 1 | |
| 875 | |
| 876 do_multiclient_test tn { | |
| 877 incr tn 2 | |
| 878 | |
| 879 do_test wal-13.$tn.0 { | |
| 880 sql1 { | |
| 881 PRAGMA journal_mode = WAL; | |
| 882 CREATE TABLE t1(x); | |
| 883 INSERT INTO t1 SELECT randomblob(800); | |
| 884 } | |
| 885 sql1 { SELECT count(*) FROM t1 } | |
| 886 } {1} | |
| 887 | |
| 888 for {set ii 1} {$ii<16} {incr ii} { | |
| 889 do_test wal-13.$tn.$ii.a { | |
| 890 sql2 { INSERT INTO t1 SELECT randomblob(800) FROM t1 } | |
| 891 sql2 { SELECT count(*) FROM t1 } | |
| 892 } [expr (1<<$ii)] | |
| 893 do_test wal-13.$tn.$ii.b { | |
| 894 sql1 { SELECT count(*) FROM t1 } | |
| 895 } [expr (1<<$ii)] | |
| 896 do_test wal-13.$tn.$ii.c { | |
| 897 sql1 { SELECT count(*) FROM t1 } | |
| 898 } [expr (1<<$ii)] | |
| 899 do_test wal-13.$tn.$ii.d { | |
| 900 sql1 { PRAGMA integrity_check } | |
| 901 } {ok} | |
| 902 } | |
| 903 } | |
| 904 | |
| 905 #------------------------------------------------------------------------- | |
| 906 # Check a fun corruption case has been fixed. | 828 # Check a fun corruption case has been fixed. |
| 907 # | 829 # |
| 908 # The problem was that after performing a checkpoint using a connection | 830 # The problem was that after performing a checkpoint using a connection |
| 909 # that had an out-of-date pager-cache, the next time the connection was | 831 # that had an out-of-date pager-cache, the next time the connection was |
| 910 # used it did not realize the cache was out-of-date and proceeded to | 832 # used it did not realize the cache was out-of-date and proceeded to |
| 911 # operate with an inconsistent cache. Leading to corruption. | 833 # operate with an inconsistent cache. Leading to corruption. |
| 912 # | 834 # |
| 913 catch { db close } | 835 catch { db close } |
| 914 catch { db2 close } | 836 catch { db2 close } |
| 915 catch { db3 close } | 837 catch { db3 close } |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1449 } | 1371 } |
| 1450 execsql { SELECT * FROM t1 } | 1372 execsql { SELECT * FROM t1 } |
| 1451 } {1 2 3 4 5 6 7 8 9 10 11 12} | 1373 } {1 2 3 4 5 6 7 8 9 10 11 12} |
| 1452 do_test wal-21.3 { | 1374 do_test wal-21.3 { |
| 1453 execsql { PRAGMA integrity_check } | 1375 execsql { PRAGMA integrity_check } |
| 1454 } {ok} | 1376 } {ok} |
| 1455 | 1377 |
| 1456 #------------------------------------------------------------------------- | 1378 #------------------------------------------------------------------------- |
| 1457 # Test reading and writing of databases with different page-sizes. | 1379 # Test reading and writing of databases with different page-sizes. |
| 1458 # | 1380 # |
| 1381 incr ::do_not_use_codec |
| 1459 foreach pgsz {512 1024 2048 4096 8192 16384 32768 65536} { | 1382 foreach pgsz {512 1024 2048 4096 8192 16384 32768 65536} { |
| 1460 do_multiclient_test tn [string map [list %PGSZ% $pgsz] { | 1383 do_multiclient_test tn [string map [list %PGSZ% $pgsz] { |
| 1461 do_test wal-22.%PGSZ%.$tn.1 { | 1384 do_test wal-22.%PGSZ%.$tn.1 { |
| 1462 sql1 { | 1385 sql1 { |
| 1463 PRAGMA main.page_size = %PGSZ%; | 1386 PRAGMA main.page_size = %PGSZ%; |
| 1464 PRAGMA auto_vacuum = 0; | 1387 PRAGMA auto_vacuum = 0; |
| 1465 PRAGMA journal_mode = WAL; | 1388 PRAGMA journal_mode = WAL; |
| 1466 CREATE TABLE t1(x UNIQUE); | 1389 CREATE TABLE t1(x UNIQUE); |
| 1467 INSERT INTO t1 SELECT randomblob(800); | 1390 INSERT INTO t1 SELECT randomblob(800); |
| 1468 INSERT INTO t1 SELECT randomblob(800); | 1391 INSERT INTO t1 SELECT randomblob(800); |
| 1469 INSERT INTO t1 SELECT randomblob(800); | 1392 INSERT INTO t1 SELECT randomblob(800); |
| 1470 } | 1393 } |
| 1471 } {wal} | 1394 } {wal} |
| 1472 do_test wal-22.%PGSZ%.$tn.2 { sql2 { PRAGMA integrity_check } } {ok} | 1395 do_test wal-22.%PGSZ%.$tn.2 { sql2 { PRAGMA integrity_check } } {ok} |
| 1473 do_test wal-22.%PGSZ%.$tn.3 { | 1396 do_test wal-22.%PGSZ%.$tn.3 { |
| 1474 sql1 {PRAGMA wal_checkpoint} | 1397 sql1 {PRAGMA wal_checkpoint} |
| 1475 expr {[file size test.db] % %PGSZ%} | 1398 expr {[file size test.db] % %PGSZ%} |
| 1476 } {0} | 1399 } {0} |
| 1477 }] | 1400 }] |
| 1478 } | 1401 } |
| 1402 incr ::do_not_use_codec -1 |
| 1479 | 1403 |
| 1480 #------------------------------------------------------------------------- | 1404 #------------------------------------------------------------------------- |
| 1481 # Test that when 1 or more pages are recovered from a WAL file, | 1405 # Test that when 1 or more pages are recovered from a WAL file, |
| 1482 # sqlite3_log() is invoked to report this to the user. | 1406 # sqlite3_log() is invoked to report this to the user. |
| 1483 # | 1407 # |
| 1484 ifcapable curdir { | 1408 ifcapable curdir { |
| 1485 set walfile [file nativename [file join [get_pwd] test.db-wal]] | 1409 set walfile [file nativename [file join [get_pwd] test.db-wal]] |
| 1486 } else { | 1410 } else { |
| 1487 set walfile test.db-wal | 1411 set walfile test.db-wal |
| 1488 } | 1412 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1583 sqlite3 db test.db | 1507 sqlite3 db test.db |
| 1584 do_test wal-25.$mode { | 1508 do_test wal-25.$mode { |
| 1585 db eval "PRAGMA journal_mode=$mode" | 1509 db eval "PRAGMA journal_mode=$mode" |
| 1586 db eval {ATTACH 'test2.db' AS t2; PRAGMA journal_mode=WAL;} | 1510 db eval {ATTACH 'test2.db' AS t2; PRAGMA journal_mode=WAL;} |
| 1587 } {wal} | 1511 } {wal} |
| 1588 db close | 1512 db close |
| 1589 } | 1513 } |
| 1590 | 1514 |
| 1591 test_restore_config_pagecache | 1515 test_restore_config_pagecache |
| 1592 finish_test | 1516 finish_test |
| OLD | NEW |