Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: impl/memory/datastore_data.go

Issue 1364333002: Add AutoIndex (Closed) Base URL: https://github.com/luci/gae.git@add_full_consistency
Patch Set: symbollls Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « impl/memory/datastore.go ('k') | impl/memory/datastore_index.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()
« no previous file with comments | « impl/memory/datastore.go ('k') | impl/memory/datastore_index.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698