-
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: support pd #395
feat: support pd #395
Conversation
Walkthrough此次更新对项目的构建配置和服务架构进行了显著改进。新增了对协议缓冲区(Protocol Buffers)的支持,增强了数据库管理功能,并引入了新的放置驱动服务,使得分布式数据库系统的操作更加高效和灵活。 Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant StoreService
participant PlacementDriverService
User->>StoreService: 请求获取存储统计
StoreService->>PlacementDriverService: 调用GetStoreStats
PlacementDriverService-->>StoreService: 返回存储统计
StoreService-->>User: 返回统计信息
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: 19
Outside diff range, codebase verification and nitpick comments (5)
src/praft/praft_service.h (1)
16-17
: 确认删除对PRaft
的依赖构造函数已修改为默认构造函数,不再接受
PRaft
指针。请确保此更改不会影响其他依赖PRaft
实例的组件。特别是,src/praft/praft.cc
中仍然使用旧的构造函数,这可能会导致代码破裂。请更新src/praft/praft.cc
中的构造函数使用。
src/praft/praft.cc
:DummyServiceImpl service(&PRAFT);
Analysis chain
确认删除对
PRaft
的依赖构造函数已修改为默认构造函数,不再接受
PRaft
指针。请确保此更改不会影响其他依赖PRaft
实例的组件。Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the removal of `PRaft` dependency does not break other components. # Test: Search for the usage of `DummyServiceImpl` constructor. Expect: No broken dependencies. rg --type cpp -A 5 $'DummyServiceImpl'Length of output: 1725
src/db.h (1)
57-57
: 确认新成员变量praft_
已添加新私有成员变量
praft_
,类型为std::unique_ptr<PRaft>
。然而,src/db.cc
中有关于praft_
初始化和使用的代码被注释掉了。请确保这些代码被正确地取消注释并经过测试,以确保praft_
的正确初始化和使用。
src/db.cc
:// praft_ = std::make_unique<PRaft>(); // butil::Status bs = praft_->Init(std::move(group_id), true); // if (!bs.ok()) { // return pstd::Status::Error(bs.error_str()); // }Analysis chain
确认新成员变量
praft_
已添加新私有成员变量
praft_
,类型为std::unique_ptr<PRaft>
,请确保其实现符合类设计,并且在使用过程中不会引入潜在问题。Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of the new `praft_` member variable. # Test: Search for the usage of `praft_` member variable. Expect: Proper usage and initialization. rg --type cpp -A 5 $'praft_'Length of output: 957
src/pd/pd_service.h (1)
1-6
: 版权声明请确保版权声明和许可证信息是最新的,并且与项目的实际情况一致。
src/praft/praft.cc (2)
注释掉的服务器初始化代码会显著影响服务器的生命周期管理,可能会引入问题。
以下是需要注意的代码位置:
src/store.cc
src/praft/praft.cc
请确保这些更改不会引入问题。
Analysis chain
Line range hint
92-118
:
请验证注释掉的服务器初始化代码的影响。注释掉的服务器初始化代码可能会影响服务器的生命周期管理,请确保这些更改不会引入问题。
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the impact of commented-out server initialization code. # Test: Search for the usage of `server_` in the codebase. Expect: No critical usage that depends on it. rg --type cpp -A 5 $'server_'Length of output: 7592
125-130
: IP 转换失败的处理逻辑需要改进在 IP 转换失败时,当前代码仅记录错误并返回状态,但没有执行任何其他的恢复或清理操作。建议在
str2ip
失败时添加必要的资源清理或服务器状态重置步骤。
src/praft/praft.cc
第 127 行附近:// server_.reset();
注释掉的代码需要实现具体的错误处理逻辑。Analysis chain
请验证 IP 转换失败的处理逻辑。
确保在 IP 转换失败时,系统能正确处理错误情况。
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the handling of IP conversion failure. # Test: Search for error handling after `str2ip` function. Expect: Proper error logging and handling. rg --type cpp -A 5 $'str2ip'Length of output: 362
Script:
#!/bin/bash # Description: Verify the handling of IP conversion failure by checking the implementation and usage of server_.reset. # Search for the implementation of server_.reset rg --type cpp 'server_\.reset' # Additionally, search for any other error handling related to str2ip rg --type cpp -A 5 'str2ip'Length of output: 881
Script:
#!/bin/bash # Description: Verify the handling of IP conversion failure by checking the implementation and usage of ERROR_LOG_AND_STATUS. # Search for the implementation of ERROR_LOG_AND_STATUS rg --type cpp 'ERROR_LOG_AND_STATUS'Length of output: 890
Script:
#!/bin/bash # Description: Verify the handling of IP conversion failure by checking the implementation of ERROR_LOG_AND_STATUS. # Search for the definition of ERROR_LOG_AND_STATUS in src/praft/praft.cc rg --type cpp --context 5 '#define ERROR_LOG_AND_STATUS' src/praft/praft.ccLength of output: 298
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (27)
- CMakeLists.txt (1 hunks)
- pikiwidb.conf (1 hunks)
- src/CMakeLists.txt (4 hunks)
- src/base_cmd.cc (2 hunks)
- src/base_cmd.h (1 hunks)
- src/cmd_raft.cc (2 hunks)
- src/cmd_raft.h (1 hunks)
- src/config.cc (1 hunks)
- src/config.h (1 hunks)
- src/db.cc (6 hunks)
- src/db.h (2 hunks)
- src/pd/CMakeLists.txt (1 hunks)
- src/pd/pd.proto (1 hunks)
- src/pd/pd_server.cc (1 hunks)
- src/pd/pd_server.h (1 hunks)
- src/pd/pd_service.cc (1 hunks)
- src/pd/pd_service.h (1 hunks)
- src/pikiwidb.cc (2 hunks)
- src/praft/CMakeLists.txt (2 hunks)
- src/praft/praft.cc (8 hunks)
- src/praft/praft.h (3 hunks)
- src/praft/praft_service.h (1 hunks)
- src/store.cc (3 hunks)
- src/store.h (2 hunks)
- src/store.proto (1 hunks)
- src/store_service.cc (1 hunks)
- src/store_service.h (1 hunks)
Files skipped from review due to trivial changes (2)
- src/base_cmd.h
- src/praft/CMakeLists.txt
Additional comments not posted (127)
src/pd/CMakeLists.txt (2)
6-14
: 确保pd.proto
文件的路径正确请确保
pd.proto
文件路径正确,并且在构建过程中可以成功生成pd.pb.cc
文件。Verification successful
确保
pd.proto
文件的路径正确已确认
pd.proto
文件存在于src/pd/pd.proto
路径下,路径正确。Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence and path of `pd.proto`. # Test: Search for `pd.proto` file. Expect: File exists in the specified directory. fd 'pd.proto' src/pdLength of output: 36
15-42
: 确认库配置请确保库的配置和依赖项正确无误,特别是
TARGET_INCLUDE_DIRECTORIES
和TARGET_LINK_LIBRARIES
部分。src/db.h (5)
56-56
: 初始化成员变量storage_
私有成员变量
storage_
已初始化为nullptr
,请确保此更改符合类设计,并且不会引入潜在问题。
47-47
: 确认成员变量类型更改私有成员变量
db_index_
已替换为db_id_
,类型为int64_t
,请确保此更改与数据库标识符的管理需求一致,并且不会导致其他部分的兼容性问题。Verification successful
确认成员变量类型更改
私有成员变量
db_index_
已替换为db_id_
,类型为int64_t
,并且在多个文件和上下文中使用。所有使用都与新类型一致,请确保此更改与数据库标识符的管理需求一致,并且不会导致其他部分的兼容性问题。
src/db.h
src/db.cc
src/pd/pd_server.h
src/pd/pd_server.cc
src/praft/praft.h
src/praft/praft.cc
src/storage/src/storage.cc
src/storage/include/storage/storage.h
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of the new `db_id_` member variable. # Test: Search for the usage of `db_id_` member variable. Expect: All usages match the new type. rg --type cpp -A 5 $'db_id_'Length of output: 11552
26-26
: 确认新方法Init
已添加新方法
Init
,请确保其实现符合类设计,并且在初始化过程中不会引入潜在问题。
44-44
: 确认方法重命名方法
GetDbIndex
已重命名为GetDBID
,请确保此更改符合新的命名约定,并且在代码库中所有引用均已更新。Verification successful
确认方法重命名
方法
GetDbIndex
已重命名为GetDBID
,并且在代码库中没有发现对旧方法名的引用。所有引用均已更新。
src/db.h
: 确认新方法名的定义。Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of the renamed `GetDBID` method. # Test: Search for the usage of `GetDBID` method. Expect: All references are updated to the new name. rg --type cpp -A 5 $'GetDBID\('Length of output: 228
Script:
#!/bin/bash # Description: Verify the usage of the renamed `GetDBID` method and ensure no references to `GetDbIndex` remain. # Test: Search for the old method name `GetDbIndex`. Expect: No references should be found. rg --type cpp -A 5 $'GetDbIndex\(' # Test: Search for the new method name `GetDBID`. Expect: All references should be updated to the new name. rg --type cpp -A 5 $'GetDBID\('Length of output: 264
23-23
: 确认构造函数参数类型更改构造函数参数类型已从
int
更改为int64_t
,请确保此更改与数据库标识符的管理需求一致,并且不会导致其他部分的兼容性问题。src/store_service.h (1)
14-16
: 类声明和构造函数看起来不错。类声明和默认构造函数都符合标准。
src/cmd_raft.h (1)
13-13
: 添加client.h
头文件。添加
client.h
头文件看起来是为了增强功能。请确保在此文件中使用了client.h
中的内容。src/pd/pd_service.h (10)
14-14
: 类定义
PlacementDriverServiceImpl
类实现了PlacementDriverService
接口,确保类的设计符合项目的架构要求。
16-16
: 默认构造函数默认构造函数定义正确。
18-21
: 方法CreateAllRegions
确保
CreateAllRegions
方法的实现符合业务逻辑需求,并且正确处理了所有可能的错误情况。
22-25
: 方法DeleteAllRegions
确保
DeleteAllRegions
方法的实现符合业务逻辑需求,并且正确处理了所有可能的错误情况。
26-27
: 方法AddStore
确保
AddStore
方法的实现符合业务逻辑需求,并且正确处理了所有可能的错误情况。
29-30
: 方法RemoveStore
确保
RemoveStore
方法的实现符合业务逻辑需求,并且正确处理了所有可能的错误情况。
32-33
: 方法GetClusterInfo
确保
GetClusterInfo
方法的实现符合业务逻辑需求,并且正确处理了所有可能的错误情况。
35-37
: 方法OpenPDScheduling
确保
OpenPDScheduling
方法的实现符合业务逻辑需求,并且正确处理了所有可能的错误情况。
39-41
: 方法ClosePDScheduling
确保
ClosePDScheduling
方法的实现符合业务逻辑需求,并且正确处理了所有可能的错误情况。
44-44
: 命名空间结束确保命名空间的使用符合项目的命名规范。
src/pd/pd.proto (23)
1-1
: 语法版本确保
proto3
语法版本符合项目需求。
2-2
: 包名包名
pikiwidb
符合项目命名规范。
3-3
: 选项
cc_generic_services
选项设置为true
,确保符合项目需求。
5-5
: 导入文件确保
store.proto
文件存在并且定义正确。
7-8
: 消息GetClusterInfoRequest
空消息定义正确。
10-13
: 消息GetClusterInfoResponse
确保
GetClusterInfoResponse
消息定义符合业务逻辑需求。
15-21
: 消息Store
确保
Store
消息定义符合业务逻辑需求。
23-29
: 消息Region
确保
Region
消息定义符合业务逻辑需求。
31-34
: 消息RegionEpoch
确保
RegionEpoch
消息定义符合业务逻辑需求。
36-40
: 枚举StoreState
确保
StoreState
枚举定义符合业务逻辑需求。
42-46
: 消息CreateAllRegionsRequest
确保
CreateAllRegionsRequest
消息定义符合业务逻辑需求。
48-50
: 消息CreateAllRegionsResponse
确保
CreateAllRegionsResponse
消息定义符合业务逻辑需求。
52-53
: 消息DeleteAllRegionsRequest
空消息定义正确。
55-57
: 消息DeleteAllRegionsResponse
确保
DeleteAllRegionsResponse
消息定义符合业务逻辑需求。
59-62
: 消息AddStoreRequest
确保
AddStoreRequest
消息定义符合业务逻辑需求。
64-68
: 消息AddStoreResponse
确保
AddStoreResponse
消息定义符合业务逻辑需求。
70-72
: 消息RemoveStoreRequest
确保
RemoveStoreRequest
消息定义符合业务逻辑需求。
74-76
: 消息RemoveStoreResponse
确保
RemoveStoreResponse
消息定义符合业务逻辑需求。
78-79
: 消息OpenPDSchedulingRequest
空消息定义正确。
81-83
: 消息OpenPDSchedulingResponse
确保
OpenPDSchedulingResponse
消息定义符合业务逻辑需求。
85-86
: 消息ClosePDSchedulingRequest
空消息定义正确。
88-90
: 消息ClosePDSchedulingResponse
确保
ClosePDSchedulingResponse
消息定义符合业务逻辑需求。
92-106
: 服务PlacementDriverService
确保
PlacementDriverService
服务定义符合业务逻辑需求,并且所有 RPC 方法都已正确定义。src/store.h (8)
12-14
: 新增头文件确保新增的头文件符合项目的依赖需求。
18-22
: 新增头文件确保新增的头文件符合项目的依赖需求。
54-54
: 方法Init
Init
方法不再需要db_number
参数,确保初始化逻辑符合项目需求。
55-56
: 新增方法InitRpcServer
和RegisterStoreToPDServer
确保新增方法实现了正确的服务器初始化和注册逻辑。
58-60
: 新增方法SetStoreID
和GetStoreID
确保新增方法实现了正确的线程安全的存储ID管理。
62-62
: 修改方法GetBackend
确保
GetBackend
方法的修改符合项目需求,并且正确处理了所有可能的错误情况。
64-64
: 新增方法AddBackend
确保新增方法实现了正确的后端添加逻辑。
71-81
: 新增成员变量确保新增的成员变量符合项目的设计需求,并且正确处理了所有可能的并发情况。
src/CMakeLists.txt (6)
6-13
: 新增的自定义命令用于生成 Protocol Buffer 源文件此自定义命令用于从 Protocol Buffer 定义文件生成 C++ 源文件,确保正确处理数据序列化和反序列化。
14-14
: 创建静态库store_pb
此更改确保生成的 Protocol Buffer 源文件被编译成静态库,以便与其他目标链接。
15-15
: 设置库输出路径此更改确保编译的库被放置在正确的目录中。
16-16
: 更新store_pb
目标的包含目录此更改确保
store_pb
目标可以访问 Protocol Buffers 所需的头文件。
60-63
: 更新pikiwidb
目标的依赖项此更改确保
pikiwidb
目标正确链接所需的库。
88-88
: 更新pikiwidb
目标的链接库此更改确保
pikiwidb
目标在链接过程中包含store_pb
库。src/pd/pd_server.h (2)
30-44
:PlacementDriverOptions
类定义良好此类定义了 Placement Driver 的选项,构造函数和 getter 方法都很合适,使用
std::move
有效地初始化字符串成员。
56-79
:PlacementDriverServer
类定义良好此类定义了 Placement Driver Server,包含初始化、启动、停止及管理 store 和 region ID 的方法。使用单例模式进行实例管理。
src/pd/pd_service.cc (2)
23-35
:AddStore
方法实现良好此方法添加一个 store 并根据操作成功与否设置响应,错误处理得当。
42-48
:GetClusterInfo
方法实现良好此方法检索集群信息并设置响应,适当使用了
ClosureGuard
。src/store.proto (19)
5-7
: 定义正确
StoreStatsRequest
消息的字段定义正确。
9-12
: 定义正确
StoreStatsResponse
消息的字段定义正确。
14-29
: 定义正确
StoreStats
消息的字段定义正确。
32-34
: 定义正确
RegionStatsRequest
消息的字段定义正确。
37-40
: 定义正确
RegionStatsResponse
消息的字段定义正确。
42-52
: 定义正确
RegionStats
消息的字段定义正确。
55-57
: 定义正确
DownPeers
消息的字段定义正确。
59-61
: 定义正确
PendingPeers
消息的字段定义正确。
63-68
: 定义正确
Peer
消息的字段定义正确。
70-75
: 定义正确
RegionOptions
消息的字段定义正确。
77-79
: 定义正确
InitRegionPeerRequest
消息的字段定义正确。
81-84
: 定义正确
InitRegionPeerResponse
消息的字段定义正确。
86-89
: 定义正确
AddRegionPeerRequest
消息的字段定义正确。
91-95
: 定义正确
AddRegionResponse
消息的字段定义正确。
97-99
: 定义正确
RemoveRegionPeerRequest
消息的字段定义正确。
102-106
: 定义正确
RemoveRegionPeerResponse
消息的字段定义正确。
108-110
: 定义正确
TransferLeaderRequest
消息的字段定义正确。
113-115
: 定义正确
TransferLeaderResponse
消息的字段定义正确。
117-129
: 定义正确
StoreService
服务的RPC方法定义正确。src/base_cmd.cc (3)
53-54
: 代码更改通过代码更改通过,使用
auto
关键字使代码更简洁。
55-69
: 添加了数据库后端检查添加了数据库后端检查,确保数据库存在。如果数据库不存在,并且命令不是
kCmdNameRaftCluster
,则返回错误信息。
70-78
: 修改了锁机制修改了锁机制,确保在命令执行后释放共享锁,改进了资源管理。
src/db.cc (6)
19-19
: 构造函数更改通过构造函数更改通过,使用
db_id
代替db_index
,符合新的命名约定。
21-21
: 析构函数更改通过析构函数更改通过,使用
db_id
记录数据库关闭日志,符合新的命名约定。
23-37
: 方法定义正确
Init
方法定义正确,尝试打开数据库并包含未来与PRaft
集成的注释代码。
Line range hint
63-78
:
方法定义正确
Open
方法定义正确,使用db_id
并改进日志记录,符合新的命名约定。
83-83
: 方法定义正确
CreateCheckpoint
方法定义正确,使用db_id
,符合新的命名约定。
Line range hint
99-154
:
方法定义正确
LoadDBFromCheckpoint
方法定义正确,使用db_id
并改进日志记录,符合新的命名约定。src/praft/praft.h (3)
144-144
: 请注意初始化逻辑的更改
IsInitialized
方法的逻辑已简化,现在仅检查node_
是否为空。这可能会影响PRaft
类的初始化逻辑,导致即使服务器未设置,类也被视为已初始化。请确保此更改不会在依赖此方法的代码部分引发问题。
169-169
: 更改成员变量类型以支持更大范围的值将
db_id_
成员变量的类型从int
更改为int64_t
,增加了可以容纳的值范围,这对于处理更大的标识符或数据库条目可能是必要的。
105-105
: 更改方法签名以提高性能将
group_id
参数类型从std::string&
更改为std::string&&
,允许方法更高效地接受临时字符串对象,启用移动语义以减少不必要的字符串数据复制。请确保所有对
Init
方法的调用都匹配新的签名。Verification successful
更改方法签名以提高性能
将
group_id
参数类型从std::string&
更改为std::string&&
,允许方法更高效地接受临时字符串对象,启用移动语义以减少不必要的字符串数据复制。所有对Init
方法的调用都已匹配新的签名。
src/cmd_raft.cc
中的调用:PRAFT.Init(std::move(cluster_id), false);
src/praft/praft.cc
中的调用:PRAFT.Init(std::move(raft_group_id), true);
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `Init` match the new signature. # Test: Search for the function usage. Expect: Only occurrences of the new signature. rg --type cpp -A 5 $'Init'Length of output: 100918
Script:
#!/bin/bash # Description: Verify all function calls to `PRaft::Init` match the new signature. # Search for the `Init` method implementation in the `PRaft` class. ast-grep --lang cpp --pattern $'class PRaft { $$$ butil::Status Init(std::string&& group_id, bool initial_conf_is_null); $$$ }' -A 10 # Search for calls to `PRaft::Init` to ensure they match the new signature. rg --type cpp 'PRAFT\.Init\(' -A 3Length of output: 685
src/config.h (5)
178-178
: 添加新的原子布尔变量as_pd
添加了新的原子布尔变量
as_pd
,可能用于管理与新 PD 功能相关的特定标志。
179-179
: 添加新的原子布尔变量fake
添加了新的原子布尔变量
fake
,可能用于管理与测试或模拟目的相关的特定标志。
180-180
: 添加新的原子字符串变量pd_group_id
添加了新的原子字符串变量
pd_group_id
,可能用于存储新 PD 功能的组 ID。
181-181
: 添加新的原子字符串变量pd_conf
添加了新的原子字符串变量
pd_conf
,可能用于存储新 PD 功能的配置详情。
182-182
: 添加新的原子整数变量request_timeout_ms
添加了新的原子整数变量
request_timeout_ms
,默认值为 1000 毫秒,用于设置请求的超时时间,这是管理请求持续时间的关键。src/pd/pd_server.cc (9)
20-23
: 单例模式实现
Instance
方法实现了PlacementDriverServer
类的单例模式,确保只创建一个类的实例。
25-28
: 析构函数实现
PlacementDriverServer
的析构函数记录一条消息并调用Stop
方法,确保对象销毁时服务器正确停止。
30-48
: 初始化方法实现
Init
方法初始化 PD 的数据库并处理独立部署。该方法包括错误处理和日志记录,确保正确初始化并为手动配置提供警告。
51-56
: 启动方法实现
Start
方法设置is_started_
标志,并包括一个 TODO 注释以供将来增强。目前,该方法仅设置标志,并为将来实现工作线程池预留了位置。请注意 TODO 注释,未来需要实现集群节点探索和元信息收集功能。
58-66
: 停止方法实现
Stop
方法重置is_started_
标志,并包括一个 TODO 注释以供将来增强。目前,该方法仅重置标志,并为将来实现相关线程池释放任务预留了位置。请注意 TODO 注释,未来需要实现相关线程池释放任务。
68-101
: 生成StoreID方法实现
GenerateStoreID
方法生成一个新的 store ID,确保原子性并处理错误。该方法包括锁机制、错误处理和日志记录,以确保正确的 ID 生成和存储。
103-136
: 生成RegionID方法实现
GenerateRegionID
方法生成一个新的 region ID,确保原子性并处理错误。该方法包括锁机制、错误处理和日志记录,以确保正确的 ID 生成和存储。
138-156
: 检查Store是否存在方法实现
CheckStoreExistByIP
方法通过 IP 地址检查 store 是否存在。该方法包括共享锁机制、错误处理和日志记录,以确保正确的存在性检查。
161-213
: 添加Store方法实现
AddStore
方法添加一个新的 store,确保原子性并处理错误。该方法包括检查存在性、生成新的 store ID,并使用锁机制、错误处理和日志记录更新 store 信息的步骤。CMakeLists.txt (1)
182-182
: 添加新子目录添加
src/pd
子目录以包含 PD 模块的构建配置。该更改是构建配置的一部分,确保新模块
src/pd
被正确包含在项目中。src/config.cc (1)
143-147
: 添加 PD 配置参数添加了与 PD 功能相关的配置参数,包括
as-pd
、pd-fake
、pd-group-id
、pd-conf
和request-timeout-ms
。这些更改增强了
PConfig
类的可配置性,允许用户在运行时指定与 PD 功能相关的参数。src/pikiwidb.cc (2)
162-162
: 请验证PSTORE.Init()
的更改是否影响功能。将
PSTORE.Init()
的调用从带参数改为无参数调用,可能会影响数据库配置的处理方式。请确保此更改不会对系统的整体功能产生负面影响。
285-285
: 请确认注释掉InitLimit()
的影响。注释掉
InitLimit()
可能会导致应用程序在启动时的行为发生变化。请确保此更改不会对系统的资源管理和运行时行为产生负面影响。src/store.cc (5)
37-59
: 请验证PStore::Init
方法的新逻辑。此方法的重构移除了
db_number
参数,并引入了新的逻辑来设置 RPC 服务器并将存储注册到 PD 服务器。请确保这些更改不会对系统的整体功能产生负面影响,并验证新逻辑的正确性。
63-109
: 请验证PStore::InitRpcServer
方法的新逻辑。此方法确保根据节点的角色(PD 或标准存储)正确配置服务器,并包括设置过程中的错误处理。请确保这些更改不会对系统的整体功能产生负面影响,并验证新逻辑的正确性。
111-183
: 请验证PStore::RegisterStoreToPDServer
方法的新逻辑。此方法允许存储将其配置注册到 PD 服务器,包括领导者选择的重试和注册过程中的错误处理。请确保这些更改不会对系统的整体功能产生负面影响,并验证新逻辑的正确性。
185-194
: 请验证PStore::GetBackend
方法的新逻辑。此方法使用互斥锁来确保线程安全,并确保对后端数据库实例的访问是同步的。请确保这些更改不会对系统的整体功能产生负面影响,并验证新逻辑的正确性。
196-205
: 请验证PStore::AddBackend
方法的新逻辑。此方法使用互斥锁来确保线程安全,并确保对后端数据库实例的访问是同步的。请确保这些更改不会对系统的整体功能产生负面影响,并验证新逻辑的正确性。
pikiwidb.conf (6)
346-346
: 请验证启用use-raft
的影响。将
use-raft
选项从no
更改为yes
,表示系统现在将使用 RAFT 共识算法。请确保此更改不会对系统的整体功能产生负面影响,并验证新逻辑的正确性。
350-350
: 请验证request-timeout-ms
配置项的影响。添加
request-timeout-ms
选项,值为1000
,可能设置请求的超时时间(以毫秒为单位)。请确保此更改不会对系统的整体功能产生负面影响,并验证新逻辑的正确性。
353-353
: 请验证启用as-pd
的影响。将
as-pd
选项从no
更改为yes
,表示系统现在将作为 PD 运行。请确保此更改不会对系统的整体功能产生负面影响,并验证新逻辑的正确性。
355-355
: 请验证pd-fake
配置项的影响。添加
pd-fake
选项,值为no
,表示部署不会使用假 PD 实例。请确保此更改不会对系统的整体功能产生负面影响,并验证新逻辑的正确性。
357-357
: 请验证pd-group-id
配置项的影响。添加
pd-group-id
选项,值为PikiwiDB
,为 PD 组建立了一个唯一标识符。请确保此更改不会对系统的整体功能产生负面影响,并验证新逻辑的正确性。
359-360
: 请验证pd-conf
配置项的影响。添加
pd-conf
选项,值为127.0.0.1:7787:0
,指定了 PD 的地址和端口。请确保此更改不会对系统的整体功能产生负面影响,并验证新逻辑的正确性。src/praft/praft.cc (7)
83-84
: 代码更改已批准。此处的更改没有问题。
87-87
: 代码更改已批准。函数签名更改为使用
std::move
提高了性能。
122-122
: 代码更改已批准。使用
std::move
进行赋值是一个很好的优化。
416-416
: 代码更改已批准。使用
std::move
进行传递是一个很好的优化。
148-148
: 请验证配置解析失败的处理逻辑。确保在配置解析失败时,系统能正确处理错误情况。
Verification successful
验证成功:
在配置解析失败时,系统会记录错误并返回状态,确保错误情况得到正确处理。
- 代码位置:
src/praft/praft.cc
第 148 行Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the handling of configuration parsing failure. # Test: Search for error handling after `parse_from` function. Expect: Proper error logging and handling. rg --type cpp -A 5 $'parse_from'Length of output: 374
164-166
: 请验证 Raft 节点初始化失败的处理逻辑。确保在 Raft 节点初始化失败时,系统能正确处理错误情况。
Verification successful
Raft 节点初始化失败的处理逻辑已正确实现。
在
src/praft/praft.cc
文件中,如果node_->init(node_options_)
失败,系统会记录错误并重置节点,表明错误处理逻辑已到位。
- 位置:
src/praft/praft.cc
, 行 164-166Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the handling of Raft node initialization failure. # Test: Search for error handling after `init` function. Expect: Proper error logging and handling. rg --type cpp -A 5 $'init'Length of output: 25962
576-578
: 请验证注释掉的服务器生命周期管理代码的影响。注释掉的服务器生命周期管理代码可能会影响系统的稳定性,请确保这些更改不会引入问题。
Also applies to: 587-589, 616-618
if (!HasFlag(kCmdFlagsExclusive)) { | ||
db->UnLockShared(); | ||
} | ||
}; | ||
} | ||
|
||
if (!DoInitial(client)) { |
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.
这里可以更新一下代码,有一个解决死锁的 pr。
|
||
// @todo | ||
// For now, create the shards with raft.cluster init | ||
auto db_id = client->GetCurrentDB(); | ||
auto status = PSTORE.AddBackend(db_id, "Pikiwidb"); | ||
if (!status.ok()) { | ||
return client->SetRes(CmdRes::kErrOther, fmt::format("Failed to init db: ", status.ToString())); | ||
} |
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.
兔子说的有道理
1、进展:在单 raft 的基础之上支持的 pd 模块,pd 按照独立部署的形式设计(混合部署等后续功能差不多了再支持),pd 和 普通节点都默认使用的是 PRAFT 和 db 0,目前能够完成 pd 初始化为一个单 raft group 之后,普通节点启动之后会主动上报注册(需要传入 pd 的成员配置信息)。
2、后续安排:
(1)把 multi-raft 的代码合并进来,完善整体的功能。
(2)目前 pd 文件夹下的 pd.proto 文件和 src 文件夹下的 store.proto 文件的 cmake 自动生成有点问题,还没来得及解决,需要大家帮忙一起看一下,在代码调试的时候我是直接手动生成的:
protoc --proto_path=./src --proto_path=./src/pd --cpp_out=./cmake-build-debug/generated_pd/ pd.proto
protoc --proto_path=./src --cpp_out=./cmake-build-debug/generated_pd/ store.proto
(3)添加测试,目前只是简单验证了正确性。
3、测试:
pd节点:默认端口为 7777,pikiwidb.conf 中 as-pd 设置为 yes
普通节点:默认端口为8888,pikiwidb.conf 中 as-pd 设置为 no
先启动 pd 节点,然后再启动普通节点。
Summary by CodeRabbit
新功能
修复
文档
重构