Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/rbu/rbu_common.tcl # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / rbu / rbu_common.tcl` 120 lines ยท 3248 bytes Raw Blame History 1 # 2015 Aug 8 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 13 if {![info exists testdir]} { 14 set testdir [file join [file dirname [info script]] .. .. test] 15 } 16 source $testdir/tester.tcl 17 18 proc if_no_rbu_support {tcl} { 19 set bOk 1 20 ifcapable !rbu { set bOk 0 } 21 if {[permutation]=="journaltest"} { set bOk 0 } 22 if {$bOk==0} { 23 set c [catch {uplevel 1 $tcl} r] 24 return -code $c $r 25 } 26 } 27 28 proc check_prestep_state {target state} { 29 set oal_exists [file exists $target-oal] 30 set wal_exists [file exists $target-wal] 31 set progress [rbu progress] 32 33 if {($progress==0 && $state!="oal" && $state!="done") 34 || ($oal_exists && $wal_exists) 35 || ($progress>0 && $state=="oal" && (!$oal_exists || $wal_exists)) 36 || ($state=="move" && (!$oal_exists || $wal_exists)) 37 || ($state=="checkpoint" && ($oal_exists || !$wal_exists)) 38 || ($state=="done" && ($oal_exists && $progress!=0)) 39 } { 40 error "B: state=$state progress=$progress oal=$oal_exists wal=$wal_exists" 41 } 42 } 43 44 proc check_poststep_state {rc target state} { 45 if {$rc=="SQLITE_OK" || $rc=="SQLITE_DONE"} { 46 set oal_exists [file exists $target-oal] 47 set wal_exists [file exists $target-wal] 48 if {$state=="move" && ($oal_exists || !$wal_exists)} { 49 error "A: state=$state progress=$progress oal=$oal_exists wal=$wal_exists" 50 } 51 } 52 } 53 54 # Run the RBU in file $rbu on target database $target until completion. 55 # 56 proc run_rbu {target rbu} { 57 sqlite3rbu rbu $target $rbu 58 while 1 { 59 set state [rbu state] 60 61 check_prestep_state $target $state 62 set rc [rbu step] 63 check_poststep_state $rc $target $state 64 65 if {$rc!="SQLITE_OK"} break 66 } 67 rbu close 68 } 69 70 proc step_rbu {target rbu} { 71 while 1 { 72 sqlite3rbu rbu $target $rbu 73 set state [rbu state] 74 check_prestep_state $target $state 75 set rc [rbu step] 76 check_poststep_state $rc $target $state 77 rbu close 78 if {$rc != "SQLITE_OK"} break 79 } 80 set rc 81 } 82 83 proc step_rbu_legacy {target rbu} { 84 while 1 { 85 sqlite3rbu rbu $target $rbu 86 set state [rbu state] 87 check_prestep_state $target $state 88 set rc [rbu step] 89 check_poststep_state $rc $target $state 90 rbu close 91 if {$rc != "SQLITE_OK"} break 92 sqlite3 tmpdb $rbu 93 tmpdb eval { DELETE FROM rbu_state WHERE k==10 } 94 tmpdb close 95 } 96 set rc 97 } 98 99 proc do_rbu_vacuum_test {tn step {statedb state.db}} { 100 forcedelete $statedb 101 if {$statedb=="" && $step==1} breakpoint 102 uplevel [list do_test $tn.1 [string map [list %state% $statedb %step% $step] { 103 if {%step%==0} { sqlite3rbu_vacuum rbu test.db {%state%}} 104 while 1 { 105 if {%step%==1} { sqlite3rbu_vacuum rbu test.db {%state%}} 106 set state [rbu state] 107 check_prestep_state test.db $state 108 set rc [rbu step] 109 check_poststep_state $rc test.db $state 110 if {$rc!="SQLITE_OK"} break 111 if {%step%==1} { rbu close } 112 } 113 rbu close 114 }] {SQLITE_DONE}] 115 116 uplevel [list do_execsql_test $tn.2 { 117 PRAGMA integrity_check 118 } ok] 119 } 120