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

Side by Side Diff: tokenserver/appengine/impl/utils/policy/entities.go

Issue 2951393002: [errors] de-specialize Transient in favor of Tags. (Closed)
Patch Set: more refactor Created 3 years, 5 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 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 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 policy 5 package policy
6 6
7 import ( 7 import (
8 "golang.org/x/net/context" 8 "golang.org/x/net/context"
9 9
10 "github.com/luci/gae/service/datastore" 10 "github.com/luci/gae/service/datastore"
11 » "github.com/luci/luci-go/common/errors" 11 » "github.com/luci/luci-go/common/retry/transient"
12 ) 12 )
13 13
14 // importedPolicyHeader is an entity that holds metadata about a cached policy. 14 // importedPolicyHeader is an entity that holds metadata about a cached policy.
15 // 15 //
16 // Most crucially, it stores a digest of serialized policy configs. It is used 16 // Most crucially, it stores a digest of serialized policy configs. It is used
17 // by Policy.Queryable() to quickly detect that no changes to the config have 17 // by Policy.Queryable() to quickly detect that no changes to the config have
18 // been made. 18 // been made.
19 // 19 //
20 // The actual serialized configs (that are much heavier than metadata) are 20 // The actual serialized configs (that are much heavier than metadata) are
21 // stored in a separate child entity, fetched only when they are really needed. 21 // stored in a separate child entity, fetched only when they are really needed.
(...skipping 26 matching lines...) Expand all
48 Name: name, 48 Name: name,
49 Revision: rev, 49 Revision: rev,
50 SHA256: sha256, 50 SHA256: sha256,
51 } 51 }
52 body := &importedPolicyBody{ 52 body := &importedPolicyBody{
53 Parent: datastore.KeyForObj(c, header), 53 Parent: datastore.KeyForObj(c, header),
54 Revision: rev, 54 Revision: rev,
55 SHA256: sha256, 55 SHA256: sha256,
56 Data: serialized, 56 Data: serialized,
57 } 57 }
58 » return errors.WrapTransient(datastore.RunInTransaction(c, func(c context .Context) error { 58 » return transient.Tag.Apply(datastore.RunInTransaction(c, func(c context. Context) error {
59 return datastore.Put(c, header, body) 59 return datastore.Put(c, header, body)
60 }, nil)) 60 }, nil))
61 } 61 }
62 62
63 // getImportedPolicyHeader loads importedPolicyHeader entity from the datastore. 63 // getImportedPolicyHeader loads importedPolicyHeader entity from the datastore.
64 // 64 //
65 // Returns (nil, nil) if there's no such entity. 65 // Returns (nil, nil) if there's no such entity.
66 func getImportedPolicyHeader(c context.Context, name string) (*importedPolicyHea der, error) { 66 func getImportedPolicyHeader(c context.Context, name string) (*importedPolicyHea der, error) {
67 e := &importedPolicyHeader{Name: name} 67 e := &importedPolicyHeader{Name: name}
68 switch err := datastore.Get(c, e); { 68 switch err := datastore.Get(c, e); {
69 case err == datastore.ErrNoSuchEntity: 69 case err == datastore.ErrNoSuchEntity:
70 return nil, nil 70 return nil, nil
71 case err != nil: 71 case err != nil:
72 » » return nil, errors.WrapTransient(err) 72 » » return nil, transient.Tag.Apply(err)
73 } 73 }
74 return e, nil 74 return e, nil
75 } 75 }
76 76
77 // getImportedPolicyBody loads importedPolicyBody entity from the datastore. 77 // getImportedPolicyBody loads importedPolicyBody entity from the datastore.
78 // 78 //
79 // Returns (nil, nil) if there's no such entity. 79 // Returns (nil, nil) if there's no such entity.
80 func getImportedPolicyBody(c context.Context, name string) (*importedPolicyBody, error) { 80 func getImportedPolicyBody(c context.Context, name string) (*importedPolicyBody, error) {
81 e := &importedPolicyBody{ 81 e := &importedPolicyBody{
82 Parent: datastore.KeyForObj(c, &importedPolicyHeader{Name: name} ), 82 Parent: datastore.KeyForObj(c, &importedPolicyHeader{Name: name} ),
83 } 83 }
84 switch err := datastore.Get(c, e); { 84 switch err := datastore.Get(c, e); {
85 case err == datastore.ErrNoSuchEntity: 85 case err == datastore.ErrNoSuchEntity:
86 return nil, nil 86 return nil, nil
87 case err != nil: 87 case err != nil:
88 » » return nil, errors.WrapTransient(err) 88 » » return nil, transient.Tag.Apply(err)
89 } 89 }
90 return e, nil 90 return e, nil
91 } 91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698