refactor: do some internal refactor.

This commit is contained in:
Haojun Liao 2023-01-16 23:58:45 +08:00
parent a9ed671dc2
commit 7425820c21
5 changed files with 20 additions and 6 deletions

View File

@ -52,6 +52,20 @@ typedef struct STraceId {
sprintf(buf, "0x%" PRIx64 ":0x%" PRIx64 "", rootId, msgId); \
} while (0)
#define TRACE_TO_STR_(_traceId, _buf) \
do { \
int64_t rootId = (_traceId) != NULL ? (_traceId)->rootId : 0; \
int64_t msgId = (_traceId) != NULL ? (_traceId)->msgId : 0; \
char* _t = _buf; \
_t[0] = '0'; \
_t[1] = 'x'; \
_t += titoa(rootId, 16, &_t[2]); \
_t[0] = ':'; \
_t[1] = '0'; \
_t[2] = 'x'; \
_t += titoa(msgId, 16, &_t[3]); \
} while (0)
#ifdef __cplusplus
}
#endif

View File

@ -47,7 +47,7 @@ int32_t taosByteArrayToHexStr(char bytes[], int32_t len, char hexstr[]);
int32_t taosHexStrToByteArray(char hexstr[], char bytes[]);
int32_t tintToHex(uint64_t val, char hex[]);
int32_t tintToStr(uint64_t val, size_t radix, char str[]);
int32_t titoa(uint64_t val, size_t radix, char str[]);
char *taosIpStr(uint32_t ipInt);
uint32_t ip2uint(const char *const ip_addr);

View File

@ -1371,7 +1371,7 @@ int32_t doProcessMsgFromServer(void* param) {
STraceId* trace = &pMsg->info.traceId;
char tbuf[40] = {0};
TRACE_TO_STR(trace, tbuf);
TRACE_TO_STR_(trace, tbuf);
tscDebug("processMsgFromServer handle %p, message: %s, size:%d, code: %s, gtid: %s", pMsg->info.handle,
TMSG_INFO(pMsg->msgType), pMsg->contLen, tstrerror(pMsg->code), tbuf);

View File

@ -108,15 +108,15 @@ void tsdbHeadFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SHeadFile *pHeadF,
*(p++) = TD_DIRSEP[0];
*(p++) = 'v';
p += tintToStr(TD_VID(pTsdb->pVnode), 10, p);
p += titoa(TD_VID(pTsdb->pVnode), 10, p);
*(p++) = 'f';
p += tintToStr(fid, 10, p);
p += titoa(fid, 10, p);
memcpy(p, "ver", 3);
p += 3;
p += tintToStr(pHeadF->commitID, 10, p);
p += titoa(pHeadF->commitID, 10, p);
memcpy(p, ".head", 5);
p[5] = 0;
}

View File

@ -336,7 +336,7 @@ int32_t tintToHex(uint64_t val, char hex[]) {
return j;
}
int32_t tintToStr(uint64_t val, size_t radix, char str[]) {
int32_t titoa(uint64_t val, size_t radix, char str[]) {
if (radix < 2 || radix > 16) {
return 0;
}