Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ec7df423
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,发现更多精彩内容 >>
提交
ec7df423
编写于
11月 25, 2022
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(tmq): time wait
上级
130d6e3b
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
52 addition
and
35 deletion
+52
-35
include/os/osSemaphore.h
include/os/osSemaphore.h
+2
-2
source/client/src/clientTmq.c
source/client/src/clientTmq.c
+25
-15
source/os/src/osSemaphore.c
source/os/src/osSemaphore.c
+25
-18
未找到文件。
include/os/osSemaphore.h
浏览文件 @
ec7df423
...
...
@@ -29,7 +29,7 @@ typedef dispatch_semaphore_t tsem_t;
int
tsem_init
(
tsem_t
*
sem
,
int
pshared
,
unsigned
int
value
);
int
tsem_wait
(
tsem_t
*
sem
);
int
tsem_timewait
(
tsem_t
*
sim
,
int64_t
nanosec
s
);
int
tsem_timewait
(
tsem_t
*
sim
,
int64_t
mili
s
);
int
tsem_post
(
tsem_t
*
sem
);
int
tsem_destroy
(
tsem_t
*
sem
);
...
...
@@ -38,7 +38,7 @@ int tsem_destroy(tsem_t *sem);
#define tsem_t sem_t
#define tsem_init sem_init
int
tsem_wait
(
tsem_t
*
sem
);
int
tsem_timewait
(
tsem_t
*
sim
,
int64_t
nanosec
s
);
int
tsem_timewait
(
tsem_t
*
sim
,
int64_t
mili
s
);
#define tsem_post sem_post
#define tsem_destroy sem_destroy
...
...
source/client/src/clientTmq.c
浏览文件 @
ec7df423
...
...
@@ -25,6 +25,13 @@
#include "tref.h"
#include "ttimer.h"
#if 0
#undef tsem_post
#define tsem_post(x) \
tscInfo("call sem post at %s %d", __FUNCTION__, __LINE__); \
sem_post(x)
#endif
int32_t
tmqAskEp
(
tmq_t
*
tmq
,
bool
async
);
typedef
struct
{
...
...
@@ -738,7 +745,7 @@ void tmqSendHbReq(void* param, void* tmrId) {
tscError
(
"tSerializeSMqHbReq failed"
);
return
;
}
void
*
pReq
=
taosMemoryCalloc
(
1
,
tlen
);
void
*
pReq
=
taosMemoryCalloc
(
1
,
tlen
);
if
(
tlen
<
0
)
{
tscError
(
"failed to malloc MqHbReq msg, size:%d"
,
tlen
);
return
;
...
...
@@ -1402,7 +1409,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool async) {
tscError
(
"tSerializeSMqAskEpReq failed"
);
return
-
1
;
}
void
*
pReq
=
taosMemoryCalloc
(
1
,
tlen
);
void
*
pReq
=
taosMemoryCalloc
(
1
,
tlen
);
if
(
tlen
<
0
)
{
tscError
(
"failed to malloc askEpReq msg, size:%d"
,
tlen
);
return
-
1
;
...
...
@@ -1461,7 +1468,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool async) {
return
code
;
}
void
tmqBuildConsumeReqImpl
(
SMqPollReq
*
pReq
,
tmq_t
*
tmq
,
int64_t
timeout
,
SMqClientTopic
*
pTopic
,
SMqClientVg
*
pVg
)
{
void
tmqBuildConsumeReqImpl
(
SMqPollReq
*
pReq
,
tmq_t
*
tmq
,
int64_t
timeout
,
SMqClientTopic
*
pTopic
,
SMqClientVg
*
pVg
)
{
/*strcpy(pReq->topic, pTopic->topicName);*/
/*strcpy(pReq->cgroup, tmq->groupId);*/
...
...
@@ -1561,7 +1568,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t timeout) {
tsem_post
(
&
tmq
->
rspSem
);
return
-
1
;
}
char
*
msg
=
taosMemoryCalloc
(
1
,
msgSize
);
char
*
msg
=
taosMemoryCalloc
(
1
,
msgSize
);
if
(
NULL
==
msg
)
{
atomic_store_32
(
&
pVg
->
vgStatus
,
TMQ_VG_STATUS__IDLE
);
tsem_post
(
&
tmq
->
rspSem
);
...
...
@@ -1797,17 +1804,20 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) {
return
NULL
;
}
if
(
timeout
!=
-
1
)
{
int64_t
end
Time
=
taosGetTimestampMs
();
int64_t
leftTime
=
end
Time
-
startTime
;
if
(
left
Time
>
timeout
)
{
tscDebug
(
"consumer:%"
PRId64
", (epoch %d) timeout, no rsp, start time %"
PRId64
",
end
time %"
PRId64
,
tmq
->
consumerId
,
tmq
->
epoch
,
startTime
,
end
Time
);
int64_t
current
Time
=
taosGetTimestampMs
();
int64_t
passedTime
=
current
Time
-
startTime
;
if
(
passed
Time
>
timeout
)
{
tscDebug
(
"consumer:%"
PRId64
", (epoch %d) timeout, no rsp, start time %"
PRId64
",
current
time %"
PRId64
,
tmq
->
consumerId
,
tmq
->
epoch
,
startTime
,
current
Time
);
return
NULL
;
}
tsem_timewait
(
&
tmq
->
rspSem
,
leftTime
*
1000
);
/*tscInfo("consumer:%" PRId64 ", (epoch %d) wait, start time %" PRId64 ", current time %" PRId64*/
/*", left time %" PRId64,*/
/*tmq->consumerId, tmq->epoch, startTime, currentTime, (timeout - passedTime));*/
tsem_timewait
(
&
tmq
->
rspSem
,
(
timeout
-
passedTime
));
}
else
{
// use tsem_timewait instead of tsem_wait to avoid unexpected stuck
tsem_timewait
(
&
tmq
->
rspSem
,
500
*
1000
);
tsem_timewait
(
&
tmq
->
rspSem
,
1000
);
}
}
}
...
...
source/os/src/osSemaphore.c
浏览文件 @
ec7df423
...
...
@@ -75,17 +75,18 @@ int32_t tsem_wait(tsem_t* sem) {
return
ret
;
}
int32_t
tsem_timewait
(
tsem_t
*
sem
,
int64_t
nanosecs
)
{
struct
timespec
ts
,
rel
;
FILETIME
ft_before
,
ft_after
;
int
rc
;
rel
.
tv_sec
=
0
;
rel
.
tv_nsec
=
nanosecs
;
GetSystemTimeAsFileTime
(
&
ft_before
);
int32_t
tsem_timewait
(
tsem_t
*
sem
,
int64_t
milis
)
{
return
tsem_wait
(
sem
);
#if 0
struct timespec ts;
timespec_get(&ts);
ts.tv_nsec += ms * 1000000;
ts.tv_sec += ts.tv_nsec / 1000000000;
ts.tv_nsec %= 1000000000;
/*GetSystemTimeAsFileTime(&ft_before);*/
// errno = 0;
rc
=
sem_timedwait
(
sem
,
pthread_win32_getabstime_np
(
&
ts
,
&
rel
)
);
rc = sem_timedwait(sem,
ts
);
/* This should have timed out */
// assert(errno == ETIMEDOUT);
...
...
@@ -102,6 +103,7 @@ int32_t tsem_timewait(tsem_t* sem, int64_t nanosecs) {
// return 1;
// }
return rc;
#endif
}
#elif defined(_TD_DARWIN_64)
...
...
@@ -133,9 +135,9 @@ int tsem_wait(tsem_t *psem) {
return
0
;
}
int
tsem_timewait
(
tsem_t
*
psem
,
int64_t
nanosec
s
)
{
int
tsem_timewait
(
tsem_t
*
psem
,
int64_t
mili
s
)
{
if
(
psem
==
NULL
||
*
psem
==
NULL
)
return
-
1
;
dispatch_semaphore_wait
(
*
psem
,
nanosecs
);
dispatch_semaphore_wait
(
*
psem
,
milis
*
1000
*
1000
);
return
0
;
}
...
...
@@ -227,15 +229,20 @@ int32_t tsem_wait(tsem_t* sem) {
return
ret
;
}
int32_t
tsem_timewait
(
tsem_t
*
sem
,
int64_t
nanosec
s
)
{
int32_t
tsem_timewait
(
tsem_t
*
sem
,
int64_t
m
s
)
{
int
ret
=
0
;
struct
timespec
tv
=
{
.
tv_sec
=
0
,
.
tv_nsec
=
nanosecs
,
};
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
,
&
t
v
))
==
-
1
&&
errno
==
EINTR
)
continue
;
while
((
ret
=
sem_timedwait
(
sem
,
&
t
s
))
==
-
1
&&
errno
==
EINTR
)
continue
;
return
ret
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录