Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8b5d005d
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8b5d005d
编写于
10月 27, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): add SyncLocalCmd
上级
bbb624b6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
157 addition
and
2 deletion
+157
-2
include/common/tmsgdef.h
include/common/tmsgdef.h
+1
-0
include/libs/sync/syncTools.h
include/libs/sync/syncTools.h
+6
-2
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+150
-0
未找到文件。
include/common/tmsgdef.h
浏览文件 @
8b5d005d
...
...
@@ -269,6 +269,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_SYNC_SET_VNODE_STANDBY
,
"set-vnode-standby"
,
NULL
,
NULL
)
// no longer used
TD_DEF_MSG_TYPE
(
TDMT_SYNC_HEARTBEAT
,
"sync-heartbeat"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_HEARTBEAT_REPLY
,
"sync-heartbeat-reply"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_LOCAL_CMD
,
"sync-local-cmd"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_MAX_MSG
,
"sync-max"
,
NULL
,
NULL
)
#if defined(TD_MSG_NUMBER_)
...
...
include/libs/sync/syncTools.h
浏览文件 @
8b5d005d
...
...
@@ -679,6 +679,10 @@ void syncReconfigFinishLog(const SyncReconfigFinish* pMsg);
void
syncReconfigFinishLog2
(
char
*
s
,
const
SyncReconfigFinish
*
pMsg
);
// ---------------------------------------------
typedef
enum
{
SYNC_STEP_DOWN
=
0
,
}
ESyncLocalCmd
;
typedef
struct
SyncLocalCmd
{
uint32_t
bytes
;
int32_t
vgId
;
...
...
@@ -686,8 +690,8 @@ typedef struct SyncLocalCmd {
SRaftId
srcId
;
SRaftId
destId
;
int
8_t
cmd
;
SyncTerm
sdNewTerm
// step down new term
int
32_t
cmd
;
SyncTerm
sdNewTerm
;
// step down new term
}
SyncLocalCmd
;
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
8b5d005d
...
...
@@ -3095,3 +3095,153 @@ void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) {
taosMemoryFree
(
serialized
);
}
}
// ---------------------------------------------
SyncLocalCmd
*
syncLocalCmdBuild
(
uint32_t
dataLen
,
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncLocalCmd
);
SyncLocalCmd
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
vgId
=
vgId
;
pMsg
->
msgType
=
TDMT_SYNC_LOCAL_CMD
;
return
pMsg
;
}
void
syncLocalCmdDestroy
(
SyncLocalCmd
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncLocalCmdSerialize
(
const
SyncLocalCmd
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
ASSERT
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncLocalCmdDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncLocalCmd
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
}
char
*
syncLocalCmdSerialize2
(
const
SyncLocalCmd
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
ASSERT
(
buf
!=
NULL
);
syncLocalCmdSerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncLocalCmd
*
syncLocalCmdDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncLocalCmd
*
pMsg
=
taosMemoryMalloc
(
bytes
);
ASSERT
(
pMsg
!=
NULL
);
syncLocalCmdDeserialize
(
buf
,
len
,
pMsg
);
ASSERT
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncLocalCmd2RpcMsg
(
const
SyncLocalCmd
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncLocalCmdSerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
void
syncLocalCmdFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncLocalCmd
*
pMsg
)
{
syncLocalCmdDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncLocalCmd
*
syncLocalCmdFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncLocalCmd
*
pMsg
=
syncLocalCmdDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
ASSERT
(
pMsg
!=
NULL
);
return
pMsg
;
}
cJSON
*
syncLocalCmd2Json
(
const
SyncLocalCmd
*
pMsg
)
{
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pMsg
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pMsg
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"vgId"
,
pMsg
->
vgId
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pMsg
->
msgType
);
cJSON
*
pSrcId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
srcId
.
addr
);
cJSON_AddStringToObject
(
pSrcId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
srcId
.
addr
;
cJSON
*
pTmp
=
pSrcId
;
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
cJSON_AddNumberToObject
(
pSrcId
,
"vgId"
,
pMsg
->
srcId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"srcId"
,
pSrcId
);
cJSON
*
pDestId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
destId
.
addr
);
cJSON_AddStringToObject
(
pDestId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
destId
.
addr
;
cJSON
*
pTmp
=
pDestId
;
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
cJSON_AddNumberToObject
(
pDestId
,
"vgId"
,
pMsg
->
destId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"destId"
,
pDestId
);
cJSON_AddNumberToObject
(
pRoot
,
"cmd"
,
pMsg
->
cmd
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
sdNewTerm
);
cJSON_AddStringToObject
(
pRoot
,
"sd-new-term"
,
u64buf
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncSnapshotRsp"
,
pRoot
);
return
pJson
;
}
char
*
syncLocalCmd2Str
(
const
SyncLocalCmd
*
pMsg
)
{
cJSON
*
pJson
=
syncLocalCmd2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
// for debug ----------------------
void
syncLocalCmdPrint
(
const
SyncLocalCmd
*
pMsg
)
{
char
*
serialized
=
syncLocalCmd2Str
(
pMsg
);
printf
(
"syncLocalCmdPrint | len:%d | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncLocalCmdPrint2
(
char
*
s
,
const
SyncLocalCmd
*
pMsg
)
{
char
*
serialized
=
syncLocalCmd2Str
(
pMsg
);
printf
(
"syncLocalCmdPrint2 | len:%d | %s | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncLocalCmdLog
(
const
SyncLocalCmd
*
pMsg
)
{
char
*
serialized
=
syncLocalCmd2Str
(
pMsg
);
sTrace
(
"syncLocalCmdLog | len:%d | %s"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
}
void
syncLocalCmdLog2
(
char
*
s
,
const
SyncLocalCmd
*
pMsg
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
syncLocalCmd2Str
(
pMsg
);
sTrace
(
"syncLocalCmdLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录