Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
adminstrot
TDengine
提交
4069969a
TDengine
项目概览
adminstrot
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4069969a
编写于
12月 17, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-1927
上级
8d110d84
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
32 deletion
+27
-32
src/inc/tsync.h
src/inc/tsync.h
+0
-4
src/sync/inc/syncInt.h
src/sync/inc/syncInt.h
+9
-3
src/sync/src/syncMain.c
src/sync/src/syncMain.c
+18
-25
未找到文件。
src/inc/tsync.h
浏览文件 @
4069969a
...
...
@@ -119,10 +119,6 @@ int32_t syncGetNodesRole(int64_t rid, SNodesRole *);
extern
char
*
syncRole
[];
//global configurable parameters
extern
int32_t
tsMaxSyncNum
;
extern
int32_t
tsSyncTcpThreads
;
extern
int32_t
tsSyncTimer
;
extern
int32_t
tsMaxFwdInfo
;
extern
int32_t
sDebugFlag
;
extern
char
tsArbitrator
[];
extern
uint16_t
tsSyncPort
;
...
...
src/sync/inc/syncInt.h
浏览文件 @
4069969a
...
...
@@ -29,11 +29,17 @@ 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 SYNC_TCP_THREADS 2
#define SYNC_MAX_NUM 2
#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 SYNC_WAIT_AFTER_CHOOSE_MASTER 3
#define SYNC_MAX_FWDS 512
#define SYNC_FWD_TIMER 300
#define SYNC_ROLE_TIMER 15000 // ms
#define SYNC_CHECK_INTERVAL 1 // ms
#define SYNC_WAIT_AFTER_CHOOSE_MASTER 10 // ms
#define nodeRole pNode->peerInfo[pNode->selfIndex]->role
#define nodeVersion pNode->peerInfo[pNode->selfIndex]->version
...
...
src/sync/src/syncMain.c
浏览文件 @
4069969a
...
...
@@ -29,19 +29,12 @@
#include "syncTcp.h"
#include "syncInt.h"
// global configurable
int32_t
tsMaxSyncNum
=
2
;
int32_t
tsSyncTcpThreads
=
2
;
int32_t
tsMaxFwdInfo
=
512
;
int32_t
tsSyncTimer
=
1
;
int32_t
tsSyncNum
=
0
;
// number of sync in process in whole system
char
tsNodeFqdn
[
TSDB_FQDN_LEN
]
=
{
0
};
// module global, not configurable
int32_t
tsSyncNum
;
// number of sync in process in whole system
char
tsNodeFqdn
[
TSDB_FQDN_LEN
];
static
void
*
tsTcpPool
;
static
void
*
tsTcpPool
=
NULL
;
static
void
*
tsSyncTmrCtrl
=
NULL
;
static
void
*
tsVgIdHash
;
static
void
*
tsVgIdHash
=
NULL
;
static
int32_t
tsSyncRefId
=
-
1
;
// local functions
...
...
@@ -83,7 +76,7 @@ char *syncStatus[] = {
int32_t
syncInit
()
{
SPoolInfo
info
=
{
0
};
info
.
numOfThreads
=
tsSyncTcpThreads
;
info
.
numOfThreads
=
SYNC_TCP_THREADS
;
info
.
serverIp
=
0
;
info
.
port
=
tsSyncPort
;
info
.
bufferSize
=
SYNC_MAX_SIZE
;
...
...
@@ -107,7 +100,7 @@ int32_t syncInit() {
tsVgIdHash
=
taosHashInit
(
TSDB_MIN_VNODES
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
HASH_ENTRY_LOCK
);
if
(
tsVgIdHash
==
NULL
)
{
sError
(
"failed to init
tsV
gIdHash"
);
sError
(
"failed to init
v
gIdHash"
);
taosTmrCleanUp
(
tsSyncTmrCtrl
);
syncCloseTcpThreadPool
(
tsTcpPool
);
tsTcpPool
=
NULL
;
...
...
@@ -210,7 +203,7 @@ int64_t syncStart(const SSyncInfo *pInfo) {
sInfo
(
"vgId:%d, %d replicas are configured, quorum:%d role:%s"
,
pNode
->
vgId
,
pNode
->
replica
,
pNode
->
quorum
,
syncRole
[
nodeRole
]);
pNode
->
pSyncFwds
=
calloc
(
sizeof
(
SSyncFwds
)
+
tsMaxFwdInfo
*
sizeof
(
SFwdInfo
),
1
);
pNode
->
pSyncFwds
=
calloc
(
sizeof
(
SSyncFwds
)
+
SYNC_MAX_FWDS
*
sizeof
(
SFwdInfo
),
1
);
if
(
pNode
->
pSyncFwds
==
NULL
)
{
sError
(
"vgId:%d, no memory to allocate syncFwds"
,
pNode
->
vgId
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
...
...
@@ -750,7 +743,7 @@ static void syncRestartPeer(SSyncPeer *pPeer) {
int32_t
ret
=
strcmp
(
pPeer
->
fqdn
,
tsNodeFqdn
);
if
(
ret
>
0
||
(
ret
==
0
&&
pPeer
->
port
>
tsSyncPort
))
{
sDebug
(
"%s, check peer connection in 1000 ms"
,
pPeer
->
id
);
taosTmrReset
(
syncCheckPeerConnection
,
tsSyncTimer
*
1000
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
taosTmrReset
(
syncCheckPeerConnection
,
SYNC_CHECK_INTERVAL
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
}
}
...
...
@@ -828,7 +821,7 @@ static void syncRecoverFromMaster(SSyncPeer *pPeer) {
taosTmrStopA
(
&
pPeer
->
timer
);
// Ensure the sync of mnode not interrupted
if
(
pNode
->
vgId
!=
1
&&
tsSyncNum
>=
tsMaxSyncNum
)
{
if
(
pNode
->
vgId
!=
1
&&
tsSyncNum
>=
SYNC_MAX_NUM
)
{
sInfo
(
"%s, %d syncs are in process, try later"
,
pPeer
->
id
,
tsSyncNum
);
taosTmrReset
(
syncTryRecoverFromMaster
,
500
+
(
pNode
->
vgId
*
10
)
%
200
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
return
;
...
...
@@ -839,7 +832,7 @@ static void syncRecoverFromMaster(SSyncPeer *pPeer) {
SSyncMsg
msg
;
syncBuildSyncReqMsg
(
&
msg
,
pNode
->
vgId
);
taosTmrReset
(
syncNotStarted
,
tsSyncTimer
*
1000
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
taosTmrReset
(
syncNotStarted
,
SYNC_CHECK_INTERVAL
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
if
(
taosWriteMsg
(
pPeer
->
peerFd
,
&
msg
,
sizeof
(
SSyncMsg
))
!=
sizeof
(
SSyncMsg
))
{
sError
(
"%s, failed to send sync-req to peer"
,
pPeer
->
id
);
...
...
@@ -859,7 +852,7 @@ static void syncProcessFwdResponse(SFwdRsp *pFwdRsp, SSyncPeer *pPeer) {
if
(
pFirst
->
version
<=
pFwdRsp
->
version
&&
pSyncFwds
->
fwds
>
0
)
{
// find the forwardInfo from first
for
(
int32_t
i
=
0
;
i
<
pSyncFwds
->
fwds
;
++
i
)
{
pFwdInfo
=
pSyncFwds
->
fwdInfo
+
(
i
+
pSyncFwds
->
first
)
%
tsMaxFwdInfo
;
pFwdInfo
=
pSyncFwds
->
fwdInfo
+
(
i
+
pSyncFwds
->
first
)
%
SYNC_MAX_FWDS
;
if
(
pFwdRsp
->
version
==
pFwdInfo
->
version
)
{
syncProcessFwdAck
(
pNode
,
pFwdInfo
,
pFwdRsp
->
code
);
syncRemoveConfirmedFwdInfo
(
pNode
);
...
...
@@ -995,7 +988,7 @@ static void syncSetupPeerConnection(SSyncPeer *pPeer) {
int32_t
connFd
=
taosOpenTcpClientSocket
(
pPeer
->
ip
,
pPeer
->
port
,
0
);
if
(
connFd
<
0
)
{
sDebug
(
"%s, failed to open tcp socket since %s"
,
pPeer
->
id
,
strerror
(
errno
));
taosTmrReset
(
syncCheckPeerConnection
,
tsSyncTimer
*
1000
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
taosTmrReset
(
syncCheckPeerConnection
,
SYNC_CHECK_INTERVAL
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
return
;
}
...
...
@@ -1011,7 +1004,7 @@ static void syncSetupPeerConnection(SSyncPeer *pPeer) {
}
else
{
sDebug
(
"%s, failed to setup peer connection to server since %s, try later"
,
pPeer
->
id
,
strerror
(
errno
));
taosClose
(
connFd
);
taosTmrReset
(
syncCheckPeerConnection
,
tsSyncTimer
*
1000
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
taosTmrReset
(
syncCheckPeerConnection
,
SYNC_CHECK_INTERVAL
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
}
}
...
...
@@ -1140,15 +1133,15 @@ static int32_t syncSaveFwdInfo(SSyncNode *pNode, uint64_t version, void *mhandle
SSyncFwds
*
pSyncFwds
=
pNode
->
pSyncFwds
;
int64_t
time
=
taosGetTimestampMs
();
if
(
pSyncFwds
->
fwds
>=
tsMaxFwdInfo
)
{
// pSyncFwds->first = (pSyncFwds->first + 1) %
tsMaxFwdInfo
;
if
(
pSyncFwds
->
fwds
>=
SYNC_MAX_FWDS
)
{
// pSyncFwds->first = (pSyncFwds->first + 1) %
SYNC_MAX_FWDS
;
// pSyncFwds->fwds--;
sError
(
"vgId:%d, failed to save fwd info, hver:%"
PRIu64
" fwds:%d"
,
pNode
->
vgId
,
version
,
pSyncFwds
->
fwds
);
return
TSDB_CODE_SYN_TOO_MANY_FWDINFO
;
}
if
(
pSyncFwds
->
fwds
>
0
)
{
pSyncFwds
->
last
=
(
pSyncFwds
->
last
+
1
)
%
tsMaxFwdInfo
;
pSyncFwds
->
last
=
(
pSyncFwds
->
last
+
1
)
%
SYNC_MAX_FWDS
;
}
SFwdInfo
*
pFwdInfo
=
pSyncFwds
->
fwdInfo
+
pSyncFwds
->
last
;
...
...
@@ -1171,7 +1164,7 @@ static void syncRemoveConfirmedFwdInfo(SSyncNode *pNode) {
SFwdInfo
*
pFwdInfo
=
pSyncFwds
->
fwdInfo
+
pSyncFwds
->
first
;
if
(
pFwdInfo
->
confirmed
==
0
)
break
;
pSyncFwds
->
first
=
(
pSyncFwds
->
first
+
1
)
%
tsMaxFwdInfo
;
pSyncFwds
->
first
=
(
pSyncFwds
->
first
+
1
)
%
SYNC_MAX_FWDS
;
pSyncFwds
->
fwds
--
;
if
(
pSyncFwds
->
fwds
==
0
)
pSyncFwds
->
first
=
pSyncFwds
->
last
;
sTrace
(
"vgId:%d, fwd info is removed, hver:%"
PRIu64
" fwds:%d"
,
pNode
->
vgId
,
pFwdInfo
->
version
,
pSyncFwds
->
fwds
);
...
...
@@ -1237,7 +1230,7 @@ static void syncMonitorFwdInfos(void *param, void *tmrId) {
if
(
pSyncFwds
->
fwds
>
0
)
{
pthread_mutex_lock
(
&
pNode
->
mutex
);
for
(
int32_t
i
=
0
;
i
<
pSyncFwds
->
fwds
;
++
i
)
{
SFwdInfo
*
pFwdInfo
=
pSyncFwds
->
fwdInfo
+
(
pSyncFwds
->
first
+
i
)
%
tsMaxFwdInfo
;
SFwdInfo
*
pFwdInfo
=
pSyncFwds
->
fwdInfo
+
(
pSyncFwds
->
first
+
i
)
%
SYNC_MAX_FWDS
;
if
(
ABS
(
time
-
pFwdInfo
->
time
)
<
2000
)
break
;
sDebug
(
"vgId:%d, forward info expired, hver:%"
PRIu64
" curtime:%"
PRIu64
" savetime:%"
PRIu64
,
pNode
->
vgId
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录