| 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" |
| 11 ) | 11 ) |
| 12 | 12 |
| 13 type dsState struct { | 13 type dsState struct { |
| 14 *state | 14 *state |
| 15 | 15 |
| 16 » ds.RawInterface | 16 » rds ds.RawInterface |
| 17 } | 17 } |
| 18 | 18 |
| 19 func (r *dsState) DecodeKey(encoded string) (ret ds.Key, err error) { | 19 func (r *dsState) DecodeCursor(s string) (ds.Cursor, error) { |
| 20 » err = r.run(func() (err error) { | 20 » curs := ds.Cursor(nil) |
| 21 » » ret, err = r.RawInterface.DecodeKey(encoded) | 21 » err := r.run(func() (err error) { |
| 22 » » curs, err = r.rds.DecodeCursor(s) |
| 22 return | 23 return |
| 23 }) | 24 }) |
| 24 » return | 25 » return curs, err |
| 26 } |
| 27 |
| 28 func (r *dsState) Run(q *ds.FinalizedQuery, cb ds.RawRunCB) error { |
| 29 » return r.run(func() error { |
| 30 » » return r.rds.Run(q, cb) |
| 31 » }) |
| 25 } | 32 } |
| 26 | 33 |
| 27 func (r *dsState) RunInTransaction(f func(c context.Context) error, opts *ds.Tra
nsactionOptions) error { | 34 func (r *dsState) RunInTransaction(f func(c context.Context) error, opts *ds.Tra
nsactionOptions) error { |
| 28 return r.run(func() error { | 35 return r.run(func() error { |
| 29 » » return r.RawInterface.RunInTransaction(f, opts) | 36 » » return r.rds.RunInTransaction(f, opts) |
| 30 }) | 37 }) |
| 31 } | 38 } |
| 32 | 39 |
| 33 // TODO(riannucci): Allow the user to specify a multierror which will propagate | 40 // TODO(riannucci): Allow the user to specify a multierror which will propagate |
| 34 // to the callback correctly. | 41 // to the callback correctly. |
| 35 | 42 |
| 36 func (r *dsState) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error { | 43 func (r *dsState) DeleteMulti(keys []*ds.Key, cb ds.DeleteMultiCB) error { |
| 37 return r.run(func() error { | 44 return r.run(func() error { |
| 38 » » return r.RawInterface.DeleteMulti(keys, cb) | 45 » » return r.rds.DeleteMulti(keys, cb) |
| 39 }) | 46 }) |
| 40 } | 47 } |
| 41 | 48 |
| 42 func (r *dsState) GetMulti(keys []ds.Key, meta ds.MultiMetaGetter, cb ds.GetMult
iCB) error { | 49 func (r *dsState) GetMulti(keys []*ds.Key, meta ds.MultiMetaGetter, cb ds.GetMul
tiCB) error { |
| 43 return r.run(func() error { | 50 return r.run(func() error { |
| 44 » » return r.RawInterface.GetMulti(keys, meta, cb) | 51 » » return r.rds.GetMulti(keys, meta, cb) |
| 45 }) | 52 }) |
| 46 } | 53 } |
| 47 | 54 |
| 48 func (r *dsState) PutMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds.PutMultiC
B) error { | 55 func (r *dsState) PutMulti(keys []*ds.Key, vals []ds.PropertyMap, cb ds.PutMulti
CB) error { |
| 49 return r.run(func() (err error) { | 56 return r.run(func() (err error) { |
| 50 » » return r.RawInterface.PutMulti(keys, vals, cb) | 57 » » return r.rds.PutMulti(keys, vals, cb) |
| 51 }) | 58 }) |
| 52 } | 59 } |
| 53 | 60 |
| 61 func (r *dsState) Testable() ds.Testable { |
| 62 return r.rds.Testable() |
| 63 } |
| 64 |
| 54 // FilterRDS installs a counter datastore filter in the context. | 65 // FilterRDS installs a counter datastore filter in the context. |
| 55 func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureB
reaker) { | 66 func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureB
reaker) { |
| 56 state := newState(defaultError) | 67 state := newState(defaultError) |
| 57 return ds.AddRawFilters(c, func(ic context.Context, RawDatastore ds.RawI
nterface) ds.RawInterface { | 68 return ds.AddRawFilters(c, func(ic context.Context, RawDatastore ds.RawI
nterface) ds.RawInterface { |
| 58 return &dsState{state, RawDatastore} | 69 return &dsState{state, RawDatastore} |
| 59 }), state | 70 }), state |
| 60 } | 71 } |
| OLD | NEW |