bugfix: reactor网络模型的的半包解析错误问题。

全量持久化时清除增量持久化的记录。
This commit is contained in:
2026-01-08 16:20:00 +08:00
parent 3cc97b9454
commit de21fe94ec
10 changed files with 282 additions and 121 deletions

View File

@@ -95,7 +95,67 @@ void array_testcase_1w(int connfd) {
}
void do_batch_example(int fd)
void rbtree_testcase_1w(int connfd) {
int count = 1000;
int i = 0;
struct timeval tv_begin;
gettimeofday(&tv_begin, NULL);
for (i = 0;i < count;i ++) {
testcase(connfd, KVS_CMD_RSET, "name", "lian", KVS_STATUS_OK, NULL, "SET NAME");
testcase(connfd, KVS_CMD_RGET, "name", NULL, KVS_STATUS_OK, "lian", "GET NAME");
testcase(connfd, KVS_CMD_RMOD, "name", "liu", KVS_STATUS_OK, NULL, "MOD NAME");
testcase(connfd, KVS_CMD_RGET, "name", NULL, KVS_STATUS_OK, "liu", "GET NAME");
testcase(connfd, KVS_CMD_REXIST, "name", NULL, KVS_STATUS_EXIST, NULL, "EXIST NAME");
testcase(connfd, KVS_CMD_RDEL, "name", NULL, KVS_STATUS_OK, NULL, "DEL NAME");
testcase(connfd, KVS_CMD_REXIST, "name", NULL, KVS_STATUS_NO_EXIST, NULL, "NOT EXIST NAME");
testcase(connfd, KVS_CMD_RMOD, "stu", "liu", KVS_STATUS_NO_EXIST, NULL, "MOD NAME");
testcase(connfd, KVS_CMD_RDEL, "stu", NULL, KVS_STATUS_NO_EXIST, NULL, "DEL SUT");
}
struct timeval tv_end;
gettimeofday(&tv_end, NULL);
int time_used = TIME_SUB_MS(tv_end, tv_begin); // ms
printf("array testcase --> time_used: %d, qps: %d\n", time_used, 9000 * 1000 / time_used);
}
void hash_testcase_1w(int connfd) {
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, "name", "lian", KVS_STATUS_OK, NULL, "SET NAME");
testcase(connfd, KVS_CMD_HGET, "name", NULL, KVS_STATUS_OK, "lian", "GET NAME");
testcase(connfd, KVS_CMD_HMOD, "name", "liu", KVS_STATUS_OK, NULL, "MOD NAME");
testcase(connfd, KVS_CMD_HGET, "name", NULL, KVS_STATUS_OK, "liu", "GET NAME");
testcase(connfd, KVS_CMD_HEXIST, "name", NULL, KVS_STATUS_EXIST, NULL, "EXIST NAME");
testcase(connfd, KVS_CMD_HDEL, "name", NULL, KVS_STATUS_OK, NULL, "DEL NAME");
testcase(connfd, KVS_CMD_HEXIST, "name", NULL, KVS_STATUS_NO_EXIST, NULL, "NOT EXIST NAME");
testcase(connfd, KVS_CMD_HMOD, "stu", "liu", KVS_STATUS_NO_EXIST, NULL, "MOD NAME");
testcase(connfd, KVS_CMD_HDEL, "stu", NULL, KVS_STATUS_NO_EXIST, NULL, "DEL SUT");
}
struct timeval tv_end;
gettimeofday(&tv_end, NULL);
int time_used = TIME_SUB_MS(tv_end, tv_begin); // ms
printf("array testcase --> time_used: %d, qps: %d\n", time_used, 9000 * 1000 / time_used);
}
void do_batch_SET_example(int fd)
{
kvs_batch_t batch;
kvs_batch_init(&batch);
@@ -103,7 +163,7 @@ void do_batch_example(int fd)
char key[10]={0}, val[10]={0};
// 组 batch最多 64 条)
for(int i = 0;i < 24; ++ i){
for(int i = 0;i < 48; ++ i){
int len = sprintf(key, "k%d", i);
len = sprintf(val, "v%d", i);
kvs_batch_add(&batch, KVS_CMD_SET, key, val);
@@ -120,16 +180,67 @@ void do_batch_example(int fd)
// 打印/处理
for (int i = 0; i < nrsp; i++) {
PRESP("BATCH", &rsps[i]);
}
int len = sprintf(key, "SET%d", i);
PRESP(key, &rsps[i]);
}
}
void do_batch_GET_example(int fd)
{
kvs_batch_t batch;
kvs_batch_init(&batch);
// 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");
// }
char key[10]={0}, val[10]={0};
// 组 batch最多 64 条)
for(int i = 0;i < 48; ++ i){
int len = sprintf(key, "k%d", i);
kvs_batch_add(&batch, KVS_CMD_GET, key, NULL);
}
// 一次性发送
kvs_batch_send(fd, &batch);
// 一次性 recv + parse
uint8_t recvbuf[BATCH_SIZE];
kvs_response_t rsps[KVS_BATCH_MAX];
int nrsp = kvs_batch_recv_parse(fd, &batch, rsps, recvbuf, sizeof(recvbuf));
// 打印/处理
for (int i = 0; i < nrsp; i++) {
int len = sprintf(key, "GET%d", i);
PRESP(key, &rsps[i]);
}
}
void do_batch_DEL_example(int fd)
{
kvs_batch_t batch;
kvs_batch_init(&batch);
char key[10]={0}, val[10]={0};
// 组 batch最多 64 条)
for(int i = 0;i < 48; ++ i){
int len = sprintf(key, "k%d", i);
kvs_batch_add(&batch, KVS_CMD_DEL, key, NULL);
}
// 一次性发送
kvs_batch_send(fd, &batch);
// 一次性 recv + parse
uint8_t recvbuf[BATCH_SIZE];
kvs_response_t rsps[KVS_BATCH_MAX];
int nrsp = kvs_batch_recv_parse(fd, &batch, rsps, recvbuf, sizeof(recvbuf));
// 打印/处理
for (int i = 0; i < nrsp; i++) {
int len = sprintf(key, "DEL%d", i);
PRESP(key, &rsps[i]);
}
}
void save(int connfd){
@@ -150,10 +261,18 @@ int main(int argc, char *argv[]) {
int connfd = connect_tcpserver(ip, port);
if(mode == 0){
do_batch_example(connfd);
do_batch_SET_example(connfd);
}else if(mode == 1){
array_testcase_1w(connfd);
do_batch_GET_example(connfd);
}else if(mode == 2){
do_batch_DEL_example(connfd);
}else if(mode == 10){
array_testcase_1w(connfd);
}else if(mode == 11){
rbtree_testcase_1w(connfd);
}else if(mode == 12){
hash_testcase_1w(connfd);
}else if(mode == -1){
save(connfd);
}
return 0;