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 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.PutMultiCB) 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |