OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
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 | 10 |
10 "golang.org/x/net/context" | 11 "golang.org/x/net/context" |
11 | 12 |
12 ds "github.com/luci/gae/service/datastore" | 13 ds "github.com/luci/gae/service/datastore" |
13 ) | 14 ) |
14 | 15 |
15 //////////////////////////////////// public //////////////////////////////////// | 16 //////////////////////////////////// public //////////////////////////////////// |
16 | 17 |
17 // useRDS adds a gae.Datastore implementation to context, accessible | 18 // useRDS adds a gae.Datastore implementation to context, accessible |
18 // by gae.GetDS(c) | 19 // by gae.GetDS(c) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 d.data.delMulti(keys, cb) | 62 d.data.delMulti(keys, cb) |
62 return nil | 63 return nil |
63 } | 64 } |
64 | 65 |
65 func (d *dsImpl) NewQuery(kind string) ds.Query { | 66 func (d *dsImpl) NewQuery(kind string) ds.Query { |
66 return &queryImpl{ns: d.ns, kind: kind} | 67 return &queryImpl{ns: d.ns, kind: kind} |
67 } | 68 } |
68 | 69 |
69 func (d *dsImpl) Run(q ds.Query, cb ds.RawRunCB) error { | 70 func (d *dsImpl) Run(q ds.Query, cb ds.RawRunCB) error { |
70 return nil | 71 return nil |
71 » /* | 72 } |
72 » » rq := q.(*queryImpl) | 73 |
73 » » rq = rq.normalize().checkCorrectness(d.ns, false) | 74 func (d *dsImpl) AddIndexes(idxs ...*ds.IndexDefinition) { |
74 » » return &queryIterImpl{rq} | 75 » for _, i := range idxs { |
75 » */ | 76 » » if !i.Compound() { |
| 77 » » » panic(fmt.Errorf("Attempted to add non-compound index: %
s", i)) |
| 78 » » } |
| 79 » } |
| 80 |
| 81 » d.data.Lock() |
| 82 » defer d.data.Unlock() |
| 83 » addIndex(d.data.store, d.ns, idxs) |
| 84 } |
| 85 |
| 86 func (d *dsImpl) TakeIndexSnapshot() ds.TestingSnapshot { |
| 87 » return d.data.takeSnapshot() |
| 88 } |
| 89 |
| 90 func (d *dsImpl) SetIndexSnapshot(snap ds.TestingSnapshot) { |
| 91 » d.data.setSnapshot(snap.(*memStore)) |
| 92 } |
| 93 |
| 94 func (d *dsImpl) CatchupIndexes() { |
| 95 » d.data.catchupIndexes() |
| 96 } |
| 97 |
| 98 func (d *dsImpl) Testable() ds.Testable { |
| 99 » return d |
76 } | 100 } |
77 | 101 |
78 ////////////////////////////////// txnDsImpl /////////////////////////////////// | 102 ////////////////////////////////// txnDsImpl /////////////////////////////////// |
79 | 103 |
80 type txnDsImpl struct { | 104 type txnDsImpl struct { |
81 data *txnDataStoreData | 105 data *txnDataStoreData |
82 ns string | 106 ns string |
83 } | 107 } |
84 | 108 |
85 var _ ds.RawInterface = (*txnDsImpl)(nil) | 109 var _ ds.RawInterface = (*txnDsImpl)(nil) |
(...skipping 21 matching lines...) Expand all Loading... |
107 | 131 |
108 func (d *txnDsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error { | 132 func (d *txnDsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error { |
109 return d.data.run(func() error { | 133 return d.data.run(func() error { |
110 return d.data.delMulti(keys, cb) | 134 return d.data.delMulti(keys, cb) |
111 }) | 135 }) |
112 } | 136 } |
113 | 137 |
114 func (d *txnDsImpl) Run(q ds.Query, cb ds.RawRunCB) error { | 138 func (d *txnDsImpl) Run(q ds.Query, cb ds.RawRunCB) error { |
115 rq := q.(*queryImpl) | 139 rq := q.(*queryImpl) |
116 if rq.ancestor == nil { | 140 if rq.ancestor == nil { |
117 » » return errors.New("memory: queries in transactions only support
ancestor queries") | 141 » » return errors.New("gae/impl/memory: queries in transactions only
support ancestor queries") |
118 } | 142 } |
| 143 if rq.eventualConsistency { |
| 144 rq = rq.clone() |
| 145 rq.eventualConsistency = false |
| 146 } |
| 147 // TODO(riannucci): use head instead of snap for indexes |
119 panic("NOT IMPLEMENTED") | 148 panic("NOT IMPLEMENTED") |
120 } | 149 } |
121 | 150 |
122 func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *ds.Transactio
nOptions) error { | 151 func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *ds.Transactio
nOptions) error { |
123 return errors.New("datastore: nested transactions are not supported") | 152 return errors.New("datastore: nested transactions are not supported") |
124 } | 153 } |
125 | 154 |
126 func (d *txnDsImpl) NewQuery(kind string) ds.Query { | 155 func (d *txnDsImpl) NewQuery(kind string) ds.Query { |
127 return &queryImpl{ns: d.ns, kind: kind} | 156 return &queryImpl{ns: d.ns, kind: kind} |
128 } | 157 } |
| 158 |
| 159 func (*txnDsImpl) Testable() ds.Testable { |
| 160 return nil |
| 161 } |
OLD | NEW |