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

Unified Diff: filter/txnBuf/context.go

Issue 1309803004: Add transaction buffer filter. (Closed) Base URL: https://github.com/luci/gae.git@add_query_support
Patch Set: one more test 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | filter/txnBuf/doc.go » ('j') | filter/txnBuf/ds_txn.go » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: filter/txnBuf/context.go
diff --git a/filter/txnBuf/context.go b/filter/txnBuf/context.go
new file mode 100644
index 0000000000000000000000000000000000000000..87fc1729713cabdf42597632f25bd8f86f1a43e5
--- /dev/null
+++ b/filter/txnBuf/context.go
@@ -0,0 +1,46 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package txnBuf
+
+import (
+ "golang.org/x/net/context"
+
+ ds "github.com/luci/gae/service/datastore"
+ "github.com/luci/gae/service/info"
+)
+
+type key int
+
+var (
+ dsTxnBufParent key
+)
+
+// FilterRDS installs a counter datastore filter in the context.
+func FilterRDS(c context.Context) context.Context {
+ // TODO(riannucci): allow the specification of the set of roots to limit this
+ // transaction to, transitively.
+ return ds.AddRawFilters(c, func(c context.Context, RawDatastore ds.RawInterface) ds.RawInterface {
Vadim Sh. 2015/09/28 18:52:56 rawDatastore I was very confused trying to figure
iannucci 2015/09/29 03:21:37 derp. Done.
+ if par, _ := c.Value(dsTxnBufParent).(*txnBufState); par != nil {
+ return &dsTxnBuf{RawDatastore, c, par}
+ }
+ return &dsBuf{RawDatastore, info.Get(c).GetNamespace()}
+ })
+}
+
+// impossible is a marker function to indicate that the given error is an
+// impossible state, due to conditions outside of the function.
+func impossible(err error) {
+ if err != nil {
+ panic(err)
+ }
+}
+
+// memoryCorruption is a marker function to indicate that given error is
+// actually due to corrupted memory to make it easier to read the code.
+func memoryCorruption(err error) {
+ if err != nil {
+ panic(err)
+ }
+}
« no previous file with comments | « no previous file | filter/txnBuf/doc.go » ('j') | filter/txnBuf/ds_txn.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698