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 "time" | 8 "time" |
9 | 9 |
10 ds "github.com/luci/gae/service/datastore" | 10 ds "github.com/luci/gae/service/datastore" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 | 51 |
52 p := makeFetchPlan(d.c, d.aid, d.ns, &facts{keys, metas, lockItems, nonc
e}) | 52 p := makeFetchPlan(d.c, d.aid, d.ns, &facts{keys, metas, lockItems, nonc
e}) |
53 | 53 |
54 if !p.empty() { | 54 if !p.empty() { |
55 // looks like we have something to pull from datastore, and mayb
e some work | 55 // looks like we have something to pull from datastore, and mayb
e some work |
56 // to save stuff back to memcache. | 56 // to save stuff back to memcache. |
57 | 57 |
58 toCas := []memcache.Item{} | 58 toCas := []memcache.Item{} |
59 j := 0 | 59 j := 0 |
60 » » err := d.RawInterface.GetMulti(p.toGet, p.toGetMeta, func(pm ds.
PropertyMap, err error) { | 60 » » err := d.RawInterface.GetMulti(p.toGet, p.toGetMeta, func(pm ds.
PropertyMap, err error) error { |
61 i := p.idxMap[j] | 61 i := p.idxMap[j] |
62 toSave := p.toSave[j] | 62 toSave := p.toSave[j] |
63 j++ | 63 j++ |
64 | 64 |
65 data := []byte(nil) | 65 data := []byte(nil) |
66 | 66 |
67 // true: save entity to memcache | 67 // true: save entity to memcache |
68 // false: lock entity in memcache forever | 68 // false: lock entity in memcache forever |
69 shouldSave := true | 69 shouldSave := true |
70 if err == nil { | 70 if err == nil { |
71 p.decoded[i] = pm | 71 p.decoded[i] = pm |
72 if toSave != nil { | 72 if toSave != nil { |
73 data = encodeItemValue(pm) | 73 data = encodeItemValue(pm) |
74 if len(data) > internalValueSizeLimit { | 74 if len(data) > internalValueSizeLimit { |
75 shouldSave = false | 75 shouldSave = false |
76 log.Warningf( | 76 log.Warningf( |
77 d.c, "dscache: encoded e
ntity too big (%d/%d)!", | 77 d.c, "dscache: encoded e
ntity too big (%d/%d)!", |
78 len(data), internalValue
SizeLimit) | 78 len(data), internalValue
SizeLimit) |
79 } | 79 } |
80 } | 80 } |
81 } else { | 81 } else { |
82 p.lme.Assign(i, err) | 82 p.lme.Assign(i, err) |
83 if err != ds.ErrNoSuchEntity { | 83 if err != ds.ErrNoSuchEntity { |
84 » » » » » return // aka continue to the next entry | 84 » » » » » return nil // aka continue to the next e
ntry |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 if toSave != nil { | 88 if toSave != nil { |
89 if shouldSave { // save | 89 if shouldSave { // save |
90 mg := metas.GetSingle(i) | 90 mg := metas.GetSingle(i) |
91 expSecs := ds.GetMetaDefault(mg, CacheEx
pirationMeta, CacheTimeSeconds).(int64) | 91 expSecs := ds.GetMetaDefault(mg, CacheEx
pirationMeta, CacheTimeSeconds).(int64) |
92 toSave.SetFlags(uint32(ItemHasData)) | 92 toSave.SetFlags(uint32(ItemHasData)) |
93 toSave.SetExpiration(time.Duration(expSe
cs) * time.Second) | 93 toSave.SetExpiration(time.Duration(expSe
cs) * time.Second) |
94 toSave.SetValue(data) | 94 toSave.SetValue(data) |
95 } else { | 95 } else { |
96 // Set a lock with an infinite timeout.
No one else should try to | 96 // Set a lock with an infinite timeout.
No one else should try to |
97 // serialize this item to memcache until
something Put/Delete's it. | 97 // serialize this item to memcache until
something Put/Delete's it. |
98 toSave.SetFlags(uint32(ItemHasLock)) | 98 toSave.SetFlags(uint32(ItemHasLock)) |
99 toSave.SetExpiration(0) | 99 toSave.SetExpiration(0) |
100 toSave.SetValue(nil) | 100 toSave.SetValue(nil) |
101 } | 101 } |
102 toCas = append(toCas, toSave) | 102 toCas = append(toCas, toSave) |
103 } | 103 } |
| 104 return nil |
104 }) | 105 }) |
105 if err != nil { | 106 if err != nil { |
106 return err | 107 return err |
107 } | 108 } |
108 if len(toCas) > 0 { | 109 if len(toCas) > 0 { |
109 // we have entries to save back to memcache. | 110 // we have entries to save back to memcache. |
110 if err := d.mc.CompareAndSwapMulti(toCas); err != nil { | 111 if err := d.mc.CompareAndSwapMulti(toCas); err != nil { |
111 (log.Fields{log.ErrorKey: err}).Warningf( | 112 (log.Fields{log.ErrorKey: err}).Warningf( |
112 d.c, "dscache: GetMulti: memcache.Compar
eAndSwapMulti") | 113 d.c, "dscache: GetMulti: memcache.Compar
eAndSwapMulti") |
113 } | 114 } |
(...skipping 17 matching lines...) Expand all Loading... |
131 if err == nil { | 132 if err == nil { |
132 err = txnState.apply(d.supportContext) | 133 err = txnState.apply(d.supportContext) |
133 } | 134 } |
134 return err | 135 return err |
135 }, opts) | 136 }, opts) |
136 if err == nil { | 137 if err == nil { |
137 txnState.release(d.supportContext) | 138 txnState.release(d.supportContext) |
138 } | 139 } |
139 return err | 140 return err |
140 } | 141 } |
OLD | NEW |