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

Side by Side Diff: filter/featureBreaker/rds.go

Issue 1253263002: Make rawdatastore API safer for writing filters. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix comments Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « filter/featureBreaker/featurebreaker_test.go ('k') | impl/dummy/dummy.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 rds "github.com/luci/gae/service/rawdatastore" 10 rds "github.com/luci/gae/service/rawdatastore"
11 ) 11 )
12 12
13 type rdsState struct { 13 type rdsState struct {
14 *state 14 *state
15 15
16 rds.Interface 16 rds.Interface
17 } 17 }
18 18
19 func (r *rdsState) DecodeKey(encoded string) (ret rds.Key, err error) { 19 func (r *rdsState) DecodeKey(encoded string) (ret rds.Key, err error) {
20 err = r.run(func() (err error) { 20 err = r.run(func() (err error) {
21 ret, err = r.Interface.DecodeKey(encoded) 21 ret, err = r.Interface.DecodeKey(encoded)
22 return 22 return
23 }) 23 })
24 return 24 return
25 } 25 }
26 26
27 func (r *rdsState) GetAll(q rds.Query, dst *[]rds.PropertyMap) (ret []rds.Key, e rr error) {
28 err = r.run(func() (err error) {
29 ret, err = r.Interface.GetAll(q, dst)
30 return
31 })
32 return
33 }
34
35 func (r *rdsState) Count(q rds.Query) (ret int, err error) {
36 err = r.run(func() (err error) {
37 ret, err = r.Interface.Count(q)
38 return
39 })
40 return
41 }
42
43 func (r *rdsState) RunInTransaction(f func(c context.Context) error, opts *rds.T ransactionOptions) error { 27 func (r *rdsState) RunInTransaction(f func(c context.Context) error, opts *rds.T ransactionOptions) error {
44 return r.run(func() error { 28 return r.run(func() error {
45 return r.Interface.RunInTransaction(f, opts) 29 return r.Interface.RunInTransaction(f, opts)
46 }) 30 })
47 } 31 }
48 32
49 func (r *rdsState) Put(key rds.Key, src rds.PropertyLoadSaver) (ret rds.Key, err error) { 33 // TODO(riannucci): Allow the user to specify a multierror which will propagate
50 » err = r.run(func() (err error) { 34 // to the callback correctly.
51 » » ret, err = r.Interface.Put(key, src)
52 » » return
53 » })
54 » return
55 }
56 35
57 func (r *rdsState) Get(key rds.Key, dst rds.PropertyLoadSaver) error { 36 func (r *rdsState) DeleteMulti(keys []rds.Key, cb rds.DeleteMultiCB) error {
58 return r.run(func() error { 37 return r.run(func() error {
59 » » return r.Interface.Get(key, dst) 38 » » return r.Interface.DeleteMulti(keys, cb)
60 }) 39 })
61 } 40 }
62 41
63 func (r *rdsState) Delete(key rds.Key) error { 42 func (r *rdsState) GetMulti(keys []rds.Key, cb rds.GetMultiCB) error {
64 return r.run(func() error { 43 return r.run(func() error {
65 » » return r.Interface.Delete(key) 44 » » return r.Interface.GetMulti(keys, cb)
66 }) 45 })
67 } 46 }
68 47
69 func (r *rdsState) DeleteMulti(keys []rds.Key) error { 48 func (r *rdsState) PutMulti(keys []rds.Key, vals []rds.PropertyLoadSaver, cb rds .PutMultiCB) error {
70 » return r.run(func() error { 49 » return r.run(func() (err error) {
71 » » return r.Interface.DeleteMulti(keys) 50 » » return r.Interface.PutMulti(keys, vals, cb)
72 }) 51 })
73 } 52 }
74 53
75 func (r *rdsState) GetMulti(keys []rds.Key, dst []rds.PropertyLoadSaver) error {
76 return r.run(func() error {
77 return r.Interface.GetMulti(keys, dst)
78 })
79 }
80
81 func (r *rdsState) PutMulti(keys []rds.Key, src []rds.PropertyLoadSaver) (ret [] rds.Key, err error) {
82 err = r.run(func() (err error) {
83 ret, err = r.Interface.PutMulti(keys, src)
84 return
85 })
86 return
87 }
88
89 // FilterRDS installs a counter RawDatastore filter in the context. 54 // FilterRDS installs a counter RawDatastore filter in the context.
90 func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureB reaker) { 55 func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureB reaker) {
91 state := newState(defaultError) 56 state := newState(defaultError)
92 return rds.AddFilters(c, func(ic context.Context, RawDatastore rds.Inter face) rds.Interface { 57 return rds.AddFilters(c, func(ic context.Context, RawDatastore rds.Inter face) rds.Interface {
93 return &rdsState{state, RawDatastore} 58 return &rdsState{state, RawDatastore}
94 }), state 59 }), state
95 } 60 }
OLDNEW
« no previous file with comments | « filter/featureBreaker/featurebreaker_test.go ('k') | impl/dummy/dummy.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698