mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 09:05:55 +00:00
stop tracking existence if the existence field is deleted
This commit is contained in:
parent
9b4c67ee60
commit
f8c745340f
3 changed files with 57 additions and 3 deletions
|
|
@ -746,7 +746,7 @@ func TestFragment_TopN_CacheSize(t *testing.T) {
|
|||
cacheSize := uint32(3)
|
||||
|
||||
// Create Index.
|
||||
index := mustOpenIndex()
|
||||
index := mustOpenIndex(IndexOptions{})
|
||||
defer index.Close()
|
||||
|
||||
// Create field.
|
||||
|
|
@ -912,7 +912,7 @@ func TestFragment_LRUCache_Persistence(t *testing.T) {
|
|||
|
||||
// Ensure a fragment's cache can be persisted between restarts.
|
||||
func TestFragment_RankCache_Persistence(t *testing.T) {
|
||||
index := mustOpenIndex()
|
||||
index := mustOpenIndex(IndexOptions{})
|
||||
defer index.Close()
|
||||
|
||||
// Create field.
|
||||
|
|
|
|||
12
index.go
12
index.go
|
|
@ -421,6 +421,18 @@ func (i *Index) DeleteField(name string) error {
|
|||
return errors.Wrap(err, "removing directory")
|
||||
}
|
||||
|
||||
// If the field being deleted is the existence field,
|
||||
// turn off existence tracking on the index.
|
||||
if name == existenceFieldName {
|
||||
i.trackExistence = false
|
||||
i.existenceField = nil
|
||||
|
||||
// Update meta data on disk.
|
||||
if err := i.saveMeta(); err != nil {
|
||||
return errors.Wrap(err, "saving existence meta data")
|
||||
}
|
||||
}
|
||||
|
||||
// Remove reference.
|
||||
delete(i.fields, name)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,11 @@ package pilosa
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// mustOpenIndex returns a new, opened index at a temporary path. Panic on error.
|
||||
func mustOpenIndex() *Index {
|
||||
func mustOpenIndex(opt IndexOptions) *Index {
|
||||
path, err := ioutil.TempDir("", "pilosa-index-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
@ -28,6 +29,10 @@ func mustOpenIndex() *Index {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
index.keys = opt.Keys
|
||||
index.trackExistence = opt.TrackExistence
|
||||
|
||||
if err := index.Open(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
@ -44,3 +49,40 @@ func (i *Index) reopen() error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Ensure that deleting the existence field is handled properly.
|
||||
func TestIndex_Existence_Delete(t *testing.T) {
|
||||
// Create Index (with existence tracking).
|
||||
index := mustOpenIndex(IndexOptions{TrackExistence: true})
|
||||
defer index.Close()
|
||||
|
||||
// Ensure existence field has been created.
|
||||
ef := index.Field(existenceFieldName)
|
||||
if ef == nil {
|
||||
t.Fatalf("expected field to have been created: %s", existenceFieldName)
|
||||
} else if !index.trackExistence {
|
||||
t.Fatalf("expected index.trackExistence to be true")
|
||||
} else if index.existenceField == nil {
|
||||
t.Fatalf("expected index.existenceField to be non-nil")
|
||||
}
|
||||
|
||||
// Delete existence field.
|
||||
if err := index.DeleteField(existenceFieldName); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Re-open index.
|
||||
if err := index.reopen(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Ensure existence field no longer exists.
|
||||
ef = index.Field(existenceFieldName)
|
||||
if ef != nil {
|
||||
t.Fatalf("expected field to have been deleted: %s", existenceFieldName)
|
||||
} else if index.trackExistence {
|
||||
t.Fatalf("expected index.trackExistence to be false")
|
||||
} else if index.existenceField != nil {
|
||||
t.Fatalf("expected index.existenceField to be nil")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue