Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
11824a52
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
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看板
未验证
提交
11824a52
编写于
7月 26, 2023
作者:
H
Haojun Liao
提交者:
GitHub
7月 26, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #22193 from taosdata/fix/TS-3727-2.6
add timeout to auth
上级
240171d3
51b72319
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
285 addition
and
191 deletion
+285
-191
src/dnode/src/dnodePeer.c
src/dnode/src/dnodePeer.c
+47
-48
src/dnode/src/dnodeShell.c
src/dnode/src/dnodeShell.c
+64
-66
src/inc/dnode.h
src/inc/dnode.h
+3
-2
src/inc/trpc.h
src/inc/trpc.h
+44
-43
src/os/inc/osSemaphore.h
src/os/inc/osSemaphore.h
+29
-25
src/os/src/darwin/dwSemaphore.c
src/os/src/darwin/dwSemaphore.c
+1
-0
src/os/src/detail/osSemaphore.c
src/os/src/detail/osSemaphore.c
+64
-5
src/rpc/src/rpcMain.c
src/rpc/src/rpcMain.c
+33
-2
未找到文件。
src/dnode/src/dnodePeer.c
浏览文件 @
11824a52
...
...
@@ -20,13 +20,13 @@
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "mnode.h"
#include "dnodeVMgmt.h"
#include "dnodeVWrite.h"
#include "dnodeMPeer.h"
#include "dnodeMInfos.h"
#include "dnodeMPeer.h"
#include "dnodeStep.h"
#include "dnodeVMgmt.h"
#include "dnodeVWrite.h"
#include "mnode.h"
#include "os.h"
static
void
(
*
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SRpcMsg
*
);
static
void
dnodeProcessReqMsgFromDnode
(
SRpcMsg
*
pMsg
,
SRpcEpSet
*
);
...
...
@@ -85,11 +85,7 @@ void dnodeCleanupServer() {
}
static
void
dnodeProcessReqMsgFromDnode
(
SRpcMsg
*
pMsg
,
SRpcEpSet
*
pEpSet
)
{
SRpcMsg
rspMsg
=
{
.
handle
=
pMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
};
SRpcMsg
rspMsg
=
{.
handle
=
pMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
};
if
(
pMsg
->
pCont
==
NULL
)
return
;
if
(
pMsg
->
msgType
==
TSDB_MSG_TYPE_NETWORK_TEST
)
{
...
...
@@ -174,13 +170,9 @@ static void dnodeProcessRspFromDnode(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
rpcFreeCont
(
pMsg
->
pCont
);
}
void
dnodeAddClientRspHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SRpcMsg
*
rpcMsg
))
{
dnodeProcessRspMsgFp
[
msgType
]
=
fp
;
}
void
dnodeAddClientRspHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SRpcMsg
*
rpcMsg
))
{
dnodeProcessRspMsgFp
[
msgType
]
=
fp
;
}
void
dnodeSendMsgToDnode
(
SRpcEpSet
*
epSet
,
SRpcMsg
*
rpcMsg
)
{
rpcSendRequest
(
tsClientRpc
,
epSet
,
rpcMsg
,
NULL
);
}
void
dnodeSendMsgToDnode
(
SRpcEpSet
*
epSet
,
SRpcMsg
*
rpcMsg
)
{
rpcSendRequest
(
tsClientRpc
,
epSet
,
rpcMsg
,
NULL
);
}
void
dnodeSendMsgToMnodeRecv
(
SRpcMsg
*
rpcMsg
,
SRpcMsg
*
rpcRsp
)
{
SRpcEpSet
epSet
=
{
0
};
...
...
@@ -189,6 +181,13 @@ void dnodeSendMsgToMnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp) {
assert
(
tsClientRpc
!=
0
);
rpcSendRecv
(
tsClientRpc
,
&
epSet
,
rpcMsg
,
rpcRsp
);
}
void
dnodeSendMsgToMnodeRecvWithTimeout
(
SRpcMsg
*
rpcMsg
,
SRpcMsg
*
rpcRsp
)
{
SRpcEpSet
epSet
=
{
0
};
dnodeGetEpSetForPeer
(
&
epSet
);
assert
(
tsClientRpc
!=
0
);
rpcSendRecvWithTimeout
(
tsClientRpc
,
&
epSet
,
rpcMsg
,
rpcRsp
);
}
void
dnodeSendMsgToDnodeRecv
(
SRpcMsg
*
rpcMsg
,
SRpcMsg
*
rpcRsp
,
SRpcEpSet
*
epSet
)
{
rpcSendRecv
(
tsClientRpc
,
epSet
,
rpcMsg
,
rpcRsp
);
...
...
src/dnode/src/dnodeShell.c
浏览文件 @
11824a52
...
...
@@ -14,20 +14,20 @@
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "http.h"
#include "mnode.h"
#include "dnodeVRead.h"
#include "dnodeVWrite.h"
#include "dnodeShell.h"
#include "dnodeMRead.h"
#include "dnodeMWrite.h"
#include "dnodeShell.h"
#include "dnodeStep.h"
#include "dnodeVRead.h"
#include "dnodeVWrite.h"
#include "http.h"
#include "mnode.h"
#include "os.h"
static
void
(
*
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SRpcMsg
*
);
static
void
dnodeProcessMsgFromShell
(
SRpcMsg
*
pMsg
,
SRpcEpSet
*
);
static
int
dnodeRetrieveUserAuthInfo
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
static
void
*
tsShellRpc
=
NULL
;
static
void
*
tsShellRpc
=
NULL
;
static
int64_t
tsQueryReqNum
=
0
;
static
int64_t
tsSubmitReqNum
=
0
;
...
...
@@ -44,7 +44,7 @@ int32_t dnodeInitShell() {
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_USER
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_USER
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_USER
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_DNODE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_DNODE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_DNODE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_DB
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_TP
]
=
dnodeDispatchToMWriteQueue
;
...
...
@@ -55,22 +55,22 @@ int32_t dnodeInitShell() {
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_FUNCTION
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_DB
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_TP
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_TABLE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_TABLE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_TABLE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_TABLE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_STREAM
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_STREAM
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_KILL_QUERY
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_KILL_STREAM
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_KILL_CONN
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CONFIG_DNODE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_COMPACT_VNODE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CONFIG_DNODE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_COMPACT_VNODE
]
=
dnodeDispatchToMWriteQueue
;
// the following message shall be treated as mnode query
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_HEARTBEAT
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CONNECT
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_USE_DB
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_TABLE_META
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_STABLE_VGROUP
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_STABLE_VGROUP
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_TABLES_META
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_SHOW
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_RETRIEVE
]
=
dnodeDispatchToMReadQueue
;
...
...
@@ -113,11 +113,7 @@ void dnodeCleanupShell() {
}
static
void
dnodeProcessMsgFromShell
(
SRpcMsg
*
pMsg
,
SRpcEpSet
*
pEpSet
)
{
SRpcMsg
rpcMsg
=
{
.
handle
=
pMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
};
SRpcMsg
rpcMsg
=
{.
handle
=
pMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
};
if
(
pMsg
->
pCont
==
NULL
)
return
;
...
...
@@ -148,9 +144,10 @@ static void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
atomic_fetch_add_64
(
&
tsQueryReqNum
,
1
);
}
else
if
(
pMsg
->
msgType
==
TSDB_MSG_TYPE_SUBMIT
)
{
atomic_fetch_add_64
(
&
tsSubmitReqNum
,
1
);
}
else
{}
}
else
{
}
if
(
dnodeProcessShellMsgFp
[
pMsg
->
msgType
]
)
{
if
(
dnodeProcessShellMsgFp
[
pMsg
->
msgType
]
)
{
(
*
dnodeProcessShellMsgFp
[
pMsg
->
msgType
])(
pMsg
);
}
else
{
dError
(
"RPC %p, shell msg:%s is not processed"
,
pMsg
->
handle
,
taosMsg
[
pMsg
->
msgType
]);
...
...
@@ -191,10 +188,10 @@ static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char
dDebug
(
"user:%s, send auth msg to mnodes"
,
user
);
SRpcMsg
rpcRsp
=
{
0
};
dnodeSendMsgToMnodeRecv
(
&
rpcMsg
,
&
rpcRsp
);
dnodeSendMsgToMnodeRecv
WithTimeout
(
&
rpcMsg
,
&
rpcRsp
);
if
(
rpcRsp
.
code
!=
0
)
{
dError
(
"user:%s, auth msg received from mnodes, error:%s"
,
user
,
tstrerror
(
rpcRsp
.
code
));
dError
(
"user:%s, auth msg received from mnodes, error:%s
, may be timeout
"
,
user
,
tstrerror
(
rpcRsp
.
code
));
}
else
{
SAuthRsp
*
pRsp
=
rpcRsp
.
pCont
;
dDebug
(
"user:%s, auth msg received from mnodes"
,
user
);
...
...
@@ -240,7 +237,8 @@ void *dnodeSendCfgTableToRecv(int32_t vgId, int32_t tid) {
int16_t
numOfTags
=
htons
(
pTable
->
numOfTags
);
int32_t
tableId
=
htonl
(
pTable
->
tid
);
uint64_t
uid
=
htobe64
(
pTable
->
uid
);
dInfo
(
"table:%s, numOfColumns:%d numOfTags:%d tid:%d uid:%"
PRIu64
,
pTable
->
tableFname
,
numOfColumns
,
numOfTags
,
tableId
,
uid
);
dInfo
(
"table:%s, numOfColumns:%d numOfTags:%d tid:%d uid:%"
PRIu64
,
pTable
->
tableFname
,
numOfColumns
,
numOfTags
,
tableId
,
uid
);
return
rpcRsp
.
pCont
;
}
...
...
src/inc/dnode.h
浏览文件 @
11824a52
...
...
@@ -20,8 +20,8 @@
extern
"C"
{
#endif
#include "trpc.h"
#include "taosmsg.h"
#include "trpc.h"
#define MAX_HTTP_STATUS_CODE_NUM 63
typedef
struct
{
...
...
@@ -50,6 +50,7 @@ int32_t dnodeStartMnode(SMInfos *pMinfos);
void
dnodeAddClientRspHandle
(
uint8_t
msgType
,
void
(
*
fp
)(
SRpcMsg
*
rpcMsg
));
void
dnodeSendMsgToDnode
(
SRpcEpSet
*
epSet
,
SRpcMsg
*
rpcMsg
);
void
dnodeSendMsgToMnodeRecv
(
SRpcMsg
*
rpcMsg
,
SRpcMsg
*
rpcRsp
);
void
dnodeSendMsgToMnodeRecvWithTimeout
(
SRpcMsg
*
rpcMsg
,
SRpcMsg
*
rpcRsp
);
void
dnodeSendMsgToDnodeRecv
(
SRpcMsg
*
rpcMsg
,
SRpcMsg
*
rpcRsp
,
SRpcEpSet
*
epSet
);
void
*
dnodeSendCfgTableToRecv
(
int32_t
vgId
,
int32_t
tid
);
...
...
src/inc/trpc.h
浏览文件 @
11824a52
...
...
@@ -90,13 +90,14 @@ void rpcSendResponse(const SRpcMsg *pMsg);
void
rpcSendRedirectRsp
(
void
*
pConn
,
const
SRpcEpSet
*
pEpSet
);
int
rpcGetConnInfo
(
void
*
thandle
,
SRpcConnInfo
*
pInfo
);
void
rpcSendRecv
(
void
*
shandle
,
SRpcEpSet
*
pEpSet
,
SRpcMsg
*
pReq
,
SRpcMsg
*
pRsp
);
void
rpcSendRecvWithTimeout
(
void
*
shandle
,
SRpcEpSet
*
pEpSet
,
SRpcMsg
*
pReq
,
SRpcMsg
*
pRsp
);
int
rpcReportProgress
(
void
*
pConn
,
char
*
pCont
,
int
contLen
);
void
rpcCancelRequest
(
int64_t
rid
);
int32_t
rpcUnusedSession
(
void
*
rpcInfo
,
bool
bLock
);
int32_t
rpcUnusedSession
(
void
*
rpcInfo
,
bool
bLock
);
// send rpc Refid connection probe alive message
bool
rpcSendProbe
(
int64_t
rpcRid
,
void
*
pPrevContext
,
bool
*
pReqOver
);
bool
rpcSendProbe
(
int64_t
rpcRid
,
void
*
pPrevContext
,
bool
*
pReqOver
);
// after sql request send , save conn info
bool
rpcSaveSendInfo
(
int64_t
rpcRid
,
void
**
ppContext
);
bool
rpcSaveSendInfo
(
int64_t
rpcRid
,
void
**
ppContext
);
#ifdef __cplusplus
}
...
...
src/os/inc/osSemaphore.h
浏览文件 @
11824a52
...
...
@@ -20,42 +20,46 @@
extern
"C"
{
#endif
#if defined (_TD_DARWIN_64)
typedef
struct
tsem_s
*
tsem_t
;
int
tsem_init
(
tsem_t
*
sem
,
int
pshared
,
unsigned
int
value
);
int
tsem_wait
(
tsem_t
*
sem
);
int
tsem_post
(
tsem_t
*
sem
);
int
tsem_destroy
(
tsem_t
*
sem
);
#include <semaphore.h>
#if defined(_TD_DARWIN_64)
typedef
struct
tsem_s
*
tsem_t
;
int
tsem_init
(
tsem_t
*
sem
,
int
pshared
,
unsigned
int
value
);
int
tsem_wait
(
tsem_t
*
sem
);
int
tsem_post
(
tsem_t
*
sem
);
int
tsem_timewait
(
tsem_t
*
sim
,
int64_t
milis
);
int
tsem_destroy
(
tsem_t
*
sem
);
#else
#define tsem_t sem_t
#define tsem_init sem_init
int
tsem_wait
(
tsem_t
*
sem
);
#define tsem_post sem_post
#define tsem_destroy sem_destroy
#define tsem_t sem_t
#define tsem_init sem_init
int
tsem_wait
(
tsem_t
*
sem
);
int
tsem_timewait
(
tsem_t
*
sim
,
int64_t
milis
);
#define tsem_post sem_post
#define tsem_destroy sem_destroy
#endif
#if defined
(_TD_DARWIN_64)
#define pthread_rwlock_t pthread_mutex_t
#define pthread_rwlock_init(lock, NULL) pthread_mutex_init(lock, NULL)
#define pthread_rwlock_destroy(lock) pthread_mutex_destroy(lock)
#define pthread_rwlock_wrlock(lock) pthread_mutex_lock(lock)
#define pthread_rwlock_rdlock(lock) pthread_mutex_lock(lock)
#define pthread_rwlock_unlock(lock) pthread_mutex_unlock(lock)
#if defined(_TD_DARWIN_64)
#define pthread_rwlock_t pthread_mutex_t
#define pthread_rwlock_init(lock, NULL) pthread_mutex_init(lock, NULL)
#define pthread_rwlock_destroy(lock) pthread_mutex_destroy(lock)
#define pthread_rwlock_wrlock(lock) pthread_mutex_lock(lock)
#define pthread_rwlock_rdlock(lock) pthread_mutex_lock(lock)
#define pthread_rwlock_unlock(lock) pthread_mutex_unlock(lock)
#define pthread_spinlock_t pthread_mutex_t
#define pthread_spin_init(lock, NULL) pthread_mutex_init(lock, NULL)
#define pthread_spin_destroy(lock) pthread_mutex_destroy(lock)
#define pthread_spin_lock(lock) pthread_mutex_lock(lock)
#define pthread_spin_unlock(lock) pthread_mutex_unlock(lock)
#define pthread_spinlock_t pthread_mutex_t
#define pthread_spin_init(lock, NULL) pthread_mutex_init(lock, NULL)
#define pthread_spin_destroy(lock) pthread_mutex_destroy(lock)
#define pthread_spin_lock(lock) pthread_mutex_lock(lock)
#define pthread_spin_unlock(lock) pthread_mutex_unlock(lock)
#endif
bool
taosCheckPthreadValid
(
pthread_t
thread
);
int64_t
taosGetSelfPthreadId
();
int64_t
taosGetPthreadId
(
pthread_t
thread
);
void
taosResetPthread
(
pthread_t
*
thread
);
void
taosResetPthread
(
pthread_t
*
thread
);
bool
taosComparePthread
(
pthread_t
first
,
pthread_t
second
);
int32_t
taosGetPId
();
int32_t
taosGetCurrentAPPName
(
char
*
name
,
int32_t
*
len
);
int32_t
taosGetCurrentAPPName
(
char
*
name
,
int32_t
*
len
);
#ifdef __cplusplus
}
...
...
src/os/src/darwin/dwSemaphore.c
浏览文件 @
11824a52
...
...
@@ -195,6 +195,7 @@ int tsem_wait(tsem_t *sem) {
#endif // SEM_USE_PTHREAD
}
int
tsem_post
(
tsem_t
*
sem
)
{
if
(
!*
sem
)
{
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==not initialized
\n
"
,
basename
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
...
...
src/os/src/detail/osSemaphore.c
浏览文件 @
11824a52
...
...
@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
#if !defined
(_TD_DARWIN_64)
#if !defined(_TD_DARWIN_64)
int32_t
tsem_wait
(
tsem_t
*
sem
)
{
int
ret
=
0
;
...
...
@@ -28,7 +28,25 @@ int32_t tsem_wait(tsem_t* sem) {
#endif
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined (_TD_DARWIN_64))
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined(_TD_DARWIN_64))
int32_t
tsem_timewait
(
tsem_t
*
sem
,
int64_t
ms
)
{
int
ret
=
0
;
struct
timespec
ts
=
{
0
};
if
(
clock_gettime
(
CLOCK_REALTIME
,
&
ts
)
==
-
1
)
{
return
-
1
;
}
ts
.
tv_nsec
+=
ms
*
1000000
;
ts
.
tv_sec
+=
ts
.
tv_nsec
/
1000000000
;
ts
.
tv_nsec
%=
1000000000
;
while
((
ret
=
sem_timedwait
(
sem
,
&
ts
))
==
-
1
&&
errno
==
EINTR
)
continue
;
return
ret
;
}
bool
taosCheckPthreadValid
(
pthread_t
thread
)
{
return
thread
!=
0
;
}
...
...
@@ -40,11 +58,11 @@ int64_t taosGetSelfPthreadId() {
}
int64_t
taosGetPthreadId
(
pthread_t
thread
)
{
return
(
int64_t
)
thread
;
}
void
taosResetPthread
(
pthread_t
*
thread
)
{
*
thread
=
0
;
}
void
taosResetPthread
(
pthread_t
*
thread
)
{
*
thread
=
0
;
}
bool
taosComparePthread
(
pthread_t
first
,
pthread_t
second
)
{
return
first
==
second
;
}
int32_t
taosGetPId
()
{
return
getpid
();
}
int32_t
taosGetCurrentAPPName
(
char
*
name
,
int32_t
*
len
)
{
int32_t
taosGetCurrentAPPName
(
char
*
name
,
int32_t
*
len
)
{
const
char
*
self
=
"/proc/self/exe"
;
char
path
[
PATH_MAX
]
=
{
0
};
...
...
@@ -70,3 +88,44 @@ int32_t taosGetCurrentAPPName(char *name, int32_t* len) {
}
#endif
#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
int32_t
tsem_timewait
(
tsem_t
*
sem
,
int64_t
ms
)
{
return
tsem_wait
(
sem
);
// struct timespec ts;
// taosClockGetTime(0, &ts);
// ts.tv_nsec += ms * 1000000;
// ts.tv_sec += ts.tv_nsec / 1000000000;
// ts.tv_nsec %= 1000000000;
// int rc;
// while ((rc = sem_timedwait(sem, &ts)) == -1 && errno == EINTR) continue;
// return rc;
// /* This should have timed out */
// // ASSERT(errno == ETIMEDOUT);
// // ASSERT(rc != 0);
// // GetSystemTimeAsFileTime(&ft_after);
// // // We specified a non-zero wait. Time must advance.
// // if (ft_before.dwLowDateTime == ft_after.dwLowDateTime && ft_before.dwHighDateTime == ft_after.dwHighDateTime)
// // {
// // printf("nanoseconds: %d, rc: %d, code:0x%x. before filetime: %d, %d; after filetime: %d, %d\n",
// // nanosecs, rc, errno,
// // (int)ft_before.dwLowDateTime, (int)ft_before.dwHighDateTime,
// // (int)ft_after.dwLowDateTime, (int)ft_after.dwHighDateTime);
// // printf("time must advance during sem_timedwait.");
// // return 1;
// // }
}
#endif
// #if defined(_TD_DARWIN_64)
// int tsem_timewait(tsem_t* psem, int64_t milis) {
// if (psem == NULL || *psem == NULL) return -1;
// dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(milis * USEC_PER_SEC));
// dispatch_semaphore_wait(*psem, time);
// return 0;
// }
// #endif
\ No newline at end of file
src/rpc/src/rpcMain.c
浏览文件 @
11824a52
...
...
@@ -561,6 +561,37 @@ void rpcSendRecv(void *shandle, SRpcEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp)
return
;
}
void
rpcSendRecvWithTimeout
(
void
*
shandle
,
SRpcEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
,
SRpcMsg
*
pRsp
)
{
SRpcReqContext
*
pContext
;
pContext
=
(
SRpcReqContext
*
)((
char
*
)
pMsg
->
pCont
-
sizeof
(
SRpcHead
)
-
sizeof
(
SRpcReqContext
));
memset
(
pRsp
,
0
,
sizeof
(
SRpcMsg
));
tsem_t
sem
;
tsem_init
(
&
sem
,
0
,
0
);
pContext
->
pSem
=
&
sem
;
pContext
->
pRsp
=
pRsp
;
pContext
->
pSet
=
pEpSet
;
int64_t
rid
=
0
;
rpcSendRequest
(
shandle
,
pEpSet
,
pMsg
,
&
rid
);
#if defined (LINUX)
if
(
tsem_timewait
(
&
sem
,
3
*
1000
)
==
0
)
{
// do nothing
}
else
{
rpcCancelRequest
(
rid
);
pRsp
->
code
=
-
1
;
}
#else
tsem_wait
(
&
sem
);
#endif
tsem_destroy
(
&
sem
);
return
;
}
// this API is used by server app to keep an APP context in case connection is broken
int
rpcReportProgress
(
void
*
handle
,
char
*
pCont
,
int
contLen
)
{
SRpcConn
*
pConn
=
(
SRpcConn
*
)
handle
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录