From 156260e68e0836a149bd168c7a6814c6367d16fe Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Wed, 12 Sep 2018 13:20:07 -0500 Subject: [PATCH] roaring allowed import to merge with existing data --- fragment.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/fragment.go b/fragment.go index 904652a57..858a47e6c 100644 --- a/fragment.go +++ b/fragment.go @@ -1430,6 +1430,35 @@ func (f *fragment) importRoaringBytes(roaringBytes []byte) error { if err != nil { return err } + + // get a list of keys in order to update the cache + i, _ := bm.Containers.Iterator(0) + set := make([]uint64, 0) + var lastRow uint64 = math.MaxUint64 + + for i.Next() { + key, _ := i.Value() + + // virtual row for the current container + vRow := key >> containersPerRowSegment + + // skip dups + if vRow == lastRow { + continue + } + set = append(set, vRow) + lastRow = vRow + } + + if f.storage.Count() > 0 { + bm = f.storage.Union(bm) + } + + for _,rowID := range set { + n := bm.CountRange(rowID*ShardWidth, (rowID+1)*ShardWidth) + f.cache.BulkAdd(rowID, n) + } + err = snapshot(f, bm) return err }