Pika 4.0(PikiwiDB) 代码分析 #1971
AlexStocks
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
1 PikiwiDB 特点
2 主体流程
2.1 请求处理
总体流程:
下面以 ”set a b" 为例子,说明命令解析后的数据物化流程。
到函数 ExecuteCmd 的时候,params 是参数列表,info 则是 command 相关,info->handler 记录了 command 的处理函数。
函数调用路径: main -> Server::MainLoop() -> PikiwiDB::run() -> Server::run() -> Internal::TaskManager::loopParseStream() -> StreamSocket::loopParseStream() -> PClient::handlePacket() -> PCommandTable::ExecuteCmd() -> pstring.cc::set()
函数调用路径: main -> Server::MainLoop() -> PikiwiDB::run() -> Server::run() -> Internal::TaskManager::loopParseStream() -> StreamSocket::loopParseStream() -> PClient::handlePacket() -> PCommandTable::ExecuteCmd() -> pstring.cc::set()
1 根据 db 号找到 db;2 把参数放入 waitSyncKeys_,由 pikiwiDB 异步写入内存和磁盘;3 返回
2.2 数据落盘过程
落盘缓冲区:PStore.waitSyncKeys_
PStore 中 backends_ 定义为:std::vector<std::unique_ptr > backends_;
PStore::DumpToBackends(int dbno) 的作用是把 PStore.waitSyncKeys_[@dbno] 中的内容写入 PStore::backends_[@dbno],如果 key 没有超时则调用的是 Put,超时则调用的是 Delete(),写完之后淘汰 waitSyncKeys_[dbno] 中的数据。
2.3 删除过时数据
查找 key 是否超时,如果超时则调用 PSTORE.DeleteKey() 删除。
Beta Was this translation helpful? Give feedback.
All reactions