Skip to content

Conversation

@moticless
Copy link
Collaborator

@moticless moticless commented Jun 5, 2024

Need to be carefull if called by modules since modules API allow to open and close key handler. We don't want to invalidate the handler underneath.

  • hashTypeExists(), hashTypeGetValueObject() - will return the logical state of the field. A flag will indicate noExpire.
  • RM_HashGet() - Will get NULL if the field expired. Fields won’t be deleted.
  • RM_ScanKey() - might return 0 items if all fields got expired. Fields won’t be deleted.
  • RM_HashSet() - If set, then override expired field. If delete, we can either delete or leave it to active-expiration. XX/NX - logically correct (Verify with tests).

Nice to have (not implemented):

  • RedisModule_CloseKey() - We can local active-expire up-to 100 items.

Note:
Length will be wrong to modules just like redis (Count expired fields).

@moticless moticless requested a review from MeirShpilraien June 5, 2024 15:23
tezc
tezc previously approved these changes Jun 6, 2024
sundb
sundb previously approved these changes Jun 6, 2024
@moticless moticless dismissed stale reviews from sundb and tezc via 505d8a6 June 10, 2024 06:24
@moticless moticless changed the title HFE - Avoid lazy expire if called by modules HFE - Avoid lazy expire if called by modules + cleanup Jun 10, 2024
@moticless moticless merged commit ce121b9 into redis:unstable Jun 10, 2024
@moticless moticless deleted the hfe-fix-modules-lazy-expire branch June 10, 2024 08:24
@YaacovHazan YaacovHazan mentioned this pull request Jun 27, 2024
YaacovHazan added a commit that referenced this pull request Jun 27, 2024
Upgrade urgency LOW: This is the second Release Candidate for Redis 7.4.

Performance and resource utilization improvements
=================================================
* #13296 Optimize CPU cache efficiency

Changes to new 7.4 new features (compared to 7.4 RC1)
=====================================================
* #13343 Hash - expiration of individual fields: when key does not exist
- reply with an array (nonexisting code for each field)
* #13329 Hash - expiration of individual fields: new keyspace event:
`hexpired`

Modules API - Potentially breaking changes to new 7.4 features (compared
to 7.4 RC1)

====================================================================================
* #13326 Hash - expiration of individual fields: avoid lazy expire when
called from a Modules API function
* field and the command was sent with XX flag, the operation could
* fail and leave the hash empty, which the caller might not expect.
* To prevent unexpected behavior, we avoid lazy deletion in this case
* yet let the operation fail. Note that moduleDelKeyIfEmpty()
Copy link
Collaborator

Choose a reason for hiding this comment

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

it seems that using direct key API can potentially delete the key (e.g. RM_ZsetRem) so why do we have a problem with RM_HashGet/Set deleting the key?

Comment on lines +5285 to +5286
if (flags & REDISMODULE_HASH_XX)
hfeFlags |= HFE_LAZY_AVOID_FIELD_DEL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why even bother deleting the field when using NX? anyway, if it's logically expired we are going to override it with hashTypeSet below

if (flags & REDISMODULE_HASH_XX)
hfeFlags |= HFE_LAZY_AVOID_FIELD_DEL;

int exists = hashTypeExists(key->db, key->value, field->ptr, hfeFlags, NULL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

please note that hashTypeExists/hashTypeGetValue should be called with HFE_LAZY_NO_NOTIFICATION because direct key API doesn't emit notifications (by design)

funny-dog pushed a commit to funny-dog/redis that referenced this pull request Sep 17, 2025
Need to be carefull if called by modules since modules API allow to open
and close key handler. We don't want to invalidate the handler
underneath.

* hashTypeExists(), hashTypeGetValueObject() - will return the logical
state of the field. A flag will indicate noExpire.
* RM_HashGet() - Will get NULL if the field expired. Fields won’t be
deleted.
* RM_ScanKey() - might return 0 items if all fields got expired. Fields
won’t be deleted.
* RM_HashSet() - If set, then override expired field. If delete, we can
either delete or leave it to active-expiration. XX/NX - logically
correct (Verify with tests).

Nice to have (not implemented):
* RedisModule_CloseKey() - We can local active-expire up-to 100 items. 

Note:
Length will be wrong to modules just like redis (Count expired fields).
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.

4 participants