mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-08 20:07:51 +00:00
reset lastContainer cache on Put to a mapped container. check lastContainer cache on Get
This commit is contained in:
parent
ce052c133c
commit
e0fc49b512
1 changed files with 13 additions and 1 deletions
|
|
@ -24,15 +24,28 @@ type BTreeContainers struct {
|
|||
}
|
||||
|
||||
func (btc *BTreeContainers) Get(key uint64) *container {
|
||||
// Check the last* cache for same container.
|
||||
if key == btc.lastKey && btc.lastContainer != nil {
|
||||
return btc.lastContainer
|
||||
}
|
||||
|
||||
var c *container
|
||||
el, ok := btc.tree.Get(key)
|
||||
if ok {
|
||||
c = el.(*container)
|
||||
btc.lastKey = key
|
||||
btc.lastContainer = c
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (btc *BTreeContainers) Put(key uint64, c *container) {
|
||||
// If a mapped container is added to the tree, reset the
|
||||
// lastContainer cache so that the cache is not pointing
|
||||
// at a read-only mmap.
|
||||
if c.mapped {
|
||||
btc.lastContainer = nil
|
||||
}
|
||||
btc.tree.Set(key, c)
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +86,6 @@ func (btc *BTreeContainers) Clone() Containers {
|
|||
}
|
||||
nbtc.tree.Set(k, v.(*container).clone())
|
||||
}
|
||||
|
||||
return nbtc
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue