Skip to content

Commit e70cd46

Browse files
addressing comments
Signed-off-by: Sarthak Aggarwal <[email protected]>
1 parent b2ae641 commit e70cd46

File tree

5 files changed

+9
-54
lines changed

5 files changed

+9
-54
lines changed

src/hashtable.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ uint64_t siphash_nocase(const uint8_t *in, const size_t inlen, const uint8_t *k)
7272
/* --- Global variables --- */
7373

7474
static uint8_t hash_function_seed[16];
75-
static uint8_t db_hash_function_seed[16];
7675
static hashtableResizePolicy resize_policy = HASHTABLE_RESIZE_ALLOW;
7776

7877
/* --- Fill factor --- */
@@ -113,14 +112,6 @@ uint64_t hashtableGenCaseHashFunction(const char *buf, size_t len) {
113112
return siphash_nocase((const uint8_t *)buf, len, hash_function_seed);
114113
}
115114

116-
void dbHashtableSetHashFunctionSeed(uint8_t *seed) {
117-
memcpy(db_hash_function_seed, seed, sizeof(db_hash_function_seed));
118-
}
119-
120-
uint64_t dbHashtableGenHashFunction(const void *key, size_t len) {
121-
return siphash(key, len, db_hash_function_seed);
122-
}
123-
124115
/* --- Global resize policy API --- */
125116

126117
/* The global resize policy is one of

src/hashtable.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ void hashtableSetHashFunctionSeed(const uint8_t *seed);
110110
uint8_t *hashtableGetHashFunctionSeed(void);
111111
uint64_t hashtableGenHashFunction(const char *buf, size_t len);
112112
uint64_t hashtableGenCaseHashFunction(const char *buf, size_t len);
113-
void dbHashtableSetHashFunctionSeed(uint8_t *seed);
114-
uint64_t dbHashtableGenHashFunction(const void *key, size_t len);
115113

116114
/* Global resize policy */
117115
void hashtableSetResizePolicy(hashtableResizePolicy policy);

src/server.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ hashtableType zsetHashtableType = {
573573
};
574574

575575
uint64_t hashtableSdsHash(const void *key) {
576-
return dbHashtableGenHashFunction((const char *)key, sdslen((char *)key));
576+
return hashtableGenHashFunction((const char *)key, sdslen((char *)key));
577577
}
578578

579579
const void *hashtableObjectGetKey(const void *entry) {
@@ -7136,7 +7136,6 @@ __attribute__((weak)) int main(int argc, char **argv) {
71367136
getRandomBytes(hashseed, sizeof(hashseed));
71377137
dictSetHashFunctionSeed(hashseed);
71387138
hashtableSetHashFunctionSeed(hashseed);
7139-
dbHashtableSetHashFunctionSeed(hashseed);
71407139

71417140
char *exec_name = strrchr(argv[0], '/');
71427141
if (exec_name == NULL) exec_name = argv[0];
@@ -7295,7 +7294,7 @@ __attribute__((weak)) int main(int argc, char **argv) {
72957294
if (server.db_hash_seed != NULL) {
72967295
memset(hashseed, 0, sizeof(hashseed));
72977296
getHashSeedFromValue(hashseed, sizeof(hashseed), server.db_hash_seed);
7298-
dbHashtableSetHashFunctionSeed(hashseed);
7297+
hashtableSetHashFunctionSeed(hashseed);
72997298
}
73007299

73017300
/* Do system checks */

src/server.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2213,7 +2213,7 @@ struct valkeyServer {
22132213
* dropping packets of a specific type */
22142214
unsigned long cluster_blacklist_ttl; /* Duration in seconds that a node is denied re-entry into
22152215
* the cluster after it is forgotten with CLUSTER FORGET. */
2216-
char *db_hash_seed; /* Configurable DB hash seed */
2216+
sds db_hash_seed; /* Configurable DB hash seed */
22172217
int cluster_slot_stats_enabled; /* Cluster slot usage statistics tracking enabled. */
22182218
mstime_t cluster_mf_timeout; /* Milliseconds to do a manual failover. */
22192219
unsigned long cluster_slot_migration_log_max_len; /* Maximum count of migrations to display in the
Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
11
start_server {tags {"scan-consistency-on-failover external:skip"}} {
2-
proc full_scan_keys {c prefix} {
3-
set cur 0
4-
set out {}
5-
while {1} {
6-
# count 1 to make the ordering fully observable
7-
set res [$c scan $cur count 1]
8-
set cur [lindex $res 0]
9-
set keys [lindex $res 1]
10-
foreach k $keys {
11-
if {[string match "${prefix}*" $k]} {
12-
lappend out $k
13-
}
14-
}
15-
if {$cur eq "0"} break
16-
}
17-
return $out
18-
}
192

203
set fixed_seed "00112233445566778899aabbccddeeff"
214
set shared_overrides [list appendonly no save "" db-hash-seed $fixed_seed activedefrag no hz 1]
@@ -25,9 +8,6 @@ start_server {tags {"scan-consistency-on-failover external:skip"}} {
258
set primary_port [srv 0 port]
269

2710
start_server [list overrides $shared_overrides] {
28-
set replica_host [srv 0 host]
29-
set replica_port [srv 0 port]
30-
3111
set primary [srv -1 client]
3212
set replica [srv 0 client]
3313

@@ -46,26 +26,13 @@ start_server {tags {"scan-consistency-on-failover external:skip"}} {
4626
fail "replica did not catch up dbsize (primary=[$primary dbsize], replica=[$replica dbsize])"
4727
}
4828

49-
wait_for_condition 200 50 {
50-
![string match {Hash table 1 stats*} [$primary debug htstats 9]] &&
51-
![string match {Hash table 1 stats*} [$replica debug htstats 9]] &&
52-
[dict get [$primary memory stats] db.dict.rehashing.count] == 0 &&
53-
[dict get [$replica memory stats] db.dict.rehashing.count] == 0
54-
} else {
55-
fail "hash tables still rehashing on primary/replica"
29+
set cursor {{0} {}}
30+
while {1} {
31+
set cursor_next [$primary scan [lindex $cursor 0]]
32+
assert_equal $cursor_next [$replica scan [lindex $cursor 0]]
33+
if {[lindex $cursor_next 0] eq "0"} break
34+
set cursor $cursor_next
5635
}
57-
58-
set pseed [$primary config get db-hash-seed]
59-
set rseed [$replica config get db-hash-seed]
60-
assert_equal $pseed $rseed
61-
62-
set pkeys [full_scan_keys $primary "k:"]
63-
set rkeys [full_scan_keys $replica "k:"]
64-
65-
assert_equal [$primary dbsize] [llength $pkeys]
66-
assert_equal [$replica dbsize] [llength $rkeys]
67-
assert_equal [llength $pkeys] [llength $rkeys]
68-
assert_equal $pkeys $rkeys
6936
}
7037
}
7138
}

0 commit comments

Comments
 (0)