12
12
#include < braft/file_system_adaptor.h>
13
13
14
14
#include < cstdint>
15
+ #include < string>
15
16
16
17
namespace curve {
17
18
namespace chunkserver {
@@ -24,7 +25,10 @@ using SnapshotID = uint64_t;
24
25
using SequenceNum = uint64_t ;
25
26
26
27
using ChunkSizeType = uint32_t ;
27
- using PageSizeType = uint32_t ;
28
+ using PageSizeType = uint32_t ;
29
+
30
+ using GroupNid = uint64_t ;
31
+ using ChunkServerID = uint32_t ;
28
32
29
33
// braft
30
34
using Configuration = braft::Configuration;
@@ -36,6 +40,51 @@ using FileSystemAdaptor = braft::FileSystemAdaptor;
36
40
using DirReader = braft::DirReader;
37
41
using PosixFileSystemAdaptor = braft::PosixFileSystemAdaptor;
38
42
43
+ /* *
44
+ * 将(LogicPoolID, CopysetID)二元组转换成数字格式的复制组ID,格式如下:
45
+ * | group id |
46
+ * | 32 | 32 |
47
+ * | logic pool id | copyset id |
48
+ */
49
+ inline GroupNid ToGroupNid (const LogicPoolID &logicPoolId,
50
+ const CopysetID ©setId) {
51
+ return (static_cast <uint64_t >(logicPoolId) << 32 ) | copysetId;
52
+ }
53
+ /* *
54
+ * 将(LogicPoolID, CopysetID)二元组转换成字符串格式的复制组ID
55
+ */
56
+ inline GroupId ToGroupId (const LogicPoolID &logicPoolId,
57
+ const CopysetID ©setId) {
58
+ return std::to_string (ToGroupNid (logicPoolId, copysetId));
59
+ }
60
+ #define ToBraftGroupId ToGroupId
61
+
62
+ /* *
63
+ * 从数字格式的复制组ID中解析LogicPoolID
64
+ */
65
+ inline LogicPoolID GetPoolID (const GroupNid &groupId) {
66
+ return groupId >> 32 ;
67
+ }
68
+ /* *
69
+ * 从数字格式的复制组ID中解析CopysetID
70
+ */
71
+ inline CopysetID GetCopysetID (const GroupNid &groupId) {
72
+ return groupId & (((uint64_t )1 << 32 ) - 1 );
73
+ }
74
+
75
+ /* 格式输出 group id 的 字符串 (logicPoolId, copysetId) */
76
+ inline std::string ToGroupIdString (const LogicPoolID &logicPoolId,
77
+ const CopysetID ©setId) {
78
+ std::string groupIdString;
79
+ groupIdString.append (" (" );
80
+ groupIdString.append (std::to_string (logicPoolId));
81
+ groupIdString.append (" , " );
82
+ groupIdString.append (std::to_string (copysetId));
83
+ groupIdString.append (" )" );
84
+ return groupIdString;
85
+ }
86
+ #define ToGroupIdStr ToGroupIdString
87
+
39
88
} // namespace chunkserver
40
89
} // namespace curve
41
90
0 commit comments