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 dscache | 5 package dscache |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 | 9 |
10 ds "github.com/luci/gae/service/datastore" | 10 ds "github.com/luci/gae/service/datastore" |
11 mc "github.com/luci/gae/service/memcache" | 11 mc "github.com/luci/gae/service/memcache" |
12 "github.com/luci/luci-go/common/errors" | 12 "github.com/luci/luci-go/common/errors" |
13 "github.com/luci/luci-go/common/logging" | 13 "github.com/luci/luci-go/common/logging" |
14 "golang.org/x/net/context" | 14 "golang.org/x/net/context" |
15 ) | 15 ) |
16 | 16 |
17 type facts struct { | 17 type facts struct { |
18 » getKeys []ds.Key | 18 » getKeys []*ds.Key |
19 getMeta ds.MultiMetaGetter | 19 getMeta ds.MultiMetaGetter |
20 lockItems []mc.Item | 20 lockItems []mc.Item |
21 nonce []byte | 21 nonce []byte |
22 } | 22 } |
23 | 23 |
24 type plan struct { | 24 type plan struct { |
25 keepMeta bool | 25 keepMeta bool |
26 | 26 |
27 // idxMap maps from the original list of keys to the reduced set of keys
in | 27 // idxMap maps from the original list of keys to the reduced set of keys
in |
28 // toGet. E.g. given the index `j` while looping over toGet, idxMap[j] w
ill | 28 // toGet. E.g. given the index `j` while looping over toGet, idxMap[j] w
ill |
29 // equal the index in the original facts.getKeys list. | 29 // equal the index in the original facts.getKeys list. |
30 idxMap []int | 30 idxMap []int |
31 | 31 |
32 // toGet is a list of datstore keys to retrieve in the call down to the | 32 // toGet is a list of datstore keys to retrieve in the call down to the |
33 // underlying datastore. It will have length >= facts.getKeys. All the k
eys | 33 // underlying datastore. It will have length >= facts.getKeys. All the k
eys |
34 // in this will be valid (not nil). | 34 // in this will be valid (not nil). |
35 » toGet []ds.Key | 35 » toGet []*ds.Key |
36 | 36 |
37 // toGetMeta is a MultiMetaGetter to be passed in the call down to the | 37 // toGetMeta is a MultiMetaGetter to be passed in the call down to the |
38 // underlying datastore.GetMulti. It has the same length as toGet. | 38 // underlying datastore.GetMulti. It has the same length as toGet. |
39 toGetMeta ds.MultiMetaGetter | 39 toGetMeta ds.MultiMetaGetter |
40 | 40 |
41 // toSave is the list of memcache items to save the results from the | 41 // toSave is the list of memcache items to save the results from the |
42 // underlying datastore.GetMulti. It MAY contain nils, which is an indic
ator | 42 // underlying datastore.GetMulti. It MAY contain nils, which is an indic
ator |
43 // that this entry SHOULD NOT be saved to memcache. | 43 // that this entry SHOULD NOT be saved to memcache. |
44 toSave []mc.Item | 44 toSave []mc.Item |
45 | 45 |
46 // decoded is a list of all the decoded property maps. Its length always
== | 46 // decoded is a list of all the decoded property maps. Its length always
== |
47 // len(facts.getKeys). After the plan is formed, it may contain nils. Th
ese | 47 // len(facts.getKeys). After the plan is formed, it may contain nils. Th
ese |
48 // nils will be filled in from the underlying datastore.GetMulti call in | 48 // nils will be filled in from the underlying datastore.GetMulti call in |
49 // ds.go. | 49 // ds.go. |
50 decoded []ds.PropertyMap | 50 decoded []ds.PropertyMap |
51 | 51 |
52 // lme is a LazyMultiError whose target Size == len(facts.getKeys). The
errors | 52 // lme is a LazyMultiError whose target Size == len(facts.getKeys). The
errors |
53 // will eventually bubble back to the layer above this filter in callbac
ks. | 53 // will eventually bubble back to the layer above this filter in callbac
ks. |
54 lme errors.LazyMultiError | 54 lme errors.LazyMultiError |
55 } | 55 } |
56 | 56 |
57 // add adds a new entry to be retrieved from the actual underlying datastore | 57 // add adds a new entry to be retrieved from the actual underlying datastore |
58 // (via GetMulti). | 58 // (via GetMulti). |
59 // | 59 // |
60 // - idx is the index into the original facts.getKeys | 60 // - idx is the index into the original facts.getKeys |
61 // - get and m are the pair of values that will be passed to datastore.GetMult
i | 61 // - get and m are the pair of values that will be passed to datastore.GetMult
i |
62 // - save is the memcache item to save the result back to. If it's nil, then | 62 // - save is the memcache item to save the result back to. If it's nil, then |
63 // it will not be saved back to memcache. | 63 // it will not be saved back to memcache. |
64 func (p *plan) add(idx int, get ds.Key, m ds.MetaGetter, save mc.Item) { | 64 func (p *plan) add(idx int, get *ds.Key, m ds.MetaGetter, save mc.Item) { |
65 p.idxMap = append(p.idxMap, idx) | 65 p.idxMap = append(p.idxMap, idx) |
66 p.toGet = append(p.toGet, get) | 66 p.toGet = append(p.toGet, get) |
67 | 67 |
68 p.toSave = append(p.toSave, save) | 68 p.toSave = append(p.toSave, save) |
69 | 69 |
70 if p.keepMeta { | 70 if p.keepMeta { |
71 p.toGetMeta = append(p.toGetMeta, m) | 71 p.toGetMeta = append(p.toGetMeta, m) |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 p.add(i, getKey, m, nil) | 128 p.add(i, getKey, m, nil) |
129 } | 129 } |
130 | 130 |
131 default: | 131 default: |
132 // have some other sort of object, or our AddMulti faile
d to add this item. | 132 // have some other sort of object, or our AddMulti faile
d to add this item. |
133 p.add(i, getKey, m, nil) | 133 p.add(i, getKey, m, nil) |
134 } | 134 } |
135 } | 135 } |
136 return &p | 136 return &p |
137 } | 137 } |
OLD | NEW |