Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9e130aef
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9e130aef
编写于
4月 19, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: check server status
上级
72735810
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
198 addition
and
239 deletion
+198
-239
include/client/taos.h
include/client/taos.h
+10
-0
include/common/tmsg.h
include/common/tmsg.h
+8
-4
include/common/tmsgdef.h
include/common/tmsgdef.h
+1
-1
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+59
-0
source/client/src/clientMsgHandler.c
source/client/src/clientMsgHandler.c
+4
-4
source/common/src/tmsg.c
source/common/src/tmsg.c
+41
-0
source/dnode/mgmt/implement/src/dmExec.c
source/dnode/mgmt/implement/src/dmExec.c
+1
-1
source/dnode/mgmt/implement/src/dmTransport.c
source/dnode/mgmt/implement/src/dmTransport.c
+3
-3
source/dnode/mgmt/interface/inc/dmDef.h
source/dnode/mgmt/interface/inc/dmDef.h
+7
-1
source/dnode/mgmt/interface/inc/dmInt.h
source/dnode/mgmt/interface/inc/dmInt.h
+2
-2
source/dnode/mgmt/interface/src/dmInt.c
source/dnode/mgmt/interface/src/dmInt.c
+54
-13
source/dnode/mgmt/mgmt_vnode/src/vmInt.c
source/dnode/mgmt/mgmt_vnode/src/vmInt.c
+1
-1
tools/shell/src/tnettest.c
tools/shell/src/tnettest.c
+7
-209
未找到文件。
include/client/taos.h
浏览文件 @
9e130aef
...
...
@@ -315,6 +315,16 @@ DLL_EXPORT TAOS_RES *tmq_create_stream(TAOS *taos, const char *streamName, const
typedef
void
(
*
TAOS_SUBSCRIBE_CALLBACK
)(
TAOS_SUB
*
tsub
,
TAOS_RES
*
res
,
void
*
param
,
int
code
);
#endif
typedef
enum
{
TSDB_SRV_STATUS_UNAVAILABLE
=
0
,
TSDB_SRV_STATUS_NETWORK_OK
=
1
,
TSDB_SRV_STATUS_SERVICE_OK
=
2
,
TSDB_SRV_STATUS_SERVICE_DEGRADED
=
3
,
TSDB_SRV_STATUS_EXTING
=
4
,
}
TSDB_SERVER_STATUS
;
DLL_EXPORT
TSDB_SERVER_STATUS
taos_check_server_status
(
const
char
*
fqdn
,
int
port
,
char
*
details
,
int
maxlen
);
#ifdef __cplusplus
}
#endif
...
...
include/common/tmsg.h
浏览文件 @
9e130aef
...
...
@@ -1071,10 +1071,14 @@ int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
int32_t
tDeserializeSAuthReq
(
void
*
buf
,
int32_t
bufLen
,
SAuthReq
*
pReq
);
typedef
struct
{
int8_t
finished
;
char
name
[
TSDB_STEP_NAME_LEN
];
char
desc
[
TSDB_STEP_DESC_LEN
];
}
SStartupReq
;
int32_t
statusCode
;
int32_t
detailLen
;
char
*
details
;
}
SServerStatusRsp
;
int32_t
tSerializeSServerStatusRsp
(
void
*
buf
,
int32_t
bufLen
,
SServerStatusRsp
*
pRsp
);
int32_t
tDeserializeSServerStatusRsp
(
void
*
buf
,
int32_t
bufLen
,
SServerStatusRsp
*
pRsp
);
void
tFreeSServerStatusRsp
(
SServerStatusRsp
*
pRsp
);
/**
* The layout of the query message payload is as following:
...
...
include/common/tmsgdef.h
浏览文件 @
9e130aef
...
...
@@ -87,7 +87,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_DND_SYNC_VNODE
,
"dnode-sync-vnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_COMPACT_VNODE
,
"dnode-compact-vnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_CONFIG_DNODE
,
"dnode-config-dnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_
NETWORK_TEST
,
"dnode-nettest
"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_
SERVER_STATUS
,
"dnode-server-status
"
,
NULL
,
NULL
)
// Requests handled by MNODE
TD_NEW_MSG_SEG
(
TDMT_MND_MSG
)
...
...
source/client/src/clientImpl.c
浏览文件 @
9e130aef
...
...
@@ -815,3 +815,62 @@ int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableR
return
setResultDataPtr
(
pResultInfo
,
pResultInfo
->
fields
,
pResultInfo
->
numOfCols
,
pResultInfo
->
numOfRows
,
convertUcs4
);
}
TSDB_SERVER_STATUS
taos_check_server_status
(
const
char
*
fqdn
,
int
port
,
char
*
details
,
int
maxlen
)
{
TSDB_SERVER_STATUS
code
=
TSDB_SRV_STATUS_UNAVAILABLE
;
void
*
clientRpc
=
NULL
;
SServerStatusRsp
statusRsp
=
{
0
};
SEpSet
epSet
=
{.
inUse
=
0
,
.
numOfEps
=
1
};
SRpcMsg
rpcMsg
=
{.
ahandle
=
(
void
*
)
0x9526
,
.
msgType
=
TDMT_DND_SERVER_STATUS
};
SRpcMsg
rpcRsp
=
{
0
};
SRpcInit
rpcInit
=
{
0
};
char
pass
[
TSDB_PASSWORD_LEN
+
1
]
=
{
0
};
taosEncryptPass_c
((
uint8_t
*
)(
"_pwd"
),
strlen
(
"_pwd"
),
pass
);
rpcInit
.
label
=
"CHK"
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
cfp
=
NULL
;
rpcInit
.
sessions
=
16
;
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
rpcInit
.
idleTime
=
tsShellActivityTimer
*
1000
;
rpcInit
.
user
=
"_dnd"
;
rpcInit
.
ckey
=
"_key"
;
rpcInit
.
spi
=
1
;
rpcInit
.
secret
=
pass
;
clientRpc
=
rpcOpen
(
&
rpcInit
);
if
(
clientRpc
==
NULL
)
{
tscError
(
"failed to init server status client"
);
goto
_OVER
;
}
tstrncpy
(
epSet
.
eps
[
0
].
fqdn
,
fqdn
,
TSDB_FQDN_LEN
);
epSet
.
eps
[
0
].
port
=
(
uint16_t
)
port
;
rpcSendRecv
(
clientRpc
,
&
epSet
,
&
rpcMsg
,
&
rpcRsp
);
if
(
rpcRsp
.
code
!=
0
||
rpcRsp
.
contLen
<=
0
||
rpcRsp
.
pCont
==
NULL
)
{
tscError
(
"failed to send server status req since %s"
,
terrstr
());
goto
_OVER
;
}
if
(
tDeserializeSServerStatusRsp
(
rpcRsp
.
pCont
,
rpcRsp
.
contLen
,
&
statusRsp
)
!=
0
)
{
tscError
(
"failed to parse server status rsp since %s"
,
terrstr
());
goto
_OVER
;
}
code
=
statusRsp
.
statusCode
;
if
(
details
!=
NULL
)
{
tstrncpy
(
details
,
statusRsp
.
details
,
maxlen
);
}
_OVER:
if
(
clientRpc
!=
NULL
)
{
rpcClose
(
clientRpc
);
}
if
(
rpcRsp
.
pCont
!=
NULL
)
{
rpcFreeCont
(
rpcRsp
.
pCont
);
}
tFreeSServerStatusRsp
(
&
statusRsp
);
return
code
;
}
source/client/src/clientMsgHandler.c
浏览文件 @
9e130aef
...
...
@@ -209,9 +209,9 @@ int32_t processDropDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
}
void
initMsgHandleFp
()
{
handleRequestRspFp
[
TMSG_INDEX
(
TDMT_MND_CONNECT
)]
=
processConnectRsp
;
handleRequestRspFp
[
TMSG_INDEX
(
TDMT_MND_CREATE_DB
)]
=
processCreateDbRsp
;
handleRequestRspFp
[
TMSG_INDEX
(
TDMT_MND_USE_DB
)]
=
processUseDbRsp
;
handleRequestRspFp
[
TMSG_INDEX
(
TDMT_MND_CONNECT
)]
=
processConnectRsp
;
handleRequestRspFp
[
TMSG_INDEX
(
TDMT_MND_CREATE_DB
)]
=
processCreateDbRsp
;
handleRequestRspFp
[
TMSG_INDEX
(
TDMT_MND_USE_DB
)]
=
processUseDbRsp
;
handleRequestRspFp
[
TMSG_INDEX
(
TDMT_MND_CREATE_STB
)]
=
processCreateTableRsp
;
handleRequestRspFp
[
TMSG_INDEX
(
TDMT_MND_DROP_DB
)]
=
processDropDbRsp
;
handleRequestRspFp
[
TMSG_INDEX
(
TDMT_MND_DROP_DB
)]
=
processDropDbRsp
;
}
source/common/src/tmsg.c
浏览文件 @
9e130aef
...
...
@@ -3097,6 +3097,47 @@ int32_t tDeserializeSAuthReq(void *buf, int32_t bufLen, SAuthReq *pReq) {
return
0
;
}
int32_t
tSerializeSServerStatusRsp
(
void
*
buf
,
int32_t
bufLen
,
SServerStatusRsp
*
pRsp
)
{
SCoder
encoder
=
{
0
};
tCoderInit
(
&
encoder
,
TD_LITTLE_ENDIAN
,
buf
,
bufLen
,
TD_ENCODER
);
if
(
tStartEncode
(
&
encoder
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pRsp
->
statusCode
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pRsp
->
detailLen
)
<
0
)
return
-
1
;
if
(
pRsp
->
detailLen
>
0
)
{
if
(
tEncodeCStr
(
&
encoder
,
pRsp
->
details
)
<
0
)
return
-
1
;
}
tEndEncode
(
&
encoder
);
int32_t
tlen
=
encoder
.
pos
;
tCoderClear
(
&
encoder
);
return
tlen
;
}
int32_t
tDeserializeSServerStatusRsp
(
void
*
buf
,
int32_t
bufLen
,
SServerStatusRsp
*
pRsp
)
{
SCoder
decoder
=
{
0
};
tCoderInit
(
&
decoder
,
TD_LITTLE_ENDIAN
,
buf
,
bufLen
,
TD_DECODER
);
if
(
tStartDecode
(
&
decoder
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pRsp
->
statusCode
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pRsp
->
detailLen
)
<
0
)
return
-
1
;
if
(
pRsp
->
detailLen
>
0
)
{
pRsp
->
details
=
taosMemoryCalloc
(
1
,
pRsp
->
detailLen
);
if
(
pRsp
->
details
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
if
(
tDecodeCStrTo
(
&
decoder
,
pRsp
->
details
)
<
0
)
return
-
1
;
}
tEndDecode
(
&
decoder
);
tCoderClear
(
&
decoder
);
return
0
;
}
void
tFreeSServerStatusRsp
(
SServerStatusRsp
*
pRsp
)
{
taosMemoryFree
(
pRsp
->
details
);
}
int32_t
tEncodeSMqOffset
(
SCoder
*
encoder
,
const
SMqOffset
*
pOffset
)
{
if
(
tEncodeI32
(
encoder
,
pOffset
->
vgId
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
encoder
,
pOffset
->
offset
)
<
0
)
return
-
1
;
...
...
source/dnode/mgmt/implement/src/dmExec.c
浏览文件 @
9e130aef
...
...
@@ -256,7 +256,7 @@ static int32_t dmStartNodes(SDnode *pDnode) {
}
dInfo
(
"TDengine initialized successfully"
);
dmReportStartup
(
pDnode
,
"TDengine"
,
"initialized successfully"
);
dmReportStartup
(
pDnode
,
"TDengine"
,
"initialized successfully"
,
true
);
return
0
;
}
...
...
source/dnode/mgmt/implement/src/dmTransport.c
浏览文件 @
9e130aef
...
...
@@ -125,9 +125,9 @@ static void dmProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
SMsgHandle
*
pHandle
=
&
pTrans
->
msgHandles
[
TMSG_INDEX
(
msgType
)];
SMgmtWrapper
*
pWrapper
=
pHandle
->
pNdWrapper
;
if
(
msgType
==
TDMT_DND_
NETWORK_TEST
)
{
dTrace
(
"
network test
req will be processed, handle:%p, app:%p"
,
pMsg
->
handle
,
pMsg
->
ahandle
);
dmProcessS
tartup
Req
(
pDnode
,
pMsg
);
if
(
msgType
==
TDMT_DND_
SERVER_STATUS
)
{
dTrace
(
"
server status
req will be processed, handle:%p, app:%p"
,
pMsg
->
handle
,
pMsg
->
ahandle
);
dmProcessS
erverStatus
Req
(
pDnode
,
pMsg
);
return
;
}
...
...
source/dnode/mgmt/interface/inc/dmDef.h
浏览文件 @
9e130aef
...
...
@@ -132,12 +132,18 @@ typedef struct {
uint16_t
serverPort
;
}
SDnodeData
;
typedef
struct
{
bool
finished
;
char
name
[
TSDB_STEP_NAME_LEN
];
char
desc
[
TSDB_STEP_DESC_LEN
];
}
SStartupInfo
;
typedef
struct
SDnode
{
EDndProcType
ptype
;
EDndNodeType
ntype
;
EDndRunStatus
status
;
EDndEvent
event
;
SStartup
Req
startup
;
SStartup
Info
startup
;
SDnodeTrans
trans
;
SDnodeData
data
;
TdThreadMutex
mutex
;
...
...
source/dnode/mgmt/interface/inc/dmInt.h
浏览文件 @
9e130aef
...
...
@@ -34,8 +34,8 @@ const char *dmEventName(EDndEvent ev);
void
dmSetStatus
(
SDnode
*
pDnode
,
EDndRunStatus
stat
);
void
dmSetEvent
(
SDnode
*
pDnode
,
EDndEvent
event
);
void
dmSetMsgHandle
(
SMgmtWrapper
*
pWrapper
,
tmsg_t
msgType
,
NodeMsgFp
nodeMsgFp
,
int8_t
vgId
);
void
dmReportStartup
(
SDnode
*
pDnode
,
const
char
*
pName
,
const
char
*
pDesc
);
void
dmProcessS
tartup
Req
(
SDnode
*
pDnode
,
SRpcMsg
*
pMsg
);
void
dmReportStartup
(
SDnode
*
pDnode
,
const
char
*
pName
,
const
char
*
pDesc
,
bool
finished
);
void
dmProcessS
erverStatus
Req
(
SDnode
*
pDnode
,
SRpcMsg
*
pMsg
);
void
dmGetMonitorSysInfo
(
SMonSysInfo
*
pInfo
);
// dmFile.c
...
...
source/dnode/mgmt/interface/src/dmInt.c
浏览文件 @
9e130aef
...
...
@@ -136,27 +136,68 @@ void dmReleaseWrapper(SMgmtWrapper *pWrapper) {
dTrace
(
"node:%s, is released, refCount:%d"
,
pWrapper
->
name
,
refCount
);
}
void
dmReportStartup
(
SDnode
*
pDnode
,
const
char
*
pName
,
const
char
*
pDesc
)
{
SStartup
Req
*
pStartup
=
&
pDnode
->
startup
;
void
dmReportStartup
(
SDnode
*
pDnode
,
const
char
*
pName
,
const
char
*
pDesc
,
bool
finished
)
{
SStartup
Info
*
pStartup
=
&
pDnode
->
startup
;
tstrncpy
(
pStartup
->
name
,
pName
,
TSDB_STEP_NAME_LEN
);
tstrncpy
(
pStartup
->
desc
,
pDesc
,
TSDB_STEP_DESC_LEN
);
pStartup
->
finished
=
0
;
pStartup
->
finished
=
false
;
}
static
void
dmGetStartup
(
SDnode
*
pDnode
,
SStartup
Req
*
pStartup
)
{
memcpy
(
pStartup
,
&
pDnode
->
startup
,
sizeof
(
SStartup
Req
));
static
void
dmGetStartup
(
SDnode
*
pDnode
,
SStartup
Info
*
pStartup
)
{
memcpy
(
pStartup
,
&
pDnode
->
startup
,
sizeof
(
SStartup
Info
));
pStartup
->
finished
=
(
pDnode
->
status
==
DND_STAT_RUNNING
);
}
void
dmProcessStartupReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pReq
)
{
dDebug
(
"startup req is received"
);
SStartupReq
*
pStartup
=
rpcMallocCont
(
sizeof
(
SStartupReq
));
dmGetStartup
(
pDnode
,
pStartup
);
static
void
dmGetServerStatus
(
SDnode
*
pDnode
,
SServerStatusRsp
*
pStatus
)
{
if
(
pDnode
->
status
==
DND_STAT_INIT
)
{
pStatus
->
statusCode
=
TSDB_SRV_STATUS_NETWORK_OK
;
}
else
if
(
pDnode
->
status
!=
DND_STAT_STOPPED
)
{
pStatus
->
statusCode
=
TSDB_SRV_STATUS_EXTING
;
}
else
{
pStatus
->
statusCode
=
TSDB_SRV_STATUS_SERVICE_OK
;
}
if
(
pStatus
->
statusCode
==
TSDB_SRV_STATUS_NETWORK_OK
)
{
SStartupInfo
*
pStartup
=
&
pDnode
->
startup
;
int32_t
len
=
strlen
(
pStartup
->
name
)
+
strlen
(
pStartup
->
desc
)
+
24
;
pStatus
->
details
=
taosMemoryCalloc
(
1
,
len
);
if
(
pStatus
->
details
!=
NULL
)
{
pStatus
->
detailLen
=
snprintf
(
pStatus
->
details
,
len
-
1
,
"%s: %s"
,
pStartup
->
name
,
pStartup
->
desc
)
+
1
;
}
}
if
(
pStatus
->
statusCode
==
TSDB_SRV_STATUS_SERVICE_OK
)
{
// check the status of mnode and vnode
}
}
void
dmProcessServerStatusReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pReq
)
{
dDebug
(
"server status req is received"
);
SServerStatusRsp
statusRsp
=
{
0
};
dmGetServerStatus
(
pDnode
,
&
statusRsp
);
SRpcMsg
rspMsg
=
{.
handle
=
pReq
->
handle
,
.
handle
=
pReq
->
ahandle
};
int32_t
rspLen
=
tSerializeSServerStatusRsp
(
NULL
,
0
,
&
statusRsp
);
if
(
rspLen
<
0
)
{
rspMsg
.
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_OVER
;
}
void
*
pRsp
=
rpcMallocCont
(
rspLen
);
if
(
pRsp
==
NULL
)
{
rspMsg
.
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_OVER
;
}
tSerializeSServerStatusRsp
(
pRsp
,
rspLen
,
&
statusRsp
);
rspMsg
.
pCont
=
pRsp
;
rspMsg
.
contLen
=
rspLen
;
dDebug
(
"startup req is sent, step:%s desc:%s finished:%d"
,
pStartup
->
name
,
pStartup
->
desc
,
pStartup
->
finished
);
SRpcMsg
rpcRsp
=
{
.
handle
=
pReq
->
handle
,
.
pCont
=
pStartup
,
.
contLen
=
sizeof
(
SStartupReq
),
.
ahandle
=
pReq
->
ahandle
};
rpcSendResponse
(
&
rpcRsp
);
_OVER:
rpcSendResponse
(
&
rspMsg
);
tFreeSServerStatusRsp
(
&
statusRsp
);
}
void
dmGetMonitorSysInfo
(
SMonSysInfo
*
pInfo
)
{
...
...
source/dnode/mgmt/mgmt_vnode/src/vmInt.c
浏览文件 @
9e130aef
...
...
@@ -130,7 +130,7 @@ static void *vmOpenVnodeFunc(void *param) {
char
stepDesc
[
TSDB_STEP_DESC_LEN
]
=
{
0
};
snprintf
(
stepDesc
,
TSDB_STEP_DESC_LEN
,
"vgId:%d, start to restore, %d of %d have been opened"
,
pCfg
->
vgId
,
pMgmt
->
state
.
openVnodes
,
pMgmt
->
state
.
totalVnodes
);
dmReportStartup
(
pDnode
,
"open-vnodes"
,
stepDesc
);
dmReportStartup
(
pDnode
,
"open-vnodes"
,
stepDesc
,
false
);
SMsgCb
msgCb
=
pMgmt
->
pDnode
->
data
.
msgCb
;
msgCb
.
pWrapper
=
pMgmt
->
pWrapper
;
...
...
tools/shell/src/tnettest.c
浏览文件 @
9e130aef
...
...
@@ -356,187 +356,6 @@ static void taosNetCheckPort(uint32_t hostIp, int32_t startPort, int32_t endPort
}
}
void
*
taosNetInitRpc
(
char
*
secretEncrypt
,
char
spi
)
{
SRpcInit
rpcInit
;
void
*
pRpcConn
=
NULL
;
char
user
[]
=
"nettestinternal"
;
char
pass
[]
=
"nettestinternal"
;
taosEncryptPass_c
((
uint8_t
*
)
pass
,
strlen
(
pass
),
secretEncrypt
);
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localPort
=
0
;
rpcInit
.
label
=
"NT"
;
rpcInit
.
numOfThreads
=
1
;
// every DB connection has only one thread
rpcInit
.
cfp
=
NULL
;
rpcInit
.
sessions
=
16
;
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
rpcInit
.
user
=
user
;
rpcInit
.
idleTime
=
2000
;
rpcInit
.
ckey
=
"key"
;
rpcInit
.
spi
=
spi
;
rpcInit
.
secret
=
secretEncrypt
;
pRpcConn
=
rpcOpen
(
&
rpcInit
);
return
pRpcConn
;
}
static
int32_t
taosNetCheckRpc
(
const
char
*
serverFqdn
,
uint16_t
port
,
uint16_t
pktLen
,
char
spi
,
SStartupReq
*
pStep
)
{
SEpSet
epSet
;
SRpcMsg
reqMsg
;
SRpcMsg
rspMsg
;
void
*
pRpcConn
;
char
secretEncrypt
[
TSDB_PASSWORD_LEN
+
1
]
=
{
0
};
pRpcConn
=
taosNetInitRpc
(
secretEncrypt
,
spi
);
if
(
NULL
==
pRpcConn
)
{
uError
(
"failed to init client rpc"
);
return
TSDB_CODE_RPC_NETWORK_UNAVAIL
;
}
memset
(
&
epSet
,
0
,
sizeof
(
SEpSet
));
strcpy
(
epSet
.
eps
[
0
].
fqdn
,
serverFqdn
);
epSet
.
eps
[
0
].
port
=
port
;
epSet
.
numOfEps
=
1
;
reqMsg
.
msgType
=
TDMT_DND_NETWORK_TEST
;
reqMsg
.
pCont
=
rpcMallocCont
(
pktLen
);
reqMsg
.
contLen
=
pktLen
;
reqMsg
.
code
=
0
;
reqMsg
.
handle
=
NULL
;
// rpc handle returned to app
reqMsg
.
ahandle
=
NULL
;
// app handle set by client
strcpy
(
reqMsg
.
pCont
,
"dnode-nettest"
);
rpcSendRecv
(
pRpcConn
,
&
epSet
,
&
reqMsg
,
&
rspMsg
);
if
((
rspMsg
.
code
!=
0
)
||
(
rspMsg
.
msgType
!=
TDMT_DND_NETWORK_TEST
+
1
))
{
uDebug
(
"ret code 0x%x %s"
,
rspMsg
.
code
,
tstrerror
(
rspMsg
.
code
));
return
rspMsg
.
code
;
}
int32_t
code
=
0
;
if
(
pStep
!=
NULL
&&
rspMsg
.
pCont
!=
NULL
&&
rspMsg
.
contLen
>
0
&&
rspMsg
.
contLen
<=
sizeof
(
SStartupReq
))
{
memcpy
(
pStep
,
rspMsg
.
pCont
,
rspMsg
.
contLen
);
code
=
1
;
}
rpcFreeCont
(
rspMsg
.
pCont
);
rpcClose
(
pRpcConn
);
return
code
;
}
static
int32_t
taosNetParseStartup
(
SStartupReq
*
pCont
)
{
SStartupReq
*
pStep
=
pCont
;
uInfo
(
"step:%s desc:%s"
,
pStep
->
name
,
pStep
->
desc
);
if
(
pStep
->
finished
)
{
uInfo
(
"check startup finished"
);
}
return
pStep
->
finished
?
0
:
1
;
}
static
void
taosNetTestStartup
(
char
*
host
,
int32_t
port
)
{
uInfo
(
"check startup, host:%s port:%d
\n
"
,
host
,
port
);
SStartupReq
*
pStep
=
taosMemoryMalloc
(
sizeof
(
SStartupReq
));
while
(
1
)
{
int32_t
code
=
taosNetCheckRpc
(
host
,
port
,
20
,
0
,
pStep
);
if
(
code
>
0
)
{
code
=
taosNetParseStartup
(
pStep
);
}
if
(
code
>
0
)
{
uDebug
(
"continue check startup step"
);
}
else
{
if
(
code
<
0
)
{
uError
(
"failed to check startup step, code:0x%x %s"
,
code
,
tstrerror
(
code
));
}
break
;
}
}
taosMemoryFree
(
pStep
);
}
static
void
taosNetCheckSync
(
char
*
host
,
int32_t
port
)
{
uint32_t
ip
=
taosGetIpv4FromFqdn
(
host
);
if
(
ip
==
0xffffffff
)
{
uError
(
"failed to get IP address from %s since %s"
,
host
,
strerror
(
errno
));
return
;
}
TdSocketPtr
pSocket
=
taosOpenTcpClientSocket
(
ip
,
(
uint16_t
)
port
,
0
);
if
(
pSocket
==
NULL
)
{
uError
(
"failed to create socket while test port:%d since %s"
,
port
,
strerror
(
errno
));
return
;
}
SSyncMsg
msg
;
memset
(
&
msg
,
0
,
sizeof
(
SSyncMsg
));
SSyncHead
*
pHead
=
&
msg
.
head
;
pHead
->
type
=
TAOS_SMSG_TEST
;
pHead
->
protocol
=
SYNC_PROTOCOL_VERSION
;
pHead
->
signature
=
SYNC_SIGNATURE
;
pHead
->
code
=
0
;
pHead
->
cId
=
0
;
pHead
->
vgId
=
-
1
;
pHead
->
len
=
sizeof
(
SSyncMsg
)
-
sizeof
(
SSyncHead
);
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
pHead
,
sizeof
(
SSyncHead
));
if
(
taosWriteMsg
(
pSocket
,
&
msg
,
sizeof
(
SSyncMsg
))
!=
sizeof
(
SSyncMsg
))
{
uError
(
"failed to test port:%d while send msg since %s"
,
port
,
strerror
(
errno
));
return
;
}
if
(
taosReadMsg
(
pSocket
,
&
msg
,
sizeof
(
SSyncMsg
))
!=
sizeof
(
SSyncMsg
))
{
uError
(
"failed to test port:%d while recv msg since %s"
,
port
,
strerror
(
errno
));
}
uInfo
(
"successed to test TCP port:%d"
,
port
);
taosCloseSocket
(
&
pSocket
);
}
static
void
taosNetTestRpc
(
char
*
host
,
int32_t
startPort
,
int32_t
pkgLen
)
{
char
spi
=
0
;
uInfo
(
"check rpc, host:%s Port:%d pkgLen:%d
\n
"
,
host
,
startPort
,
pkgLen
);
uint16_t
port
=
startPort
;
int32_t
sendpkgLen
;
if
(
pkgLen
<=
tsRpcMaxUdpSize
)
{
sendpkgLen
=
tsRpcMaxUdpSize
+
1000
;
}
else
{
sendpkgLen
=
pkgLen
;
}
tsRpcForceTcp
=
1
;
int32_t
ret
=
taosNetCheckRpc
(
host
,
port
,
sendpkgLen
,
spi
,
NULL
);
if
(
ret
<
0
)
{
printf
(
"failed to test TCP port:%d
\n
"
,
port
);
}
else
{
printf
(
"successed to test TCP port:%d
\n
"
,
port
);
}
if
(
pkgLen
>=
tsRpcMaxUdpSize
)
{
sendpkgLen
=
tsRpcMaxUdpSize
-
1000
;
}
else
{
sendpkgLen
=
pkgLen
;
}
/*
tsRpcForceTcp = 0;
ret = taosNetCheckRpc(host, port, pkgLen, spi, NULL);
if (ret < 0) {
printf("failed to test UDP port:%d\n", port);
} else {
printf("successed to test UDP port:%d\n", port);
}
*/
taosNetCheckSync
(
host
,
startPort
);
}
static
void
taosNetTestClient
(
char
*
host
,
int32_t
startPort
,
int32_t
pkgLen
)
{
uInfo
(
"work as client, host:%s Port:%d pkgLen:%d
\n
"
,
host
,
startPort
,
pkgLen
);
...
...
@@ -586,22 +405,10 @@ static void taosNetTestServer(char *host, int32_t startPort, int32_t pkgLen) {
}
}
static
void
taosNetTestFqdn
(
char
*
host
)
{
int
code
=
0
;
uint64_t
startTime
=
taosGetTimestampUs
();
uint32_t
ip
=
taosGetIpv4FromFqdn
(
host
);
if
(
ip
==
0xffffffff
)
{
uError
(
"failed to get IP address from %s since %s"
,
host
,
strerror
(
errno
));
code
=
-
1
;
}
uint64_t
endTime
=
taosGetTimestampUs
();
uint64_t
el
=
endTime
-
startTime
;
printf
(
"check convert fqdn spend, status: %d
\t
cost: %"
PRIu64
" us
\n
"
,
code
,
el
);
return
;
}
static
void
taosNetCheckSpeed
(
char
*
host
,
int32_t
port
,
int32_t
pkgLen
,
int32_t
pkgNum
,
char
*
pkgType
)
{
#if 0
// record config
int32_t compressTmp = tsCompressMsgSize;
int32_t maxUdpSize = tsRpcMaxUdpSize;
...
...
@@ -674,19 +481,19 @@ static void taosNetCheckSpeed(char *host, int32_t port, int32_t pkgLen,
tsRpcMaxUdpSize = maxUdpSize;
tsRpcForceTcp = forceTcp;
return;
#endif
}
void
taosNetTest
(
char
*
role
,
char
*
host
,
int32_t
port
,
int32_t
pkgLen
,
int32_t
pkgNum
,
char
*
pkgType
)
{
void
taosNetTest
(
char
*
role
,
char
*
host
,
int32_t
port
,
int32_t
pkgLen
,
int32_t
pkgNum
,
char
*
pkgType
)
{
tsLogEmbedded
=
1
;
if
(
host
==
NULL
)
host
=
tsLocalFqdn
;
if
(
port
==
0
)
port
=
tsServerPort
;
if
(
0
==
strcmp
(
"speed"
,
role
)){
if
(
0
==
strcmp
(
"speed"
,
role
))
{
if
(
pkgLen
<=
MIN_SPEED_PKG_LEN
)
pkgLen
=
MIN_SPEED_PKG_LEN
;
if
(
pkgLen
>
MAX_SPEED_PKG_LEN
)
pkgLen
=
MAX_SPEED_PKG_LEN
;
if
(
pkgNum
<=
MIN_SPEED_PKG_NUM
)
pkgNum
=
MIN_SPEED_PKG_NUM
;
if
(
pkgNum
>
MAX_SPEED_PKG_NUM
)
pkgNum
=
MAX_SPEED_PKG_NUM
;
}
else
{
}
else
{
if
(
pkgLen
<=
10
)
pkgLen
=
1000
;
if
(
pkgLen
>
MAX_PKG_LEN
)
pkgLen
=
MAX_PKG_LEN
;
}
...
...
@@ -695,21 +502,12 @@ void taosNetTest(char *role, char *host, int32_t port, int32_t pkgLen,
taosNetTestClient
(
host
,
port
,
pkgLen
);
}
else
if
(
0
==
strcmp
(
"server"
,
role
))
{
taosNetTestServer
(
host
,
port
,
pkgLen
);
}
else
if
(
0
==
strcmp
(
"rpc"
,
role
))
{
tsLogEmbedded
=
0
;
taosNetTestRpc
(
host
,
port
,
pkgLen
);
}
else
if
(
0
==
strcmp
(
"sync"
,
role
))
{
taosNetCheckSync
(
host
,
port
);
}
else
if
(
0
==
strcmp
(
"startup"
,
role
))
{
taosNetTestStartup
(
host
,
port
);
}
else
if
(
0
==
strcmp
(
"speed"
,
role
))
{
tsLogEmbedded
=
0
;
char
type
[
10
]
=
{
0
};
taosNetCheckSpeed
(
host
,
port
,
pkgLen
,
pkgNum
,
strtolower
(
type
,
pkgType
));
}
else
if
(
0
==
strcmp
(
"fqdn"
,
role
))
{
taosNetTestFqdn
(
host
);
}
else
{
taosNetTestStartup
(
host
,
port
);
TASSERT
(
1
);
}
tsLogEmbedded
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录