interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / rbu / rburesume.test

256 lines · 6441 bytes Raw Blame History
1# 2017 January 13
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# TESTRUNNER: slow
13#
14# This file contains tests for resumption of RBU operations in the
15# case where the previous RBU process crashed.
16#
17
18source [file join [file dirname [info script]] rbu_common.tcl]
19if_no_rbu_support { finish_test ; return }
20set ::testprefix rburesume
21
22forcedelete test.db-shm test.db-oal
23do_execsql_test 1.0 {
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);
28 WITH s(i) AS (
29 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<50
30 )
31 INSERT INTO t1 SELECT randomblob(50), randomblob(75), randomblob(100) FROM s;
32}
33db_save_and_close
34
35do_test 1.1 {
36 list [file exists test.db] \
37 [file exists test.db-wal] \
38 [file exists test.db-shm] \
39 [file exists test.db-oal]
40} {1 0 0 0}
41
42# Each iteration of the following loop:
43#
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.
48#
49# The loop runs until $n is large enough that step (2) vacuums the entire
50# database.
51#
52for {set n 1} {$n < 5000} {incr n} {
53 db_restore
54 forcedelete state.db
55 sqlite3rbu_vacuum rbu test.db state.db
56 for {set i 0} {$i<$n} {incr i} {
57 set rc [rbu step]
58 if {$rc == "SQLITE_DONE"} break
59 }
60 rbu close
61 if {$rc == "SQLITE_DONE"} break
62
63 do_test 1.2.$n.1 {
64 sqlite3rbu_vacuum rbu test.db state.db
65 while {[rbu step]=="SQLITE_OK"} {}
66 rbu close
67 } {SQLITE_DONE}
68
69 do_test 1.2.$n.2 {
70 sqlite3 db2 test.db
71 db2 eval {
72 SELECT count(*) FROM t1;
73 PRAGMA integrity_check;
74 }
75 } {50 ok}
76 db2 close
77}
78
79# Each iteration of this loop:
80#
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
85# vacuum op.
86#
87# The loop runs until $n is large enough that step (2) vacuums the entire
88# database.
89#
90for {set n 1} {$n < 5000} {incr n} {
91 db_restore
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} {
95 set rc [rbu step]
96 if {$rc == "SQLITE_DONE"} break
97 }
98 if {$rc == "SQLITE_DONE"} {
99 rbu close
100 break
101 }
102
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]} {
106 forcecopy $f $f2
107 } else {
108 forcedelete $f2
109 }
110 }
111 forcecopy state.db state.db2
112 rbu close
113
114 do_test 1.3.$n.1 {
115 sqlite3rbu_vacuum rbu test.db2 state.db2
116 while {[rbu step]=="SQLITE_OK"} {}
117 rbu close
118 } {SQLITE_DONE}
119
120 do_test 1.3.$n.2 {
121 sqlite3 db2 test.db2
122 db2 eval {
123 SELECT count(*) FROM t1;
124 PRAGMA integrity_check;
125 }
126 } {50 ok}
127 db2 close
128}
129
130# Each iteration of this loop:
131#
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
137# vacuum op.
138#
139# The loop runs until $n is large enough that step (3) vacuums the entire
140# database.
141#
142for {set n 1} {$n < 5000} {incr n} {
143 db_restore
144 forcedelete state.db state.db-shm state.db-oal state.db-wal
145
146 sqlite3rbu_vacuum rbu test.db state.db
147 for {set i 0} {$i<10} {incr i} {
148 rbu step
149 }
150 rbu close
151
152 sqlite3rbu_vacuum rbu test.db state.db
153 for {set i 0} {$i<$n} {incr i} {
154 set rc [rbu step]
155 if {$rc == "SQLITE_DONE"} break
156 }
157 if {$rc == "SQLITE_DONE"} {
158 rbu close
159 break
160 }
161
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]} {
165 forcecopy $f $f2
166 } else {
167 forcedelete $f2
168 }
169 }
170 forcecopy state.db state.db2
171 rbu close
172
173 do_test 1.4.$n.1 {
174 sqlite3rbu_vacuum rbu test.db2 state.db2
175 while {[rbu step]=="SQLITE_OK"} {}
176 rbu close
177 } {SQLITE_DONE}
178
179 do_test 1.4.$n.2 {
180 sqlite3 db2 test.db2
181 db2 eval {
182 SELECT count(*) FROM t1;
183 PRAGMA integrity_check;
184 }
185 } {50 ok}
186 db2 close
187}
188
189forcedelete rbu.db
190do_test 2.0 {
191 sqlite3 db2 rbu.db
192 db2 eval {
193 CREATE TABLE data_t1(a, b, c, rbu_control);
194 WITH s(i) AS (
195 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<10
196 )
197 INSERT INTO data_t1
198 SELECT randomblob(50), randomblob(75), randomblob(100), 0 FROM s;
199 }
200 db2 close
201} {}
202
203# Each iteration of this loop:
204#
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.
211#
212# The loop runs until $n is large enough that step (3) applies the entire
213# update.
214#
215for {set n 1} {$n < 5000} {incr n} {
216 db_restore
217 forcedelete state.db state.db-shm state.db-oal state.db-wal
218 sqlite3rbu rbu test.db rbu.db state.db
219
220 for {set i 0} {$i<$n} {incr i} {
221 set rc [rbu step]
222 if {$rc == "SQLITE_DONE"} break
223 }
224 if {$rc == "SQLITE_DONE"} {
225 rbu close
226 break
227 }
228
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]} {
232 forcecopy $f $f2
233 } else {
234 forcedelete $f2
235 }
236 }
237 forcecopy state.db state.db2
238 rbu close
239
240 do_test 2.$n.1 {
241 sqlite3rbu rbu test.db2 rbu.db state.db2
242 while {[rbu step]=="SQLITE_OK"} {}
243 rbu close
244 } {SQLITE_DONE}
245
246 do_test 2.$n.2 {
247 sqlite3 db2 test.db2
248 db2 eval {
249 SELECT count(*) FROM t1;
250 PRAGMA integrity_check;
251 }
252 } {60 ok}
253 db2 close
254}
255
256finish_test