rburesume.test 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. source [file join [file dirname [info script]] rbu_common.tcl]
  18. if_no_rbu_support { finish_test ; return }
  19. set ::testprefix rburesume
  20. forcedelete test.db-shm test.db-oal
  21. do_execsql_test 1.0 {
  22. CREATE TABLE t1(a PRIMARY KEY, b, c);
  23. CREATE INDEX t1a ON t1(a);
  24. CREATE INDEX t1b ON t1(b);
  25. CREATE INDEX t1c ON t1(c);
  26. WITH s(i) AS (
  27. VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<50
  28. )
  29. INSERT INTO t1 SELECT randomblob(50), randomblob(75), randomblob(100) FROM s;
  30. }
  31. db_save_and_close
  32. do_test 1.1 {
  33. list [file exists test.db] \
  34. [file exists test.db-wal] \
  35. [file exists test.db-shm] \
  36. [file exists test.db-oal]
  37. } {1 0 0 0}
  38. # Each iteration of the following loop:
  39. #
  40. # 1. Restores the db to the state it was in following test case 1.0
  41. # 2. Opens an RBU vacuum and steps it $n times.
  42. # 3. Closes the RBU vacuum handled opened in (2).
  43. # 4. Opens a second RBU vacuum handle, resumes and completes the vacuum op.
  44. #
  45. # The loop runs until $n is large enough that step (2) vacuums the entire
  46. # database.
  47. #
  48. for {set n 1} {$n < 5000} {incr n} {
  49. db_restore
  50. forcedelete state.db
  51. sqlite3rbu_vacuum rbu test.db state.db
  52. for {set i 0} {$i<$n} {incr i} {
  53. set rc [rbu step]
  54. if {$rc == "SQLITE_DONE"} break
  55. }
  56. rbu close
  57. if {$rc == "SQLITE_DONE"} break
  58. do_test 1.2.$n.1 {
  59. sqlite3rbu_vacuum rbu test.db state.db
  60. while {[rbu step]=="SQLITE_OK"} {}
  61. rbu close
  62. } {SQLITE_DONE}
  63. do_test 1.2.$n.2 {
  64. sqlite3 db2 test.db
  65. db2 eval {
  66. SELECT count(*) FROM t1;
  67. PRAGMA integrity_check;
  68. }
  69. } {50 ok}
  70. db2 close
  71. }
  72. # Each iteration of this loop:
  73. #
  74. # 1. Restores the db to the state it was in following test case 1.0
  75. # 2. Opens an RBU vacuum and steps it $n times.
  76. # 3. Takes a copy of all database files and the state db.
  77. # 4. Opens a second RBU vacuum handle on the copy, resumes and completes the
  78. # vacuum op.
  79. #
  80. # The loop runs until $n is large enough that step (2) vacuums the entire
  81. # database.
  82. #
  83. for {set n 1} {$n < 5000} {incr n} {
  84. db_restore
  85. forcedelete state.db state.db-shm state.db-oal state.db-wal
  86. sqlite3rbu_vacuum rbu test.db state.db
  87. for {set i 0} {$i<$n} {incr i} {
  88. set rc [rbu step]
  89. if {$rc == "SQLITE_DONE"} break
  90. }
  91. if {$rc == "SQLITE_DONE"} {
  92. rbu close
  93. break
  94. }
  95. foreach f {test.db test.db-oal test.db-wal test.db-vacuum} {
  96. set f2 [string map [list test.db test.db2] $f]
  97. if {[file exists $f]} {
  98. forcecopy $f $f2
  99. } else {
  100. forcedelete $f2
  101. }
  102. }
  103. forcecopy state.db state.db2
  104. rbu close
  105. do_test 1.3.$n.1 {
  106. sqlite3rbu_vacuum rbu test.db2 state.db2
  107. while {[rbu step]=="SQLITE_OK"} {}
  108. rbu close
  109. } {SQLITE_DONE}
  110. do_test 1.3.$n.2 {
  111. sqlite3 db2 test.db2
  112. db2 eval {
  113. SELECT count(*) FROM t1;
  114. PRAGMA integrity_check;
  115. }
  116. } {50 ok}
  117. db2 close
  118. }
  119. # Each iteration of this loop:
  120. #
  121. # 1. Restores the db to the state it was in following test case 1.0
  122. # 2. Opens an RBU vacuum and steps it 10 times. Then closes it.
  123. # 2. Opens an RBU vacuum and steps it $n times.
  124. # 3. Takes a copy of all database files and the state db.
  125. # 4. Opens a second RBU vacuum handle on the copy, resumes and completes the
  126. # vacuum op.
  127. #
  128. # The loop runs until $n is large enough that step (3) vacuums the entire
  129. # database.
  130. #
  131. for {set n 1} {$n < 5000} {incr n} {
  132. db_restore
  133. forcedelete state.db state.db-shm state.db-oal state.db-wal
  134. sqlite3rbu_vacuum rbu test.db state.db
  135. for {set i 0} {$i<10} {incr i} {
  136. rbu step
  137. }
  138. rbu close
  139. sqlite3rbu_vacuum rbu test.db state.db
  140. for {set i 0} {$i<$n} {incr i} {
  141. set rc [rbu step]
  142. if {$rc == "SQLITE_DONE"} break
  143. }
  144. if {$rc == "SQLITE_DONE"} {
  145. rbu close
  146. break
  147. }
  148. foreach f {test.db test.db-oal test.db-wal test.db-vacuum} {
  149. set f2 [string map [list test.db test.db2] $f]
  150. if {[file exists $f]} {
  151. forcecopy $f $f2
  152. } else {
  153. forcedelete $f2
  154. }
  155. }
  156. forcecopy state.db state.db2
  157. rbu close
  158. do_test 1.4.$n.1 {
  159. sqlite3rbu_vacuum rbu test.db2 state.db2
  160. while {[rbu step]=="SQLITE_OK"} {}
  161. rbu close
  162. } {SQLITE_DONE}
  163. do_test 1.4.$n.2 {
  164. sqlite3 db2 test.db2
  165. db2 eval {
  166. SELECT count(*) FROM t1;
  167. PRAGMA integrity_check;
  168. }
  169. } {50 ok}
  170. db2 close
  171. }
  172. forcedelete rbu.db
  173. do_test 2.0 {
  174. sqlite3 db2 rbu.db
  175. db2 eval {
  176. CREATE TABLE data_t1(a, b, c, rbu_control);
  177. WITH s(i) AS (
  178. VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<10
  179. )
  180. INSERT INTO data_t1
  181. SELECT randomblob(50), randomblob(75), randomblob(100), 0 FROM s;
  182. }
  183. db2 close
  184. } {}
  185. # Each iteration of this loop:
  186. #
  187. # 1. Restores the db to the state it was in following test case 1.0
  188. # 2. Opens an RBU handle to apply the RBU update created in test case 2.0.
  189. # 3. Steps the RBU handle $n times.
  190. # 4. Takes a copy of all database files and the state db.
  191. # 5. Opens a second RBU handle on the copy, resumes and completes the
  192. # RBU op. Checks it worked as expected.
  193. #
  194. # The loop runs until $n is large enough that step (3) applies the entire
  195. # update.
  196. #
  197. for {set n 1} {$n < 5000} {incr n} {
  198. db_restore
  199. forcedelete state.db state.db-shm state.db-oal state.db-wal
  200. sqlite3rbu rbu test.db rbu.db state.db
  201. for {set i 0} {$i<$n} {incr i} {
  202. set rc [rbu step]
  203. if {$rc == "SQLITE_DONE"} break
  204. }
  205. if {$rc == "SQLITE_DONE"} {
  206. rbu close
  207. break
  208. }
  209. foreach f {test.db test.db-oal test.db-wal test.db-vacuum} {
  210. set f2 [string map [list test.db test.db2] $f]
  211. if {[file exists $f]} {
  212. forcecopy $f $f2
  213. } else {
  214. forcedelete $f2
  215. }
  216. }
  217. forcecopy state.db state.db2
  218. rbu close
  219. do_test 2.$n.1 {
  220. sqlite3rbu rbu test.db2 rbu.db state.db2
  221. while {[rbu step]=="SQLITE_OK"} {}
  222. rbu close
  223. } {SQLITE_DONE}
  224. do_test 2.$n.2 {
  225. sqlite3 db2 test.db2
  226. db2 eval {
  227. SELECT count(*) FROM t1;
  228. PRAGMA integrity_check;
  229. }
  230. } {60 ok}
  231. db2 close
  232. }
  233. finish_test