3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
14 # This file contains tests for resumption of RBU operations in the
15 # case where the previous RBU process crashed.
18 source [file join [file dirname [info script]] rbu_common.tcl]
19 if_no_rbu_support { finish_test ; return }
20 set ::testprefix rburesume
22 forcedelete test.db-shm test.db-oal
24 CREATE TABLE t1(a PRIMARY KEY, b, c);
25 CREATE INDEX t1a ON t1(a);
26 CREATE INDEX t1b ON t1(b);
27 CREATE INDEX t1c ON t1(c);
29 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<50
31 INSERT INTO t1 SELECT randomblob(50), randomblob(75), randomblob(100) FROM s;
36 list [file exists test.db] \
37 [file exists test.db-wal] \
38 [file exists test.db-shm] \
39 [file exists test.db-oal]
42 # Each iteration of the following loop:
44 # 1. Restores the db to the state it was in following test case 1.0
45 # 2. Opens an RBU vacuum and steps it $n times.
46 # 3. Closes the RBU vacuum handled opened in (2).
47 # 4. Opens a second RBU vacuum handle, resumes and completes the vacuum op.
49 # The loop runs until $n is large enough that step (2) vacuums the entire
52 for {set n 1} {$n < 5000} {incr n} {
55 sqlite3rbu_vacuum rbu test.db state.db
56 for {set i 0} {$i<$n} {incr i} {
58 if {$rc == "SQLITE_DONE"} break
61 if {$rc == "SQLITE_DONE"} break
64 sqlite3rbu_vacuum rbu test.db state.db
65 while {[rbu step]=="SQLITE_OK"} {}
72 SELECT count(*) FROM t1;
73 PRAGMA integrity_check;
79 # Each iteration of this loop:
81 # 1. Restores the db to the state it was in following test case 1.0
82 # 2. Opens an RBU vacuum and steps it $n times.
83 # 3. Takes a copy of all database files and the state db.
84 # 4. Opens a second RBU vacuum handle on the copy, resumes and completes the
87 # The loop runs until $n is large enough that step (2) vacuums the entire
90 for {set n 1} {$n < 5000} {incr n} {
92 forcedelete state.db state.db-shm state.db-oal state.db-wal
93 sqlite3rbu_vacuum rbu test.db state.db
94 for {set i 0} {$i<$n} {incr i} {
96 if {$rc == "SQLITE_DONE"} break
98 if {$rc == "SQLITE_DONE"} {
103 foreach f {test.db test.db-oal test.db-wal test.db-vacuum} {
104 set f2 [string map [list test.db test.db2] $f]
105 if {[file exists $f]} {
111 forcecopy state.db state.db2
115 sqlite3rbu_vacuum rbu test.db2 state.db2
116 while {[rbu step]=="SQLITE_OK"} {}
123 SELECT count(*) FROM t1;
124 PRAGMA integrity_check;
130 # Each iteration of this loop:
132 # 1. Restores the db to the state it was in following test case 1.0
133 # 2. Opens an RBU vacuum and steps it 10 times. Then closes it.
134 # 2. Opens an RBU vacuum and steps it $n times.
135 # 3. Takes a copy of all database files and the state db.
136 # 4. Opens a second RBU vacuum handle on the copy, resumes and completes the
139 # The loop runs until $n is large enough that step (3) vacuums the entire
142 for {set n 1} {$n < 5000} {incr n} {
144 forcedelete state.db state.db-shm state.db-oal state.db-wal
146 sqlite3rbu_vacuum rbu test.db state.db
147 for {set i 0} {$i<10} {incr i} {
152 sqlite3rbu_vacuum rbu test.db state.db
153 for {set i 0} {$i<$n} {incr i} {
155 if {$rc == "SQLITE_DONE"} break
157 if {$rc == "SQLITE_DONE"} {
162 foreach f {test.db test.db-oal test.db-wal test.db-vacuum} {
163 set f2 [string map [list test.db test.db2] $f]
164 if {[file exists $f]} {
170 forcecopy state.db state.db2
174 sqlite3rbu_vacuum rbu test.db2 state.db2
175 while {[rbu step]=="SQLITE_OK"} {}
182 SELECT count(*) FROM t1;
183 PRAGMA integrity_check;
193 CREATE TABLE data_t1(a, b, c, rbu_control);
195 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<10
198 SELECT randomblob(50), randomblob(75), randomblob(100), 0 FROM s;
203 # Each iteration of this loop:
205 # 1. Restores the db to the state it was in following test case 1.0
206 # 2. Opens an RBU handle to apply the RBU update created in test case 2.0.
207 # 3. Steps the RBU handle $n times.
208 # 4. Takes a copy of all database files and the state db.
209 # 5. Opens a second RBU handle on the copy, resumes and completes the
210 # RBU op. Checks it worked as expected.
212 # The loop runs until $n is large enough that step (3) applies the entire
215 for {set n 1} {$n < 5000} {incr n} {
217 forcedelete state.db state.db-shm state.db-oal state.db-wal
218 sqlite3rbu rbu test.db rbu.db state.db
220 for {set i 0} {$i<$n} {incr i} {
222 if {$rc == "SQLITE_DONE"} break
224 if {$rc == "SQLITE_DONE"} {
229 foreach f {test.db test.db-oal test.db-wal test.db-vacuum} {
230 set f2 [string map [list test.db test.db2] $f]
231 if {[file exists $f]} {
237 forcecopy state.db state.db2
241 sqlite3rbu rbu test.db2 rbu.db state.db2
242 while {[rbu step]=="SQLITE_OK"} {}
249 SELECT count(*) FROM t1;
250 PRAGMA integrity_check;