Skip to content

Commit 1d5ac99

Browse files
YaacovHazanyaacov Hazan
andauthored
add support for resp3 (#182)
Co-authored-by: yaacov Hazan <[email protected]> Co-authored-by: YaacovHazan <[email protected]>
1 parent 422252c commit 1d5ac99

File tree

7 files changed

+204
-80
lines changed

7 files changed

+204
-80
lines changed

cluster_client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ bool cluster_client::get_key_for_conn(unsigned int conn_id, int iter, unsigned l
342342
}
343343

344344
// in case connection is during cluster slots command, his slots mapping not relevant
345-
if (m_connections[other_conn_id]->get_cluster_slots_state() != slots_done)
345+
if (m_connections[other_conn_id]->get_cluster_slots_state() != setup_done)
346346
continue;
347347

348348
// store key for other connection, if queue is not full
@@ -429,7 +429,7 @@ void cluster_client::handle_moved(unsigned int conn_id, struct timeval timestamp
429429
}
430430

431431
// connection already issued 'cluster slots' command, wait for slots mapping to be updated
432-
if (m_connections[conn_id]->get_cluster_slots_state() != slots_done)
432+
if (m_connections[conn_id]->get_cluster_slots_state() != setup_done)
433433
return;
434434

435435
// queue may stored uncorrected mapping indexes, empty them

memtier_benchmark.cpp

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ void benchmark_log(int level, const char *fmt, ...)
7878
va_end(args);
7979
}
8080

81+
bool is_redis_protocol(enum PROTOCOL_TYPE type) {
82+
return (type == PROTOCOL_REDIS_DEFAULT || type == PROTOCOL_RESP2 || type == PROTOCOL_RESP3);
83+
}
84+
85+
static const char * get_protocol_name(enum PROTOCOL_TYPE type) {
86+
if (type == PROTOCOL_REDIS_DEFAULT) return "redis";
87+
else if (type == PROTOCOL_RESP2) return "resp2";
88+
else if (type == PROTOCOL_RESP3) return "resp3";
89+
else if (type == PROTOCOL_MEMCACHE_TEXT) return "memcache_text";
90+
else if (type == PROTOCOL_MEMCACHE_BINARY) return "memcache_binary";
91+
else return "none";
92+
}
8193

