-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add blpop cmd #373
feat: Add blpop cmd #373
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Walkthrough此次更新主要为 Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant BLPopCmd
participant BaseCmd
participant PikiwiDB
Client->>+BLPopCmd: 执行BLPop命令
BLPopCmd->>+BaseCmd: ServeAndUnblockConns(key)
BaseCmd->>+PikiwiDB: 获取键到连接的映射
PikiwiDB-->>-BaseCmd: 返回连接列表
BaseCmd-->>-BLPopCmd: 处理连接并返回结果
BLPopCmd-->>-Client: 返回元素或等待消息
loop 每250毫秒
PikiwiDB->>PikiwiDB: ScanExpiredBlockedConnsOfBlrpop
end
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- src/base_cmd.cc (1 hunks)
- src/base_cmd.h (2 hunks)
- src/cmd_list.cc (3 hunks)
- src/cmd_list.h (1 hunks)
- src/cmd_table_manager.cc (1 hunks)
- src/pikiwidb.h (2 hunks)
Additional comments not posted (12)
src/pikiwidb.h (2)
48-50
: 添加的GetMapFromKeyToConns方法这个方法返回了一个对
key_to_blocked_conns_
成员变量的引用。这个方法的实现是正确的,但需要注意线程安全问题。如果多个线程可能同时访问或修改这个映射,应该考虑添加适当的同步机制。请确认在使用这个方法的地方是否已经考虑了线程安全问题。
67-74
: 添加的key_to_blocked_conns_成员变量这个成员变量用于存储从“Blockkey”到被阻塞的客户端连接的映射。注释详细说明了其用途,代码实现看起来没有问题。
这个成员变量的添加是合理的,与BLPop功能的描述一致。
src/cmd_list.h (2)
34-37
: 新增的BLPopCmd类这个类继承自
BaseCmd
,并添加了构造函数。构造函数接受命令名称和参数数量,符合命令类的设计模式。这个构造函数的实现是正确的。
38-44
: BLPopCmd类的方法实现
DoInitial
和DoCmd
方法是命令执行的核心,BlockThisClientToWaitLRPush
方法用于阻塞客户端等待数据。需要确保这些方法的逻辑正确,并且线程安全。请确认这些方法的实现是否已经过测试,特别是
BlockThisClientToWaitLRPush
方法的阻塞逻辑。src/base_cmd.cc (1)
99-125
: 新增的ServeAndUnblockConns方法这个方法遍历等待列表并为每个阻塞的客户端提供数据。需要注意几点:
- 确保在遍历等待列表时没有数据竞争。
- 处理所有可能的错误情况。
- 确保性能没有明显问题。
代码逻辑看起来是正确的,但需要确认在实际使用中是否表现良好。
请确认这个方法在高并发情况下的表现,并确保没有数据竞争问题。
src/cmd_table_manager.cc (1)
160-160
: 在命令表中新增BLPop命令这个命令的注册看起来是正确的,并且与其他命令的注册方式一致。
这个命令的注册实现是正确的。
src/cmd_list.cc (5)
32-32
: 确认 ServeAndUnblockConns 方法的正确性请确保 ServeAndUnblockConns 方法正确实现并集成。
120-121
: BLPopCmd 类的构造函数构造函数中初始化了命令名称和参数数量,代码看起来没有问题。
123-125
: DoInitial 方法该方法正确地设置了客户端的键。
128-140
: DoCmd 方法的逻辑请确认以下几点:
LPop
操作是否正确处理了键不存在的情况。BlockThisClientToWaitLRPush
方法是否正确实现了阻塞逻辑。
142-152
: BlockThisClientToWaitLRPush 方法该方法将客户端添加到等待列表中,请确保以下几点:
key_to_conns_
的正确初始化。- 并发情况下的线程安全性。
src/base_cmd.h (1)
319-320
: ServeAndUnblockConns 方法请确保 ServeAndUnblockConns 方法正确实现并集成到 BaseCmd 类中。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (8)
- src/base_cmd.cc (2 hunks)
- src/base_cmd.h (3 hunks)
- src/cmd_list.cc (3 hunks)
- src/cmd_list.h (1 hunks)
- src/cmd_table_manager.cc (1 hunks)
- src/pikiwidb.cc (2 hunks)
- src/pikiwidb.h (2 hunks)
- tests/assets/default.conf (4 hunks)
Files skipped from review as they are similar to previous changes (5)
- src/base_cmd.cc
- src/base_cmd.h
- src/cmd_list.cc
- src/cmd_list.h
- src/pikiwidb.h
Additional comments not posted (9)
src/cmd_table_manager.cc (1)
160-160
: 添加 BLPop 命令代码中正确地将
BLPop
命令添加到了命令表中。src/pikiwidb.cc (2)
127-142
: 实现了 ScanExpiredBlockedConnsOfBlrpop 方法这个方法遍历了所有阻塞的连接并检查它们是否过期。如果过期,则向客户端发送空字符串并写回响应。逻辑正确,但需要注意性能和潜在的 race condition。
请确保此方法在高并发情况下的性能,并检查是否需要额外的锁机制来防止数据竞争。
188-189
: 定期调度任务正确地将
ScanExpiredBlockedConnsOfBlrpop
方法添加到了定期调度任务中,每250毫秒执行一次。tests/assets/default.conf (6)
13-13
: 绑定到特定 IP 地址确保绑定到正确的IP地址,以防止潜在的安全问题。
38-38
: 增加数据库数量将数据库数量从3增加到16。确保系统资源足够支持增加的数据库数量。
请确认增加数据库数量后,系统是否有足够的资源来处理。
318-322
: RocksDB 实例数量配置将 RocksDB 实例数量配置为3。确保这个配置适合你的负载和性能需求。
324-326
: 小型压缩阈值配置配置了小型压缩阈值。确保这个配置适合你的数据增长和压缩策略。
329-344
: RocksDB 配置参数增加了多个 RocksDB 配置参数。这些配置参数有助于调整性能。确保这些配置符合你的性能和资源需求。
346-348
: Raft 配置配置了 Raft 端口偏移。确保 Raft 配置正确并且不会与其他服务冲突。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- src/base_cmd.cc (2 hunks)
- src/cmd_list.cc (3 hunks)
- src/pikiwidb.cc (2 hunks)
- src/pikiwidb.h (2 hunks)
Files skipped from review as they are similar to previous changes (4)
- src/base_cmd.cc
- src/cmd_list.cc
- src/pikiwidb.cc
- src/pikiwidb.h
Summary of Changes
This pull request implements the BLPOP command. The BLPOP command is designed to block the client when the specified key does not contain any data, and it will unblock the client once the key has data input.
Current Implementation
The basic framework for the BLPOP command has been established.
The command is functional in blocking the client and waiting for data input on the specified key.
Tasks Remaining
Raft log Handling: Implementation for handling binary logs needs to be completed.
Expiration Support: Add support for key expiration.
Locking Mechanism: Implement a locking mechanism to ensure thread safety and data consistency.
Multi-DB Consideration: Ensure the BLPOP command works correctly across multiple databases.
BRPOP Command: Implement the BRPOP command, which should function similarly to BLPOP but operates on the right end of the list.
Summary by CodeRabbit
新功能
ServeAndUnblockConns
方法,用于根据键值服务并解锁连接。BLPopCmd
类,支持从列表中弹出元素,并处理客户端阻塞。PikiwiDB
类中新增ScanExpiredBlockedConnsOfBlrpop
方法,用于扫描和处理过期的阻塞连接。PikiwiDB
类增加了GetMapFromKeyToConns
方法和key_to_blocked_conns_
成员变量,用于存储键到连接的映射。优化
PikiwiDB
类的Init
函数中添加了一个定期任务,每250毫秒调用一次ScanExpiredBlockedConnsOfBlrpop
方法。