实现全量持久化:save操作落盘,启动时读取到内存
增量持久化:执行修改操作时将cmd追加到log中,启动时逐条取出顺序执行
This commit is contained in:
@@ -67,21 +67,23 @@ void testcase(int connfd, uint8_t op, const char* key, const char* value, rsp_re
|
||||
|
||||
void array_testcase_1w(int connfd) {
|
||||
|
||||
int count = 10000;
|
||||
int count = 1000;
|
||||
int i = 0;
|
||||
|
||||
struct timeval tv_begin;
|
||||
gettimeofday(&tv_begin, NULL);
|
||||
|
||||
for (i = 0;i < count;i ++) {
|
||||
testcase(connfd, KVS_CMD_HSET, "nage", "lian", KVS_STATUS_OK, NULL, "SET NAME");
|
||||
testcase(connfd, KVS_CMD_HGET, "nage", NULL, KVS_STATUS_OK, "lian", "GET NAME");
|
||||
testcase(connfd, KVS_CMD_HMOD, "nage", "liu", KVS_STATUS_OK, NULL, "MOD NAME");
|
||||
testcase(connfd, KVS_CMD_HGET, "nage", NULL, KVS_STATUS_OK, "liu", "GET NAME");
|
||||
|
||||
testcase(connfd, KVS_CMD_HEXIST, "nage", NULL, KVS_STATUS_EXIST, NULL, "EXIST NAME");
|
||||
testcase(connfd, KVS_CMD_HDEL, "nage", NULL, KVS_STATUS_OK, NULL, "DEL NAME");
|
||||
testcase(connfd, KVS_CMD_HEXIST, "nage", NULL, KVS_STATUS_NO_EXIST, NULL, "NOT EXIST NAME");
|
||||
testcase(connfd, KVS_CMD_SET, "name", "lian", KVS_STATUS_OK, NULL, "SET NAME");
|
||||
testcase(connfd, KVS_CMD_GET, "name", NULL, KVS_STATUS_OK, "lian", "GET NAME");
|
||||
testcase(connfd, KVS_CMD_MOD, "name", "liu", KVS_STATUS_OK, NULL, "MOD NAME");
|
||||
testcase(connfd, KVS_CMD_GET, "name", NULL, KVS_STATUS_OK, "liu", "GET NAME");
|
||||
testcase(connfd, KVS_CMD_EXIST, "name", NULL, KVS_STATUS_EXIST, NULL, "EXIST NAME");
|
||||
testcase(connfd, KVS_CMD_DEL, "name", NULL, KVS_STATUS_OK, NULL, "DEL NAME");
|
||||
testcase(connfd, KVS_CMD_EXIST, "name", NULL, KVS_STATUS_NO_EXIST, NULL, "NOT EXIST NAME");
|
||||
|
||||
testcase(connfd, KVS_CMD_MOD, "stu", "liu", KVS_STATUS_NO_EXIST, NULL, "MOD NAME");
|
||||
testcase(connfd, KVS_CMD_DEL, "stu", NULL, KVS_STATUS_NO_EXIST, NULL, "DEL SUT");
|
||||
}
|
||||
|
||||
struct timeval tv_end;
|
||||
@@ -89,7 +91,7 @@ void array_testcase_1w(int connfd) {
|
||||
|
||||
int time_used = TIME_SUB_MS(tv_end, tv_begin); // ms
|
||||
|
||||
printf("array testcase --> time_used: %d, qps: %d\n", time_used, 70000 * 1000 / time_used);
|
||||
printf("array testcase --> time_used: %d, qps: %d\n", time_used, 9000 * 1000 / time_used);
|
||||
|
||||
}
|
||||
|
||||
@@ -104,7 +106,7 @@ void do_batch_example(int fd)
|
||||
for(int i = 0;i < 24; ++ i){
|
||||
int len = sprintf(key, "k%d", i);
|
||||
len = sprintf(val, "v%d", i);
|
||||
kvs_batch_add(&batch, KVS_CMD_HSET, key, val);
|
||||
kvs_batch_add(&batch, KVS_CMD_SET, key, val);
|
||||
}
|
||||
|
||||
// 一次性发送
|
||||
@@ -122,28 +124,37 @@ void do_batch_example(int fd)
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0;i < 24; ++ i){
|
||||
int len = sprintf(key, "k%d", i);
|
||||
len = sprintf(val, "v%d", i);
|
||||
testcase(fd, KVS_CMD_HGET, key, NULL, KVS_STATUS_OK, val, "GET K");
|
||||
}
|
||||
// for(int i = 0;i < 24; ++ i){
|
||||
// int len = sprintf(key, "k%d", i);
|
||||
// len = sprintf(val, "v%d", i);
|
||||
// testcase(fd, KVS_CMD_GET, key, NULL, KVS_STATUS_OK, val, "GET K");
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
void save(int connfd){
|
||||
testcase(connfd, KVS_CMD_SAVE, NULL, NULL, KVS_STATUS_OK, NULL, "SAVE");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 3) {
|
||||
if (argc != 4) {
|
||||
printf("arg error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *ip = argv[1];
|
||||
int port = atoi(argv[2]);
|
||||
int mode = atoi(argv[3]);
|
||||
|
||||
int connfd = connect_tcpserver(ip, port);
|
||||
|
||||
array_testcase_1w(connfd);
|
||||
// do_batch_example(connfd);
|
||||
|
||||
if(mode == 0){
|
||||
do_batch_example(connfd);
|
||||
}else if(mode == 1){
|
||||
array_testcase_1w(connfd);
|
||||
}else if(mode == 2){
|
||||
save(connfd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user