blob: 83bae737dfa25988ed9103dd7fc5cbceb27177cf [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
mistachkinc60941f2012-09-13 01:51:02 +000021set testprefix zerodamage
drhf12b3f62011-12-21 14:42:29 +000022
drh60e4a742012-01-06 13:58:04 +000023ifcapable !vtab {
24 finish_test
25 return
26}
27
drhcb15f352011-12-23 01:04:17 +000028# POWERSAFE_OVERWRITE defaults to true
drhf12b3f62011-12-21 14:42:29 +000029#
30do_test zerodamage-1.0 {
drhcb15f352011-12-23 01:04:17 +000031 file_control_powersafe_overwrite db -1
drhf12b3f62011-12-21 14:42:29 +000032} {0 1}
33
34# Check the ability to turn zero-damage on and off.
35#
36do_test zerodamage-1.1 {
drhcb15f352011-12-23 01:04:17 +000037 file_control_powersafe_overwrite db 0
38 file_control_powersafe_overwrite db -1
drhf12b3f62011-12-21 14:42:29 +000039} {0 0}
40do_test zerodamage-1.2 {
drhcb15f352011-12-23 01:04:17 +000041 file_control_powersafe_overwrite db 1
42 file_control_powersafe_overwrite db -1
drhf12b3f62011-12-21 14:42:29 +000043} {0 1}
44
45# Run a transaction with zero-damage on, a small page size and a much larger
46# sectorsize. Verify that the maximum journal size is small - that the
47# rollback journal is not being padded.
48#
49do_test zerodamage-2.0 {
50 db close
51 testvfs tv -default 1
52 tv sectorsize 8192
drhcb15f352011-12-23 01:04:17 +000053 sqlite3 db file:test.db?psow=TRUE -uri 1
drhf12b3f62011-12-21 14:42:29 +000054 unset -nocomplain ::max_journal_size
55 set ::max_journal_size 0
56 proc xDeleteCallback {method file args} {
57 set sz [file size $file]
58 if {$sz>$::max_journal_size} {set ::max_journal_size $sz}
59 }
60 tv filter xDelete
61 tv script xDeleteCallback
drh24b64222013-04-25 11:58:36 +000062 load_static_extension db wholenumber
drhf12b3f62011-12-21 14:42:29 +000063 db eval {
64 PRAGMA page_size=1024;
65 PRAGMA journal_mode=DELETE;
66 PRAGMA cache_size=5;
67 CREATE VIRTUAL TABLE nums USING wholenumber;
68 CREATE TABLE t1(x, y);
69 INSERT INTO t1 SELECT value, randomblob(100) FROM nums
70 WHERE value BETWEEN 1 AND 400;
71 }
72 set ::max_journal_size 0
73 db eval {
74 UPDATE t1 SET y=randomblob(50) WHERE x=123;
75 }
drhcb15f352011-12-23 01:04:17 +000076 concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
dan69aedc82018-01-13 13:07:49 +000077} [list 0 1 [expr ([atomic_batch_write test.db]==0)*2576]]
drhf12b3f62011-12-21 14:42:29 +000078
79# Repeat the previous step with zero-damage turned off. This time the
80# maximum rollback journal size should be much larger.
81#
82do_test zerodamage-2.1 {
83 set ::max_journal_size 0
84 db close
drhcb15f352011-12-23 01:04:17 +000085 sqlite3 db file:test.db?psow=FALSE -uri 1
drhf12b3f62011-12-21 14:42:29 +000086 db eval {
87 UPDATE t1 SET y=randomblob(50) WHERE x=124;
88 }
drhcb15f352011-12-23 01:04:17 +000089 concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
dan69aedc82018-01-13 13:07:49 +000090} [list 0 0 [expr ([atomic_batch_write test.db]==0)*24704]]
drhf12b3f62011-12-21 14:42:29 +000091
dan05accd22016-04-27 18:54:49 +000092if {[wal_is_capable]} {
mistachkinc60941f2012-09-13 01:51:02 +000093 # Run a WAL-mode transaction with POWERSAFE_OVERWRITE on to verify that the
94 # WAL file does not get too big.
95 #
96 do_test zerodamage-3.0 {
97 db eval {
98 PRAGMA journal_mode=WAL;
99 }
100 db close
101 sqlite3 db file:test.db?psow=TRUE -uri 1
102 db eval {
103 UPDATE t1 SET y=randomblob(50) WHERE x=124;
104 }
105 file size test.db-wal
106 } {1080}
drhf12b3f62011-12-21 14:42:29 +0000107
mistachkinc60941f2012-09-13 01:51:02 +0000108 # Repeat the previous with POWERSAFE_OVERWRITE off. Verify that the WAL file
109 # is padded.
110 #
111 do_test zerodamage-3.1 {
112 db close
113 sqlite3 db file:test.db?psow=FALSE -uri 1
114 db eval {
drhe243de52016-03-08 15:14:26 +0000115 PRAGMA synchronous=FULL;
mistachkinc60941f2012-09-13 01:51:02 +0000116 UPDATE t1 SET y=randomblob(50) WHERE x=124;
117 }
118 file size test.db-wal
dandd973542014-02-13 19:27:08 +0000119 } {16800}
mistachkinc60941f2012-09-13 01:51:02 +0000120}
drh60e4a742012-01-06 13:58:04 +0000121
122finish_test