Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package dscache | |
| 6 | |
| 7 import ( | |
| 8 "bytes" | |
| 9 | |
| 10 ds "github.com/luci/gae/service/datastore" | |
| 11 mc "github.com/luci/gae/service/memcache" | |
| 12 "github.com/luci/luci-go/common/errors" | |
| 13 "github.com/luci/luci-go/common/logging" | |
| 14 ) | |
| 15 | |
| 16 type facts struct { | |
| 17 getKeys []ds.Key | |
| 18 getMeta ds.MultiMetaGetter | |
| 19 lockItems []mc.Item | |
| 20 nonce []byte | |
| 21 } | |
| 22 | |
| 23 type plan struct { | |
| 24 keepMeta bool | |
| 25 | |
| 26 idxMap []int | |
| 27 toGet []ds.Key | |
| 28 toGetMeta ds.MultiMetaGetter | |
| 29 toSave []mc.Item | |
| 30 | |
| 31 decoded []ds.PropertyMap | |
| 32 lme errors.LazyMultiError | |
| 33 } | |
| 34 | |
| 35 func (p *plan) add(idx int, get ds.Key, m ds.MetaGetter, save mc.Item) { | |
| 36 p.idxMap = append(p.idxMap, idx) | |
| 37 p.toGet = append(p.toGet, get) | |
| 38 | |
| 39 p.toSave = append(p.toSave, save) | |
|
Vadim Sh.
2015/08/06 01:23:34
is it ok that you append 'nil's here?
iannucci
2015/08/06 02:37:33
yeah. nil means "don't save it" I added a bunch of
| |
| 40 | |
| 41 if p.keepMeta { | |
| 42 p.toGetMeta = append(p.toGetMeta, m) | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 func (p *plan) empty() bool { | |
| 47 return len(p.idxMap) == 0 | |
| 48 } | |
| 49 | |
| 50 func makePlan(aid, ns string, log logging.Logger, f *facts) *plan { | |
|
Vadim Sh.
2015/08/06 01:23:34
nit: makeFetchPlan or something
iannucci
2015/08/06 02:37:33
Done.
| |
| 51 p := plan{ | |
| 52 keepMeta: f.getMeta != nil, | |
| 53 decoded: make([]ds.PropertyMap, len(f.lockItems)), | |
| 54 lme: errors.LazyMultiError{Size: len(f.lockItems)}, | |
| 55 } | |
| 56 for i, lockItm := range f.lockItems { | |
| 57 m := f.getMeta.GetSingle(i) | |
| 58 getKey := f.getKeys[i] | |
| 59 | |
| 60 if lockItm == nil { // this item wasn't cacheable | |
|
Vadim Sh.
2015/08/06 01:23:34
typo: "wasn't cached" (unless I misunderstand some
iannucci
2015/08/06 02:37:33
fixed comment, it meant something different.
| |
| 61 p.add(i, getKey, m, nil) | |
| 62 continue | |
| 63 } | |
| 64 | |
| 65 flg := FlagValue(lockItm.Flags()) | |
| 66 if flg == ItemHasLock { | |
|
dnj
2015/08/05 18:32:18
Consider "switch" on "flag", clearer what values/a
iannucci
2015/08/06 01:54:01
Done.
| |
| 67 if !bytes.Equal(f.nonce, lockItm.Value()) { | |
|
dnj
2015/08/05 18:32:18
Invert this to make it more readable: if bytes.Equ
iannucci
2015/08/06 01:54:01
Done.
| |
| 68 lockItm = nil // someone else has the lock, don' t save | |
| 69 } | |
| 70 p.add(i, getKey, m, lockItm) | |
| 71 continue | |
| 72 } | |
| 73 | |
| 74 // have some other sort of object, or our AddMulti failed to add this item. | |
| 75 if flg != ItemHasData { | |
| 76 p.add(i, getKey, m, nil) | |
| 77 continue | |
| 78 } | |
| 79 | |
| 80 pmap, err := decodeItemValue(lockItm.Value(), aid, ns) | |
| 81 switch err { | |
| 82 case nil: | |
| 83 p.decoded[i] = pmap | |
| 84 case ds.ErrNoSuchEntity: | |
| 85 p.lme.Assign(i, ds.ErrNoSuchEntity) | |
| 86 default: | |
| 87 log.Errorf("dscache: error decoding %s, %s: %s", lockItm .Key(), getKey, err) | |
| 88 p.add(i, getKey, m, nil) | |
| 89 } | |
| 90 } | |
| 91 return &p | |
| 92 } | |
| OLD | NEW |