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

Unified Diff: impl/memory/datastore_data.go

Issue 1285703002: Add testable interface for datastore. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fixes after Raw change Created 5 years, 4 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 dff438b30b33a9d6415fa218e698f26b1fdd3f55..1afc1f30581cf86c99ac287f5a65b3e864823aa6 100644
--- a/impl/memory/datastore_data.go
+++ b/impl/memory/datastore_data.go
@@ -45,6 +45,36 @@ func (d *dataStoreData) Unlock() {
d.rwlock.Unlock()
}
+func (d *dataStoreData) getQuerySnaps(consistent bool) (idx, head *memStore) {
+ d.rwlock.RLock()
+ defer d.rwlock.RUnlock()
+ head = d.store.Snapshot()
+ if consistent {
+ idx = head
+ } else {
+ idx = d.snap
+ }
+ return
+}
+
+func (d *dataStoreData) takeSnapshot() *memStore {
+ d.rwlock.RLock()
+ defer d.rwlock.RUnlock()
+ return d.store.Snapshot()
+}
+
+func (d *dataStoreData) setSnapshot(snap *memStore) {
+ d.rwlock.Lock()
+ defer d.rwlock.Unlock()
+ d.snap = snap
+}
+
+func (d *dataStoreData) catchupIndexes() {
+ d.rwlock.Lock()
+ defer d.rwlock.Unlock()
+ d.snap = d.store.Snapshot()
+}
+
/////////////////////////// indicies(dataStoreData) ////////////////////////////
func groupMetaKey(key ds.Key) []byte {
@@ -165,9 +195,7 @@ func getMultiInner(keys []ds.Key, cb ds.GetMultiCB, getColl func() (*memCollecti
func (d *dataStoreData) getMulti(keys []ds.Key, cb ds.GetMultiCB) error {
getMultiInner(keys, cb, func() (*memCollection, error) {
- d.rwlock.RLock()
- s := d.store.Snapshot()
- d.rwlock.RUnlock()
+ s := d.takeSnapshot()
return s.GetCollection("ents:" + keys[0].Namespace()), nil
})
« 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