8294
static void config_print(FILE *file, struct benchmark_config *cfg)
8395
{
@@ -135,7 +147,7 @@ static void config_print(FILE *file, struct benchmark_config *cfg)
135147
cfg->server,
136148
cfg->port,
137149
cfg->unix_socket,
138-
cfg->protocol,
150+
get_protocol_name(cfg->protocol),
139151
#ifdef USE_TLS
140152
cfg->tls ? "yes" : "no",
141153
cfg->tls_cert,
@@ -191,7 +203,7 @@ static void config_print_to_json(json_handler * jsonhandler, struct benchmark_co
191203
jsonhandler->write_obj("server" ,"\"%s\"", cfg->server);
192204
jsonhandler->write_obj("port" ,"%u", cfg->port);
193205
jsonhandler->write_obj("unix socket" ,"\"%s\"", cfg->unix_socket);
194-
jsonhandler->write_obj("protocol" ,"\"%s\"", cfg->protocol);
206+
jsonhandler->write_obj("protocol" ,"\"%s\"", get_protocol_name(cfg->protocol));
195207
jsonhandler->write_obj("out_file" ,"\"%s\"", cfg->out_file);
196208
#ifdef USE_TLS
197209
jsonhandler->write_obj("tls" ,"\"%s\"", cfg->tls ? "true" : "false");
@@ -245,8 +257,6 @@ static void config_init_defaults(struct benchmark_config *cfg)
245257
cfg->server = "localhost";
246258
if (!cfg->port && !cfg->unix_socket)
247259
cfg->port = 6379;
248-
if (!cfg->protocol)
249-
cfg->protocol = "redis";
250260
if (!cfg->run_count)
251261
cfg->run_count = 1;
252262
if (!cfg->clients)
@@ -307,7 +317,7 @@ static bool verify_cluster_option(struct benchmark_config *cfg) {
307317
} else if (cfg->wait_ratio.is_defined()) {
308318
fprintf(stderr, "error: cluster mode dose not support wait-ratio option.\n");
309319
return false;
310-
} else if (cfg->protocol && strcmp(cfg->protocol, "redis")) {
320+
} else if (!is_redis_protocol(cfg->protocol)) {
311321
fprintf(stderr, "error: cluster mode supported only in redis protocol.\n");
312322
return false;
313323
} else if (cfg->unix_socket) {
@@ -492,13 +502,20 @@ static int config_parse_args(int argc, char *argv[], struct benchmark_config *cf
492502
}
493503
break;
494504
case 'P':
495-
if (strcmp(optarg, "memcache_text") &&
496-
strcmp(optarg, "memcache_binary") &&
497-
strcmp(optarg, "redis")) {
498-
fprintf(stderr, "error: supported protocols are 'memcache_text', 'memcache_binary' and 'redis'.\n");
499-
return -1;
505+
if (strcmp(optarg, "redis") == 0) {
506+
cfg->protocol = PROTOCOL_REDIS_DEFAULT;
507+
} else if (strcmp(optarg, "resp2") == 0) {
508+
cfg->protocol = PROTOCOL_RESP2;
509+
} else if (strcmp(optarg, "resp3") == 0) {
510+
cfg->protocol = PROTOCOL_RESP3;
511+
} else if (strcmp(optarg, "memcache_text") == 0) {
512+
cfg->protocol = PROTOCOL_MEMCACHE_TEXT;
513+
} else if (strcmp(optarg, "memcache_binary") == 0) {
514+
cfg->protocol = PROTOCOL_MEMCACHE_BINARY;
515+
} else {
516+
fprintf(stderr, "error: supported protocols are 'memcache_text', 'memcache_binary', 'redis', 'resp2' and resp3'.\n");
517+
return -1;
500518
}
501-
cfg->protocol = optarg;
502519
break;
503520
case 'o':
504521
cfg->out_file = optarg;
@@ -857,9 +874,9 @@ void usage() {
857874
" -s, --server=ADDR Server address (default: localhost)\n"
858875
" -p, --port=PORT Server port (default: 6379)\n"
859876
" -S, --unix-socket=SOCKET UNIX Domain socket name (default: none)\n"
860-
" -P, --protocol=PROTOCOL Protocol to use (default: redis). Other\n"
861-
" supported protocols are memcache_text,\n"
862-
" memcache_binary.\n"
877+
" -P, --protocol=PROTOCOL Protocol to use (default: redis).\n"
878+
" other supported protocols are resp2, resp3, memcache_text and memcache_binary.\n"
879+
" when using one of resp2 or resp3 the redis protocol version will be set via HELLO command.\n"
863880
" -a, --authenticate=CREDENTIALS Authenticate using specified credentials.\n"
864881
" A simple password is used for memcache_text\n"
865882
" and Redis <= 5.x. <USER>:<PASSWORD> can be\n"
@@ -1410,12 +1427,11 @@ int main(int argc, char *argv[])
14101427
}
14111428

14121429
if (cfg.authenticate) {
1413-
if (strcmp(cfg.protocol, "redis") != 0 &&
1414-
strcmp(cfg.protocol, "memcache_binary") != 0) {
1430+
if (cfg.protocol == PROTOCOL_MEMCACHE_TEXT) {
14151431
fprintf(stderr, "error: authenticate can only be used with redis or memcache_binary.\n");
14161432
usage();
14171433
}
1418-
if (strcmp(cfg.protocol, "memcache_binary") == 0 &&
1434+
if (cfg.protocol == PROTOCOL_MEMCACHE_BINARY &&
14191435
strchr(cfg.authenticate, ':') == NULL) {
14201436
fprintf(stderr, "error: binary_memcache credentials must be in the form of USER:PASSWORD.\n");
14211437
usage();
@@ -1425,7 +1441,7 @@ int main(int argc, char *argv[])
14251441
obj_gen->set_random_data(cfg.random_data);
14261442
}
14271443

1428-
if (cfg.select_db > 0 && strcmp(cfg.protocol, "redis")) {
1444+
if (cfg.select_db > 0 && !is_redis_protocol(cfg.protocol)) {
14291445
fprintf(stderr, "error: select-db can only be used with redis protocol.\n");
14301446
usage();
14311447
}
@@ -1434,7 +1450,7 @@ int main(int argc, char *argv[])
14341450
fprintf(stderr, "error: data-offset too long\n");
14351451
usage();
14361452
}
1437-
if (cfg.expiry_range.min || cfg.expiry_range.max || strcmp(cfg.protocol, "redis")) {
1453+
if (cfg.expiry_range.min || cfg.expiry_range.max || !is_redis_protocol(cfg.protocol)) {
14381454
fprintf(stderr, "error: data-offset can only be used with redis protocol, and cannot be used with expiry\n");
14391455
usage();
14401456
}

memtier_benchmark.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,20 @@ enum key_pattern_index {
4141
key_pattern_get = 2
4242
};
4343

44+
enum PROTOCOL_TYPE {
45+
PROTOCOL_REDIS_DEFAULT,
46+
PROTOCOL_RESP2,
47+
PROTOCOL_RESP3,
48+
PROTOCOL_MEMCACHE_TEXT,
49+
PROTOCOL_MEMCACHE_BINARY,
50+
};
51+
4452
struct benchmark_config {
4553
const char *server;
4654
unsigned short port;
4755
struct server_addr *server_addr;
4856
const char *unix_socket;
49-
const char *protocol;
57+
enum PROTOCOL_TYPE protocol;
5058
const char *out_file;
5159
const char *client_stats;
5260
unsigned int run_count;
@@ -109,5 +117,6 @@ struct benchmark_config {
109117

110118
extern void benchmark_log_file_line(int level, const char *filename, unsigned int line, const char *fmt, ...);
111119
extern void benchmark_log(int level, const char *fmt, ...);
120+
bool is_redis_protocol(enum PROTOCOL_TYPE type);
112121

113122
#endif /* _MEMTIER_BENCHMARK_H */

0 commit comments

Comments
 (0)