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 txnBuf | 5 package txnBuf |
6 | 6 |
7 import ( | 7 import ( |
8 "golang.org/x/net/context" | 8 "golang.org/x/net/context" |
9 | 9 |
10 ds "github.com/luci/gae/service/datastore" | 10 ds "github.com/luci/gae/service/datastore" |
11 "github.com/luci/gae/service/info" | |
12 ) | 11 ) |
13 | 12 |
14 type key int | 13 type key int |
15 | 14 |
16 var ( | 15 var ( |
17 » dsTxnBufParent key | 16 » dsTxnBufParent key |
| 17 » dsTxnBufHaveLock key = 1 |
18 ) | 18 ) |
19 | 19 |
20 // FilterRDS installs a transaction buffer datastore filter in the context. | 20 // FilterRDS installs a transaction buffer datastore filter in the context. |
21 func FilterRDS(c context.Context) context.Context { | 21 func FilterRDS(c context.Context) context.Context { |
22 // TODO(riannucci): allow the specification of the set of roots to limit
this | 22 // TODO(riannucci): allow the specification of the set of roots to limit
this |
23 // transaction to, transitively. | 23 // transaction to, transitively. |
24 return ds.AddRawFilters(c, func(c context.Context, rds ds.RawInterface)
ds.RawInterface { | 24 return ds.AddRawFilters(c, func(c context.Context, rds ds.RawInterface)
ds.RawInterface { |
25 if par, _ := c.Value(dsTxnBufParent).(*txnBufState); par != nil
{ | 25 if par, _ := c.Value(dsTxnBufParent).(*txnBufState); par != nil
{ |
26 » » » return &dsTxnBuf{c, par} | 26 » » » haveLock, _ := c.Value(dsTxnBufHaveLock).(bool) |
| 27 » » » return &dsTxnBuf{c, par, haveLock} |
27 } | 28 } |
28 » » return &dsBuf{rds, info.Get(c).GetNamespace()} | 29 » » return &dsBuf{rds} |
29 }) | 30 }) |
30 } | 31 } |
31 | 32 |
32 // impossible is a marker function to indicate that the given error is an | 33 // impossible is a marker function to indicate that the given error is an |
33 // impossible state, due to conditions outside of the function. | 34 // impossible state, due to conditions outside of the function. |
34 func impossible(err error) { | 35 func impossible(err error) { |
35 if err != nil { | 36 if err != nil { |
36 panic(err) | 37 panic(err) |
37 } | 38 } |
38 } | 39 } |
39 | 40 |
40 // memoryCorruption is a marker function to indicate that given error is | 41 // memoryCorruption is a marker function to indicate that given error is |
41 // actually due to corrupted memory to make it easier to read the code. | 42 // actually due to corrupted memory to make it easier to read the code. |
42 func memoryCorruption(err error) { | 43 func memoryCorruption(err error) { |
43 if err != nil { | 44 if err != nil { |
44 panic(err) | 45 panic(err) |
45 } | 46 } |
46 } | 47 } |
OLD | NEW |