Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Issue 1269113005: A transparent cache for datastore, backed by memcache. (Closed)

Created:
5 years, 4 months ago by iannucci
Modified:
5 years, 4 months ago
CC:
chromium-reviews
Base URL:
https://github.com/luci/gae.git@add_meta
Target Ref:
refs/heads/master
Visibility:
Public.

Description

A transparent cache for datastore, backed by memcache. Check doc.go for details, but: * allows cache disablement on a per-model/Key basis * allows cache expiration on a per-model basis * efficient (non-gob) encoding scheme * gzip for large entities * allows randomized sharding for Gets * allows good throughput for hot items * shards may be determined on a per-Key basis * caches negative hits R=dnj@chromium.org, vadimsh@chromium.org, estaab@chromium.org, tandrii@chromium.org BUG= Committed: https://github.com/luci/gae/commit/bf5c5a93f90884d7f1a85ad5ad68e5b3a323e6f9

Patch Set 1 #

Total comments: 1

Patch Set 2 : fix old references #

Patch Set 3 : 81% #

Patch Set 4 : refactor #

Patch Set 5 : fix stuff #

Patch Set 6 : cleanup #

Patch Set 7 : rebase #

Patch Set 8 : Ready to rock #

Patch Set 9 : add test for per-model expiration #

Total comments: 95

Patch Set 10 : Made algorithm more correct, fixed some boogs, added global escape hatch. #

Patch Set 11 : docs #

Patch Set 12 : more fixins #

Patch Set 13 : clarify and refactor #

Patch Set 14 : some minor comments #

Total comments: 16

Patch Set 15 : fix comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1593 lines, -38 lines) Patch
A filter/dscache/context.go View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +54 lines, -0 lines 0 comments Download
A filter/dscache/doc.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 chunk +160 lines, -0 lines 0 comments Download
A filter/dscache/ds.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 1 chunk +139 lines, -0 lines 0 comments Download
A filter/dscache/ds_txn.go View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +32 lines, -0 lines 0 comments Download
A filter/dscache/ds_txn_state.go View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +86 lines, -0 lines 0 comments Download
A filter/dscache/dscache.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 chunk +117 lines, -0 lines 0 comments Download
A filter/dscache/dscache_test.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 chunk +457 lines, -0 lines 0 comments Download
A filter/dscache/globalconfig.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 chunk +107 lines, -0 lines 0 comments Download
A filter/dscache/plan.go View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +137 lines, -0 lines 0 comments Download
A filter/dscache/serialize.go View 1 2 3 1 chunk +61 lines, -0 lines 0 comments Download
A filter/dscache/support.go View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +158 lines, -0 lines 0 comments Download
M impl/memory/memcache.go View 1 2 3 4 5 6 7 8 9 3 chunks +10 lines, -2 lines 0 comments Download
M impl/memory/raw_datastore_data.go View 1 2 3 4 5 6 7 8 9 1 chunk +11 lines, -9 lines 0 comments Download
M impl/prod/memcache.go View 1 2 3 4 5 6 7 1 chunk +7 lines, -5 lines 0 comments Download
M service/datastore/properties.go View 1 2 3 4 5 2 chunks +7 lines, -1 line 0 comments Download
M service/datastore/properties_test.go View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M service/datastore/serialize.go View 1 chunk +10 lines, -5 lines 0 comments Download
M service/memcache/memcache.go View 1 2 3 4 5 6 7 3 chunks +34 lines, -12 lines 0 comments Download
M service/memcache/raw_interface.go View 1 2 3 4 5 6 7 1 chunk +2 lines, -1 line 0 comments Download
M service/memcache/types.go View 1 2 3 4 5 6 7 1 chunk +3 lines, -2 lines 0 comments Download

Messages

