Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d083c797
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d083c797
编写于
3月 09, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync refactor
上级
3dfb9bb0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
69 addition
and
2 deletion
+69
-2
source/libs/sync/inc/syncRaftEntry.h
source/libs/sync/inc/syncRaftEntry.h
+8
-0
source/libs/sync/src/syncRaftEntry.c
source/libs/sync/src/syncRaftEntry.c
+61
-2
未找到文件。
source/libs/sync/inc/syncRaftEntry.h
浏览文件 @
d083c797
...
...
@@ -39,8 +39,16 @@ typedef struct SSyncRaftEntry {
char
data
[];
}
SSyncRaftEntry
;
#define SYNC_ENTRY_FIX_LEN \
(sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint64_t) + sizeof(bool) + sizeof(SyncTerm) + \
sizeof(SyncIndex) + sizeof(uint32_t))
SSyncRaftEntry
*
syncEntryBuild
(
SyncClientRequest
*
pMsg
,
SyncTerm
term
,
SyncIndex
index
);
void
syncEntryDestory
(
SSyncRaftEntry
*
pEntry
);
void
syncEntrySerialize
(
const
SSyncRaftEntry
*
pEntry
,
char
*
buf
,
uint32_t
bufLen
);
void
syncEntryDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SSyncRaftEntry
*
pEntry
);
cJSON
*
syncEntry2Json
(
const
SSyncRaftEntry
*
pEntry
);
char
*
syncEntry2Str
(
const
SSyncRaftEntry
*
pEntry
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncRaftEntry.c
浏览文件 @
d083c797
...
...
@@ -15,6 +15,65 @@
#include "syncRaftEntry.h"
SSyncRaftEntry
*
syncEntryBuild
(
SyncClientRequest
*
pMsg
,
SyncTerm
term
,
SyncIndex
index
)
{}
SSyncRaftEntry
*
syncEntryBuild
(
SyncClientRequest
*
pMsg
,
SyncTerm
term
,
SyncIndex
index
)
{
uint32_t
bytes
=
SYNC_ENTRY_FIX_LEN
+
pMsg
->
bytes
;
SSyncRaftEntry
*
pEntry
=
malloc
(
bytes
);
assert
(
pEntry
!=
NULL
);
memset
(
pEntry
,
0
,
bytes
);
void
syncEntryDestory
(
SSyncRaftEntry
*
pEntry
)
{}
\ No newline at end of file
pEntry
->
bytes
=
bytes
;
pEntry
->
msgType
=
pMsg
->
msgType
;
pEntry
->
originalRpcType
=
pMsg
->
originalRpcType
;
pEntry
->
seqNum
=
pMsg
->
seqNum
;
pEntry
->
isWeak
=
pMsg
->
isWeak
;
pEntry
->
term
=
term
;
pEntry
->
index
=
index
;
pEntry
->
dataLen
=
pMsg
->
dataLen
;
memcpy
(
pEntry
->
data
,
pMsg
->
data
,
pMsg
->
dataLen
);
return
pEntry
;
}
void
syncEntryDestory
(
SSyncRaftEntry
*
pEntry
)
{
if
(
pEntry
!=
NULL
)
{
free
(
pEntry
);
}
}
void
syncEntrySerialize
(
const
SSyncRaftEntry
*
pEntry
,
char
*
buf
,
uint32_t
bufLen
)
{
assert
(
pEntry
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pEntry
,
pEntry
->
bytes
);
}
void
syncEntryDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SSyncRaftEntry
*
pEntry
)
{
memcpy
(
pEntry
,
buf
,
len
);
assert
(
len
==
pEntry
->
bytes
);
}
cJSON
*
syncEntry2Json
(
const
SSyncRaftEntry
*
pEntry
)
{
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pEntry
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pEntry
->
msgType
);
cJSON_AddNumberToObject
(
pRoot
,
"originalRpcType"
,
pEntry
->
originalRpcType
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pEntry
->
seqNum
);
cJSON_AddStringToObject
(
pRoot
,
"seqNum"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"isWeak"
,
pEntry
->
isWeak
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pEntry
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pEntry
->
index
);
cJSON_AddStringToObject
(
pRoot
,
"index"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"dataLen"
,
pEntry
->
dataLen
);
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SSyncRaftEntry"
,
pRoot
);
return
pJson
;
}
char
*
syncEntry2Str
(
const
SSyncRaftEntry
*
pEntry
)
{
cJSON
*
pJson
=
syncEntry2Json
(
pEntry
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录