arana-db / arana-db/kiwi-cpp

将存储引擎中直接写 Rocksdb 的部分换成调用封装的 Batch 接口

Open
#17 5 comments 0 reactions 2 assignees Claimed by @ForestLH View on GitHub
✏️ Feature
Dominant language
C++
Stars
49
Forks
8
PR merge metrics
No merged PRs in 30d

Description

为方便在 raft 模式和单机模式之间切换,所有的写命令底层在写 rocksdb 时应当采用我们封装的 Batch 接口。
> 参考PR:https://github.com/OpenAtomFoundation/pikiwidb/pull/285
## 修改方法:
参考上述PR,总结起来有四件事:
1. 构造我们封装的 Batch ,不使用 rocksdb::Batch(同时包含 rocksdb:batch 和写 raft 的逻辑);
3. 把 put 和 delete 换成 Batch 接口的 put 和 delete;
4. 调用 Batch 的 Commit 方法,并返回 Commit 方法的返回值
5. 在 consistency_test.go 中增加简单的一致性测试

## 小技巧
对于第 2 点,也是最麻烦的地方,但可以用 vim 的替换来做,非常方便。
这里我把替换的命令放出来,只需要在命令模式下,在下边这行命令前边加上行号范围即可

- vscode vim 插件:`s/batch\.(\w+)\(handles_\[(\w+)\], (.+)\);/batch->\1(\2, \3);/gc`
- 原生vim:`s/batch\.\(\w\+\)(handles_\[\(\w\+\)\], \(.\+\));/batch->\1(\2, \3);/gc`

示例:如图,找到想要替换的函数的范围(行号),然后添加在上述命令前即可。比如我想要替换 LPushx 这个函数的写操作,找到开始行号和结束行号,然后在VIM中输入下边内容即可:
```
:356,387s/batch\.\(\w\+\)(handles_\[\(\w\+\)\], \(.\+\));/batch->\1(\2, \3);/gc
```
![image](https://github.com/OpenAtomFoundation/pikiwidb/assets/77976092/60b77ee4-d8b6-4b3c-b519-3e2cd84c61f8)

## 待做事项

// Strings Commands
- [x] Set

@解君豪:
smj:
- [ ] Append
- [ ] Decrby
- [ ] GetSet
- [ ] Incrby
- [ ] Incrbyfloat

lh
- [x] MSet
- [x] MSetnx
- [ ] Setxx
- [x] SetBit
- [x] Setex
gkj:
- [ ] Setnx
- [ ] Setvx
- [ ] Delvx
- [ ] Setrange
- [ ] BitOp

// Hash
- [x] HDel
- [x] HSet

ncy:
- [x] HIncrby
- [x] HIncrbyfloat
- [x] HMSet
- [x] HSetnx

// Sets Commands
- [x] SAdd
- [x] SRem
lh:
- [x] SDiffstore
- [x] SInterstore
- [x] SMove
- [x] SPop
- [x] SUnionstore

// Lists Commands
- [x] LPop
- [x] LPush

zzl:
- [x] LInsert
- [x] LPushx
- [x] LRem
- [x] LSet
- [x] LTrim

lihao:
- [ ] RPop
- [ ] RPoplpush
- [ ] RPush
- [ ] RPushx

// Zsets Commands
- [x] ZAdd
- [x] ZRem

- [ ] ZIncrby
- [ ] ZRemrangebylex
- [ ] ZRemrangebyrank
- [ ] ZRemrangebyscore

todo:
lh:
- [ ] ZUnionstore
- [ ] ZInterstore
- [ ] ZPopMax
- [ ] ZPopMin

// Keys Commands
- [ ] StringsDel
- [ ] HashesDel
- [ ] ListsDel
- [ ] ZsetsDel
- [ ] SetsDel
- [ ] StringsPKPatternMatchDel
- [ ] ListsPKPatternMatchDel
- [ ] HashesPKPatternMatchDel
- [ ] ZsetsPKPatternMatchDel
- [ ] SetsPKPatternMatchDel
- [ ] StringsExpire
- [ ] HashesExpire
- [ ] ListsExpire
- [ ] ZsetsExpire
- [ ] SetsExpire
- [ ] StringsExpireat
- [ ] HashesExpireat
- [ ] ListsExpireat
- [ ] SetsExpireat
- [ ] ZsetsExpireat

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.