| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be 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 rds ds.RawInterface | 16 rds ds.RawInterface |
| 17 } | 17 } |
| 18 | 18 |
| 19 func (r *dsState) AllocateIDs(incomplete *ds.Key, n int) (int64, error) { | 19 func (r *dsState) AllocateIDs(keys []*ds.Key, cb ds.NewKeyCB) error { |
| 20 » start := int64(0) | 20 » return r.run(func() error { |
| 21 » err := r.run(func() (err error) { | 21 » » return r.rds.AllocateIDs(keys, cb) |
| 22 » » start, err = r.rds.AllocateIDs(incomplete, n) | |
| 23 » » return | |
| 24 }) | 22 }) |
| 25 return start, err | |
| 26 } | 23 } |
| 27 | 24 |
| 28 func (r *dsState) DecodeCursor(s string) (ds.Cursor, error) { | 25 func (r *dsState) DecodeCursor(s string) (ds.Cursor, error) { |
| 29 curs := ds.Cursor(nil) | 26 curs := ds.Cursor(nil) |
| 30 err := r.run(func() (err error) { | 27 err := r.run(func() (err error) { |
| 31 curs, err = r.rds.DecodeCursor(s) | 28 curs, err = r.rds.DecodeCursor(s) |
| 32 return | 29 return |
| 33 }) | 30 }) |
| 34 return curs, err | 31 return curs, err |
| 35 } | 32 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 63 return r.rds.DeleteMulti(keys, cb) | 60 return r.rds.DeleteMulti(keys, cb) |
| 64 }) | 61 }) |
| 65 } | 62 } |
| 66 | 63 |
| 67 func (r *dsState) GetMulti(keys []*ds.Key, meta ds.MultiMetaGetter, cb ds.GetMul
tiCB) error { | 64 func (r *dsState) GetMulti(keys []*ds.Key, meta ds.MultiMetaGetter, cb ds.GetMul
tiCB) error { |
| 68 return r.run(func() error { | 65 return r.run(func() error { |
| 69 return r.rds.GetMulti(keys, meta, cb) | 66 return r.rds.GetMulti(keys, meta, cb) |
| 70 }) | 67 }) |
| 71 } | 68 } |
| 72 | 69 |
| 73 func (r *dsState) PutMulti(keys []*ds.Key, vals []ds.PropertyMap, cb ds.PutMulti
CB) error { | 70 func (r *dsState) PutMulti(keys []*ds.Key, vals []ds.PropertyMap, cb ds.NewKeyCB
) error { |
| 74 return r.run(func() (err error) { | 71 return r.run(func() (err error) { |
| 75 return r.rds.PutMulti(keys, vals, cb) | 72 return r.rds.PutMulti(keys, vals, cb) |
| 76 }) | 73 }) |
| 77 } | 74 } |
| 78 | 75 |
| 79 func (r *dsState) Testable() ds.Testable { | 76 func (r *dsState) Testable() ds.Testable { |
| 80 return r.rds.Testable() | 77 return r.rds.Testable() |
| 81 } | 78 } |
| 82 | 79 |
| 83 // FilterRDS installs a featureBreaker datastore filter in the context. | 80 // FilterRDS installs a featureBreaker datastore filter in the context. |
| 84 func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureB
reaker) { | 81 func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureB
reaker) { |
| 85 state := newState(defaultError) | 82 state := newState(defaultError) |
| 86 return ds.AddRawFilters(c, func(ic context.Context, RawDatastore ds.RawI
nterface) ds.RawInterface { | 83 return ds.AddRawFilters(c, func(ic context.Context, RawDatastore ds.RawI
nterface) ds.RawInterface { |
| 87 return &dsState{state, RawDatastore} | 84 return &dsState{state, RawDatastore} |
| 88 }), state | 85 }), state |
| 89 } | 86 } |
| OLD | NEW |