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 "sync" | 9 "sync" |
10 | 10 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // | 128 // |
129 // It really should have been appengine.Context.RunInTransaction(func(tc...)), | 129 // It really should have been appengine.Context.RunInTransaction(func(tc...)), |
130 // but because it's not, this method is on dsImpl instead to mirror the official | 130 // but because it's not, this method is on dsImpl instead to mirror the official |
131 // API. | 131 // API. |
132 // | 132 // |
133 // The fake implementation also differs from the real implementation because the | 133 // The fake implementation also differs from the real implementation because the |
134 // fake TaskQueue is NOT backed by the fake Datastore. This is done to make the | 134 // fake TaskQueue is NOT backed by the fake Datastore. This is done to make the |
135 // test-access API for TaskQueue better (instead of trying to reconstitute the | 135 // test-access API for TaskQueue better (instead of trying to reconstitute the |
136 // state of the task queue from a bunch of datastore accesses). | 136 // state of the task queue from a bunch of datastore accesses). |
137 func (d *dsImpl) RunInTransaction(f func(context.Context) error, o *ds.Transacti
onOptions) error { | 137 func (d *dsImpl) RunInTransaction(f func(context.Context) error, o *ds.Transacti
onOptions) error { |
| 138 if d.data.getDisableSpecialEntities() { |
| 139 return errors.New("special entities are disabled. no transaction
s for you") |
| 140 } |
| 141 |
138 // Keep in separate function for defers. | 142 // Keep in separate function for defers. |
139 loopBody := func(applyForReal bool) error { | 143 loopBody := func(applyForReal bool) error { |
140 curMC := cur(d.c) | 144 curMC := cur(d.c) |
141 | 145 |
142 txnMC := curMC.mkTxn(o) | 146 txnMC := curMC.mkTxn(o) |
143 | 147 |
144 defer func() { | 148 defer func() { |
145 txnMC.Lock() | 149 txnMC.Lock() |
146 defer txnMC.Unlock() | 150 defer txnMC.Unlock() |
147 | 151 |
(...skipping 20 matching lines...) Expand all Loading... |
168 if o != nil && o.Attempts != 0 { | 172 if o != nil && o.Attempts != 0 { |
169 attempts = o.Attempts | 173 attempts = o.Attempts |
170 } | 174 } |
171 for attempt := 0; attempt < attempts; attempt++ { | 175 for attempt := 0; attempt < attempts; attempt++ { |
172 if err := loopBody(attempt >= d.data.txnFakeRetry); err != ds.Er
rConcurrentTransaction { | 176 if err := loopBody(attempt >= d.data.txnFakeRetry); err != ds.Er
rConcurrentTransaction { |
173 return err | 177 return err |
174 } | 178 } |
175 } | 179 } |
176 return ds.ErrConcurrentTransaction | 180 return ds.ErrConcurrentTransaction |
177 } | 181 } |
OLD | NEW |