Skip to content

Commit

Permalink
Fix for issue #1352
Browse files Browse the repository at this point in the history
Resetting the closeCh in Open api so that scorch
index's main routine trio remains in their active
work loops.
  • Loading branch information
sreekanth-cb committed Mar 17, 2020
1 parent f9a23fb commit ee9ffd7
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index/scorch/scorch.go
Expand Up @@ -223,7 +223,7 @@ func (s *Scorch) openBolt() error {
s.introducerNotifier = make(chan *epochWatcher, 1)
s.revertToSnapshots = make(chan *snapshotReversion)
s.persisterNotifier = make(chan *epochWatcher, 1)

s.closeCh = make(chan struct{})
if !s.readOnly && s.path != "" {
err := s.removeOldZapFiles() // Before persister or merger create any new files.
if err != nil {
Expand Down
110 changes: 110 additions & 0 deletions index/scorch/scorch_test.go
Expand Up @@ -163,6 +163,116 @@ func TestIndexOpenReopen(t *testing.T) {
}
}

func TestIndexOpenReopenWithInsert(t *testing.T) {
cfg := CreateConfig("TestIndexOpenReopen")
err := InitTest(cfg)
if err != nil {
t.Fatal(err)
}
defer func() {
err := DestroyTest(cfg)
if err != nil {
t.Log(err)
}
}()

analysisQueue := index.NewAnalysisQueue(1)
idx, err := NewScorch(Name, cfg, analysisQueue)
if err != nil {
t.Fatal(err)
}
err = idx.Open()
if err != nil {
t.Errorf("error opening index: %v", err)
}

var expectedCount uint64
reader, err := idx.Reader()
if err != nil {
t.Fatal(err)
}
docCount, err := reader.DocCount()
if err != nil {
t.Error(err)
}
if docCount != expectedCount {
t.Errorf("Expected document count to be %d got %d", expectedCount, docCount)
}
err = reader.Close()
if err != nil {
t.Fatal(err)
}

// insert a doc
doc := document.NewDocument("1")
doc.AddField(document.NewTextField("name", []uint64{}, []byte("test")))
err = idx.Update(doc)
if err != nil {
t.Errorf("Error updating index: %v", err)
}
expectedCount++

reader, err = idx.Reader()
if err != nil {
t.Fatal(err)
}
docCount, err = reader.DocCount()
if err != nil {
t.Error(err)
}
if docCount != expectedCount {
t.Errorf("Expected document count to be %d got %d", expectedCount, docCount)
}
err = reader.Close()
if err != nil {
t.Fatal(err)
}

// now close it
err = idx.Close()
if err != nil {
t.Fatal(err)
}

// try to open the index and insert data
err = idx.Open()
if err != nil {
t.Errorf("error opening index: %v", err)
}

// insert a doc
doc = document.NewDocument("2")
doc.AddField(document.NewTextField("name", []uint64{}, []byte("test2")))
err = idx.Update(doc)
if err != nil {
t.Errorf("Error updating index: %v", err)
}
expectedCount++

// check the doc count again after reopening it
reader, err = idx.Reader()
if err != nil {
t.Fatal(err)
}
docCount, err = reader.DocCount()
if err != nil {
t.Error(err)
}
if docCount != expectedCount {
t.Errorf("Expected document count to be %d got %d", expectedCount, docCount)
}
err = reader.Close()
if err != nil {
t.Fatal(err)
}

// now close it
err = idx.Close()
if err != nil {
t.Fatal(err)
}
}

func TestIndexInsert(t *testing.T) {
cfg := CreateConfig("TestIndexInsert")
err := InitTest(cfg)
Expand Down

0 comments on commit ee9ffd7

Please sign in to comment.