Repository navigation
Conversation
Hold the client as BaseClient, so either a standalone GlideClient or a cluster GlideClusterClient can be passed in. Replace MGET/MSET/multi-key DEL with per-key GET/SET/DEL issued concurrently, since multi-key commands fail with CROSSSLOT on a cluster whenever the keys hash to different slots -- which is the normal case for Objectify keys. CAS still uses the native SET ... IFEQ from Valkey 8.1, but on a cluster the command is routed explicitly to the primary owning the key's slot (SlotKeyRoute). customCommand isn't declared on BaseClient and returns a ClusterValue on the cluster client, so both client types are handled in one place (casAsync).
Every write went to Valkey with no expiration: put/putAll, the cold-cache null sentinel bootstrapped in getIdentifiables, and putIfUntouched when the entity declared no expirationSeconds (the common case -- a bare @Cache is 0). Memcache sheds cold entries via LRU, so a no-TTL write pattern was fine there. A Valkey server or cluster configured with noeviction cannot: the keyspace grows until maxmemory, after which every write against that server fails with OOM -- including writes from unrelated callers sharing it. Apply a default TTL (24h) to all write paths; entities that declare their own expiration still keep it. The single-arg constructor supplies the default, so existing callers are unchanged, and a second constructor takes an explicit value.
Contributor
Author
Contributor
Author
|
@stickfigure Whoops, forgot I had already submitted these changes. Please ignore. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #527, from running that cache in production.
1. Cluster support.
ValkeyCacheServiceonly worked against a standalone server.MGET/MSET/multi-keyDELfail withCROSSSLOTon a cluster as soon as the keys hash to different slots, which is the normal case for Objectify keys. This holds the client asBaseClientso either aGlideClientor aGlideClusterClientcan be supplied, and issues the multi-key operations as independent per-key commands fired concurrently (glide multiplexes them over the connection, so this costs one round trip's worth of latency, not N). TheSET ... IFEQCAS is unchanged except that on a cluster it is routed to the primary owning the key's slot.2. Default TTL. Every write path went in without an expiration, including the cold-cache null sentinel that
getIdentifiablesbootstraps on every miss. Under memcache that is harmless — LRU evicts cold entries. Valkey withnoevictiondoes not: the keyspace grows untilmaxmemory, and then all writes to that server start failing withOOM, including writes from anything else sharing the cluster. Writes now carry a TTL (default 24h, overridable via a new constructor); an entity's ownexpirationSecondsstill wins where it declares one.Note that this changes the constructor signature (
GlideClient→BaseClient, and the lombok-generated constructor becomes explicit so the TTL can be defaulted).ValkeyCacheServicehasn't shipped in a release yet, andGlideClientis aBaseClient, so existing source keeps compiling.Testing.
ValkeyCacheServiceTestscovers the rewritten multi-key paths and adds coverage for the default TTL onput,putAll, the cold-cache sentinel, and CAS without an explicit expiration. All 25 tests undersrc/test/java/com/googlecode/objectify/test/valkeypass locally.The cluster routing itself is not covered by a test: testcontainers can't easily expose a real cluster's advertised node addresses to the host in a way that works on both Linux and Docker Desktop. It has been exercised against a live multi-node Valkey cluster in production. Happy to attempt a Linux-only cluster test if you'd want one.