wal9.test 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # 2012 October 15
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #***********************************************************************
  11. #
  12. # This test case tests that a problem causing a failing assert() has
  13. # been fixed. The problem occurred if a writer process with a subset
  14. # of the *shm file mapped rolled back a transaction begun after the
  15. # entire WAL file was checkpointed into the db file (i.e. a transaction
  16. # that would have restarted the WAL file from the beginning).
  17. #
  18. set testdir [file dirname $argv0]
  19. source $testdir/tester.tcl
  20. set testprefix wal9
  21. sqlite3 db2 test.db
  22. do_execsql_test 1.0 {
  23. PRAGMA page_size = 1024;
  24. PRAGMA journal_mode = WAL;
  25. PRAGMA wal_autocheckpoint = 0;
  26. CREATE TABLE t(x);
  27. } {wal 0}
  28. do_test 1.1 {
  29. execsql "SELECT * FROM t" db2
  30. } {}
  31. do_execsql_test 1.2 {
  32. BEGIN;
  33. INSERT INTO t VALUES(randomblob(100));
  34. INSERT INTO t SELECT randomblob(100) FROM t;
  35. INSERT INTO t SELECT randomblob(100) FROM t;
  36. INSERT INTO t SELECT randomblob(100) FROM t;
  37. INSERT INTO t SELECT randomblob(100) FROM t;
  38. INSERT INTO t SELECT randomblob(100) FROM t;
  39. INSERT INTO t SELECT randomblob(100) FROM t;
  40. INSERT INTO t SELECT randomblob(100) FROM t;
  41. INSERT INTO t SELECT randomblob(100) FROM t;
  42. INSERT INTO t SELECT randomblob(100) FROM t;
  43. INSERT INTO t SELECT randomblob(100) FROM t;
  44. INSERT INTO t SELECT randomblob(100) FROM t;
  45. INSERT INTO t SELECT randomblob(100) FROM t;
  46. INSERT INTO t SELECT randomblob(100) FROM t;
  47. INSERT INTO t SELECT randomblob(100) FROM t;
  48. INSERT INTO t SELECT randomblob(100) FROM t;
  49. INSERT INTO t SELECT randomblob(100) FROM t;
  50. INSERT INTO t SELECT randomblob(100) FROM t;
  51. COMMIT;
  52. } {}
  53. # Check file sizes are as expected. The real requirement here is that
  54. # the *shm file is now more than one chunk (>32KiB).
  55. #
  56. # The sizes of various files are slightly different in normal and
  57. # auto-vacuum mode.
  58. do_test 1.3 { file size test.db } {1024}
  59. do_test 1.4 { expr {[file size test.db-wal]>(1500*1024)} } {1}
  60. do_test 1.5 { expr {[file size test.db-shm]>32768} } {1}
  61. do_test 1.6 {
  62. foreach {a b c} [db eval {PRAGMA wal_checkpoint}] break
  63. list [expr {$a==0}] [expr {$b>14500}] [expr {$c>14500}] [expr {$b==$c}]
  64. } {1 1 1 1}
  65. # At this point connection [db2] has mapped the first 32KB of the *shm file
  66. # only. Because the entire WAL file has been checkpointed, it is not
  67. # necessary to map any more of the *-shm file to read or write the database
  68. # (since all data will be read directly from the db file).
  69. #
  70. # However, at one point if a transaction that had not yet written to the
  71. # WAL file was rolled back an assert() attempting to verify that the entire
  72. # *-shm file was mapped would fail. If NDEBUG was defined (and the assert()
  73. # disabled) this bug caused SQLite to ignore the return code of a mmap()
  74. # call.
  75. #
  76. do_test 1.7 {
  77. execsql {
  78. BEGIN;
  79. INSERT INTO t VALUES('hello');
  80. ROLLBACK;
  81. } db2
  82. } {}
  83. db2 close
  84. finish_test