Repository navigation
[Redis 8.10] Add HIMPORT (Hinted Hash Templates) support - #4667
Conversation
Test Results 206 files ± 0 206 suites ±0 8m 12s ⏱️ +53s Results for commit e41fdb4. ± Comparison against base commit f2fe13e. This pull request removes 2 and adds 38 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b8ae031ac2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c317db290b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
ggivo
left a comment
There was a problem hiding this comment.
Adding a few more findings
I think most review bot finding are also legitimate and need to be addressed
A long-lived template kept strong references to every connection it was prepared on, retaining connections the pool had already destroyed. Record them in ConnectionRegistry instead: a weak-reference registry (same class as the maintenance-events branch, PR #4668) that prunes collected connections, so close() visits only live ones. close() is now idempotent, and registerConnection re-checks discarded afterwards so a close() racing first use cannot leave the fieldset undiscarded.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 14725896d1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
On an ASK redirect the executor sent ASKING out-of-band before the command; a command-intrinsic hook such as HIMPORT's lazy PREPARE then consumed the one-shot ASKING state, redirecting the command again until attempts were exhausted. CommandObject is now immutable and carries an ordered list of pre-process hooks; withPreProcessHook() returns a modified copy. ClusterCommandExecutor appends the ASKING hook to a copy of the redirected command, so the wire order is PREPARE, ASKING, SET and ASKING applies to the command itself. Covered by CommandObjectTest and testAskResponseWithHimportSet (himportSet on a migrating slot), verified against a live cluster.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9b5ccdde23
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Discard reconciliation ran only in ConnectionFactory.activateObject, so legacy JedisPool/JedisSentinelPool and direct unpooled connections never issued queued HIMPORT DISCARDs, accumulating server-side fieldsets. A discard failure was also swallowed there after marking the connection broken, handing a dead connection to the borrower. Move reconciliation to the Connection.executeCommand entry points: one choke point covers every path, gated by a single volatile read. Pending discards go out as one packed write with replies drained in one pass; error replies are ignored while connection failures propagate to the retry machinery. activateObject is a no-op again.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7594f06. Configure here.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7594f066ac
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
The HIMPORT PREPARE injected before a first-use himportSet was buffered like a user command, so syncAndReturnAll() returned an extra OK and shifted the positions callers rely on. Pipeline responses are now QueuedResponse entries flagged internal or user at creation; internal commands are buffered via appendInternalCommand and their replies, while still read in wire order, are filtered from syncAndReturnAll(). sync() is unchanged.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 974e218f35
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
setBroken() cleared the connection's HIMPORT state, but it may be called by threads that do not own the connection (forceDisconnect, maintenance paths), racing the owner's unsynchronized prepared set. The clear was also unnecessary: broken connections are dropped on every pooled and executor path, never reused. Remove the reset from setBroken(); connect() alone resets the state (renamed HimportConnectionState.reset()), which only the owner thread runs. Drop the legacy integration tag from HashImportReconcileIT - the IT suffix alone routes it to failsafe.
Empty field names slipped past validation despite the documented contract, deferring the failure to HIMPORT PREPARE on the server. Reject "" and zero-length byte[] in the shared build step. Replace HashImportReconcileIT (legacy-client, introspection-based) with HimportLifecycleMockTest: a TcpMockServer command log pins the wire contract - PREPARE once per connection ahead of the first SET, queued DISCARDs of closed templates drained right before the next command, batched. Reconciliation runs at the shared Connection.executeCommand choke point, so provisioning-path variants added no logic coverage.
RESET drops connection-scoped fieldsets server-side, but the client kept its prepared note, so later himportSet calls skipped PREPARE and failed until reconnect. Jedis.reset() now resets the connection's HIMPORT state; clearing in finally is harmless on failure (at worst one extra re-PREPARE). Raw sendCommand(RESET) is intentionally out of scope.
New public API needs release provenance in the generated docs; also complete the truncated javadoc sentence.
Every himportSet call eagerly built the PREPARE command object - fieldset name plus all field tokens - just to capture it in the pre-process hook, then discarded it whenever the connection was already prepared, the common case in bulk-import loops. Assemble the PREPARE arguments inside prepareBeforeUse instead, on the not-prepared branch only; the steady-state path allocates nothing PREPARE-related. Wire order covered by HimportLifecycleMockTest.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8237e27775
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| himportSendPendingDiscards(); | ||
| sendCommand(args); | ||
| return getOne(); |
There was a problem hiding this comment.
Clear HIMPORT state on low-level RESET
When the same physical connection is reset through the public low-level path, e.g. connection.executeCommand(Protocol.Command.RESET) before returning to a Jedis wrapper, Redis drops the connection-local HIMPORT fieldsets but this method leaves himportState marked as prepared. Fresh evidence is that this patch only clears the state in Jedis.reset(), so the next managed himportSet on that connection skips PREPARE and fails as an unprepared fieldset; clear the HIMPORT state when these Connection command paths issue RESET as well.
Useful? React with 👍 / 👎.
Expand the himportSet javadoc on all four command interfaces with the verified contract: existing hashes are replaced, wrong value count and closed templates fail eagerly, transactions and cluster pipelines are unsupported, PREPARE is injected per pooled connection. Add docs/hash-import.md under User Guide covering usage, pipelining, cluster behavior and limitations, with a compiled example (HashImportUsage) mirroring the doc snippets, verified against a live Redis 8.10.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e41fdb472e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Adds client support for the Redis 8.10
HIMPORTcommand family (Hinted Hash Templates). When many hashes share the same field names, a client names the field set once and then creates keys sending only their values, cutting client→server traffic and letting the server store the keys template-encoded. The keys produced are ordinary hashes.The public surface is a single managed command,
himportSet, plus aHashImporttemplate:A fieldset is per-physical-connection server state, so
PREPARE/DISCARDare managed transparently rather than exposed: eachhimportSetlazily prepares the template on whichever connection runs it, and cleanup happens when connections are next borrowed.Design
himportSetlives on the existing hash interfaces (HashCommands,HashBinaryCommands, and theirHashPipeline*variants), not a separate interface — it is an ordinary hash command from the caller's point of view. Implemented onUnifiedJedis, legacyJedis, and standalonePipeline.CommandExecutor. ThehimportSetCommandObjectcarries apreProcessHook(Consumer<Connection>) thatConnection.executeCommandruns immediately before sending the command. The hook injects a lazyPREPAREon the chosen connection when the fieldset is not yet prepared there. Because the command still travels the executor path, clusterMOVED/ASKredirection, retry, and failover all re-run the hook on whatever connection the executor lands on. The command is never routed around the executor.Connectionkeeps a note of the fieldsets prepared on it (name → weak reference to theHashImport), reset whenever the socket is (re)connected or broken.HashImport.close()just marks the template discarded, before next command execution on a connection discards any fieldset on that connection whose template was closed or garbage-collected, and drops it from the note.himportSetroutes by the key's slot and self-prepares on that node; each node pool reconciles independently.Behavior
himportSetvalidates the value count against the template's field count and rejects a discarded template, both client-side.JedisrejectshimportSetinsideMULTI/pipeline via the existingcheckIsInMultiOrPipeline()guard.Pipeline, which buffersPREPAREahead of theSET. A transaction (MULTI) and a cluster pipeline throwUnsupportedOperationException— a keylessPREPAREcannot be routed by slot, and injecting it into a transaction would desyncEXEC.@Experimental(@since 8.0); HIMPORT ships only in Redis 8.10+.Testing
All against a live Redis 8.10 RC environment, gated with
@EnabledOnCommand("HIMPORT"):HashImportTest— template validation (empty/null/duplicate fields, defensivebyte[]copy,close()), unit.HashesCommandsTestBase(standalone + cluster runners), legacyHashesCommandsTest, andHashesPipelineCommandsTest.HashImportReconciliationIT— white-box tests for the per-connection mechanism: borrow-time discard of a closed fieldset, discard of a garbage-collected one, and note reset + lazy re-prepare after a broken connection.Notes
himportPrepare/himportDiscard/himportDiscardAll; the lifecycle is internal.Note
Medium Risk
Touches core command execution (
Connection,CommandObject, cluster redirection) and connection-local protocol state; behavior is well-tested but mistakes could affect non-HIMPORT paths (hooks, ASK ordering).Overview
Adds experimental client support for Redis 8.10 HIMPORT (Hinted Hash Templates): a reusable
HashImportfield-set template andhimportSeton the existing hash command surfaces (HashCommands, pipelines,UnifiedJedis/Jedis).The client hides connection-local PREPARE / DISCARD lifecycle.
himportSettravels the normal executor path with aCommandObjectpre-process hook that lazily sendsHIMPORT PREPAREon the connection that will run theSET. Per-connectionHimportConnectionStatetracks prepared fieldsets; closing a template queues discards that are flushed before the next command on each touched connection. Single-connectionPipelinebuffers internalPREPAREreplies sosyncAndReturnAll()only returns user commands; MULTI and cluster pipelines rejecthimportSet.Cluster ASK retries now append
ASKINGas a pre-process hook (after any HIMPORTPREPARE) so one-shot ASKING is not consumed early.RESETand reconnect clear client HIMPORT state.Adds
docs/hash-import.md, protocolHIMPORTkeywords, and unit/integration/mock tests.Reviewed by Cursor Bugbot for commit e41fdb4. Bugbot is set up for automated code reviews on this repo. Configure here.