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

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

Issue 1846123002: Fix missing/broken ds.Stop handling in raw DS. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Better "count" helper function. Created 4 years, 8 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 | « no previous file | filter/dsQueryBatch/filter.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 count 5 package count
6 6
7 import ( 7 import (
8 "github.com/luci/luci-go/common/errors"
9 "golang.org/x/net/context" 8 "golang.org/x/net/context"
10 9
11 ds "github.com/luci/gae/service/datastore" 10 ds "github.com/luci/gae/service/datastore"
12 ) 11 )
13 12
14 // DSCounter is the counter object for the datastore service. 13 // DSCounter is the counter object for the datastore service.
15 type DSCounter struct { 14 type DSCounter struct {
16 AllocateIDs Entry 15 AllocateIDs Entry
17 DecodeCursor Entry 16 DecodeCursor Entry
18 RunInTransaction Entry 17 RunInTransaction Entry
(...skipping 16 matching lines...) Expand all
35 start, err := r.ds.AllocateIDs(incomplete, n) 34 start, err := r.ds.AllocateIDs(incomplete, n)
36 return start, r.c.AllocateIDs.up(err) 35 return start, r.c.AllocateIDs.up(err)
37 } 36 }
38 37
39 func (r *dsCounter) DecodeCursor(s string) (ds.Cursor, error) { 38 func (r *dsCounter) DecodeCursor(s string) (ds.Cursor, error) {
40 cursor, err := r.ds.DecodeCursor(s) 39 cursor, err := r.ds.DecodeCursor(s)
41 return cursor, r.c.DecodeCursor.up(err) 40 return cursor, r.c.DecodeCursor.up(err)
42 } 41 }
43 42
44 func (r *dsCounter) Run(q *ds.FinalizedQuery, cb ds.RawRunCB) error { 43 func (r *dsCounter) Run(q *ds.FinalizedQuery, cb ds.RawRunCB) error {
45 » return r.c.Run.up(errors.Filter(r.ds.Run(q, cb), ds.Stop)) 44 » return r.c.Run.upFilterStop(r.ds.Run(q, cb))
46 } 45 }
47 46
48 func (r *dsCounter) Count(q *ds.FinalizedQuery) (int64, error) { 47 func (r *dsCounter) Count(q *ds.FinalizedQuery) (int64, error) {
49 count, err := r.ds.Count(q) 48 count, err := r.ds.Count(q)
50 return count, r.c.Count.up(err) 49 return count, r.c.Count.up(err)
51 } 50 }
52 51
53 func (r *dsCounter) RunInTransaction(f func(context.Context) error, opts *ds.Tra nsactionOptions) error { 52 func (r *dsCounter) RunInTransaction(f func(context.Context) error, opts *ds.Tra nsactionOptions) error {
54 return r.c.RunInTransaction.up(r.ds.RunInTransaction(f, opts)) 53 return r.c.RunInTransaction.up(r.ds.RunInTransaction(f, opts))
55 } 54 }
56 55
57 func (r *dsCounter) DeleteMulti(keys []*ds.Key, cb ds.DeleteMultiCB) error { 56 func (r *dsCounter) DeleteMulti(keys []*ds.Key, cb ds.DeleteMultiCB) error {
58 » return r.c.DeleteMulti.up(errors.Filter(r.ds.DeleteMulti(keys, cb), ds.S top)) 57 » return r.c.DeleteMulti.upFilterStop(r.ds.DeleteMulti(keys, cb))
59 } 58 }
60 59
61 func (r *dsCounter) GetMulti(keys []*ds.Key, meta ds.MultiMetaGetter, cb ds.GetM ultiCB) error { 60 func (r *dsCounter) GetMulti(keys []*ds.Key, meta ds.MultiMetaGetter, cb ds.GetM ultiCB) error {
62 » return r.c.GetMulti.up(errors.Filter(r.ds.GetMulti(keys, meta, cb), ds.S top)) 61 » return r.c.GetMulti.upFilterStop(r.ds.GetMulti(keys, meta, cb))
63 } 62 }
64 63
65 func (r *dsCounter) PutMulti(keys []*ds.Key, vals []ds.PropertyMap, cb ds.PutMul tiCB) error { 64 func (r *dsCounter) PutMulti(keys []*ds.Key, vals []ds.PropertyMap, cb ds.PutMul tiCB) error {
66 » return r.c.PutMulti.up(errors.Filter(r.ds.PutMulti(keys, vals, cb), ds.S top)) 65 » return r.c.PutMulti.upFilterStop(r.ds.PutMulti(keys, vals, cb))
67 } 66 }
68 67
69 func (r *dsCounter) Testable() ds.Testable { 68 func (r *dsCounter) Testable() ds.Testable {
70 return r.ds.Testable() 69 return r.ds.Testable()
71 } 70 }
72 71
73 // FilterRDS installs a counter datastore filter in the context. 72 // FilterRDS installs a counter datastore filter in the context.
74 func FilterRDS(c context.Context) (context.Context, *DSCounter) { 73 func FilterRDS(c context.Context) (context.Context, *DSCounter) {
75 state := &DSCounter{} 74 state := &DSCounter{}
76 return ds.AddRawFilters(c, func(ic context.Context, ds ds.RawInterface) ds.RawInterface { 75 return ds.AddRawFilters(c, func(ic context.Context, ds ds.RawInterface) ds.RawInterface {
77 return &dsCounter{state, ds} 76 return &dsCounter{state, ds}
78 }), state 77 }), state
79 } 78 }
79
80 // upFilterStop wraps up, handling the special case datastore.Stop error.
81 // datastore.Stop will pass through this function, but, unlike other error
82 // codes, will be counted as a success.
83 func (e *Entry) upFilterStop(err error) error {
84 upErr := err
85 if upErr == ds.Stop {
86 upErr = nil
87 }
88 e.up(upErr)
89 return err
90 }
OLDNEW
« no previous file with comments | « no previous file | filter/dsQueryBatch/filter.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698