fix:add-status-timestamp

This commit is contained in:
dmchen 2025-02-27 15:22:33 +08:00
parent 031f176aa1
commit 93992f3d6e
7 changed files with 44 additions and 4 deletions

View File

@ -1845,6 +1845,7 @@ typedef struct {
int32_t statusSeq; int32_t statusSeq;
int64_t ipWhiteVer; int64_t ipWhiteVer;
int64_t analVer; int64_t analVer;
int64_t timestamp;
} SStatusReq; } SStatusReq;
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq); int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);

View File

@ -82,7 +82,7 @@ int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec
int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision); int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision);
int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t ts, int32_t precision); int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t ts, int32_t precision);
char* formatTimestampLocal(char* buf, int64_t val, int precision);
struct STm { struct STm {
struct tm tm; struct tm tm;
int64_t fsec; // in NANOSECOND int64_t fsec; // in NANOSECOND

View File

@ -1477,6 +1477,8 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
TAOS_CHECK_EXIT(tEncodeI64(&encoder, pload->syncCommitIndex)); TAOS_CHECK_EXIT(tEncodeI64(&encoder, pload->syncCommitIndex));
} }
TAOS_CHECK_EXIT(tEncodeI64(&encoder, pReq->timestamp));
tEndEncode(&encoder); tEndEncode(&encoder);
_exit: _exit:
@ -1614,6 +1616,10 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
} }
} }
if (!tDecodeIsEnd(&decoder)) {
TAOS_CHECK_EXIT(tDecodeI64(&decoder, &pReq->timestamp));
}
tEndDecode(&decoder); tEndDecode(&decoder);
_exit: _exit:

View File

@ -1000,6 +1000,34 @@ int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precisio
TAOS_RETURN(TSDB_CODE_SUCCESS); TAOS_RETURN(TSDB_CODE_SUCCESS);
} }
char* formatTimestampLocal(char* buf, int64_t val, int precision) {
time_t tt;
if (precision == TSDB_TIME_PRECISION_MICRO) {
tt = (time_t)(val / 1000000);
}
if (precision == TSDB_TIME_PRECISION_NANO) {
tt = (time_t)(val / 1000000000);
} else {
tt = (time_t)(val / 1000);
}
struct tm tm;
if (taosLocalTime(&tt, &tm, NULL, 0, NULL) == NULL) {
return NULL;
}
size_t pos = taosStrfTime(buf, 32, "%Y-%m-%d %H:%M:%S", &tm);
if (precision == TSDB_TIME_PRECISION_MICRO) {
sprintf(buf + pos, ".%06d", (int)(val % 1000000));
} else if (precision == TSDB_TIME_PRECISION_NANO) {
sprintf(buf + pos, ".%09d", (int)(val % 1000000000));
} else {
sprintf(buf + pos, ".%03d", (int)(val % 1000));
}
return buf;
}
int32_t taosTs2Tm(int64_t ts, int32_t precision, struct STm* tm, timezone_t tz) { int32_t taosTs2Tm(int64_t ts, int32_t precision, struct STm* tm, timezone_t tz) {
tm->fsec = ts % TICK_PER_SECOND[precision] * (TICK_PER_SECOND[TSDB_TIME_PRECISION_NANO] / TICK_PER_SECOND[precision]); tm->fsec = ts % TICK_PER_SECOND[precision] * (TICK_PER_SECOND[TSDB_TIME_PRECISION_NANO] / TICK_PER_SECOND[precision]);
time_t t = ts / TICK_PER_SECOND[precision]; time_t t = ts / TICK_PER_SECOND[precision];

View File

@ -167,6 +167,7 @@ static void dmProcessStatusRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) {
void dmSendStatusReq(SDnodeMgmt *pMgmt) { void dmSendStatusReq(SDnodeMgmt *pMgmt) {
int32_t code = 0; int32_t code = 0;
SStatusReq req = {0}; SStatusReq req = {0};
req.timestamp = taosGetTimestampMs();
dDebug("send status req to mnode, statusSeq:%d, begin to mgnt lock", pMgmt->statusSeq); dDebug("send status req to mnode, statusSeq:%d, begin to mgnt lock", pMgmt->statusSeq);
(void)taosThreadRwlockRdlock(&pMgmt->pData->lock); (void)taosThreadRwlockRdlock(&pMgmt->pData->lock);

View File

@ -782,8 +782,12 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
bool needCheck = !online || dnodeChanged || reboot || supportVnodesChanged || analVerChanged || bool needCheck = !online || dnodeChanged || reboot || supportVnodesChanged || analVerChanged ||
pMnode->ipWhiteVer != statusReq.ipWhiteVer || encryptKeyChanged || enableWhiteListChanged; pMnode->ipWhiteVer != statusReq.ipWhiteVer || encryptKeyChanged || enableWhiteListChanged;
const STraceId *trace = &pReq->info.traceId; const STraceId *trace = &pReq->info.traceId;
mGTrace("dnode:%d, status received, accessTimes:%d check:%d online:%d reboot:%d changed:%d statusSeq:%d", pDnode->id, char timestamp[TD_TIME_STR_LEN] = {0};
pDnode->accessTimes, needCheck, online, reboot, dnodeChanged, statusReq.statusSeq); if (mDebugFlag & DEBUG_TRACE) (void)formatTimestampLocal(timestamp, statusReq.timestamp, TSDB_TIME_PRECISION_MILLI);
mGTrace(
"dnode:%d, status received, accessTimes:%d check:%d online:%d reboot:%d changed:%d statusSeq:%d "
"timestamp:%s",
pDnode->id, pDnode->accessTimes, needCheck, online, reboot, dnodeChanged, statusReq.statusSeq, timestamp);
if (reboot) { if (reboot) {
tsGrantHBInterval = GRANT_HEART_BEAT_MIN; tsGrantHBInterval = GRANT_HEART_BEAT_MIN;

View File

@ -116,7 +116,7 @@ static void syncPrintTime(bool formatTime, int32_t* len, int64_t tsMs, int32_t i
if (formatTime) { if (formatTime) {
char pBuf[TD_TIME_STR_LEN] = {0}; char pBuf[TD_TIME_STR_LEN] = {0};
if (tsMs > 0) { if (tsMs > 0) {
if (taosFormatUtcTime(pBuf, TD_TIME_STR_LEN, tsMs, TSDB_TIME_PRECISION_MILLI) != 0) { if (formatTimestampLocal(pBuf, tsMs, TSDB_TIME_PRECISION_MILLI) == NULL) {
pBuf[0] = '\0'; pBuf[0] = '\0';
} }
} }