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

Side by Side Diff: filter/txnBuf/context.go

Issue 1434873003: Fix races in txnBuf (Closed) Base URL: https://github.com/luci/gae.git@race_tests
Patch Set: fix stuff Created 5 years, 1 month 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 | « no previous file | filter/txnBuf/doc.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 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 }
OLDNEW
« no previous file with comments | « no previous file | filter/txnBuf/doc.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698