mirror of
https://github.com/etcd-io/bbolt.git
synced 2025-07-13 07:38:42 +00:00
Validate page being fetched at possition 'p' self identifies as page 'p'.
It's the easiest verification whether the page is actually written, or its 'random' garbage in the block. Signed-off-by: Piotr Tabor <ptab@google.com>
This commit is contained in:
parent
109f510a5e
commit
d1aa8034d4
7
page.go
7
page.go
@ -2,6 +2,7 @@ package bbolt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
"unsafe"
|
||||
@ -53,6 +54,12 @@ func (p *page) meta() *meta {
|
||||
return (*meta)(unsafeAdd(unsafe.Pointer(p), unsafe.Sizeof(*p)))
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// leafPageElement retrieves the leaf node by index
|
||||
func (p *page) leafPageElement(index uint16) *leafPageElement {
|
||||
return (*leafPageElement)(unsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p),
|
||||
|
5
tx.go
5
tx.go
@ -609,12 +609,15 @@ func (tx *Tx) page(id pgid) *page {
|
||||
// Check the dirty pages first.
|
||||
if tx.pages != nil {
|
||||
if p, ok := tx.pages[id]; ok {
|
||||
p.fastCheck(id)
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise return directly from the mmap.
|
||||
return tx.db.page(id)
|
||||
p := tx.db.page(id)
|
||||
p.fastCheck(id)
|
||||
return p
|
||||
}
|
||||
|
||||
// forEachPage iterates over every page within a given page and executes a function.
|
||||
|
Loading…
x
Reference in New Issue
Block a user