Stop template hashes from growing past the configured field count - #15873
Hashim1999164 wants to merge 2 commits into
Conversation
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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
Reviewed by Cursor Bugbot for commit 7278022. Configure here.
|
I have read the CLA Document and I hereby sign the CLA |
|
recheck |
756647c to
6b04d5b
Compare
9ee4f02 to
1cdd22e
Compare
|
recheck |
|
This change touches performance-sensitive code paths. Adding the |
|
@fcostaoliveira yeah makes sense. i dont have rights to slap that label on though, mind adding |
|
@fcostaoliveira any update on this? still need that |
|
@fcostaoliveira gentle ping on the |

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-entrieswhen 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 withHASH_SET_NO_TEMPLATE_CONVERTso it stays plain.Also hoists
total_field_countso the same total drives both the new template-entry cap and the existing listpack-entry conversion check.Tests assert that incremental
HSETand a single multi-fieldHSETboth 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.