已有数据同步功能完成
This commit is contained in:
@@ -464,13 +464,13 @@ int kvs_rbtree_exist(kvs_rbtree_t *inst, const void *key, uint32_t key_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int kvs_rbtree_save_node(int fd, off_t *current_off, kvs_rbtree_t *inst, rbtree_node *node) {
|
||||
static int kvs_rbtree_save_node(iouring_ctx_t *uring, int fd, off_t *current_off, kvs_rbtree_t *inst, rbtree_node *node) {
|
||||
if (!current_off || !inst || !node) return -1;
|
||||
if (node == inst->nil) return 0;
|
||||
|
||||
int rc = 0;
|
||||
|
||||
rc = kvs_rbtree_save_node(fd, current_off, inst, node->left);
|
||||
rc = kvs_rbtree_save_node(uring, fd, current_off, inst, node->left);
|
||||
if (rc < 0) return rc;
|
||||
|
||||
uint32_t klen = htonl(node->key_len);
|
||||
@@ -503,7 +503,7 @@ static int kvs_rbtree_save_node(int fd, off_t *current_off, kvs_rbtree_t *inst,
|
||||
size_t total = 0;
|
||||
for (int i = 0; i < count; i++) total += lens[i];
|
||||
|
||||
task_t *t = submit_write(&global_uring_ctx, fd, bufs, lens, count, *current_off);
|
||||
task_t *t = submit_write(uring, fd, bufs, lens, count, *current_off);
|
||||
|
||||
|
||||
if (!t) { return -4; }
|
||||
@@ -516,22 +516,22 @@ static int kvs_rbtree_save_node(int fd, off_t *current_off, kvs_rbtree_t *inst,
|
||||
|
||||
*current_off += (off_t) total;
|
||||
|
||||
rc = kvs_rbtree_save_node(fd, current_off, inst, node->right);
|
||||
rc = kvs_rbtree_save_node(uring, fd, current_off, inst, node->right);
|
||||
if (rc < 0) return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 0 success, <0 error
|
||||
int kvs_rbtree_save(kvs_rbtree_t *inst, const char* filename){
|
||||
if (!inst || !filename) return -1;
|
||||
int kvs_rbtree_save(iouring_ctx_t *uring, kvs_rbtree_t *inst, const char* filename){
|
||||
if (!uring || !inst || !filename) return -1;
|
||||
|
||||
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
if(fd < 0) return -2;
|
||||
off_t current_off = 0;
|
||||
|
||||
|
||||
int rc = kvs_rbtree_save_node(fd, ¤t_off, inst, inst->root);
|
||||
int rc = kvs_rbtree_save_node(uring, fd, ¤t_off, inst, inst->root);
|
||||
|
||||
close(fd);
|
||||
return rc;
|
||||
|
||||
Reference in New Issue
Block a user