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

Unified Diff: impl/memory/datastore_data.go

Issue 1894403002: datastore: Fix AddIndexes with existing namespaces (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Created 4 years, 8 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 b0613e6defa409ea8f70fe6cc285e1fa5ad979fc..ff06a4722099e6dbd770ea2ca067ad5bd5a888a9 100644
--- a/impl/memory/datastore_data.go
+++ b/impl/memory/datastore_data.go
@@ -7,6 +7,7 @@ package memory
import (
"bytes"
"fmt"
+ "strings"
"sync"
"sync/atomic"
@@ -79,10 +80,10 @@ func (d *dataStoreData) setConsistent(always bool) {
}
}
-func (d *dataStoreData) addIndexes(ns string, idxs []*ds.IndexDefinition) {
+func (d *dataStoreData) addIndexes(idxs []*ds.IndexDefinition) {
d.Lock()
defer d.Unlock()
- addIndexes(d.head, d.aid, ns, idxs)
+ addIndexes(d.head, d.aid, idxs)
}
func (d *dataStoreData) setAutoIndex(enable bool) {
@@ -105,7 +106,7 @@ func (d *dataStoreData) maybeAutoIndex(err error) bool {
return false
}
- d.addIndexes(mi.ns, []*ds.IndexDefinition{mi.Missing})
+ d.addIndexes([]*ds.IndexDefinition{mi.Missing})
return true
}
@@ -165,6 +166,13 @@ func (d *dataStoreData) catchupIndexes() {
d.snap = d.head.Snapshot()
}
+func (d *dataStoreData) namespaces() []string {
+ d.rwlock.Lock()
+ defer d.rwlock.Unlock()
+
+ return namespaces(d.head)
+}
+
/////////////////////////// indexes(dataStoreData) ////////////////////////////
func groupMetaKey(key *ds.Key) []byte {
@@ -570,3 +578,25 @@ func rpm(data []byte) (ds.PropertyMap, error) {
return serialize.ReadPropertyMap(bytes.NewBuffer(data),
serialize.WithContext, "", "")
}
+
+func namespaces(store *memStore) []string {
+ var namespaces []string
+ for _, c := range store.GetCollectionNames() {
+ ns, has := trimPrefix(c, "ents:")
+ if !has {
+ if len(namespaces) > 0 {
+ break
+ }
+ continue
+ }
+ namespaces = append(namespaces, ns)
+ }
+ return namespaces
+}
+
+func trimPrefix(v, p string) (string, bool) {
+ if strings.HasPrefix(v, p) {
+ return v[len(p):], true
+ }
+ return v, false
+}
« 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