MCPcopy
hub / github.com/etcd-io/bbolt / MustCheck

Method MustCheck

internal/btesting/btesting.go:134–167  ·  view source on GitHub ↗

MustCheck runs a consistency check on the database and panics if any errors are found.

()

Source from the content-addressed store, hash-verified

132
133// MustCheck runs a consistency check on the database and panics if any errors are found.
134func (db *DB) MustCheck() {
135 err := db.View(func(tx *bolt.Tx) error {
136 // Collect all the errors.
137 var errors []error
138 for err := range tx.Check() {
139 errors = append(errors, err)
140 if len(errors) > 10 {
141 break
142 }
143 }
144
145 // If errors occurred, copy the DB and print the errors.
146 if len(errors) > 0 {
147 var path = filepath.Join(db.t.TempDir(), "db.backup")
148 err := tx.CopyFile(path, 0600)
149 require.NoError(db.t, err)
150
151 // Print errors.
152 fmt.Print("\n\n")
153 fmt.Printf("consistency check failed (%d errors)\n", len(errors))
154 for _, err := range errors {
155 fmt.Println(err)
156 }
157 fmt.Println("")
158 fmt.Println("db saved to:")
159 fmt.Println(path)
160 fmt.Print("\n\n")
161 os.Exit(-1)
162 }
163
164 return nil
165 })
166 require.NoError(db.t, err)
167}
168
169// Fill - fills the DB using numTx transactions and numKeysPerTx.
170func (db *DB) Fill(bucket []byte, numTx int, numKeysPerTx int,

Callers 10

PostTestCleanupMethod · 0.95
TestBucket_NestedFunction · 0.80
TestBucket_StatsFunction · 0.80
TestBucket_Stats_SmallFunction · 0.80
TestBucket_Stats_NestedFunction · 0.80
TestBucket_Stats_LargeFunction · 0.80
TestRevertMetaPageFunction · 0.80

Calls 4

ViewMethod · 0.95
CheckMethod · 0.80
CopyFileMethod · 0.80
PrintMethod · 0.80

Tested by 9

TestBucket_NestedFunction · 0.64
TestBucket_StatsFunction · 0.64
TestBucket_Stats_SmallFunction · 0.64
TestBucket_Stats_NestedFunction · 0.64
TestBucket_Stats_LargeFunction · 0.64
TestRevertMetaPageFunction · 0.64