OpenAtomFoundation / pikiwidb

a high-performance, large-capacity, multi-tenant, data-persistent, strong data consistency based on raft, Redis-compatible elastic KV data storage system based on RocksDB
BSD 3-Clause "New" or "Revised" License
204 stars 63 forks source link

command develop tasks #30

Open lqxhub opened 1 year ago

lqxhub commented 1 year ago

pikiwidb 命令处理相关功能的开发

在pikiwidb中, 每一个命令处理对应一个C++的class, 当服务端收到一条命令时,会去找这个命令处理对应的对象, 如果没有找到返回错误, 如果找到后, 执行对应的命令.

函数入口(这是临时处理函数,后面会调整这个函数的实现) https://github.com/OpenAtomFoundation/pikiwidb/blob/e05878dfe99c232be3a6f40b6dc9ab73785c7db0/src/client.cc#L244

命令处理相关代码

BaseCmd 是所有命令处理类的基类, https://github.com/OpenAtomFoundation/pikiwidb/blob/e05878dfe99c232be3a6f40b6dc9ab73785c7db0/src/base_cmd.h#L89

所有命令处理的class需要继承这个类, 并且重写 DoInitialDoCmd 这两个虚函数.

DoInitial 函数, 在命令执行前调用, 负责处理命令执行需要的参数, 例如把 命令的key找到, 命令参数的大小写转换等等 DoCmd 函数, 命令执行时的逻辑处理函数, 负责整个命令的具体处理逻辑

需要在 构造函数中,给 BaseCmdflag 赋值, flag值根据实际情况确定, 例子:https://github.com/OpenAtomFoundation/pikiwidb/blob/e05878dfe99c232be3a6f40b6dc9ab73785c7db0/src/cmd_kv.cc#L13

命令分类

命令分为两大类

命令注册

所有的命令需要把命令对象的指针注册(写入)到 commandManager 这个map中, map的 key 是 命令名, value 是处理这个命令的指针

命令注册函数 https://github.com/OpenAtomFoundation/pikiwidb/blob/e05878dfe99c232be3a6f40b6dc9ab73785c7db0/src/cmd_table_manager.cc#L20

代码文件

代码文件, 每个类型的命令有一个单独的文件, 并且命令处理相关的文件以 cmd 开头, 例如 STRING 相关的命令, 文件名cmd_kv.cccmd_kv.h, HASH 相关的命令 cmd_hash.cc, cmd_hash.h

实现步骤

AlexStocks commented 1 year ago

string:

get done set done strlen done mset done setnx done setex done psetex done getset done mget done append done bitcount done bitop done getbit done setbit done incr done decr done incrby done incrbyfloat done decrby done getrange done setrange done msetnx done

AlexStocks commented 11 months ago

hashtable

ncy: hlen over hstrlen over hset over hget over hgetall over hmset over hmget over hkeys over hrandfield over hscan over

csx: hsetnx done hincrby done

pcy: hincrbyfloat done hvals over

qxh: hdel over

ncy: hexists done

AlexStocks commented 11 months ago

set:

whr: sadd over scard done

cwl: sismember over

crp:
srem over srandmember done

whr: smembers done sdiff done sdiffstore done

cwl: sinter done sinterstore done sscan done

Henry: sunion over sunionstore over

pcy: smove done spop done

longfar-ncy commented 11 months ago

我写了个小工具用于对比 pikiwidb 与 redis 输出,在实现命令时可以用来与 redis 对比。 代码放在我 fork 的仓库了:https://github.com/longfar-ncy/pikiwidb/tree/feat/pr-cli/tool/pr-cli 效果如图: image image

578223592 commented 11 months ago

请问sadd可以提pr吗?我尝试完成了sismember,但是没有sadd作为基础无法完整测试。或者我先提sismember?或者我来负责sadd?

Centurybbx commented 10 months ago

list:

cwl: lpush done rpush done

liuhuan: lpushx done rpushx done lpop done lindex done llen done

csq: rpop done

cwl: lset done ltrim done lrange done linsert done

