redis dictFind when rehash

30 views
Skip to first unread message

erpeng zhang

unread,
Dec 12, 2018, 3:41:48 AM12/12/18
to Redis DB
when find a key ,if redis is rehashing, now we should lookup both tables (ht[0] and ht[1]).
why don't we use the key's index comparing to the rehashidx,if index < rehashidx,then we don't need to lookup ht[0].

blow is the code :
for (table = 0; table <= 1; table++) {
idx = h & d->ht[table].sizemask;
he = d->ht[table].table[idx];
while(he) {
if (key==he->key || dictCompareKeys(d, key, he->key))
return he;
he = he->next;
}
if (!dictIsRehashing(d)) return NULL;
}

we can change it :
for (table = 0; table <= 1; table++) {
idx = h & d->ht[table].sizemask;
if (idx < d->rehashidx) continue;
he = d->ht[table].table[idx];
while(he) {
if (key==he->key || dictCompareKeys(d, key, he->key))
return he;
he = he->next;
}
if (!dictIsRehashing(d)) return NULL;
}

if idx < d->rehashidx,we can conclude:
1.it is rehashing(rehashidx is -1 if it is not rehashing)
2.we can't find key in ht[0]

so continue

Itamar Haber

unread,
Dec 12, 2018, 7:08:02 AM12/12/18
to redi...@googlegroups.com
Hello Erpeng

This may be an interesting optimization - I suggest that you resubmit it for discussion as a pull request at https://github.com/antirez/redis/pulls for the developers.

Cheers,

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.


--

Itamar Haber
Technicalist Evangely

Phone: +972.54.567.9692

Redis Labs

erpeng zhang

unread,
Dec 12, 2018, 8:17:29 PM12/12/18
to redi...@googlegroups.com
Ok. Thank you for reply

erpeng zhang

unread,
Feb 20, 2019, 5:44:52 AM2/20/19
to Redis DB
Hi,Itamar!

I have commited a pull request:


welcome a review

在 2018年12月12日星期三 UTC+8下午8:08:02,Itamar Haber写道:
Reply all
Reply to author
Forward
0 new messages