Skip to content

Stop template hashes from growing past the configured field count - #15873

Open
Hashim1999164 wants to merge 2 commits into
redis:unstablefrom
Hashim1999164:fix/templateHashMaxFieldCount
Open

Hashim1999164 wants to merge 2 commits into
redis:unstablefrom
Hashim1999164:fix/templateHashMaxFieldCount

Conversation

@Hashim1999164

@Hashim1999164 Hashim1999164 commented Sep 25, 2026 •

Copy link
Copy Markdown

Fixes #15835

hashTypeTryConvertToTemplate already leaves a hash plain when it is created with more fields than the configured maximum. Adding fields to a hash that is already a template skipped that check, so a hash that started at or below the bound stayed in the shared template registry as it grew.

When the new field count is over the limit, convert the hash to a plain encoding and then apply the new fields. Existing values stay readable.

Tests cover growing one field at a time and widening in a single HSET, for both template encodings.

I ran the hash template unit tests. All tests passed.


Note

Medium Risk
Touches core hash template mutation and encoding conversion paths; wrong limits or conversion order could corrupt field layout or leave hashes incorrectly registered as templates.

Overview
Enforces hash-max-template-entries when fields are added to an already-templated hash, not only on initial creation. If the post-add field count would exceed the limit, the hash is converted off the shared template (to listpack, then HT if listpack limits fail) and the new fields are written with HASH_SET_NO_TEMPLATE_CONVERT so it stays plain.

Also hoists total_field_count so the same total drives both the new template-entry cap and the existing listpack-entry conversion check.

Tests assert that incremental HSET and a single multi-field HSET both drop to the plain encoding while preserving field count and values, for each template encoding under test.

Reviewed by Cursor Bugbot for commit 1cdd22e. Bugbot is set up for automated code reviews on this repo. Configure here.

hashTypeTryConvertToTemplate already refused a wide hash, but adding
fields to a hash that was already a template skipped that bound. Convert
to a plain encoding when the new field count is over the limit.
@CLAassistant

CLAassistant commented Sep 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 7278022. Configure here.

Comment thread src/t_hash.c
Comment thread src/t_hash.c
@Hashim1999164

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@Hashim1999164

Copy link
Copy Markdown
Author

recheck

@Hashim1999164
Hashim1999164 force-pushed the fix/templateHashMaxFieldCount branch from 756647c to 6b04d5b Compare September 26, 2026 00:10
@Hashim1999164
Hashim1999164 force-pushed the fix/templateHashMaxFieldCount branch 2 times, most recently from 9ee4f02 to 1cdd22e Compare September 26, 2026 00:11
@Hashim1999164

Copy link
Copy Markdown
Author

recheck

@fcostaoliveira

Copy link
Copy Markdown
Collaborator

This change touches performance-sensitive code paths. Adding the action:run-benchmark label will trigger the CE Performance suite so we can see the impact before merge.

@Hashim1999164

Copy link
Copy Markdown
Author

@fcostaoliveira yeah makes sense. i dont have rights to slap that label on though, mind adding action:run-benchmark for me?

@Hashim1999164

Copy link
Copy Markdown
Author

@fcostaoliveira any update on this? still need that action:run-benchmark label from someone with rights when you get a chance

@Hashim1999164

Copy link
Copy Markdown
Author

@fcostaoliveira gentle ping on the action:run-benchmark label when you have a sec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] hash-max-template-entries is not enforced when a template hash gains fields

3 participants