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

Side by Side Diff: impl/memory/datastore.go

Issue 1302813003: impl/memory: Implement Queries (Closed) Base URL: https://github.com/luci/gae.git@add_multi_iterator
Patch Set: inequalities work now 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
dnj (Google) 2015/08/23 06:50:07 Perhaps you already have, but would be worthwhile
iannucci 2015/08/23 18:19:43 Yeah, it would be. I was thinking about doing that
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package memory 5 package memory
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "fmt" 9 "fmt"
10 10
11 "golang.org/x/net/context" 11 "golang.org/x/net/context"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 func (d *dsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error { 62 func (d *dsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error {
63 d.data.delMulti(keys, cb) 63 d.data.delMulti(keys, cb)
64 return nil 64 return nil
65 } 65 }
66 66
67 func (d *dsImpl) NewQuery(kind string) ds.Query { 67 func (d *dsImpl) NewQuery(kind string) ds.Query {
68 return &queryImpl{ns: d.ns, kind: kind} 68 return &queryImpl{ns: d.ns, kind: kind}
69 } 69 }
70 70
71 func (d *dsImpl) DecodeCursor(s string) (ds.Cursor, error) { 71 func (d *dsImpl) DecodeCursor(s string) (ds.Cursor, error) {
72 » return decodeCursor(s) 72 » return newCursor(s)
73 } 73 }
74 74
75 func (d *dsImpl) Run(q ds.Query, cb ds.RawRunCB) error { 75 func (d *dsImpl) Run(q ds.Query, cb ds.RawRunCB) error {
76 rq := q.(*queryImpl) 76 rq := q.(*queryImpl)
77 » done, err := rq.valid(d.ns, true) 77 » consistent := rq.eqFilters["__ancestor__"] != nil && !rq.eventualConsist ency
78 » if done || err != nil { 78 » idx, head := d.data.getQuerySnaps(consistent)
79 » » return err // will be nil if done 79 » return executeQuery(q, d.ns, false, idx, head, cb)
80 » }
81 » return nil
82 } 80 }
83 81
84 func (d *dsImpl) AddIndexes(idxs ...*ds.IndexDefinition) { 82 func (d *dsImpl) AddIndexes(idxs ...*ds.IndexDefinition) {
83 if len(idxs) == 0 {
84 return
85 }
86
85 for _, i := range idxs { 87 for _, i := range idxs {
86 if !i.Compound() { 88 if !i.Compound() {
87 panic(fmt.Errorf("Attempted to add non-compound index: % s", i)) 89 panic(fmt.Errorf("Attempted to add non-compound index: % s", i))
88 } 90 }
89 } 91 }
90 92
91 d.data.Lock() 93 d.data.Lock()
92 defer d.data.Unlock() 94 defer d.data.Unlock()
93 addIndex(d.data.store, d.ns, idxs) 95 addIndex(d.data.store, d.ns, idxs)
94 } 96 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 }) 141 })
140 } 142 }
141 143
142 func (d *txnDsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error { 144 func (d *txnDsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error {
143 return d.data.run(func() error { 145 return d.data.run(func() error {
144 return d.data.delMulti(keys, cb) 146 return d.data.delMulti(keys, cb)
145 }) 147 })
146 } 148 }
147 149
148 func (d *txnDsImpl) DecodeCursor(s string) (ds.Cursor, error) { 150 func (d *txnDsImpl) DecodeCursor(s string) (ds.Cursor, error) {
149 » return decodeCursor(s) 151 » return newCursor(s)
150 } 152 }
151 153
152 func (d *txnDsImpl) Run(q ds.Query, cb ds.RawRunCB) error { 154 func (d *txnDsImpl) Run(q ds.Query, cb ds.RawRunCB) error {
153 » rq := q.(*queryImpl) 155 » return executeQuery(q, d.ns, true, d.data.snap, d.data.snap, cb)
154 » done, err := rq.valid(d.ns, true)
155 » if done || err != nil {
156 » » return err // will be nil if done
157 » }
158 » if rq.eventualConsistency {
159 » » rq = rq.checkMutateClone(nil, nil)
160 » » rq.eventualConsistency = false
161 » }
162 » // TODO(riannucci): use head instead of snap for indexes
163 » panic("NOT IMPLEMENTED")
164 } 156 }
165 157
166 func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *ds.Transactio nOptions) error { 158 func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *ds.Transactio nOptions) error {
167 return errors.New("datastore: nested transactions are not supported") 159 return errors.New("datastore: nested transactions are not supported")
168 } 160 }
169 161
170 func (d *txnDsImpl) NewQuery(kind string) ds.Query { 162 func (d *txnDsImpl) NewQuery(kind string) ds.Query {
171 return &queryImpl{ns: d.ns, kind: kind} 163 return &queryImpl{ns: d.ns, kind: kind}
172 } 164 }
173 165
174 func (*txnDsImpl) Testable() ds.Testable { 166 func (*txnDsImpl) Testable() ds.Testable {
175 return nil 167 return nil
176 } 168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698