Detect pages that have multiple flags set.

Signed-off-by: Piotr Tabor <ptab@google.com>
pull/358/head
Piotr Tabor 2022-12-18 13:36:37 +01:00
parent d1aa8034d4
commit 3cbd9c9a44
2 changed files with 9 additions and 6 deletions

View File

@ -191,9 +191,9 @@ func (n *node) read(p *page) {
func (n *node) write(p *page) {
// Initialize page.
if n.isLeaf {
p.flags |= leafPageFlag
p.flags = leafPageFlag
} else {
p.flags |= branchPageFlag
p.flags = branchPageFlag
}
if len(n.inodes) >= 0xFFFF {

11
page.go
View File

@ -2,7 +2,6 @@ package bbolt
import (
"fmt"
"log"
"os"
"sort"
"unsafe"
@ -55,9 +54,13 @@ func (p *page) meta() *meta {
}
func (p *page) fastCheck(id pgid) {
if p.id != id {
log.Panicf("Page expected to be: %v, but self identifies as %v", id, p.id)
}
_assert(p.id == id, "Page expected to be: %v, but self identifies as %v", id, p.id)
// Only one flag of page-type can be set.
_assert(p.flags == branchPageFlag ||
p.flags == leafPageFlag ||
p.flags == metaPageFlag ||
p.flags == freelistPageFlag,
"page %v: has unexpected type/flags: %x", p.id, p.flags)
}
// leafPageElement retrieves the leaf node by index