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

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

Issue 1335083002: Add emulation of transaction retries to memory impl of RunInTransaction. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: add Testable() to non-Raw interfaces 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 unified diff | Download patch
« no previous file with comments | « impl/memory/context.go ('k') | impl/memory/datastore_query_execution_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "fmt"
10 10
11 "golang.org/x/net/context" 11 "golang.org/x/net/context"
12 12
13 ds "github.com/luci/gae/service/datastore" 13 ds "github.com/luci/gae/service/datastore"
14 "github.com/luci/gae/service/datastore/dskey" 14 "github.com/luci/gae/service/datastore/dskey"
15 ) 15 )
16 16
17 //////////////////////////////////// public //////////////////////////////////// 17 //////////////////////////////////// public ////////////////////////////////////
18 18
19 // useRDS adds a gae.Datastore implementation to context, accessible 19 // useRDS adds a gae.Datastore implementation to context, accessible
20 // by gae.GetDS(c) 20 // by gae.GetDS(c)
21 func useRDS(c context.Context) context.Context { 21 func useRDS(c context.Context) context.Context {
22 return ds.SetRawFactory(c, func(ic context.Context) ds.RawInterface { 22 return ds.SetRawFactory(c, func(ic context.Context) ds.RawInterface {
23 dsd := cur(ic).Get(memContextDSIdx) 23 dsd := cur(ic).Get(memContextDSIdx)
24 24
25 ns := curGID(ic).namespace 25 ns := curGID(ic).namespace
26 if x, ok := dsd.(*dataStoreData); ok { 26 if x, ok := dsd.(*dataStoreData); ok {
27 » » » return &dsImpl{x, ns, ic} 27 » » » return &dsImpl{x, ns, 0, ic}
28 } 28 }
29 return &txnDsImpl{dsd.(*txnDataStoreData), ns} 29 return &txnDsImpl{dsd.(*txnDataStoreData), ns}
30 }) 30 })
31 } 31 }
32 32
33 //////////////////////////////////// dsImpl //////////////////////////////////// 33 //////////////////////////////////// dsImpl ////////////////////////////////////
34 34
35 // dsImpl exists solely to bind the current c to the datastore data. 35 // dsImpl exists solely to bind the current c to the datastore data.
36 type dsImpl struct { 36 type dsImpl struct {
37 » data *dataStoreData 37 » data *dataStoreData
38 » ns string 38 » ns string
39 » c context.Context 39 » txnFakeRetry int
40 » c context.Context
40 } 41 }
41 42
42 var _ ds.RawInterface = (*dsImpl)(nil) 43 var _ ds.RawInterface = (*dsImpl)(nil)
43 44
44 func (d *dsImpl) DecodeKey(encoded string) (ds.Key, error) { 45 func (d *dsImpl) DecodeKey(encoded string) (ds.Key, error) {
45 return dskey.NewFromEncoded(encoded) 46 return dskey.NewFromEncoded(encoded)
46 } 47 }
47 48
48 func (d *dsImpl) NewKey(kind, stringID string, intID int64, parent ds.Key) ds.Ke y { 49 func (d *dsImpl) NewKey(kind, stringID string, intID int64, parent ds.Key) ds.Ke y {
49 return dskey.New(globalAppID, d.ns, kind, stringID, intID, parent) 50 return dskey.New(globalAppID, d.ns, kind, stringID, intID, parent)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 101 }
101 102
102 func (d *dsImpl) SetIndexSnapshot(snap ds.TestingSnapshot) { 103 func (d *dsImpl) SetIndexSnapshot(snap ds.TestingSnapshot) {
103 d.data.setSnapshot(snap.(*memStore)) 104 d.data.setSnapshot(snap.(*memStore))
104 } 105 }
105 106
106 func (d *dsImpl) CatchupIndexes() { 107 func (d *dsImpl) CatchupIndexes() {
107 d.data.catchupIndexes() 108 d.data.catchupIndexes()
108 } 109 }
109 110
111 func (d *dsImpl) SetTransactionRetryCount(count int) {
112 d.txnFakeRetry = count
113 }
114
110 func (d *dsImpl) Testable() ds.Testable { 115 func (d *dsImpl) Testable() ds.Testable {
111 return d 116 return d
112 } 117 }
113 118
114 ////////////////////////////////// txnDsImpl /////////////////////////////////// 119 ////////////////////////////////// txnDsImpl ///////////////////////////////////
115 120
116 type txnDsImpl struct { 121 type txnDsImpl struct {
117 data *txnDataStoreData 122 data *txnDataStoreData
118 ns string 123 ns string
119 } 124 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return errors.New("datastore: nested transactions are not supported") 164 return errors.New("datastore: nested transactions are not supported")
160 } 165 }
161 166
162 func (d *txnDsImpl) NewQuery(kind string) ds.Query { 167 func (d *txnDsImpl) NewQuery(kind string) ds.Query {
163 return &queryImpl{ns: d.ns, kind: kind} 168 return &queryImpl{ns: d.ns, kind: kind}
164 } 169 }
165 170
166 func (*txnDsImpl) Testable() ds.Testable { 171 func (*txnDsImpl) Testable() ds.Testable {
167 return nil 172 return nil
168 } 173 }
OLDNEW
« no previous file with comments | « impl/memory/context.go ('k') | impl/memory/datastore_query_execution_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698