OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 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 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // | 160 // |
161 // AppEngine's memcache reserves the right to evict keys at any moment. This is | 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 | 162 // especially true for shared memcache, which is subject to pressures outside of |
163 // your application. When when eviction happens due to memory pressure, | 163 // your application. When eviction happens due to memory pressure, |
164 // least-recently-used values are evicted first. | 164 // least-recently-used values are evicted first. |
165 // | 165 // |
166 // https://cloud.google.com/appengine/docs/go/memcache/#Go_How_cached_data_expir
es | 166 // https://cloud.google.com/appengine/docs/go/memcache/#Go_How_cached_data_expir
es |
167 // | 167 // |
168 // Eviction presents a potential race window, as lock items that were put in | 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 | 169 // memcache may be evicted prior to the locked operations completing (or |
170 // failing), causing concurrent Get operations to cache bad data indefinitely. | 170 // failing), causing concurrent Get operations to cache bad data indefinitely. |
171 // | 171 // |
172 // In practice, a dedicated memcache will be safe. LRU-based eviction means that | 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 | 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 | 174 // operations are complete, and a dedicated memcache lowers eviction pressure to |
175 // a single application's operation. Production systems that have data integrity | 175 // a single application's operation. Production systems that have data integrity |
176 // requirements are encouraged to use a dedicated memcache. | 176 // requirements are encouraged to use a dedicated memcache. |
177 // | 177 // |
178 // Note that flusing memcache of a running application may also induce this | 178 // Note that flusing memcache of a running application may also induce this |
179 // race. Flushes should be performed with this concern in mind. | 179 // race. Flushes should be performed with this concern in mind. |
180 // | 180 // |
181 // TODO: A potential mitigation to lock eviction poisoning is to use memcache | 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 | 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 | 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), | 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. | 185 // bounding the period of time when poisoned data may reside in the cache. |
186 package dscache | 186 package dscache |
OLD | NEW |