diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c
index fb175618c0429d08e86976c5dc7f20c91918f653..e98acfc9a68b2dfd108e047b580b115e72bcac42 100644
--- a/src/client/src/TSDBJNIConnector.c
+++ b/src/client/src/TSDBJNIConnector.c
@@ -13,8 +13,6 @@
* along with this program. If not, see .
*/
-#include
-
#include "os.h"
#include "com_taosdata_jdbc_TSDBJNIConnector.h"
#include "taos.h"
diff --git a/src/client/src/tscAst.c b/src/client/src/tscAst.c
index 845a9fd36d1a694d39e35f1ad3c0b06ec0f1b59c..fe0921c64d72af1d36202dfd57d8c93a33cc0b4d 100644
--- a/src/client/src/tscAst.c
+++ b/src/client/src/tscAst.c
@@ -13,12 +13,6 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
-#include
-#include
-
#include "os.h"
#include "taosmsg.h"
#include "tast.h"
diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c
index 6e0e1ae7c5c73720a53558701b01fb79af592e27..aad02959591eab0b1ea48e0336ea4d0eed3774b6 100644
--- a/src/client/src/tscAsync.c
+++ b/src/client/src/tscAsync.c
@@ -13,8 +13,7 @@
* along with this program. If not, see .
*/
-#include
-#include
+#include "os.h"
#include "tlog.h"
#include "trpc.h"
diff --git a/src/client/src/tscCache.c b/src/client/src/tscCache.c
index 866b6e7dbc137c6e07d21d1e140ded39d1f4cd88..f508857ce1bc1477dc898de400b96c234ffe9bd8 100644
--- a/src/client/src/tscCache.c
+++ b/src/client/src/tscCache.c
@@ -13,14 +13,7 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include "os.h"
#include "tglobalcfg.h"
#include "tlog.h"
diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c
index 7eeb87832a37e36832346522f89ccb7cc84c4d91..c23536f63170876bb4b3998fa38fafbc8c3cd23d 100644
--- a/src/client/src/tscFunctionImpl.c
+++ b/src/client/src/tscFunctionImpl.c
@@ -15,16 +15,6 @@
#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
#include "os.h"
#include "taosmsg.h"
#include "tast.h"
diff --git a/src/client/src/tscJoinProcess.c b/src/client/src/tscJoinProcess.c
index 4965498eff0dbadbbf87d3e04d757e6afd002fa4..dfeebc8c61e868b9b7c558287b40ad0fbc093099 100644
--- a/src/client/src/tscJoinProcess.c
+++ b/src/client/src/tscJoinProcess.c
@@ -13,13 +13,6 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
-#include
-#include
-#include
-
#include "os.h"
#include "tcache.h"
#include "tscJoinProcess.h"
diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c
index 9afb74fec201353dc5980aa572a1a7af2fe4cae9..d217d0958833fad40c2a2aaf7cb135e43222f56c 100644
--- a/src/client/src/tscLocal.c
+++ b/src/client/src/tscLocal.c
@@ -13,9 +13,7 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
+#include "os.h"
#include "taosmsg.h"
#include "tcache.h"
diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c
index 37a32e9ebb360ed0a3bc1f9f97a5b70955782ec5..c8ce728de15858e2628bb6a8debd011197ecd184 100644
--- a/src/client/src/tscParseInsert.c
+++ b/src/client/src/tscParseInsert.c
@@ -21,22 +21,8 @@
#pragma GCC diagnostic ignored "-Woverflow"
#pragma GCC diagnostic ignored "-Wunused-variable"
-#include
-#include
-#include
-
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "ihash.h"
#include "os.h"
+#include "ihash.h"
#include "tscSecondaryMerge.h"
#include "tscUtil.h"
#include "tschemautil.h"
diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c
index e956d6159e4a02707e15197672b59edc66466043..03f644ac36ddb985402a7a72ce68283abaafc63a 100644
--- a/src/client/src/tscPrepare.c
+++ b/src/client/src/tscPrepare.c
@@ -13,9 +13,6 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "taos.h"
#include "tsclient.h"
#include "tsql.h"
diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c
index 7472a9dac350a2218f5fe5352a442fb16e46094c..350167a3b35ba8e1dbf32c5b93bb6011e09adddf 100644
--- a/src/client/src/tscProfile.c
+++ b/src/client/src/tscProfile.c
@@ -13,9 +13,6 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "os.h"
#include "tlog.h"
#include "tsclient.h"
@@ -23,6 +20,27 @@
#include "ttimer.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) {
static uint32_t queryId = 1;
@@ -47,26 +65,28 @@ void tscAddIntoSqlList(SSqlObj *pSql) {
void tscSaveSlowQueryFpCb(void *param, TAOS_RES *result, int code) {
if (code < 0) {
- tscError("failed to save slowquery, 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) {
char *sql = handle;
- static void *taos = NULL;
- if (taos == NULL) {
- taos = taos_connect(NULL, "monitor", tsInternalPass, NULL, 0);
- if (taos == NULL) {
- tscError("failed to save slow query, can't connect to server");
+ if (!tscSlowQueryConnInitialized) {
+ if (tscSlowQueryConn == NULL) {
+ tscTrace("start to init slow query connect");
+ taos_connect_a(NULL, "monitor", tsInternalPass, "", 0, tscInitConnCb, sql, &tscSlowQueryConn);
+ } else {
+ tscError("taos:%p, slow query connect is already initialized", tscSlowQueryConn);
free(sql);
- return;
}
+ } else {
+ tscTrace("taos:%p, save slow query:%s", tscSlowQueryConn, sql);
+ taos_query_a(tscSlowQueryConn, sql, tscSaveSlowQueryFpCb, NULL);
+ free(sql);
}
-
- tscTrace("save slow query:sql", sql);
- taos_query_a(taos, sql, tscSaveSlowQueryFpCb, NULL);
- free(sql);
}
void tscSaveSlowQuery(SSqlObj *pSql) {
diff --git a/src/client/src/tscSQLParserImpl.c b/src/client/src/tscSQLParserImpl.c
index 7e1b4a7cf19e75274f65f10d8344c200c7ad8fb7..4fefe1665c514bce7215c395132c7b4290d433ce 100644
--- a/src/client/src/tscSQLParserImpl.c
+++ b/src/client/src/tscSQLParserImpl.c
@@ -13,13 +13,6 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
-#include
-#include
-#include
-
#include "os.h"
#include "tglobalcfg.h"
#include "tsql.h"
diff --git a/src/client/src/tscSchemaUtil.c b/src/client/src/tscSchemaUtil.c
index 9728811ae70286264ed0ee6d91b144a1743a1120..5e50c27ab1af180009a4aa13a221073f33168a5f 100644
--- a/src/client/src/tscSchemaUtil.c
+++ b/src/client/src/tscSchemaUtil.c
@@ -13,10 +13,6 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
-
#include "os.h"
#include "taosmsg.h"
#include "tschemautil.h"
diff --git a/src/client/src/tscSecondaryMerge.c b/src/client/src/tscSecondaryMerge.c
index ac2638f635961bcdab3593994228164d79fdb6a0..398cd1cca6ceb4de0042788e78ab3336448019ed 100644
--- a/src/client/src/tscSecondaryMerge.c
+++ b/src/client/src/tscSecondaryMerge.c
@@ -13,13 +13,8 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
-#include
-#include
-#include "tlosertree.h"
+#include "os.h"
#include "tlosertree.h"
#include "tscSecondaryMerge.h"
#include "tscUtil.h"
diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c
index 6edec3d4773f94bd0c6de975653dfd56f6d4f8a8..49368e4d177b200e37af1f0572d24b1f3fba60f3 100644
--- a/src/client/src/tscServer.c
+++ b/src/client/src/tscServer.c
@@ -13,12 +13,6 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
-#include
-#include
-
#include "os.h"
#include "tcache.h"
#include "trpc.h"
@@ -2848,7 +2842,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) {
return msgLen;
}
-int tscEstimateBuildHeartBeatMsgLength(SSqlObj *pSql) {
+int tscEstimateHeartBeatMsgLength(SSqlObj *pSql) {
int size = 0;
STscObj *pObj = pSql->pTscObj;
@@ -2881,7 +2875,7 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql) {
pthread_mutex_lock(&pObj->mutex);
- size = tscEstimateBuildHeartBeatMsgLength(pSql);
+ size = tscEstimateHeartBeatMsgLength(pSql);
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) {
tscError("%p failed to malloc for heartbeat msg", pSql);
return -1;
@@ -3613,7 +3607,7 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *meterId) {
code = tscDoGetMeterMeta(pSql, meterId, 0); // todo ??
} else {
- tscTrace("%p metric query not update metric meta, numOfTags:%d, numOfCols:%d, uid:%d, addr:%p", pSql,
+ tscTrace("%p metric query not update metric meta, numOfTags:%d, numOfCols:%d, uid:%lld, addr:%p", pSql,
pMeterMetaInfo->pMeterMeta->numOfTags, pCmd->numOfCols, pMeterMetaInfo->pMeterMeta->uid,
pMeterMetaInfo->pMeterMeta);
}
diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c
index fa72b18d164f8db92e6da9e2baf77621d61f9145..10eac0bb637356f22ca42553e11c6e68a5873cd5 100644
--- a/src/client/src/tscSql.c
+++ b/src/client/src/tscSql.c
@@ -13,9 +13,6 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "os.h"
#include "tcache.h"
#include "tlog.h"
diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c
index dee8f02118c0fd2ef22428d67393a801073c23c8..bcbcaba4c4a207c07763198db72357459630b977 100644
--- a/src/client/src/tscSub.c
+++ b/src/client/src/tscSub.c
@@ -13,7 +13,7 @@
* along with this program. If not, see .
*/
-#include
+#include "os.h"
#include "shash.h"
#include "taos.h"
diff --git a/src/client/src/tscSyntaxtreefunction.c b/src/client/src/tscSyntaxtreefunction.c
index 00781919e466c5049de84650eacd1d0badf58b72..bbd30c1fa942c7fd9132f24a4e03ca2e034fd30b 100644
--- a/src/client/src/tscSyntaxtreefunction.c
+++ b/src/client/src/tscSyntaxtreefunction.c
@@ -13,10 +13,7 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
-#include
+#include "os.h"
#include "tscSyntaxtreefunction.h"
#include "tsql.h"
diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c
index 7ebd43cd19d2b6b1f94ec21651c0fa3c2578c84f..708ceee4054c2f22dd44d1cf5a5c72a419994eff 100644
--- a/src/client/src/tscSystem.c
+++ b/src/client/src/tscSystem.c
@@ -13,15 +13,6 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
#include "os.h"
#include "taosmsg.h"
#include "tcache.h"
diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c
index ec5c9806129197929667bfa30f2e55ce1f7446d7..579365647718d177053e114029ff52661b369086 100644
--- a/src/client/src/tscUtil.c
+++ b/src/client/src/tscUtil.c
@@ -13,10 +13,6 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
-
#include "os.h"
#include "ihash.h"
#include "taosmsg.h"
diff --git a/src/connector/go/src/taosSql/taosSqlCgo.go b/src/connector/go/src/taosSql/taosSqlCgo.go
index e240ac44ec23116c332b250499848e42143066f4..fcef14045fe1252f3636598576b2c6e753315aed 100755
--- a/src/connector/go/src/taosSql/taosSqlCgo.go
+++ b/src/connector/go/src/taosSql/taosSqlCgo.go
@@ -29,46 +29,47 @@ import (
"unsafe"
)
-func (mc *taosConn) taosConnect(ip, user, pass, db string, port int) (taos unsafe.Pointer, err error){
+func (mc *taosConn) taosConnect(ip, user, pass, db string, port int) (taos unsafe.Pointer, err error) {
cuser := C.CString(user)
cpass := C.CString(pass)
- cip := C.CString(ip)
- cdb := C.CString(db)
+ cip := C.CString(ip)
+ cdb := C.CString(db)
defer C.free(unsafe.Pointer(cip))
defer C.free(unsafe.Pointer(cuser))
defer C.free(unsafe.Pointer(cpass))
defer C.free(unsafe.Pointer(cdb))
taosObj := C.taos_connect(cip, cuser, cpass, cdb, (C.int)(port))
- if taosObj == nil {
- return nil, errors.New("taos_connect() fail!")
- }
+ if taosObj == nil {
+ return nil, errors.New("taos_connect() fail!")
+ }
- return (unsafe.Pointer)(taosObj), nil
-}
+ return (unsafe.Pointer)(taosObj), nil
+}
func (mc *taosConn) taosQuery(sqlstr string) (int, error) {
- taosLog.Printf("taosQuery() input sql:%s\n", sqlstr)
+ //taosLog.Printf("taosQuery() input sql:%s\n", sqlstr)
- csqlstr := C.CString(sqlstr)
+ csqlstr := C.CString(sqlstr)
defer C.free(unsafe.Pointer(csqlstr))
- code := int(C.taos_query(mc.taos, csqlstr))
+ code := int(C.taos_query(mc.taos, csqlstr))
- if 0 != code {
- mc.taos_error()
- errStr := C.GoString(C.taos_errstr(mc.taos))
- taosLog.Println("taos_query() failed:", errStr)
- return 0, errors.New(errStr)
- }
+ if 0 != code {
+ mc.taos_error()
+ errStr := C.GoString(C.taos_errstr(mc.taos))
+ taosLog.Println("taos_query() failed:", errStr)
+ taosLog.Printf("taosQuery() input sql:%s\n", sqlstr)
+ return 0, errors.New(errStr)
+ }
- // read result and save into mc struct
- num_fields := int(C.taos_field_count(mc.taos))
- if 0 == num_fields { // there are no select and show kinds of commands
- mc.affectedRows = int(C.taos_affected_rows(mc.taos))
- mc.insertId = 0
- }
+ // read result and save into mc struct
+ num_fields := int(C.taos_field_count(mc.taos))
+ if 0 == num_fields { // there are no select and show kinds of commands
+ mc.affectedRows = int(C.taos_affected_rows(mc.taos))
+ mc.insertId = 0
+ }
- return num_fields, nil
+ return num_fields, nil
}
func (mc *taosConn) taos_close() {
@@ -76,8 +77,8 @@ func (mc *taosConn) taos_close() {
}
func (mc *taosConn) taos_error() {
- // free local resouce: allocated memory/metric-meta refcnt
- //var pRes unsafe.Pointer
- pRes := C.taos_use_result(mc.taos)
- C.taos_free_result(pRes)
+ // free local resouce: allocated memory/metric-meta refcnt
+ //var pRes unsafe.Pointer
+ pRes := C.taos_use_result(mc.taos)
+ C.taos_free_result(pRes)
}
diff --git a/src/inc/tglobalcfg.h b/src/inc/tglobalcfg.h
index e83c89593fb11e7e0eba74526e43811f8799af3e..026d48ba0822ec7a16f9342f1905cefd991796d4 100644
--- a/src/inc/tglobalcfg.h
+++ b/src/inc/tglobalcfg.h
@@ -169,6 +169,8 @@ extern uint32_t debugFlag;
extern uint32_t odbcdebugFlag;
extern uint32_t qdebugFlag;
+extern uint32_t taosMaxTmrCtrl;
+
extern int tsRpcTimer;
extern int tsRpcMaxTime;
extern int tsUdpDelay;
diff --git a/src/inc/ttimer.h b/src/inc/ttimer.h
index ddfd3f1fdf2a6d5e6a46ad16a047ed209ebcce8b..b9bbbb04dd5a22252a8d9e587977324c7c51221e 100644
--- a/src/inc/ttimer.h
+++ b/src/inc/ttimer.h
@@ -25,6 +25,7 @@ typedef void (*TAOS_TMR_CALLBACK)(void *, void *);
extern uint32_t tmrDebugFlag;
extern int taosTmrThreads;
+extern uint32_t taosMaxTmrCtrl;
#define tmrError(...) \
do { if (tmrDebugFlag & DEBUG_ERROR) { \
@@ -41,7 +42,6 @@ extern int taosTmrThreads;
tprintf("TMR ", tmrDebugFlag, __VA_ARGS__); \
} } while(0)
-#define MAX_NUM_OF_TMRCTL 32
#define MSECONDS_PER_TICK 5
void *taosTmrInit(int maxTmr, int resoultion, int longest, const char *label);
diff --git a/src/inc/tutil.h b/src/inc/tutil.h
index f63f8b6cec6d8d5c5f610e23126c7d8fa6cf8c5f..884e448aae5b6b0096c4ca4eb481c773f6de7162 100644
--- a/src/inc/tutil.h
+++ b/src/inc/tutil.h
@@ -169,8 +169,6 @@ int32_t taosInitTimer(void (*callback)(int), int32_t ms);
*/
uint32_t MurmurHash3_32(const void *key, int32_t len);
-bool taosCheckDbName(char *db, char *monitordb);
-
bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len);
bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
diff --git a/src/os/linux/inc/os.h b/src/os/linux/inc/os.h
index 78065e6df0590755d098563316fbe214c695658d..ee65965a5b44420f12ee6c053879908282999a09 100644
--- a/src/os/linux/inc/os.h
+++ b/src/os/linux/inc/os.h
@@ -1,17 +1,17 @@
/*
-* Copyright (c) 2019 TAOS Data, Inc.
-*
-* This program is free software: you can use, redistribute, and/or modify
-* it under the terms of the GNU Affero General Public License, version 3
-* or later ("AGPL"), as published by the Free Software Foundation.
-*
-* This program is distributed in the hope that it will be useful, but WITHOUT
-* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-* FITNESS FOR A PARTICULAR PURPOSE.
-*
-* You should have received a copy of the GNU Affero General Public License
-* along with this program. If not, see .
-*/
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
#ifndef TDENGINE_PLATFORM_LINUX_H
#define TDENGINE_PLATFORM_LINUX_H
@@ -25,10 +25,12 @@ extern "C" {
#include
#include
+#include
#include
#include
#include
#include
+#include
#include
#include
#include
@@ -37,7 +39,8 @@ extern "C" {
#include
#include
#include
-#include
+#include
+#include
#include
#include
#include
@@ -45,21 +48,19 @@ extern "C" {
#include
#include
#include
+#include
#include
#include
#include
#include
#include
#include
-#include
#include
#include
#include
#include
#include
#include
-#include
-#include
#define taosCloseSocket(x) \
{ \
@@ -110,7 +111,7 @@ extern "C" {
#define __sync_sub_and_fetch_ptr __sync_sub_and_fetch
int32_t __sync_val_load_32(int32_t *ptr);
-void __sync_val_restore_32(int32_t *ptr, int32_t newval);
+void __sync_val_restore_32(int32_t *ptr, int32_t newval);
#define SWAP(a, b, c) \
do { \
@@ -168,9 +169,9 @@ bool taosSkipSocketCheck();
int64_t str2int64(char *str);
#define BUILDIN_CLZL(val) __builtin_clzl(val)
-#define BUILDIN_CLZ(val) __builtin_clz(val)
+#define BUILDIN_CLZ(val) __builtin_clz(val)
#define BUILDIN_CTZL(val) __builtin_ctzl(val)
-#define BUILDIN_CTZ(val) __builtin_ctz(val)
+#define BUILDIN_CTZ(val) __builtin_ctz(val)
#ifdef __cplusplus
}
diff --git a/src/system/detail/inc/mgmtUtil.h b/src/system/detail/inc/mgmtUtil.h
index aecb229dba3024c712b82d8dafab7a0dbbf146e7..6a6b819bf2b8cf17c52f404fd2c2d66b65e20876 100644
--- a/src/system/detail/inc/mgmtUtil.h
+++ b/src/system/detail/inc/mgmtUtil.h
@@ -30,6 +30,7 @@ char* mgmtMeterGetTag(STabObj* pMeter, int32_t col, SSchema* pTagColSchema);
int32_t mgmtFindTagCol(STabObj * pMetric, const char * tagName);
int32_t mgmtGetTagsLength(STabObj* pMetric, int32_t col);
+bool mgmtCheckIsMonitorDB(char *db, char *monitordb);
int32_t mgmtRetrieveMetersFromMetric(SMetricMetaMsg* pInfo, int32_t tableIndex, tQueryResultset* pRes);
int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes);
diff --git a/src/system/detail/src/mgmtDb.c b/src/system/detail/src/mgmtDb.c
index ae4c5bed7ce86b712c0886b98b9cf2e5118899f6..e87266aa4b3ee29123e48fe9bcea3e32ea7aa8d3 100644
--- a/src/system/detail/src/mgmtDb.c
+++ b/src/system/detail/src/mgmtDb.c
@@ -14,9 +14,11 @@
*/
#define _DEFAULT_SOURCE
+#include "os.h"
+
#include "mgmt.h"
-#include
#include "mgmtBalance.h"
+#include "mgmtUtil.h"
#include "tschemautil.h"
void *dbSdb = NULL;
@@ -373,10 +375,12 @@ int mgmtDropDbByName(SAcctObj *pAcct, char *name) {
if (pDb == NULL) {
mWarn("db:%s is not there", name);
// return TSDB_CODE_INVALID_DB;
- return 0;
+ return TSDB_CODE_SUCCESS;
}
- if (taosCheckDbName(pDb->name, tsMonitorDbName)) return TSDB_CODE_MONITOR_DB_FORBEIDDEN;
+ if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) {
+ return TSDB_CODE_MONITOR_DB_FORBEIDDEN;
+ }
return mgmtDropDb(pDb);
}
diff --git a/src/system/detail/src/mgmtMeter.c b/src/system/detail/src/mgmtMeter.c
index bccf9a06c8652cecf6e0ef9b884479523358c614..2db920fdd71a6005d45d442aff4c108a31dc9c72 100644
--- a/src/system/detail/src/mgmtMeter.c
+++ b/src/system/detail/src/mgmtMeter.c
@@ -688,8 +688,10 @@ int mgmtDropMeter(SDbObj *pDb, char *meterId, int ignore) {
pAcct = mgmtGetAcct(pDb->cfg.acct);
- // 0.sys
- if (taosCheckDbName(pDb->name, tsMonitorDbName)) return TSDB_CODE_MONITOR_DB_FORBEIDDEN;
+ // 0.log
+ if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) {
+ return TSDB_CODE_MONITOR_DB_FORBEIDDEN;
+ }
if (mgmtIsNormalMeter(pMeter)) {
return dropMeterImp(pDb, pMeter, pAcct);
@@ -719,8 +721,8 @@ int mgmtAlterMeter(SDbObj *pDb, SAlterTableMsg *pAlter) {
return TSDB_CODE_INVALID_TABLE;
}
- // 0.sys
- if (taosCheckDbName(pDb->name, tsMonitorDbName)) return TSDB_CODE_MONITOR_DB_FORBEIDDEN;
+ // 0.log
+ if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) return TSDB_CODE_MONITOR_DB_FORBEIDDEN;
if (pAlter->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) {
if (!mgmtIsNormalMeter(pMeter) || !mgmtMeterCreateFromMetric(pMeter)) {
@@ -833,6 +835,7 @@ static void removeMeterFromMetricIndex(STabObj *pMetric, STabObj *pMeter) {
}
}
+ tSkipListDestroyKey(&key);
if (num != 0) {
free(pRes);
}
diff --git a/src/system/detail/src/mgmtUtil.c b/src/system/detail/src/mgmtUtil.c
index a427771e0f900c3a19bb13dbc45897b3190d7f15..be90180f681be75396c208ce078c9025c687d286 100644
--- a/src/system/detail/src/mgmtUtil.c
+++ b/src/system/detail/src/mgmtUtil.c
@@ -87,3 +87,10 @@ int32_t mgmtGetTagsLength(STabObj* pMetric, int32_t col) { // length before col
return len;
}
+
+bool mgmtCheckIsMonitorDB(char *db, char *monitordb) {
+ char dbName[TSDB_DB_NAME_LEN + 1] = {0};
+ extractDBName(db, dbName);
+
+ return (strncasecmp(dbName, monitordb, strlen(dbName)) == 0);
+}
diff --git a/src/system/detail/src/vnodeQueryImpl.c b/src/system/detail/src/vnodeQueryImpl.c
index 187269d30b1b374778dc5646677a2d275a3bce27..9c0d7883a5242987b46909b98f7d0081ba82fc92 100644
--- a/src/system/detail/src/vnodeQueryImpl.c
+++ b/src/system/detail/src/vnodeQueryImpl.c
@@ -3436,9 +3436,18 @@ void pointInterpSupporterSetData(SQInfo *pQInfo, SPointInterpoSupporter *pPointI
if (pQuery->interpoType == TSDB_INTERPO_SET_VALUE) {
for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) {
SQLFunctionCtx *pCtx = &pRuntimeEnv->pCtx[i];
+
+ // only the function of interp needs the corresponding information
+ if (pCtx->functionId != TSDB_FUNC_INTERP) {
+ continue;
+ }
+
+ pCtx->numOfParams = 4;
+
SInterpInfo * pInterpInfo = (SInterpInfo *)pRuntimeEnv->pCtx[i].aOutputBuf;
pInterpInfo->pInterpDetail = calloc(1, sizeof(SInterpInfoDetail));
+
SInterpInfoDetail *pInterpDetail = pInterpInfo->pInterpDetail;
// for primary timestamp column, set the flag
diff --git a/src/system/detail/src/vnodeShell.c b/src/system/detail/src/vnodeShell.c
index 190c1d6ee675ae11e15adecd080bbd20c765e2e9..353b2668ee94c1da31b005f84beb63e5036b6341 100644
--- a/src/system/detail/src/vnodeShell.c
+++ b/src/system/detail/src/vnodeShell.c
@@ -419,7 +419,7 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
if (code == TSDB_CODE_SUCCESS) {
pRsp->offset = htobe64(vnodeGetOffsetVal(pRetrieve->qhandle));
- pRsp->useconds = ((SQInfo *)(pRetrieve->qhandle))->useconds;
+ pRsp->useconds = htobe64(((SQInfo *)(pRetrieve->qhandle))->useconds);
} else {
pRsp->offset = 0;
pRsp->useconds = 0;
diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c
index 9abe60220f27452d74728abb0d65a5abb9a9edf2..586f32900133e23369f0372c115b0f2b4efd75e0 100644
--- a/src/util/src/tglobalcfg.c
+++ b/src/util/src/tglobalcfg.c
@@ -536,6 +536,11 @@ void tsInitGlobalConfig() {
0, 2, 0, TSDB_CFG_UTYPE_NONE);
// 0-any, 1-mgmt, 2-dnode
+ // timer
+ tsInitConfigOption(cfg++, "maxTmrCtrl", &taosMaxTmrCtrl, TSDB_CFG_VTYPE_INT,
+ TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER,
+ 8, 2048, 0, TSDB_CFG_UTYPE_NONE);
+
// time
tsInitConfigOption(cfg++, "monitorInterval", &tsMonitorInterval, TSDB_CFG_VTYPE_INT,
TSDB_CFG_CTYPE_B_CONFIG,
diff --git a/src/util/src/ttimer.c b/src/util/src/ttimer.c
index 798e63a64a51efa008968fd5070331c49620eaac..97e218915330d838f18f5da3a8346cf4c2b27890 100644
--- a/src/util/src/ttimer.c
+++ b/src/util/src/ttimer.c
@@ -82,13 +82,16 @@ typedef struct time_wheel_t {
} time_wheel_t;
uint32_t tmrDebugFlag = DEBUG_ERROR | DEBUG_WARN | DEBUG_FILE;
+uint32_t taosMaxTmrCtrl = 512;
static pthread_once_t tmrModuleInit = PTHREAD_ONCE_INIT;
static pthread_mutex_t tmrCtrlMutex;
-static tmr_ctrl_t tmrCtrls[MAX_NUM_OF_TMRCTL];
+static tmr_ctrl_t* tmrCtrls;
static tmr_ctrl_t* unusedTmrCtrl = NULL;
-void* tmrQhandle;
-int taosTmrThreads = 1;
+static void* tmrQhandle;
+static int numOfTmrCtrl = 0;
+
+int taosTmrThreads = 1;
static uintptr_t nextTimerId = 0;
@@ -129,7 +132,7 @@ static void unlockTimerList(timer_list_t* list) {
int64_t tid = taosGetPthreadId();
if (__sync_val_compare_and_swap_64(&(list->lockedBy), tid, 0) != tid) {
assert(false);
- tmrError("trying to unlock a timer list not locked by current thread.");
+ tmrError("%d trying to unlock a timer list not locked by current thread.", tid);
}
}
@@ -256,13 +259,13 @@ static void processExpiredTimer(void* handle, void* arg) {
timer->executedBy = taosGetPthreadId();
uint8_t state = __sync_val_compare_and_swap_8(&timer->state, TIMER_STATE_WAITING, TIMER_STATE_EXPIRED);
if (state == TIMER_STATE_WAITING) {
- const char* fmt = "timer[label=%s, id=%lld, fp=%p, param=%p] execution start.";
+ const char* fmt = "%s timer[id=%lld, fp=%p, param=%p] execution start.";
tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param);
(*timer->fp)(timer->param, (tmr_h)timer->id);
atomic_store_8(&timer->state, TIMER_STATE_STOPPED);
- fmt = "timer[label=%s, id=%lld, fp=%p, param=%p] execution end.";
+ fmt = "%s timer[id=%lld, fp=%p, param=%p] execution end.";
tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param);
}
removeTimer(timer->id);
@@ -270,18 +273,21 @@ static void processExpiredTimer(void* handle, void* arg) {
}
static void addToExpired(tmr_obj_t* head) {
- const char* fmt = "timer[label=%s, id=%lld, fp=%p, param=%p] expired";
+ const char* fmt = "%s adding expired timer[id=%lld, fp=%p, param=%p] to queue.";
while (head != NULL) {
- tmrTrace(fmt, head->ctrl->label, head->id, head->fp, head->param);
-
+ uintptr_t id = head->id;
tmr_obj_t* next = head->next;
+ tmrTrace(fmt, head->ctrl->label, id, head->fp, head->param);
+
SSchedMsg schedMsg;
schedMsg.fp = NULL;
schedMsg.tfp = processExpiredTimer;
schedMsg.ahandle = head;
schedMsg.thandle = NULL;
taosScheduleTask(tmrQhandle, &schedMsg);
+
+ tmrTrace("timer[id=%lld] has been added to queue.", id);
head = next;
}
}
@@ -295,7 +301,7 @@ static uintptr_t doStartTimer(tmr_obj_t* timer, TAOS_TMR_CALLBACK fp, int msecon
timer->ctrl = ctrl;
addTimer(timer);
- const char* fmt = "timer[label=%s, id=%lld, fp=%p, param=%p] started";
+ const char* fmt = "%s timer[id=%lld, fp=%p, param=%p] started";
tmrTrace(fmt, ctrl->label, timer->id, timer->fp, timer->param);
if (mseconds == 0) {
@@ -318,7 +324,7 @@ tmr_h taosTmrStart(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle
tmr_obj_t* timer = (tmr_obj_t*)calloc(1, sizeof(tmr_obj_t));
if (timer == NULL) {
- tmrError("failed to allocated memory for new timer object.");
+ tmrError("%s failed to allocated memory for new timer object.", ctrl->label);
return NULL;
}
@@ -389,7 +395,7 @@ static bool doStopTimer(tmr_obj_t* timer, uint8_t state) {
// we cannot guarantee the thread safety of the timr in all other cases.
reusable = true;
}
- const char* fmt = "timer[label=%s, id=%lld, fp=%p, param=%p] is cancelled.";
+ const char* fmt = "%s timer[id=%lld, fp=%p, param=%p] is cancelled.";
tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param);
} else if (state != TIMER_STATE_EXPIRED) {
// timer already stopped or cancelled, has nothing to do in this case
@@ -400,7 +406,7 @@ static bool doStopTimer(tmr_obj_t* timer, uint8_t state) {
} else {
assert(timer->executedBy != taosGetPthreadId());
- const char* fmt = "timer[label=%s, id=%lld, fp=%p, param=%p] fired, waiting...";
+ const char* fmt = "%s timer[id=%lld, fp=%p, param=%p] fired, waiting...";
tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param);
for (int i = 1; atomic_load_8(&timer->state) != TIMER_STATE_STOPPED; i++) {
@@ -409,7 +415,7 @@ static bool doStopTimer(tmr_obj_t* timer, uint8_t state) {
}
}
- fmt = "timer[label=%s, id=%lld, fp=%p, param=%p] stopped.";
+ fmt = "%s timer[id=%lld, fp=%p, param=%p] stopped.";
tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param);
}
@@ -448,7 +454,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle,
bool stopped = false;
tmr_obj_t* timer = findTimer(id);
if (timer == NULL) {
- tmrTrace("timer[id=%lld] does not exist", id);
+ tmrTrace("%s timer[id=%lld] does not exist", ctrl->label, id);
} else {
uint8_t state = __sync_val_compare_and_swap_8(&timer->state, TIMER_STATE_WAITING, TIMER_STATE_CANCELED);
if (!doStopTimer(timer, state)) {
@@ -463,7 +469,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle,
return stopped;
}
- tmrTrace("timer[id=%lld] is reused", timer->id);
+ tmrTrace("%s timer[id=%lld] is reused", ctrl->label, timer->id);
// wait until there's no other reference to this timer,
// so that we can reuse this timer safely.
@@ -481,7 +487,13 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle,
}
static void taosTmrModuleInit(void) {
- for (int i = 0; i < tListLen(tmrCtrls) - 1; ++i) {
+ tmrCtrls = malloc(sizeof(tmr_ctrl_t) * taosMaxTmrCtrl);
+ if (tmrCtrls == NULL) {
+ tmrError("failed to allocate memory for timer controllers.");
+ return;
+ }
+
+ for (int i = 0; i < taosMaxTmrCtrl - 1; ++i) {
tmr_ctrl_t* ctrl = tmrCtrls + i;
ctrl->next = ctrl + 1;
}
@@ -526,17 +538,18 @@ void* taosTmrInit(int maxNumOfTmrs, int resolution, int longest, const char* lab
tmr_ctrl_t* ctrl = unusedTmrCtrl;
if (ctrl != NULL) {
unusedTmrCtrl = ctrl->next;
+ numOfTmrCtrl++;
}
pthread_mutex_unlock(&tmrCtrlMutex);
if (ctrl == NULL) {
- tmrError("too many timer controllers, failed to create timer controller[label=%s].", label);
+ tmrError("%s too many timer controllers, failed to create timer controller.", label);
return NULL;
}
strncpy(ctrl->label, label, sizeof(ctrl->label));
ctrl->label[sizeof(ctrl->label) - 1] = 0;
- tmrTrace("timer controller[label=%s] is initialized.", label);
+ tmrTrace("%s timer controller is initialized, number of timer controllers: %d.", label, numOfTmrCtrl);
return ctrl;
}
@@ -544,11 +557,12 @@ void taosTmrCleanUp(void* handle) {
tmr_ctrl_t* ctrl = (tmr_ctrl_t*)handle;
assert(ctrl != NULL && ctrl->label[0] != 0);
- tmrTrace("timer controller[label=%s] is cleaned up.", ctrl->label);
+ tmrTrace("%s timer controller is cleaned up.", ctrl->label);
ctrl->label[0] = 0;
pthread_mutex_lock(&tmrCtrlMutex);
ctrl->next = unusedTmrCtrl;
+ numOfTmrCtrl--;
unusedTmrCtrl = ctrl;
pthread_mutex_unlock(&tmrCtrlMutex);
}
diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c
index 805f27a3813fccbe36a26aa47358a01ee22f9c33..0d1ea9ed50cb1b4736ba5e713f014a562b59875b 100644
--- a/src/util/src/tutil.c
+++ b/src/util/src/tutil.c
@@ -406,13 +406,6 @@ int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstP
return rename(fullPath, *dstPath);
}
-bool taosCheckDbName(char *db, char *monitordb) {
- char *pos = strchr(db, '.');
- if (pos == NULL) return false;
-
- return strncasecmp(pos + 1, monitordb, strlen(monitordb)) == 0;
-}
-
bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
#ifdef USE_LIBICONV
iconv_t cd = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);