提交 9a5db032 编写于 作者: dengyihao's avatar dengyihao

opt log time

上级 1af09ec9
...@@ -79,6 +79,7 @@ typedef struct SCliThrd { ...@@ -79,6 +79,7 @@ typedef struct SCliThrd {
uint64_t nextTimeout; // next timeout uint64_t nextTimeout; // next timeout
void* pTransInst; // void* pTransInst; //
SHashObj* fqdn2ipCache;
SCvtAddr cvtAddr; SCvtAddr cvtAddr;
SCliMsg* stopMsg; SCliMsg* stopMsg;
...@@ -135,6 +136,9 @@ static FORCE_INLINE void cliMayCvtFqdnToIp(SEpSet* pEpSet, SCvtAddr* pCvtAddr); ...@@ -135,6 +136,9 @@ static FORCE_INLINE void cliMayCvtFqdnToIp(SEpSet* pEpSet, SCvtAddr* pCvtAddr);
static FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* resp); static FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* resp);
static FORCE_INLINE uint32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn);
static FORCE_INLINE void cliUpdateFqdnCache(SHashObj* cache, char* fqdn);
// process data read from server, add decompress etc later // process data read from server, add decompress etc later
static void cliHandleResp(SCliConn* conn); static void cliHandleResp(SCliConn* conn);
// handle except about conn // handle except about conn
...@@ -154,7 +158,7 @@ static FORCE_INLINE int cliRBChoseIdx(STrans* pTransInst); ...@@ -154,7 +158,7 @@ static FORCE_INLINE int cliRBChoseIdx(STrans* pTransInst);
static FORCE_INLINE void transDestroyConnCtx(STransConnCtx* ctx); static FORCE_INLINE void transDestroyConnCtx(STransConnCtx* ctx);
// thread obj // thread obj
static SCliThrd* createThrdObj(); static SCliThrd* createThrdObj(void* trans);
static void destroyThrdObj(SCliThrd* pThrd); static void destroyThrdObj(SCliThrd* pThrd);
static void cliWalkCb(uv_handle_t* handle, void* arg); static void cliWalkCb(uv_handle_t* handle, void* arg);
...@@ -930,6 +934,21 @@ FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* pResp) { ...@@ -930,6 +934,21 @@ FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* pResp) {
return 0; return 0;
} }
static FORCE_INLINE uint32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn) {
uint32_t addr = 0;
uint32_t* v = taosHashGet(cache, fqdn, strlen(fqdn));
if (v == NULL) {
addr = taosGetIpv4FromFqdn(fqdn);
taosHashPut(cache, fqdn, strlen(fqdn), &addr, sizeof(addr));
} else {
addr = *v;
}
return addr;
}
static FORCE_INLINE void cliUpdateFqdnCache(SHashObj* cache, char* fqdn) {
// impl later
return;
}
void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
STrans* pTransInst = pThrd->pTransInst; STrans* pTransInst = pThrd->pTransInst;
...@@ -985,7 +1004,8 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { ...@@ -985,7 +1004,8 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
struct sockaddr_in addr; struct sockaddr_in addr;
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_addr.s_addr = taosGetIpv4FromFqdn(conn->ip);
addr.sin_addr.s_addr = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, conn->ip);
addr.sin_port = (uint16_t)htons((uint16_t)conn->port); addr.sin_port = (uint16_t)htons((uint16_t)conn->port);
tTrace("%s conn %p try to connect to %s:%d", pTransInst->label, conn, conn->ip, conn->port); tTrace("%s conn %p try to connect to %s:%d", pTransInst->label, conn, conn->ip, conn->port);
ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb);
...@@ -1132,10 +1152,7 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, ...@@ -1132,10 +1152,7 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads,
cli->pThreadObj = (SCliThrd**)taosMemoryCalloc(cli->numOfThreads, sizeof(SCliThrd*)); cli->pThreadObj = (SCliThrd**)taosMemoryCalloc(cli->numOfThreads, sizeof(SCliThrd*));
for (int i = 0; i < cli->numOfThreads; i++) { for (int i = 0; i < cli->numOfThreads; i++) {
SCliThrd* pThrd = createThrdObj(); SCliThrd* pThrd = createThrdObj(shandle);
pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime);
pThrd->pTransInst = shandle;
int err = taosThreadCreate(&pThrd->thread, NULL, cliWorkThread, (void*)(pThrd)); int err = taosThreadCreate(&pThrd->thread, NULL, cliWorkThread, (void*)(pThrd));
if (err == 0) { if (err == 0) {
tDebug("success to create tranport-cli thread:%d", i); tDebug("success to create tranport-cli thread:%d", i);
...@@ -1164,7 +1181,9 @@ static FORCE_INLINE void destroyCmsg(void* arg) { ...@@ -1164,7 +1181,9 @@ static FORCE_INLINE void destroyCmsg(void* arg) {
taosMemoryFree(pMsg); taosMemoryFree(pMsg);
} }
static SCliThrd* createThrdObj() { static SCliThrd* createThrdObj(void* trans) {
STrans* pTransInst = trans;
SCliThrd* pThrd = (SCliThrd*)taosMemoryCalloc(1, sizeof(SCliThrd)); SCliThrd* pThrd = (SCliThrd*)taosMemoryCalloc(1, sizeof(SCliThrd));
QUEUE_INIT(&pThrd->msg); QUEUE_INIT(&pThrd->msg);
...@@ -1193,6 +1212,10 @@ static SCliThrd* createThrdObj() { ...@@ -1193,6 +1212,10 @@ static SCliThrd* createThrdObj() {
transDQCreate(pThrd->loop, &pThrd->timeoutQueue); transDQCreate(pThrd->loop, &pThrd->timeoutQueue);
pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime);
pThrd->pTransInst = trans;
pThrd->fqdn2ipCache = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
pThrd->quit = false; pThrd->quit = false;
return pThrd; return pThrd;
} }
...@@ -1217,6 +1240,7 @@ static void destroyThrdObj(SCliThrd* pThrd) { ...@@ -1217,6 +1240,7 @@ static void destroyThrdObj(SCliThrd* pThrd) {
taosArrayDestroy(pThrd->timerList); taosArrayDestroy(pThrd->timerList);
taosMemoryFree(pThrd->prepare); taosMemoryFree(pThrd->prepare);
taosMemoryFree(pThrd->loop); taosMemoryFree(pThrd->loop);
taosHashCleanup(pThrd->fqdn2ipCache);
taosMemoryFree(pThrd); taosMemoryFree(pThrd);
} }
......
...@@ -494,7 +494,7 @@ struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, time_t tz ...@@ -494,7 +494,7 @@ struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, time_t tz
} else { } else {
localtime_s(result, timep); localtime_s(result, timep);
} }
#else #elif defined(LINUX)
time_t secsMin = 60, secsHour = 3600, secsDay = 3600 * 24; time_t secsMin = 60, secsHour = 3600, secsDay = 3600 * 24;
time_t t = *timep; time_t t = *timep;
...@@ -536,6 +536,8 @@ struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, time_t tz ...@@ -536,6 +536,8 @@ struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, time_t tz
result->tm_mday = days + 1; /* Add 1 since our 'days' is zero-based. */ result->tm_mday = days + 1; /* Add 1 since our 'days' is zero-based. */
result->tm_year -= 1900; /* Surprisingly tm_year is year-1900. */ result->tm_year -= 1900; /* Surprisingly tm_year is year-1900. */
#else
localtime_r(timep, result);
#endif #endif
return result; return result;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册