OLD | NEW |
1 # 2010 April 13 | 1 # 2010 April 13 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 do_multiclient_test tn { | 190 do_multiclient_test tn { |
191 setup_and_attach_aux | 191 setup_and_attach_aux |
192 do_test 2.1.$tn.1 { | 192 do_test 2.1.$tn.1 { |
193 sql1 { | 193 sql1 { |
194 CREATE TABLE t1(a, b); | 194 CREATE TABLE t1(a, b); |
195 INSERT INTO t1 VALUES(1, 2); | 195 INSERT INTO t1 VALUES(1, 2); |
196 CREATE TABLE aux.t2(a, b); | 196 CREATE TABLE aux.t2(a, b); |
197 INSERT INTO t2 VALUES(1, 2); | 197 INSERT INTO t2 VALUES(1, 2); |
198 } | 198 } |
199 } {} | 199 } {} |
200 do_test 2.2.$tn.2 { file_page_counts } {1 5 1 5} | 200 do_test 2.2.$tn.2 { file_page_counts } {1 3 1 3} |
201 do_test 2.1.$tn.3 { code1 { do_wal_checkpoint db } } {0 5 5} | 201 do_test 2.1.$tn.3 { code1 { do_wal_checkpoint db } } {0 3 3} |
202 do_test 2.1.$tn.4 { file_page_counts } {2 5 2 5} | 202 do_test 2.1.$tn.4 { file_page_counts } {2 3 2 3} |
203 } | 203 } |
204 | 204 |
205 do_multiclient_test tn { | 205 do_multiclient_test tn { |
206 setup_and_attach_aux | 206 setup_and_attach_aux |
207 do_test 2.2.$tn.1 { | 207 do_test 2.2.$tn.1 { |
208 execsql { | 208 execsql { |
209 CREATE TABLE t1(a, b); | 209 CREATE TABLE t1(a, b); |
210 INSERT INTO t1 VALUES(1, 2); | 210 INSERT INTO t1 VALUES(1, 2); |
211 CREATE TABLE aux.t2(a, b); | 211 CREATE TABLE aux.t2(a, b); |
212 INSERT INTO t2 VALUES(1, 2); | 212 INSERT INTO t2 VALUES(1, 2); |
213 INSERT INTO t2 VALUES(3, 4); | 213 INSERT INTO t2 VALUES(3, 4); |
214 } | 214 } |
215 } {} | 215 } {} |
216 do_test 2.2.$tn.2 { file_page_counts } {1 5 1 7} | 216 do_test 2.2.$tn.2 { file_page_counts } {1 3 1 4} |
217 do_test 2.2.$tn.3 { sql2 { BEGIN; SELECT * FROM t1 } } {1 2} | 217 do_test 2.2.$tn.3 { sql2 { BEGIN; SELECT * FROM t1 } } {1 2} |
218 do_test 2.2.$tn.4 { code1 { do_wal_checkpoint db -mode restart } } {1 5 5} | 218 do_test 2.2.$tn.4 { code1 { do_wal_checkpoint db -mode restart } } {1 3 3} |
219 do_test 2.2.$tn.5 { file_page_counts } {2 5 2 7} | 219 do_test 2.2.$tn.5 { file_page_counts } {2 3 2 4} |
220 } | 220 } |
221 | 221 |
222 do_multiclient_test tn { | 222 do_multiclient_test tn { |
223 setup_and_attach_aux | 223 setup_and_attach_aux |
224 do_test 2.3.$tn.1 { | 224 do_test 2.3.$tn.1 { |
225 execsql { | 225 execsql { |
226 CREATE TABLE t1(a, b); | 226 CREATE TABLE t1(a, b); |
227 INSERT INTO t1 VALUES(1, 2); | 227 INSERT INTO t1 VALUES(1, 2); |
228 CREATE TABLE aux.t2(a, b); | 228 CREATE TABLE aux.t2(a, b); |
229 INSERT INTO t2 VALUES(1, 2); | 229 INSERT INTO t2 VALUES(1, 2); |
230 } | 230 } |
231 } {} | 231 } {} |
232 do_test 2.3.$tn.2 { file_page_counts } {1 5 1 5} | 232 do_test 2.3.$tn.2 { file_page_counts } {1 3 1 3} |
233 do_test 2.3.$tn.3 { sql2 { BEGIN; SELECT * FROM t1 } } {1 2} | 233 do_test 2.3.$tn.3 { sql2 { BEGIN; SELECT * FROM t1 } } {1 2} |
234 do_test 2.3.$tn.4 { sql1 { INSERT INTO t1 VALUES(3, 4) } } {} | 234 do_test 2.3.$tn.4 { sql1 { INSERT INTO t1 VALUES(3, 4) } } {} |
235 do_test 2.3.$tn.5 { sql1 { INSERT INTO t2 VALUES(3, 4) } } {} | 235 do_test 2.3.$tn.5 { sql1 { INSERT INTO t2 VALUES(3, 4) } } {} |
236 do_test 2.3.$tn.6 { file_page_counts } {1 7 1 7} | 236 do_test 2.3.$tn.6 { file_page_counts } {1 4 1 4} |
237 do_test 2.3.$tn.7 { code1 { do_wal_checkpoint db -mode full } } {1 7 5} | 237 do_test 2.3.$tn.7 { code1 { do_wal_checkpoint db -mode full } } {1 4 3} |
238 do_test 2.3.$tn.8 { file_page_counts } {1 7 2 7} | 238 |
| 239 # The checkpoint above only writes page 1 of the db file. The other |
| 240 # page (page 2) is locked by the read-transaction opened by the |
| 241 # [sql2] commmand above. So normally, the db is 1 page in size here. |
| 242 # However, in mmap() mode, the db is pre-allocated to 2 pages at the |
| 243 # start of the checkpoint, even though page 2 cannot be written. |
| 244 set nDb 2 |
| 245 if {[permutation]!="mmap"} {set nDb 1} |
| 246 ifcapable !mmap {set nDb 1} |
| 247 do_test 2.3.$tn.8 { file_page_counts } [list $nDb 4 2 4] |
239 } | 248 } |
240 | 249 |
241 # Check that checkpoints block on the correct locks. And respond correctly | 250 # Check that checkpoints block on the correct locks. And respond correctly |
242 # if they cannot obtain those locks. There are three locks that a checkpoint | 251 # if they cannot obtain those locks. There are three locks that a checkpoint |
243 # may block on (in the following order): | 252 # may block on (in the following order): |
244 # | 253 # |
245 # 1. The writer lock: FULL and RESTART checkpoints block until any writer | 254 # 1. The writer lock: FULL and RESTART checkpoints block until any writer |
246 # process releases its lock. | 255 # process releases its lock. |
247 # | 256 # |
248 # 2. Readers using part of the log file. FULL and RESTART checkpoints block | 257 # 2. Readers using part of the log file. FULL and RESTART checkpoints block |
249 # until readers using part (but not all) of the log file have finished. | 258 # until readers using part (but not all) of the log file have finished. |
250 # | 259 # |
251 # 3. Readers using any of the log file. After copying data into the | 260 # 3. Readers using any of the log file. After copying data into the |
252 # database file, RESTART checkpoints block until readers using any part | 261 # database file, RESTART checkpoints block until readers using any part |
253 # of the log file have finished. | 262 # of the log file have finished. |
254 # | 263 # |
255 # This test case involves running a checkpoint while there exist other | 264 # This test case involves running a checkpoint while there exist other |
256 # processes holding all three types of locks. | 265 # processes holding all three types of locks. |
257 # | 266 # |
258 foreach {tn1 checkpoint busy_on ckpt_expected expected} { | 267 foreach {tn1 checkpoint busy_on ckpt_expected expected} { |
259 1 PASSIVE - {0 5 5} - | 268 1 PASSIVE - {0 3 3} - |
260 2 TYPO - {0 5 5} - | 269 2 TYPO - {0 3 3} - |
261 | 270 |
262 3 FULL - {0 7 7} 2 | 271 3 FULL - {0 4 4} 2 |
263 4 FULL 1 {1 5 5} 1 | 272 4 FULL 1 {1 3 3} 1 |
264 5 FULL 2 {1 7 5} 2 | 273 5 FULL 2 {1 4 3} 2 |
265 6 FULL 3 {0 7 7} 2 | 274 6 FULL 3 {0 4 4} 2 |
266 | 275 |
267 7 RESTART - {0 7 7} 3 | 276 7 RESTART - {0 4 4} 3 |
268 8 RESTART 1 {1 5 5} 1 | 277 8 RESTART 1 {1 3 3} 1 |
269 9 RESTART 2 {1 7 5} 2 | 278 9 RESTART 2 {1 4 3} 2 |
270 10 RESTART 3 {1 7 7} 3 | 279 10 RESTART 3 {1 4 4} 3 |
271 | 280 |
272 } { | 281 } { |
273 do_multiclient_test tn { | 282 do_multiclient_test tn { |
274 setup_and_attach_aux | 283 setup_and_attach_aux |
275 | 284 |
276 proc busyhandler {x} { | 285 proc busyhandler {x} { |
277 set ::max_busyhandler $x | 286 set ::max_busyhandler $x |
278 if {$::busy_on!="-" && $x==$::busy_on} { return 1 } | 287 if {$::busy_on!="-" && $x==$::busy_on} { return 1 } |
279 switch -- $x { | 288 switch -- $x { |
280 1 { sql2 "COMMIT ; BEGIN ; SELECT * FROM t1" } | 289 1 { sql2 "COMMIT ; BEGIN ; SELECT * FROM t1" } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 code3 {sqlite3 db3 test.db} | 345 code3 {sqlite3 db3 test.db} |
337 | 346 |
338 do_test 3.$tn.5 { sql3 { PRAGMA journal_mode } } {wal} | 347 do_test 3.$tn.5 { sql3 { PRAGMA journal_mode } } {wal} |
339 | 348 |
340 do_test 3.$tn.6 { code3 { do_wal_checkpoint db3 } } {0 0 0} | 349 do_test 3.$tn.6 { code3 { do_wal_checkpoint db3 } } {0 0 0} |
341 } | 350 } |
342 } | 351 } |
343 | 352 |
344 | 353 |
345 finish_test | 354 finish_test |
346 | |
OLD | NEW |