henry: lrem done

lh: blpop brpop rpoplpush 从 Redis 6.2.0起, RPOPLPUSH 被废弃,使用 LMOVE 替代 brpoplpush 从 Redis 6.2.0 起,建议使用 BLMOVE 替代 BRPOPLPUSH

panlei-coder commented 10 months ago

zset done

whr: zcard done

pl: zrank done zrevrank done zrem done zincrby done

wxr: zadd done zrevrange done zrangebyscore done

csx: zrevrangebyscore done zremrangebyrank done
zrangebylex done zrevrangebylex done zscore done zrange done zremrangebyscore done

AlexStocks commented 10 months ago

key:

henry: exists done del done

lft: type done expire done ttl done

cwl: pexpire done pttl done expireat done pexpireat done

lh: persist done keys done

AlexStocks commented 10 months ago

// admin

select done

dingxiaoshuai config done

panlei: scan

pcy flushdb done flushall done

lft: hello slowlog

renzhenfeng(0629): dbsize pr bgsave pr

lh: save 实现成本比较高 lastsave 实现成本比较高

tangruilin: echo pr auth pr

bzm: shutdown done

smj info pr

zzl: rename done renamenx done

zhy: 2024.6.15 sort done

gkj: 2024.6.15 client pr monitor pr

optics: debug done

ping done

todo: randomkey move:涉及多 db 的时候,保证一致性比较难,暂时不做

hero-heng commented 9 months ago

command 类型 新增一种类型halfWrite sinter, sunion, sinterstore, sunionstore, msetnx, zinter, zunion, zunionstore, ziter, zinterstore

AlexStocks commented 7 months ago

image

美团 KV 系统 RTC 优化

from https://tech.meituan.com/2024/03/15/kv-squirrel-cellar.html

总流程: 1 Pikiwidb 将是内存和磁盘混合存储模型 2 线程模型分为网络线程池和 worker 线程池 3 网络线程池处理客户端连接请求,和对内存的读请求 4 worker 线程池处理磁盘读写任务 以及对内存的写任务

hahahashen commented 7 months ago

我想认领一下string 的 msetnx命令的实现,我目前的想法是:参照PikiviDB MSetCmd类的实现和pika MsetCmd MsetnxCmd类的实现,在PikiwiDB实现一个新的MSetNXCmd类,这个类主要的函数有DoInitial,DoCmd DoInitial函数给client key赋值,类型为std::vector,也就是msetnx命令将要赋值的keys DoCmd函数是msetnx命令处理的处理逻辑,参照pika实现,调用storage层的MSetnx函数,这个函数目前在PikiwiDB已经被实现了;但storage层的MSetnx函数并没有上锁,所以具体实现的时候还要再看一下这个细节 其他还有一些初始化相关的地方,目前看到了两处,一处是cmd_table_manager.cc处InitCmdTable要ADD_COMMAND,另一处是base_cmd.h文件中也要添加对应的常量

AlexStocks commented 7 months ago

测试: 1 string 缺少 go-test 2 hashtable 有一半命令没有 go-test 3 tcl 测试

Mixficsol commented 7 months ago

Go Test测试移植Pika的到PikiwiDB @dingxiaoshuai123

Issues-translate-bot commented 7 months ago

Bot detected the issue body's language is not English, translate it automatically.


Go Test tests porting Pika to PikiwiDB @dingxiaoshuai123

panlei-coder commented 6 months ago

@Tangruilin 看todo

Issues-translate-bot commented 6 months ago

Bot detected the issue body's language is not English, translate it automatically.


@Tangruilin nantodo

Tangruilin commented 6 months ago

ping

trl: ping

我先把这个实现以下吧

Issues-translate-bot commented 6 months ago

Bot detected the issue body's language is not English, translate it automatically.


ping

trl: ping

Let me implement this first:

AlexStocks commented 5 months ago

RedisRaft 支持的 Redis 命令列表 https://github.com/RedisLabs/redisraft/blob/master/docs/Using.md