Skip to content

Commit 8dcbbed

Browse files
Merge branch 'valkey-io:unstable' into skolosov/replicate-no-one
2 parents dca695e + f1d8d77 commit 8dcbbed

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed

deps/hiredis/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)
1+
CMAKE_MINIMUM_REQUIRED(VERSION 3.10.0)
22

33
OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON)
44
OPTION(ENABLE_SSL "Build hiredis_ssl for SSL support" OFF)

src/acl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3094,8 +3094,8 @@ void aclCommand(client *c) {
30943094
" Show the ACL log entries.",
30953095
"SAVE",
30963096
" Save the current config to the ACL file.",
3097-
"SETUSER <username> <attribute> [<attribute> ...]",
3098-
" Create or modify a user with the specified attributes.",
3097+
"SETUSER <username> <rule> [<rule> ...]",
3098+
" Create or modify a user with the specified rules.",
30993099
"USERS",
31003100
" List all the registered usernames.",
31013101
"WHOAMI",

src/valkey-benchmark.c

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ static struct config {
100100
long long previous_tick;
101101
int keysize;
102102
int datasize;
103-
int randomkeys;
104-
int randomkeys_keyspacelen;
103+
int replacekeys;
104+
int keyspacelen;
105+
int sequential_replacement;
105106
int keepalive;
106107
int pipeline;
107108
long long start;
@@ -393,18 +394,23 @@ static void resetClient(client c) {
393394
c->pending = config.pipeline;
394395
}
395396

396-
static void randomizeClientKey(client c) {
397-
size_t i;
398-
399-
for (i = 0; i < c->randlen; i++) {
397+
static void generateClientKey(client c) {
398+
static _Atomic size_t seq_key = 0;
399+
for (size_t i = 0; i < c->randlen; i++) {
400400
char *p = c->randptr[i] + 11;
401-
size_t r = 0;
402-
if (config.randomkeys_keyspacelen != 0) r = random() % config.randomkeys_keyspacelen;
403-
size_t j;
401+
size_t key = 0;
402+
if (config.keyspacelen != 0) {
403+
if (config.sequential_replacement) {
404+
key = atomic_fetch_add_explicit(&seq_key, 1, memory_order_relaxed);
405+
} else {
406+
key = random();
407+
}
408+
key %= config.keyspacelen;
409+
}
404410

405-
for (j = 0; j < 12; j++) {
406-
*p = '0' + r % 10;
407-
r /= 10;
411+
for (size_t j = 0; j < 12; j++) {
412+
*p = '0' + key % 10;
413+
key /= 10;
408414
p--;
409415
}
410416
}
@@ -577,8 +583,8 @@ static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
577583
return;
578584
}
579585

580-
/* Really initialize: randomize keys and set start time. */
581-
if (config.randomkeys) randomizeClientKey(c);
586+
/* Really initialize: replace keys and set start time. */
587+
if (config.replacekeys) generateClientKey(c);
582588
if (config.cluster_mode && c->staglen > 0) setClusterKeyHashTag(c);
583589
c->slots_last_update = atomic_load_explicit(&config.slots_last_update, memory_order_relaxed);
584590
c->start = ustime();
@@ -749,8 +755,8 @@ static client createClient(char *cmd, size_t len, client from, int thread_id) {
749755
c->stagptr = NULL;
750756
c->staglen = 0;
751757

752-
/* Find substrings in the output buffer that need to be randomized. */
753-
if (config.randomkeys) {
758+
/* Find substrings in the output buffer that need to be replaced. */
759+
if (config.replacekeys) {
754760
if (from) {
755761
c->randlen = from->randlen;
756762
c->randfree = 0;
@@ -1366,9 +1372,11 @@ int parseOptions(int argc, char **argv) {
13661372
p++;
13671373
if (*p < '0' || *p > '9') goto invalid;
13681374
}
1369-
config.randomkeys = 1;
1370-
config.randomkeys_keyspacelen = atoi(next);
1371-
if (config.randomkeys_keyspacelen < 0) config.randomkeys_keyspacelen = 0;
1375+
config.replacekeys = 1;
1376+
config.keyspacelen = atoi(next);
1377+
if (config.keyspacelen < 0) config.keyspacelen = 0;
1378+
} else if (!strcmp(argv[i], "--sequential")) {
1379+
config.sequential_replacement = 1;
13721380
} else if (!strcmp(argv[i], "-q")) {
13731381
config.quiet = 1;
13741382
} else if (!strcmp(argv[i], "--csv")) {
@@ -1541,14 +1549,16 @@ int parseOptions(int argc, char **argv) {
15411549
" -k <boolean> 1=keep alive 0=reconnect (default 1)\n"
15421550
" -r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD,\n"
15431551
" random members and scores for ZADD.\n"
1544-
" Using this option the benchmark will expand the string\n"
1545-
" __rand_int__ inside an argument with a 12 digits number in\n"
1546-
" the specified range from 0 to keyspacelen-1. The\n"
1552+
" Using this option the benchmark will replace the string\n"
1553+
" __rand_int__ inside an argument with a random 12 digit\n"
1554+
" number in the specified range from 0 to keyspacelen-1. The\n"
15471555
" substitution changes every time a command is executed.\n"
15481556
" Default tests use this to hit random keys in the specified\n"
15491557
" range.\n"
15501558
" Note: If -r is omitted, all commands in a benchmark will\n"
15511559
" use the same key.\n"
1560+
" --sequential Modifies the -r argument to replace the string __rand_int__\n"
1561+
" with 12 digit numbers sequentially instead of randomly.\n"
15521562
" -P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline).\n"
15531563
" -q Quiet. Just show query/sec values\n"
15541564
" --precision Number of decimal places to display in latency output (default 0)\n"
@@ -1703,8 +1713,9 @@ int main(int argc, char **argv) {
17031713
config.keepalive = 1;
17041714
config.datasize = 3;
17051715
config.pipeline = 1;
1706-
config.randomkeys = 0;
1707-
config.randomkeys_keyspacelen = 0;
1716+
config.replacekeys = 0;
1717+
config.keyspacelen = 0;
1718+
config.sequential_replacement = 0;
17081719
config.quiet = 0;
17091720
config.csv = 0;
17101721
config.loop = 0;
@@ -1948,7 +1959,7 @@ int main(int argc, char **argv) {
19481959

19491960
if (test_is_selected("zadd")) {
19501961
char *score = "0";
1951-
if (config.randomkeys) score = "__rand_int__";
1962+
if (config.replacekeys) score = "__rand_int__";
19521963
len = redisFormatCommand(&cmd, "ZADD myzset%s %s element:__rand_int__", tag, score);
19531964
benchmark("ZADD", cmd, len);
19541965
free(cmd);

0 commit comments

Comments
 (0)