Total messages: 14 (0 generated)
iannucci
5 years, 4 months ago (2015-08-04 05:17:30 UTC) #1
iannucci
On 2015/08/04 05:17:30, iannucci wrote: Has ~65% coverage in tests, will be adding more, but ...
5 years, 4 months ago (2015-08-04 05:18:02 UTC) #2
iannucci
https://codereview.chromium.org/1269113005/diff/1/filter/dscache/dscache_test.go File filter/dscache/dscache_test.go (right): https://codereview.chromium.org/1269113005/diff/1/filter/dscache/dscache_test.go#newcode82 filter/dscache/dscache_test.go:82: []byte("\x00\x80\x80W1[\x8fW(\x80\x80\x06i5@")) for reference, the equivalent gob encoding is 57 ...
5 years, 4 months ago (2015-08-04 05:26:17 UTC) #3
iannucci
OK, PTAL. Tests only cover ~96%, but the rest is really boring crap (like serialization ...
5 years, 4 months ago (2015-08-05 08:00:41 UTC) #4
Vadim Sh.
(reviewed doc.go only) https://codereview.chromium.org/1269113005/diff/150001/filter/dscache/doc.go File filter/dscache/doc.go (right): https://codereview.chromium.org/1269113005/diff/150001/filter/dscache/doc.go#newcode26 filter/dscache/doc.go:26: // - SHA1 has been chosen ...
5 years, 4 months ago (2015-08-05 17:09:31 UTC) #5
dnj
https://codereview.chromium.org/1269113005/diff/150001/filter/dscache/context.go File filter/dscache/context.go (right): https://codereview.chromium.org/1269113005/diff/150001/filter/dscache/context.go#newcode39 filter/dscache/context.go:39: logging.Get(ic), Why not retain the context itself, instead of ...
5 years, 4 months ago (2015-08-05 18:32:18 UTC) #6
Vadim Sh.
Ok, looked through most of it. My brain hurts. Consider making smaller code dumps :( ...
5 years, 4 months ago (2015-08-06 01:23:34 UTC) #7
iannucci
PTAL again https://codereview.chromium.org/1269113005/diff/150001/filter/dscache/context.go File filter/dscache/context.go (right): https://codereview.chromium.org/1269113005/diff/150001/filter/dscache/context.go#newcode39 filter/dscache/context.go:39: logging.Get(ic), On 2015/08/05 18:32:17, dnj wrote: > ...
5 years, 4 months ago (2015-08-06 01:54:02 UTC) #8
iannucci
https://codereview.chromium.org/1269113005/diff/150001/filter/dscache/context.go File filter/dscache/context.go (right): https://codereview.chromium.org/1269113005/diff/150001/filter/dscache/context.go#newcode20 filter/dscache/context.go:20: // FilterRDS installs a counter RawDatastore filter in the ...
5 years, 4 months ago (2015-08-06 02:37:33 UTC) #9
iannucci
PTAL/pang :)
5 years, 4 months ago (2015-08-07 00:05:18 UTC) #10
dnj
lgtm w/ nits https://codereview.chromium.org/1269113005/diff/150001/filter/dscache/ds.go File filter/dscache/ds.go (right): https://codereview.chromium.org/1269113005/diff/150001/filter/dscache/ds.go#newcode50 filter/dscache/ds.go:50: if !p.empty() { On 2015/08/06 01:54:01, ...
5 years, 4 months ago (2015-08-07 16:30:07 UTC) #11
Vadim Sh.
lgtm with nit also add a TODO to investigate a "fast path" algorithm to do ...
5 years, 4 months ago (2015-08-07 17:30:47 UTC) #12
iannucci
Committed patchset #15 (id:260001) manually as bf5c5a93f90884d7f1a85ad5ad68e5b3a323e6f9 (presubmit successful).
5 years, 4 months ago (2015-08-07 19:40:36 UTC) #13
iannucci
5 years, 4 months ago (2015-08-07 19:41:00 UTC) #14
Message was sent while issue was closed.
oh, fixed all the nits btw

https://chromiumcodereview.appspot.com/1269113005/diff/250001/filter/dscache/...
File filter/dscache/doc.go (right):

https://chromiumcodereview.appspot.com/1269113005/diff/250001/filter/dscache/...
filter/dscache/doc.go:116: // at random. This is good for heavily-read, but
infrequently updated, entities.
On 2015/08/07 17:30:47, Vadim Sh. wrote:
> nit: mention that it's needed to avoid having hot keys in memcached, e.g. the
> contention happens in memcached guts, not in our code. You sort of mention
this
> below, but it would be clearer here.

Done.

https://chromiumcodereview.appspot.com/1269113005/diff/250001/filter/dscache/...
File filter/dscache/dscache.go (right):

https://chromiumcodereview.appspot.com/1269113005/diff/250001/filter/dscache/...
filter/dscache/dscache.go:36: CacheTimeSeconds int64 = int64((time.Hour *
24).Seconds())
On 2015/08/07 16:30:06, dnj wrote:
> WDYT about just making this a "time.Duration" w/ the comment note that the
value
> will be rounded up to seconds? No need to fudge around with integer values
when
> discussing time intervals.

I mentioned this elsewhere, but memcache truncates to the second. This means if
you set this to, say, less than a second, it will actually be infinite. I
updated this comment.

https://chromiumcodereview.appspot.com/1269113005/diff/250001/filter/dscache/...
filter/dscache/dscache.go:122: type GlobalConfig struct {
On 2015/08/07 16:30:06, dnj wrote:
> IMO move to a separate ".go" file.

Done.

https://chromiumcodereview.appspot.com/1269113005/diff/250001/filter/dscache/...
filter/dscache/dscache.go:157: globalEnabledLock.RLock()
On 2015/08/07 16:30:07, dnj wrote:
> For peace of mind (and to avoid C-style cleanup patterns), consider one of:
> globalEnabledLock.RLock()
> nextCheck := globalEnabledNextCheck
> globalEnabledLock.RUnlock()
> if now.Before(nextCheck) { ... }

derp, dunno what I was thinking. did this.

> 
> -or-
> 
> def getGlobalEnabledNextCheck() time.Time {
>   globalEnabledLock.RLock()
>   defer globalEnabledLock.RUnlock()
>   return globalEnabled
> }
> 
> ...
> 
> if now.Before(getGlobalEnabledNextCheck()) { ... }

https://chromiumcodereview.appspot.com/1269113005/diff/250001/filter/dscache/...
filter/dscache/dscache.go:171: // alawys go to the default namespace
On 2015/08/07 16:30:06, dnj wrote:
> always

Done.

https://chromiumcodereview.appspot.com/1269113005/diff/250001/filter/dscache/...
filter/dscache/dscache.go:174: return true
On 2015/08/07 16:30:06, dnj wrote:
> When the memcache failure case can perpetuate stale data, perhaps the default
> error result should be "false".

Nope, because then you could end up doing Put operations without invalidating
the memcache, where all the other instances would then read stale data. I
explain this in the comment on this function :)

https://chromiumcodereview.appspot.com/1269113005/diff/250001/filter/dscache/...
filter/dscache/dscache.go:182: return globalEnabled
On 2015/08/07 16:30:06, dnj wrote:
> Just return "cfg.Enable".

I actually prefer not to. globalEnabled is the value that everything in the
program sees, but cfg.Enable is local to this function. if future code ends up
not updating gloablEnabled for some reason, then this will continue to return a
program-wide consistent value. If I make it cfg.Enable, it could return an
inconsistent value.

https://chromiumcodereview.appspot.com/1269113005/diff/250001/filter/dscache/...
filter/dscache/dscache.go:185: func SetDynamicGlobalEnable(c context.Context,
memcacheEnabled bool) error {
On 2015/08/07 16:30:07, dnj wrote:
> Why "Dynamic"? Seems inconsistent with the other variables/methods.

old naming artifact. fixed.

Powered by Google App Engine
This is Rietveld 408576698