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

Side by Side Diff: impl/prod/raw_datastore.go

Issue 2007123002: datastore: Update AllocateIDs to take keys. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Created 4 years, 7 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
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 prod 5 package prod
6 6
7 import ( 7 import (
8 ds "github.com/luci/gae/service/datastore" 8 ds "github.com/luci/gae/service/datastore"
9 "github.com/luci/luci-go/common/errors" 9 "github.com/luci/luci-go/common/errors"
10 "golang.org/x/net/context" 10 "golang.org/x/net/context"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 me, ok := err.(errors.MultiError) 50 me, ok := err.(errors.MultiError)
51 if ok { 51 if ok {
52 for i, err := range me { 52 for i, err := range me {
53 cb(i, err) 53 cb(i, err)
54 } 54 }
55 return nil 55 return nil
56 } 56 }
57 return err 57 return err
58 } 58 }
59 59
60 func (d rdsImpl) AllocateIDs(incomplete *ds.Key, n int) (start int64, err error) { 60 func (d rdsImpl) AllocateIDs(keys []*ds.Key) error {
61 » // Allocate a set of IDs in our key namespace. We know that "keys" has a t
62 » // least one entry and that all keys share the same namespace and entty
63 » // type because checkfilter has already asserted this.
64 » incomplete := keys[0]
61 par, err := dsF2R(d.aeCtx, incomplete.Parent()) 65 par, err := dsF2R(d.aeCtx, incomplete.Parent())
62 if err != nil { 66 if err != nil {
63 » » return 67 » » return err
64 } 68 }
65 69
66 » start, _, err = datastore.AllocateIDs(d.aeCtx, incomplete.Kind(), par, n ) 70 » start, _, err := datastore.AllocateIDs(d.aeCtx, incomplete.Kind(), par, len(keys))
67 » return 71 » if err != nil {
72 » » return err
73 » }
74
75 » for i, k := range keys {
76 » » keys[i] = ds.NewKey(k.AppID(), k.Namespace(), k.Kind(), "", star t+int64(i), k.Parent())
77 » }
78 » return nil
68 } 79 }
69 80
70 func (d rdsImpl) DeleteMulti(ks []*ds.Key, cb ds.DeleteMultiCB) error { 81 func (d rdsImpl) DeleteMulti(ks []*ds.Key, cb ds.DeleteMultiCB) error {
71 keys, err := dsMF2R(d.aeCtx, ks) 82 keys, err := dsMF2R(d.aeCtx, ks)
72 if err == nil { 83 if err == nil {
73 err = datastore.DeleteMulti(d.aeCtx, keys) 84 err = datastore.DeleteMulti(d.aeCtx, keys)
74 } 85 }
75 return idxCallbacker(err, len(ks), func(_ int, err error) { 86 return idxCallbacker(err, len(ks), func(_ int, err error) {
76 cb(err) 87 cb(err)
77 }) 88 })
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 func (d rdsImpl) RunInTransaction(f func(c context.Context) error, opts *ds.Tran sactionOptions) error { 241 func (d rdsImpl) RunInTransaction(f func(c context.Context) error, opts *ds.Tran sactionOptions) error {
231 ropts := (*datastore.TransactionOptions)(opts) 242 ropts := (*datastore.TransactionOptions)(opts)
232 return datastore.RunInTransaction(d.aeCtx, func(c context.Context) error { 243 return datastore.RunInTransaction(d.aeCtx, func(c context.Context) error {
233 return f(context.WithValue(d.userCtx, prodContextKey, c)) 244 return f(context.WithValue(d.userCtx, prodContextKey, c))
234 }, ropts) 245 }, ropts)
235 } 246 }
236 247
237 func (d rdsImpl) Testable() ds.Testable { 248 func (d rdsImpl) Testable() ds.Testable {
238 return nil 249 return nil
239 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698