Skip to content

HFE to support AOF and replicas#13285

Merged
sundb merged 18 commits intoredis:hash-field-expiry-integfrom
moticless:hfe-integ-aof-and-replica
May 29, 2024
Merged

HFE to support AOF and replicas#13285
sundb merged 18 commits intoredis:hash-field-expiry-integfrom
moticless:hfe-integ-aof-and-replica

Conversation

@moticless
Copy link
Copy Markdown
Collaborator

@moticless moticless commented May 21, 2024

  • For replica sake, rewrite commands H*EXPIRE* , HSETF, HGETF to have absolute unix time in msec.
  • On active-expiration of field, propagate HDEL to replica (propagateHashFieldDeletion())
  • On lazy-expiration, propagate HDEL to replica (hashTypeGetValue() now calls hashTypeDelete(). It also takes care to call propagateHashFieldDeletion()).
  • Fix H*EXPIRE* command such that if it gets flag LT and it doesn’t have any expiration on the field then it will considered as valid condition.

Note, replicas doesn’t make any active expiration, and should avoid lazy expiration. On hashTypeGetValue() it doesn't check expiration (As long as the master didn’t request to delete the field, it is valid)

TODO:

  • Attach dbid to HASH metadata. See here

@moticless moticless requested review from oranagra, sundb and tezc May 21, 2024 12:13
Comment thread src/aof.c Outdated
Comment thread src/server.h Outdated
Comment thread src/t_hash.c Outdated
Comment thread src/t_hash.c
@sundb
Copy link
Copy Markdown
Collaborator

sundb commented May 23, 2024

Comment thread src/t_hash.c Outdated
Comment thread tests/unit/type/hash-field-expire.tcl Outdated
Comment thread src/t_hash.c
Comment thread src/t_hash.c
Comment thread tests/support/util.tcl
Comment thread src/t_hash.c Outdated
Comment thread src/t_hash.c
Comment thread src/t_hash.c Outdated
@moticless
Copy link
Copy Markdown
Collaborator Author

Comment thread src/module.c Outdated
Comment thread src/module.c Outdated
Comment thread src/t_hash.c Outdated
Comment thread src/t_hash.c Outdated
Comment thread src/aof.c Outdated
Comment thread tests/unit/type/hash-field-expire.tcl Outdated
Comment thread src/t_hash.c
Comment thread src/aof.c Outdated
Comment thread src/t_hash.c Outdated
Comment thread src/rdb.c Outdated
Comment thread src/rdb.c Outdated
Comment thread src/rdb.c
Comment thread src/rdb.c Outdated
Comment thread src/rdb.c
Comment thread src/aof.c Outdated
Comment thread src/t_hash.c
/* Delete all the expired fields in one go */
if (r.expired > 0)
lpt->lp = lpDeleteRange(lpt->lp, 0, r.expired * 3);
ptr = lpNext(lpt->lp, ptr);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just a note to all of us, maybe we can implement this logic with lpFindCb() in future to avoid performance cost of lpNext() calls.

Comment thread src/module.c
Comment on lines +5274 to +5277
int isHashDeleted;
int exists = hashTypeExists(key->db, key->value, field->ptr, &isHashDeleted);
/* hash-field-expiration is not exposed to modules */
serverAssert(isHashDeleted == 0);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if i use hexpire command to create a hash with TTL fields, then operate the hash with RM_HashSet, will thia assertion be triggered?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Regarding this matter, I am seeking input from those experienced with modules:

  • We likely need to pass the mode/flags of the opened key and respond appropriately.
  • Should we update the opened key if the key was deleted due to last field expiration?

@MeirShpilraien, perhaps you can assist. Thanks.

Comment thread src/t_hash.c
Comment thread src/t_hash.c Outdated
Comment thread src/t_hash.c
Comment thread src/t_hash.c
Comment thread src/t_hash.c
Comment thread src/t_hash.c Outdated
Comment thread src/t_hash.c Outdated
Comment thread src/t_hash.c
Comment thread src/t_hash.c
shared.hdel,
createStringObject((char*) key, sdslen(key)),
createStringObject(field, fieldLen)
};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Note: Later, maybe we can add a check to avoid creating these objects if we are not going to propagate anything.

Comment thread tests/integration/psync2-master-restart.tcl Outdated
@sundb sundb merged commit 33fc0fb into redis:hash-field-expiry-integ May 29, 2024
funny-dog pushed a commit to funny-dog/redis that referenced this pull request Sep 17, 2025
* For replica sake, rewrite commands `H*EXPIRE*` , `HSETF`, `HGETF` to
have absolute unix time in msec.
* On active-expiration of field, propagate HDEL to replica
(`propagateHashFieldDeletion()`)
* On lazy-expiration, propagate HDEL to replica (`hashTypeGetValue()`
now calls `hashTypeDelete()`. It also takes care to call
`propagateHashFieldDeletion()`).
* Fix `H*EXPIRE*` command such that if it gets flag `LT` and it doesn’t
have any expiration on the field then it will considered as valid
condition.

Note, replicas doesn’t make any active expiration, and should avoid lazy
expiration. On `hashTypeGetValue()` it doesn't check expiration (As long
as the master didn’t request to delete the field, it is valid)

TODO: 
* Attach `dbid` to HASH metadata. See
[here](redis#13209 (comment))

---------

Co-authored-by: debing.sun <[email protected]>
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