rbtree和hash的全量持久化操作。rbtree的二进制安全。
粗略测试。
This commit is contained in:
@@ -72,12 +72,12 @@ int kvs_write_u8(uint8_t **pp, const uint8_t *end, uint8_t v);
|
||||
int kvs_write_u16(uint8_t **pp, const uint8_t *end, uint16_t v);
|
||||
int kvs_write_u32(uint8_t **pp, const uint8_t *end, uint32_t v);
|
||||
|
||||
int getcmd(uint8_t op, const char *key, const char *value, uint8_t *buf);
|
||||
int getcmd(uint8_t op, const char *key, uint32_t key_len, const char *value, uint32_t value_len, uint8_t *buf);
|
||||
|
||||
int parse_response(const uint8_t *buf, int buflen, kvs_response_t *rsp);
|
||||
void print_response(const char *cmd_name, const kvs_response_t *rsp);
|
||||
int verify_response(const kvs_response_t *rsp, uint8_t expected_op,
|
||||
uint8_t expected_status, const char *expected_data);
|
||||
uint8_t expected_status, const char *expected_data, uint32_t expected_len);
|
||||
|
||||
|
||||
|
||||
@@ -101,10 +101,10 @@ static void kvs_batch_init(kvs_batch_t *b)
|
||||
* 用 getcmd() 生成单条命令,然后 append 到 batch buffer
|
||||
* 返回:0 成功,-1 失败(太多条 or buffer 不够)
|
||||
*/
|
||||
static int kvs_batch_add(kvs_batch_t *b, uint8_t op, const char *key, const char *value){
|
||||
static int kvs_batch_add(kvs_batch_t *b, uint8_t op, const char *key, uint32_t key_len, const char *value, uint32_t value_len){
|
||||
if (b->cnt >= KVS_BATCH_MAX) return -1;
|
||||
uint8_t tmp[CMD_SIZE];
|
||||
int n = getcmd(op, key, value, tmp); // 你提供的函数
|
||||
int n = getcmd(op, key, key_len, value, value_len, tmp); // 你提供的函数
|
||||
if (n <= 0) return -1;
|
||||
|
||||
if (b->len + n > (int)sizeof(b->buf)) return -1;
|
||||
@@ -122,7 +122,7 @@ static int kvs_batch_add(kvs_batch_t *b, uint8_t op, const char *key, const char
|
||||
*/
|
||||
static int kvs_batch_send(int fd, const kvs_batch_t *b)
|
||||
{
|
||||
printf("send : %d\n", b->len);
|
||||
// printf("send : %d\n", b->len);
|
||||
return (int)send(fd, b->buf, b->len, 0);
|
||||
}
|
||||
|
||||
@@ -141,9 +141,7 @@ static int kvs_batch_recv_parse(int fd,
|
||||
int used = 0;
|
||||
|
||||
while(parsed < b->cnt){
|
||||
printf("recv loop: parsed=%d\n", parsed);
|
||||
int nrecv = (int)recv(fd, recvbuf+used, recvbuf_cap, 0);
|
||||
printf("recv nrecv=%d\n", nrecv);
|
||||
if (nrecv <= 0) return -1;
|
||||
|
||||
int off = 0;
|
||||
@@ -156,7 +154,6 @@ static int kvs_batch_recv_parse(int fd,
|
||||
used+= consumed;
|
||||
parsed++;
|
||||
}
|
||||
printf("after parse: parsed=%d, used=%d\n", parsed, used);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
Reference in New Issue
Block a user