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 #***********************************************************************
12 # This file contains tests for resumption of RBU operations in the
13 # case where the previous RBU process crashed.
16 source [file join [file dirname [info script]] rbu_common.tcl]
17 set ::testprefix rburesume
19 forcedelete test.db-shm test.db-oal
21 CREATE TABLE t1(a PRIMARY KEY, b, c);
22 CREATE INDEX t1a ON t1(a);
23 CREATE INDEX t1b ON t1(b);
24 CREATE INDEX t1c ON t1(c);
26 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<50
28 INSERT INTO t1 SELECT randomblob(50), randomblob(75), randomblob(100) FROM s;
33 list [file exists test.db] \
34 [file exists test.db-wal] \
35 [file exists test.db-shm] \
36 [file exists test.db-oal]
39 # Each iteration of the following loop:
41 # 1. Restores the db to the state it was in following test case 1.0
42 # 2. Opens an RBU vacuum and steps it $n times.
43 # 3. Closes the RBU vacuum handled opened in (2).
44 # 4. Opens a second RBU vacuum handle, resumes and completes the vacuum op.
46 # The loop runs until $n is large enough that step (2) vacuums the entire
49 for {set n 1} {$n < 5000} {incr n} {
52 sqlite3rbu_vacuum rbu test.db state.db
53 for {set i 0} {$i<$n} {incr i} {
55 if {$rc == "SQLITE_DONE"} break
58 if {$rc == "SQLITE_DONE"} break
61 sqlite3rbu_vacuum rbu test.db state.db
62 while {[rbu step]=="SQLITE_OK"} {}
69 SELECT count(*) FROM t1;
70 PRAGMA integrity_check;
76 # Each iteration of this loop:
78 # 1. Restores the db to the state it was in following test case 1.0
79 # 2. Opens an RBU vacuum and steps it $n times.
80 # 3. Takes a copy of all database files and the state db.
81 # 4. Opens a second RBU vacuum handle on the copy, resumes and completes the
84 # The loop runs until $n is large enough that step (2) vacuums the entire
87 for {set n 1} {$n < 5000} {incr n} {
89 forcedelete state.db state.db-shm state.db-oal state.db-wal
90 sqlite3rbu_vacuum rbu test.db state.db
91 for {set i 0} {$i<$n} {incr i} {
93 if {$rc == "SQLITE_DONE"} break
95 if {$rc == "SQLITE_DONE"} {
100 foreach f {test.db test.db-oal test.db-wal test.db-shm test.db-vacuum} {
101 set f2 [string map [list test.db test.db2] $f]
102 if {[file exists $f]} {
108 forcecopy state.db state.db2
112 sqlite3rbu_vacuum rbu test.db2 state.db2
113 while {[rbu step]=="SQLITE_OK"} {}
120 SELECT count(*) FROM t1;
121 PRAGMA integrity_check;
127 # Each iteration of this loop:
129 # 1. Restores the db to the state it was in following test case 1.0
130 # 2. Opens an RBU vacuum and steps it 10 times. Then closes it.
131 # 2. Opens an RBU vacuum and steps it $n times.
132 # 3. Takes a copy of all database files and the state db.
133 # 4. Opens a second RBU vacuum handle on the copy, resumes and completes the
136 # The loop runs until $n is large enough that step (3) vacuums the entire
139 for {set n 1} {$n < 5000} {incr n} {
141 forcedelete state.db state.db-shm state.db-oal state.db-wal
143 sqlite3rbu_vacuum rbu test.db state.db
144 for {set i 0} {$i<10} {incr i} {
149 sqlite3rbu_vacuum rbu test.db state.db
150 for {set i 0} {$i<$n} {incr i} {
152 if {$rc == "SQLITE_DONE"} break
154 if {$rc == "SQLITE_DONE"} {
159 foreach f {test.db test.db-oal test.db-wal test.db-shm test.db-vacuum} {
160 set f2 [string map [list test.db test.db2] $f]
161 if {[file exists $f]} {
167 forcecopy state.db state.db2
171 sqlite3rbu_vacuum rbu test.db2 state.db2
172 while {[rbu step]=="SQLITE_OK"} {}
179 SELECT count(*) FROM t1;
180 PRAGMA integrity_check;
190 CREATE TABLE data_t1(a, b, c, rbu_control);
192 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<10
195 SELECT randomblob(50), randomblob(75), randomblob(100), 0 FROM s;
200 # Each iteration of this loop:
202 # 1. Restores the db to the state it was in following test case 1.0
203 # 2. Opens an RBU handle to apply the RBU update created in test case 2.0.
204 # 3. Steps the RBU handle $n times.
205 # 4. Takes a copy of all database files and the state db.
206 # 5. Opens a second RBU handle on the copy, resumes and completes the
207 # RBU op. Checks it worked as expected.
209 # The loop runs until $n is large enough that step (3) applies the entire
212 for {set n 1} {$n < 5000} {incr n} {
214 forcedelete state.db state.db-shm state.db-oal state.db-wal
215 sqlite3rbu rbu test.db rbu.db state.db
217 for {set i 0} {$i<$n} {incr i} {
219 if {$rc == "SQLITE_DONE"} break
221 if {$rc == "SQLITE_DONE"} {
226 foreach f {test.db test.db-oal test.db-wal test.db-shm test.db-vacuum} {
227 set f2 [string map [list test.db test.db2] $f]
228 if {[file exists $f]} {
234 forcecopy state.db state.db2
238 sqlite3rbu rbu test.db2 rbu.db state.db2
239 while {[rbu step]=="SQLITE_OK"} {}
246 SELECT count(*) FROM t1;
247 PRAGMA integrity_check;