From a6f7abdfa392172a16ab631b56f8eefad17e2acd Mon Sep 17 00:00:00 2001 From: Antoine Grondin Date: Fri, 25 Dec 2015 11:33:46 +0700 Subject: [PATCH 1/2] firestore: reproducer for division by zero on GC --- index/firestorm/garbage_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index/firestorm/garbage_test.go b/index/firestorm/garbage_test.go index 096823d3..3313608f 100644 --- a/index/firestorm/garbage_test.go +++ b/index/firestorm/garbage_test.go @@ -11,6 +11,7 @@ package firestorm import ( "testing" + "time" "github.com/blevesearch/bleve/index" "github.com/blevesearch/bleve/index/store/gtreap" @@ -115,3 +116,17 @@ func TestGarbageCleanup(t *testing.T) { } } + +func TestGarbageDontPanicOnEmptyDocs(t *testing.T) { + idx, err := NewFirestorm("", nil, index.NewAnalysisQueue(1)) + if err != nil { + t.Fatal(err) + } + f := idx.(*Firestorm) + gc := NewGarbageCollector(f) + gc.garbageSleep = 30 * time.Millisecond + + gc.Start() + time.Sleep(40 * time.Millisecond) + gc.Stop() +} From 68063436773404d85b95f1f2562ef01a24c25a33 Mon Sep 17 00:00:00 2001 From: Antoine Grondin Date: Fri, 25 Dec 2015 11:34:19 +0700 Subject: [PATCH 2/2] firestore: fix #296 for division by zero on GC --- index/firestorm/garbage.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index/firestorm/garbage.go b/index/firestorm/garbage.go index 42a6b999..d70d5036 100644 --- a/index/firestorm/garbage.go +++ b/index/firestorm/garbage.go @@ -76,6 +76,9 @@ func (gc *GarbageCollector) run() { logger.Printf("garbage collector error getting doc count: %v", err) continue } + if docSize == 0 { + continue + } garbageRatio := int(uint64(garbageSize) / docSize) if garbageRatio > gc.garbageThreshold { gc.cleanup()