MustCheck runs a consistency check on the database and panics if any errors are found.
()
| 132 | |
| 133 | // MustCheck runs a consistency check on the database and panics if any errors are found. |
| 134 | func (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. |
| 170 | func (db *DB) Fill(bucket []byte, numTx int, numKeysPerTx int, |