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 provides a transparent cache for RawDatastore which is | 5 // Package dscache provides a transparent cache for RawDatastore which is |
6 // backed by Memcache. | 6 // backed by Memcache. |
7 // | 7 // |
8 // Inspiration | 8 // Inspiration |
9 // | 9 // |
10 // Although this is not a port of any particular implementation, it takes | 10 // Although this is not a port of any particular implementation, it takes |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 // effect. If you have very long-running backend requests, you may need to | 150 // effect. If you have very long-running backend requests, you may need to |
151 // cycle them to have it take effect. This dynamic bit is read essentially | 151 // cycle them to have it take effect. This dynamic bit is read essentially |
152 // once per http request (when FilteRDS is called on the context). | 152 // once per http request (when FilteRDS is called on the context). |
153 // - push a new version of the application disabling the cache filter | 153 // - push a new version of the application disabling the cache filter |
154 // by setting InstanceEnabledStatic to false in an init() function. | 154 // by setting InstanceEnabledStatic to false in an init() function. |
155 // | 155 // |
156 // On every dscache.FilterRDS invocation, it takes the opportunity to fetch this | 156 // On every dscache.FilterRDS invocation, it takes the opportunity to fetch this |
157 // datastore value, if it hasn't been fetched in the last | 157 // datastore value, if it hasn't been fetched in the last |
158 // GlobalEnabledCheckInterval time (5 minutes). This equates to essentially once | 158 // GlobalEnabledCheckInterval time (5 minutes). This equates to essentially once |
159 // per http request, per 5 minutes, per instance. | 159 // per http request, per 5 minutes, per instance. |
160 // | |
161 // AppEngine's memcache reserves the right to evict keys at any moment. This is | |
162 // especially true for shared memcache, which is subject to pressures outside of | |
163 // your application. When when eviction happens due to memory pressure, | |
164 // least-recently-used values are evicted first. | |
165 // | |
166 // https://cloud.google.com/appengine/docs/go/memcache/#Go_How_cached_data_expir es | |
167 // | |
168 // Eviction presents a potential race window, as lock items that were put in | |
169 // memcache may be evicted prior to the locked operations completing (or | |
170 // failing), causing concurrent Get operations to cache bad data indefinitely. | |
171 // | |
172 // In practice, a dedicated memcache will be safe. LRU-based eviction means that | |
173 // that locks recently added will almost certainly not be evicted before their | |
174 // operations are complete, and a dedicated memcache lowers eviction pressure to | |
175 // a single application's operation. Production systems that have data integrity | |
176 // requirements are encouraged to use a dedicated memcache. | |
177 // | |
178 // Note that flusing memcache of a running application may also induce this | |
179 // race. Flushes should be performed with this concern in mind. | |
180 // | |
181 // TODO: A potential mitigation to lock eviction poisoning is to use memcache | |
182 // Statistics to identify the oldest memcache item and use that age to bound | |
183 // the lifetime of cached datastore entries. This would cause dscache items | |
184 // created around the time of a flush to expire quickly (instead of never), | |
185 // bounding the period of time when poisoned data may reside in the cache. | |
iannucci
2016/05/29 19:49:12
but even with this, there's potential for a sampli
dnj
2016/05/29 21:25:18
Hmm we could do a post-Put Statistics grab and try
| |
160 package dscache | 186 package dscache |
OLD | NEW |