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