Index: impl/memory/datastore_data.go |
diff --git a/impl/memory/datastore_data.go b/impl/memory/datastore_data.go |
index 8a01e89e8000613881bb98a0ae5438bbb049bb70..a17283ac702fd3ab40c0eba8c5c17969aa562666 100644 |
--- a/impl/memory/datastore_data.go |
+++ b/impl/memory/datastore_data.go |
@@ -27,6 +27,9 @@ type dataStoreData struct { |
txnFakeRetry int |
// true means that head always == snap |
consistent bool |
+ // true means that queries with insufficent indexes will pause to add them |
+ // and then continue instead of failing. |
+ autoIndex bool |
} |
var ( |
@@ -66,6 +69,39 @@ func (d *dataStoreData) setConsistent(always bool) { |
} |
} |
+func (d *dataStoreData) addIndexes(ns string, idxs []*ds.IndexDefinition) { |
+ d.Lock() |
+ defer d.Unlock() |
+ addIndexes(d.head, ns, idxs) |
+ if d.consistent { |
+ d.snap = d.head.Snapshot() |
+ } |
+} |
+ |
+func (d *dataStoreData) setAutoIndex(enable bool) { |
+ d.Lock() |
+ defer d.Unlock() |
+ d.autoIndex = enable |
+} |
+ |
+func (d *dataStoreData) maybeAutoIndex(err error) bool { |
+ mi, ok := err.(*ErrMissingIndex) |
+ if !ok { |
+ return false |
+ } |
+ |
+ d.rwlock.RLock() |
+ ai := d.autoIndex |
+ d.rwlock.RUnlock() |
+ |
+ if !ai { |
+ return false |
+ } |
+ |
+ d.addIndexes(mi.ns, []*ds.IndexDefinition{mi.Missing}) |
+ return true |
+} |
+ |
func (d *dataStoreData) getQuerySnaps(consistent bool) (idx, head *memStore) { |
d.rwlock.RLock() |
defer d.rwlock.RUnlock() |