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 featureBreaker | 5 package featureBreaker |
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" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 }) | 48 }) |
49 return count, err | 49 return count, err |
50 } | 50 } |
51 | 51 |
52 func (r *dsState) RunInTransaction(f func(c context.Context) error, opts *ds.Tra
nsactionOptions) error { | 52 func (r *dsState) RunInTransaction(f func(c context.Context) error, opts *ds.Tra
nsactionOptions) error { |
53 return r.run(func() error { | 53 return r.run(func() error { |
54 return r.rds.RunInTransaction(f, opts) | 54 return r.rds.RunInTransaction(f, opts) |
55 }) | 55 }) |
56 } | 56 } |
57 | 57 |
58 // TODO(riannucci): Allow the user to specify a multierror which will propagate | 58 // TODO(iannucci): Allow the user to specify a multierror which will propagate |
59 // to the callback correctly. | 59 // to the callback correctly. |
60 | 60 |
61 func (r *dsState) DeleteMulti(keys []*ds.Key, cb ds.DeleteMultiCB) error { | 61 func (r *dsState) DeleteMulti(keys []*ds.Key, cb ds.DeleteMultiCB) error { |
62 return r.run(func() error { | 62 return r.run(func() error { |
63 return r.rds.DeleteMulti(keys, cb) | 63 return r.rds.DeleteMulti(keys, cb) |
64 }) | 64 }) |
65 } | 65 } |
66 | 66 |
67 func (r *dsState) GetMulti(keys []*ds.Key, meta ds.MultiMetaGetter, cb ds.GetMul
tiCB) error { | 67 func (r *dsState) GetMulti(keys []*ds.Key, meta ds.MultiMetaGetter, cb ds.GetMul
tiCB) error { |
68 return r.run(func() error { | 68 return r.run(func() error { |
69 return r.rds.GetMulti(keys, meta, cb) | 69 return r.rds.GetMulti(keys, meta, cb) |
70 }) | 70 }) |
71 } | 71 } |
72 | 72 |
73 func (r *dsState) PutMulti(keys []*ds.Key, vals []ds.PropertyMap, cb ds.PutMulti
CB) error { | 73 func (r *dsState) PutMulti(keys []*ds.Key, vals []ds.PropertyMap, cb ds.PutMulti
CB) error { |
74 return r.run(func() (err error) { | 74 return r.run(func() (err error) { |
75 return r.rds.PutMulti(keys, vals, cb) | 75 return r.rds.PutMulti(keys, vals, cb) |
76 }) | 76 }) |
77 } | 77 } |
78 | 78 |
79 func (r *dsState) Testable() ds.Testable { | 79 func (r *dsState) Testable() ds.Testable { |
80 return r.rds.Testable() | 80 return r.rds.Testable() |
81 } | 81 } |
82 | 82 |
83 // FilterRDS installs a counter datastore filter in the context. | 83 // FilterRDS installs a featureBreaker datastore filter in the context. |
84 func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureB
reaker) { | 84 func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureB
reaker) { |
85 state := newState(defaultError) | 85 state := newState(defaultError) |
86 return ds.AddRawFilters(c, func(ic context.Context, RawDatastore ds.RawI
nterface) ds.RawInterface { | 86 return ds.AddRawFilters(c, func(ic context.Context, RawDatastore ds.RawI
nterface) ds.RawInterface { |
87 return &dsState{state, RawDatastore} | 87 return &dsState{state, RawDatastore} |
88 }), state | 88 }), state |
89 } | 89 } |
OLD | NEW |