Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a82d594a
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
a82d594a
编写于
11月 19, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-2157
上级
2171bf7a
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
71 addition
and
36 deletion
+71
-36
src/inc/tsync.h
src/inc/tsync.h
+9
-9
src/sync/inc/syncInt.h
src/sync/inc/syncInt.h
+17
-13
src/sync/src/syncMain.c
src/sync/src/syncMain.c
+45
-14
未找到文件。
src/inc/tsync.h
浏览文件 @
a82d594a
...
...
@@ -24,18 +24,18 @@ extern "C" {
#define TAOS_SYNC_MAX_INDEX 0x7FFFFFFF
typedef
enum
_TAOS_SYNC_ROLE
{
TAOS_SYNC_ROLE_OFFLINE
,
TAOS_SYNC_ROLE_UNSYNCED
,
TAOS_SYNC_ROLE_SYNCING
,
TAOS_SYNC_ROLE_SLAVE
,
TAOS_SYNC_ROLE_MASTER
,
TAOS_SYNC_ROLE_OFFLINE
=
0
,
TAOS_SYNC_ROLE_UNSYNCED
=
1
,
TAOS_SYNC_ROLE_SYNCING
=
2
,
TAOS_SYNC_ROLE_SLAVE
=
3
,
TAOS_SYNC_ROLE_MASTER
=
4
}
ESyncRole
;
typedef
enum
_TAOS_SYNC_STATUS
{
TAOS_SYNC_STATUS_INIT
,
TAOS_SYNC_STATUS_START
,
TAOS_SYNC_STATUS_FILE
,
TAOS_SYNC_STATUS_CACHE
,
TAOS_SYNC_STATUS_INIT
=
0
,
TAOS_SYNC_STATUS_START
=
1
,
TAOS_SYNC_STATUS_FILE
=
2
,
TAOS_SYNC_STATUS_CACHE
=
3
}
ESyncStatus
;
typedef
struct
{
...
...
src/sync/inc/syncInt.h
浏览文件 @
a82d594a
...
...
@@ -27,16 +27,20 @@ extern "C" {
#define sDebug(...) { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); }}
#define sTrace(...) { if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); }}
#define TAOS_SMSG_SYNC_DATA 1
#define TAOS_SMSG_FORWARD 2
#define TAOS_SMSG_FORWARD_RSP 3
#define TAOS_SMSG_SYNC_REQ 4
#define TAOS_SMSG_SYNC_RSP 5
#define TAOS_SMSG_SYNC_MUST 6
#define TAOS_SMSG_STATUS 7
typedef
enum
{
TAOS_SMSG_SYNC_DATA
=
1
,
TAOS_SMSG_FORWARD
=
2
,
TAOS_SMSG_FORWARD_RSP
=
3
,
TAOS_SMSG_SYNC_REQ
=
4
,
TAOS_SMSG_SYNC_RSP
=
5
,
TAOS_SMSG_SYNC_MUST
=
6
,
TAOS_SMSG_STATUS
=
7
}
ESyncMsgType
;
#define SYNC_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead) + sizeof(SSyncHead) + 16)
#define SYNC_RECV_BUFFER_SIZE (5*1024*1024)
#define SYNC_FWD_TIMER 300
#define SYNC_ROLE_TIMER 10000
#define nodeRole pNode->peerInfo[pNode->selfIndex]->role
#define nodeVersion pNode->peerInfo[pNode->selfIndex]->version
...
...
@@ -123,10 +127,10 @@ typedef struct SsyncPeer {
int32_t
nodeId
;
uint32_t
ip
;
uint16_t
port
;
char
fqdn
[
TSDB_FQDN_LEN
];
// peer ip string
char
id
[
TSDB_EP_LEN
+
32
];
// peer vgId + end point
int8_t
role
;
int8_t
sstatus
;
// sync status
char
fqdn
[
TSDB_FQDN_LEN
];
// peer ip string
char
id
[
TSDB_EP_LEN
+
32
];
// peer vgId + end point
uint64_t
version
;
uint64_t
sversion
;
// track the peer version in retrieve process
int32_t
syncFd
;
...
...
@@ -138,7 +142,7 @@ typedef struct SsyncPeer {
int32_t
notifyFd
;
int32_t
watchNum
;
int32_t
*
watchFd
;
int
8_t
refCount
;
// reference count
int
32_t
refCount
;
// reference count
struct
SSyncNode
*
pSyncNode
;
}
SSyncPeer
;
...
...
@@ -146,16 +150,16 @@ typedef struct SSyncNode {
char
path
[
TSDB_FILENAME_LEN
];
int8_t
replica
;
int8_t
quorum
;
int8_t
selfIndex
;
uint32_t
vgId
;
int64_t
rid
;
void
*
ahandle
;
int8_t
selfIndex
;
SSyncPeer
*
peerInfo
[
TAOS_SYNC_MAX_REPLICA
+
1
];
// extra one for arbitrator
SSyncPeer
*
pMaster
;
int8_t
refCount
;
SRecvBuffer
*
pRecv
;
SSyncFwds
*
pSyncFwds
;
// saved forward info if quorum >1
void
*
pFwdTimer
;
void
*
pRoleTimer
;
FGetFileInfo
getFileInfo
;
FGetWalInfo
getWalInfo
;
FWriteToCache
writeToCache
;
...
...
src/sync/src/syncMain.c
浏览文件 @
a82d594a
...
...
@@ -59,6 +59,7 @@ static void syncAddArbitrator(SSyncNode *pNode);
static
void
syncFreeNode
(
void
*
);
static
void
syncRemoveConfirmedFwdInfo
(
SSyncNode
*
pNode
);
static
void
syncMonitorFwdInfos
(
void
*
param
,
void
*
tmrId
);
static
void
syncMonitorNodeRole
(
void
*
param
,
void
*
tmrId
);
static
void
syncProcessFwdAck
(
SSyncNode
*
pNode
,
SFwdInfo
*
pFwdInfo
,
int32_t
code
);
static
void
syncSaveFwdInfo
(
SSyncNode
*
pNode
,
uint64_t
version
,
void
*
mhandle
);
static
void
syncRestartPeer
(
SSyncPeer
*
pPeer
);
...
...
@@ -79,7 +80,9 @@ typedef enum {
SYNC_STATUS_SETUP_CONN
,
SYNC_STATUS_SETUP_CONN_RSP
,
SYNC_STATUS_EXCHANGE_DATA
,
SYNC_STATUS_EXCHANGE_DATA_RSP
SYNC_STATUS_EXCHANGE_DATA_RSP
,
SYNC_STATUS_CHECK_ROLE
,
SYNC_STATUS_CHECK_ROLE_RSP
}
ESyncStatusType
;
char
*
statusType
[]
=
{
...
...
@@ -88,7 +91,9 @@ char *statusType[] = {
"setup-conn"
,
"setup-conn-rsp"
,
"exchange-data"
,
"exchange-data-rsp"
"exchange-data-rsp"
,
"check-role"
,
"check-role-rsp"
};
uint16_t
syncGenTranId
()
{
...
...
@@ -233,9 +238,16 @@ int64_t syncStart(const SSyncInfo *pInfo) {
return
-
1
;
}
pNode
->
pFwdTimer
=
taosTmrStart
(
syncMonitorFwdInfos
,
300
,
(
void
*
)
pNode
->
rid
,
tsSyncTmrCtrl
);
pNode
->
pFwdTimer
=
taosTmrStart
(
syncMonitorFwdInfos
,
SYNC_FWD_TIMER
,
(
void
*
)
pNode
->
rid
,
tsSyncTmrCtrl
);
if
(
pNode
->
pFwdTimer
==
NULL
)
{
sError
(
"vgId:%d, failed to allocate timer"
,
pNode
->
vgId
);
sError
(
"vgId:%d, failed to allocate fwd timer"
,
pNode
->
vgId
);
syncStop
(
pNode
->
rid
);
return
-
1
;
}
pNode
->
pRoleTimer
=
taosTmrStart
(
syncMonitorNodeRole
,
SYNC_ROLE_TIMER
,
(
void
*
)
pNode
->
rid
,
tsSyncTmrCtrl
);
if
(
pNode
->
pRoleTimer
==
NULL
)
{
sError
(
"vgId:%d, failed to allocate role timer"
,
pNode
->
vgId
);
syncStop
(
pNode
->
rid
);
return
-
1
;
}
...
...
@@ -262,6 +274,7 @@ void syncStop(int64_t rid) {
if
(
tsVgIdHash
)
taosHashRemove
(
tsVgIdHash
,
(
const
char
*
)
&
pNode
->
vgId
,
sizeof
(
int32_t
));
if
(
pNode
->
pFwdTimer
)
taosTmrStop
(
pNode
->
pFwdTimer
);
if
(
pNode
->
pRoleTimer
)
taosTmrStop
(
pNode
->
pRoleTimer
);
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
pPeer
=
pNode
->
peerInfo
[
i
];
...
...
@@ -471,10 +484,10 @@ static void syncFreeNode(void *param) {
tfree
(
pNode
);
}
void
syncAddPeerRef
(
SSyncPeer
*
pPeer
)
{
atomic_add_fetch_
8
(
&
pPeer
->
refCount
,
1
);
}
void
syncAddPeerRef
(
SSyncPeer
*
pPeer
)
{
atomic_add_fetch_
32
(
&
pPeer
->
refCount
,
1
);
}
int32_t
syncDecPeerRef
(
SSyncPeer
*
pPeer
)
{
if
(
atomic_sub_fetch_
8
(
&
pPeer
->
refCount
,
1
)
==
0
)
{
if
(
atomic_sub_fetch_
32
(
&
pPeer
->
refCount
,
1
)
==
0
)
{
taosReleaseRef
(
tsSyncRefId
,
pPeer
->
pSyncNode
->
rid
);
sDebug
(
"%s, resource is freed"
,
pPeer
->
id
);
...
...
@@ -699,20 +712,20 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus* peersStatus, int8_t new
int8_t
syncRequired
=
0
;
pPeer
->
role
=
newPeerRole
;
s
Trace
(
"%s, peer role:%s change to %s"
,
pPeer
->
id
,
syncRole
[
oldPeerRole
],
syncRole
[
newPeerRole
]);
s
Debug
(
"%s, peer role:%s change to %s"
,
pPeer
->
id
,
syncRole
[
oldPeerRole
],
syncRole
[
newPeerRole
]);
SSyncPeer
*
pMaster
=
syncCheckMaster
(
pNode
);
if
(
pMaster
)
{
// master is there
pNode
->
pMaster
=
pMaster
;
s
Trace
(
"%s, it is the master, sver:%"
PRIu64
,
pMaster
->
id
,
pMaster
->
version
);
s
Debug
(
"%s, it is the master, sver:%"
PRIu64
,
pMaster
->
id
,
pMaster
->
version
);
if
(
syncValidateMaster
(
pPeer
)
<
0
)
return
;
if
(
nodeRole
==
TAOS_SYNC_ROLE_UNSYNCED
)
{
if
(
nodeVersion
<
pMaster
->
version
)
{
s
Trace
(
"%s, is master, sync required, self sver:%"
PRIu64
,
pMaster
->
id
,
nodeVersion
);
s
Debug
(
"%s, is master, sync required, self sver:%"
PRIu64
,
pMaster
->
id
,
nodeVersion
);
syncRequired
=
1
;
}
else
{
sInfo
(
"%s, is master, work as slave, self sver:%"
PRIu64
,
pMaster
->
id
,
nodeVersion
);
...
...
@@ -720,7 +733,7 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus* peersStatus, int8_t new
(
*
pNode
->
notifyRole
)(
pNode
->
ahandle
,
nodeRole
);
}
}
else
if
(
nodeRole
==
TAOS_SYNC_ROLE_SLAVE
&&
pMaster
==
pPeer
)
{
s
Trace
(
"%s, is master, continue work as slave, self sver:%"
PRIu64
,
pMaster
->
id
,
nodeVersion
);
s
Debug
(
"%s, is master, continue work as slave, self sver:%"
PRIu64
,
pMaster
->
id
,
nodeVersion
);
}
}
else
{
// master not there, if all peer's state and version are consistent, choose the master
...
...
@@ -739,10 +752,10 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus* peersStatus, int8_t new
}
if
(
consistent
)
{
s
Trace
(
"vgId:%d, choose master"
,
pNode
->
vgId
);
s
Debug
(
"vgId:%d, choose master"
,
pNode
->
vgId
);
syncChooseMaster
(
pNode
);
}
else
{
s
Trace
(
"vgId:%d, version inconsistent, cannot choose master"
,
pNode
->
vgId
);
s
Debug
(
"vgId:%d, version inconsistent, cannot choose master"
,
pNode
->
vgId
);
}
}
...
...
@@ -1221,8 +1234,26 @@ static void syncProcessFwdAck(SSyncNode *pNode, SFwdInfo *pFwdInfo, int32_t code
}
}
static
void
syncMonitorNodeRole
(
void
*
param
,
void
*
tmrId
)
{
int64_t
rid
=
(
int64_t
)
param
;
SSyncNode
*
pNode
=
taosAcquireRef
(
tsSyncRefId
,
rid
);
if
(
pNode
==
NULL
)
return
;
for
(
int32_t
index
=
0
;
index
<
pNode
->
replica
;
index
++
)
{
if
(
index
==
pNode
->
selfIndex
)
continue
;
SSyncPeer
*
pPeer
=
pNode
->
peerInfo
[
index
];
if
(
pPeer
->
role
<=
TAOS_SYNC_ROLE_UNSYNCED
||
nodeRole
<=
TAOS_SYNC_ROLE_UNSYNCED
)
{
syncSendPeersStatusMsgToPeer
(
pPeer
,
1
,
SYNC_STATUS_CHECK_ROLE
,
syncGenTranId
());
}
}
pNode
->
pRoleTimer
=
taosTmrStart
(
syncMonitorNodeRole
,
SYNC_ROLE_TIMER
,
(
void
*
)
pNode
->
rid
,
tsSyncTmrCtrl
);
taosReleaseRef
(
tsSyncRefId
,
rid
);
}
static
void
syncMonitorFwdInfos
(
void
*
param
,
void
*
tmrId
)
{
int64_t
rid
=
(
int64_t
)
param
;
int64_t
rid
=
(
int64_t
)
param
;
SSyncNode
*
pNode
=
taosAcquireRef
(
tsSyncRefId
,
rid
);
if
(
pNode
==
NULL
)
return
;
...
...
@@ -1246,7 +1277,7 @@ static void syncMonitorFwdInfos(void *param, void *tmrId) {
pthread_mutex_unlock
(
&
(
pNode
->
mutex
));
}
pNode
->
pFwdTimer
=
taosTmrStart
(
syncMonitorFwdInfos
,
300
,
(
void
*
)
pNode
->
rid
,
tsSyncTmrCtrl
);
pNode
->
pFwdTimer
=
taosTmrStart
(
syncMonitorFwdInfos
,
SYNC_FWD_TIMER
,
(
void
*
)
pNode
->
rid
,
tsSyncTmrCtrl
);
}
taosReleaseRef
(
tsSyncRefId
,
rid
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录