From 1f2868f05930d816fc5208d29ce78b9312f9f296 Mon Sep 17 00:00:00 2001 From: Seebs Date: Mon, 17 Aug 2020 11:21:17 -0500 Subject: [PATCH] when updating a container, drop the single-container cache This can cause incredibly weird and hard-to-debug problems if the previous container value is still in the cache after an update, and in particular, can result in having a stale container value cached after a roaring import that modified the container. Coupled with another bug which could corrupt containers on a delete, this produces a very strange bug where a value is present in a fragment, but an attempt to delete it reports failure. --- roaring/containers_btree.go | 2 ++ roaring/containers_slice.go | 1 + 2 files changed, 3 insertions(+) diff --git a/roaring/containers_btree.go b/roaring/containers_btree.go index 257a756fa..79a3d557c 100644 --- a/roaring/containers_btree.go +++ b/roaring/containers_btree.go @@ -189,6 +189,8 @@ func (btc *bTreeContainers) Repair() { // replace the given container. func (btc *bTreeContainers) Update(key uint64, fn func(*Container, bool) (*Container, bool)) { btc.tree.Put(key, fn) + btc.lastKey = ^uint64(0) + btc.lastContainer = nil } // UpdateEvery calls fn (existing-container, existed), and expects diff --git a/roaring/containers_slice.go b/roaring/containers_slice.go index 1eaa65cf0..325b10547 100644 --- a/roaring/containers_slice.go +++ b/roaring/containers_slice.go @@ -205,6 +205,7 @@ func (sc *sliceContainers) Update(key uint64, fn func(*Container, bool) (*Contai sc.insertAt(key, nc, i) } } + sc.invalidateCache() } // UpdateEvery calls fn (existing-container, existed), and expects