[TD-2875]<fix>: use monotonic clock source to fix leap-second issue
This commit is contained in:
parent
a916028334
commit
fdf860eb84
|
@ -3,9 +3,10 @@ PROJECT(TDengine)
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/rpc/inc)
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/rpc/inc)
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/sync/inc)
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/sync/inc)
|
||||||
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/rmonotonic/inc)
|
||||||
AUX_SOURCE_DIRECTORY(src SRC)
|
AUX_SOURCE_DIRECTORY(src SRC)
|
||||||
ADD_LIBRARY(tutil ${SRC})
|
ADD_LIBRARY(tutil ${SRC})
|
||||||
TARGET_LINK_LIBRARIES(tutil pthread osdetail lz4 z)
|
TARGET_LINK_LIBRARIES(tutil pthread osdetail lz4 z rmonotonic)
|
||||||
|
|
||||||
IF (TD_LINUX)
|
IF (TD_LINUX)
|
||||||
TARGET_LINK_LIBRARIES(tutil m rt)
|
TARGET_LINK_LIBRARIES(tutil m rt)
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "tsched.h"
|
#include "tsched.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
#include "monotonic.h"
|
||||||
|
|
||||||
extern int8_t tscEmbedded;
|
extern int8_t tscEmbedded;
|
||||||
|
|
||||||
|
@ -186,6 +187,10 @@ static void removeTimer(uintptr_t id) {
|
||||||
unlockTimerList(list);
|
unlockTimerList(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int64_t getMonotonicMs(void) {
|
||||||
|
return (int64_t) getMonotonicUs() / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
static void addToWheel(tmr_obj_t* timer, uint32_t delay) {
|
static void addToWheel(tmr_obj_t* timer, uint32_t delay) {
|
||||||
timerAddRef(timer);
|
timerAddRef(timer);
|
||||||
// select a wheel for the timer, we are not an accurate timer,
|
// select a wheel for the timer, we are not an accurate timer,
|
||||||
|
@ -201,7 +206,7 @@ static void addToWheel(tmr_obj_t* timer, uint32_t delay) {
|
||||||
|
|
||||||
time_wheel_t* wheel = wheels + timer->wheel;
|
time_wheel_t* wheel = wheels + timer->wheel;
|
||||||
timer->prev = NULL;
|
timer->prev = NULL;
|
||||||
timer->expireAt = taosGetTimestampMs() + delay;
|
timer->expireAt = getMonotonicMs() + delay;
|
||||||
|
|
||||||
pthread_mutex_lock(&wheel->mutex);
|
pthread_mutex_lock(&wheel->mutex);
|
||||||
|
|
||||||
|
@ -334,7 +339,7 @@ tmr_h taosTmrStart(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosTimerLoopFunc(int signo) {
|
static void taosTimerLoopFunc(int signo) {
|
||||||
int64_t now = taosGetTimestampMs();
|
int64_t now = getMonotonicMs();
|
||||||
|
|
||||||
for (int i = 0; i < tListLen(wheels); i++) {
|
for (int i = 0; i < tListLen(wheels); i++) {
|
||||||
// `expried` is a temporary expire list.
|
// `expried` is a temporary expire list.
|
||||||
|
@ -501,7 +506,8 @@ static void taosTmrModuleInit(void) {
|
||||||
|
|
||||||
pthread_mutex_init(&tmrCtrlMutex, NULL);
|
pthread_mutex_init(&tmrCtrlMutex, NULL);
|
||||||
|
|
||||||
int64_t now = taosGetTimestampMs();
|
tmrInfo("ttimer monotonic clock source:%s", monotonicInit());
|
||||||
|
int64_t now = getMonotonicMs();
|
||||||
for (int i = 0; i < tListLen(wheels); i++) {
|
for (int i = 0; i < tListLen(wheels); i++) {
|
||||||
time_wheel_t* wheel = wheels + i;
|
time_wheel_t* wheel = wheels + i;
|
||||||
if (pthread_mutex_init(&wheel->mutex, NULL) != 0) {
|
if (pthread_mutex_init(&wheel->mutex, NULL) != 0) {
|
||||||
|
|
Loading…
Reference in New Issue