Unverified Commit c33c91db authored by Moti Cohen's avatar Moti Cohen Committed by GitHub
Browse files

Support HSET+expire in one command, at infra level (#13230)

Unify infra of `HSETF`, `HEXPIRE`, `HSET` and provide API for RDB load
as well. Whereas setting plain fields is rather straightforward, setting
expiration time to fields might be time-consuming and complex since each 
update of expiration time, not only updates `ebuckets` of corresponding hash, 
but also might update `ebuckets` of global HFE DS. It is required to opt 
sequence of field updates with expirartion for a given hash, such that only once
done, the global HFE DS will get updated.

To do so, follow the scheme:
1. Call `hashTypeSetExInit()` to initialize the HashTypeSetEx struct.
2. Call `hashTypeSetEx()` one time or more, for each field/expiration update.
3. Call `hashTypeSetExDone()` for notification and update of global HFE.

If expiration is not required, then avoid this API and use instead hashTypeSet().
parent c18ff056
......@@ -1170,6 +1170,7 @@ static void ebValidateRax(rax *rax, EbucketsType *type) {
raxStart(&raxIter, rax);
raxSeek(&raxIter, "^", NULL, 0);
while (raxNext(&raxIter)) {
int expectFirstItemBucket = 1;
FirstSegHdr *firstSegHdr = raxIter.data;
eItem iter;
ExpireMeta *mIter, *mHead;
......@@ -1181,7 +1182,6 @@ static void ebValidateRax(rax *rax, EbucketsType *type) {
void *segHdr = firstSegHdr;
mIter = type->getExpireMeta(iter);
assert(mIter->firstItemBucket == 1);
while (1) {
uint64_t curBktKey, prevBktKey;
for (int i = 0; i < mHead->numItems ; ++i) {
......@@ -1191,6 +1191,8 @@ static void ebValidateRax(rax *rax, EbucketsType *type) {
if (i == 0) {
assert(mIter->numItems > 0 && mIter->numItems <= EB_SEG_MAX_ITEMS);
assert(mIter->firstItemBucket == expectFirstItemBucket);
expectFirstItemBucket = 0;
prevBktKey = curBktKey;
} else {
assert( (extendedSeg && prevBktKey == curBktKey) ||
......
......@@ -251,7 +251,10 @@ typedef struct ExpireInfo {
void *ctx; /* [INPUT ] context to pass to onExpireItem */
uint64_t now; /* [INPUT ] Current time in msec. */
uint64_t nextExpireTime; /* [OUTPUT] Next expiration time. Return 0, if none left. */
uint64_t itemsExpired; /* [OUTPUT] Returns the number of expired items. */
/* TODO: Distinct between expired & updated */
uint64_t itemsExpired; /* [OUTPUT] Returns the number of expired or updated items. */
} ExpireInfo;
/* ebuckets API */
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment