[TBASE-1060]
This commit is contained in:
parent
d3941fe95b
commit
2a11363e0c
|
@ -23,6 +23,27 @@
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
|
||||||
|
void tscSaveSlowQueryFp(void *handle, void *tmrId);
|
||||||
|
void *tscSlowQueryConn = NULL;
|
||||||
|
bool tscSlowQueryConnInitialized = false;
|
||||||
|
TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, int port, void (*fp)(void *, TAOS_RES *, int),
|
||||||
|
void *param, void **taos);
|
||||||
|
|
||||||
|
void tscInitConnCb(void *param, TAOS_RES *result, int code) {
|
||||||
|
char *sql = param;
|
||||||
|
if (code < 0) {
|
||||||
|
tscError("taos:%p, slow query connect failed, code:%d", tscSlowQueryConn, code);
|
||||||
|
taos_close(tscSlowQueryConn);
|
||||||
|
tscSlowQueryConn = NULL;
|
||||||
|
tscSlowQueryConnInitialized = false;
|
||||||
|
free(sql);
|
||||||
|
} else {
|
||||||
|
tscTrace("taos:%p, slow query connect success, code:%d", tscSlowQueryConn, code);
|
||||||
|
tscSlowQueryConnInitialized = true;
|
||||||
|
tscSaveSlowQueryFp(sql, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void tscAddIntoSqlList(SSqlObj *pSql) {
|
void tscAddIntoSqlList(SSqlObj *pSql) {
|
||||||
static uint32_t queryId = 1;
|
static uint32_t queryId = 1;
|
||||||
|
|
||||||
|
@ -48,26 +69,28 @@ void tscAddIntoSqlList(SSqlObj *pSql) {
|
||||||
void tscSaveSlowQueryFpCb(void *param, TAOS_RES *result, int code) {
|
void tscSaveSlowQueryFpCb(void *param, TAOS_RES *result, int code) {
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
tscError("failed to save slow query, code:%d", code);
|
tscError("failed to save slow query, code:%d", code);
|
||||||
|
} else {
|
||||||
|
tscTrace("success to save slow query, code:%d", code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscSaveSlowQueryFp(void *handle, void *tmrId) {
|
void tscSaveSlowQueryFp(void *handle, void *tmrId) {
|
||||||
char *sql = handle;
|
char *sql = handle;
|
||||||
|
|
||||||
static void *taos = NULL;
|
if (!tscSlowQueryConnInitialized) {
|
||||||
if (taos == NULL) {
|
if (tscSlowQueryConn == NULL) {
|
||||||
taos = taos_connect(NULL, "monitor", tsInternalPass, NULL, 0);
|
tscTrace("start to init slow query connect");
|
||||||
if (taos == NULL) {
|
taos_connect_a(NULL, "monitor", tsInternalPass, "", 0, tscInitConnCb, sql, &tscSlowQueryConn);
|
||||||
tscError("failed to save slow query, can't connect to server");
|
} else {
|
||||||
|
tscError("taos:%p, slow query connect is already initialized", tscSlowQueryConn);
|
||||||
free(sql);
|
free(sql);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
tscTrace("taos:%p, save slow query:%s", tscSlowQueryConn, sql);
|
||||||
tscTrace("save slow query:sql", sql);
|
taos_query_a(tscSlowQueryConn, sql, tscSaveSlowQueryFpCb, NULL);
|
||||||
taos_query_a(taos, sql, tscSaveSlowQueryFpCb, NULL);
|
|
||||||
free(sql);
|
free(sql);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void tscSaveSlowQuery(SSqlObj *pSql) {
|
void tscSaveSlowQuery(SSqlObj *pSql) {
|
||||||
const static int64_t SLOW_QUERY_INTERVAL = 3000000L;
|
const static int64_t SLOW_QUERY_INTERVAL = 3000000L;
|
||||||
|
|
Loading…
Reference in New Issue