未验证 提交 62ac3d2e 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

Merge pull request #5295 from taosdata/hotfix/sangshuduo/TD-2210-use-tid

Hotfix/sangshuduo/td 2210 use tid
...@@ -334,7 +334,7 @@ typedef struct SSubqueryState { ...@@ -334,7 +334,7 @@ typedef struct SSubqueryState {
typedef struct SSqlObj { typedef struct SSqlObj {
void *signature; void *signature;
pthread_t owner; // owner of sql object, by which it is executed int64_t owner; // owner of sql object, by which it is executed
STscObj *pTscObj; STscObj *pTscObj;
int64_t rpcRid; int64_t rpcRid;
__async_cb_func_t fp; __async_cb_func_t fp;
......
...@@ -2578,11 +2578,7 @@ bool tscSetSqlOwner(SSqlObj* pSql) { ...@@ -2578,11 +2578,7 @@ bool tscSetSqlOwner(SSqlObj* pSql) {
SSqlRes* pRes = &pSql->res; SSqlRes* pRes = &pSql->res;
// set the sql object owner // set the sql object owner
#ifdef __APPLE__ int64_t threadId = taosGetSelfPthreadId();
pthread_t threadId = (pthread_t)taosGetSelfPthreadId();
#else // __APPLE__
uint64_t threadId = taosGetSelfPthreadId();
#endif // __APPLE__
if (atomic_val_compare_exchange_64(&pSql->owner, 0, threadId) != 0) { if (atomic_val_compare_exchange_64(&pSql->owner, 0, threadId) != 0) {
pRes->code = TSDB_CODE_QRY_IN_EXEC; pRes->code = TSDB_CODE_QRY_IN_EXEC;
return false; return false;
...@@ -2592,7 +2588,6 @@ bool tscSetSqlOwner(SSqlObj* pSql) { ...@@ -2592,7 +2588,6 @@ bool tscSetSqlOwner(SSqlObj* pSql) {
} }
void tscClearSqlOwner(SSqlObj* pSql) { void tscClearSqlOwner(SSqlObj* pSql) {
assert(taosCheckPthreadValid(pSql->owner));
atomic_store_64(&pSql->owner, 0); atomic_store_64(&pSql->owner, 0);
} }
......
...@@ -4536,13 +4536,13 @@ void *superQueryProcess(void *sarg) { ...@@ -4536,13 +4536,13 @@ void *superQueryProcess(void *sarg) {
} }
selectAndGetResult(winfo->taos, g_queryInfo.superQueryInfo.sql[i], tmpFile); selectAndGetResult(winfo->taos, g_queryInfo.superQueryInfo.sql[i], tmpFile);
int64_t t2 = taosGetTimestampUs(); int64_t t2 = taosGetTimestampUs();
printf("=[taosc] thread[%"PRIu64"] complete one sql, Spent %f s\n", taosGetSelfPthreadId(), (t2 - t1)/1000000.0); printf("=[taosc] thread[%"PRId64"] complete one sql, Spent %f s\n", taosGetSelfPthreadId(), (t2 - t1)/1000000.0);
} else { } else {
#ifdef TD_LOWA_CURL #ifdef TD_LOWA_CURL
int64_t t1 = taosGetTimestampUs(); int64_t t1 = taosGetTimestampUs();
int retCode = curlProceSql(g_queryInfo.host, g_queryInfo.port, g_queryInfo.superQueryInfo.sql[i], winfo->curl_handle); int retCode = curlProceSql(g_queryInfo.host, g_queryInfo.port, g_queryInfo.superQueryInfo.sql[i], winfo->curl_handle);
int64_t t2 = taosGetTimestampUs(); int64_t t2 = taosGetTimestampUs();
printf("=[restful] thread[%"PRIu64"] complete one sql, Spent %f s\n", taosGetSelfPthreadId(), (t2 - t1)/1000000.0); printf("=[restful] thread[%"PRId64"] complete one sql, Spent %f s\n", taosGetSelfPthreadId(), (t2 - t1)/1000000.0);
if (0 != retCode) { if (0 != retCode) {
printf("====curl return fail, threadID[%d]\n", winfo->threadID); printf("====curl return fail, threadID[%d]\n", winfo->threadID);
...@@ -4552,7 +4552,7 @@ void *superQueryProcess(void *sarg) { ...@@ -4552,7 +4552,7 @@ void *superQueryProcess(void *sarg) {
} }
} }
et = taosGetTimestampMs(); et = taosGetTimestampMs();
printf("==thread[%"PRIu64"] complete all sqls to specify tables once queries duration:%.6fs\n\n", taosGetSelfPthreadId(), (double)(et - st)/1000.0); printf("==thread[%"PRId64"] complete all sqls to specify tables once queries duration:%.6fs\n\n", taosGetSelfPthreadId(), (double)(et - st)/1000.0);
} }
return NULL; return NULL;
} }
...@@ -4601,7 +4601,7 @@ void *subQueryProcess(void *sarg) { ...@@ -4601,7 +4601,7 @@ void *subQueryProcess(void *sarg) {
} }
} }
et = taosGetTimestampMs(); et = taosGetTimestampMs();
printf("####thread[%"PRIu64"] complete all sqls to allocate all sub-tables[%d - %d] once queries duration:%.4fs\n\n", taosGetSelfPthreadId(), winfo->start_table_id, winfo->end_table_id, (double)(et - st)/1000.0); printf("####thread[%"PRId64"] complete all sqls to allocate all sub-tables[%d - %d] once queries duration:%.4fs\n\n", taosGetSelfPthreadId(), winfo->start_table_id, winfo->end_table_id, (double)(et - st)/1000.0);
} }
return NULL; return NULL;
} }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <mach/mach_error.h> #include <mach/mach_error.h>
#include <mach/semaphore.h> #include <mach/semaphore.h>
#include <mach/task.h> #include <mach/task.h>
#include <pthread.h>
static pthread_t sem_thread; static pthread_t sem_thread;
static pthread_once_t sem_once; static pthread_once_t sem_once;
...@@ -288,7 +289,9 @@ bool taosCheckPthreadValid(pthread_t thread) { ...@@ -288,7 +289,9 @@ bool taosCheckPthreadValid(pthread_t thread) {
} }
int64_t taosGetSelfPthreadId() { int64_t taosGetSelfPthreadId() {
return (int64_t)pthread_self(); uint64_t id;
pthread_threadid_np(0, &id);
return (int64_t) id;
} }
int64_t taosGetPthreadId(pthread_t thread) { int64_t taosGetPthreadId(pthread_t thread) {
......
...@@ -31,7 +31,14 @@ int tsem_wait(tsem_t* sem) { ...@@ -31,7 +31,14 @@ int tsem_wait(tsem_t* sem) {
#ifndef TAOS_OS_FUNC_SEMPHONE_PTHREAD #ifndef TAOS_OS_FUNC_SEMPHONE_PTHREAD
bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; } bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; }
int64_t taosGetSelfPthreadId() { return (int64_t)pthread_self(); }
int64_t taosGetSelfPthreadId() {
static __thread int id = 0;
if (id != 0) return id;
id = syscall(SYS_gettid);
return id;
}
int64_t taosGetPthreadId(pthread_t thread) { return (int64_t)thread; } int64_t taosGetPthreadId(pthread_t thread) { return (int64_t)thread; }
void taosResetPthread(pthread_t *thread) { *thread = 0; } void taosResetPthread(pthread_t *thread) { *thread = 0; }
bool taosComparePthread(pthread_t first, pthread_t second) { return first == second; } bool taosComparePthread(pthread_t first, pthread_t second) { return first == second; }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "ttimer.h" #include "ttimer.h"
#include "tulog.h" #include "tulog.h"
#include "tutil.h" #include "tutil.h"
#include <windows.h>
bool taosCheckPthreadValid(pthread_t thread) { return thread.p != NULL; } bool taosCheckPthreadValid(pthread_t thread) { return thread.p != NULL; }
...@@ -33,7 +34,9 @@ int64_t taosGetPthreadId(pthread_t thread) { ...@@ -33,7 +34,9 @@ int64_t taosGetPthreadId(pthread_t thread) {
#endif #endif
} }
int64_t taosGetSelfPthreadId() { return taosGetPthreadId(pthread_self()); } int64_t taosGetSelfPthreadId() {
return GetCurrentThreadId();
}
bool taosComparePthread(pthread_t first, pthread_t second) { bool taosComparePthread(pthread_t first, pthread_t second) {
return first.p == second.p; return first.p == second.p;
...@@ -55,4 +58,4 @@ int32_t taosGetCurrentAPPName(char *name, int32_t* len) { ...@@ -55,4 +58,4 @@ int32_t taosGetCurrentAPPName(char *name, int32_t* len) {
} }
return 0; return 0;
} }
\ No newline at end of file
...@@ -379,7 +379,7 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { ...@@ -379,7 +379,7 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) {
curTime = timeSecs.tv_sec; curTime = timeSecs.tv_sec;
ptm = localtime_r(&curTime, &Tm); ptm = localtime_r(&curTime, &Tm);
len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%08" PRIx64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour,
ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId()); ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId());
len += sprintf(buffer + len, "%s", flags); len += sprintf(buffer + len, "%s", flags);
...@@ -465,7 +465,7 @@ void taosPrintLongString(const char *flags, int32_t dflag, const char *format, . ...@@ -465,7 +465,7 @@ void taosPrintLongString(const char *flags, int32_t dflag, const char *format, .
curTime = timeSecs.tv_sec; curTime = timeSecs.tv_sec;
ptm = localtime_r(&curTime, &Tm); ptm = localtime_r(&curTime, &Tm);
len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%08" PRIx64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour,
ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId()); ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId());
len += sprintf(buffer + len, "%s", flags); len += sprintf(buffer + len, "%s", flags);
......
...@@ -248,7 +248,7 @@ void taosNotePrint(SNoteObj *pNote, const char *const format, ...) { ...@@ -248,7 +248,7 @@ void taosNotePrint(SNoteObj *pNote, const char *const format, ...) {
gettimeofday(&timeSecs, NULL); gettimeofday(&timeSecs, NULL);
curTime = timeSecs.tv_sec; curTime = timeSecs.tv_sec;
ptm = localtime_r(&curTime, &Tm); ptm = localtime_r(&curTime, &Tm);
len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%08" PRIx64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour,
ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId()); ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId());
va_start(argpointer, format); va_start(argpointer, format);
len += vsnprintf(buffer + len, MAX_NOTE_LINE_SIZE - len, format, argpointer); len += vsnprintf(buffer + len, MAX_NOTE_LINE_SIZE - len, format, argpointer);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册