// Check performs several consistency checks on the database for this transaction. // An error is returned if any inconsistency is found. // // It can be safely run concurrently on a writable transaction. However, this // incurs a high cost for large databases and databases with a lot of subbuckets // because of caching. This overhead can be removed if running on a read-only // transaction, however, it is not safe to execute other writer transactions at // the same time. func (tx *Tx) Check() <-chan error { … } // CheckWithOptions allows users to provide a customized `KVStringer` implementation, // so that bolt can generate human-readable diagnostic messages. func (tx *Tx) CheckWithOptions(options ...CheckOption) <-chan error { … } func (tx *Tx) check(kvStringer KVStringer, ch chan error) { … } func (tx *Tx) checkBucket(b *Bucket, reachable map[pgid]*page, freed map[pgid]bool, kvStringer KVStringer, ch chan error) { … } // recursivelyCheckPages confirms database consistency with respect to b-tree // key order constraints: // - keys on pages must be sorted // - keys on children pages are between 2 consecutive keys on the parent's branch page). func (tx *Tx) recursivelyCheckPages(pgId pgid, keyToString func([]byte) string, ch chan error) { … } // recursivelyCheckPagesInternal verifies that all keys in the subtree rooted at `pgid` are: // - >=`minKeyClosed` (can be nil) // - <`maxKeyOpen` (can be nil) // - Are in right ordering relationship to their parents. // `pagesStack` is expected to contain IDs of pages from the tree root to `pgid` for the clean debugging message. func (tx *Tx) recursivelyCheckPagesInternal( pgId pgid, minKeyClosed, maxKeyOpen []byte, pagesStack []pgid, keyToString func([]byte) string, ch chan error) (maxKeyInSubtree []byte) { … } /*** * verifyKeyOrder checks whether an entry with given #index on pgId (pageType: "branch|leaf") that has given "key", * is within range determined by (previousKey..maxKeyOpen) and reports found violations to the channel (ch). */ func verifyKeyOrder(pgId pgid, pageType string, index int, key []byte, previousKey []byte, maxKeyOpen []byte, ch chan error, keyToString func([]byte) string, pagesStack []pgid) { … } type checkConfig … type CheckOption … func WithKVStringer(kvStringer KVStringer) CheckOption { … } type KVStringer … // HexKVStringer serializes both key & value to hex representation. func HexKVStringer() KVStringer { … } type hexKvStringer … func (_ hexKvStringer) KeyToString(key []byte) string { … } func (_ hexKvStringer) ValueToString(value []byte) string { … }