blob: 0e82ce3505edccb9a65d337fee237cb935b131f7 [file] [log] [blame]
drhf12b3f62011-12-21 14:42:29 +00001# 2011 December 21
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#
drhcb15f352011-12-23 01:04:17 +000012# This file implements tests of the SQLITE_IOCAP_POWERSAFE_OVERWRITE property
13# and the SQLITE_FCNTL_POWERSAFE_OVERWRITE file-control for manipulating it.
14#
15# The name of this file comes from the fact that we used to call the
16# POWERSAFE_OVERWRITE property ZERO_DAMAGE.
drhf12b3f62011-12-21 14:42:29 +000017#
18
19set testdir [file dirname $argv0]
20source $testdir/tester.tcl
21set testprefix wal5
22
drhcb15f352011-12-23 01:04:17 +000023# POWERSAFE_OVERWRITE defaults to true
drhf12b3f62011-12-21 14:42:29 +000024#
25do_test zerodamage-1.0 {
drhcb15f352011-12-23 01:04:17 +000026 file_control_powersafe_overwrite db -1
drhf12b3f62011-12-21 14:42:29 +000027} {0 1}
28
29# Check the ability to turn zero-damage on and off.
30#
31do_test zerodamage-1.1 {
drhcb15f352011-12-23 01:04:17 +000032 file_control_powersafe_overwrite db 0
33 file_control_powersafe_overwrite db -1
drhf12b3f62011-12-21 14:42:29 +000034} {0 0}
35do_test zerodamage-1.2 {
drhcb15f352011-12-23 01:04:17 +000036 file_control_powersafe_overwrite db 1
37 file_control_powersafe_overwrite db -1
drhf12b3f62011-12-21 14:42:29 +000038} {0 1}
39
40# Run a transaction with zero-damage on, a small page size and a much larger
41# sectorsize. Verify that the maximum journal size is small - that the
42# rollback journal is not being padded.
43#
44do_test zerodamage-2.0 {
45 db close
46 testvfs tv -default 1
47 tv sectorsize 8192
drhcb15f352011-12-23 01:04:17 +000048 sqlite3 db file:test.db?psow=TRUE -uri 1
drhf12b3f62011-12-21 14:42:29 +000049 unset -nocomplain ::max_journal_size
50 set ::max_journal_size 0
51 proc xDeleteCallback {method file args} {
52 set sz [file size $file]
53 if {$sz>$::max_journal_size} {set ::max_journal_size $sz}
54 }
55 tv filter xDelete
56 tv script xDeleteCallback
57 register_wholenumber_module db
58 db eval {
59 PRAGMA page_size=1024;
60 PRAGMA journal_mode=DELETE;
61 PRAGMA cache_size=5;
62 CREATE VIRTUAL TABLE nums USING wholenumber;
63 CREATE TABLE t1(x, y);
64 INSERT INTO t1 SELECT value, randomblob(100) FROM nums
65 WHERE value BETWEEN 1 AND 400;
66 }
67 set ::max_journal_size 0
68 db eval {
69 UPDATE t1 SET y=randomblob(50) WHERE x=123;
70 }
drhcb15f352011-12-23 01:04:17 +000071 concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
drhf12b3f62011-12-21 14:42:29 +000072} {0 1 2576}
73
74# Repeat the previous step with zero-damage turned off. This time the
75# maximum rollback journal size should be much larger.
76#
77do_test zerodamage-2.1 {
78 set ::max_journal_size 0
79 db close
drhcb15f352011-12-23 01:04:17 +000080 sqlite3 db file:test.db?psow=FALSE -uri 1
drhf12b3f62011-12-21 14:42:29 +000081 db eval {
82 UPDATE t1 SET y=randomblob(50) WHERE x=124;
83 }
drhcb15f352011-12-23 01:04:17 +000084 concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
drhf12b3f62011-12-21 14:42:29 +000085} {0 0 24704}
86
drhcb15f352011-12-23 01:04:17 +000087# Run a WAL-mode transaction with POWERSAFE_OVERWRITE on to verify that the
drhf12b3f62011-12-21 14:42:29 +000088# WAL file does not get too big.
89#
90do_test zerodamage-3.0 {
91 db eval {
92 PRAGMA journal_mode=WAL;
93 }
94 db close
drhcb15f352011-12-23 01:04:17 +000095 sqlite3 db file:test.db?psow=TRUE -uri 1
drhf12b3f62011-12-21 14:42:29 +000096 db eval {
97 UPDATE t1 SET y=randomblob(50) WHERE x=124;
98 }
99 file size test.db-wal
100} {1080}
101
drhcb15f352011-12-23 01:04:17 +0000102# Repeat the previous with POWERSAFE_OVERWRITE off. Verify that the WAL file
drhf12b3f62011-12-21 14:42:29 +0000103# is padded.
104#
105do_test zerodamage-3.1 {
106 db close
drhcb15f352011-12-23 01:04:17 +0000107 sqlite3 db file:test.db?psow=FALSE -uri 1
drhf12b3f62011-12-21 14:42:29 +0000108 db eval {
109 UPDATE t1 SET y=randomblob(50) WHERE x=124;
110 }
111 file size test.db-wal
112} {8416}