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

Unified Diff: impl/memory/datastore.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 | « no previous file | impl/memory/datastore_data.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/datastore.go
diff --git a/impl/memory/datastore.go b/impl/memory/datastore.go
index 973d59b8d3753beb31511366b91046e04a8cb76e..33a245e62a455a9450ae4b873183af4d64ef945c 100644
--- a/impl/memory/datastore.go
+++ b/impl/memory/datastore.go
@@ -65,12 +65,22 @@ func (d *dsImpl) DecodeCursor(s string) (ds.Cursor, error) {
func (d *dsImpl) Run(fq *ds.FinalizedQuery, cb ds.RawRunCB) error {
idx, head := d.data.getQuerySnaps(!fq.EventuallyConsistent())
- return executeQuery(fq, d.ns, false, idx, head, cb)
+ err := executeQuery(fq, d.ns, false, idx, head, cb)
+ if d.data.maybeAutoIndex(err) {
+ idx, head = d.data.getQuerySnaps(!fq.EventuallyConsistent())
+ err = executeQuery(fq, d.ns, false, idx, head, cb)
+ }
+ return err
}
func (d *dsImpl) Count(fq *ds.FinalizedQuery) (ret int64, err error) {
idx, head := d.data.getQuerySnaps(!fq.EventuallyConsistent())
- return countQuery(fq, d.ns, false, idx, head)
+ ret, err = countQuery(fq, d.ns, false, idx, head)
+ if d.data.maybeAutoIndex(err) {
+ idx, head := d.data.getQuerySnaps(!fq.EventuallyConsistent())
+ ret, err = countQuery(fq, d.ns, false, idx, head)
+ }
+ return
}
func (d *dsImpl) AddIndexes(idxs ...*ds.IndexDefinition) {
@@ -84,9 +94,7 @@ func (d *dsImpl) AddIndexes(idxs ...*ds.IndexDefinition) {
}
}
- d.data.Lock()
- defer d.data.Unlock()
- addIndex(d.data.head, d.ns, idxs)
+ d.data.addIndexes(d.ns, idxs)
}
func (d *dsImpl) TakeIndexSnapshot() ds.TestingSnapshot {
@@ -109,6 +117,10 @@ func (d *dsImpl) Consistent(always bool) {
d.data.setConsistent(always)
}
+func (d *dsImpl) AutoIndex(enable bool) {
+ d.data.setAutoIndex(enable)
+}
+
func (d *dsImpl) Testable() ds.Testable {
return d
}
@@ -151,6 +163,15 @@ func (d *txnDsImpl) DecodeCursor(s string) (ds.Cursor, error) {
}
func (d *txnDsImpl) Run(q *ds.FinalizedQuery, cb ds.RawRunCB) error {
+ // note that autoIndex has no effect inside transactions. This is because
+ // the transaction guarantees a consistent view of head at the time that the
+ // transaction opens. At best, we could add the index on head, but then return
+ // the error anyway, but adding the index then re-snapping at head would
+ // potentially reveal other entities not in the original transaction snapshot.
+ //
+ // It's possible that if you have full-consistency and also auto index enabled
+ // that this would make sense... but at that point you should probably just
+ // add the index up front.
return executeQuery(q, d.ns, true, d.data.snap, d.data.snap, cb)
}
« no previous file with comments | « no previous file | impl/memory/datastore_data.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698