From 9eae7a6e058f5d315769e79aaf1d5885e4fb8821 Mon Sep 17 00:00:00 2001
From: Yu Chen <74105241+yu285@users.noreply.github.com>
Date: Wed, 25 Dec 2024 10:16:15 +0800
Subject: [PATCH 01/56] docs/optimize the description in Update
03-taosadapter.md
---
docs/zh/14-reference/01-components/03-taosadapter.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/zh/14-reference/01-components/03-taosadapter.md b/docs/zh/14-reference/01-components/03-taosadapter.md
index b74ee77862..bf5060cec5 100644
--- a/docs/zh/14-reference/01-components/03-taosadapter.md
+++ b/docs/zh/14-reference/01-components/03-taosadapter.md
@@ -14,7 +14,7 @@ taosAdapter 是一个 TDengine 的配套工具,是 TDengine 集群和应用程
taosAdapter 提供以下功能:
-- RESTful 接口
+- Websocket/RESTful 接口
- 兼容 InfluxDB v1 写接口
- 兼容 OpenTSDB JSON 和 telnet 格式写入
- 无缝连接到 Telegraf
From 20a0ae79050dd74447d9e489b3020b42cf5a0463 Mon Sep 17 00:00:00 2001
From: dmchen
Date: Wed, 25 Dec 2024 11:51:37 +0000
Subject: [PATCH 02/56] fix/remove-resolve-fqdn-retry
---
include/common/tglobal.h | 1 -
source/common/src/tglobal.c | 6 ------
source/libs/sync/src/syncUtil.c | 12 ++++--------
3 files changed, 4 insertions(+), 15 deletions(-)
diff --git a/include/common/tglobal.h b/include/common/tglobal.h
index 584c4b5775..6ecee822ee 100644
--- a/include/common/tglobal.h
+++ b/include/common/tglobal.h
@@ -291,7 +291,6 @@ extern int tsStreamAggCnt;
extern bool tsFilterScalarMode;
extern int32_t tsMaxStreamBackendCache;
extern int32_t tsPQSortMemThreshold;
-extern int32_t tsResolveFQDNRetryTime;
extern bool tsStreamCoverage;
extern bool tsExperimental;
diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c
index c58ad32a18..355a34d05b 100644
--- a/source/common/src/tglobal.c
+++ b/source/common/src/tglobal.c
@@ -327,7 +327,6 @@ char tsUdfdLdLibPath[512] = "";
bool tsDisableStream = false;
int64_t tsStreamBufferSize = 128 * 1024 * 1024;
bool tsFilterScalarMode = false;
-int tsResolveFQDNRetryTime = 100; // seconds
int tsStreamAggCnt = 100000;
bool tsStreamCoverage = false;
@@ -956,7 +955,6 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
TAOS_CHECK_RETURN(cfgAddBool(pCfg, "filterScalarMode", tsFilterScalarMode, CFG_SCOPE_SERVER, CFG_DYN_NONE,CFG_CATEGORY_LOCAL));
TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "maxStreamBackendCache", tsMaxStreamBackendCache, 16, 1024, CFG_SCOPE_SERVER, CFG_DYN_ENT_SERVER_LAZY,CFG_CATEGORY_LOCAL));
TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "pqSortMemThreshold", tsPQSortMemThreshold, 1, 10240, CFG_SCOPE_SERVER, CFG_DYN_NONE,CFG_CATEGORY_LOCAL));
- TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "resolveFQDNRetryTime", tsResolveFQDNRetryTime, 1, 10240, CFG_SCOPE_SERVER, CFG_DYN_NONE,CFG_CATEGORY_GLOBAL));
TAOS_CHECK_RETURN(cfgAddString(pCfg, "s3Accesskey", tsS3AccessKey[0], CFG_SCOPE_SERVER, CFG_DYN_ENT_SERVER_LAZY,CFG_CATEGORY_GLOBAL));
TAOS_CHECK_RETURN(cfgAddString(pCfg, "s3Endpoint", tsS3Endpoint[0], CFG_SCOPE_SERVER, CFG_DYN_ENT_SERVER_LAZY,CFG_CATEGORY_GLOBAL));
@@ -1822,9 +1820,6 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "pqSortMemThreshold");
tsPQSortMemThreshold = pItem->i32;
- TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "resolveFQDNRetryTime");
- tsResolveFQDNRetryTime = pItem->i32;
-
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "minDiskFreeSize");
tsMinDiskFreeSize = pItem->i64;
@@ -2453,7 +2448,6 @@ static int32_t taosCfgDynamicOptionsForServer(SConfig *pCfg, const char *name) {
{"randErrorDivisor", &tsRandErrDivisor},
{"randErrorScope", &tsRandErrScope},
{"syncLogBufferMemoryAllowed", &tsLogBufferMemoryAllowed},
- {"resolveFQDNRetryTime", &tsResolveFQDNRetryTime},
{"syncHeartbeatInterval", &tsHeartbeatInterval},
{"syncHeartbeatTimeout", &tsHeartbeatTimeout},
{"syncSnapReplMaxWaitN", &tsSnapReplMaxWaitN},
diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c
index 0fedd96e4c..d9eff2e9b8 100644
--- a/source/libs/sync/src/syncUtil.c
+++ b/source/libs/sync/src/syncUtil.c
@@ -45,14 +45,10 @@ void syncUtilNodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet) {
bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* raftId) {
uint32_t ipv4 = 0xFFFFFFFF;
sDebug("vgId:%d, resolve sync addr from fqdn, ep:%s:%u", vgId, pInfo->nodeFqdn, pInfo->nodePort);
- for (int32_t i = 0; i < tsResolveFQDNRetryTime; i++) {
- int32_t code = taosGetIpv4FromFqdn(pInfo->nodeFqdn, &ipv4);
- if (code) {
- sError("vgId:%d, failed to resolve sync addr, dnode:%d fqdn:%s, retry", vgId, pInfo->nodeId, pInfo->nodeFqdn);
- taosSsleep(1);
- } else {
- break;
- }
+
+ int32_t code = taosGetIpv4FromFqdn(pInfo->nodeFqdn, &ipv4);
+ if (code) {
+ sError("vgId:%d, failed to resolve sync addr, dnode:%d fqdn:%s, retry", vgId, pInfo->nodeId, pInfo->nodeFqdn);
}
if (ipv4 == 0xFFFFFFFF || ipv4 == 1) {
From 484e4c14380dc10e76e4dd29fb452440c723e10d Mon Sep 17 00:00:00 2001
From: dmchen
Date: Thu, 26 Dec 2024 00:53:39 +0000
Subject: [PATCH 03/56] fix/remove-resolve-fqdn-retry-fix-case
---
tests/army/alter/test_alter_config.py | 5 -----
tests/script/tsim/show/basic.sim | 2 +-
tests/script/tsim/valgrind/checkError1.sim | 2 +-
tests/system-test/0-others/test_alter_config.py | 5 -----
tests/system-test/2-query/db.py | 2 +-
5 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/tests/army/alter/test_alter_config.py b/tests/army/alter/test_alter_config.py
index 1b59293187..229f3150b3 100644
--- a/tests/army/alter/test_alter_config.py
+++ b/tests/army/alter/test_alter_config.py
@@ -310,11 +310,6 @@ class TDTestCase:
"value": 1024 * 1024 * 20 * 10,
"category": "global"
},
- {
- "name": "resolveFQDNRetryTime",
- "value": 500,
- "category": "global"
- },
{
"name": "syncHeartbeatInterval",
"value": 3000,
diff --git a/tests/script/tsim/show/basic.sim b/tests/script/tsim/show/basic.sim
index 4c4f9da912..7569cd832c 100644
--- a/tests/script/tsim/show/basic.sim
+++ b/tests/script/tsim/show/basic.sim
@@ -230,7 +230,7 @@ endi
sql_error show create stable t0;
sql show variables;
-if $rows != 94 then
+if $rows != 93 then
return -1
endi
diff --git a/tests/script/tsim/valgrind/checkError1.sim b/tests/script/tsim/valgrind/checkError1.sim
index b7b04a030f..64f9cdec1f 100644
--- a/tests/script/tsim/valgrind/checkError1.sim
+++ b/tests/script/tsim/valgrind/checkError1.sim
@@ -120,7 +120,7 @@ if $rows != 3 then
endi
sql show variables;
-if $rows != 94 then
+if $rows != 93 then
return -1
endi
diff --git a/tests/system-test/0-others/test_alter_config.py b/tests/system-test/0-others/test_alter_config.py
index 14e77bb489..bdc3a0e835 100644
--- a/tests/system-test/0-others/test_alter_config.py
+++ b/tests/system-test/0-others/test_alter_config.py
@@ -207,11 +207,6 @@ class TDTestCase:
"value": 1024 * 1024 * 20 * 10,
"category": "global"
},
- {
- "name": "resolveFQDNRetryTime",
- "value": 500,
- "category": "global"
- },
{
"name": "syncElectInterval",
"value": 50000,
diff --git a/tests/system-test/2-query/db.py b/tests/system-test/2-query/db.py
index 0c5c9773c8..66776e0a23 100644
--- a/tests/system-test/2-query/db.py
+++ b/tests/system-test/2-query/db.py
@@ -47,7 +47,7 @@ class TDTestCase:
def case2(self):
tdSql.query("show variables")
- tdSql.checkRows(94)
+ tdSql.checkRows(93)
for i in range(self.replicaVar):
tdSql.query("show dnode %d variables like 'debugFlag'" % (i + 1))
From 16a79dd86d1de701a779e551274787d0998d4dd4 Mon Sep 17 00:00:00 2001
From: "pengrongkun94@qq.com"
Date: Wed, 25 Dec 2024 10:59:37 +0800
Subject: [PATCH 04/56] add stmt test case
---
source/client/test/CMakeLists.txt | 16 ++
source/client/test/stmt2Test.cpp | 417 ++++++++++++++++++++++++++++++
2 files changed, 433 insertions(+)
create mode 100644 source/client/test/stmt2Test.cpp
diff --git a/source/client/test/CMakeLists.txt b/source/client/test/CMakeLists.txt
index fecddbbff4..62b7bb3e91 100644
--- a/source/client/test/CMakeLists.txt
+++ b/source/client/test/CMakeLists.txt
@@ -41,6 +41,12 @@ TARGET_LINK_LIBRARIES(
PUBLIC ${TAOS_LIB}
)
+ADD_EXECUTABLE(stmt2Test stmt2Test.cpp)
+TARGET_LINK_LIBRARIES(
+ stmt2Test
+ os util common transport parser catalog scheduler gtest ${TAOS_LIB_STATIC} qcom executor function
+)
+
TARGET_INCLUDE_DIRECTORIES(
clientTest
PUBLIC "${TD_SOURCE_DIR}/include/client/"
@@ -82,6 +88,12 @@ TARGET_INCLUDE_DIRECTORIES(
# PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
#)
+TARGET_INCLUDE_DIRECTORIES(
+ stmt2Test
+ PUBLIC "${TD_SOURCE_DIR}/include/client/"
+ PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
+)
+
add_test(
NAME smlTest
COMMAND smlTest
@@ -97,3 +109,7 @@ add_test(
COMMAND userOperTest
)
+add_test(
+ NAME stmt2Test
+ COMMAND stmt2Test
+)
diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp
new file mode 100644
index 0000000000..c325ed3a38
--- /dev/null
+++ b/source/client/test/stmt2Test.cpp
@@ -0,0 +1,417 @@
+/*
+ * 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 .
+ */
+
+#include
+#include
+#include "clientInt.h"
+#include "osSemaphore.h"
+#include "taoserror.h"
+#include "tglobal.h"
+#include "thash.h"
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wwrite-strings"
+#pragma GCC diagnostic ignored "-Wunused-function"
+#pragma GCC diagnostic ignored "-Wunused-variable"
+#pragma GCC diagnostic ignored "-Wsign-compare"
+
+#include "executor.h"
+#include "taos.h"
+
+namespace {
+void getFieldsSuccess(TAOS* taos, const char* sql, TAOS_FIELD_ALL* expectedFields, int expectedFieldNum) {
+ TAOS_STMT2_OPTION option = {0};
+ TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
+ int code = taos_stmt2_prepare(stmt, sql, 0);
+ ASSERT_EQ(code, 0);
+
+ int fieldNum = 0;
+ TAOS_FIELD_ALL* pFields = NULL;
+ code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields);
+ ASSERT_EQ(code, 0);
+ ASSERT_EQ(fieldNum, expectedFieldNum);
+
+ for (int i = 0; i < fieldNum; i++) {
+ ASSERT_STREQ(pFields[i].name, expectedFields[i].name);
+ ASSERT_EQ(pFields[i].type, expectedFields[i].type);
+ ASSERT_EQ(pFields[i].field_type, expectedFields[i].field_type);
+ ASSERT_EQ(pFields[i].precision, expectedFields[i].precision);
+ ASSERT_EQ(pFields[i].bytes, expectedFields[i].bytes);
+ ASSERT_EQ(pFields[i].scale, expectedFields[i].scale);
+ }
+ taos_stmt2_free_fields(stmt, pFields);
+ taos_stmt2_close(stmt);
+}
+
+void getQueryFields(TAOS* taos, const char* sql) {
+ TAOS_STMT2_OPTION option = {0};
+ TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
+ int code = taos_stmt2_prepare(stmt, sql, 0);
+ if (code != 0) {
+ printf("failed to execute taos_stmt2_prepare. error:%s\n", taos_stmt2_error(stmt));
+ taos_stmt2_close(stmt);
+ return;
+ }
+ int fieldNum = 0;
+ TAOS_FIELD_ALL* pFields = NULL;
+ code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields);
+ if (code != 0) {
+ printf("failed get col,ErrCode: 0x%x, ErrMessage: %s.\n", code, taos_stmt2_error(stmt));
+ } else {
+ printf("bind nums:%d\n", fieldNum);
+ }
+ printf("====================================\n");
+ taos_stmt2_free_fields(stmt, pFields);
+ taos_stmt2_close(stmt);
+}
+
+void do_query(TAOS* taos, const char* sql) {
+ TAOS_RES* result = taos_query(taos, sql);
+ int code = taos_errno(result);
+ ASSERT_EQ(code, 0);
+
+ taos_free_result(result);
+}
+
+// void do_stmt(TAOS* taos) {
+
+// printf("=================error test===================\n");
+
+// // case 14 : INSERT INTO db.d0 using db.stb values(?,?)
+// // none para for ctbname
+// sql = "INSERT INTO db.d0 using db.stb values(?,?)";
+// printf("case 14 (no tags error): %s\n", sql);
+// getFields(taos, sql);
+
+// // case 15 : insert into db.stb(t1,t2,tbname) values(?,?,?)
+// // no value
+// sql = "insert into db.stb(t1,t2,tbname) values(?,?,?)";
+// printf("case 15 (no PK error): %s\n", sql);
+// getFields(taos, sql);
+
+// // case 16 : insert into db.stb(ts,b,tbname) values(?,?,?,?,?)
+// // wrong para nums
+// sql = "insert into db.stb(ts,b,tbname) values(?,?,?,?,?)";
+// printf("case 16 (wrong para nums): %s\n", sql);
+// getFields(taos, sql);
+
+// // case 17 : insert into db.? values(?,?)
+// // normal table must have tbnam
+// sql = "insert into db.? values(?,?)";
+// printf("case 17 (normal table must have tbname): %s\n", sql);
+// getFields(taos, sql);
+
+// // case 18 : INSERT INTO db.stb(t1,t2,ts,b) values(?,?,?,?)
+// // no tbname error
+// sql = "INSERT INTO db.stb(t1,t2,ts,b) values(?,?,?,?)";
+// printf("case 18 (no tbname error): %s\n", sql);
+// getFields(taos, sql);
+
+// // case 19 : insert into db.ntb(nts,ni) values(?,?,?,?,?)
+// // wrong para nums
+// sql = "insert into ntb(nts,ni) values(?,?,?,?,?)";
+// printf("case 19 : %s\n", sql);
+// getFields(taos, sql);
+
+// // case 20 : insert into db.stb(t1,t2,ts,b,tbname) values(*,*,*,*,*)
+// // wrong simbol
+// sql = "insert into db.stb(t1,t2,ts,b,tbname) values(*,*,*,*,*)";
+// printf("=================normal test===================\n");
+// printf("case 20 : %s\n", sql);
+// getFields(taos, sql);
+
+// // case 21 : INSERT INTO ! using db.stb TAGS(?,?) VALUES(?,?)
+// // wrong simbol
+// sql = "insert into ! using db.stb tags(?, ?) values(?,?)";
+// printf("case 21 : %s\n", sql);
+// getFields(taos, sql);
+
+// // case 22 : INSERT INTO ! using db.stb TAGS(?,?) VALUES(?,?)
+// // wrong tbname
+// sql = "insert into db.stb values(?,?)";
+// printf("case 22 : %s\n", sql);
+// getFields(taos, sql);
+
+// // case 23 : select * from ? where ts = ?
+// // wrong query type
+// sql = "select * from ? where ts = ?";
+// printf("case 23 : %s\n", sql);
+// getQueryFields(taos, sql);
+// }
+
+} // namespace
+
+int main(int argc, char** argv) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+
+TEST(clientCase, driverInit_Test) {
+ // taosInitGlobalCfg();
+ // taos_init();
+}
+
+TEST(stmt2Case, insert_stb_get_fields_Test) {
+ TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
+ ASSERT_NE(taos, nullptr);
+
+ do_query(taos, "drop database if exists db");
+ do_query(taos, "create database db PRECISION 'ns'");
+ do_query(taos, "use db");
+ do_query(taos,
+ "create table db.stb (ts timestamp, b binary(10)) tags(t1 "
+ "int, t2 binary(10))");
+ do_query(
+ taos,
+ "create table if not exists all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 "
+ "tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 "
+ "binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20))tags(tts timestamp, tv1 bool, tv2 tinyint, tv3 "
+ "smallint, tv4 int, tv5 bigint, tv6 tinyint unsigned, tv7 smallint unsigned, tv8 int unsigned, tv9 bigint "
+ "unsigned, tv10 float, tv11 double, tv12 binary(20), tv13 varbinary(20), tv14 geometry(100), tv15 nchar(20));");
+
+ // // case 1 : test super table
+ // {
+ // const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)";
+ // TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
+ // {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
+ // printf("case 1 : %s\n", sql);
+ // getFieldsSuccess(taos, sql, expectedFields, 5);
+ // }
+
+ // case 2 : no tbname
+ {
+ const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(1,?,?,'abc',?)";
+ TAOS_FIELD_ALL expectedFields[3] = {{"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
+ printf("case 2 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 3);
+ }
+
+ {
+ // case 3 : insert into db.stb(ts,b,tbname) values(?,?,?)
+ // no tag
+ const char* sql = "insert into db.stb(ts,b,tbname) values(?,?,?)";
+ TAOS_FIELD_ALL expectedFields[3] = {
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
+ {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ };
+ printf("case 5 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 3);
+ }
+
+ // case 12 : insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
+ // values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
+ // test all types
+ {
+ const char* sql =
+ "insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+ TAOS_FIELD_ALL expectedFields[33] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ {"tts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_TAG},
+ {"tv1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_TAG},
+ {"tv2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_TAG},
+ {"tv3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
+ {"tv4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"tv5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_TAG},
+ {"tv6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_TAG},
+ {"tv7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
+ {"tv8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"tv9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_TAG},
+ {"tv10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"tv11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_TAG},
+ {"tv12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_TAG},
+ {"tv13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_TAG},
+ {"tv14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_TAG},
+ {"tv15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_TAG},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"v1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_COL},
+ {"v2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_COL},
+ {"v3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_COL},
+ {"v4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL},
+ {"v5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_COL},
+ {"v6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_COL},
+ {"v7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_COL},
+ {"v8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_COL},
+ {"v9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_COL},
+ {"v10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_COL},
+ {"v11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_COL},
+ {"v12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_COL},
+ {"v13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_COL},
+ {"v14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_COL},
+ {"v15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_COL}};
+ printf("case 12 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 33);
+ }
+
+ taos_close(taos);
+ taos_cleanup();
+}
+
+TEST(stmt2Case, insert_ctb_using_get_fields_Test) {
+ // do_query(taos, "CREATE TABLE db.d0 USING db.stb (t1,t2) TAGS (7,'Cali');");
+
+ // // case 2 : INSERT INTO db.d0 VALUES (?,?)
+ // // test child table
+ // {
+ // const char* sql = "INSERT INTO db.d0(ts,b) VALUES (?,?)";
+ // TAOS_FIELD_ALL expectedFields[2] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
+ // printf("case 2 : %s\n", sql);
+ // getFieldsSuccess(taos, sql, expectedFields, 2);
+ // }
+
+ // // case 6 : INSERT INTO db.? using db.stb (t1,t2)TAGS(?,?) (ts,b)VALUES(?,?)
+ // // normal insert clause
+ // {
+ // const char* sql = "INSERT INTO db.? using db.stb (t1,t2)TAGS(?,?) (ts,b)VALUES(?,?)";
+ // TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ // {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
+ // printf("case 6 : %s\n", sql);
+ // getFieldsSuccess(taos, sql, expectedFields, 5);
+ // }
+
+ // // case 7 : insert into db.? using db.stb(t2,t1) tags(?, ?) (b,ts)values(?,?)
+ // // disordered
+ // {
+ // const char* sql = "insert into db.? using db.stb(t2,t1) tags(?, ?) (b,ts)values(?,?)";
+ // TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ // {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
+ // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}};
+ // printf("case 7 : %s\n", sql);
+ // getFieldsSuccess(taos, sql, expectedFields, 5);
+ // }
+
+ // // case 8 : insert into db.? using db.stb tags(?, ?) values(?,?)
+ // // no field name
+ // {
+ // const char* sql = "insert into db.? using db.stb tags(?, ?) values(?,?)";
+ // TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ // {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
+ // printf("case 8 : %s\n", sql);
+ // getFieldsSuccess(taos, sql, expectedFields, 5);
+ // }
+
+ // // case 9 : insert into db.? using db.stb (t2)tags(?) (ts)values(?)
+ // // less para
+ // {
+ // const char* sql = "insert into db.? using db.stb (t2)tags(?) (ts)values(?)";
+ // TAOS_FIELD_ALL expectedFields[3] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}};
+ // printf("case 9 : %s\n", sql);
+ // getFieldsSuccess(taos, sql, expectedFields, 3);
+ // }
+
+ // // case 10 : insert into db.d0 (ts)values(?)
+ // // less para
+ // {
+ // const char* sql = "insert into db.d0 (ts)values(?)";
+ // TAOS_FIELD_ALL expectedFields[1] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}};
+ // printf("case 10 : %s\n", sql);
+ // getFieldsSuccess(taos, sql, expectedFields, 1);
+ // }
+ // // case 11 : insert into abc using stb tags(?, ?) values(?,?)
+ // // insert create table
+ // {
+ // const char* sql = "insert into abc using stb tags(?, ?) values(?,?)";
+ // TAOS_FIELD_ALL expectedFields[4] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
+ // printf("case 11 : %s\n", sql);
+ // getFieldsSuccess(taos, sql, expectedFields, 4);
+ // }
+
+ // // // case 13 : insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
+ // // values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
+ // // // test all types
+ // // sql =
+ // // "insert into all_stb "
+ // //
+ // "(tbname,tts,tv1,tv2,tv3,tv4,tv5,tv6,tv7,tv8,tv9,tv10,tv11,tv12,tv13,tv14,tv15,ts,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,"
+ // // "v11,v12,v13,v14,v15) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+ // // printf("case 13 : %s\n", sql);
+ // // getFields(taos, sql);
+}
+
+TEST(stmt2Case, insert_ntb_get_fields_Test) {
+ // do_query(taos, "CREATE TABLE db.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);");
+
+ // // // case 3 : INSERT INTO db.ntb VALUES(?,?,?,?)
+ // // // test normal table
+ // {
+ // const char* sql = "INSERT INTO db.ntb VALUES(?,?,?,?)";
+ // TAOS_FIELD_ALL expectedFields[4] = {{"nts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ // {"nb", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
+ // {"nvc", TSDB_DATA_TYPE_BINARY, 0, 0, 18, TAOS_FIELD_COL},
+ // {"ni", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL}};
+ // printf("case 3 : %s\n", sql);
+ // getFieldsSuccess(taos, sql, expectedFields, 4);
+ // }
+
+ // {
+ // // case 4 : insert into db.stb(t1,tbname,ts,t2,b) values(?,?,?,?,?)
+ // // test random order
+ // const char* sql = "insert into db.stb(t1,tbname,ts,t2,b) values(?,?,?,?,?)";
+ // TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ // {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
+ // printf("case 4 : %s\n", sql);
+ // getFieldsSuccess(taos, sql, expectedFields, 5);
+ // }
+}
+
+TEST(stmt2Case, select_get_fields_Test) {
+ // // case 14 : select * from ntb where ts = ?
+ // // query type
+ // sql = "select * from ntb where ts = ?";
+ // printf("case 14 : %s\n", sql);
+ // getQueryFields(taos, sql);
+
+ // // case 15 : select * from ntb where ts = ? and b = ?
+ // // query type
+ // sql = "select * from ntb where ts = ? and b = ?";
+ // printf("case 15 : %s\n", sql);
+ // getQueryFields(taos, sql);
+}
+
+TEST(stmt2Case, db_get_fields_Test) {}
+
+TEST(stmt2Case, get_fields_error_Test) {
+ // {
+ // const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(1,?,?,'abc',?)";
+ // TAOS_FIELD_ALL expectedFields[3] = {{"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ // {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
+ // printf("case 2 : %s\n", sql);
+ // getFieldsSuccess(taos, sql, expectedFields, 3);
+ // }
+}
+
+#pragma GCC diagnostic pop
From 05f836c555e0a60ebf6114728b2a4a6a96db169f Mon Sep 17 00:00:00 2001
From: wangjiaming0909 <604227650@qq.com>
Date: Thu, 26 Dec 2024 16:10:17 +0800
Subject: [PATCH 05/56] fix sma filtering returned wrong rows
---
source/client/test/clientTests.cpp | 4 ++++
source/libs/scalar/src/filter.c | 4 ++--
tests/pytest/util/sql.py | 2 +-
tests/system-test/2-query/smaTest.py | 35 ++++++++++++++++++++++++----
4 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp
index 3e4667fbe7..60f0a72e39 100644
--- a/source/client/test/clientTests.cpp
+++ b/source/client/test/clientTests.cpp
@@ -126,6 +126,10 @@ void fetchCallback(void* param, void* res, int32_t numOfRow) {
void queryCallback(void* param, void* res, int32_t code) {
if (code != TSDB_CODE_SUCCESS) {
(void)printf("failed to execute, reason:%s\n", taos_errstr(res));
+ taos_free_result(res);
+ tsem_t *sem = (tsem_t *)param;
+ tsem_post(sem);
+ return;
}
(void)printf("start to fetch data\n");
taos_fetch_raw_block_a(res, fetchCallback, param);
diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c
index b329bbbd44..6689e12edd 100644
--- a/source/libs/scalar/src/filter.c
+++ b/source/libs/scalar/src/filter.c
@@ -5128,8 +5128,8 @@ static int32_t fltSclCollectOperatorFromNode(SNode *pNode, SArray *sclOpList) {
SOperatorNode *pOper = (SOperatorNode *)pNode;
- SValueNode *valNode = (SValueNode *)pOper->pRight;
- if (IS_NUMERIC_TYPE(valNode->node.resType.type) || valNode->node.resType.type == TSDB_DATA_TYPE_TIMESTAMP) {
+ SExprNode* pLeft = (SExprNode*)pOper->pLeft;
+ if (IS_NUMERIC_TYPE(pLeft->resType.type) || pLeft->resType.type == TSDB_DATA_TYPE_TIMESTAMP) {
SNode* pLeft = NULL, *pRight = NULL;
int32_t code = nodesCloneNode(pOper->pLeft, &pLeft);
if (TSDB_CODE_SUCCESS != code) {
diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py
index bb7b8411f9..cdfe3ce8a0 100644
--- a/tests/pytest/util/sql.py
+++ b/tests/pytest/util/sql.py
@@ -100,7 +100,7 @@ class TDSql:
if drop:
s = f'drop database if exists {dbname}'
self.cursor.execute(s)
- s = f'create database {dbname}'
+ s = f'create database {dbname} stt_trigger 1'
for k, v in kwargs.items():
s += f" {k} {v}"
if "duration" not in kwargs:
diff --git a/tests/system-test/2-query/smaTest.py b/tests/system-test/2-query/smaTest.py
index 04fb893e75..355ac04707 100644
--- a/tests/system-test/2-query/smaTest.py
+++ b/tests/system-test/2-query/smaTest.py
@@ -39,6 +39,27 @@ class TDTestCase:
self.create_tables();
self.ts = 1500000000000
+ def test_TD_33336(self):
+ sql = "flush database db"
+ tdSql.execute(sql)
+ time.sleep(5)
+ sql = f'select last(ts) + 1d, last(ts) - 1d from db.t1'
+ tdSql.query(sql, queryTimes=1)
+ lastTs_add1d = tdSql.queryResult[0][0]
+ lastTs_sub1d = tdSql.queryResult[0][1]
+
+ sql = f'select count(*) from db.t1 where ts < "{lastTs_add1d}" and vc1 = 1'
+ tdSql.query(sql, queryTimes=1)
+ all_row_count = tdSql.queryResult[0][0]
+ tdLog.debug(f"all rows: {all_row_count}")
+
+ sql = f'select count(*) from db.t1 where ts < "{lastTs_sub1d}" and vc1 = 1'
+ tdSql.query(sql, queryTimes=1)
+ row_count_sub1d = tdSql.queryResult[0][0]
+ tdLog.debug(f"row_count_sub1d: {row_count_sub1d}")
+
+ if row_count_sub1d > all_row_count:
+ tdLog.exit(f' err rows returned for sql: {sql} row_count_sub1d: {row_count_sub1d} > all_row_count: {all_row_count}')
# run case
def run(self):
@@ -53,6 +74,8 @@ class TDTestCase:
# self.test_case2()
tdLog.debug(" LIMIT test_case2 ............ [OK]")
+ self.test_TD_33336()
+
# stop
def stop(self):
tdSql.close()
@@ -65,11 +88,11 @@ class TDTestCase:
# create table
def create_tables(self, dbname="db"):
# super table
- tdSql.execute(f"create table {dbname}.st(ts timestamp, i1 int,i2 int) tags(area int)")
+ tdSql.execute(f"create table {dbname}.st(ts timestamp, i1 int,i2 int, vc1 varchar(255)) tags(area int)")
# child table
tdSql.execute(f"create table {dbname}.t1 using {dbname}.st tags(1)")
- tdSql.execute(f"create table {dbname}.st1(ts timestamp, i1 int ,i2 int) tags(area int) sma(i2) ")
+ tdSql.execute(f"create table {dbname}.st1(ts timestamp, i1 int ,i2 int, vc1 varchar(255)) tags(area int) sma(i2) ")
tdSql.execute(f"create table {dbname}.t4 using {dbname}.st1 tags(1)")
return
@@ -98,7 +121,11 @@ class TDTestCase:
sql = pre_insert
tdLog.debug("insert table %s rows=%d ..." % (tbname, count))
for i in range(count):
- sql += " (%d,%d,%d)" % (ts_start + i*1000, i, i+1)
+ if random.randint(0, 4) > 2:
+ tail = ''
+ else:
+ tail = 'asd'
+ sql += " (%d,%d,%d,%s)" % (ts_start + i*1000, i, i+1, '"' + str(random.randint(0,5)) + f'{tail}"')
if i > 0 and i % 20000 == 0:
tdLog.info("%d rows inserted" % i)
tdSql.execute(sql)
@@ -125,4 +152,4 @@ class TDTestCase:
# add case with filename
#
tdCases.addWindows(__file__, TDTestCase())
-tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
+tdCases.addLinux(__file__, TDTestCase())
From 0d1a99d7d07bdf4c5e8a5c5f149e83326dd4e2e4 Mon Sep 17 00:00:00 2001
From: "pengrongkun94@qq.com"
Date: Thu, 26 Dec 2024 16:30:50 +0800
Subject: [PATCH 06/56] remove some unused code
---
source/client/inc/clientStmt2.h | 3 -
source/client/src/clientMain.c | 82 +++----
source/client/src/clientStmt2.c | 161 --------------
source/client/test/stmt2Test.cpp | 352 ++++++++++++++++++++++---------
4 files changed, 281 insertions(+), 317 deletions(-)
diff --git a/source/client/inc/clientStmt2.h b/source/client/inc/clientStmt2.h
index 0fe813473d..05a4c849f8 100644
--- a/source/client/inc/clientStmt2.h
+++ b/source/client/inc/clientStmt2.h
@@ -221,11 +221,8 @@ int stmtPrepare2(TAOS_STMT2 *stmt, const char *sql, unsigned long length
int stmtSetTbName2(TAOS_STMT2 *stmt, const char *tbName);
int stmtSetTbTags2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *tags);
int stmtBindBatch2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *bind, int32_t colIdx);
-int stmtGetTagFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields);
-int stmtGetColFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields);
int stmtGetStbColFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_ALL **fields);
int stmtGetParamNum2(TAOS_STMT2 *stmt, int *nums);
-int stmtGetParamTbName(TAOS_STMT2 *stmt, int *nums);
int stmtIsInsert2(TAOS_STMT2 *stmt, int *insert);
TAOS_RES *stmtUseResult2(TAOS_STMT2 *stmt);
const char *stmtErrstr2(TAOS_STMT2 *stmt);
diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c
index f041e4b030..83aff351dd 100644
--- a/source/client/src/clientMain.c
+++ b/source/client/src/clientMain.c
@@ -24,13 +24,13 @@
#include "query.h"
#include "scheduler.h"
#include "tcompare.h"
+#include "tconv.h"
#include "tdatablock.h"
#include "tglobal.h"
#include "tmsg.h"
#include "tref.h"
#include "trpc.h"
#include "version.h"
-#include "tconv.h"
#define TSC_VAR_NOT_RELEASE 1
#define TSC_VAR_RELEASED 0
@@ -56,12 +56,12 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
}
#ifndef WINDOWS
-static void freeTz(void *p){
+static void freeTz(void *p) {
timezone_t tz = *(timezone_t *)p;
tzfree(tz);
}
-int32_t tzInit(){
+int32_t tzInit() {
pTimezoneMap = taosHashInit(0, MurmurHash3_32, false, HASH_ENTRY_LOCK);
if (pTimezoneMap == NULL) {
return terrno;
@@ -75,15 +75,15 @@ int32_t tzInit(){
return 0;
}
-void tzCleanup(){
+void tzCleanup() {
taosHashCleanup(pTimezoneMap);
taosHashCleanup(pTimezoneNameMap);
}
-static timezone_t setConnnectionTz(const char* val){
- timezone_t tz = NULL;
+static timezone_t setConnnectionTz(const char *val) {
+ timezone_t tz = NULL;
timezone_t *tmp = taosHashGet(pTimezoneMap, val, strlen(val));
- if (tmp != NULL && *tmp != NULL){
+ if (tmp != NULL && *tmp != NULL) {
tz = *tmp;
goto END;
}
@@ -100,20 +100,20 @@ static timezone_t setConnnectionTz(const char* val){
}
}
int32_t code = taosHashPut(pTimezoneMap, val, strlen(val), &tz, sizeof(timezone_t));
- if (code != 0){
+ if (code != 0) {
tscError("%s put timezone to tz map error:%d", __func__, code);
tzfree(tz);
tz = NULL;
goto END;
}
- time_t tx1 = taosGetTimestampSec();
- char output[TD_TIMEZONE_LEN] = {0};
+ time_t tx1 = taosGetTimestampSec();
+ char output[TD_TIMEZONE_LEN] = {0};
code = taosFormatTimezoneStr(tx1, val, tz, output);
- if (code == 0){
+ if (code == 0) {
code = taosHashPut(pTimezoneNameMap, &tz, sizeof(timezone_t), output, strlen(output) + 1);
}
- if (code != 0){
+ if (code != 0) {
tscError("failed to put timezone %s to map", val);
}
@@ -122,18 +122,18 @@ END:
}
#endif
-static int32_t setConnectionOption(TAOS *taos, TSDB_OPTION_CONNECTION option, const char* val){
+static int32_t setConnectionOption(TAOS *taos, TSDB_OPTION_CONNECTION option, const char *val) {
if (taos == NULL) {
return terrno = TSDB_CODE_INVALID_PARA;
}
#ifdef WINDOWS
- if (option == TSDB_OPTION_CONNECTION_TIMEZONE){
+ if (option == TSDB_OPTION_CONNECTION_TIMEZONE) {
return terrno = TSDB_CODE_NOT_SUPPORTTED_IN_WINDOWS;
}
#endif
- if (option < TSDB_OPTION_CONNECTION_CLEAR || option >= TSDB_MAX_OPTIONS_CONNECTION){
+ if (option < TSDB_OPTION_CONNECTION_CLEAR || option >= TSDB_MAX_OPTIONS_CONNECTION) {
return terrno = TSDB_CODE_INVALID_PARA;
}
@@ -149,7 +149,7 @@ static int32_t setConnectionOption(TAOS *taos, TSDB_OPTION_CONNECTION option, co
return terrno;
}
- if (option == TSDB_OPTION_CONNECTION_CLEAR){
+ if (option == TSDB_OPTION_CONNECTION_CLEAR) {
val = NULL;
}
@@ -165,19 +165,19 @@ static int32_t setConnectionOption(TAOS *taos, TSDB_OPTION_CONNECTION option, co
goto END;
}
pObj->optionInfo.charsetCxt = tmp;
- }else{
+ } else {
pObj->optionInfo.charsetCxt = NULL;
}
}
if (option == TSDB_OPTION_CONNECTION_TIMEZONE || option == TSDB_OPTION_CONNECTION_CLEAR) {
#ifndef WINDOWS
- if (val != NULL){
- if (val[0] == 0){
+ if (val != NULL) {
+ if (val[0] == 0) {
val = "UTC";
}
timezone_t tz = setConnnectionTz(val);
- if (tz == NULL){
+ if (tz == NULL) {
code = terrno;
goto END;
}
@@ -199,7 +199,7 @@ static int32_t setConnectionOption(TAOS *taos, TSDB_OPTION_CONNECTION option, co
if (option == TSDB_OPTION_CONNECTION_USER_IP || option == TSDB_OPTION_CONNECTION_CLEAR) {
if (val != NULL) {
pObj->optionInfo.userIp = taosInetAddr(val);
- if (pObj->optionInfo.userIp == INADDR_NONE){
+ if (pObj->optionInfo.userIp == INADDR_NONE) {
code = TSDB_CODE_INVALID_PARA;
goto END;
}
@@ -213,7 +213,7 @@ END:
return terrno = code;
}
-int taos_options_connection(TAOS *taos, TSDB_OPTION_CONNECTION option, const void *arg, ...){
+int taos_options_connection(TAOS *taos, TSDB_OPTION_CONNECTION option, const void *arg, ...) {
return setConnectionOption(taos, option, (const char *)arg);
}
@@ -2129,6 +2129,11 @@ int taos_stmt_close(TAOS_STMT *stmt) {
}
TAOS_STMT2 *taos_stmt2_init(TAOS *taos, TAOS_STMT2_OPTION *option) {
+ if (NULL == taos) {
+ tscError("NULL parameter for %s", __FUNCTION__);
+ terrno = TSDB_CODE_INVALID_PARA;
+ return NULL;
+ }
STscObj *pObj = acquireTscObj(*(int64_t *)taos);
if (NULL == pObj) {
tscError("invalid parameter for %s", __FUNCTION__);
@@ -2257,16 +2262,7 @@ int taos_stmt2_close(TAOS_STMT2 *stmt) {
return stmtClose2(stmt);
}
-/*
-int taos_stmt2_param_count(TAOS_STMT2 *stmt, int *nums) {
- if (stmt == NULL || nums == NULL) {
- tscError("NULL parameter for %s", __FUNCTION__);
- terrno = TSDB_CODE_INVALID_PARA;
- return terrno;
- }
- return stmtGetParamNum2(stmt, nums);
-}
-*/
+
int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert) {
if (stmt == NULL || insert == NULL) {
tscError("NULL parameter for %s", __FUNCTION__);
@@ -2277,28 +2273,6 @@ int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert) {
return stmtIsInsert2(stmt, insert);
}
-// int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count, TAOS_FIELD_E **fields) {
-// if (stmt == NULL || count == NULL) {
-// tscError("NULL parameter for %s", __FUNCTION__);
-// terrno = TSDB_CODE_INVALID_PARA;
-// return terrno;
-// }
-
-// if (field_type == TAOS_FIELD_COL) {
-// return stmtGetColFields2(stmt, count, fields);
-// } else if (field_type == TAOS_FIELD_TAG) {
-// return stmtGetTagFields2(stmt, count, fields);
-// } else if (field_type == TAOS_FIELD_QUERY) {
-// return stmtGetParamNum2(stmt, count);
-// } else if (field_type == TAOS_FIELD_TBNAME) {
-// return stmtGetParamTbName(stmt, count);
-// } else {
-// tscError("invalid parameter for %s", __FUNCTION__);
-// terrno = TSDB_CODE_INVALID_PARA;
-// return terrno;
-// }
-// }
-
int taos_stmt2_get_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_ALL **fields) {
if (stmt == NULL || count == NULL) {
tscError("NULL parameter for %s", __FUNCTION__);
diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c
index acd118acc9..f7f4cbb087 100644
--- a/source/client/src/clientStmt2.c
+++ b/source/client/src/clientStmt2.c
@@ -1036,28 +1036,6 @@ int stmtSetTbTags2(TAOS_STMT2* stmt, TAOS_STMT2_BIND* tags) {
return TSDB_CODE_SUCCESS;
}
-static int stmtFetchTagFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_E** fields) {
- if (pStmt->errCode != TSDB_CODE_SUCCESS) {
- return pStmt->errCode;
- }
-
- if (STMT_TYPE_QUERY == pStmt->sql.type) {
- tscError("invalid operation to get query tag fileds");
- STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
- }
-
- STableDataCxt** pDataBlock =
- (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
- if (NULL == pDataBlock) {
- tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
- STMT_ERR_RET(TSDB_CODE_APP_ERROR);
- }
-
- STMT_ERR_RET(qBuildStmtTagFields(*pDataBlock, pStmt->bInfo.boundTags, fieldNum, fields));
-
- return TSDB_CODE_SUCCESS;
-}
-
static int stmtFetchColFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_E** fields) {
if (pStmt->errCode != TSDB_CODE_SUCCESS) {
return pStmt->errCode;
@@ -1819,47 +1797,6 @@ int stmtAffectedRows(TAOS_STMT* stmt) { return ((STscStmt2*)stmt)->affectedRows;
int stmtAffectedRowsOnce(TAOS_STMT* stmt) { return ((STscStmt2*)stmt)->exec.affectedRows; }
*/
-int stmtGetTagFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_E** fields) {
- int32_t code = 0;
- STscStmt2* pStmt = (STscStmt2*)stmt;
- int32_t preCode = pStmt->errCode;
-
- STMT_DLOG_E("start to get tag fields");
-
- if (pStmt->errCode != TSDB_CODE_SUCCESS) {
- return pStmt->errCode;
- }
-
- if (STMT_TYPE_QUERY == pStmt->sql.type) {
- STMT_ERRI_JRET(TSDB_CODE_TSC_STMT_API_ERROR);
- }
-
- STMT_ERRI_JRET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS));
-
- if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 &&
- STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
- pStmt->bInfo.needParse = false;
- }
-
- if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) {
- taos_free_result(pStmt->exec.pRequest);
- pStmt->exec.pRequest = NULL;
- }
-
- STMT_ERRI_JRET(stmtCreateRequest(pStmt));
-
- if (pStmt->bInfo.needParse) {
- STMT_ERRI_JRET(stmtParseSql(pStmt));
- }
-
- STMT_ERRI_JRET(stmtFetchTagFields2(stmt, nums, fields));
-
-_return:
-
- pStmt->errCode = preCode;
-
- return code;
-}
int stmtParseColFields2(TAOS_STMT2* stmt) {
int32_t code = 0;
@@ -1902,15 +1839,6 @@ _return:
return code;
}
-int stmtGetColFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_E** fields) {
- int32_t code = stmtParseColFields2(stmt);
- if (code != TSDB_CODE_SUCCESS) {
- return code;
- }
-
- return stmtFetchColFields2(stmt, nums, fields);
-}
-
int stmtGetStbColFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_ALL** fields) {
int32_t code = stmtParseColFields2(stmt);
if (code != TSDB_CODE_SUCCESS) {
@@ -1956,95 +1884,6 @@ int stmtGetParamNum2(TAOS_STMT2* stmt, int* nums) {
return TSDB_CODE_SUCCESS;
}
-int stmtGetParamTbName(TAOS_STMT2* stmt, int* nums) {
- STscStmt2* pStmt = (STscStmt2*)stmt;
- int32_t code = 0;
- int32_t preCode = pStmt->errCode;
-
- STMT_DLOG_E("start to get param num");
-
- if (pStmt->errCode != TSDB_CODE_SUCCESS) {
- return pStmt->errCode;
- }
-
- STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS));
-
- if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 &&
- STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
- pStmt->bInfo.needParse = false;
- }
-
- if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) {
- taos_free_result(pStmt->exec.pRequest);
- pStmt->exec.pRequest = NULL;
- }
-
- STMT_ERR_RET(stmtCreateRequest(pStmt));
-
- if (pStmt->bInfo.needParse) {
- STMT_ERRI_JRET(stmtParseSql(pStmt));
- }
-
- *nums = STMT_TYPE_MULTI_INSERT == pStmt->sql.type ? 1 : 0;
-
-_return:
- if (TSDB_CODE_TSC_STMT_TBNAME_ERROR == code) {
- *nums = 1;
- code = TSDB_CODE_SUCCESS;
- }
-
- pStmt->errCode = preCode;
- return code;
-}
-/*
-int stmtGetParam(TAOS_STMT* stmt, int idx, int* type, int* bytes) {
- STscStmt2* pStmt = (STscStmt2*)stmt;
-
- STMT_DLOG_E("start to get param");
-
- if (pStmt->errCode != TSDB_CODE_SUCCESS) {
- return pStmt->errCode;
- }
-
- if (STMT_TYPE_QUERY == pStmt->sql.type) {
- STMT_RET(TSDB_CODE_TSC_STMT_API_ERROR);
- }
-
- STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS));
-
- if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 &&
- STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
- pStmt->bInfo.needParse = false;
- }
-
- if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) {
- taos_free_result(pStmt->exec.pRequest);
- pStmt->exec.pRequest = NULL;
- }
-
- STMT_ERR_RET(stmtCreateRequest(pStmt));
-
- if (pStmt->bInfo.needParse) {
- STMT_ERR_RET(stmtParseSql(pStmt));
- }
-
- int32_t nums = 0;
- TAOS_FIELD_E* pField = NULL;
- STMT_ERR_RET(stmtFetchColFields(stmt, &nums, &pField));
- if (idx >= nums) {
- tscError("idx %d is too big", idx);
- taosMemoryFree(pField);
- STMT_ERR_RET(TSDB_CODE_INVALID_PARA);
- }
-
- *type = pField[idx].type;
- *bytes = pField[idx].bytes;
-
- taosMemoryFree(pField);
-
- return TSDB_CODE_SUCCESS;
-}
-*/
TAOS_RES* stmtUseResult2(TAOS_STMT2* stmt) {
STscStmt2* pStmt = (STscStmt2*)stmt;
diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp
index c325ed3a38..267b777ff3 100644
--- a/source/client/test/stmt2Test.cpp
+++ b/source/client/test/stmt2Test.cpp
@@ -27,10 +27,17 @@
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
+#include "../inc/clientStmt.h"
+#include "../inc/clientStmt2.h"
#include "executor.h"
#include "taos.h"
namespace {
+void stmtAsyncQueryCb(void* param, TAOS_RES* pRes, int code) {
+ int affected_rows = taos_affected_rows(pRes);
+ return;
+}
+
void getFieldsSuccess(TAOS* taos, const char* sql, TAOS_FIELD_ALL* expectedFields, int expectedFieldNum) {
TAOS_STMT2_OPTION option = {0};
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
@@ -55,28 +62,35 @@ void getFieldsSuccess(TAOS* taos, const char* sql, TAOS_FIELD_ALL* expectedField
taos_stmt2_close(stmt);
}
-void getQueryFields(TAOS* taos, const char* sql) {
+void getFieldsError(TAOS* taos, const char* sql, int errorCode) {
TAOS_STMT2_OPTION option = {0};
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
int code = taos_stmt2_prepare(stmt, sql, 0);
- if (code != 0) {
- printf("failed to execute taos_stmt2_prepare. error:%s\n", taos_stmt2_error(stmt));
- taos_stmt2_close(stmt);
- return;
- }
+ ASSERT_EQ(code, 0);
+
int fieldNum = 0;
TAOS_FIELD_ALL* pFields = NULL;
code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields);
- if (code != 0) {
- printf("failed get col,ErrCode: 0x%x, ErrMessage: %s.\n", code, taos_stmt2_error(stmt));
- } else {
- printf("bind nums:%d\n", fieldNum);
- }
- printf("====================================\n");
+ ASSERT_EQ(code, errorCode);
taos_stmt2_free_fields(stmt, pFields);
taos_stmt2_close(stmt);
}
+void getQueryFields(TAOS* taos, const char* sql, int expectedFieldNum) {
+ TAOS_STMT2_OPTION option = {0};
+ TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
+ int code = taos_stmt2_prepare(stmt, sql, 0);
+ ASSERT_EQ(code, 0);
+
+ int fieldNum = 0;
+ TAOS_FIELD_ALL* pFields = NULL;
+ code = taos_stmt2_get_fields(stmt, &fieldNum, NULL);
+ ASSERT_EQ(code, 0);
+ ASSERT_EQ(fieldNum, expectedFieldNum);
+ taos_stmt2_free_fields(stmt, NULL);
+ taos_stmt2_close(stmt);
+}
+
void do_query(TAOS* taos, const char* sql) {
TAOS_RES* result = taos_query(taos, sql);
int code = taos_errno(result);
@@ -169,94 +183,134 @@ TEST(stmt2Case, insert_stb_get_fields_Test) {
do_query(taos, "drop database if exists db");
do_query(taos, "create database db PRECISION 'ns'");
- do_query(taos, "use db");
do_query(taos,
"create table db.stb (ts timestamp, b binary(10)) tags(t1 "
"int, t2 binary(10))");
do_query(
taos,
- "create table if not exists all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 "
+ "create table if not exists db.all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 "
"tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 "
"binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20))tags(tts timestamp, tv1 bool, tv2 tinyint, tv3 "
"smallint, tv4 int, tv5 bigint, tv6 tinyint unsigned, tv7 smallint unsigned, tv8 int unsigned, tv9 bigint "
"unsigned, tv10 float, tv11 double, tv12 binary(20), tv13 varbinary(20), tv14 geometry(100), tv15 nchar(20));");
+ printf("support case \n");
- // // case 1 : test super table
- // {
- // const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)";
- // TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
- // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
- // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
- // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
- // {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
- // printf("case 1 : %s\n", sql);
- // getFieldsSuccess(taos, sql, expectedFields, 5);
- // }
-
- // case 2 : no tbname
+ // case 1 : test super table
{
- const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(1,?,?,'abc',?)";
- TAOS_FIELD_ALL expectedFields[3] = {{"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)";
+ TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
+ {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
+ printf("case 1 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 5);
+ }
+
+ {
+ // case 2 : no tag
+ const char* sql = "insert into db.stb(ts,b,tbname) values(?,?,?)";
+ TAOS_FIELD_ALL expectedFields[3] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
printf("case 2 : %s\n", sql);
getFieldsSuccess(taos, sql, expectedFields, 3);
}
+ // case 3 : random order
{
- // case 3 : insert into db.stb(ts,b,tbname) values(?,?,?)
- // no tag
- const char* sql = "insert into db.stb(ts,b,tbname) values(?,?,?)";
- TAOS_FIELD_ALL expectedFields[3] = {
- {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
- {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
- {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
- };
- printf("case 5 : %s\n", sql);
- getFieldsSuccess(taos, sql, expectedFields, 3);
+ const char* sql = "insert into db.stb(tbname,ts,t2,b,t1) values(?,?,?,?,?)";
+ TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
+ {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}};
+ printf("case 3 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 5);
}
- // case 12 : insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
- // values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
- // test all types
+ // case 4 : random order
{
- const char* sql =
- "insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
- TAOS_FIELD_ALL expectedFields[33] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
- {"tts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_TAG},
- {"tv1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_TAG},
- {"tv2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_TAG},
- {"tv3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
- {"tv4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
- {"tv5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_TAG},
- {"tv6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_TAG},
- {"tv7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
- {"tv8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_TAG},
- {"tv9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_TAG},
- {"tv10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_TAG},
- {"tv11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_TAG},
- {"tv12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_TAG},
- {"tv13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_TAG},
- {"tv14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_TAG},
- {"tv15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_TAG},
- {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
- {"v1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_COL},
- {"v2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_COL},
- {"v3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_COL},
- {"v4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL},
- {"v5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_COL},
- {"v6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_COL},
- {"v7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_COL},
- {"v8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_COL},
- {"v9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_COL},
- {"v10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_COL},
- {"v11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_COL},
- {"v12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_COL},
- {"v13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_COL},
- {"v14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_COL},
- {"v15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_COL}};
- printf("case 12 : %s\n", sql);
- getFieldsSuccess(taos, sql, expectedFields, 33);
+ const char* sql = "insert into db.stb(tbname,ts,t2,b,t1) values(?,?,?,?,?)";
+ TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
+ {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}};
+ printf("case 4 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 5);
+ }
+
+ // case 5 : 'db'.'stb'
+ {
+ const char* sql = "insert into 'db'.'stb'(t1,t2,ts,b,tbname) values(?,?,?,?,?)";
+ TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
+ {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
+ printf("case 5 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 5);
+ }
+
+ // case 6 : use db
+ {
+ do_query(taos, "use db");
+ const char* sql = "insert into stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)";
+ TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
+ {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
+ printf("case 6 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 5);
+ }
+
+ // case 7 : less param
+ {
+ const char* sql = "insert into db.stb(ts,tbname) values(?,?)";
+ TAOS_FIELD_ALL expectedFields[2] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
+ printf("case 7 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 2);
+ }
+
+ // not support case
+ printf("not support case \n");
+
+ // case 5 : add in main TD-33353
+ // {
+ // const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(1,?,?,'abc',?)";
+ // printf("case 2 : %s\n", sql);
+ // getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
+ // }
+
+ // case 7 : no pk
+ {
+ const char* sql = "insert into db.stb(b,tbname) values(?,?)";
+ printf("case 7 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
+ }
+
+ // case 5 : no tbname and tag(not support bind)
+ {
+ const char* sql = "insert into db.stb(ts,b) values(?,?)";
+ printf("case 5 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
+ }
+
+ // case 5 : no tbname and tag(not support bind)
+ {
+ const char* sql = "insert into db.stb(tbname) values(?)";
+ printf("case 5 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
+ }
+
+ // case 8 : no param
+ {
+ const char* sql = "insert into db.stb(?,?,?,?,?)";
+ printf("case 8 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
}
taos_close(taos);
@@ -356,6 +410,49 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) {
// // "v11,v12,v13,v14,v15) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
// // printf("case 13 : %s\n", sql);
// // getFields(taos, sql);
+
+ // case 12 : insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
+ // values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
+ // test all types
+ // {
+ // const char* sql =
+ // "insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+ // TAOS_FIELD_ALL expectedFields[33] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ // {"tts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_TAG},
+ // {"tv1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_TAG},
+ // {"tv2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_TAG},
+ // {"tv3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
+ // {"tv4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ // {"tv5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_TAG},
+ // {"tv6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_TAG},
+ // {"tv7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
+ // {"tv8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_TAG},
+ // {"tv9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_TAG},
+ // {"tv10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_TAG},
+ // {"tv11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_TAG},
+ // {"tv12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_TAG},
+ // {"tv13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_TAG},
+ // {"tv14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_TAG},
+ // {"tv15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_TAG},
+ // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ // {"v1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_COL},
+ // {"v2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_COL},
+ // {"v3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_COL},
+ // {"v4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL},
+ // {"v5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_COL},
+ // {"v6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_COL},
+ // {"v7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_COL},
+ // {"v8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_COL},
+ // {"v9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_COL},
+ // {"v10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_COL},
+ // {"v11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_COL},
+ // {"v12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_COL},
+ // {"v13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_COL},
+ // {"v14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_COL},
+ // {"v15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_COL}};
+ // printf("case 12 : %s\n", sql);
+ // getFieldsSuccess(taos, sql, expectedFields, 33);
+ // }
}
TEST(stmt2Case, insert_ntb_get_fields_Test) {
@@ -388,30 +485,87 @@ TEST(stmt2Case, insert_ntb_get_fields_Test) {
}
TEST(stmt2Case, select_get_fields_Test) {
- // // case 14 : select * from ntb where ts = ?
- // // query type
- // sql = "select * from ntb where ts = ?";
- // printf("case 14 : %s\n", sql);
- // getQueryFields(taos, sql);
+ TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
+ ASSERT_NE(taos, nullptr);
+ do_query(taos, "drop database if exists db");
+ do_query(taos, "create database db PRECISION 'ns'");
+ do_query(taos, "use db");
+ do_query(taos, "CREATE TABLE db.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);");
+ {
+ // case 1 : select * from ntb where ts = ?
+ // query type
+ const char* sql = "select * from ntb where ts = ?";
+ printf("case 1 : %s\n", sql);
+ getQueryFields(taos, sql, 1);
+ }
- // // case 15 : select * from ntb where ts = ? and b = ?
- // // query type
- // sql = "select * from ntb where ts = ? and b = ?";
- // printf("case 15 : %s\n", sql);
- // getQueryFields(taos, sql);
+ {
+ // case 2 : select * from ntb where ts = ? and b = ?
+ // query type
+ const char* sql = "select * from ntb where ts = ? and b = ?";
+ printf("case 2 : %s\n", sql);
+ getQueryFields(taos, sql, 2);
+ }
}
-TEST(stmt2Case, db_get_fields_Test) {}
-
TEST(stmt2Case, get_fields_error_Test) {
- // {
- // const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(1,?,?,'abc',?)";
- // TAOS_FIELD_ALL expectedFields[3] = {{"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
- // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
- // {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
- // printf("case 2 : %s\n", sql);
- // getFieldsSuccess(taos, sql, expectedFields, 3);
- // }
+ // case 1 :
+ {
+ printf("case 1 : NULL param \n");
+ int code = taos_stmt2_get_fields(NULL, NULL, NULL);
+ ASSERT_EQ(code, TSDB_CODE_INVALID_PARA);
+ }
}
+TEST(stmt2Case, stmt2_init_prepare_Test) {
+ TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
+
+ {
+ (void)taos_stmt2_init(NULL, NULL);
+ ASSERT_EQ(terrno, TSDB_CODE_INVALID_PARA);
+ terrno = 0;
+ }
+
+ {
+ (void)taos_stmt2_prepare(NULL, NULL, 0);
+ ASSERT_EQ(terrno, TSDB_CODE_INVALID_PARA);
+ terrno = 0;
+ }
+
+ {
+ TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
+ TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
+ ASSERT_EQ(terrno, 0);
+ ASSERT_NE(stmt, nullptr);
+ int code = taos_stmt2_prepare(stmt, "wrong sql", 0);
+ ASSERT_EQ(terrno, 0);
+ ASSERT_NE(stmt, nullptr);
+ ASSERT_EQ(((STscStmt2*)stmt)->db, nullptr);
+
+ code = taos_stmt2_prepare(stmt, "insert into 'db'.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)", 0);
+ ASSERT_EQ(terrno, 0);
+ ASSERT_NE(stmt, nullptr);
+ // ASSERT_STREQ(((STscStmt2*)stmt)->db, "db"); //add in main TD-33332
+ taos_stmt2_close(stmt);
+ }
+
+ {
+ TAOS_STMT2_OPTION option = {0, true, false, NULL, NULL};
+ TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
+ ASSERT_EQ(terrno, 0);
+ ASSERT_NE(stmt, nullptr);
+ taos_stmt2_close(stmt);
+ }
+
+ {
+ TAOS_STMT2_OPTION option = {0, true, true, stmtAsyncQueryCb, NULL};
+ TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
+ ASSERT_EQ(terrno, 0);
+ ASSERT_NE(stmt, nullptr);
+ taos_stmt2_close(stmt);
+ }
+}
+
+TEST(stmt2Case, stmt2_status_Test) {}
+
#pragma GCC diagnostic pop
From d5f1aab4fec0ee28ac1fabc58c1571f1d340f5b1 Mon Sep 17 00:00:00 2001
From: Minglei Jin
Date: Thu, 26 Dec 2024 18:27:43 +0800
Subject: [PATCH 07/56] fix(tdb/cd): free cell decoder's mem w.r.t. btree prev
---
source/libs/tdb/src/db/tdbBtree.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c
index 19a3f211b1..c806bdfbd8 100644
--- a/source/libs/tdb/src/db/tdbBtree.c
+++ b/source/libs/tdb/src/db/tdbBtree.c
@@ -2023,16 +2023,29 @@ int tdbBtreePrev(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
memcpy(pKey, cd.pKey, (size_t)cd.kLen);
if (ppVal) {
- // TODO: vLen may be zero
- pVal = tdbRealloc(*ppVal, cd.vLen);
- if (pVal == NULL) {
- tdbFree(pKey);
- return terrno;
+ if (cd.vLen > 0) {
+ pVal = tdbRealloc(*ppVal, cd.vLen);
+ if (pVal == NULL) {
+ tdbFree(pKey);
+ return terrno;
+ }
+
+ memcpy(pVal, cd.pVal, (size_t)cd.vLen);
+ if (TDB_CELLDECODER_FREE_VAL(&cd)) {
+ tdbTrace("tdb/btree-next decoder: %p pVal free: %p", &cd, cd.pVal);
+ tdbFree(cd.pVal);
+ }
+ } else {
+ pVal = NULL;
}
*ppVal = pVal;
*vLen = cd.vLen;
- memcpy(pVal, cd.pVal, (size_t)cd.vLen);
+ } else {
+ if (TDB_CELLDECODER_FREE_VAL(&cd)) {
+ tdbTrace("tdb/btree-next2 decoder: %p pVal free: %p", &cd, cd.pVal);
+ tdbFree(cd.pVal);
+ }
}
ret = tdbBtcMoveToPrev(pBtc);
From 69aac6d778c23a4f93ff517133b6d880e2ecaf5a Mon Sep 17 00:00:00 2001
From: "pengrongkun94@qq.com"
Date: Thu, 26 Dec 2024 18:40:07 +0800
Subject: [PATCH 08/56] finish stmt2 get fiels test
---
source/client/test/stmt2Test.cpp | 615 +++++++++++++++++++------------
1 file changed, 380 insertions(+), 235 deletions(-)
diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp
index 267b777ff3..bf05f7788b 100644
--- a/source/client/test/stmt2Test.cpp
+++ b/source/client/test/stmt2Test.cpp
@@ -103,68 +103,12 @@ void do_query(TAOS* taos, const char* sql) {
// printf("=================error test===================\n");
-// // case 14 : INSERT INTO db.d0 using db.stb values(?,?)
-// // none para for ctbname
-// sql = "INSERT INTO db.d0 using db.stb values(?,?)";
-// printf("case 14 (no tags error): %s\n", sql);
-// getFields(taos, sql);
-
-// // case 15 : insert into db.stb(t1,t2,tbname) values(?,?,?)
-// // no value
-// sql = "insert into db.stb(t1,t2,tbname) values(?,?,?)";
-// printf("case 15 (no PK error): %s\n", sql);
-// getFields(taos, sql);
-
-// // case 16 : insert into db.stb(ts,b,tbname) values(?,?,?,?,?)
-// // wrong para nums
-// sql = "insert into db.stb(ts,b,tbname) values(?,?,?,?,?)";
-// printf("case 16 (wrong para nums): %s\n", sql);
-// getFields(taos, sql);
-
-// // case 17 : insert into db.? values(?,?)
-// // normal table must have tbnam
-// sql = "insert into db.? values(?,?)";
-// printf("case 17 (normal table must have tbname): %s\n", sql);
-// getFields(taos, sql);
-
-// // case 18 : INSERT INTO db.stb(t1,t2,ts,b) values(?,?,?,?)
-// // no tbname error
-// sql = "INSERT INTO db.stb(t1,t2,ts,b) values(?,?,?,?)";
-// printf("case 18 (no tbname error): %s\n", sql);
-// getFields(taos, sql);
-
-// // case 19 : insert into db.ntb(nts,ni) values(?,?,?,?,?)
-// // wrong para nums
-// sql = "insert into ntb(nts,ni) values(?,?,?,?,?)";
-// printf("case 19 : %s\n", sql);
-// getFields(taos, sql);
-
-// // case 20 : insert into db.stb(t1,t2,ts,b,tbname) values(*,*,*,*,*)
-// // wrong simbol
-// sql = "insert into db.stb(t1,t2,ts,b,tbname) values(*,*,*,*,*)";
-// printf("=================normal test===================\n");
-// printf("case 20 : %s\n", sql);
-// getFields(taos, sql);
-
-// // case 21 : INSERT INTO ! using db.stb TAGS(?,?) VALUES(?,?)
-// // wrong simbol
-// sql = "insert into ! using db.stb tags(?, ?) values(?,?)";
-// printf("case 21 : %s\n", sql);
-// getFields(taos, sql);
-
// // case 22 : INSERT INTO ! using db.stb TAGS(?,?) VALUES(?,?)
// // wrong tbname
// sql = "insert into db.stb values(?,?)";
// printf("case 22 : %s\n", sql);
// getFields(taos, sql);
-// // case 23 : select * from ? where ts = ?
-// // wrong query type
-// sql = "select * from ? where ts = ?";
-// printf("case 23 : %s\n", sql);
-// getQueryFields(taos, sql);
-// }
-
} // namespace
int main(int argc, char** argv) {
@@ -229,13 +173,13 @@ TEST(stmt2Case, insert_stb_get_fields_Test) {
getFieldsSuccess(taos, sql, expectedFields, 5);
}
- // case 4 : random order
+ // case 4 : random order 2
{
- const char* sql = "insert into db.stb(tbname,ts,t2,b,t1) values(?,?,?,?,?)";
- TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
- {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
- {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ const char* sql = "insert into db.stb(ts,tbname,b,t2,t1) values(?,?,?,?,?)";
+ TAOS_FIELD_ALL expectedFields[5] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
{"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}};
printf("case 4 : %s\n", sql);
getFieldsSuccess(taos, sql, expectedFields, 5);
@@ -275,6 +219,50 @@ TEST(stmt2Case, insert_stb_get_fields_Test) {
getFieldsSuccess(taos, sql, expectedFields, 2);
}
+ // case 8 : test all types
+ {
+ const char* sql =
+ "insert into "
+ "all_stb(tbname,tts,tv1,tv2,tv3,tv4,tv5,tv6,tv7,tv8,tv9,tv10,tv11,tv12,tv13,tv14,tv15,ts,v1,v2,v3,v4,v5,v6,v7,"
+ "v8,v9,v10,"
+ "v11,v12,v13,v14,v15) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+ TAOS_FIELD_ALL expectedFields[33] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ {"tts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_TAG},
+ {"tv1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_TAG},
+ {"tv2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_TAG},
+ {"tv3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
+ {"tv4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"tv5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_TAG},
+ {"tv6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_TAG},
+ {"tv7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
+ {"tv8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"tv9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_TAG},
+ {"tv10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"tv11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_TAG},
+ {"tv12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_TAG},
+ {"tv13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_TAG},
+ {"tv14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_TAG},
+ {"tv15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_TAG},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"v1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_COL},
+ {"v2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_COL},
+ {"v3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_COL},
+ {"v4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL},
+ {"v5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_COL},
+ {"v6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_COL},
+ {"v7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_COL},
+ {"v8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_COL},
+ {"v9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_COL},
+ {"v10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_COL},
+ {"v11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_COL},
+ {"v12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_COL},
+ {"v13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_COL},
+ {"v14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_COL},
+ {"v15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_COL}};
+ printf("case 8 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 33);
+ }
+
// not support case
printf("not support case \n");
@@ -285,32 +273,60 @@ TEST(stmt2Case, insert_stb_get_fields_Test) {
// getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
// }
- // case 7 : no pk
+ // case 2 : no pk
{
const char* sql = "insert into db.stb(b,tbname) values(?,?)";
+ printf("case 2 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
+ }
+
+ // case 3 : no tbname and tag(not support bind)
+ {
+ const char* sql = "insert into db.stb(ts,b) values(?,?)";
+ printf("case 3 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
+ }
+
+ // case 4 : no col and tag(not support bind)
+ {
+ const char* sql = "insert into db.stb(tbname) values(?)";
+ printf("case 4 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
+ }
+
+ // case 5 : no field name
+ {
+ const char* sql = "insert into db.stb(?,?,?,?,?)";
+ printf("case 5 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
+ }
+
+ // case 6 : test super table not exist
+ {
+ const char* sql = "insert into db.nstb(?,?,?,?,?)";
+ printf("case 6 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
+ }
+
+ // case 7 : no col
+ {
+ const char* sql = "insert into db.stb(t1,t2,tbname) values(?,?,?)";
printf("case 7 : %s\n", sql);
getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
}
- // case 5 : no tbname and tag(not support bind)
+ // case 8 : wrong para nums
{
- const char* sql = "insert into db.stb(ts,b) values(?,?)";
- printf("case 5 : %s\n", sql);
- getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
- }
-
- // case 5 : no tbname and tag(not support bind)
- {
- const char* sql = "insert into db.stb(tbname) values(?)";
- printf("case 5 : %s\n", sql);
- getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
- }
-
- // case 8 : no param
- {
- const char* sql = "insert into db.stb(?,?,?,?,?)";
+ const char* sql = "insert into db.stb(ts,b,tbname) values(?,?,?,?,?)";
printf("case 8 : %s\n", sql);
- getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
+ getFieldsError(taos, sql, TSDB_CODE_PAR_INVALID_COLUMNS_NUM);
+ }
+
+ // case 9 : wrong simbol
+ {
+ const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(*,*,*,*,*)";
+ printf("case 9 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_TSC_SQL_SYNTAX_ERROR);
}
taos_close(taos);
@@ -318,170 +334,295 @@ TEST(stmt2Case, insert_stb_get_fields_Test) {
}
TEST(stmt2Case, insert_ctb_using_get_fields_Test) {
- // do_query(taos, "CREATE TABLE db.d0 USING db.stb (t1,t2) TAGS (7,'Cali');");
+ TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
+ ASSERT_NE(taos, nullptr);
- // // case 2 : INSERT INTO db.d0 VALUES (?,?)
- // // test child table
- // {
- // const char* sql = "INSERT INTO db.d0(ts,b) VALUES (?,?)";
- // TAOS_FIELD_ALL expectedFields[2] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
- // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
- // printf("case 2 : %s\n", sql);
- // getFieldsSuccess(taos, sql, expectedFields, 2);
- // }
+ do_query(taos, "drop database if exists db");
+ do_query(taos, "create database db PRECISION 'ns'");
+ do_query(taos,
+ "create table db.stb (ts timestamp, b binary(10)) tags(t1 "
+ "int, t2 binary(10))");
+ do_query(
+ taos,
+ "create table if not exists db.all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 "
+ "tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 "
+ "binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20))tags(tts timestamp, tv1 bool, tv2 tinyint, tv3 "
+ "smallint, tv4 int, tv5 bigint, tv6 tinyint unsigned, tv7 smallint unsigned, tv8 int unsigned, tv9 bigint "
+ "unsigned, tv10 float, tv11 double, tv12 binary(20), tv13 varbinary(20), tv14 geometry(100), tv15 nchar(20));");
+ do_query(taos, "CREATE TABLE db.t0 USING db.stb (t1,t2) TAGS (7,'Cali');");
- // // case 6 : INSERT INTO db.? using db.stb (t1,t2)TAGS(?,?) (ts,b)VALUES(?,?)
- // // normal insert clause
- // {
- // const char* sql = "INSERT INTO db.? using db.stb (t1,t2)TAGS(?,?) (ts,b)VALUES(?,?)";
- // TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
- // {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
- // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
- // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
- // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
- // printf("case 6 : %s\n", sql);
- // getFieldsSuccess(taos, sql, expectedFields, 5);
- // }
+ printf("support case \n");
+ // case 1 : test child table already exist
+ {
+ const char* sql = "INSERT INTO db.t0(ts,b)using db.stb (t1,t2) TAGS(?,?) VALUES (?,?)";
+ TAOS_FIELD_ALL expectedFields[4] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
+ printf("case 1 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 4);
+ }
- // // case 7 : insert into db.? using db.stb(t2,t1) tags(?, ?) (b,ts)values(?,?)
- // // disordered
- // {
- // const char* sql = "insert into db.? using db.stb(t2,t1) tags(?, ?) (b,ts)values(?,?)";
- // TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
- // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
- // {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
- // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
- // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}};
- // printf("case 7 : %s\n", sql);
- // getFieldsSuccess(taos, sql, expectedFields, 5);
- // }
+ // case 2 : insert clause
+ {
+ const char* sql = "INSERT INTO db.? using db.stb (t1,t2) TAGS(?,?) (ts,b)VALUES(?,?)";
+ TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
+ printf("case 2 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 5);
+ }
- // // case 8 : insert into db.? using db.stb tags(?, ?) values(?,?)
- // // no field name
- // {
- // const char* sql = "insert into db.? using db.stb tags(?, ?) values(?,?)";
- // TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
- // {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
- // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
- // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
- // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
- // printf("case 8 : %s\n", sql);
- // getFieldsSuccess(taos, sql, expectedFields, 5);
- // }
+ // case 3 : insert child table not exist
+ {
+ const char* sql = "INSERT INTO db.d1 using db.stb (t1,t2)TAGS(?,?) (ts,b)VALUES(?,?)";
+ TAOS_FIELD_ALL expectedFields[4] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
+ printf("case 3 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 4);
+ }
- // // case 9 : insert into db.? using db.stb (t2)tags(?) (ts)values(?)
- // // less para
- // {
- // const char* sql = "insert into db.? using db.stb (t2)tags(?) (ts)values(?)";
- // TAOS_FIELD_ALL expectedFields[3] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
- // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
- // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}};
- // printf("case 9 : %s\n", sql);
- // getFieldsSuccess(taos, sql, expectedFields, 3);
- // }
+ // case 4 : random order
+ {
+ const char* sql = "INSERT INTO db.? using db.stb (t2,t1)TAGS(?,?) (b,ts)VALUES(?,?)";
+ TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}};
+ printf("case 4 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 5);
+ }
- // // case 10 : insert into db.d0 (ts)values(?)
- // // less para
- // {
- // const char* sql = "insert into db.d0 (ts)values(?)";
- // TAOS_FIELD_ALL expectedFields[1] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}};
- // printf("case 10 : %s\n", sql);
- // getFieldsSuccess(taos, sql, expectedFields, 1);
- // }
- // // case 11 : insert into abc using stb tags(?, ?) values(?,?)
- // // insert create table
- // {
- // const char* sql = "insert into abc using stb tags(?, ?) values(?,?)";
- // TAOS_FIELD_ALL expectedFields[4] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
- // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
- // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
- // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
- // printf("case 11 : %s\n", sql);
- // getFieldsSuccess(taos, sql, expectedFields, 4);
- // }
+ // case 5 : less para
+ {
+ const char* sql = "insert into db.? using db.stb (t2)tags(?) (ts)values(?)";
+ TAOS_FIELD_ALL expectedFields[3] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}};
+ printf("case 5 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 3);
+ }
- // // // case 13 : insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
- // // values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
- // // // test all types
- // // sql =
- // // "insert into all_stb "
- // //
- // "(tbname,tts,tv1,tv2,tv3,tv4,tv5,tv6,tv7,tv8,tv9,tv10,tv11,tv12,tv13,tv14,tv15,ts,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,"
- // // "v11,v12,v13,v14,v15) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
- // // printf("case 13 : %s\n", sql);
- // // getFields(taos, sql);
+ // case 6 : insert into db.? using db.stb tags(?, ?) values(?,?)
+ // no field name
+ {
+ const char* sql = "insert into db.? using db.stb tags(?, ?) values(?,?)";
+ TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
+ printf("case 6 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 5);
+ }
- // case 12 : insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
- // values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
- // test all types
- // {
- // const char* sql =
- // "insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
- // TAOS_FIELD_ALL expectedFields[33] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
- // {"tts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_TAG},
- // {"tv1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_TAG},
- // {"tv2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_TAG},
- // {"tv3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
- // {"tv4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
- // {"tv5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_TAG},
- // {"tv6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_TAG},
- // {"tv7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
- // {"tv8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_TAG},
- // {"tv9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_TAG},
- // {"tv10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_TAG},
- // {"tv11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_TAG},
- // {"tv12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_TAG},
- // {"tv13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_TAG},
- // {"tv14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_TAG},
- // {"tv15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_TAG},
- // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
- // {"v1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_COL},
- // {"v2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_COL},
- // {"v3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_COL},
- // {"v4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL},
- // {"v5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_COL},
- // {"v6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_COL},
- // {"v7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_COL},
- // {"v8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_COL},
- // {"v9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_COL},
- // {"v10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_COL},
- // {"v11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_COL},
- // {"v12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_COL},
- // {"v13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_COL},
- // {"v14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_COL},
- // {"v15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_COL}};
- // printf("case 12 : %s\n", sql);
- // getFieldsSuccess(taos, sql, expectedFields, 33);
- // }
+ // case 7 : insert into db.d0 (ts)values(?)
+ // less para
+ {
+ const char* sql = "insert into db.t0 (ts)values(?)";
+ TAOS_FIELD_ALL expectedFields[1] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}};
+ printf("case 7 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 1);
+ }
+
+ // case 8 : 'db' 'stb'
+ {
+ const char* sql = "INSERT INTO 'db'.? using 'db'.'stb' (t1,t2) TAGS(?,?) (ts,b)VALUES(?,?)";
+ TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
+ printf("case 8 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 5);
+ }
+
+ // case 9 : use db
+ {
+ do_query(taos, "use db");
+ const char* sql = "INSERT INTO ? using stb (t1,t2) TAGS(?,?) (ts,b)VALUES(?,?)";
+ TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
+ printf("case 9 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 5);
+ }
+
+ // case 10 : test all types
+ {
+ const char* sql =
+ "insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+ TAOS_FIELD_ALL expectedFields[33] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
+ {"tts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_TAG},
+ {"tv1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_TAG},
+ {"tv2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_TAG},
+ {"tv3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
+ {"tv4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"tv5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_TAG},
+ {"tv6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_TAG},
+ {"tv7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
+ {"tv8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"tv9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_TAG},
+ {"tv10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_TAG},
+ {"tv11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_TAG},
+ {"tv12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_TAG},
+ {"tv13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_TAG},
+ {"tv14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_TAG},
+ {"tv15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_TAG},
+ {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
+ {"v1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_COL},
+ {"v2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_COL},
+ {"v3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_COL},
+ {"v4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL},
+ {"v5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_COL},
+ {"v6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_COL},
+ {"v7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_COL},
+ {"v8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_COL},
+ {"v9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_COL},
+ {"v10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_COL},
+ {"v11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_COL},
+ {"v12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_COL},
+ {"v13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_COL},
+ {"v14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_COL},
+ {"v15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_COL}};
+ printf("case 10 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 33);
+ }
+ printf("not support case \n");
+
+ // case 1 : test super table not exist
+ {
+ const char* sql = "INSERT INTO db.?(ts,b)using db.nstb (t1,t2) TAGS(?,?) VALUES (?,?)";
+ printf("case 1 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
+ }
+
+ // case 2 : no pk
+ {
+ const char* sql = "INSERT INTO db.?(ts,b)using db.nstb (t1,t2) TAGS(?,?) (n)VALUES (?)";
+ printf("case 2 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
+ }
+
+ // case 3 : less param and no filed name
+ {
+ const char* sql = "INSERT INTO db.?(ts,b)using db.stb TAGS(?)VALUES (?,?)";
+ printf("case 3 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
+ }
+
+ // case 4 : none para for ctbname
+ {
+ const char* sql = "INSERT INTO db.d0 using db.stb values(?,?)";
+ printf("case 4 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_TSC_SQL_SYNTAX_ERROR);
+ }
+
+ // case 5 : none para for ctbname
+ {
+ const char* sql = "insert into ! using db.stb tags(?, ?) values(?,?)";
+ printf("case 5 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_TSC_SQL_SYNTAX_ERROR);
+ }
}
TEST(stmt2Case, insert_ntb_get_fields_Test) {
- // do_query(taos, "CREATE TABLE db.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);");
+ TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
+ ASSERT_NE(taos, nullptr);
- // // // case 3 : INSERT INTO db.ntb VALUES(?,?,?,?)
- // // // test normal table
- // {
- // const char* sql = "INSERT INTO db.ntb VALUES(?,?,?,?)";
- // TAOS_FIELD_ALL expectedFields[4] = {{"nts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
- // {"nb", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
- // {"nvc", TSDB_DATA_TYPE_BINARY, 0, 0, 18, TAOS_FIELD_COL},
- // {"ni", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL}};
- // printf("case 3 : %s\n", sql);
- // getFieldsSuccess(taos, sql, expectedFields, 4);
- // }
+ do_query(taos, "drop database if exists db");
+ do_query(taos, "create database db PRECISION 'ms'");
+ do_query(taos, "CREATE TABLE db.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);");
+ do_query(
+ taos,
+ "create table if not exists db.all_ntb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 "
+ "tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 "
+ "binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20));");
- // {
- // // case 4 : insert into db.stb(t1,tbname,ts,t2,b) values(?,?,?,?,?)
- // // test random order
- // const char* sql = "insert into db.stb(t1,tbname,ts,t2,b) values(?,?,?,?,?)";
- // TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
- // {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
- // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
- // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
- // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
- // printf("case 4 : %s\n", sql);
- // getFieldsSuccess(taos, sql, expectedFields, 5);
- // }
+ printf("support case \n");
+
+ // case 1 : test normal table no field name
+ {
+ const char* sql = "INSERT INTO db.ntb VALUES(?,?,?,?)";
+ TAOS_FIELD_ALL expectedFields[4] = {{"nts", TSDB_DATA_TYPE_TIMESTAMP, 0, 0, 8, TAOS_FIELD_COL},
+ {"nb", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
+ {"nvc", TSDB_DATA_TYPE_BINARY, 0, 0, 18, TAOS_FIELD_COL},
+ {"ni", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL}};
+ printf("case 1 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 4);
+ }
+
+ // case 2 : test random order
+ {
+ const char* sql = "INSERT INTO db.ntb (ni,nb,nvc,nts)VALUES(?,?,?,?)";
+ TAOS_FIELD_ALL expectedFields[4] = {{"ni", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL},
+ {"nb", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
+ {"nvc", TSDB_DATA_TYPE_BINARY, 0, 0, 18, TAOS_FIELD_COL},
+ {"nts", TSDB_DATA_TYPE_TIMESTAMP, 0, 0, 8, TAOS_FIELD_COL}};
+ printf("case 2 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 4);
+ }
+
+ // case 3 : less param
+ {
+ const char* sql = "INSERT INTO db.ntb (nts)VALUES(?)";
+ TAOS_FIELD_ALL expectedFields[1] = {{"nts", TSDB_DATA_TYPE_TIMESTAMP, 0, 0, 8, TAOS_FIELD_COL}};
+ printf("case 3 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 1);
+ }
+
+ // case 4 : test all types
+ {
+ const char* sql = "insert into db.all_ntb values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+ TAOS_FIELD_ALL expectedFields[16] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 0, 0, 8, TAOS_FIELD_COL},
+ {"v1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_COL},
+ {"v2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_COL},
+ {"v3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_COL},
+ {"v4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL},
+ {"v5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_COL},
+ {"v6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_COL},
+ {"v7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_COL},
+ {"v8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_COL},
+ {"v9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_COL},
+ {"v10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_COL},
+ {"v11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_COL},
+ {"v12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_COL},
+ {"v13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_COL},
+ {"v14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_COL},
+ {"v15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_COL}};
+ printf("case 4 : %s\n", sql);
+ getFieldsSuccess(taos, sql, expectedFields, 16);
+ }
+
+ printf("not support case \n");
+
+ // case 1 : wrong db
+ {
+ const char* sql = "insert into ntb values(?,?,?,?)";
+ printf("case 1 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
+ }
+
+ // case 2 : normal table must have tbnam
+ {
+ const char* sql = "insert into db.? values(?,?)";
+ printf("case 2 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_PAR_TABLE_NOT_EXIST);
+ }
+
+ // case 3 : wrong para nums
+ {
+ const char* sql = "insert into db.ntb(nts,ni) values(?,?,?,?,?)";
+ printf("case 3 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_PAR_INVALID_COLUMNS_NUM);
+ }
}
TEST(stmt2Case, select_get_fields_Test) {
@@ -492,20 +633,25 @@ TEST(stmt2Case, select_get_fields_Test) {
do_query(taos, "use db");
do_query(taos, "CREATE TABLE db.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);");
{
- // case 1 : select * from ntb where ts = ?
- // query type
+ // case 1 :
const char* sql = "select * from ntb where ts = ?";
printf("case 1 : %s\n", sql);
getQueryFields(taos, sql, 1);
}
{
- // case 2 : select * from ntb where ts = ? and b = ?
- // query type
+ // case 2 :
const char* sql = "select * from ntb where ts = ? and b = ?";
printf("case 2 : %s\n", sql);
getQueryFields(taos, sql, 2);
}
+
+ {
+ // case 3 :
+ const char* sql = "select * from ? where ts = ?";
+ printf("case 3 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
+ }
}
TEST(stmt2Case, get_fields_error_Test) {
@@ -519,7 +665,6 @@ TEST(stmt2Case, get_fields_error_Test) {
TEST(stmt2Case, stmt2_init_prepare_Test) {
TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
-
{
(void)taos_stmt2_init(NULL, NULL);
ASSERT_EQ(terrno, TSDB_CODE_INVALID_PARA);
From 7283d54770d52c8bc5a8a09349446f989d30779e Mon Sep 17 00:00:00 2001
From: "pengrongkun94@qq.com"
Date: Thu, 26 Dec 2024 22:22:06 +0800
Subject: [PATCH 09/56] add bind exec test
---
source/client/test/stmt2Test.cpp | 111 ++++++++++++++++++++++++++++---
1 file changed, 103 insertions(+), 8 deletions(-)
diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp
index bf05f7788b..4542f953ab 100644
--- a/source/client/test/stmt2Test.cpp
+++ b/source/client/test/stmt2Test.cpp
@@ -14,7 +14,7 @@
*/
#include
-#include
+#include
#include "clientInt.h"
#include "osSemaphore.h"
#include "taoserror.h"
@@ -99,15 +99,100 @@ void do_query(TAOS* taos, const char* sql) {
taos_free_result(result);
}
-// void do_stmt(TAOS* taos) {
+void do_stmt(TAOS* taos, const char* sql, int CTB_NUMS, int ROW_NUMS, int CYC_NUMS, bool createTable) {
+ do_query(taos, "drop database if exists db");
+ do_query(taos, "create database db");
+ do_query(taos, "create table db.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))");
+ do_query(taos, "use db");
-// printf("=================error test===================\n");
+ TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
-// // case 22 : INSERT INTO ! using db.stb TAGS(?,?) VALUES(?,?)
-// // wrong tbname
-// sql = "insert into db.stb values(?,?)";
-// printf("case 22 : %s\n", sql);
-// getFields(taos, sql);
+ TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
+ ASSERT_NE(stmt, nullptr);
+ int code = taos_stmt2_prepare(stmt, sql, 0);
+ ASSERT_EQ(code, 0);
+ ASSERT_EQ(terrno, 0);
+
+ // tbname
+ char** tbs = (char**)taosMemoryMalloc(CTB_NUMS * sizeof(char*));
+ for (int i = 0; i < CTB_NUMS; i++) {
+ tbs[i] = (char*)taosMemoryMalloc(sizeof(char) * 20);
+ sprintf(tbs[i], "ctb_%d", i);
+ if (createTable) {
+ char* tmp = (char*)taosMemoryMalloc(sizeof(char) * 100);
+ sprintf(tmp, "create table db.%s using db.stb tags(0, 'after')", tbs[i]);
+ do_query(taos, tmp);
+ }
+ }
+ for (int r = 0; r < CYC_NUMS; r++) {
+ // col params
+ int64_t** ts = (int64_t**)taosMemoryMalloc(CTB_NUMS * sizeof(int64_t*));
+ char** b = (char**)taosMemoryMalloc(CTB_NUMS * sizeof(char*));
+ int* ts_len = (int*)taosMemoryMalloc(ROW_NUMS * sizeof(int));
+ int* b_len = (int*)taosMemoryMalloc(ROW_NUMS * sizeof(int));
+ for (int i = 0; i < ROW_NUMS; i++) {
+ ts_len[i] = sizeof(int64_t);
+ b_len[i] = 1;
+ }
+ for (int i = 0; i < CTB_NUMS; i++) {
+ ts[i] = (int64_t*)taosMemoryMalloc(ROW_NUMS * sizeof(int64_t));
+ b[i] = (char*)taosMemoryMalloc(ROW_NUMS * sizeof(char));
+ for (int j = 0; j < ROW_NUMS; j++) {
+ ts[i][j] = 1591060628000 + r * 100000 + j;
+ b[i][j] = 'a' + j;
+ }
+ }
+ // tag params
+ int t1 = 0;
+ int t1len = sizeof(int);
+ int t2len = 3;
+ // TAOS_STMT2_BIND* tagv[2] = {&tags[0][0], &tags[1][0]};
+
+ // bind params
+ TAOS_STMT2_BIND** paramv = (TAOS_STMT2_BIND**)taosMemoryMalloc(CTB_NUMS * sizeof(TAOS_STMT2_BIND*));
+ TAOS_STMT2_BIND** tags = (TAOS_STMT2_BIND**)taosMemoryMalloc(CTB_NUMS * sizeof(TAOS_STMT2_BIND*));
+ for (int i = 0; i < CTB_NUMS; i++) {
+ // create tags
+ tags[i] = (TAOS_STMT2_BIND*)taosMemoryMalloc(2 * sizeof(TAOS_STMT2_BIND));
+ tags[i][0] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_INT, &t1, &t1len, NULL, 0};
+ tags[i][1] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_BINARY, (void*)"after", &t2len, NULL, 0};
+
+ // create col params
+ paramv[i] = (TAOS_STMT2_BIND*)taosMemoryMalloc(2 * sizeof(TAOS_STMT2_BIND));
+ paramv[i][0] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_TIMESTAMP, &ts[i][0], &ts_len[0], NULL, ROW_NUMS};
+ paramv[i][1] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_BINARY, &b[i][0], &b_len[0], NULL, ROW_NUMS};
+ }
+ // bind
+ TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, tags, paramv};
+ code = taos_stmt2_bind_param(stmt, &bindv, -1);
+ ASSERT_EQ(code, 0);
+ ASSERT_EQ(errno, 0);
+
+ // exec
+ code = taos_stmt2_exec(stmt, NULL);
+ ASSERT_EQ(code, 0);
+ ASSERT_EQ(errno, 0);
+
+ for (int i = 0; i < CTB_NUMS; i++) {
+ taosMemoryFree(tags[i]);
+ taosMemoryFree(paramv[i]);
+ taosMemoryFree(ts[i]);
+ taosMemoryFree(b[i]);
+ }
+ taosMemoryFree(ts);
+ taosMemoryFree(b);
+ taosMemoryFree(ts_len);
+ taosMemoryFree(b_len);
+ taosMemoryFree(paramv);
+ taosMemoryFree(tags);
+ }
+ for (int i = 0; i < CTB_NUMS; i++) {
+ taosMemoryFree(tbs[i]);
+ }
+ taosMemoryFree(tbs);
+
+ taos_stmt2_close(stmt);
+}
} // namespace
@@ -665,6 +750,7 @@ TEST(stmt2Case, get_fields_error_Test) {
TEST(stmt2Case, stmt2_init_prepare_Test) {
TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
+ ASSERT_NE(taos, nullptr);
{
(void)taos_stmt2_init(NULL, NULL);
ASSERT_EQ(terrno, TSDB_CODE_INVALID_PARA);
@@ -711,6 +797,15 @@ TEST(stmt2Case, stmt2_init_prepare_Test) {
}
}
+TEST(stmt2Case, stmt2_all) {
+ TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0);
+ ASSERT_NE(taos, nullptr);
+
+ { do_stmt(taos, "insert into db.stb (tbname,ts,b,t1,t2) values(?,?,?,?,?)", 3, 3, 3, true); }
+ taos_close(taos);
+ taos_cleanup();
+}
+
TEST(stmt2Case, stmt2_status_Test) {}
#pragma GCC diagnostic pop
From 001a2b653b6e1bb61c0605e04f324434f39c3a61 Mon Sep 17 00:00:00 2001
From: Minglei Jin
Date: Thu, 26 Dec 2024 18:27:43 +0800
Subject: [PATCH 10/56] fix(tdb/cd): free cell decoder's mem w.r.t. btree prev
---
source/libs/tdb/src/db/tdbBtree.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c
index 19a3f211b1..c806bdfbd8 100644
--- a/source/libs/tdb/src/db/tdbBtree.c
+++ b/source/libs/tdb/src/db/tdbBtree.c
@@ -2023,16 +2023,29 @@ int tdbBtreePrev(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
memcpy(pKey, cd.pKey, (size_t)cd.kLen);
if (ppVal) {
- // TODO: vLen may be zero
- pVal = tdbRealloc(*ppVal, cd.vLen);
- if (pVal == NULL) {
- tdbFree(pKey);
- return terrno;
+ if (cd.vLen > 0) {
+ pVal = tdbRealloc(*ppVal, cd.vLen);
+ if (pVal == NULL) {
+ tdbFree(pKey);
+ return terrno;
+ }
+
+ memcpy(pVal, cd.pVal, (size_t)cd.vLen);
+ if (TDB_CELLDECODER_FREE_VAL(&cd)) {
+ tdbTrace("tdb/btree-next decoder: %p pVal free: %p", &cd, cd.pVal);
+ tdbFree(cd.pVal);
+ }
+ } else {
+ pVal = NULL;
}
*ppVal = pVal;
*vLen = cd.vLen;
- memcpy(pVal, cd.pVal, (size_t)cd.vLen);
+ } else {
+ if (TDB_CELLDECODER_FREE_VAL(&cd)) {
+ tdbTrace("tdb/btree-next2 decoder: %p pVal free: %p", &cd, cd.pVal);
+ tdbFree(cd.pVal);
+ }
}
ret = tdbBtcMoveToPrev(pBtc);
From 91abb86693fc9a9857fff73f447b93eab5b2d77e Mon Sep 17 00:00:00 2001
From: dmchen
Date: Fri, 27 Dec 2024 02:22:54 +0000
Subject: [PATCH 11/56] fix/resolve_fqdn_retry_times
---
source/libs/sync/src/syncUtil.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c
index d9eff2e9b8..38fd660cfd 100644
--- a/source/libs/sync/src/syncUtil.c
+++ b/source/libs/sync/src/syncUtil.c
@@ -24,6 +24,8 @@
#include "tglobal.h"
#include "ttime.h"
+#define FQDNRETRYTIMES 100
+
static void syncCfg2SimpleStr(const SSyncCfg* pCfg, char* buf, int32_t bufLen) {
int32_t len = tsnprintf(buf, bufLen, "{num:%d, as:%d, [", pCfg->replicaNum, pCfg->myIndex);
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
@@ -46,9 +48,14 @@ bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId*
uint32_t ipv4 = 0xFFFFFFFF;
sDebug("vgId:%d, resolve sync addr from fqdn, ep:%s:%u", vgId, pInfo->nodeFqdn, pInfo->nodePort);
- int32_t code = taosGetIpv4FromFqdn(pInfo->nodeFqdn, &ipv4);
- if (code) {
- sError("vgId:%d, failed to resolve sync addr, dnode:%d fqdn:%s, retry", vgId, pInfo->nodeId, pInfo->nodeFqdn);
+ for (int32_t i = 0; i < FQDNRETRYTIMES; i++) {
+ int32_t code = taosGetIpv4FromFqdn(pInfo->nodeFqdn, &ipv4);
+ if (code) {
+ sError("vgId:%d, failed to resolve sync addr, dnode:%d fqdn:%s, retry", vgId, pInfo->nodeId, pInfo->nodeFqdn);
+ taosSsleep(1);
+ } else {
+ break;
+ }
}
if (ipv4 == 0xFFFFFFFF || ipv4 == 1) {
From de62d9bb836745035e7d477ddcae0283888fef24 Mon Sep 17 00:00:00 2001
From: "pengrongkun94@qq.com"
Date: Fri, 27 Dec 2024 10:44:02 +0800
Subject: [PATCH 12/56] fix some case
---
source/client/test/stmt2Test.cpp | 34 +++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)
diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp
index 4542f953ab..ada3b66dc9 100644
--- a/source/client/test/stmt2Test.cpp
+++ b/source/client/test/stmt2Test.cpp
@@ -33,6 +33,19 @@
#include "taos.h"
namespace {
+
+void checkRows(TAOS* pConn, const char* sql, int32_t expectedRows) {
+ TAOS_RES* pRes = taos_query(pConn, sql);
+ ASSERT_EQ(taos_errno(pRes), TSDB_CODE_SUCCESS);
+ TAOS_ROW pRow = NULL;
+ int rows = 0;
+ while ((pRow = taos_fetch_row(pRes)) != NULL) {
+ rows++;
+ }
+ ASSERT_EQ(rows, expectedRows);
+ taos_free_result(pRes);
+}
+
void stmtAsyncQueryCb(void* param, TAOS_RES* pRes, int code) {
int affected_rows = taos_affected_rows(pRes);
return;
@@ -186,6 +199,8 @@ void do_stmt(TAOS* taos, const char* sql, int CTB_NUMS, int ROW_NUMS, int CYC_NU
taosMemoryFree(paramv);
taosMemoryFree(tags);
}
+
+ checkRows(taos, "select * from db.stb", CYC_NUMS * ROW_NUMS * CTB_NUMS);
for (int i = 0; i < CTB_NUMS; i++) {
taosMemoryFree(tbs[i]);
}
@@ -352,11 +367,11 @@ TEST(stmt2Case, insert_stb_get_fields_Test) {
printf("not support case \n");
// case 5 : add in main TD-33353
- // {
- // const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(1,?,?,'abc',?)";
- // printf("case 2 : %s\n", sql);
- // getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
- // }
+ {
+ const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(1,?,?,'abc',?)";
+ printf("case 2 : %s\n", sql);
+ getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
+ }
// case 2 : no pk
{
@@ -411,11 +426,10 @@ TEST(stmt2Case, insert_stb_get_fields_Test) {
{
const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(*,*,*,*,*)";
printf("case 9 : %s\n", sql);
- getFieldsError(taos, sql, TSDB_CODE_TSC_SQL_SYNTAX_ERROR);
+ getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
}
taos_close(taos);
- taos_cleanup();
}
TEST(stmt2Case, insert_ctb_using_get_fields_Test) {
@@ -616,6 +630,7 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) {
printf("case 5 : %s\n", sql);
getFieldsError(taos, sql, TSDB_CODE_TSC_SQL_SYNTAX_ERROR);
}
+ taos_close(taos);
}
TEST(stmt2Case, insert_ntb_get_fields_Test) {
@@ -737,6 +752,7 @@ TEST(stmt2Case, select_get_fields_Test) {
printf("case 3 : %s\n", sql);
getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
}
+ taos_close(taos);
}
TEST(stmt2Case, get_fields_error_Test) {
@@ -776,7 +792,7 @@ TEST(stmt2Case, stmt2_init_prepare_Test) {
code = taos_stmt2_prepare(stmt, "insert into 'db'.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)", 0);
ASSERT_EQ(terrno, 0);
ASSERT_NE(stmt, nullptr);
- // ASSERT_STREQ(((STscStmt2*)stmt)->db, "db"); //add in main TD-33332
+ ASSERT_STREQ(((STscStmt2*)stmt)->db, "db"); // add in main TD-33332
taos_stmt2_close(stmt);
}
@@ -795,6 +811,7 @@ TEST(stmt2Case, stmt2_init_prepare_Test) {
ASSERT_NE(stmt, nullptr);
taos_stmt2_close(stmt);
}
+ taos_close(taos);
}
TEST(stmt2Case, stmt2_all) {
@@ -803,7 +820,6 @@ TEST(stmt2Case, stmt2_all) {
{ do_stmt(taos, "insert into db.stb (tbname,ts,b,t1,t2) values(?,?,?,?,?)", 3, 3, 3, true); }
taos_close(taos);
- taos_cleanup();
}
TEST(stmt2Case, stmt2_status_Test) {}
From 8bf82a9ce85e791a22858838c2b9e3fb8264f00e Mon Sep 17 00:00:00 2001
From: WANG MINGMING
Date: Fri, 27 Dec 2024 11:13:52 +0800
Subject: [PATCH 13/56] Update 01-taosd.md
---
docs/zh/14-reference/01-components/01-taosd.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/zh/14-reference/01-components/01-taosd.md b/docs/zh/14-reference/01-components/01-taosd.md
index 7a0a306a41..0a4160a00b 100644
--- a/docs/zh/14-reference/01-components/01-taosd.md
+++ b/docs/zh/14-reference/01-components/01-taosd.md
@@ -250,7 +250,7 @@ charset 的有效值是 UTF-8。
|minimalLogDirGB | |不支持动态修改 |日志文件夹所在磁盘可用空间大小小于该值时,停止写日志,单位 GB,默认值 1|
|numOfLogLines | |支持动态修改 立即生效 |单个日志文件允许的最大行数,默认值 10,000,000|
|asyncLog | |支持动态修改 立即生效 |日志写入模式,0:同步,1:异步,默认值 1|
-|logKeepDays | |支持动态修改 立即生效 |日志文件的最长保存时间,单位:天,默认值 0,意味着无限保存,日志文件不会被重命名,也不会有新的日志文件滚动产生,但日志文件的内容有可能会不断滚动,取决于日志文件大小的设置;当设置为大于 0 的值时,当日志文件大小达到设置的上限时会被重命名为 taosdlog.yyy,其中 yyy 为日志文件最后修改的时间戳,并滚动产生新的日志文件|
+|logKeepDays | |支持动态修改 立即生效 |日志文件的最长保存时间,单位:天,默认值 0,小于等于0意味着只有两个日志文件相互切换保存日志,超过两个文件保存数量的日志会被删除;当设置为大于 0 的值时,当日志文件大小达到设置的上限时会被重命名为 taosdlog.yyy,其中 yyy 为日志文件最后修改的时间戳,并滚动产生新的日志文件|
|slowLogThreshold|3.3.3.0 后|支持动态修改 立即生效 |慢查询门限值,大于等于门限值认为是慢查询,单位秒,默认值 3 |
|slowLogMaxLen |3.3.3.0 后|支持动态修改 立即生效 |慢查询日志最大长度,取值范围 1-16384,默认值 4096|
|slowLogScope |3.3.3.0 后|支持动态修改 立即生效 |慢查询记录类型,取值范围 ALL/QUERY/INSERT/OTHERS/NONE,默认值 QUERY|
From fc6af95ba212d67d87f12596dcc545ce8717ebbb Mon Sep 17 00:00:00 2001
From: Jinqing Kuang
Date: Fri, 27 Dec 2024 11:51:50 +0800
Subject: [PATCH 14/56] fix(query)[TS-5058]. Add note about scenarios where
interval auto offset may not work
---
docs/en/14-reference/03-taos-sql/12-distinguished.md | 1 +
docs/zh/14-reference/03-taos-sql/12-distinguished.md | 1 +
2 files changed, 2 insertions(+)
diff --git a/docs/en/14-reference/03-taos-sql/12-distinguished.md b/docs/en/14-reference/03-taos-sql/12-distinguished.md
index 4c09f140a1..e98b654be3 100644
--- a/docs/en/14-reference/03-taos-sql/12-distinguished.md
+++ b/docs/en/14-reference/03-taos-sql/12-distinguished.md
@@ -148,6 +148,7 @@ When using time windows, note:
- The window width of the aggregation period is specified by the keyword INTERVAL, with the shortest interval being 10 milliseconds (10a); it also supports an offset (the offset must be less than the interval), which is the offset of the time window division compared to "UTC moment 0". The SLIDING statement is used to specify the forward increment of the aggregation period, i.e., the duration of each window slide forward.
- When using the INTERVAL statement, unless in very special cases, it is required to configure the timezone parameter in the taos.cfg configuration files of both the client and server to the same value to avoid frequent cross-time zone conversions by time processing functions, which can cause severe performance impacts.
- The returned results have a strictly monotonically increasing time-series.
+- When using AUTO as the window offset, if the WHERE time condition is complex, such as multiple AND/OR/IN combinations, AUTO may not take effect. In such cases, you can manually specify the window offset to resolve the issue.
- When using AUTO as the window offset, if the window width unit is d (day), n (month), w (week), y (year), such as: INTERVAL(1d, AUTO), INTERVAL(3w, AUTO), the TSMA optimization cannot take effect. If TSMA is manually created on the target table, the statement will report an error and exit; in this case, you can explicitly specify the Hint SKIP_TSMA or not use AUTO as the window offset.
### State Window
diff --git a/docs/zh/14-reference/03-taos-sql/12-distinguished.md b/docs/zh/14-reference/03-taos-sql/12-distinguished.md
index ef8faff85a..bd6705b33b 100644
--- a/docs/zh/14-reference/03-taos-sql/12-distinguished.md
+++ b/docs/zh/14-reference/03-taos-sql/12-distinguished.md
@@ -138,6 +138,7 @@ SELECT COUNT(*) FROM meters WHERE _rowts - voltage > 1000000;
- 聚合时间段的窗口宽度由关键词 INTERVAL 指定,最短时间间隔 10 毫秒(10a);并且支持偏移 offset(偏移必须小于间隔),也即时间窗口划分与“UTC 时刻 0”相比的偏移量。SLIDING 语句用于指定聚合时间段的前向增量,也即每次窗口向前滑动的时长。
- 使用 INTERVAL 语句时,除非极特殊的情况,都要求把客户端和服务端的 taos.cfg 配置文件中的 timezone 参数配置为相同的取值,以避免时间处理函数频繁进行跨时区转换而导致的严重性能影响。
- 返回的结果中时间序列严格单调递增。
+- 使用 AUTO 作为窗口偏移量时,如果 WHERE 时间条件比较复杂,比如多个 AND/OR/IN 互相组合,那么 AUTO 可能不生效,这种情况可以通过手动指定窗口偏移量进行解决。
- 使用 AUTO 作为窗口偏移量时,如果窗口宽度的单位是 d (天), n (月), w (周), y (年),比如: INTERVAL(1d, AUTO), INTERVAL(3w, AUTO),此时 TSMA 优化无法生效。如果目标表上手动创建了TSMA,语句会报错退出;这种情况下,可以显式指定 Hint SKIP_TSMA 或者不使用 AUTO 作为窗口偏移量。
### 状态窗口
From 3f642fd0135801ea1e9c8dc344836d8e831e5563 Mon Sep 17 00:00:00 2001
From: kailixu
Date: Fri, 27 Dec 2024 12:01:07 +0800
Subject: [PATCH 15/56] fix: unlock and error code of tlog
---
source/util/src/tlog.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c
index 88eccfaffd..4df5b322a2 100644
--- a/source/util/src/tlog.c
+++ b/source/util/src/tlog.c
@@ -673,11 +673,11 @@ static int32_t taosInitNormalLog(const char *logName, int32_t maxFileNum) {
}
_exit:
- taosUnLockLogFile(tsLogObj.logHandle->pFile);
if (code != 0) {
+ taosUnLockLogFile(tsLogObj.logHandle->pFile);
TAOS_UNUSED(printf("failed to init normal log file:%s at line %d, reason:%s\n", name, lino, tstrerror(code)));
}
- return 0;
+ return code;
}
static void taosUpdateLogNums(ELogLevel level) {
From 2d7c1a206f6f44913b8deebda1f6e509a839130b Mon Sep 17 00:00:00 2001
From: Hongze Cheng
Date: Fri, 27 Dec 2024 15:10:21 +0800
Subject: [PATCH 16/56] enh: add more cases
---
source/libs/executor/src/sysscanoperator.c | 2 +
tests/parallel_test/cases.task | 1 +
tests/system-test/0-others/ins_filesets.py | 54 ++++++++++++++++++++++
3 files changed, 57 insertions(+)
create mode 100644 tests/system-test/0-others/ins_filesets.py
diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c
index 7862b36f27..56060b0061 100644
--- a/source/libs/executor/src/sysscanoperator.c
+++ b/source/libs/executor/src/sysscanoperator.c
@@ -2269,6 +2269,8 @@ static SSDataBlock* sysTableBuildUserFileSets(SOperatorInfo* pOperator) {
if (ret) {
if (ret == TSDB_CODE_NOT_FOUND) {
// no more scan entry
+ setOperatorCompleted(pOperator);
+ pAPI->tsdReader.fileSetReaderClose(&pInfo->pFileSetReader);
break;
} else {
code = ret;
diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task
index 38dd080ef5..8903ef27a4 100644
--- a/tests/parallel_test/cases.task
+++ b/tests/parallel_test/cases.task
@@ -484,6 +484,7 @@
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/show.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/show_tag_index.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/information_schema.py
+,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/ins_filesets.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/grant.py
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/abs.py
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/abs.py -R
diff --git a/tests/system-test/0-others/ins_filesets.py b/tests/system-test/0-others/ins_filesets.py
new file mode 100644
index 0000000000..e5bc4b61b7
--- /dev/null
+++ b/tests/system-test/0-others/ins_filesets.py
@@ -0,0 +1,54 @@
+###################################################################
+# Copyright (c) 2016 by TAOS Technologies, Inc.
+# All rights reserved.
+#
+# This file is proprietary and confidential to TAOS Technologies.
+# No part of this file may be reproduced, stored, transmitted,
+# disclosed or used in any form or by any means other than as
+# expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+
+import re
+from util.log import *
+from util.cases import *
+from util.sql import *
+from util.common import *
+from util.sqlset import *
+
+class TDTestCase:
+ def init(self, conn, logSql, replicaVar=1):
+ self.replicaVar = int(replicaVar)
+ tdLog.debug("start to execute %s" % __file__)
+ tdSql.init(conn.cursor())
+
+ def run(self):
+ tdSql.execute('create database db vgroups 1')
+ tdSql.execute('use db')
+ tdSql.execute('create table t1 (ts timestamp, a int, b int)')
+ tdSql.execute('insert into t1 values(\'2024-12-27 14:00:00\', 1, 2)')
+ tdSql.execute('flush database db')
+
+ tdLog.sleep(5)
+
+ rows = tdSql.query('select * from information_schema.ins_filesets')
+ tdSql.checkRows(1)
+ tdSql.checkEqual(tdSql.getData(0, 0), 'db')
+ tdSql.checkEqual(tdSql.getData(0, 1), 2)
+ tdSql.checkEqual(tdSql.getData(0, 2), 2008)
+ # tdSql.CheckEqual(str(tdSql.getData(0, 3)), '2024-12-23 08:00:00.000')
+ # tdSql.CheckEqual(str(tdSql.getData(0, 4)), '2025-01-02 07:59:59.999')
+ # tdSql.CheckEqual(tdSql.getData(0, 6), '1970-01-01 08:00:00.000')
+ # tdSql.CheckEqual(tdSql.getData(0, 7), False)
+
+ tdDnodes.stopAll()
+
+
+ def stop(self):
+ tdSql.close()
+ tdLog.success("%s successfully executed" % __file__)
+
+tdCases.addWindows(__file__, TDTestCase())
+tdCases.addLinux(__file__, TDTestCase())
From 78018b3a167acfa79cde0db80b1de16b6574d8a6 Mon Sep 17 00:00:00 2001
From: kailixu
Date: Fri, 27 Dec 2024 17:05:09 +0800
Subject: [PATCH 17/56] test: add test case for auto compact
---
source/common/src/systable.c | 3 ++
source/dnode/mnode/impl/src/mndDb.c | 30 ++++++++++++++++---
.../0-others/information_schema.py | 2 +-
tests/system-test/1-insert/alter_database.py | 13 +++++---
4 files changed, 39 insertions(+), 9 deletions(-)
diff --git a/source/common/src/systable.c b/source/common/src/systable.c
index 38dce105bb..1f018606a8 100644
--- a/source/common/src/systable.c
+++ b/source/common/src/systable.c
@@ -123,6 +123,9 @@ static const SSysDbTableSchema userDBSchema[] = {
{.name = "s3_compact", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true},
{.name = "with_arbitrator", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true},
{.name = "encrypt_algorithm", .bytes = TSDB_ENCRYPT_ALGO_STR_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
+ {.name = "compact_interval", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
+ {.name = "compact_time_range", .bytes = 24 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
+ {.name = "compact_time_offset", .bytes = 4 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
};
static const SSysDbTableSchema userFuncSchema[] = {
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index 1efbff9d53..02e13e9951 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -2435,6 +2435,7 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)strictVstr, false), &lino, _OVER);
+ char durationStr[128] = {0};
char durationVstr[128] = {0};
int32_t len = formatDurationOrKeep(&durationVstr[VARSTR_HEADER_SIZE], sizeof(durationVstr) - VARSTR_HEADER_SIZE,
pDb->cfg.daysPerFile);
@@ -2443,10 +2444,10 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER);
- char keepVstr[512] = {0};
- char keep0Str[128] = {0};
- char keep1Str[128] = {0};
- char keep2Str[128] = {0};
+ char keepVstr[128] = {0};
+ char keep0Str[32] = {0};
+ char keep1Str[32] = {0};
+ char keep2Str[32] = {0};
int32_t lenKeep0 = formatDurationOrKeep(keep0Str, sizeof(keep0Str), pDb->cfg.daysToKeep0);
int32_t lenKeep1 = formatDurationOrKeep(keep1Str, sizeof(keep1Str), pDb->cfg.daysToKeep1);
@@ -2559,6 +2560,27 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
STR_WITH_MAXSIZE_TO_VARSTR(encryptAlgorithmVStr, encryptAlgorithmStr, 24);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)encryptAlgorithmVStr, false), &lino, _OVER);
+
+ formatDurationOrKeep(durationStr, sizeof(durationStr), pDb->cfg.compactInterval);
+ STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr));
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ if (pColInfo) {
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER);
+ }
+
+ len = formatDurationOrKeep(durationStr, sizeof(durationStr), pDb->cfg.compactStartTime);
+ formatDurationOrKeep(durationVstr, sizeof(durationVstr), pDb->cfg.compactEndTime);
+ snprintf(durationStr + len, sizeof(durationStr) - len, ",%s", durationVstr);
+ STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr));
+ if ((pColInfo = taosArrayGet(pBlock->pDataBlock, cols++))) {
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER);
+ }
+
+ snprintf(durationStr, sizeof(durationStr), "%dh", pDb->cfg.compactTimeOffset);
+ STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr));
+ if ((pColInfo = taosArrayGet(pBlock->pDataBlock, cols++))) {
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER);
+ }
}
_OVER:
if (code != 0) mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py
index 8c25b70b76..390bf3d9dd 100644
--- a/tests/system-test/0-others/information_schema.py
+++ b/tests/system-test/0-others/information_schema.py
@@ -222,7 +222,7 @@ class TDTestCase:
tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'")
tdLog.info(len(tdSql.queryResult))
- tdSql.checkEqual(True, len(tdSql.queryResult) in range(309, 310))
+ tdSql.checkEqual(True, len(tdSql.queryResult) in range(312, 313))
tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'")
tdSql.checkEqual(61, len(tdSql.queryResult))
diff --git a/tests/system-test/1-insert/alter_database.py b/tests/system-test/1-insert/alter_database.py
index f58bb7517e..47ad142bc4 100644
--- a/tests/system-test/1-insert/alter_database.py
+++ b/tests/system-test/1-insert/alter_database.py
@@ -75,6 +75,10 @@ class TDTestCase:
tdSql.checkEqual("Invalid option encrypt_algorithm: none ", tdSql.error('alter database db encrypt_algorithm \'none \''))
tdSql.execute('drop database db')
+ def alter_compact(self):
+ tdSql.error('create database db compact_time_range 60,61', expectErrInfo="Invalid option compact_time_range: 86400m, start_time should be in range: [-5256000m, -14400m]", fullMatched=True)
+ tdSql.execute('drop database db')
+
def alter_same_options(self):
tdSql.execute('drop database if exists db')
tdSql.execute('create database db')
@@ -101,10 +105,11 @@ class TDTestCase:
def run(self):
- self.alter_buffer()
- self.alter_pages()
- self.alter_encrypt_alrogithm()
- self.alter_same_options()
+ # self.alter_buffer()
+ # self.alter_pages()
+ # self.alter_encrypt_alrogithm()
+ # self.alter_same_options()
+ self.alter_compact()
def stop(self):
tdSql.close()
From a72c46a7fc28cb38d078c715956b742d68e3a255 Mon Sep 17 00:00:00 2001
From: Hongze Cheng
Date: Fri, 27 Dec 2024 17:44:05 +0800
Subject: [PATCH 18/56] more cases
---
source/dnode/vnode/src/tsdb/tsdbFS2.c | 25 +++++++++++++++----
source/dnode/vnode/src/tsdb/tsdbFSet2.c | 32 +++++++++++++++++++++++++
source/dnode/vnode/src/tsdb/tsdbFSet2.h | 2 ++
3 files changed, 55 insertions(+), 4 deletions(-)
diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c
index 82dd49b0e2..aa68a8af5c 100644
--- a/source/dnode/vnode/src/tsdb/tsdbFS2.c
+++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c
@@ -680,7 +680,7 @@ static int32_t fset_cmpr_fn(const struct STFileSet *pSet1, const struct STFileSe
return 0;
}
-static int32_t edit_fs(STFileSystem *fs, const TFileOpArray *opArray) {
+static int32_t edit_fs(STFileSystem *fs, const TFileOpArray *opArray, EFEditT etype) {
int32_t code = 0;
int32_t lino = 0;
@@ -690,6 +690,8 @@ static int32_t edit_fs(STFileSystem *fs, const TFileOpArray *opArray) {
TFileSetArray *fsetArray = fs->fSetArrTmp;
STFileSet *fset = NULL;
const STFileOp *op;
+ int32_t fid = INT32_MIN;
+ TSKEY now = taosGetTimestampMs();
TARRAY2_FOREACH_PTR(opArray, op) {
if (!fset || fset->fid != op->fid) {
STFileSet tfset = {.fid = op->fid};
@@ -708,6 +710,15 @@ static int32_t edit_fs(STFileSystem *fs, const TFileOpArray *opArray) {
code = tsdbTFileSetEdit(fs->tsdb, fset, op);
TSDB_CHECK_CODE(code, lino, _exit);
+
+ if (fid != op->fid) {
+ fid = op->fid;
+ if (etype == TSDB_FEDIT_COMMIT) {
+ fset->lastCommit = now;
+ } else if (etype == TSDB_FEDIT_COMPACT) {
+ fset->lastCompact = now;
+ }
+ }
}
// remove empty empty stt level and empty file set
@@ -864,7 +875,7 @@ int32_t tsdbFSEditBegin(STFileSystem *fs, const TFileOpArray *opArray, EFEditT e
fs->etype = etype;
// edit
- code = edit_fs(fs, opArray);
+ code = edit_fs(fs, opArray, etype);
TSDB_CHECK_CODE(code, lino, _exit);
// save fs
@@ -1288,6 +1299,12 @@ int32_t tsdbFileSetReaderOpen(void *pVnode, struct SFileSetReader **ppReader) {
return TSDB_CODE_SUCCESS;
}
+extern bool tsdbShouldCompact(const STFileSet *pFileSet);
+
+#ifndef TD_ENTERPRISE
+bool tsdbShouldCompact(const STFileSet *pFileSet) { return false; }
+#endif
+
static int32_t tsdbFileSetReaderNextNoLock(struct SFileSetReader *pReader) {
STsdb *pTsdb = pReader->pTsdb;
int32_t code = TSDB_CODE_SUCCESS;
@@ -1311,7 +1328,7 @@ static int32_t tsdbFileSetReaderNextNoLock(struct SFileSetReader *pReader) {
// get file set details
pReader->fid = pReader->pFileSet->fid;
tsdbFidKeyRange(pReader->fid, pTsdb->keepCfg.days, pTsdb->keepCfg.precision, &pReader->startTime, &pReader->endTime);
- pReader->lastCompactTime = 0; // TODO
+ pReader->lastCompactTime = pReader->pFileSet->lastCompact;
pReader->totalSize = 0;
for (int32_t i = 0; i < TSDB_FTYPE_MAX; i++) {
STFileObj *fobj = pReader->pFileSet->farr[i];
@@ -1375,7 +1392,7 @@ int32_t tsdbFileSetGetEntryField(struct SFileSetReader *pReader, const char *fie
fieldName = "should_compact";
if (strncmp(field, fieldName, strlen(fieldName) + 1) == 0) {
- *(char *)value = 0; // TODO
+ *(char *)value = tsdbShouldCompact(pReader->pFileSet);
return TSDB_CODE_SUCCESS;
}
diff --git a/source/dnode/vnode/src/tsdb/tsdbFSet2.c b/source/dnode/vnode/src/tsdb/tsdbFSet2.c
index 68914300e4..6530ee2269 100644
--- a/source/dnode/vnode/src/tsdb/tsdbFSet2.c
+++ b/source/dnode/vnode/src/tsdb/tsdbFSet2.c
@@ -273,6 +273,15 @@ int32_t tsdbTFileSetToJson(const STFileSet *fset, cJSON *json) {
if (code) return code;
}
+ // about compact and commit
+ if (cJSON_AddNumberToObject(json, "last compact", fset->lastCompact) == NULL) {
+ return TSDB_CODE_OUT_OF_MEMORY;
+ }
+
+ if (cJSON_AddNumberToObject(json, "last commit", fset->lastCommit) == NULL) {
+ return TSDB_CODE_OUT_OF_MEMORY;
+ }
+
return 0;
}
@@ -324,6 +333,20 @@ int32_t tsdbJsonToTFileSet(STsdb *pTsdb, const cJSON *json, STFileSet **fset) {
} else {
return TSDB_CODE_FILE_CORRUPTED;
}
+ // about compact and commit
+ item1 = cJSON_GetObjectItem(json, "last compact");
+ if (cJSON_IsNumber(item1)) {
+ (*fset)->lastCompact = item1->valuedouble;
+ } else {
+ (*fset)->lastCompact = 0;
+ }
+
+ item1 = cJSON_GetObjectItem(json, "last commit");
+ if (cJSON_IsNumber(item1)) {
+ (*fset)->lastCommit = item1->valuedouble;
+ } else {
+ (*fset)->lastCommit = 0;
+ }
return 0;
}
@@ -467,6 +490,9 @@ int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *f
}
}
+ fset2->lastCompact = fset1->lastCompact;
+ fset2->lastCommit = fset1->lastCommit;
+
return 0;
}
@@ -522,6 +548,9 @@ int32_t tsdbTFileSetInitCopy(STsdb *pTsdb, const STFileSet *fset1, STFileSet **f
if (code) return code;
}
+ (*fset)->lastCompact = fset1->lastCompact;
+ (*fset)->lastCommit = fset1->lastCommit;
+
return 0;
}
@@ -617,6 +646,9 @@ int32_t tsdbTFileSetInitRef(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fs
}
}
+ (*fset)->lastCompact = fset1->lastCompact;
+ (*fset)->lastCommit = fset1->lastCommit;
+
return 0;
}
diff --git a/source/dnode/vnode/src/tsdb/tsdbFSet2.h b/source/dnode/vnode/src/tsdb/tsdbFSet2.h
index 83ef32e5e5..ca9c133e9c 100644
--- a/source/dnode/vnode/src/tsdb/tsdbFSet2.h
+++ b/source/dnode/vnode/src/tsdb/tsdbFSet2.h
@@ -92,6 +92,8 @@ struct STFileSet {
int64_t maxVerValid;
STFileObj *farr[TSDB_FTYPE_MAX]; // file array
TSttLvlArray lvlArr[1]; // level array
+ TSKEY lastCompact;
+ TSKEY lastCommit;
bool mergeScheduled;
SVATaskID mergeTask;
From 42410d6c85034aa18a61ac309ee4afa30cf553e7 Mon Sep 17 00:00:00 2001
From: "pengrongkun94@qq.com"
Date: Fri, 27 Dec 2024 15:25:42 +0800
Subject: [PATCH 19/56] only linux run stmt2Test
---
source/client/test/CMakeLists.txt | 11 +++++------
source/client/test/stmt2Test.cpp | 8 ++++----
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/source/client/test/CMakeLists.txt b/source/client/test/CMakeLists.txt
index 62b7bb3e91..ce1cc064db 100644
--- a/source/client/test/CMakeLists.txt
+++ b/source/client/test/CMakeLists.txt
@@ -68,6 +68,10 @@ IF(${TD_LINUX})
NAME connectOptionsTest
COMMAND connectOptionsTest
)
+ add_test(
+ NAME stmt2Test
+ COMMAND stmt2Test
+ )
ENDIF ()
TARGET_INCLUDE_DIRECTORIES(
@@ -107,9 +111,4 @@ add_test(
add_test(
NAME userOperTest
COMMAND userOperTest
-)
-
-add_test(
- NAME stmt2Test
- COMMAND stmt2Test
-)
+)
\ No newline at end of file
diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp
index ada3b66dc9..4fea2452d0 100644
--- a/source/client/test/stmt2Test.cpp
+++ b/source/client/test/stmt2Test.cpp
@@ -167,13 +167,13 @@ void do_stmt(TAOS* taos, const char* sql, int CTB_NUMS, int ROW_NUMS, int CYC_NU
for (int i = 0; i < CTB_NUMS; i++) {
// create tags
tags[i] = (TAOS_STMT2_BIND*)taosMemoryMalloc(2 * sizeof(TAOS_STMT2_BIND));
- tags[i][0] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_INT, &t1, &t1len, NULL, 0};
- tags[i][1] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_BINARY, (void*)"after", &t2len, NULL, 0};
+ tags[i][0] = {TSDB_DATA_TYPE_INT, &t1, &t1len, NULL, 0};
+ tags[i][1] = {TSDB_DATA_TYPE_BINARY, (void*)"after", &t2len, NULL, 0};
// create col params
paramv[i] = (TAOS_STMT2_BIND*)taosMemoryMalloc(2 * sizeof(TAOS_STMT2_BIND));
- paramv[i][0] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_TIMESTAMP, &ts[i][0], &ts_len[0], NULL, ROW_NUMS};
- paramv[i][1] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_BINARY, &b[i][0], &b_len[0], NULL, ROW_NUMS};
+ paramv[i][0] = {TSDB_DATA_TYPE_TIMESTAMP, &ts[i][0], &ts_len[0], NULL, ROW_NUMS};
+ paramv[i][1] = {TSDB_DATA_TYPE_BINARY, &b[i][0], &b_len[0], NULL, ROW_NUMS};
}
// bind
TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, tags, paramv};
From 289f8181a10b56ff7aecb9f26a92e221fb5f5767 Mon Sep 17 00:00:00 2001
From: kailixu
Date: Fri, 27 Dec 2024 18:32:34 +0800
Subject: [PATCH 20/56] test: add test case for auto compact
---
source/libs/parser/src/parTranslater.c | 80 +++++++++++---------
tests/system-test/1-insert/alter_database.py | 14 +++-
2 files changed, 55 insertions(+), 39 deletions(-)
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index 8f3cbd6f8b..6ed0cc60b2 100755
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -7809,23 +7809,23 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS
}
static int32_t checkRangeOption(STranslateContext* pCxt, int32_t code, const char* pName, int64_t val, int64_t minVal,
- int64_t maxVal, bool skipUndef) {
+ int64_t maxVal, int8_t unit, bool skipUndef) {
if (skipUndef ? ((val >= 0) && (val < minVal || val > maxVal)) : (val < minVal || val > maxVal)) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, code,
- "Invalid option %s: %" PRId64 ", valid range: [%" PRId64 ", %" PRId64 "]", pName,
- val, minVal, maxVal);
+ "Invalid option %s: %" PRId64 "%c, valid range: [%" PRId64 "%c, %" PRId64 "%c]",
+ pName, val, unit, minVal, unit, maxVal, unit);
}
return TSDB_CODE_SUCCESS;
}
static int32_t checkDbRangeOption(STranslateContext* pCxt, const char* pName, int64_t val, int64_t minVal,
- int64_t maxVal) {
- return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_DB_OPTION, pName, val, minVal, maxVal, true);
+ int64_t maxVal, int8_t unit) {
+ return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_DB_OPTION, pName, val, minVal, maxVal, unit, true);
}
static int32_t checkTableRangeOption(STranslateContext* pCxt, const char* pName, int64_t val, int64_t minVal,
int64_t maxVal) {
- return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_TABLE_OPTION, pName, val, minVal, maxVal, true);
+ return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_TABLE_OPTION, pName, val, minVal, maxVal, 0, true);
}
static int32_t checkDbS3KeepLocalOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
@@ -7841,7 +7841,8 @@ static int32_t checkDbS3KeepLocalOption(STranslateContext* pCxt, SDatabaseOption
}
pOptions->s3KeepLocal = getBigintFromValueNode(pOptions->s3KeepLocalStr);
}
- return checkDbRangeOption(pCxt, "s3KeepLocal", pOptions->s3KeepLocal, TSDB_MIN_S3_KEEP_LOCAL, TSDB_MAX_S3_KEEP_LOCAL);
+ return checkDbRangeOption(pCxt, "s3KeepLocal", pOptions->s3KeepLocal, TSDB_MIN_S3_KEEP_LOCAL, TSDB_MAX_S3_KEEP_LOCAL,
+ 0);
}
static int32_t checkDbDaysOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
@@ -7857,7 +7858,8 @@ static int32_t checkDbDaysOption(STranslateContext* pCxt, SDatabaseOptions* pOpt
}
pOptions->daysPerFile = getBigintFromValueNode(pOptions->pDaysPerFile);
}
- return checkDbRangeOption(pCxt, "daysPerFile", pOptions->daysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE);
+ return checkDbRangeOption(pCxt, "daysPerFile", pOptions->daysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE,
+ 0);
}
static int32_t checkDbKeepOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
@@ -8197,7 +8199,7 @@ static int32_t checkDbCompactIntervalOption(STranslateContext* pCxt, const char*
TAOS_CHECK_RETURN(translateGetDbCfg(pCxt, pDbName, &pOptions->pDbCfg));
keep2 = pOptions->pDbCfg->daysToKeep2;
}
- code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2);
+ code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2, TIME_UNIT_MINUTE);
}
} else if (pOptions->compactInterval > 0) {
interval = pOptions->compactInterval * 1440; // convert to minutes
@@ -8205,7 +8207,7 @@ static int32_t checkDbCompactIntervalOption(STranslateContext* pCxt, const char*
TAOS_CHECK_RETURN(translateGetDbCfg(pCxt, pDbName, &pOptions->pDbCfg));
keep2 = pOptions->pDbCfg->daysToKeep2;
}
- code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2);
+ code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2, TIME_UNIT_MINUTE);
}
if (code == 0) pOptions->compactInterval = interval;
return code;
@@ -8291,12 +8293,12 @@ static int32_t checkDbCompactTimeOffsetOption(STranslateContext* pCxt, SDatabase
pOptions->compactTimeOffset = getBigintFromValueNode(pOptions->pCompactTimeOffsetNode) / 60;
}
return checkDbRangeOption(pCxt, "compact_time_offset", pOptions->compactTimeOffset, TSDB_MIN_COMPACT_TIME_OFFSET,
- TSDB_MAX_COMPACT_TIME_OFFSET);
+ TSDB_MAX_COMPACT_TIME_OFFSET, TIME_UNIT_HOUR);
}
static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions) {
int32_t code =
- checkDbRangeOption(pCxt, "buffer", pOptions->buffer, TSDB_MIN_BUFFER_PER_VNODE, TSDB_MAX_BUFFER_PER_VNODE);
+ checkDbRangeOption(pCxt, "buffer", pOptions->buffer, TSDB_MIN_BUFFER_PER_VNODE, TSDB_MAX_BUFFER_PER_VNODE, 0);
if (TSDB_CODE_SUCCESS == code) {
code = checkDbCacheModelOption(pCxt, pOptions);
}
@@ -8304,26 +8306,27 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
code = checkDbEncryptAlgorithmOption(pCxt, pOptions);
}
if (TSDB_CODE_SUCCESS == code) {
- code =
- checkDbRangeOption(pCxt, "cacheSize", pOptions->cacheLastSize, TSDB_MIN_DB_CACHE_SIZE, TSDB_MAX_DB_CACHE_SIZE);
+ code = checkDbRangeOption(pCxt, "cacheSize", pOptions->cacheLastSize, TSDB_MIN_DB_CACHE_SIZE,
+ TSDB_MAX_DB_CACHE_SIZE, 0);
}
if (TSDB_CODE_SUCCESS == code) {
- code =
- checkDbRangeOption(pCxt, "compression", pOptions->compressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL);
+ code = checkDbRangeOption(pCxt, "compression", pOptions->compressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL,
+ 0);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbDaysOption(pCxt, pOptions);
}
if (TSDB_CODE_SUCCESS == code) {
- code = checkDbRangeOption(pCxt, "fsyncPeriod", pOptions->fsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD);
+ code =
+ checkDbRangeOption(pCxt, "fsyncPeriod", pOptions->fsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD, 0);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "maxRowsPerBlock", pOptions->maxRowsPerBlock, TSDB_MIN_MAXROWS_FBLOCK,
- TSDB_MAX_MAXROWS_FBLOCK);
+ TSDB_MAX_MAXROWS_FBLOCK, 0);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "minRowsPerBlock", pOptions->minRowsPerBlock, TSDB_MIN_MINROWS_FBLOCK,
- TSDB_MAX_MINROWS_FBLOCK);
+ TSDB_MAX_MINROWS_FBLOCK, 0);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbPrecisionOption(pCxt, pOptions);
@@ -8335,18 +8338,18 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
code = checkDbKeepTimeOffsetOption(pCxt, pOptions);
}
if (TSDB_CODE_SUCCESS == code) {
- code = checkDbRangeOption(pCxt, "pages", pOptions->pages, TSDB_MIN_PAGES_PER_VNODE, TSDB_MAX_PAGES_PER_VNODE);
+ code = checkDbRangeOption(pCxt, "pages", pOptions->pages, TSDB_MIN_PAGES_PER_VNODE, TSDB_MAX_PAGES_PER_VNODE, 0);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "pagesize", pOptions->pagesize, TSDB_MIN_PAGESIZE_PER_VNODE,
- TSDB_MAX_PAGESIZE_PER_VNODE);
+ TSDB_MAX_PAGESIZE_PER_VNODE, 0);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "tsdbPagesize", pOptions->tsdbPageSize, TSDB_MIN_TSDB_PAGESIZE,
- TSDB_MAX_TSDB_PAGESIZE);
+ TSDB_MAX_TSDB_PAGESIZE, 0);
}
if (TSDB_CODE_SUCCESS == code) {
- code = checkDbRangeOption(pCxt, "replications", pOptions->replica, TSDB_MIN_DB_REPLICA, TSDB_MAX_DB_REPLICA);
+ code = checkDbRangeOption(pCxt, "replications", pOptions->replica, TSDB_MIN_DB_REPLICA, TSDB_MAX_DB_REPLICA, 0);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbStrictOption(pCxt, pOptions);
@@ -8356,7 +8359,8 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
TSDB_MAX_WAL_LEVEL);
}
if (TSDB_CODE_SUCCESS == code) {
- code = checkDbRangeOption(pCxt, "vgroups", pOptions->numOfVgroups, TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB);
+ code =
+ checkDbRangeOption(pCxt, "vgroups", pOptions->numOfVgroups, TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB, 0);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbEnumOption(pCxt, "singleStable", pOptions->singleStable, TSDB_DB_SINGLE_STABLE_ON,
@@ -8370,21 +8374,23 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "walRetentionPeriod", pOptions->walRetentionPeriod,
- TSDB_DB_MIN_WAL_RETENTION_PERIOD, INT32_MAX);
+ TSDB_DB_MIN_WAL_RETENTION_PERIOD, INT32_MAX, 0);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "walRetentionSize", pOptions->walRetentionSize, TSDB_DB_MIN_WAL_RETENTION_SIZE,
- INT32_MAX);
- }
- if (TSDB_CODE_SUCCESS == code) {
- code = checkDbRangeOption(pCxt, "walRollPeriod", pOptions->walRollPeriod, TSDB_DB_MIN_WAL_ROLL_PERIOD, INT32_MAX);
+ INT32_MAX, 0);
}
if (TSDB_CODE_SUCCESS == code) {
code =
- checkDbRangeOption(pCxt, "walSegmentSize", pOptions->walSegmentSize, TSDB_DB_MIN_WAL_SEGMENT_SIZE, INT32_MAX);
+ checkDbRangeOption(pCxt, "walRollPeriod", pOptions->walRollPeriod, TSDB_DB_MIN_WAL_ROLL_PERIOD, INT32_MAX, 0);
}
if (TSDB_CODE_SUCCESS == code) {
- code = checkDbRangeOption(pCxt, "sstTrigger", pOptions->sstTrigger, TSDB_MIN_STT_TRIGGER, TSDB_MAX_STT_TRIGGER);
+ code = checkDbRangeOption(pCxt, "walSegmentSize", pOptions->walSegmentSize, TSDB_DB_MIN_WAL_SEGMENT_SIZE, INT32_MAX,
+ 0);
+ }
+ if (TSDB_CODE_SUCCESS == code) {
+ code =
+ checkDbRangeOption(pCxt, "sstTrigger", pOptions->sstTrigger, TSDB_MIN_STT_TRIGGER, TSDB_MAX_STT_TRIGGER, 0);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbEnumOption(pCxt, "withArbitrator", pOptions->withArbitrator, TSDB_MIN_DB_WITH_ARBITRATOR,
@@ -8405,10 +8411,10 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "s3_chunkpages", pOptions->s3ChunkSize, TSDB_MIN_S3_CHUNK_SIZE,
- TSDB_MAX_S3_CHUNK_SIZE);
+ TSDB_MAX_S3_CHUNK_SIZE, 0);
}
if (TSDB_CODE_SUCCESS == code) {
- code = checkDbRangeOption(pCxt, "s3_compact", pOptions->s3Compact, TSDB_MIN_S3_COMPACT, TSDB_MAX_S3_COMPACT);
+ code = checkDbRangeOption(pCxt, "s3_compact", pOptions->s3Compact, TSDB_MIN_S3_COMPACT, TSDB_MAX_S3_COMPACT, 0);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbCompactIntervalOption(pCxt, pDbName, pOptions);
@@ -9961,7 +9967,7 @@ static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* p
static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pStmt) {
int32_t code = 0;
SCreateUserReq createReq = {0};
- if ((code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, false))) {
+ if ((code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, 0, false))) {
return code;
}
tstrncpy(createReq.user, pStmt->userName, TSDB_USER_LEN);
@@ -9990,13 +9996,13 @@ static int32_t checkAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt) {
int32_t code = 0;
switch (pStmt->alterType) {
case TSDB_ALTER_USER_ENABLE:
- code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "enable", pStmt->enable, 0, 1, false);
+ code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "enable", pStmt->enable, 0, 1, 0, false);
break;
case TSDB_ALTER_USER_SYSINFO:
- code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, false);
+ code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, 0, false);
break;
case TSDB_ALTER_USER_CREATEDB:
- code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "createdb", pStmt->createdb, 0, 1, false);
+ code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "createdb", pStmt->createdb, 0, 1, 0, false);
break;
}
return code;
diff --git a/tests/system-test/1-insert/alter_database.py b/tests/system-test/1-insert/alter_database.py
index 47ad142bc4..2bbfff55a4 100644
--- a/tests/system-test/1-insert/alter_database.py
+++ b/tests/system-test/1-insert/alter_database.py
@@ -76,8 +76,18 @@ class TDTestCase:
tdSql.execute('drop database db')
def alter_compact(self):
- tdSql.error('create database db compact_time_range 60,61', expectErrInfo="Invalid option compact_time_range: 86400m, start_time should be in range: [-5256000m, -14400m]", fullMatched=True)
- tdSql.execute('drop database db')
+ tdSql.execute('create database db')
+ tdSql.execute('alter database db compact_time_offset 2')
+ tdSql.execute('alter database db compact_time_offset 3h')
+ tdSql.error('create database db1 compact_time_range 60,61', expectErrInfo="Invalid option compact_time_range: 86400m, start_time should be in range: [-5256000m, -14400m]", fullMatched=False)
+ tdSql.error('create database db1 compact_time_offset -1', expectErrInfo="syntax error near", fullMatched=False)
+ tdSql.error('create database d3 compact_interval 1m; ', expectErrInfo="Invalid option compact_interval: 1m, valid range: [10m, 5256000m]", fullMatched=False)
+ tdSql.error('alter database db compact_time_offset -1', expectErrInfo="syntax error near", fullMatched=False)
+ tdSql.error('alter database db compact_time_offset 24', expectErrInfo="Invalid option compact_time_offset: 24h, valid range: [0h, 23h]", fullMatched=False)
+ tdSql.error('alter database db compact_time_offset 24h', expectErrInfo="Invalid option compact_time_offset: 24h, valid range: [0h, 23h]", fullMatched=False)
+ tdSql.error('alter database db compact_time_offset 1d', expectErrInfo="Invalid option compact_time_offset unit: d, only h allowed", fullMatched=False)
+
+
def alter_same_options(self):
tdSql.execute('drop database if exists db')
From fcd436830ff1d30a5c13e565ebc8d2510d97a945 Mon Sep 17 00:00:00 2001
From: kailixu
Date: Fri, 27 Dec 2024 18:54:22 +0800
Subject: [PATCH 21/56] test: add test case for auto compact
---
source/dnode/mnode/impl/src/mndDb.c | 4 ++--
tests/system-test/1-insert/alter_database.py | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index 02e13e9951..e6a7a9cf6b 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -2570,13 +2570,13 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
len = formatDurationOrKeep(durationStr, sizeof(durationStr), pDb->cfg.compactStartTime);
formatDurationOrKeep(durationVstr, sizeof(durationVstr), pDb->cfg.compactEndTime);
- snprintf(durationStr + len, sizeof(durationStr) - len, ",%s", durationVstr);
+ (void)snprintf(durationStr + len, sizeof(durationStr) - len, ",%s", durationVstr);
STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr));
if ((pColInfo = taosArrayGet(pBlock->pDataBlock, cols++))) {
TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER);
}
- snprintf(durationStr, sizeof(durationStr), "%dh", pDb->cfg.compactTimeOffset);
+ (void)snprintf(durationStr, sizeof(durationStr), "%dh", pDb->cfg.compactTimeOffset);
STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr));
if ((pColInfo = taosArrayGet(pBlock->pDataBlock, cols++))) {
TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER);
diff --git a/tests/system-test/1-insert/alter_database.py b/tests/system-test/1-insert/alter_database.py
index 2bbfff55a4..c20ace6ff4 100644
--- a/tests/system-test/1-insert/alter_database.py
+++ b/tests/system-test/1-insert/alter_database.py
@@ -115,10 +115,10 @@ class TDTestCase:
def run(self):
- # self.alter_buffer()
- # self.alter_pages()
- # self.alter_encrypt_alrogithm()
- # self.alter_same_options()
+ self.alter_buffer()
+ self.alter_pages()
+ self.alter_encrypt_alrogithm()
+ self.alter_same_options()
self.alter_compact()
def stop(self):
From bf33ef0c07db5e173c85b134a7d82967478ed08b Mon Sep 17 00:00:00 2001
From: kailixu
Date: Fri, 27 Dec 2024 18:57:12 +0800
Subject: [PATCH 22/56] test: add test case for auto compact
---
source/dnode/mnode/impl/src/mndDb.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index e6a7a9cf6b..432d0329d1 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -2561,22 +2561,21 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)encryptAlgorithmVStr, false), &lino, _OVER);
- formatDurationOrKeep(durationStr, sizeof(durationStr), pDb->cfg.compactInterval);
- STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr));
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- if (pColInfo) {
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER);
- }
-
- len = formatDurationOrKeep(durationStr, sizeof(durationStr), pDb->cfg.compactStartTime);
- formatDurationOrKeep(durationVstr, sizeof(durationVstr), pDb->cfg.compactEndTime);
- (void)snprintf(durationStr + len, sizeof(durationStr) - len, ",%s", durationVstr);
+ TAOS_UNUSED(formatDurationOrKeep(durationStr, sizeof(durationStr), pDb->cfg.compactInterval));
STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr));
if ((pColInfo = taosArrayGet(pBlock->pDataBlock, cols++))) {
TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER);
}
- (void)snprintf(durationStr, sizeof(durationStr), "%dh", pDb->cfg.compactTimeOffset);
+ len = formatDurationOrKeep(durationStr, sizeof(durationStr), pDb->cfg.compactStartTime);
+ formatDurationOrKeep(durationVstr, sizeof(durationVstr), pDb->cfg.compactEndTime);
+ TAOS_UNUSED(snprintf(durationStr + len, sizeof(durationStr) - len, ",%s", durationVstr));
+ STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr));
+ if ((pColInfo = taosArrayGet(pBlock->pDataBlock, cols++))) {
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER);
+ }
+
+ TAOS_UNUSED(snprintf(durationStr, sizeof(durationStr), "%dh", pDb->cfg.compactTimeOffset));
STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr));
if ((pColInfo = taosArrayGet(pBlock->pDataBlock, cols++))) {
TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER);
From dc1ab696d4a320f1c26017b87c224fe8005db599 Mon Sep 17 00:00:00 2001
From: haoranchen
Date: Fri, 27 Dec 2024 19:40:34 +0800
Subject: [PATCH 23/56] Create taosd-ci-build.yml
---
.github/workflows/taosd-ci-build.yml | 65 ++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
create mode 100644 .github/workflows/taosd-ci-build.yml
diff --git a/.github/workflows/taosd-ci-build.yml b/.github/workflows/taosd-ci-build.yml
new file mode 100644
index 0000000000..3ac3caaa7f
--- /dev/null
+++ b/.github/workflows/taosd-ci-build.yml
@@ -0,0 +1,65 @@
+name: TDengine CI
+
+on:
+ pull_request:
+ branches:
+ - 'main'
+ - '3.0'
+ - '3.1'
+ push:
+ branches:
+ - 'enh/main/TD-33380'
+ - '3.0'
+ - '3.1'
+ - 'main'
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ name: Run unit tests
+
+ steps:
+ - name: Checkout the repository
+ uses: actions/checkout@v4
+
+ - name: Set up Go
+ uses: actions/setup-go@v5
+ with:
+ go-version: 1.18
+
+ - name: Install system dependencies
+ run: |
+ sudo apt update -y
+ sudo apt install -y build-essential cmake libgeos-dev
+
+ - name: Install TDengine
+ run: |
+ mkdir debug
+ cd debug
+ cmake .. -DBUILD_HTTP=false -DBUILD_JDBC=false -DBUILD_TOOLS=false -DBUILD_TEST=off -DBUILD_KEEPER=true -DBUILD_DEPENDENCY_TESTS=false
+ make -j 4
+ sudo make install
+ which taosd
+ which taosadapter
+ which taoskeeper
+
+ - name: Start taosd
+ run: |
+ cp /etc/taos/taos.cfg ./
+ sudo echo "supportVnodes 256" >> taos.cfg
+ nohup sudo taosd -c taos.cfg &
+
+ - name: Start taosadapter
+ run: nohup sudo taosadapter &
+
+ - name: Run tests with coverage
+ working-directory: tools/keeper
+ run: |
+ taosBenchmark -t 10 -n 10 -y
+ taos -s "select count(*) from test.meters"
+
+ - name: Clean up
+ if: always()
+ run: |
+ if pgrep taosd; then sudo pkill taosd; fi
+ if pgrep taosadapter; then sudo pkill taosadapter; fi
From 0928590519fff3d01e6f1c2c99932680088813fa Mon Sep 17 00:00:00 2001
From: haoranchen
Date: Fri, 27 Dec 2024 19:43:09 +0800
Subject: [PATCH 24/56] Update taosd-ci-build.yml
---
.github/workflows/taosd-ci-build.yml | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/taosd-ci-build.yml b/.github/workflows/taosd-ci-build.yml
index 3ac3caaa7f..4495fd737e 100644
--- a/.github/workflows/taosd-ci-build.yml
+++ b/.github/workflows/taosd-ci-build.yml
@@ -36,7 +36,7 @@ jobs:
run: |
mkdir debug
cd debug
- cmake .. -DBUILD_HTTP=false -DBUILD_JDBC=false -DBUILD_TOOLS=false -DBUILD_TEST=off -DBUILD_KEEPER=true -DBUILD_DEPENDENCY_TESTS=false
+ cmake .. -DBUILD_HTTP=false -DBUILD_JDBC=false -DBUILD_TOOLS=true -DBUILD_TEST=off -DBUILD_KEEPER=true -DBUILD_DEPENDENCY_TESTS=false
make -j 4
sudo make install
which taosd
@@ -52,8 +52,7 @@ jobs:
- name: Start taosadapter
run: nohup sudo taosadapter &
- - name: Run tests with coverage
- working-directory: tools/keeper
+ - name: Run tests with taosBenchmark
run: |
taosBenchmark -t 10 -n 10 -y
taos -s "select count(*) from test.meters"
From a675882d14c898b080796b418ab36d851128ea41 Mon Sep 17 00:00:00 2001
From: haoranchen
Date: Fri, 27 Dec 2024 19:53:37 +0800
Subject: [PATCH 25/56] fix: add dependencies for taos-tools compile
---
.github/workflows/taosd-ci-build.yml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/taosd-ci-build.yml b/.github/workflows/taosd-ci-build.yml
index 4495fd737e..8a0294a0a6 100644
--- a/.github/workflows/taosd-ci-build.yml
+++ b/.github/workflows/taosd-ci-build.yml
@@ -30,7 +30,8 @@ jobs:
- name: Install system dependencies
run: |
sudo apt update -y
- sudo apt install -y build-essential cmake libgeos-dev
+ sudo apt install -y build-essential cmake libgeos-dev libjansson-dev libsnappy-dev liblzma-dev libz-dev zlib1g pkg-config libssl-dev gawk
+
- name: Install TDengine
run: |
From a005a132d9e75d3c98e0e491314279d79f60be4b Mon Sep 17 00:00:00 2001
From: haoranchen
Date: Fri, 27 Dec 2024 20:15:52 +0800
Subject: [PATCH 26/56] Update taosd-ci-build.yml
---
.github/workflows/taosd-ci-build.yml | 1 -
1 file changed, 1 deletion(-)
diff --git a/.github/workflows/taosd-ci-build.yml b/.github/workflows/taosd-ci-build.yml
index 8a0294a0a6..3adfde3460 100644
--- a/.github/workflows/taosd-ci-build.yml
+++ b/.github/workflows/taosd-ci-build.yml
@@ -8,7 +8,6 @@ on:
- '3.1'
push:
branches:
- - 'enh/main/TD-33380'
- '3.0'
- '3.1'
- 'main'
From 746cbc09c3338839866c4cc98fff70063031b745 Mon Sep 17 00:00:00 2001
From: Haojun Liao
Date: Thu, 26 Dec 2024 17:24:17 +0800
Subject: [PATCH 27/56] test(analytics): add tests for tdanalytics.
---
source/util/src/tanalytics.c | 6 +--
tests/script/sh/stop_dnodes.sh | 8 +--
tests/script/tsim/analytics/basic0.sim | 67 +++++++++++++++++++++++++-
3 files changed, 73 insertions(+), 8 deletions(-)
diff --git a/source/util/src/tanalytics.c b/source/util/src/tanalytics.c
index e68edd4b76..bf2cb4fd07 100644
--- a/source/util/src/tanalytics.c
+++ b/source/util/src/tanalytics.c
@@ -20,7 +20,7 @@
#ifdef USE_ANALYTICS
#include
-#define ANAL_ALGO_SPLIT ","
+#define ANALYTICS_ALOG_SPLIT_CHAR ","
typedef struct {
int64_t ver;
@@ -136,7 +136,7 @@ bool taosAnalGetOptStr(const char *option, const char *optName, char *optValue,
return false;
}
- pEnd = strstr(pStart, ANAL_ALGO_SPLIT);
+ pEnd = strstr(pStart, ANALYTICS_ALOG_SPLIT_CHAR);
if (optMaxLen > 0) {
if (pEnd > pStart) {
int32_t len = (int32_t)(pEnd - pStart);
@@ -168,7 +168,7 @@ bool taosAnalGetOptInt(const char *option, const char *optName, int64_t *optValu
int32_t bufLen = tsnprintf(buf, sizeof(buf), "%s=", optName);
char *pos1 = strstr(option, buf);
- char *pos2 = strstr(option, ANAL_ALGO_SPLIT);
+ char *pos2 = strstr(option, ANALYTICS_ALOG_SPLIT_CHAR);
if (pos1 != NULL) {
*optValue = taosStr2Int64(pos1 + bufLen, NULL, 10);
return true;
diff --git a/tests/script/sh/stop_dnodes.sh b/tests/script/sh/stop_dnodes.sh
index 8923804547..da2083b013 100755
--- a/tests/script/sh/stop_dnodes.sh
+++ b/tests/script/sh/stop_dnodes.sh
@@ -13,7 +13,7 @@ if [ -n "$PID" ]; then
systemctl stop taosd
fi
-PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
+PID=`ps -ef|grep -w taosd | grep -v grep | grep -v taosanode | awk '{print $2}'`
while [ -n "$PID" ]; do
echo kill -9 $PID
#pkill -9 taosd
@@ -38,10 +38,10 @@ while [ -n "$PID" ]; do
else
lsof -nti:6030 | xargs kill -9
fi
- PID=`ps -ef|grep -w taos | grep -v grep | awk '{print $2}'`
+ PID=`ps -ef|grep -w taos | grep -v grep |grep -v taosanode| awk '{print $2}'`
done
-PID=`ps -ef|grep -w tmq_sim | grep -v grep | awk '{print $2}'`
+PID=`ps -ef|grep -w tmq_sim | grep -v grep | grep -v taosanode|awk '{print $2}'`
while [ -n "$PID" ]; do
echo kill -9 $PID
#pkill -9 tmq_sim
@@ -52,5 +52,5 @@ while [ -n "$PID" ]; do
else
lsof -nti:6030 | xargs kill -9
fi
- PID=`ps -ef|grep -w tmq_sim | grep -v grep | awk '{print $2}'`
+ PID=`ps -ef|grep -w tmq_sim | grep -v grep | grep -v taosanode| awk '{print $2}'`
done
\ No newline at end of file
diff --git a/tests/script/tsim/analytics/basic0.sim b/tests/script/tsim/analytics/basic0.sim
index 77c9184e8f..35774e7682 100644
--- a/tests/script/tsim/analytics/basic0.sim
+++ b/tests/script/tsim/analytics/basic0.sim
@@ -3,7 +3,17 @@ system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sql connect
-print =============== create anode
+print =============== failed to create anode on '127.0.0.1:1101'
+sql_error create anode '127.0.0.1:1101'
+
+sql show anodes
+if $rows != 0 then
+ return -1
+endi
+
+sql_error drop anode 1
+
+print ================ create anode
sql create anode '192.168.1.116:6050'
sql show anodes
@@ -58,6 +68,61 @@ if $data00 != 1 then
return -1
endi
+sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=0.5,wncheck=1,period=0') from ct1
+sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=119,wncheck=1,period=0') from ct1
+sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters1,conf=0.5,wncheck=1,period=0') from ct1
+sql_error select forecast(c1, 'conf=50 ,algo = arima, rows=0') from ct1
+sql_error select forecast(c1, 'conf=50 ,algo = arima, rows=-10') from ct1
+sql_error select forecast(c1, 'conf=50 ,algo = arima, every=0') from ct1
+
+sql select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters, conf=50 ') from ct1
+sql select _frowts, _flow, _fhigh, forecast(c1, ' algo=holtwinters , conf=50 ') from ct1
+sql select _frowts, _flow, _fhigh, forecast(c1, ' algo = holtwinters , conf = 50 ') from ct1
+sql select _frowts, _flow, _fhigh, forecast(c1, 'conf=50 ,algo = holtwinters, ') from ct1
+sql select _frowts, _flow, _fhigh, forecast(c1, 'conf=50 ,algo = holtwinters, ,') from ct1
+sql select _frowts, _flow, _fhigh, forecast(c1, 'conf=50 ,algo = holtwinters, , ,') from ct1
+sql select _frowts, _flow, _fhigh, forecast(c1, 'conf=50 ,algo = holtwinters, a =') from ct1
+sql select _frowts, _flow, _fhigh, forecast(c1, 'conf=50 ,algo = holtwinters, = a ,') from ct1
+sql select forecast(c1, 'conf=50 ,algo = arima') from ct1
+sql select forecast(c1, 'conf=50 ,algo = arima, rows=1') from ct1
+
+sql select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=50,wncheck=1,period=0,start=1700000000000,every=2') from ct1
+if $rows != 10 then
+ return -1
+endi
+
+if $data03 != 28 then
+ return -1
+endi
+
+if $data00 != @23-11-15 06:13:20.000@ then
+ print expect 23-11-15 06:13:20.000 , actual $data00
+ return -1
+endi
+
+if $data10 != @23-11-15 06:13:20.002@ then
+ print expect 23-11-15 06:13:20.002 , actual $data10
+ return -1
+endi
+
+if $data20 != @23-11-15 06:13:20.004@ then
+ return -1
+endi
+
+print test the every option and rows option
+
+sql select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=50,wncheck=1,period=0,start=1700000000000,every=100,rows=5') from ct1
+if $rows != 5 then
+ return -1
+endi
+
+if $data00 != @23-11-15 06:13:20.000@ then
+ return -1
+endi
+
+if $data10 != @23-11-15 06:13:20.100@ then
+ return -1
+endi
sql drop anode 1
sql show anodes
From 98a3fa1ab5ac633d41d01d41c01fac9a6facf1f8 Mon Sep 17 00:00:00 2001
From: Haojun Liao
Date: Thu, 26 Dec 2024 18:17:02 +0800
Subject: [PATCH 28/56] test: add test case for anamaly detection in
tdanalytics.
---
.../libs/executor/src/anomalywindowoperator.c | 49 +++++++++----------
tests/script/tsim/analytics/basic0.sim | 44 +++++++++++++++--
2 files changed, 62 insertions(+), 31 deletions(-)
diff --git a/source/libs/executor/src/anomalywindowoperator.c b/source/libs/executor/src/anomalywindowoperator.c
index dd1a52022e..eb72edb964 100644
--- a/source/libs/executor/src/anomalywindowoperator.c
+++ b/source/libs/executor/src/anomalywindowoperator.c
@@ -61,9 +61,13 @@ static int32_t anomalyCacheBlock(SAnomalyWindowOperatorInfo* pInfo, SSDataBlock*
int32_t createAnomalywindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* physiNode, SExecTaskInfo* pTaskInfo,
SOperatorInfo** pOptrInfo) {
QRY_PARAM_CHECK(pOptrInfo);
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t lino = 0;
+ size_t keyBufSize = 0;
+ int32_t num = 0;
+ SExprInfo* pExprInfo = NULL;
+ const char* id = GET_TASKID(pTaskInfo);
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t lino = 0;
SAnomalyWindowOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAnomalyWindowOperatorInfo));
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
SAnomalyWindowPhysiNode* pAnomalyNode = (SAnomalyWindowPhysiNode*)physiNode;
@@ -74,13 +78,13 @@ int32_t createAnomalywindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* p
}
if (!taosAnalGetOptStr(pAnomalyNode->anomalyOpt, "algo", pInfo->algoName, sizeof(pInfo->algoName))) {
- qError("failed to get anomaly_window algorithm name from %s", pAnomalyNode->anomalyOpt);
+ qError("%s failed to get anomaly_window algorithm name from %s", id, pAnomalyNode->anomalyOpt);
code = TSDB_CODE_ANA_ALGO_NOT_FOUND;
goto _error;
}
if (taosAnalGetAlgoUrl(pInfo->algoName, ANAL_ALGO_TYPE_ANOMALY_DETECT, pInfo->algoUrl, sizeof(pInfo->algoUrl)) != 0) {
- qError("failed to get anomaly_window algorithm url from %s", pInfo->algoName);
+ qError("%s failed to get anomaly_window algorithm url from %s", id, pInfo->algoName);
code = TSDB_CODE_ANA_ALGO_NOT_LOAD;
goto _error;
}
@@ -94,20 +98,18 @@ int32_t createAnomalywindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* p
SExprInfo* pScalarExprInfo = NULL;
code = createExprInfo(pAnomalyNode->window.pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
QUERY_CHECK_CODE(code, lino, _error);
+
code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
QUERY_CHECK_CODE(code, lino, _error);
}
- size_t keyBufSize = 0;
- int32_t num = 0;
- SExprInfo* pExprInfo = NULL;
code = createExprInfo(pAnomalyNode->window.pFuncs, NULL, &pExprInfo, &num);
QUERY_CHECK_CODE(code, lino, _error);
initResultSizeInfo(&pOperator->resultInfo, 4096);
- code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
- pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
+ code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, id, pTaskInfo->streamInfo.pState,
+ &pTaskInfo->storageAPI.functionStore);
QUERY_CHECK_CODE(code, lino, _error);
SSDataBlock* pResBlock = createDataBlockFromDescNode(pAnomalyNode->window.node.pOutputDataBlockDesc);
@@ -124,27 +126,19 @@ int32_t createAnomalywindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* p
pInfo->anomalyCol = extractColumnFromColumnNode(pColNode);
pInfo->anomalyKey.type = pInfo->anomalyCol.type;
pInfo->anomalyKey.bytes = pInfo->anomalyCol.bytes;
+
pInfo->anomalyKey.pData = taosMemoryCalloc(1, pInfo->anomalyCol.bytes);
- if (pInfo->anomalyKey.pData == NULL) {
- goto _error;
- }
+ QUERY_CHECK_NULL(pInfo->anomalyKey.pData, code, lino, _error, terrno)
int32_t itemSize = sizeof(int32_t) + pInfo->aggSup.resultRowSize + pInfo->anomalyKey.bytes;
pInfo->anomalySup.pResultRow = taosMemoryCalloc(1, itemSize);
- if (pInfo->anomalySup.pResultRow == NULL) {
- code = terrno;
- goto _error;
- }
+ QUERY_CHECK_NULL(pInfo->anomalySup.pResultRow, code, lino, _error, terrno)
+
pInfo->anomalySup.blocks = taosArrayInit(16, sizeof(SSDataBlock*));
- if (pInfo->anomalySup.blocks == NULL) {
- code = terrno;
- goto _error;
- }
+ QUERY_CHECK_NULL(pInfo->anomalySup.blocks, code, lino, _error, terrno)
+
pInfo->anomalySup.windows = taosArrayInit(16, sizeof(STimeWindow));
- if (pInfo->anomalySup.windows == NULL) {
- code = terrno;
- goto _error;
- }
+ QUERY_CHECK_NULL(pInfo->anomalySup.windows, code, lino, _error, terrno)
code = filterInitFromNode((SNode*)pAnomalyNode->window.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0);
QUERY_CHECK_CODE(code, lino, _error);
@@ -162,18 +156,21 @@ int32_t createAnomalywindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* p
*pOptrInfo = pOperator;
- qDebug("anomaly_window operator is created, algo:%s url:%s opt:%s", pInfo->algoName, pInfo->algoUrl,
+ qDebug("%s anomaly_window operator is created, algo:%s url:%s opt:%s", id, pInfo->algoName, pInfo->algoUrl,
pInfo->anomalyOpt);
return TSDB_CODE_SUCCESS;
_error:
+ qError("%s failed to create anomaly_window operator, line:%d algo:%s code:%s", id, lino, pAnomalyNode->anomalyOpt,
+ tstrerror(code));
+
if (pInfo != NULL) {
anomalyDestroyOperatorInfo(pInfo);
}
destroyOperatorAndDownstreams(pOperator, &downstream, 1);
pTaskInfo->code = code;
- qError("failed to create anomaly_window operator, algo:%s code:0x%x", pInfo->algoName, code);
+
return code;
}
diff --git a/tests/script/tsim/analytics/basic0.sim b/tests/script/tsim/analytics/basic0.sim
index 35774e7682..3ac49b1fc3 100644
--- a/tests/script/tsim/analytics/basic0.sim
+++ b/tests/script/tsim/analytics/basic0.sim
@@ -40,7 +40,7 @@ print $data00 $data01 $data02
sql use d0
print =============== create super table, include column type for count/sum/min/max/first
-sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int unsigned)
+sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 double, c4 tinyint, c5 bigint, c6 varchar(12)) tags (t1 int unsigned)
sql show stables
if $rows != 1 then
@@ -52,10 +52,11 @@ sql create table ct1 using stb tags(1000)
print ==================== insert data
# input_list = [5, 14, 15, 15, 14, 19, 17, 16, 20, 22, 8, 21, 28, 11, 9, 29, 40]
-sql insert into ct1(ts, c1) values(now-1a, 5)(now+1a, 14)(now+2a, 15)(now+3a, 15)(now+4a, 14)
-sql insert into ct1(ts, c1) values(now+5a, 19)(now+6a, 17)(now+7a, 16)(now+8a, 20)(now+9a, 22)
-sql insert into ct1(ts, c1) values(now+10a, 8)(now+11a, 21)(now+12a, 28)(now+13a, 11)(now+14a, 9)
-sql insert into ct1(ts, c1) values(now+15a, 29)(now+16a, 40)
+sql insert into ct1(ts, c1, c2, c3, c4, c5, c6) values(now-1a, 5, 5, 5, 5, 5, 'a')(now+1a, 14, 14, 14, 14, 14, 'a')(now+2a, 15, 15, 15, 15, 15, 'a')
+sql insert into ct1 values(now+3a, 15, 15, 15, 15, 15, 'a')(now+4a, 14, 14, 14, 14, 14, 'a')(now+5a, 19, 19, 19, 19, 19, 'a')(now+6a, 17, 17, 17, 17, 17, 'a')
+sql insert into ct1 values(now+7a, 16, 16, 16, 16, 16, 'a')(now+8a, 20, 20, 20, 20, 20, 'a')(now+9a, 22, 22, 22, 22, 22, 'a')
+sql insert into ct1 values(now+10a, 8, 8, 8, 8, 8, 'a')(now+11a, 21, 21, 21, 21, 21, 'a')(now+12a, 28, 28, 28, 28, 28, 'a')(now+13a, 11, 11, 11, 11, 11, 'a')(now+14a, 9, 9, 9, 9, 9, 'a')
+sql insert into ct1 values(now+15a, 29, 29, 29, 29, 29, 'a')(now+16a, 40, 40, 40, 40, 40, 'a')
sql select count(*) from ct1
if $data00 != 17 then
@@ -68,6 +69,25 @@ if $data00 != 1 then
return -1
endi
+print ================= try every loaded anomaly detection algorithm
+sql select count(*) from ct1 anomaly_window(c1, 'algo=iqr');
+sql select count(*) from ct1 anomaly_window(c1, 'algo=ksigma');
+sql select count(*) from ct1 anomaly_window(c1, 'algo=lof');
+sql select count(*) from ct1 anomaly_window(c1, 'algo=shesd');
+sql select count(*) from ct1 anomaly_window(c1, 'algo=grubbs');
+
+print ================= try every column type of column
+sql select count(*) from ct1 anomaly_window(c1, 'algo=ksigma,k=2');
+sql select count(*) from ct1 anomaly_window(c2, 'algo=ksigma,k=2');
+sql select count(*) from ct1 anomaly_window(c3, 'algo=ksigma,k=2');
+sql select count(*) from ct1 anomaly_window(c4, 'algo=ksigma,k=2');
+sql select count(*) from ct1 anomaly_window(c5, 'algo=ksigma,k=2');
+
+print =================== invalid column type
+sql_error select count(*) from ct1 anomaly_window(c6, 'algo=ksigma,k=2');
+sql_error select forecast(c6, 'algo=holtwinters,conf=0.5,wncheck=1,period=0') from ct1
+
+
sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=0.5,wncheck=1,period=0') from ct1
sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=119,wncheck=1,period=0') from ct1
sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters1,conf=0.5,wncheck=1,period=0') from ct1
@@ -83,8 +103,15 @@ sql select _frowts, _flow, _fhigh, forecast(c1, 'conf=50 ,algo = holtwinters, ,'
sql select _frowts, _flow, _fhigh, forecast(c1, 'conf=50 ,algo = holtwinters, , ,') from ct1
sql select _frowts, _flow, _fhigh, forecast(c1, 'conf=50 ,algo = holtwinters, a =') from ct1
sql select _frowts, _flow, _fhigh, forecast(c1, 'conf=50 ,algo = holtwinters, = a ,') from ct1
+
+print =================== valid column type
sql select forecast(c1, 'conf=50 ,algo = arima') from ct1
sql select forecast(c1, 'conf=50 ,algo = arima, rows=1') from ct1
+sql select forecast(c2, 'conf=50 ,algo = arima, rows=1') from ct1
+sql select forecast(c3, 'conf=50 ,algo = arima, rows=1') from ct1
+sql select forecast(c4, 'conf=50 ,algo = arima, rows=1') from ct1
+sql select forecast(c5, 'conf=50 ,algo = arima, rows=1') from ct1
+sql select forecast(c5, 'conf=50 ,algo = arima, rows=1') from ct1
sql select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=50,wncheck=1,period=0,start=1700000000000,every=2') from ct1
if $rows != 10 then
@@ -131,6 +158,13 @@ if $rows != 0 then
return -1
endi
+sleep 1000
+
+print ===================== query without anodes
+sql_error select forecast(c5, 'conf=50 ,algo = arima, rows=1') from ct1
+sql_error select count(*) from ct1 anomaly_window(c1, 'algo=iqr');
+
+
_OVER:
system sh/exec.sh -n dnode1 -s stop -x SIGINT
print =============== check
From e8f63cded9e3b946e5daf89a30a09679e27d9e66 Mon Sep 17 00:00:00 2001
From: 54liuyao <54liuyao@163.com>
Date: Fri, 27 Dec 2024 10:27:05 +0800
Subject: [PATCH 29/56] fix stream state operator issue
---
.../executor/src/streamtimewindowoperator.c | 17 ++++++-
tests/script/tsim/stream/basic5.sim | 49 ++++++++++++++-----
2 files changed, 54 insertions(+), 12 deletions(-)
diff --git a/source/libs/executor/src/streamtimewindowoperator.c b/source/libs/executor/src/streamtimewindowoperator.c
index 91af218a7e..031d2e8bdc 100644
--- a/source/libs/executor/src/streamtimewindowoperator.c
+++ b/source/libs/executor/src/streamtimewindowoperator.c
@@ -4466,6 +4466,19 @@ _end:
return code;
}
+static bool isWinResult(SSessionKey* pKey, SSHashObj* pSeUpdate, SSHashObj* pResults) {
+ SSessionKey checkKey = {0};
+ getSessionHashKey(pKey, &checkKey);
+ if (tSimpleHashGet(pSeUpdate, &checkKey, sizeof(SSessionKey)) != NULL) {
+ return true;
+ }
+
+ if (tSimpleHashGet(pResults, &checkKey, sizeof(SSessionKey)) != NULL) {
+ return true;
+ }
+ return false;
+}
+
static void doStreamStateAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBlock, SSHashObj* pSeUpdated,
SSHashObj* pStDeleted) {
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
@@ -4518,7 +4531,9 @@ static void doStreamStateAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBl
code = setStateOutputBuf(pAggSup, tsCols[i], groupId, pKeyData, &curWin, &nextWin);
QUERY_CHECK_CODE(code, lino, _end);
- releaseOutputBuf(pAggSup->pState, nextWin.winInfo.pStatePos, &pAPI->stateStore);
+ if (isWinResult(&nextWin.winInfo.sessionWin, pSeUpdated, pAggSup->pResultRows) == false) {
+ releaseOutputBuf(pAggSup->pState, nextWin.winInfo.pStatePos, &pAPI->stateStore);
+ }
setSessionWinOutputInfo(pSeUpdated, &curWin.winInfo);
code = updateStateWindowInfo(pAggSup, &curWin, &nextWin, tsCols, groupId, pKeyColInfo, rows, i, &allEqual,
diff --git a/tests/script/tsim/stream/basic5.sim b/tests/script/tsim/stream/basic5.sim
index d7dd603d3c..5d90740b13 100644
--- a/tests/script/tsim/stream/basic5.sim
+++ b/tests/script/tsim/stream/basic5.sim
@@ -2,13 +2,28 @@ system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c debugflag -v 135
system sh/cfg.sh -n dnode1 -c streamBufferSize -v 10
+system sh/cfg.sh -n dnode1 -c checkpointinterval -v 60
+system sh/cfg.sh -n dnode1 -c snodeAddress -v 127.0.0.1:873
system sh/exec.sh -n dnode1 -s start
sleep 500
sql connect
+print step1 =============
-print step1=============
+print ================ create snode
+sql show snodes
+if $rows != 0 then
+ return -1
+endi
+
+sql create snode on dnode 1;
+sql show snodes;
+if $rows != 1 then
+ return -1
+endi
+
+print ============== snode created , create db
sql create database test3 vgroups 1;
sql use test3;
@@ -57,7 +72,7 @@ loop8:
sleep 200
$loop_count = $loop_count + 1
-if $loop_count == 10 then
+if $loop_count == 30 then
return -1
endi
@@ -87,7 +102,7 @@ loop9:
sleep 200
$loop_count = $loop_count + 1
-if $loop_count == 10 then
+if $loop_count == 30 then
return -1
endi
@@ -127,7 +142,7 @@ loop10:
sleep 200
$loop_count = $loop_count + 1
-if $loop_count == 10 then
+if $loop_count == 30 then
return -1
endi
@@ -162,7 +177,7 @@ loop11:
sleep 200
$loop_count = $loop_count + 1
-if $loop_count == 10 then
+if $loop_count == 30 then
return -1
endi
@@ -194,7 +209,7 @@ loop11:
sleep 200
$loop_count = $loop_count + 1
-if $loop_count == 10 then
+if $loop_count == 30 then
return -1
endi
@@ -239,7 +254,7 @@ loop12:
sleep 200
$loop_count = $loop_count + 1
-if $loop_count == 10 then
+if $loop_count == 30 then
return -1
endi
@@ -315,7 +330,7 @@ loop13:
sleep 200
$loop_count = $loop_count + 1
-if $loop_count == 10 then
+if $loop_count == 30 then
return -1
endi
@@ -369,7 +384,6 @@ if $data24 != 1 then
endi
print step4=============
-
sql create database test6 vgroups 4;
sql use test6;
sql create stable st(ts timestamp,a int,b int,c int,d int) tags(ta int,tb int,tc int);
@@ -396,7 +410,7 @@ loop14:
sleep 200
$loop_count = $loop_count + 1
-if $loop_count == 10 then
+if $loop_count == 30 then
return -1
endi
@@ -449,4 +463,17 @@ if $data25 != 2 then
goto loop14
endi
-system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
+print sleep for 1min for checkpoint generate
+sleep 60000
+
+print ================== restart to load checkpoint from snode
+
+system sh/exec.sh -n dnode1 -s stop -x SIGINT
+system sh/exec.sh -n dnode1 -s start
+
+sleep 500
+sql connect
+
+sleep 30000
+
+sql select start_ver, checkpoint_ver from information_schema.ins_stream_tasks;
From a334bf19914dbede98207c18441ca7680285dc4e Mon Sep 17 00:00:00 2001
From: Haojun Liao
Date: Fri, 27 Dec 2024 11:19:24 +0800
Subject: [PATCH 30/56] test: update the sim, set the output as uint, instead
of int to avoid overflow.
---
source/libs/function/src/builtinsimpl.c | 2 +-
tests/script/tsim/stream/basic5.sim | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c
index 1c77d12fb2..707018ac65 100644
--- a/source/libs/function/src/builtinsimpl.c
+++ b/source/libs/function/src/builtinsimpl.c
@@ -6429,7 +6429,7 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
return code;
}
- len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE, "Inmem_Rows=[%d] Stt_Rows=[%d] ",
+ len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE, "Inmem_Rows=[%u] Stt_Rows=[%u] ",
pData->numOfInmemRows, pData->numOfSttRows);
varDataSetLen(st, len);
code = colDataSetVal(pColInfo, row++, st, false);
diff --git a/tests/script/tsim/stream/basic5.sim b/tests/script/tsim/stream/basic5.sim
index 5d90740b13..866fbd3ebe 100644
--- a/tests/script/tsim/stream/basic5.sim
+++ b/tests/script/tsim/stream/basic5.sim
@@ -476,4 +476,8 @@ sql connect
sleep 30000
-sql select start_ver, checkpoint_ver from information_schema.ins_stream_tasks;
+sql select start_ver, checkpoint_ver from information_schema.ins_stream_tasks where level='source';
+sleep 500
+
+system sh/exec.sh -n dnode1 -s stop -x SIGINT
+
From ec2c8c435edc5793db61bcc3b69f4c500f5af1e2 Mon Sep 17 00:00:00 2001
From: Shengliang Guan
Date: Fri, 27 Dec 2024 22:26:43 +0800
Subject: [PATCH 31/56] Revert "Enh:[td 29974]improve trans"
---
docs/en/08-operation/04-maintenance.md | 2 +-
docs/en/14-reference/03-taos-sql/24-show.md | 3 +-
docs/zh/08-operation/04-maintenance.md | 2 +-
docs/zh/14-reference/03-taos-sql/24-show.md | 3 +-
include/common/systable.h | 1 -
include/common/tmsg.h | 2 -
include/libs/nodes/cmdnodes.h | 5 -
include/util/taoserror.h | 1 -
include/util/tdef.h | 6 +-
source/common/src/systable.c | 12 -
source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 1 -
source/dnode/mnode/impl/inc/mndDef.h | 8 -
source/dnode/mnode/impl/inc/mndTrans.h | 4 -
.../dnode/mnode/impl/src/mndCompactDetail.c | 2 -
source/dnode/mnode/impl/src/mndDb.c | 3 -
source/dnode/mnode/impl/src/mndShow.c | 5 +-
source/dnode/mnode/impl/src/mndTrans.c | 484 +-----------------
source/dnode/mnode/impl/src/mndVgroup.c | 16 +-
source/libs/executor/src/sysscanoperator.c | 3 +-
source/libs/nodes/src/nodesCodeFuncs.c | 2 -
source/libs/nodes/src/nodesUtilFuncs.c | 8 -
source/libs/parser/inc/parAst.h | 1 -
source/libs/parser/inc/sql.y | 1 -
source/libs/parser/src/parAstCreater.c | 12 -
source/libs/parser/src/parAstParser.c | 8 -
source/libs/parser/src/parTranslater.c | 51 +-
source/util/src/terror.c | 1 -
.../develop-test/2-query/table_count_scan.py | 16 +-
tests/parallel_test/cases.task | 3 -
tests/script/tsim/query/sys_tbname.sim | 2 +-
tests/script/tsim/query/tableCount.sim | 6 +-
.../0-others/information_schema.py | 6 +-
.../0-others/kill_balance_leader.py | 64 ---
.../0-others/show_transaction_detail.py | 115 -----
tests/system-test/2-query/union.py | 2 +-
.../restore/kill_restore_dnode.py | 90 ----
.../3-enterprise/restore/restoreBasic.py | 28 -
37 files changed, 50 insertions(+), 929 deletions(-)
delete mode 100644 tests/system-test/0-others/kill_balance_leader.py
delete mode 100644 tests/system-test/0-others/show_transaction_detail.py
delete mode 100644 tests/system-test/3-enterprise/restore/kill_restore_dnode.py
diff --git a/docs/en/08-operation/04-maintenance.md b/docs/en/08-operation/04-maintenance.md
index 2f6afbf9df..970ee40d18 100644
--- a/docs/en/08-operation/04-maintenance.md
+++ b/docs/en/08-operation/04-maintenance.md
@@ -17,7 +17,7 @@ TDengine is designed for various writing scenarios, and many of these scenarios
```sql
COMPACT DATABASE db_name [start with 'XXXX'] [end with 'YYYY'];
-SHOW COMPACT [compact_id];
+SHOW COMPACTS [compact_id];
KILL COMPACT compact_id;
```
diff --git a/docs/en/14-reference/03-taos-sql/24-show.md b/docs/en/14-reference/03-taos-sql/24-show.md
index b46fb41fa0..36c20df0b4 100644
--- a/docs/en/14-reference/03-taos-sql/24-show.md
+++ b/docs/en/14-reference/03-taos-sql/24-show.md
@@ -304,10 +304,9 @@ Displays information about all topics in the current database.
```sql
SHOW TRANSACTIONS;
-SHOW TRANSACTION [tranaction_id];
```
-Displays information about one of or all transaction(s) currently being executed in the system (these transactions are only for metadata level, not for regular tables).
+Displays information about transactions currently being executed in the system (these transactions are only for metadata level, not for regular tables).
## SHOW USERS
diff --git a/docs/zh/08-operation/04-maintenance.md b/docs/zh/08-operation/04-maintenance.md
index 429542485d..9ef165179d 100644
--- a/docs/zh/08-operation/04-maintenance.md
+++ b/docs/zh/08-operation/04-maintenance.md
@@ -19,7 +19,7 @@ TDengine 面向多种写入场景,而很多写入场景下,TDengine 的存
```SQL
COMPACT DATABASE db_name [start with 'XXXX'] [end with 'YYYY'];
COMPACT [db_name.]VGROUPS IN (vgroup_id1, vgroup_id2, ...) [start with 'XXXX'] [end with 'YYYY'];
-SHOW COMPACT [compact_id];
+SHOW COMPACTS [compact_id];
KILL COMPACT compact_id;
```
diff --git a/docs/zh/14-reference/03-taos-sql/24-show.md b/docs/zh/14-reference/03-taos-sql/24-show.md
index 3898920e65..4596a03281 100644
--- a/docs/zh/14-reference/03-taos-sql/24-show.md
+++ b/docs/zh/14-reference/03-taos-sql/24-show.md
@@ -306,10 +306,9 @@ SHOW TOPICS;
```sql
SHOW TRANSACTIONS;
-SHOW TRANSACTION [tranaction_id];
```
-显示当前系统中正在执行的所有或者某一个事务的信息(该事务仅针对除普通表以外的元数据级别)
+显示当前系统中正在执行的事务的信息(该事务仅针对除普通表以外的元数据级别)
## SHOW USERS
diff --git a/include/common/systable.h b/include/common/systable.h
index fe867c9ad0..bd8ba76f4f 100644
--- a/include/common/systable.h
+++ b/include/common/systable.h
@@ -63,7 +63,6 @@ extern "C" {
#define TSDB_INS_TABLE_TSMAS "ins_tsmas"
#define TSDB_INS_DISK_USAGE "ins_disk_usage"
#define TSDB_INS_TABLE_FILESETS "ins_filesets"
-#define TSDB_INS_TABLE_TRANSACTION_DETAILS "ins_transaction_details"
#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
#define TSDB_PERFS_TABLE_SMAS "perf_smas"
diff --git a/include/common/tmsg.h b/include/common/tmsg.h
index 9488e54615..0b6a8b3f1b 100644
--- a/include/common/tmsg.h
+++ b/include/common/tmsg.h
@@ -163,7 +163,6 @@ typedef enum _mgmt_table {
TSDB_MGMT_TABLE_ANODE_FULL,
TSDB_MGMT_TABLE_USAGE,
TSDB_MGMT_TABLE_FILESETS,
- TSDB_MGMT_TABLE_TRANSACTION_DETAIL,
TSDB_MGMT_TABLE_MAX,
} EShowType;
@@ -406,7 +405,6 @@ typedef enum ENodeType {
QUERY_NODE_SHOW_CREATE_TSMA_STMT,
QUERY_NODE_DROP_TSMA_STMT,
QUERY_NODE_SHOW_FILESETS_STMT,
- QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
// logic plan node
QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h
index 0f736e7068..8eb30b8184 100644
--- a/include/libs/nodes/cmdnodes.h
+++ b/include/libs/nodes/cmdnodes.h
@@ -439,11 +439,6 @@ typedef struct SShowCompactDetailsStmt {
SNode* pCompactId;
} SShowCompactDetailsStmt;
-typedef struct SShowTransactionDetailsStmt {
- ENodeType type;
- SNode* pTransactionId;
-} SShowTransactionDetailsStmt;
-
typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT, INDEX_TYPE_NORMAL } EIndexType;
typedef struct SIndexOptions {
diff --git a/include/util/taoserror.h b/include/util/taoserror.h
index 890758762a..e317fdd65a 100644
--- a/include/util/taoserror.h
+++ b/include/util/taoserror.h
@@ -411,7 +411,6 @@ int32_t taosGetErrSize();
#define TSDB_CODE_MND_TRANS_CTX_SWITCH TAOS_DEF_ERROR_CODE(0, 0x03D8)
#define TSDB_CODE_MND_TRANS_CONFLICT_COMPACT TAOS_DEF_ERROR_CODE(0, 0x03D9)
#define TSDB_CODE_MND_TRANS_UNKNOW_ERROR TAOS_DEF_ERROR_CODE(0, 0x03DF)
-#define TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED TAOS_DEF_ERROR_CODE(0, 0x03D2)
// mnode-mq
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E0)
diff --git a/include/util/tdef.h b/include/util/tdef.h
index 2b0aa00b1a..2ee84b42bd 100644
--- a/include/util/tdef.h
+++ b/include/util/tdef.h
@@ -329,11 +329,7 @@ typedef enum ELogicConditionType {
#define TSDB_TRANS_STAGE_LEN 12
#define TSDB_TRANS_TYPE_LEN 16
-#define TSDB_TRANS_ERROR_LEN 512
-#define TSDB_TRANS_OBJTYPE_LEN 40
-#define TSDB_TRANS_RESULT_LEN 100
-#define TSDB_TRANS_TARGET_LEN 300
-#define TSDB_TRANS_DETAIL_LEN 100
+#define TSDB_TRANS_ERROR_LEN 512
#define TSDB_STEP_NAME_LEN 32
#define TSDB_STEP_DESC_LEN 128
diff --git a/source/common/src/systable.c b/source/common/src/systable.c
index 38dce105bb..cb08046399 100644
--- a/source/common/src/systable.c
+++ b/source/common/src/systable.c
@@ -314,8 +314,6 @@ static const SSysDbTableSchema transSchema[] = {
{.name = "oper", .bytes = TSDB_TRANS_OPER_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "stable", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
- {.name = "killable", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
- //{.name = "kill_mnode", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "failed_times", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
{.name = "last_exec_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
{.name = "last_action_info", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
@@ -405,15 +403,6 @@ static const SSysDbTableSchema userCompactsDetailSchema[] = {
{.name = "remain_time(s)", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = false},
};
-static const SSysDbTableSchema userTransactionDetailSchema[] = {
- {.name = "transaction_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
- {.name = "action", .bytes = 30 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
- {.name = "obj_type", .bytes = TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
- {.name = "result", .bytes = TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
- {.name = "target", .bytes = TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
- {.name = "detail", .bytes = TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
-};
-
static const SSysDbTableSchema anodesSchema[] = {
{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
{.name = "url", .bytes = TSDB_ANALYTIC_ANODE_URL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
@@ -532,7 +521,6 @@ static const SSysTableMeta infosMeta[] = {
{TSDB_INS_TABLE_ANODES_FULL, anodesFullSchema, tListLen(anodesFullSchema), true},
{TSDB_INS_DISK_USAGE, diskUsageSchema, tListLen(diskUsageSchema), false},
{TSDB_INS_TABLE_FILESETS, filesetsFullSchema, tListLen(filesetsFullSchema), false},
- {TSDB_INS_TABLE_TRANSACTION_DETAILS, userTransactionDetailSchema, tListLen(userTransactionDetailSchema), false},
};
static const SSysDbTableSchema connectionsSchema[] = {
diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
index 423268a8cc..9ed4ee83c4 100644
--- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
+++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
@@ -681,7 +681,6 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
return TSDB_CODE_INVALID_MSG;
}
- dInfo("retrieve table:%s, user:%s, compactId:%" PRId64, retrieveReq.tb, retrieveReq.user, retrieveReq.compactId);
#if 0
if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
code = TSDB_CODE_MND_NO_RIGHTS;
diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h
index b32274e0a7..e3d2ad6d34 100644
--- a/source/dnode/mnode/impl/inc/mndDef.h
+++ b/source/dnode/mnode/impl/inc/mndDef.h
@@ -133,12 +133,6 @@ typedef enum {
TRN_EXEC_SERIAL = 1,
} ETrnExec;
-typedef enum {
- TRN_KILL_MODE_SKIP = 0,
- TRN_KILL_MODE_INTERUPT = 1,
- //TRN_KILL_MODE_ROLLBACK = 2,
-} ETrnKillMode;
-
typedef enum {
DND_REASON_ONLINE = 0,
DND_REASON_STATUS_MSG_TIMEOUT,
@@ -207,8 +201,6 @@ typedef struct {
SRWLatch lockRpcArray;
int64_t mTraceId;
TdThreadMutex mutex;
- bool ableToBeKilled;
- ETrnKillMode killMode;
} STrans;
typedef struct {
diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h
index 05280d0d68..7f039bc21f 100644
--- a/source/dnode/mnode/impl/inc/mndTrans.h
+++ b/source/dnode/mnode/impl/inc/mndTrans.h
@@ -54,8 +54,6 @@ typedef struct {
SSdbRaw *pRaw;
int64_t mTraceId;
- int64_t startTime;
- int64_t endTime;
} STransAction;
typedef void (*TransCbFp)(SMnode *pMnode, void *param, int32_t paramLen);
@@ -82,8 +80,6 @@ void mndTransSetCb(STrans *pTrans, ETrnFunc startFunc, ETrnFunc stopFunc, voi
void mndTransSetDbName(STrans *pTrans, const char *dbname, const char *stbname);
void mndTransAddArbGroupId(STrans *pTrans, int32_t groupId);
void mndTransSetSerial(STrans *pTrans);
-void mndTransSetBeKilled(STrans *pTrans, bool ableToBeKilled);
-void mndTransSetKillMode(STrans *pTrans, ETrnKillMode killMode);
void mndTransSetParallel(STrans *pTrans);
void mndTransSetChangeless(STrans *pTrans);
void mndTransSetOper(STrans *pTrans, EOperType oper);
diff --git a/source/dnode/mnode/impl/src/mndCompactDetail.c b/source/dnode/mnode/impl/src/mndCompactDetail.c
index 0052f5de56..9a053066b2 100644
--- a/source/dnode/mnode/impl/src/mndCompactDetail.c
+++ b/source/dnode/mnode/impl/src/mndCompactDetail.c
@@ -45,8 +45,6 @@ int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
char *sep = NULL;
SDbObj *pDb = NULL;
- mInfo("retrieve compact detail");
-
if (strlen(pShow->db) > 0) {
sep = strchr(pShow->db, '.');
if (sep &&
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index 1efbff9d53..c28fd343f0 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -1270,7 +1270,6 @@ static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *p
TAOS_RETURN(code);
}
mInfo("trans:%d, used to alter db:%s", pTrans->id, pOld->name);
- mInfo("trans:%d, used to alter db, ableToBeKilled:%d, killMode:%d", pTrans->id, pTrans->ableToBeKilled, pTrans->killMode);
mndTransSetDbName(pTrans, pOld->name, NULL);
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
@@ -1279,8 +1278,6 @@ static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *p
TAOS_CHECK_GOTO(mndSetAlterDbPrepareLogs(pMnode, pTrans, pOld, pNew), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterDbCommitLogs(pMnode, pTrans, pOld, pNew), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterDbRedoActions(pMnode, pTrans, pOld, pNew), NULL, _OVER);
-
- mInfo("trans:%d, used to alter db, ableToBeKilled:%d, killMode:%d", pTrans->id, pTrans->ableToBeKilled, pTrans->killMode);
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
code = 0;
diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c
index f19eabd885..49dc62d471 100644
--- a/source/dnode/mnode/impl/src/mndShow.c
+++ b/source/dnode/mnode/impl/src/mndShow.c
@@ -132,8 +132,6 @@ static int32_t convertToRetrieveType(char *name, int32_t len) {
type = TSDB_MGMT_TABLE_COMPACT;
} else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
- } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
- type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
} else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
type = TSDB_MGMT_TABLE_GRANTS_FULL;
} else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
@@ -238,8 +236,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
SRetrieveTableReq retrieveReq = {0};
TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq));
- mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
- retrieveReq.compactId);
+ mDebug("process to retrieve systable req db:%s, tb:%s", retrieveReq.db, retrieveReq.tb);
if (retrieveReq.showId == 0) {
STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c
index 83fad45919..718b7d0df6 100644
--- a/source/dnode/mnode/impl/src/mndTrans.c
+++ b/source/dnode/mnode/impl/src/mndTrans.c
@@ -14,21 +14,19 @@
*/
#define _DEFAULT_SOURCE
-#include "mndTrans.h"
#include "mndDb.h"
#include "mndPrivilege.h"
#include "mndShow.h"
#include "mndStb.h"
#include "mndSubscribe.h"
#include "mndSync.h"
+#include "mndTrans.h"
#include "mndUser.h"
-#include "mndVgroup.h"
-#include "osTime.h"
#define TRANS_VER1_NUMBER 1
#define TRANS_VER2_NUMBER 2
#define TRANS_ARRAY_SIZE 8
-#define TRANS_RESERVE_SIZE 42
+#define TRANS_RESERVE_SIZE 44
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans);
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *OldTrans, STrans *pOld);
@@ -72,7 +70,7 @@ static int32_t mndProcessKillTransReq(SRpcMsg *pReq);
static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter);
-static int32_t mndRetrieveTransDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
+
static int32_t tsMaxTransId = 0;
int32_t mndInitTrans(SMnode *pMnode) {
@@ -91,7 +89,6 @@ int32_t mndInitTrans(SMnode *pMnode) {
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndRetrieveTrans);
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndCancelGetNextTrans);
- mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TRANSACTION_DETAIL, mndRetrieveTransDetail);
return sdbSetTable(pMnode->pSdb, table);
}
@@ -159,7 +156,7 @@ SSdbRaw *mndTransEncode(STrans *pTrans) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_INVALID_MSG;
- int8_t sver = TRANS_VER2_NUMBER;
+ int8_t sver = taosArrayGetSize(pTrans->prepareActions) ? TRANS_VER2_NUMBER : TRANS_VER1_NUMBER;
int32_t rawDataLen = sizeof(STrans) + TRANS_RESERVE_SIZE + pTrans->paramLen;
rawDataLen += mndTransGetActionsSize(pTrans->prepareActions);
@@ -223,11 +220,6 @@ SSdbRaw *mndTransEncode(STrans *pTrans) {
pIter = taosHashIterate(pTrans->arbGroupIds, pIter);
}
- if (sver > TRANS_VER1_NUMBER) {
- SDB_SET_INT8(pRaw, dataPos, pTrans->ableToBeKilled, _OVER)
- SDB_SET_INT32(pRaw, dataPos, pTrans->killMode, _OVER)
- }
-
SDB_SET_RESERVE(pRaw, dataPos, TRANS_RESERVE_SIZE, _OVER)
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
@@ -318,7 +310,7 @@ SSdbRow *mndTransDecode(SSdbRaw *pRaw) {
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
- if (sver > TRANS_VER2_NUMBER) {
+ if (sver != TRANS_VER1_NUMBER && sver != TRANS_VER2_NUMBER) {
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
goto _OVER;
}
@@ -397,13 +389,6 @@ SSdbRow *mndTransDecode(SSdbRaw *pRaw) {
if ((terrno = taosHashPut(pTrans->arbGroupIds, &arbGroupId, sizeof(int32_t), NULL, 0)) != 0) goto _OVER;
}
- int8_t ableKill = 0;
- int8_t killMode = 0;
- SDB_GET_INT8(pRaw, dataPos, &ableKill, _OVER)
- SDB_GET_INT8(pRaw, dataPos, &killMode, _OVER)
- pTrans->ableToBeKilled = ableKill;
- pTrans->killMode = killMode;
-
SDB_GET_RESERVE(pRaw, dataPos, TRANS_RESERVE_SIZE, _OVER)
terrno = 0;
@@ -445,25 +430,12 @@ static const char *mndTransStr(ETrnStage stage) {
}
}
-static const char *mndTransTypeStr(ETrnAct actionType) {
- switch (actionType) {
- case TRANS_ACTION_MSG:
- return "msg";
- case TRANS_ACTION_RAW:
- return "sdb";
- default:
- return "invalid";
- }
-}
-
static void mndSetTransLastAction(STrans *pTrans, STransAction *pAction) {
if (pAction != NULL) {
- if (pAction->errCode != TSDB_CODE_ACTION_IN_PROGRESS) {
- pTrans->lastAction = pAction->id;
- pTrans->lastMsgType = pAction->msgType;
- pTrans->lastEpset = pAction->epSet;
- pTrans->lastErrorNo = pAction->errCode;
- }
+ pTrans->lastAction = pAction->id;
+ pTrans->lastMsgType = pAction->msgType;
+ pTrans->lastEpset = pAction->epSet;
+ pTrans->lastErrorNo = pAction->errCode;
} else {
pTrans->lastAction = 0;
pTrans->lastMsgType = 0;
@@ -664,7 +636,6 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnConflct conflict,
pTrans->policy = policy;
pTrans->conflict = conflict;
pTrans->exec = TRN_EXEC_PARALLEL;
- pTrans->ableToBeKilled = false;
pTrans->createdTime = taosGetTimestampMs();
pTrans->prepareActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
pTrans->redoActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
@@ -833,13 +804,6 @@ void mndTransAddArbGroupId(STrans *pTrans, int32_t groupId) {
void mndTransSetSerial(STrans *pTrans) { pTrans->exec = TRN_EXEC_SERIAL; }
-void mndTransSetBeKilled(STrans *pTrans, bool ableToBeKilled) { pTrans->ableToBeKilled = ableToBeKilled; }
-
-void mndTransSetKillMode(STrans *pTrans, ETrnKillMode killMode) {
- pTrans->ableToBeKilled = true;
- pTrans->killMode = killMode;
-}
-
void mndTransSetParallel(STrans *pTrans) { pTrans->exec = TRN_EXEC_PARALLEL; }
void mndTransSetChangeless(STrans *pTrans) { pTrans->changeless = true; }
@@ -1079,39 +1043,6 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
return TSDB_CODE_INVALID_PARA;
}
- mInfo("trans:%d, action list:", pTrans->id);
- int32_t index = 0;
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->prepareActions); ++i, ++index) {
- STransAction *pAction = taosArrayGet(pTrans->prepareActions, i);
- mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index,
- mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
- }
-
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->redoActions); ++i, ++index) {
- STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
- mInfo("trans:%d, action:%d, %s:%d msgType:%s", pTrans->id, index,
- mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType));;
- }
-
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->commitActions); ++i, ++index) {
- STransAction *pAction = taosArrayGet(pTrans->commitActions, i);
- mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index,
- mndTransStr(pAction->stage), i, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
- }
-
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->undoActions); ++i, ++index) {
- STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
- if(pAction->actionType == TRANS_ACTION_MSG){
- mInfo("trans:%d, action:%d, %s:%d msgType:%s", pTrans->id, index,
- mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType));;
- }
- else{
- mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index,
- mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
- }
- }
-
-
TAOS_CHECK_RETURN(mndTransCheckConflict(pMnode, pTrans));
TAOS_CHECK_RETURN(mndTransCheckParallelActions(pMnode, pTrans));
@@ -1329,10 +1260,7 @@ int32_t mndTransProcessRsp(SRpcMsg *pRsp) {
if (pAction != NULL) {
pAction->msgReceived = 1;
pAction->errCode = pRsp->code;
- pAction->endTime = taosGetTimestampMs();
-
- // pTrans->lastErrorNo = pRsp->code;
- mndSetTransLastAction(pTrans, pAction);
+ pTrans->lastErrorNo = pRsp->code;
mInfo("trans:%d, %s:%d response is received, received code:0x%x(%s), accept:0x%x(%s) retry:0x%x(%s)", transId,
mndTransStr(pAction->stage), action, pRsp->code, tstrerror(pRsp->code), pAction->acceptableCode,
@@ -1446,8 +1374,6 @@ static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransActio
pAction->msgSent = 1;
// pAction->msgReceived = 0;
pAction->errCode = TSDB_CODE_ACTION_IN_PROGRESS;
- pAction->startTime = taosGetTimestampMs();
- pAction->endTime = 0;
mInfo("trans:%d, %s:%d is sent, %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, detail);
mndSetTransLastAction(pTrans, pAction);
@@ -1601,9 +1527,8 @@ static int32_t mndTransExecuteActionsSerial(SMnode *pMnode, STrans *pTrans, SArr
for (int32_t action = pTrans->actionPos; action < numOfActions; ++action) {
STransAction *pAction = taosArrayGet(pActions, action);
- mInfo("trans:%d, current action:%d, stage:%s, actionType(1:msg,2:log):%d, msgSent:%d, msgReceived:%d",
- pTrans->id, pTrans->actionPos, mndTransStr(pAction->stage), pAction->actionType, pAction->msgSent,
- pAction->msgReceived);
+ mInfo("trans:%d, current action:%d, stage:%s, actionType(1:msg,2:log):%d", pTrans->id, pTrans->actionPos,
+ mndTransStr(pAction->stage), pAction->actionType);
code = mndTransExecSingleAction(pMnode, pTrans, pAction, topHalf);
if (code == 0) {
@@ -1999,25 +1924,13 @@ int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) {
TAOS_RETURN(TSDB_CODE_MND_TRANS_INVALID_STAGE);
}
- if(pTrans->ableToBeKilled == false){
- return TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED;
- }
-
- if(pTrans->killMode == TRN_KILL_MODE_SKIP){
- for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
- STransAction *pAction = taosArrayGet(pArray, i);
- mInfo("trans:%d, %s:%d set processed for kill msg received, errCode from %s to success", pTrans->id,
- mndTransStr(pAction->stage), i, tstrerror(pAction->errCode));
- pAction->msgSent = 1;
- pAction->msgReceived = 1;
- pAction->errCode = 0;
- }
- }
- else if(pTrans->killMode == TRN_KILL_MODE_INTERUPT){
- pTrans->stage = TRN_STAGE_PRE_FINISH;
- }
- else{
- return TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED;
+ for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
+ STransAction *pAction = taosArrayGet(pArray, i);
+ mInfo("trans:%d, %s:%d set processed for kill msg received, errCode from %s to success", pTrans->id,
+ mndTransStr(pAction->stage), i, tstrerror(pAction->errCode));
+ pAction->msgSent = 1;
+ pAction->msgReceived = 1;
+ pAction->errCode = 0;
}
mndTransExecute(pMnode, pTrans);
@@ -2089,114 +2002,6 @@ void mndTransPullup(SMnode *pMnode) {
taosArrayDestroy(pArray);
}
-static char *formatTimestamp(char *buf, int64_t val, int precision) {
- time_t tt;
- if (precision == TSDB_TIME_PRECISION_MICRO) {
- tt = (time_t)(val / 1000000);
- }
- if (precision == TSDB_TIME_PRECISION_NANO) {
- tt = (time_t)(val / 1000000000);
- } else {
- tt = (time_t)(val / 1000);
- }
-
- struct tm tm;
- if (taosLocalTime(&tt, &tm, NULL, 0, NULL) == NULL) {
- mError("failed to get local time");
- return NULL;
- }
- size_t pos = taosStrfTime(buf, 32, "%Y-%m-%d %H:%M:%S", &tm);
-
- if (precision == TSDB_TIME_PRECISION_MICRO) {
- sprintf(buf + pos, ".%06d", (int)(val % 1000000));
- } else if (precision == TSDB_TIME_PRECISION_NANO) {
- sprintf(buf + pos, ".%09d", (int)(val % 1000000000));
- } else {
- sprintf(buf + pos, ".%03d", (int)(val % 1000));
- }
-
- return buf;
-}
-
-static void mndTransLogAction(STrans *pTrans) {
- char detail[512] = {0};
- int32_t len = 0;
- int32_t index = 0;
-
- if (pTrans->stage == TRN_STAGE_PREPARE) {
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->prepareActions); ++i, ++index) {
- len = 0;
- STransAction *pAction = taosArrayGet(pTrans->prepareActions, i);
- len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
- mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
- sdbStatusName(pAction->pRaw->status));
- mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
- }
- }
-
- if (pTrans->stage == TRN_STAGE_REDO_ACTION) {
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->redoActions); ++i, ++index) {
- len = 0;
- STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
- if (pAction->actionType == TRANS_ACTION_MSG) {
- char bufStart[40] = {0};
- (void)formatTimestamp(bufStart, pAction->startTime, TSDB_TIME_PRECISION_MILLI);
-
- char endStart[40] = {0};
- (void)formatTimestamp(endStart, pAction->endTime, TSDB_TIME_PRECISION_MILLI);
- len += snprintf(detail + len, sizeof(detail) - len,
- "action:%d, %s:%d msgType:%s,"
- "sent:%d, received:%d, startTime:%s, endTime:%s, ",
- index, mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType), pAction->msgSent,
- pAction->msgReceived, bufStart, endStart);
-
- SEpSet epset = pAction->epSet;
- if (epset.numOfEps > 0) {
- len += snprintf(detail + len, sizeof(detail) - len, "numOfEps:%d inUse:%d ", epset.numOfEps, epset.inUse);
- for (int32_t i = 0; i < epset.numOfEps; ++i) {
- len +=
- snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
- }
- }
-
- len += snprintf(detail + len, sizeof(detail) - len, ", errCode:0x%x(%s)\n", pAction->errCode & 0xFFFF,
- tstrerror(pAction->errCode));
- } else {
- len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s, written:%d\n",
- index, mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
- sdbStatusName(pAction->pRaw->status), pAction->rawWritten);
- }
- mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
- }
- }
-
- if (pTrans->stage == TRN_STAGE_COMMIT_ACTION) {
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->commitActions); ++i, ++index) {
- len = 0;
- STransAction *pAction = taosArrayGet(pTrans->commitActions, i);
- len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
- mndTransStr(pAction->stage), i, sdbTableName(pAction->pRaw->type),
- sdbStatusName(pAction->pRaw->status));
- mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
- }
-
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->undoActions); ++i, ++index) {
- len = 0;
- STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
- if (pAction->actionType == TRANS_ACTION_MSG) {
- len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d msgType:%s\n", index,
- mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType));
- ;
- } else {
- len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
- mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
- sdbStatusName(pAction->pRaw->status));
- }
- mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
- }
- }
-}
-
static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
SMnode *pMnode = pReq->info.node;
SSdb *pSdb = pMnode->pSdb;
@@ -2239,20 +2044,6 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)stbname, false), pTrans, &lino, _OVER);
- const char *killableStr = pTrans->ableToBeKilled ? "yes" : "no";
- char killableVstr[10 + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(killableVstr, killableStr, 10 + VARSTR_HEADER_SIZE);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)killableVstr, false), pTrans, &lino, _OVER);
-
- /*
- const char *killModeStr = pTrans->killMode == TRN_KILL_MODE_SKIP ? "skip" : "interrupt";
- char killModeVstr[10 + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(killModeVstr, killModeStr, 24);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)killModeVstr, false), pTrans, &lino, _OVER);
- */
-
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->failedTimes, false), pTrans, &lino,
_OVER);
@@ -2270,15 +2061,13 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
len += tsnprintf(detail + len, sizeof(detail) - len, "msgType:%s numOfEps:%d inUse:%d ",
TMSG_INFO(pTrans->lastMsgType), epset.numOfEps, epset.inUse);
for (int32_t i = 0; i < pTrans->lastEpset.numOfEps; ++i) {
- len += snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
+ len += tsnprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
}
}
STR_WITH_MAXSIZE_TO_VARSTR(lastInfo, detail, pShow->pMeta->pSchemas[cols].bytes);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)lastInfo, false), pTrans, &lino, _OVER);
- mndTransLogAction(pTrans);
-
numOfRows++;
sdbRelease(pSdb, pTrans);
}
@@ -2289,239 +2078,6 @@ _OVER:
return numOfRows;
}
-static int32_t mndShowTransCommonColumns(SShowObj *pShow, SSDataBlock *pBlock, STransAction *pAction,
- int32_t transactionId, int32_t curActionId, int32_t numOfRows, int32_t *cols) {
- int32_t code = 0;
- int32_t lino = 0;
- int32_t len = 0;
-
- SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, (*cols)++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&transactionId, false), &lino, _OVER);
-
- char action[30 + 1] = {0};
- if (curActionId == pAction->id) {
- len += snprintf(action + len, sizeof(action) - len, "%s:%d(%s)<-last", mndTransStr(pAction->stage), pAction->id,
- mndTransTypeStr(pAction->actionType));
- } else {
- len += snprintf(action + len, sizeof(action) - len, "%s:%d(%s)", mndTransStr(pAction->stage), pAction->id,
- mndTransTypeStr(pAction->actionType));
- }
- char actionVStr[30 + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(actionVStr, action, pShow->pMeta->pSchemas[*cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, (*cols)++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)actionVStr, false), &lino, _OVER);
-_OVER:
- if (code != 0) mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
- return code;
-}
-
-static void mndShowTransAction(SShowObj *pShow, SSDataBlock *pBlock, STransAction *pAction, int32_t transactionId,
- int32_t curActionId, int32_t rows, int32_t numOfRows) {
- int32_t code = 0;
- int32_t lino = 0;
- int32_t len = 0;
- int32_t cols = 0;
-
- cols = 0;
-
- if (mndShowTransCommonColumns(pShow, pBlock, pAction, transactionId, curActionId, numOfRows, &cols) != 0) return;
-
- if (pAction->actionType == TRANS_ACTION_MSG) {
- int32_t len = 0;
-
- char objType[TSDB_TRANS_OBJTYPE_LEN + 1] = {0};
- len += snprintf(objType + len, sizeof(objType) - len, "%s(s:%d,r:%d)", TMSG_INFO(pAction->msgType),
- pAction->msgSent, pAction->msgReceived);
- char objTypeVStr[TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(objTypeVStr, objType, pShow->pMeta->pSchemas[cols].bytes);
- SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)objTypeVStr, false), &lino, _OVER);
-
- char result[TSDB_TRANS_RESULT_LEN + 1] = {0};
- len = 0;
- len += snprintf(result + len, sizeof(result) - len, "errCode:0x%x(%s)", pAction->errCode & 0xFFFF,
- tstrerror(pAction->errCode));
- char resultVStr[TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(resultVStr, result, pShow->pMeta->pSchemas[cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)resultVStr, false), &lino, _OVER);
-
- char target[TSDB_TRANS_TARGET_LEN] = {0};
- len = 0;
- SEpSet epset = pAction->epSet;
- if (epset.numOfEps > 0) {
- for (int32_t i = 0; i < epset.numOfEps; ++i) {
- len += snprintf(target + len, sizeof(target) - len, "ep:%d-%s:%u,", i, epset.eps[i].fqdn, epset.eps[i].port);
- }
- len += snprintf(target + len, sizeof(target) - len, "(%d:%d) ", epset.numOfEps, epset.inUse);
- }
- char targetVStr[TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(targetVStr, target, pShow->pMeta->pSchemas[cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)targetVStr, false), &lino, _OVER);
-
- char detail[TSDB_TRANS_DETAIL_LEN] = {0};
- len = 0;
- char bufStart[40] = {0};
- if (pAction->startTime > 0) (void)formatTimestamp(bufStart, pAction->startTime, TSDB_TIME_PRECISION_MILLI);
- char bufEnd[40] = {0};
- if (pAction->endTime > 0) (void)formatTimestamp(bufEnd, pAction->endTime, TSDB_TIME_PRECISION_MILLI);
- len += snprintf(detail + len, sizeof(detail) - len, "startTime:%s, endTime:%s, ", bufStart, bufEnd);
- char detailVStr[TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(detailVStr, detail, pShow->pMeta->pSchemas[cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)detailVStr, false), &lino, _OVER);
-
- } else {
- int32_t len = 0;
-
- char objType[TSDB_TRANS_OBJTYPE_LEN + 1] = {0};
- if (pAction->pRaw->type == SDB_VGROUP) {
- SSdbRow *pRow = mndVgroupActionDecode(pAction->pRaw);
- SVgObj *pVgroup = sdbGetRowObj(pRow);
- len += snprintf(objType + len, sizeof(objType) - len, "%s(%d)", sdbTableName(pAction->pRaw->type), pVgroup->vgId);
- taosMemoryFreeClear(pRow);
- } else {
- strcpy(objType, sdbTableName(pAction->pRaw->type));
- }
- char objTypeVStr[TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(objTypeVStr, objType, pShow->pMeta->pSchemas[cols].bytes);
- SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)objTypeVStr, false), &lino, _OVER);
-
- char result[TSDB_TRANS_RESULT_LEN + 1] = {0};
- len = 0;
- len += snprintf(result + len, sizeof(result) - len, "rawWritten:%d", pAction->rawWritten);
- char resultVStr[TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(resultVStr, result, pShow->pMeta->pSchemas[cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)resultVStr, false), &lino, _OVER);
-
- char target[TSDB_TRANS_TARGET_LEN] = "";
- char targetVStr[TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(targetVStr, target, pShow->pMeta->pSchemas[cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)targetVStr, false), &lino, _OVER);
-
- char detail[TSDB_TRANS_DETAIL_LEN] = {0};
- len = 0;
- len += snprintf(detail + len, sizeof(detail) - len, "sdbStatus:%s", sdbStatusName(pAction->pRaw->status));
- char detailVStr[TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(detailVStr, detail, pShow->pMeta->pSchemas[cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)detailVStr, false), &lino, _OVER);
- }
-
-_OVER:
- if (code != 0) mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
-}
-
-static SArray *mndTransGetAction(STrans *pTrans, ETrnStage stage) {
- if (stage == TRN_STAGE_PREPARE) {
- return pTrans->prepareActions;
- }
- if (stage == TRN_STAGE_REDO_ACTION) {
- return pTrans->redoActions;
- }
- if (stage == TRN_STAGE_COMMIT_ACTION) {
- return pTrans->commitActions;
- }
- if (stage == TRN_STAGE_UNDO_ACTION) {
- return pTrans->undoActions;
- }
- return NULL;
-}
-
-typedef struct STransDetailIter {
- void *pIter;
- STrans *pTrans;
- ETrnStage stage;
- int32_t num;
-} STransDetailIter;
-
-static void mndTransShowActions(SSdb *pSdb, STransDetailIter *pShowIter, SShowObj *pShow, SSDataBlock *pBlock,
- int32_t rows, int32_t *numOfRows, SArray *pActions, int32_t end, int32_t start) {
- int32_t actionNum = taosArrayGetSize(pActions);
- mInfo("stage:%s, Actions num:%d", mndTransStr(pShowIter->stage), actionNum);
-
- for (int32_t i = start; i < actionNum; ++i) {
- STransAction *pAction = taosArrayGet(pShowIter->pTrans->redoActions, i);
- mndShowTransAction(pShow, pBlock, pAction, pShowIter->pTrans->id, pShowIter->pTrans->lastAction, rows, *numOfRows);
- (*numOfRows)++;
- if (*numOfRows >= rows) break;
- }
-
- if (*numOfRows == end) {
- sdbRelease(pSdb, pShowIter->pTrans);
- pShowIter->pTrans = NULL;
- pShowIter->num = 0;
- } else {
- pShowIter->pTrans = pShowIter->pTrans;
- pShowIter->stage = pShowIter->pTrans->stage;
- pShowIter->num += (*numOfRows);
- }
-}
-
-static int32_t mndRetrieveTransDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
- SMnode *pMnode = pReq->info.node;
- SSdb *pSdb = pMnode->pSdb;
- int32_t numOfRows = 0;
-
- int32_t code = 0;
- int32_t lino = 0;
-
- mInfo("start to mndRetrieveTransDetail, rows:%d, pShow->numOfRows:%d, pShow->pIter:%p", rows, pShow->numOfRows,
- pShow->pIter);
-
- if (pShow->pIter == NULL) {
- pShow->pIter = taosMemoryMalloc(sizeof(STransDetailIter));
- if (pShow->pIter == NULL) {
- mError("failed to malloc for pShow->pIter");
- return 0;
- }
- memset(pShow->pIter, 0, sizeof(STransDetailIter));
- }
-
- STransDetailIter *pShowIter = (STransDetailIter *)pShow->pIter;
-
- while (numOfRows < rows) {
- if (pShowIter->pTrans == NULL) {
- pShowIter->pIter = sdbFetch(pSdb, SDB_TRANS, pShowIter->pIter, (void **)&(pShowIter->pTrans));
- mDebug("retrieve trans detail from fetch, pShow->pIter:%p, pTrans:%p", pShowIter->pIter, pShowIter->pTrans);
- if (pShowIter->pIter == NULL) break;
- mInfo("retrieve trans detail from fetch, id:%d, trans stage:%d, IterNum:%d", pShowIter->pTrans->id,
- pShowIter->pTrans->stage, pShowIter->num);
-
- SArray *pActions = mndTransGetAction(pShowIter->pTrans, pShowIter->pTrans->stage);
-
- mndTransShowActions(pSdb, pShowIter, pShow, pBlock, rows, &numOfRows, pActions, taosArrayGetSize(pActions), 0);
- break;
- } else {
- mInfo("retrieve trans detail from iter, id:%d, iterStage:%d, IterNum:%d", pShowIter->pTrans->id, pShowIter->stage,
- pShowIter->num);
- SArray *pActions = mndTransGetAction(pShowIter->pTrans, pShowIter->stage);
-
- mndTransShowActions(pSdb, pShowIter, pShow, pBlock, rows, &numOfRows, pActions,
- taosArrayGetSize(pActions) - pShowIter->num, pShowIter->num);
- break;
- }
- }
-
-_OVER:
- pShow->numOfRows += numOfRows;
-
- if (code != 0) {
- mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
- } else {
- mInfo("retrieve trans detail, numOfRows:%d, pShow->numOfRows:%d", numOfRows, pShow->numOfRows)
- }
- if (numOfRows == 0) {
- taosMemoryFree(pShow->pIter);
- pShow->pIter = NULL;
- }
- return numOfRows;
-}
-
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter) {
SSdb *pSdb = pMnode->pSdb;
sdbCancelFetchByType(pSdb, pIter, SDB_TRANS);
diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c
index e20afb7201..0bce21290b 100644
--- a/source/dnode/mnode/impl/src/mndVgroup.c
+++ b/source/dnode/mnode/impl/src/mndVgroup.c
@@ -2766,14 +2766,12 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
mndTransSetSerial(pTrans);
- if (pNewDb->cfg.replications == 3) {
+ if (pNewVgroup->replica == 1 && pNewDb->cfg.replications == 3) {
mInfo("db:%s, vgId:%d, will add 2 vnodes, vn:0 dnode:%d", pVgroup->dbName, pVgroup->vgId,
pVgroup->vnodeGid[0].dnodeId);
// add second
- if (pNewVgroup->replica == 1){
- TAOS_CHECK_RETURN(mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
- }
+ TAOS_CHECK_RETURN(mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
// learner stage
pNewVgroup->vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
@@ -2792,9 +2790,7 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
TAOS_CHECK_RETURN(mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup));
// add third
- if (pNewVgroup->replica == 2){
- TAOS_CHECK_RETURN (mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
- }
+ TAOS_CHECK_RETURN(mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
pNewVgroup->vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
pNewVgroup->vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_VOTER;
@@ -2806,7 +2802,7 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
TAOS_CHECK_RETURN(mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, pNewVgroup, &pNewVgroup->vnodeGid[2]));
TAOS_CHECK_RETURN(mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup));
- } else if (pNewDb->cfg.replications == 1) {
+ } else if (pNewVgroup->replica == 3 && pNewDb->cfg.replications == 1) {
mInfo("db:%s, vgId:%d, will remove 2 vnodes, vn:0 dnode:%d vn:1 dnode:%d vn:2 dnode:%d", pVgroup->dbName,
pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId, pVgroup->vnodeGid[1].dnodeId, pVgroup->vnodeGid[2].dnodeId);
@@ -2823,9 +2819,9 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
TAOS_CHECK_RETURN(mndRemoveVnodeFromVgroup(pMnode, pTrans, pNewVgroup, pArray, &del2));
TAOS_CHECK_RETURN(mndAddDropVnodeAction(pMnode, pTrans, pNewDb, pNewVgroup, &del2, true));
TAOS_CHECK_RETURN(
- mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId));
+ mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId));
TAOS_CHECK_RETURN(mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup));
- } else if (pNewDb->cfg.replications == 2) {
+ } else if (pNewVgroup->replica == 1 && pNewDb->cfg.replications == 2) {
mInfo("db:%s, vgId:%d, will add 1 vnode, vn:0 dnode:%d", pVgroup->dbName, pVgroup->vgId,
pVgroup->vnodeGid[0].dnodeId);
diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c
index 7862b36f27..3f08db0e98 100644
--- a/source/libs/executor/src/sysscanoperator.c
+++ b/source/libs/executor/src/sysscanoperator.c
@@ -2543,8 +2543,7 @@ static int32_t doSysTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes)
if (pInfo->showRewrite) {
getDBNameFromCondition(pInfo->pCondition, dbName);
if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, TSDB_TABLE_FNAME_LEN) != 0 &&
- strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, TSDB_TABLE_FNAME_LEN) != 0 &&
- strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, TSDB_TABLE_FNAME_LEN) != 0) {
+ strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, TSDB_TABLE_FNAME_LEN) != 0) {
TAOS_UNUSED(tsnprintf(pInfo->req.db, sizeof(pInfo->req.db), "%d.%s", pInfo->accountId, dbName));
}
} else if (strncasecmp(name, TSDB_INS_TABLE_COLS, TSDB_TABLE_FNAME_LEN) == 0) {
diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c
index c2290b9eac..6d4d89607f 100644
--- a/source/libs/nodes/src/nodesCodeFuncs.c
+++ b/source/libs/nodes/src/nodesCodeFuncs.c
@@ -292,8 +292,6 @@ const char* nodesNodeName(ENodeType type) {
return "ShowCompactsStmt";
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
return "ShowCompactDetailsStmt";
- case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
- return "ShowTransactionDetailsStmt";
case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
return "ShowGrantsFullStmt";
case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c
index 5bfc35aa9c..7beaeaa46c 100644
--- a/source/libs/nodes/src/nodesUtilFuncs.c
+++ b/source/libs/nodes/src/nodesUtilFuncs.c
@@ -714,9 +714,6 @@ int32_t nodesMakeNode(ENodeType type, SNode** ppNodeOut) {
break;
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
code = makeNode(type, sizeof(SShowCompactDetailsStmt), &pNode);
- break;
- case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
- code = makeNode(type, sizeof(SShowTransactionDetailsStmt), &pNode);
break;
case QUERY_NODE_KILL_QUERY_STMT:
code = makeNode(type, sizeof(SKillQueryStmt), &pNode);
@@ -1565,11 +1562,6 @@ void nodesDestroyNode(SNode* pNode) {
nodesDestroyNode(pStmt->pCompactId);
break;
}
- case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT: {
- SShowTransactionDetailsStmt* pStmt = (SShowTransactionDetailsStmt*)pNode;
- nodesDestroyNode(pStmt->pTransactionId);
- break;
- }
case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
taosMemoryFreeClear(((SShowCreateDatabaseStmt*)pNode)->pCfg);
break;
diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h
index 8b2a98baf2..e69a3da4a9 100644
--- a/source/libs/parser/inc/parAst.h
+++ b/source/libs/parser/inc/parAst.h
@@ -320,7 +320,6 @@ SNode* createCreateViewStmt(SAstCreateContext* pCxt, bool orReplace, SNode* pVie
SNode* createDropViewStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pView);
SNode* createShowCompactDetailsStmt(SAstCreateContext* pCxt, SNode* pCompactIdNode);
SNode* createShowCompactsStmt(SAstCreateContext* pCxt, ENodeType type);
-SNode* createShowTransactionDetailsStmt(SAstCreateContext* pCxt, SNode* pTransactionIdNode);
SNode* createCreateTSMAStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* tsmaName, SNode* pOptions,
SNode* pRealTable, SNode* pInterval);
diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y
index 38e93a7ce3..63eb09d509 100644
--- a/source/libs/parser/inc/sql.y
+++ b/source/libs/parser/inc/sql.y
@@ -594,7 +594,6 @@ cmd ::= SHOW BNODES.
cmd ::= SHOW SNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); }
cmd ::= SHOW CLUSTER. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); }
cmd ::= SHOW TRANSACTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); }
-cmd ::= SHOW TRANSACTION NK_INTEGER(A). { pCxt->pRootNode = createShowTransactionDetailsStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &A)); }
cmd ::= SHOW TABLE DISTRIBUTED full_table_name(A). { pCxt->pRootNode = createShowTableDistributedStmt(pCxt, A); }
cmd ::= SHOW CONSUMERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); }
cmd ::= SHOW SUBSCRIPTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); }
diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c
index 5fc5f5fafe..fa656667af 100644
--- a/source/libs/parser/src/parAstCreater.c
+++ b/source/libs/parser/src/parAstCreater.c
@@ -2931,18 +2931,6 @@ _err:
return NULL;
}
-SNode* createShowTransactionDetailsStmt(SAstCreateContext* pCxt, SNode* pTransactionIdNode) {
- CHECK_PARSER_STATUS(pCxt);
- SShowTransactionDetailsStmt* pStmt = NULL;
- pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT, (SNode**)&pStmt);
- CHECK_MAKE_NODE(pStmt);
- pStmt->pTransactionId = pTransactionIdNode;
- return (SNode*)pStmt;
-_err:
- nodesDestroyNode(pTransactionIdNode);
- return NULL;
-}
-
static int32_t getIpV4RangeFromWhitelistItem(char* ipRange, SIpV4Range* pIpRange) {
int32_t code = TSDB_CODE_SUCCESS;
char* ipCopy = taosStrdup(ipRange);
diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c
index e876575f48..1687916cb0 100644
--- a/source/libs/parser/src/parAstParser.c
+++ b/source/libs/parser/src/parAstParser.c
@@ -770,12 +770,6 @@ static int32_t collectMetaKeyFromShowCompactDetails(SCollectMetaKeyCxt* pCxt, SS
return code;
}
-static int32_t collectMetaKeyFromShowTransactionDetails(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
- int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
- TSDB_INS_TABLE_TRANSACTION_DETAILS, pCxt->pMetaCache);
- return code;
-}
-
static int32_t collectMetaKeyFromShowGrantsFull(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_GRANTS_FULL,
pCxt->pMetaCache);
@@ -1100,8 +1094,6 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
return collectMetaKeyFromShowCompacts(pCxt, (SShowStmt*)pStmt);
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
return collectMetaKeyFromShowCompactDetails(pCxt, (SShowStmt*)pStmt);
- case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
- return collectMetaKeyFromShowTransactionDetails(pCxt, (SShowStmt*)pStmt);
case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
return collectMetaKeyFromShowGrantsFull(pCxt, (SShowStmt*)pStmt);
case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index 8f3cbd6f8b..9f411c4296 100755
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -371,40 +371,12 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = {
.pShowCols = {"*"}
},
{
- .showType = QUERY_NODE_CREATE_TSMA_STMT,
- .pDbName = "",
- .pTableName = "",
- .numOfShowCols = 1,
- .pShowCols = {"*"}
- },
- {
- .showType = QUERY_NODE_SHOW_CREATE_TSMA_STMT,
- .pDbName = "",
- .pTableName = "",
- .numOfShowCols = 1,
- .pShowCols = {"*"}
- },
- {
- .showType = QUERY_NODE_DROP_TSMA_STMT,
- .pDbName = "",
- .pTableName = "",
- .numOfShowCols = 1,
- .pShowCols = {"*"}
- },
- {
.showType = QUERY_NODE_SHOW_FILESETS_STMT,
.pDbName = TSDB_INFORMATION_SCHEMA_DB,
.pTableName = TSDB_INS_TABLE_FILESETS,
.numOfShowCols = 1,
.pShowCols = {"*"}
- },
- {
- .showType = QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
- .pDbName = TSDB_INFORMATION_SCHEMA_DB,
- .pTableName = TSDB_INS_TABLE_TRANSACTION_DETAILS,
- .numOfShowCols = 1,
- .pShowCols = {"*"}
- },
+ },
};
// clang-format on
@@ -16387,24 +16359,6 @@ static int32_t rewriteShowCompactDetailsStmt(STranslateContext* pCxt, SQuery* pQ
return code;
}
-static int32_t rewriteShowTransactionDetailsStmt(STranslateContext* pCxt, SQuery* pQuery) {
- SShowTransactionDetailsStmt* pShow = (SShowTransactionDetailsStmt*)(pQuery->pRoot);
- SSelectStmt* pStmt = NULL;
- int32_t code = createSelectStmtForShow(QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT, &pStmt);
- if (TSDB_CODE_SUCCESS == code) {
- if (NULL != pShow->pTransactionId) {
- code = createOperatorNode(OP_TYPE_EQUAL, "transaction_id", pShow->pTransactionId, &pStmt->pWhere);
- }
- }
- if (TSDB_CODE_SUCCESS == code) {
- pCxt->showRewrite = true;
- pQuery->showRewrite = true;
- nodesDestroyNode(pQuery->pRoot);
- pQuery->pRoot = (SNode*)pStmt;
- }
- return code;
-}
-
static int32_t createParWhenThenNode(SNode* pWhen, SNode* pThen, SNode** ppResWhenThen) {
SWhenThenNode* pWThen = NULL;
int32_t code = nodesMakeNode(QUERY_NODE_WHEN_THEN, (SNode**)&pWThen);
@@ -16980,9 +16934,6 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
code = rewriteShowCompactDetailsStmt(pCxt, pQuery);
break;
- case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
- code = rewriteShowTransactionDetailsStmt(pCxt, pQuery);
- break;
case QUERY_NODE_SHOW_DB_ALIVE_STMT:
case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
code = rewriteShowAliveStmt(pCxt, pQuery);
diff --git a/source/util/src/terror.c b/source/util/src/terror.c
index feed297f71..b2a8c422f7 100644
--- a/source/util/src/terror.c
+++ b/source/util/src/terror.c
@@ -326,7 +326,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_SYNC_TIMEOUT, "Sync timeout While ex
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_CTX_SWITCH, "Wrong transaction execution context")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_CONFLICT_COMPACT, "Transaction not completed due to conflict with compact")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_UNKNOW_ERROR, "Unknown transaction error")
-TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED, "The transaction is not able to be killed")
// mnode-mq
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOPIC_ALREADY_EXIST, "Topic already exists")
diff --git a/tests/develop-test/2-query/table_count_scan.py b/tests/develop-test/2-query/table_count_scan.py
index b5c6140481..9725c36bee 100644
--- a/tests/develop-test/2-query/table_count_scan.py
+++ b/tests/develop-test/2-query/table_count_scan.py
@@ -68,7 +68,7 @@ class TDTestCase:
for i in range(0, 3):
db_name = tdSql.getData(i, 1)
if db_name == 'information_schema':
- tdSql.checkData(i, 0, 37)
+ tdSql.checkData(i, 0, 36)
tdSql.checkData(i, 2, None)
elif db_name == 'performance_schema':
tdSql.checkData(i, 0, 5)
@@ -81,7 +81,7 @@ class TDTestCase:
tdSql.query('select count(1) v,db_name, stable_name from information_schema.ins_tables group by db_name, stable_name order by v desc;')
tdSql.checkRows(3)
- tdSql.checkData(0, 0, 37)
+ tdSql.checkData(0, 0, 36)
tdSql.checkData(0, 1, 'information_schema')
tdSql.checkData(0, 2, None)
tdSql.checkData(1, 0, 5)
@@ -97,7 +97,7 @@ class TDTestCase:
tdSql.checkData(1, 1, 'performance_schema')
tdSql.checkData(0, 0, 3)
tdSql.checkData(0, 1, 'tbl_count')
- tdSql.checkData(2, 0, 37)
+ tdSql.checkData(2, 0, 36)
tdSql.checkData(2, 1, 'information_schema')
tdSql.query("select count(*) from information_schema.ins_tables where db_name='tbl_count'")
@@ -110,7 +110,7 @@ class TDTestCase:
tdSql.query('select count(*) from information_schema.ins_tables')
tdSql.checkRows(1)
- tdSql.checkData(0, 0, 45)
+ tdSql.checkData(0, 0, 44)
tdSql.execute('create table stba (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(10), c9 nchar(10), c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned) TAGS(t1 int, t2 binary(10), t3 double);')
@@ -193,7 +193,7 @@ class TDTestCase:
tdSql.checkData(2, 0, 5)
tdSql.checkData(2, 1, 'performance_schema')
tdSql.checkData(2, 2, None)
- tdSql.checkData(3, 0, 37)
+ tdSql.checkData(3, 0, 36)
tdSql.checkData(3, 1, 'information_schema')
tdSql.checkData(3, 2, None)
@@ -208,7 +208,7 @@ class TDTestCase:
tdSql.checkData(2, 0, 5)
tdSql.checkData(2, 1, 'performance_schema')
tdSql.checkData(2, 2, None)
- tdSql.checkData(3, 0, 37)
+ tdSql.checkData(3, 0, 36)
tdSql.checkData(3, 1, 'information_schema')
tdSql.checkData(3, 2, None)
@@ -219,7 +219,7 @@ class TDTestCase:
tdSql.checkData(0, 1, 'tbl_count')
tdSql.checkData(1, 0, 5)
tdSql.checkData(1, 1, 'performance_schema')
- tdSql.checkData(2, 0, 37)
+ tdSql.checkData(2, 0, 36)
tdSql.checkData(2, 1, 'information_schema')
tdSql.query("select count(*) from information_schema.ins_tables where db_name='tbl_count'")
@@ -232,7 +232,7 @@ class TDTestCase:
tdSql.query('select count(*) from information_schema.ins_tables')
tdSql.checkRows(1)
- tdSql.checkData(0, 0, 46)
+ tdSql.checkData(0, 0, 45)
tdSql.execute('drop database tbl_count')
diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task
index 38dd080ef5..ed73a2742c 100644
--- a/tests/parallel_test/cases.task
+++ b/tests/parallel_test/cases.task
@@ -408,9 +408,6 @@
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/test_hot_refresh_configurations.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/subscribe_stream_privilege.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/empty_identifier.py
-,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/show_transaction_detail.py -N 3
-# ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/kill_balance_leader.py -N 3
-# ,,y,system-test,./pytest.sh python3 ./test.py -f 3-enterprise/restore/kill_restore_dnode.py -N 5
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/persisit_config.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/qmemCtrl.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/compact_vgroups.py
diff --git a/tests/script/tsim/query/sys_tbname.sim b/tests/script/tsim/query/sys_tbname.sim
index c6c979e97c..f8c1d6a986 100644
--- a/tests/script/tsim/query/sys_tbname.sim
+++ b/tests/script/tsim/query/sys_tbname.sim
@@ -58,7 +58,7 @@ endi
sql select tbname from information_schema.ins_tables;
print $rows $data00
-if $rows != 46 then
+if $rows != 45 then
return -1
endi
if $data00 != @ins_tables@ then
diff --git a/tests/script/tsim/query/tableCount.sim b/tests/script/tsim/query/tableCount.sim
index 19568b42b6..49e9126361 100644
--- a/tests/script/tsim/query/tableCount.sim
+++ b/tests/script/tsim/query/tableCount.sim
@@ -53,7 +53,7 @@ sql select stable_name,count(table_name) from information_schema.ins_tables grou
if $rows != 3 then
return -1
endi
-if $data01 != 43 then
+if $data01 != 42 then
return -1
endi
if $data11 != 10 then
@@ -72,7 +72,7 @@ endi
if $data11 != 5 then
return -1
endi
-if $data21 != 37 then
+if $data21 != 36 then
return -1
endi
if $data31 != 5 then
@@ -97,7 +97,7 @@ endi
if $data42 != 3 then
return -1
endi
-if $data52 != 37 then
+if $data52 != 36 then
return -1
endi
if $data62 != 5 then
diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py
index 8c25b70b76..af0dd6d949 100644
--- a/tests/system-test/0-others/information_schema.py
+++ b/tests/system-test/0-others/information_schema.py
@@ -61,7 +61,7 @@ class TDTestCase:
self.ins_list = ['ins_dnodes','ins_mnodes','ins_qnodes','ins_snodes','ins_cluster','ins_databases','ins_functions',\
'ins_indexes','ins_stables','ins_tables','ins_tags','ins_columns','ins_users','ins_grants','ins_vgroups','ins_configs','ins_dnode_variables',\
'ins_topics','ins_subscriptions','ins_streams','ins_stream_tasks','ins_vnodes','ins_user_privileges','ins_views',
- 'ins_compacts', 'ins_compact_details', 'ins_grants_full','ins_grants_logs', 'ins_machines', 'ins_arbgroups', 'ins_tsmas', "ins_encryptions", "ins_anodes", "ins_anodes_full", "ins_disk_usagea", "ins_filesets", "ins_transaction_details"]
+ 'ins_compacts', 'ins_compact_details', 'ins_grants_full','ins_grants_logs', 'ins_machines', 'ins_arbgroups', 'ins_tsmas', "ins_encryptions", "ins_anodes", "ins_anodes_full", "ins_disk_usagea", "ins_filesets"]
self.perf_list = ['perf_connections','perf_queries','perf_consumers','perf_trans','perf_apps']
def insert_data(self,column_dict,tbname,row_num):
insert_sql = self.setsql.set_insertsql(column_dict,tbname,self.binary_str,self.nchar_str)
@@ -222,10 +222,10 @@ class TDTestCase:
tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'")
tdLog.info(len(tdSql.queryResult))
- tdSql.checkEqual(True, len(tdSql.queryResult) in range(309, 310))
+ tdSql.checkEqual(True, len(tdSql.queryResult) in range(303, 304))
tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'")
- tdSql.checkEqual(61, len(tdSql.queryResult))
+ tdSql.checkEqual(60, len(tdSql.queryResult))
def ins_dnodes_check(self):
tdSql.execute('drop database if exists db2')
diff --git a/tests/system-test/0-others/kill_balance_leader.py b/tests/system-test/0-others/kill_balance_leader.py
deleted file mode 100644
index be86336661..0000000000
--- a/tests/system-test/0-others/kill_balance_leader.py
+++ /dev/null
@@ -1,64 +0,0 @@
-###################################################################
-# Copyright (c) 2016 by TAOS Technologies, Inc.
-# All rights reserved.
-#
-# This file is proprietary and confidential to TAOS Technologies.
-# No part of this file may be reproduced, stored, transmitted,
-# disclosed or used in any form or by any means other than as
-# expressly provided by the written permission from Jianhui Tao
-#
-###################################################################
-
-# -*- coding: utf-8 -*-
-from util.log import *
-from util.cases import *
-from util.dnodes import *
-from util.sql import *
-
-
-
-class TDTestCase:
- def init(self, conn, logSql, replicaVar=1):
- tdLog.debug(f"start to init {__file__}")
- self.replicaVar = int(replicaVar)
- tdSql.init(conn.cursor(), logSql)
-
- def stop(self):
- tdSql.close()
- tdLog.success(f"{__file__} successfully executed")
-
- def run(self):
- tdLog.debug(f"start to excute {__file__}")
-
- tdSql.execute('CREATE DATABASE db vgroups 160 replica 3;')
-
- tdSql.execute('balance vgroup leader')
-
- sql ="show transactions;"
- rows = tdSql.query(sql)
-
- if rows > 0:
- tranId = tdSql.getData(0, 0)
- tdLog.info('kill transaction %d'%tranId)
- tdSql.execute('kill transaction %d'%tranId, queryTimes=1 )
-
- if self.waitTransactionZero() is False:
- tdLog.exit(f"{sql} transaction not finished")
- return False
-
- def waitTransactionZero(self, seconds = 300, interval = 1):
- # wait end
- for i in range(seconds):
- sql ="show transactions;"
- rows = tdSql.query(sql)
- if rows == 0:
- tdLog.info("transaction count became zero.")
- return True
- #tdLog.info(f"i={i} wait ...")
- time.sleep(interval)
-
- return False
-
-
-tdCases.addLinux(__file__, TDTestCase())
-tdCases.addWindows(__file__, TDTestCase())
\ No newline at end of file
diff --git a/tests/system-test/0-others/show_transaction_detail.py b/tests/system-test/0-others/show_transaction_detail.py
deleted file mode 100644
index ba588f8f01..0000000000
--- a/tests/system-test/0-others/show_transaction_detail.py
+++ /dev/null
@@ -1,115 +0,0 @@
-###################################################################
-# Copyright (c) 2016 by TAOS Technologies, Inc.
-# All rights reserved.
-#
-# This file is proprietary and confidential to TAOS Technologies.
-# No part of this file may be reproduced, stored, transmitted,
-# disclosed or used in any form or by any means other than as
-# expressly provided by the written permission from Jianhui Tao
-#
-###################################################################
-
-# -*- coding: utf-8 -*-
-from util.log import *
-from util.cases import *
-from util.dnodes import *
-from util.sql import *
-from util.cluster import *
-import threading
-
-class TDTestCase:
- def init(self, conn, logSql, replicaVar=1):
- tdLog.debug(f"start to init {__file__}")
- self.replicaVar = int(replicaVar)
- tdSql.init(conn.cursor(), logSql)
- self.dnodes = cluster.dnodes
-
- def stop(self):
- tdSql.close()
- tdLog.success(f"{__file__} successfully executed")
-
- def run(self):
- tdLog.debug(f"start to excute {__file__}")
-
- tdLog.info("CREATE DATABASE db1 vgroups 16 replica 1;")
- tdSql.execute('CREATE DATABASE db1 vgroups 16 replica 1;')
-
- if self.waitTransactionZero() is False:
- tdLog.exit(f"{sql} transaction not finished")
- return False
-
- newTdSql1=tdCom.newTdSql()
- t1 = threading.Thread(target=self.alterDbThread, args=('', newTdSql1))
-
- newTdSql2=tdCom.newTdSql()
- t2 = threading.Thread(target=self.createDbThread, args=('', newTdSql2))
-
- t1.start()
- t2.start()
-
- #time.sleep(1)
-
- dnode = self.dnodes[2]
-
- # stop dnode
- tdLog.info(f"stop dnode 2")
- dnode.stoptaosd()
-
- tdLog.info(f"show transactions;")
- rows = tdSql.query("show transactions;", queryTimes=1)
- tdLog.info(f"rows={rows}")
- if rows > 0:
- tranId1 = tdSql.getData(0, 0)
- oper1 = tdSql.getData(0, 3)
- tdLog.info(f"show transaction {tranId1}, {oper1}")
-
- #tranId2 = tdSql.getData(1, 0)
- #oper2 = tdSql.getData(1, 3)
- #tdLog.info(f"show transaction {tranId2}, {oper2}")
-
- rows = tdSql.query(f"show transaction {tranId1}", queryTimes=1)
- if rows != 120 and rows != 176:
- tdLog.exit(f"show transaction detial error, rows={rows}")
- return False
-
- #rows = tdSql.query(f"show transaction {tranId2}", queryTimes=1)
- #if rows != 176 and rows != 120:
- # tdLog.exit(f"show transaction detial error, rows={rows}")
- # return False
-
- tdLog.info(f"select * from ins_transaction_details")
- rows = tdSql.query(f"select * from information_schema.ins_transaction_details", queryTimes=1)
-
- #if rows != 296:
- if rows != 176:
- tdLog.exit(f"show transaction detial error, rows={rows}")
- return False
-
- dnode.starttaosd()
-
- t1.join()
- t2.join()
-
- def createDbThread(self, sql, newTdSql):
- tdLog.info("CREATE DATABASE db2 vgroups 40 replica 3;")
- newTdSql.execute('CREATE DATABASE db2 vgroups 40 replica 3;', queryTimes=1)
-
- def alterDbThread(self, sql, newTdSql):
- tdLog.info("alter DATABASE db1 replica 3;")
- newTdSql.execute('alter DATABASE db1 replica 3;', queryTimes=1)
-
- def waitTransactionZero(self, seconds = 300, interval = 1):
- # wait end
- for i in range(seconds):
- sql ="show transactions;"
- rows = tdSql.query(sql)
- if rows == 0:
- tdLog.info("transaction count became zero.")
- return True
- #tdLog.info(f"i={i} wait ...")
- time.sleep(interval)
-
- return False
-
-tdCases.addLinux(__file__, TDTestCase())
-tdCases.addWindows(__file__, TDTestCase())
\ No newline at end of file
diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py
index 1abe2b1a65..380b7879c4 100644
--- a/tests/system-test/2-query/union.py
+++ b/tests/system-test/2-query/union.py
@@ -441,7 +441,7 @@ class TDTestCase:
tdSql.checkRows(2)
sql = "select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, stable_name `TABLE_NAME`, 'TABLE' `TABLE_TYPE`, table_comment `REMARKS` from information_schema.ins_stables union all select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, table_name `TABLE_NAME`, case when `type`='SYSTEM_TABLE' then 'TABLE' when `type`='NORMAL_TABLE' then 'TABLE' when `type`='CHILD_TABLE' then 'TABLE' else 'UNKNOWN' end `TABLE_TYPE`, table_comment `REMARKS` from information_schema.ins_tables union all select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, view_name `TABLE_NAME`, 'VIEW' `TABLE_TYPE`, NULL `REMARKS` from information_schema.ins_views"
tdSql.query(sql, queryTimes=1)
- tdSql.checkRows(50)
+ tdSql.checkRows(49)
sql = "select null union select null"
tdSql.query(sql, queryTimes=1)
diff --git a/tests/system-test/3-enterprise/restore/kill_restore_dnode.py b/tests/system-test/3-enterprise/restore/kill_restore_dnode.py
deleted file mode 100644
index d29a11f159..0000000000
--- a/tests/system-test/3-enterprise/restore/kill_restore_dnode.py
+++ /dev/null
@@ -1,90 +0,0 @@
-###################################################################
-# Copyright (c) 2016 by TAOS Technologies, Inc.
-# All rights reserved.
-#
-# This file is proprietary and confidential to TAOS Technologies.
-# No part of this file may be reproduced, stored, transmitted,
-# disclosed or used in any form or by any means other than as
-# expressly provided by the written permission from Jianhui Tao
-#
-###################################################################
-
-# -*- coding: utf-8 -*-
-
-import sys
-
-from util.log import *
-from util.cases import *
-from util.sql import *
-from util.common import *
-sys.path.append("./3-enterprise/restore")
-from restoreBasic import *
-from util.common import tdCom
-import threading
-
-
-class TDTestCase:
- # init
- def init(self, conn, logSql, replicaVar=1):
- tdLog.debug("start to execute %s" % __file__)
- self.basic = RestoreBasic()
- self.basic.init(conn, logSql, replicaVar)
-
- # run
- def run(self):
- self.basic.restore_dnode_prepare(2)
-
- self.execute()
-
- def execute(self):
- newTdSql=tdCom.newTdSql()
- t0 = threading.Thread(target=self.restoreDnodeThread, args=('', newTdSql))
- t0.start()
-
- time.sleep(2)
- sql ="show transactions;"
- tdLog.info(sql)
- rows = tdSql.query(sql)
-
- if rows > 0:
- self.basic.stop_dnode(2)
-
- tranId = tdSql.getData(0, 0)
-
- tdLog.info('show transaction %d'%tranId)
- rows=tdSql.query('show transaction %d'%tranId, queryTimes=1)
- if rows != 11:
- tdLog.exit(f"restore transaction detial error, rows={rows}")
- return False
-
- tdLog.info('kill transaction %d'%tranId)
- tdSql.execute('kill transaction %d'%tranId, queryTimes=1 )
-
- time.sleep(3)
- sql ="show transactions;"
- tdLog.info(sql)
- rows = tdSql.query(sql)
- if rows > 0:
- tdLog.info(f"{sql} transaction not finished")
- return False
-
- self.basic.restore_dnode_exec(2)
- else:
- tdLog.exit(f"{sql} no transaction exist")
- return False
-
- def restoreDnodeThread(self, p, newTdSql):
- sleep(1)
-
- sql = f"restore dnode 2"
- tdLog.info(sql)
- newTdSql.error(sql, expectErrInfo="Wrong transaction execution context")
- tdLog.info(f"{sql} finished")
-
- # stop
- def stop(self):
- self.basic.stop()
- tdLog.success("%s successfully executed" % __file__)
-
-tdCases.addWindows(__file__, TDTestCase())
-tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
diff --git a/tests/system-test/3-enterprise/restore/restoreBasic.py b/tests/system-test/3-enterprise/restore/restoreBasic.py
index 74cf572018..77fa606b9c 100644
--- a/tests/system-test/3-enterprise/restore/restoreBasic.py
+++ b/tests/system-test/3-enterprise/restore/restoreBasic.py
@@ -143,34 +143,6 @@ class RestoreBasic:
tdSql.execute(sql)
self.check_corrent()
- def restore_dnode_prepare(self, index):
- tdLog.info(f"start restore dnode {index}")
- dnode = self.dnodes[index - 1]
-
- # stop dnode
- tdLog.info(f"stop dnode {index}")
- dnode.stoptaosd()
-
- # remove dnode folder
- try:
- shutil.rmtree(dnode.dataDir)
- tdLog.info(f"delete dir {dnode.dataDir} successful")
- except OSError as x:
- tdLog.exit(f"remove path {dnode.dataDir} error : {x.strerror}")
-
- dnode.starttaosd()
-
- def restore_dnode_exec(self, index):
- # exec restore
- sql = f"restore dnode {index}"
- tdLog.info(sql)
- tdSql.execute(sql)
- self.check_corrent()
-
- def stop_dnode(self, index):
- dnode = self.dnodes[index - 1]
-
- dnode.starttaosd()
# restore vnode
def restore_vnode(self, index):
tdLog.info(f"start restore vnode on dnode {index}")
From c82aef5836492a9160aff40f9ad9067c099036ee Mon Sep 17 00:00:00 2001
From: Shengliang Guan
Date: Fri, 27 Dec 2024 22:27:24 +0800
Subject: [PATCH 32/56] Revert "Revert "Enh:[td 29974]improve trans""
---
docs/en/08-operation/04-maintenance.md | 2 +-
docs/en/14-reference/03-taos-sql/24-show.md | 3 +-
docs/zh/08-operation/04-maintenance.md | 2 +-
docs/zh/14-reference/03-taos-sql/24-show.md | 3 +-
include/common/systable.h | 1 +
include/common/tmsg.h | 2 +
include/libs/nodes/cmdnodes.h | 5 +
include/util/taoserror.h | 1 +
include/util/tdef.h | 6 +-
source/common/src/systable.c | 12 +
source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 1 +
source/dnode/mnode/impl/inc/mndDef.h | 8 +
source/dnode/mnode/impl/inc/mndTrans.h | 4 +
.../dnode/mnode/impl/src/mndCompactDetail.c | 2 +
source/dnode/mnode/impl/src/mndDb.c | 3 +
source/dnode/mnode/impl/src/mndShow.c | 5 +-
source/dnode/mnode/impl/src/mndTrans.c | 484 +++++++++++++++++-
source/dnode/mnode/impl/src/mndVgroup.c | 16 +-
source/libs/executor/src/sysscanoperator.c | 3 +-
source/libs/nodes/src/nodesCodeFuncs.c | 2 +
source/libs/nodes/src/nodesUtilFuncs.c | 8 +
source/libs/parser/inc/parAst.h | 1 +
source/libs/parser/inc/sql.y | 1 +
source/libs/parser/src/parAstCreater.c | 12 +
source/libs/parser/src/parAstParser.c | 8 +
source/libs/parser/src/parTranslater.c | 51 +-
source/util/src/terror.c | 1 +
.../develop-test/2-query/table_count_scan.py | 16 +-
tests/parallel_test/cases.task | 3 +
tests/script/tsim/query/sys_tbname.sim | 2 +-
tests/script/tsim/query/tableCount.sim | 6 +-
.../0-others/information_schema.py | 6 +-
.../0-others/kill_balance_leader.py | 64 +++
.../0-others/show_transaction_detail.py | 115 +++++
tests/system-test/2-query/union.py | 2 +-
.../restore/kill_restore_dnode.py | 90 ++++
.../3-enterprise/restore/restoreBasic.py | 28 +
37 files changed, 929 insertions(+), 50 deletions(-)
create mode 100644 tests/system-test/0-others/kill_balance_leader.py
create mode 100644 tests/system-test/0-others/show_transaction_detail.py
create mode 100644 tests/system-test/3-enterprise/restore/kill_restore_dnode.py
diff --git a/docs/en/08-operation/04-maintenance.md b/docs/en/08-operation/04-maintenance.md
index 970ee40d18..2f6afbf9df 100644
--- a/docs/en/08-operation/04-maintenance.md
+++ b/docs/en/08-operation/04-maintenance.md
@@ -17,7 +17,7 @@ TDengine is designed for various writing scenarios, and many of these scenarios
```sql
COMPACT DATABASE db_name [start with 'XXXX'] [end with 'YYYY'];
-SHOW COMPACTS [compact_id];
+SHOW COMPACT [compact_id];
KILL COMPACT compact_id;
```
diff --git a/docs/en/14-reference/03-taos-sql/24-show.md b/docs/en/14-reference/03-taos-sql/24-show.md
index 36c20df0b4..b46fb41fa0 100644
--- a/docs/en/14-reference/03-taos-sql/24-show.md
+++ b/docs/en/14-reference/03-taos-sql/24-show.md
@@ -304,9 +304,10 @@ Displays information about all topics in the current database.
```sql
SHOW TRANSACTIONS;
+SHOW TRANSACTION [tranaction_id];
```
-Displays information about transactions currently being executed in the system (these transactions are only for metadata level, not for regular tables).
+Displays information about one of or all transaction(s) currently being executed in the system (these transactions are only for metadata level, not for regular tables).
## SHOW USERS
diff --git a/docs/zh/08-operation/04-maintenance.md b/docs/zh/08-operation/04-maintenance.md
index 9ef165179d..429542485d 100644
--- a/docs/zh/08-operation/04-maintenance.md
+++ b/docs/zh/08-operation/04-maintenance.md
@@ -19,7 +19,7 @@ TDengine 面向多种写入场景,而很多写入场景下,TDengine 的存
```SQL
COMPACT DATABASE db_name [start with 'XXXX'] [end with 'YYYY'];
COMPACT [db_name.]VGROUPS IN (vgroup_id1, vgroup_id2, ...) [start with 'XXXX'] [end with 'YYYY'];
-SHOW COMPACTS [compact_id];
+SHOW COMPACT [compact_id];
KILL COMPACT compact_id;
```
diff --git a/docs/zh/14-reference/03-taos-sql/24-show.md b/docs/zh/14-reference/03-taos-sql/24-show.md
index 4596a03281..3898920e65 100644
--- a/docs/zh/14-reference/03-taos-sql/24-show.md
+++ b/docs/zh/14-reference/03-taos-sql/24-show.md
@@ -306,9 +306,10 @@ SHOW TOPICS;
```sql
SHOW TRANSACTIONS;
+SHOW TRANSACTION [tranaction_id];
```
-显示当前系统中正在执行的事务的信息(该事务仅针对除普通表以外的元数据级别)
+显示当前系统中正在执行的所有或者某一个事务的信息(该事务仅针对除普通表以外的元数据级别)
## SHOW USERS
diff --git a/include/common/systable.h b/include/common/systable.h
index bd8ba76f4f..fe867c9ad0 100644
--- a/include/common/systable.h
+++ b/include/common/systable.h
@@ -63,6 +63,7 @@ extern "C" {
#define TSDB_INS_TABLE_TSMAS "ins_tsmas"
#define TSDB_INS_DISK_USAGE "ins_disk_usage"
#define TSDB_INS_TABLE_FILESETS "ins_filesets"
+#define TSDB_INS_TABLE_TRANSACTION_DETAILS "ins_transaction_details"
#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
#define TSDB_PERFS_TABLE_SMAS "perf_smas"
diff --git a/include/common/tmsg.h b/include/common/tmsg.h
index 0b6a8b3f1b..9488e54615 100644
--- a/include/common/tmsg.h
+++ b/include/common/tmsg.h
@@ -163,6 +163,7 @@ typedef enum _mgmt_table {
TSDB_MGMT_TABLE_ANODE_FULL,
TSDB_MGMT_TABLE_USAGE,
TSDB_MGMT_TABLE_FILESETS,
+ TSDB_MGMT_TABLE_TRANSACTION_DETAIL,
TSDB_MGMT_TABLE_MAX,
} EShowType;
@@ -405,6 +406,7 @@ typedef enum ENodeType {
QUERY_NODE_SHOW_CREATE_TSMA_STMT,
QUERY_NODE_DROP_TSMA_STMT,
QUERY_NODE_SHOW_FILESETS_STMT,
+ QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
// logic plan node
QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h
index 8eb30b8184..0f736e7068 100644
--- a/include/libs/nodes/cmdnodes.h
+++ b/include/libs/nodes/cmdnodes.h
@@ -439,6 +439,11 @@ typedef struct SShowCompactDetailsStmt {
SNode* pCompactId;
} SShowCompactDetailsStmt;
+typedef struct SShowTransactionDetailsStmt {
+ ENodeType type;
+ SNode* pTransactionId;
+} SShowTransactionDetailsStmt;
+
typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT, INDEX_TYPE_NORMAL } EIndexType;
typedef struct SIndexOptions {
diff --git a/include/util/taoserror.h b/include/util/taoserror.h
index e317fdd65a..890758762a 100644
--- a/include/util/taoserror.h
+++ b/include/util/taoserror.h
@@ -411,6 +411,7 @@ int32_t taosGetErrSize();
#define TSDB_CODE_MND_TRANS_CTX_SWITCH TAOS_DEF_ERROR_CODE(0, 0x03D8)
#define TSDB_CODE_MND_TRANS_CONFLICT_COMPACT TAOS_DEF_ERROR_CODE(0, 0x03D9)
#define TSDB_CODE_MND_TRANS_UNKNOW_ERROR TAOS_DEF_ERROR_CODE(0, 0x03DF)
+#define TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED TAOS_DEF_ERROR_CODE(0, 0x03D2)
// mnode-mq
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E0)
diff --git a/include/util/tdef.h b/include/util/tdef.h
index 2ee84b42bd..2b0aa00b1a 100644
--- a/include/util/tdef.h
+++ b/include/util/tdef.h
@@ -329,7 +329,11 @@ typedef enum ELogicConditionType {
#define TSDB_TRANS_STAGE_LEN 12
#define TSDB_TRANS_TYPE_LEN 16
-#define TSDB_TRANS_ERROR_LEN 512
+#define TSDB_TRANS_ERROR_LEN 512
+#define TSDB_TRANS_OBJTYPE_LEN 40
+#define TSDB_TRANS_RESULT_LEN 100
+#define TSDB_TRANS_TARGET_LEN 300
+#define TSDB_TRANS_DETAIL_LEN 100
#define TSDB_STEP_NAME_LEN 32
#define TSDB_STEP_DESC_LEN 128
diff --git a/source/common/src/systable.c b/source/common/src/systable.c
index cb08046399..38dce105bb 100644
--- a/source/common/src/systable.c
+++ b/source/common/src/systable.c
@@ -314,6 +314,8 @@ static const SSysDbTableSchema transSchema[] = {
{.name = "oper", .bytes = TSDB_TRANS_OPER_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "stable", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "killable", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ //{.name = "kill_mnode", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "failed_times", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
{.name = "last_exec_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
{.name = "last_action_info", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
@@ -403,6 +405,15 @@ static const SSysDbTableSchema userCompactsDetailSchema[] = {
{.name = "remain_time(s)", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = false},
};
+static const SSysDbTableSchema userTransactionDetailSchema[] = {
+ {.name = "transaction_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
+ {.name = "action", .bytes = 30 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "obj_type", .bytes = TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "result", .bytes = TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "target", .bytes = TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "detail", .bytes = TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+};
+
static const SSysDbTableSchema anodesSchema[] = {
{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
{.name = "url", .bytes = TSDB_ANALYTIC_ANODE_URL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
@@ -521,6 +532,7 @@ static const SSysTableMeta infosMeta[] = {
{TSDB_INS_TABLE_ANODES_FULL, anodesFullSchema, tListLen(anodesFullSchema), true},
{TSDB_INS_DISK_USAGE, diskUsageSchema, tListLen(diskUsageSchema), false},
{TSDB_INS_TABLE_FILESETS, filesetsFullSchema, tListLen(filesetsFullSchema), false},
+ {TSDB_INS_TABLE_TRANSACTION_DETAILS, userTransactionDetailSchema, tListLen(userTransactionDetailSchema), false},
};
static const SSysDbTableSchema connectionsSchema[] = {
diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
index 9ed4ee83c4..423268a8cc 100644
--- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
+++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
@@ -681,6 +681,7 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
return TSDB_CODE_INVALID_MSG;
}
+ dInfo("retrieve table:%s, user:%s, compactId:%" PRId64, retrieveReq.tb, retrieveReq.user, retrieveReq.compactId);
#if 0
if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
code = TSDB_CODE_MND_NO_RIGHTS;
diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h
index e3d2ad6d34..b32274e0a7 100644
--- a/source/dnode/mnode/impl/inc/mndDef.h
+++ b/source/dnode/mnode/impl/inc/mndDef.h
@@ -133,6 +133,12 @@ typedef enum {
TRN_EXEC_SERIAL = 1,
} ETrnExec;
+typedef enum {
+ TRN_KILL_MODE_SKIP = 0,
+ TRN_KILL_MODE_INTERUPT = 1,
+ //TRN_KILL_MODE_ROLLBACK = 2,
+} ETrnKillMode;
+
typedef enum {
DND_REASON_ONLINE = 0,
DND_REASON_STATUS_MSG_TIMEOUT,
@@ -201,6 +207,8 @@ typedef struct {
SRWLatch lockRpcArray;
int64_t mTraceId;
TdThreadMutex mutex;
+ bool ableToBeKilled;
+ ETrnKillMode killMode;
} STrans;
typedef struct {
diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h
index 7f039bc21f..05280d0d68 100644
--- a/source/dnode/mnode/impl/inc/mndTrans.h
+++ b/source/dnode/mnode/impl/inc/mndTrans.h
@@ -54,6 +54,8 @@ typedef struct {
SSdbRaw *pRaw;
int64_t mTraceId;
+ int64_t startTime;
+ int64_t endTime;
} STransAction;
typedef void (*TransCbFp)(SMnode *pMnode, void *param, int32_t paramLen);
@@ -80,6 +82,8 @@ void mndTransSetCb(STrans *pTrans, ETrnFunc startFunc, ETrnFunc stopFunc, voi
void mndTransSetDbName(STrans *pTrans, const char *dbname, const char *stbname);
void mndTransAddArbGroupId(STrans *pTrans, int32_t groupId);
void mndTransSetSerial(STrans *pTrans);
+void mndTransSetBeKilled(STrans *pTrans, bool ableToBeKilled);
+void mndTransSetKillMode(STrans *pTrans, ETrnKillMode killMode);
void mndTransSetParallel(STrans *pTrans);
void mndTransSetChangeless(STrans *pTrans);
void mndTransSetOper(STrans *pTrans, EOperType oper);
diff --git a/source/dnode/mnode/impl/src/mndCompactDetail.c b/source/dnode/mnode/impl/src/mndCompactDetail.c
index 9a053066b2..0052f5de56 100644
--- a/source/dnode/mnode/impl/src/mndCompactDetail.c
+++ b/source/dnode/mnode/impl/src/mndCompactDetail.c
@@ -45,6 +45,8 @@ int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
char *sep = NULL;
SDbObj *pDb = NULL;
+ mInfo("retrieve compact detail");
+
if (strlen(pShow->db) > 0) {
sep = strchr(pShow->db, '.');
if (sep &&
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index c28fd343f0..1efbff9d53 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -1270,6 +1270,7 @@ static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *p
TAOS_RETURN(code);
}
mInfo("trans:%d, used to alter db:%s", pTrans->id, pOld->name);
+ mInfo("trans:%d, used to alter db, ableToBeKilled:%d, killMode:%d", pTrans->id, pTrans->ableToBeKilled, pTrans->killMode);
mndTransSetDbName(pTrans, pOld->name, NULL);
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
@@ -1278,6 +1279,8 @@ static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *p
TAOS_CHECK_GOTO(mndSetAlterDbPrepareLogs(pMnode, pTrans, pOld, pNew), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterDbCommitLogs(pMnode, pTrans, pOld, pNew), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterDbRedoActions(pMnode, pTrans, pOld, pNew), NULL, _OVER);
+
+ mInfo("trans:%d, used to alter db, ableToBeKilled:%d, killMode:%d", pTrans->id, pTrans->ableToBeKilled, pTrans->killMode);
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
code = 0;
diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c
index 49dc62d471..f19eabd885 100644
--- a/source/dnode/mnode/impl/src/mndShow.c
+++ b/source/dnode/mnode/impl/src/mndShow.c
@@ -132,6 +132,8 @@ static int32_t convertToRetrieveType(char *name, int32_t len) {
type = TSDB_MGMT_TABLE_COMPACT;
} else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
+ } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
+ type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
} else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
type = TSDB_MGMT_TABLE_GRANTS_FULL;
} else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
@@ -236,7 +238,8 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
SRetrieveTableReq retrieveReq = {0};
TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq));
- mDebug("process to retrieve systable req db:%s, tb:%s", retrieveReq.db, retrieveReq.tb);
+ mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
+ retrieveReq.compactId);
if (retrieveReq.showId == 0) {
STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c
index 718b7d0df6..83fad45919 100644
--- a/source/dnode/mnode/impl/src/mndTrans.c
+++ b/source/dnode/mnode/impl/src/mndTrans.c
@@ -14,19 +14,21 @@
*/
#define _DEFAULT_SOURCE
+#include "mndTrans.h"
#include "mndDb.h"
#include "mndPrivilege.h"
#include "mndShow.h"
#include "mndStb.h"
#include "mndSubscribe.h"
#include "mndSync.h"
-#include "mndTrans.h"
#include "mndUser.h"
+#include "mndVgroup.h"
+#include "osTime.h"
#define TRANS_VER1_NUMBER 1
#define TRANS_VER2_NUMBER 2
#define TRANS_ARRAY_SIZE 8
-#define TRANS_RESERVE_SIZE 44
+#define TRANS_RESERVE_SIZE 42
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans);
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *OldTrans, STrans *pOld);
@@ -70,7 +72,7 @@ static int32_t mndProcessKillTransReq(SRpcMsg *pReq);
static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter);
-
+static int32_t mndRetrieveTransDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
static int32_t tsMaxTransId = 0;
int32_t mndInitTrans(SMnode *pMnode) {
@@ -89,6 +91,7 @@ int32_t mndInitTrans(SMnode *pMnode) {
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndRetrieveTrans);
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndCancelGetNextTrans);
+ mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TRANSACTION_DETAIL, mndRetrieveTransDetail);
return sdbSetTable(pMnode->pSdb, table);
}
@@ -156,7 +159,7 @@ SSdbRaw *mndTransEncode(STrans *pTrans) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_INVALID_MSG;
- int8_t sver = taosArrayGetSize(pTrans->prepareActions) ? TRANS_VER2_NUMBER : TRANS_VER1_NUMBER;
+ int8_t sver = TRANS_VER2_NUMBER;
int32_t rawDataLen = sizeof(STrans) + TRANS_RESERVE_SIZE + pTrans->paramLen;
rawDataLen += mndTransGetActionsSize(pTrans->prepareActions);
@@ -220,6 +223,11 @@ SSdbRaw *mndTransEncode(STrans *pTrans) {
pIter = taosHashIterate(pTrans->arbGroupIds, pIter);
}
+ if (sver > TRANS_VER1_NUMBER) {
+ SDB_SET_INT8(pRaw, dataPos, pTrans->ableToBeKilled, _OVER)
+ SDB_SET_INT32(pRaw, dataPos, pTrans->killMode, _OVER)
+ }
+
SDB_SET_RESERVE(pRaw, dataPos, TRANS_RESERVE_SIZE, _OVER)
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
@@ -310,7 +318,7 @@ SSdbRow *mndTransDecode(SSdbRaw *pRaw) {
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
- if (sver != TRANS_VER1_NUMBER && sver != TRANS_VER2_NUMBER) {
+ if (sver > TRANS_VER2_NUMBER) {
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
goto _OVER;
}
@@ -389,6 +397,13 @@ SSdbRow *mndTransDecode(SSdbRaw *pRaw) {
if ((terrno = taosHashPut(pTrans->arbGroupIds, &arbGroupId, sizeof(int32_t), NULL, 0)) != 0) goto _OVER;
}
+ int8_t ableKill = 0;
+ int8_t killMode = 0;
+ SDB_GET_INT8(pRaw, dataPos, &ableKill, _OVER)
+ SDB_GET_INT8(pRaw, dataPos, &killMode, _OVER)
+ pTrans->ableToBeKilled = ableKill;
+ pTrans->killMode = killMode;
+
SDB_GET_RESERVE(pRaw, dataPos, TRANS_RESERVE_SIZE, _OVER)
terrno = 0;
@@ -430,12 +445,25 @@ static const char *mndTransStr(ETrnStage stage) {
}
}
+static const char *mndTransTypeStr(ETrnAct actionType) {
+ switch (actionType) {
+ case TRANS_ACTION_MSG:
+ return "msg";
+ case TRANS_ACTION_RAW:
+ return "sdb";
+ default:
+ return "invalid";
+ }
+}
+
static void mndSetTransLastAction(STrans *pTrans, STransAction *pAction) {
if (pAction != NULL) {
- pTrans->lastAction = pAction->id;
- pTrans->lastMsgType = pAction->msgType;
- pTrans->lastEpset = pAction->epSet;
- pTrans->lastErrorNo = pAction->errCode;
+ if (pAction->errCode != TSDB_CODE_ACTION_IN_PROGRESS) {
+ pTrans->lastAction = pAction->id;
+ pTrans->lastMsgType = pAction->msgType;
+ pTrans->lastEpset = pAction->epSet;
+ pTrans->lastErrorNo = pAction->errCode;
+ }
} else {
pTrans->lastAction = 0;
pTrans->lastMsgType = 0;
@@ -636,6 +664,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnConflct conflict,
pTrans->policy = policy;
pTrans->conflict = conflict;
pTrans->exec = TRN_EXEC_PARALLEL;
+ pTrans->ableToBeKilled = false;
pTrans->createdTime = taosGetTimestampMs();
pTrans->prepareActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
pTrans->redoActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
@@ -804,6 +833,13 @@ void mndTransAddArbGroupId(STrans *pTrans, int32_t groupId) {
void mndTransSetSerial(STrans *pTrans) { pTrans->exec = TRN_EXEC_SERIAL; }
+void mndTransSetBeKilled(STrans *pTrans, bool ableToBeKilled) { pTrans->ableToBeKilled = ableToBeKilled; }
+
+void mndTransSetKillMode(STrans *pTrans, ETrnKillMode killMode) {
+ pTrans->ableToBeKilled = true;
+ pTrans->killMode = killMode;
+}
+
void mndTransSetParallel(STrans *pTrans) { pTrans->exec = TRN_EXEC_PARALLEL; }
void mndTransSetChangeless(STrans *pTrans) { pTrans->changeless = true; }
@@ -1043,6 +1079,39 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
return TSDB_CODE_INVALID_PARA;
}
+ mInfo("trans:%d, action list:", pTrans->id);
+ int32_t index = 0;
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->prepareActions); ++i, ++index) {
+ STransAction *pAction = taosArrayGet(pTrans->prepareActions, i);
+ mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index,
+ mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
+ }
+
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->redoActions); ++i, ++index) {
+ STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
+ mInfo("trans:%d, action:%d, %s:%d msgType:%s", pTrans->id, index,
+ mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType));;
+ }
+
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->commitActions); ++i, ++index) {
+ STransAction *pAction = taosArrayGet(pTrans->commitActions, i);
+ mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index,
+ mndTransStr(pAction->stage), i, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
+ }
+
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->undoActions); ++i, ++index) {
+ STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
+ if(pAction->actionType == TRANS_ACTION_MSG){
+ mInfo("trans:%d, action:%d, %s:%d msgType:%s", pTrans->id, index,
+ mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType));;
+ }
+ else{
+ mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index,
+ mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
+ }
+ }
+
+
TAOS_CHECK_RETURN(mndTransCheckConflict(pMnode, pTrans));
TAOS_CHECK_RETURN(mndTransCheckParallelActions(pMnode, pTrans));
@@ -1260,7 +1329,10 @@ int32_t mndTransProcessRsp(SRpcMsg *pRsp) {
if (pAction != NULL) {
pAction->msgReceived = 1;
pAction->errCode = pRsp->code;
- pTrans->lastErrorNo = pRsp->code;
+ pAction->endTime = taosGetTimestampMs();
+
+ // pTrans->lastErrorNo = pRsp->code;
+ mndSetTransLastAction(pTrans, pAction);
mInfo("trans:%d, %s:%d response is received, received code:0x%x(%s), accept:0x%x(%s) retry:0x%x(%s)", transId,
mndTransStr(pAction->stage), action, pRsp->code, tstrerror(pRsp->code), pAction->acceptableCode,
@@ -1374,6 +1446,8 @@ static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransActio
pAction->msgSent = 1;
// pAction->msgReceived = 0;
pAction->errCode = TSDB_CODE_ACTION_IN_PROGRESS;
+ pAction->startTime = taosGetTimestampMs();
+ pAction->endTime = 0;
mInfo("trans:%d, %s:%d is sent, %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, detail);
mndSetTransLastAction(pTrans, pAction);
@@ -1527,8 +1601,9 @@ static int32_t mndTransExecuteActionsSerial(SMnode *pMnode, STrans *pTrans, SArr
for (int32_t action = pTrans->actionPos; action < numOfActions; ++action) {
STransAction *pAction = taosArrayGet(pActions, action);
- mInfo("trans:%d, current action:%d, stage:%s, actionType(1:msg,2:log):%d", pTrans->id, pTrans->actionPos,
- mndTransStr(pAction->stage), pAction->actionType);
+ mInfo("trans:%d, current action:%d, stage:%s, actionType(1:msg,2:log):%d, msgSent:%d, msgReceived:%d",
+ pTrans->id, pTrans->actionPos, mndTransStr(pAction->stage), pAction->actionType, pAction->msgSent,
+ pAction->msgReceived);
code = mndTransExecSingleAction(pMnode, pTrans, pAction, topHalf);
if (code == 0) {
@@ -1924,13 +1999,25 @@ int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) {
TAOS_RETURN(TSDB_CODE_MND_TRANS_INVALID_STAGE);
}
- for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
- STransAction *pAction = taosArrayGet(pArray, i);
- mInfo("trans:%d, %s:%d set processed for kill msg received, errCode from %s to success", pTrans->id,
- mndTransStr(pAction->stage), i, tstrerror(pAction->errCode));
- pAction->msgSent = 1;
- pAction->msgReceived = 1;
- pAction->errCode = 0;
+ if(pTrans->ableToBeKilled == false){
+ return TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED;
+ }
+
+ if(pTrans->killMode == TRN_KILL_MODE_SKIP){
+ for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
+ STransAction *pAction = taosArrayGet(pArray, i);
+ mInfo("trans:%d, %s:%d set processed for kill msg received, errCode from %s to success", pTrans->id,
+ mndTransStr(pAction->stage), i, tstrerror(pAction->errCode));
+ pAction->msgSent = 1;
+ pAction->msgReceived = 1;
+ pAction->errCode = 0;
+ }
+ }
+ else if(pTrans->killMode == TRN_KILL_MODE_INTERUPT){
+ pTrans->stage = TRN_STAGE_PRE_FINISH;
+ }
+ else{
+ return TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED;
}
mndTransExecute(pMnode, pTrans);
@@ -2002,6 +2089,114 @@ void mndTransPullup(SMnode *pMnode) {
taosArrayDestroy(pArray);
}
+static char *formatTimestamp(char *buf, int64_t val, int precision) {
+ time_t tt;
+ if (precision == TSDB_TIME_PRECISION_MICRO) {
+ tt = (time_t)(val / 1000000);
+ }
+ if (precision == TSDB_TIME_PRECISION_NANO) {
+ tt = (time_t)(val / 1000000000);
+ } else {
+ tt = (time_t)(val / 1000);
+ }
+
+ struct tm tm;
+ if (taosLocalTime(&tt, &tm, NULL, 0, NULL) == NULL) {
+ mError("failed to get local time");
+ return NULL;
+ }
+ size_t pos = taosStrfTime(buf, 32, "%Y-%m-%d %H:%M:%S", &tm);
+
+ if (precision == TSDB_TIME_PRECISION_MICRO) {
+ sprintf(buf + pos, ".%06d", (int)(val % 1000000));
+ } else if (precision == TSDB_TIME_PRECISION_NANO) {
+ sprintf(buf + pos, ".%09d", (int)(val % 1000000000));
+ } else {
+ sprintf(buf + pos, ".%03d", (int)(val % 1000));
+ }
+
+ return buf;
+}
+
+static void mndTransLogAction(STrans *pTrans) {
+ char detail[512] = {0};
+ int32_t len = 0;
+ int32_t index = 0;
+
+ if (pTrans->stage == TRN_STAGE_PREPARE) {
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->prepareActions); ++i, ++index) {
+ len = 0;
+ STransAction *pAction = taosArrayGet(pTrans->prepareActions, i);
+ len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
+ mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
+ sdbStatusName(pAction->pRaw->status));
+ mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
+ }
+ }
+
+ if (pTrans->stage == TRN_STAGE_REDO_ACTION) {
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->redoActions); ++i, ++index) {
+ len = 0;
+ STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
+ if (pAction->actionType == TRANS_ACTION_MSG) {
+ char bufStart[40] = {0};
+ (void)formatTimestamp(bufStart, pAction->startTime, TSDB_TIME_PRECISION_MILLI);
+
+ char endStart[40] = {0};
+ (void)formatTimestamp(endStart, pAction->endTime, TSDB_TIME_PRECISION_MILLI);
+ len += snprintf(detail + len, sizeof(detail) - len,
+ "action:%d, %s:%d msgType:%s,"
+ "sent:%d, received:%d, startTime:%s, endTime:%s, ",
+ index, mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType), pAction->msgSent,
+ pAction->msgReceived, bufStart, endStart);
+
+ SEpSet epset = pAction->epSet;
+ if (epset.numOfEps > 0) {
+ len += snprintf(detail + len, sizeof(detail) - len, "numOfEps:%d inUse:%d ", epset.numOfEps, epset.inUse);
+ for (int32_t i = 0; i < epset.numOfEps; ++i) {
+ len +=
+ snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
+ }
+ }
+
+ len += snprintf(detail + len, sizeof(detail) - len, ", errCode:0x%x(%s)\n", pAction->errCode & 0xFFFF,
+ tstrerror(pAction->errCode));
+ } else {
+ len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s, written:%d\n",
+ index, mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
+ sdbStatusName(pAction->pRaw->status), pAction->rawWritten);
+ }
+ mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
+ }
+ }
+
+ if (pTrans->stage == TRN_STAGE_COMMIT_ACTION) {
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->commitActions); ++i, ++index) {
+ len = 0;
+ STransAction *pAction = taosArrayGet(pTrans->commitActions, i);
+ len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
+ mndTransStr(pAction->stage), i, sdbTableName(pAction->pRaw->type),
+ sdbStatusName(pAction->pRaw->status));
+ mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
+ }
+
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->undoActions); ++i, ++index) {
+ len = 0;
+ STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
+ if (pAction->actionType == TRANS_ACTION_MSG) {
+ len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d msgType:%s\n", index,
+ mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType));
+ ;
+ } else {
+ len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
+ mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
+ sdbStatusName(pAction->pRaw->status));
+ }
+ mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
+ }
+ }
+}
+
static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
SMnode *pMnode = pReq->info.node;
SSdb *pSdb = pMnode->pSdb;
@@ -2044,6 +2239,20 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)stbname, false), pTrans, &lino, _OVER);
+ const char *killableStr = pTrans->ableToBeKilled ? "yes" : "no";
+ char killableVstr[10 + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(killableVstr, killableStr, 10 + VARSTR_HEADER_SIZE);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)killableVstr, false), pTrans, &lino, _OVER);
+
+ /*
+ const char *killModeStr = pTrans->killMode == TRN_KILL_MODE_SKIP ? "skip" : "interrupt";
+ char killModeVstr[10 + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(killModeVstr, killModeStr, 24);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)killModeVstr, false), pTrans, &lino, _OVER);
+ */
+
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->failedTimes, false), pTrans, &lino,
_OVER);
@@ -2061,13 +2270,15 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
len += tsnprintf(detail + len, sizeof(detail) - len, "msgType:%s numOfEps:%d inUse:%d ",
TMSG_INFO(pTrans->lastMsgType), epset.numOfEps, epset.inUse);
for (int32_t i = 0; i < pTrans->lastEpset.numOfEps; ++i) {
- len += tsnprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
+ len += snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
}
}
STR_WITH_MAXSIZE_TO_VARSTR(lastInfo, detail, pShow->pMeta->pSchemas[cols].bytes);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)lastInfo, false), pTrans, &lino, _OVER);
+ mndTransLogAction(pTrans);
+
numOfRows++;
sdbRelease(pSdb, pTrans);
}
@@ -2078,6 +2289,239 @@ _OVER:
return numOfRows;
}
+static int32_t mndShowTransCommonColumns(SShowObj *pShow, SSDataBlock *pBlock, STransAction *pAction,
+ int32_t transactionId, int32_t curActionId, int32_t numOfRows, int32_t *cols) {
+ int32_t code = 0;
+ int32_t lino = 0;
+ int32_t len = 0;
+
+ SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, (*cols)++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&transactionId, false), &lino, _OVER);
+
+ char action[30 + 1] = {0};
+ if (curActionId == pAction->id) {
+ len += snprintf(action + len, sizeof(action) - len, "%s:%d(%s)<-last", mndTransStr(pAction->stage), pAction->id,
+ mndTransTypeStr(pAction->actionType));
+ } else {
+ len += snprintf(action + len, sizeof(action) - len, "%s:%d(%s)", mndTransStr(pAction->stage), pAction->id,
+ mndTransTypeStr(pAction->actionType));
+ }
+ char actionVStr[30 + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(actionVStr, action, pShow->pMeta->pSchemas[*cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, (*cols)++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)actionVStr, false), &lino, _OVER);
+_OVER:
+ if (code != 0) mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
+ return code;
+}
+
+static void mndShowTransAction(SShowObj *pShow, SSDataBlock *pBlock, STransAction *pAction, int32_t transactionId,
+ int32_t curActionId, int32_t rows, int32_t numOfRows) {
+ int32_t code = 0;
+ int32_t lino = 0;
+ int32_t len = 0;
+ int32_t cols = 0;
+
+ cols = 0;
+
+ if (mndShowTransCommonColumns(pShow, pBlock, pAction, transactionId, curActionId, numOfRows, &cols) != 0) return;
+
+ if (pAction->actionType == TRANS_ACTION_MSG) {
+ int32_t len = 0;
+
+ char objType[TSDB_TRANS_OBJTYPE_LEN + 1] = {0};
+ len += snprintf(objType + len, sizeof(objType) - len, "%s(s:%d,r:%d)", TMSG_INFO(pAction->msgType),
+ pAction->msgSent, pAction->msgReceived);
+ char objTypeVStr[TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(objTypeVStr, objType, pShow->pMeta->pSchemas[cols].bytes);
+ SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)objTypeVStr, false), &lino, _OVER);
+
+ char result[TSDB_TRANS_RESULT_LEN + 1] = {0};
+ len = 0;
+ len += snprintf(result + len, sizeof(result) - len, "errCode:0x%x(%s)", pAction->errCode & 0xFFFF,
+ tstrerror(pAction->errCode));
+ char resultVStr[TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(resultVStr, result, pShow->pMeta->pSchemas[cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)resultVStr, false), &lino, _OVER);
+
+ char target[TSDB_TRANS_TARGET_LEN] = {0};
+ len = 0;
+ SEpSet epset = pAction->epSet;
+ if (epset.numOfEps > 0) {
+ for (int32_t i = 0; i < epset.numOfEps; ++i) {
+ len += snprintf(target + len, sizeof(target) - len, "ep:%d-%s:%u,", i, epset.eps[i].fqdn, epset.eps[i].port);
+ }
+ len += snprintf(target + len, sizeof(target) - len, "(%d:%d) ", epset.numOfEps, epset.inUse);
+ }
+ char targetVStr[TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(targetVStr, target, pShow->pMeta->pSchemas[cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)targetVStr, false), &lino, _OVER);
+
+ char detail[TSDB_TRANS_DETAIL_LEN] = {0};
+ len = 0;
+ char bufStart[40] = {0};
+ if (pAction->startTime > 0) (void)formatTimestamp(bufStart, pAction->startTime, TSDB_TIME_PRECISION_MILLI);
+ char bufEnd[40] = {0};
+ if (pAction->endTime > 0) (void)formatTimestamp(bufEnd, pAction->endTime, TSDB_TIME_PRECISION_MILLI);
+ len += snprintf(detail + len, sizeof(detail) - len, "startTime:%s, endTime:%s, ", bufStart, bufEnd);
+ char detailVStr[TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(detailVStr, detail, pShow->pMeta->pSchemas[cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)detailVStr, false), &lino, _OVER);
+
+ } else {
+ int32_t len = 0;
+
+ char objType[TSDB_TRANS_OBJTYPE_LEN + 1] = {0};
+ if (pAction->pRaw->type == SDB_VGROUP) {
+ SSdbRow *pRow = mndVgroupActionDecode(pAction->pRaw);
+ SVgObj *pVgroup = sdbGetRowObj(pRow);
+ len += snprintf(objType + len, sizeof(objType) - len, "%s(%d)", sdbTableName(pAction->pRaw->type), pVgroup->vgId);
+ taosMemoryFreeClear(pRow);
+ } else {
+ strcpy(objType, sdbTableName(pAction->pRaw->type));
+ }
+ char objTypeVStr[TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(objTypeVStr, objType, pShow->pMeta->pSchemas[cols].bytes);
+ SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)objTypeVStr, false), &lino, _OVER);
+
+ char result[TSDB_TRANS_RESULT_LEN + 1] = {0};
+ len = 0;
+ len += snprintf(result + len, sizeof(result) - len, "rawWritten:%d", pAction->rawWritten);
+ char resultVStr[TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(resultVStr, result, pShow->pMeta->pSchemas[cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)resultVStr, false), &lino, _OVER);
+
+ char target[TSDB_TRANS_TARGET_LEN] = "";
+ char targetVStr[TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(targetVStr, target, pShow->pMeta->pSchemas[cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)targetVStr, false), &lino, _OVER);
+
+ char detail[TSDB_TRANS_DETAIL_LEN] = {0};
+ len = 0;
+ len += snprintf(detail + len, sizeof(detail) - len, "sdbStatus:%s", sdbStatusName(pAction->pRaw->status));
+ char detailVStr[TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(detailVStr, detail, pShow->pMeta->pSchemas[cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)detailVStr, false), &lino, _OVER);
+ }
+
+_OVER:
+ if (code != 0) mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
+}
+
+static SArray *mndTransGetAction(STrans *pTrans, ETrnStage stage) {
+ if (stage == TRN_STAGE_PREPARE) {
+ return pTrans->prepareActions;
+ }
+ if (stage == TRN_STAGE_REDO_ACTION) {
+ return pTrans->redoActions;
+ }
+ if (stage == TRN_STAGE_COMMIT_ACTION) {
+ return pTrans->commitActions;
+ }
+ if (stage == TRN_STAGE_UNDO_ACTION) {
+ return pTrans->undoActions;
+ }
+ return NULL;
+}
+
+typedef struct STransDetailIter {
+ void *pIter;
+ STrans *pTrans;
+ ETrnStage stage;
+ int32_t num;
+} STransDetailIter;
+
+static void mndTransShowActions(SSdb *pSdb, STransDetailIter *pShowIter, SShowObj *pShow, SSDataBlock *pBlock,
+ int32_t rows, int32_t *numOfRows, SArray *pActions, int32_t end, int32_t start) {
+ int32_t actionNum = taosArrayGetSize(pActions);
+ mInfo("stage:%s, Actions num:%d", mndTransStr(pShowIter->stage), actionNum);
+
+ for (int32_t i = start; i < actionNum; ++i) {
+ STransAction *pAction = taosArrayGet(pShowIter->pTrans->redoActions, i);
+ mndShowTransAction(pShow, pBlock, pAction, pShowIter->pTrans->id, pShowIter->pTrans->lastAction, rows, *numOfRows);
+ (*numOfRows)++;
+ if (*numOfRows >= rows) break;
+ }
+
+ if (*numOfRows == end) {
+ sdbRelease(pSdb, pShowIter->pTrans);
+ pShowIter->pTrans = NULL;
+ pShowIter->num = 0;
+ } else {
+ pShowIter->pTrans = pShowIter->pTrans;
+ pShowIter->stage = pShowIter->pTrans->stage;
+ pShowIter->num += (*numOfRows);
+ }
+}
+
+static int32_t mndRetrieveTransDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
+ SMnode *pMnode = pReq->info.node;
+ SSdb *pSdb = pMnode->pSdb;
+ int32_t numOfRows = 0;
+
+ int32_t code = 0;
+ int32_t lino = 0;
+
+ mInfo("start to mndRetrieveTransDetail, rows:%d, pShow->numOfRows:%d, pShow->pIter:%p", rows, pShow->numOfRows,
+ pShow->pIter);
+
+ if (pShow->pIter == NULL) {
+ pShow->pIter = taosMemoryMalloc(sizeof(STransDetailIter));
+ if (pShow->pIter == NULL) {
+ mError("failed to malloc for pShow->pIter");
+ return 0;
+ }
+ memset(pShow->pIter, 0, sizeof(STransDetailIter));
+ }
+
+ STransDetailIter *pShowIter = (STransDetailIter *)pShow->pIter;
+
+ while (numOfRows < rows) {
+ if (pShowIter->pTrans == NULL) {
+ pShowIter->pIter = sdbFetch(pSdb, SDB_TRANS, pShowIter->pIter, (void **)&(pShowIter->pTrans));
+ mDebug("retrieve trans detail from fetch, pShow->pIter:%p, pTrans:%p", pShowIter->pIter, pShowIter->pTrans);
+ if (pShowIter->pIter == NULL) break;
+ mInfo("retrieve trans detail from fetch, id:%d, trans stage:%d, IterNum:%d", pShowIter->pTrans->id,
+ pShowIter->pTrans->stage, pShowIter->num);
+
+ SArray *pActions = mndTransGetAction(pShowIter->pTrans, pShowIter->pTrans->stage);
+
+ mndTransShowActions(pSdb, pShowIter, pShow, pBlock, rows, &numOfRows, pActions, taosArrayGetSize(pActions), 0);
+ break;
+ } else {
+ mInfo("retrieve trans detail from iter, id:%d, iterStage:%d, IterNum:%d", pShowIter->pTrans->id, pShowIter->stage,
+ pShowIter->num);
+ SArray *pActions = mndTransGetAction(pShowIter->pTrans, pShowIter->stage);
+
+ mndTransShowActions(pSdb, pShowIter, pShow, pBlock, rows, &numOfRows, pActions,
+ taosArrayGetSize(pActions) - pShowIter->num, pShowIter->num);
+ break;
+ }
+ }
+
+_OVER:
+ pShow->numOfRows += numOfRows;
+
+ if (code != 0) {
+ mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
+ } else {
+ mInfo("retrieve trans detail, numOfRows:%d, pShow->numOfRows:%d", numOfRows, pShow->numOfRows)
+ }
+ if (numOfRows == 0) {
+ taosMemoryFree(pShow->pIter);
+ pShow->pIter = NULL;
+ }
+ return numOfRows;
+}
+
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter) {
SSdb *pSdb = pMnode->pSdb;
sdbCancelFetchByType(pSdb, pIter, SDB_TRANS);
diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c
index 0bce21290b..e20afb7201 100644
--- a/source/dnode/mnode/impl/src/mndVgroup.c
+++ b/source/dnode/mnode/impl/src/mndVgroup.c
@@ -2766,12 +2766,14 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
mndTransSetSerial(pTrans);
- if (pNewVgroup->replica == 1 && pNewDb->cfg.replications == 3) {
+ if (pNewDb->cfg.replications == 3) {
mInfo("db:%s, vgId:%d, will add 2 vnodes, vn:0 dnode:%d", pVgroup->dbName, pVgroup->vgId,
pVgroup->vnodeGid[0].dnodeId);
// add second
- TAOS_CHECK_RETURN(mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
+ if (pNewVgroup->replica == 1){
+ TAOS_CHECK_RETURN(mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
+ }
// learner stage
pNewVgroup->vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
@@ -2790,7 +2792,9 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
TAOS_CHECK_RETURN(mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup));
// add third
- TAOS_CHECK_RETURN(mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
+ if (pNewVgroup->replica == 2){
+ TAOS_CHECK_RETURN (mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
+ }
pNewVgroup->vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
pNewVgroup->vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_VOTER;
@@ -2802,7 +2806,7 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
TAOS_CHECK_RETURN(mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, pNewVgroup, &pNewVgroup->vnodeGid[2]));
TAOS_CHECK_RETURN(mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup));
- } else if (pNewVgroup->replica == 3 && pNewDb->cfg.replications == 1) {
+ } else if (pNewDb->cfg.replications == 1) {
mInfo("db:%s, vgId:%d, will remove 2 vnodes, vn:0 dnode:%d vn:1 dnode:%d vn:2 dnode:%d", pVgroup->dbName,
pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId, pVgroup->vnodeGid[1].dnodeId, pVgroup->vnodeGid[2].dnodeId);
@@ -2819,9 +2823,9 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
TAOS_CHECK_RETURN(mndRemoveVnodeFromVgroup(pMnode, pTrans, pNewVgroup, pArray, &del2));
TAOS_CHECK_RETURN(mndAddDropVnodeAction(pMnode, pTrans, pNewDb, pNewVgroup, &del2, true));
TAOS_CHECK_RETURN(
- mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId));
+ mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId));
TAOS_CHECK_RETURN(mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup));
- } else if (pNewVgroup->replica == 1 && pNewDb->cfg.replications == 2) {
+ } else if (pNewDb->cfg.replications == 2) {
mInfo("db:%s, vgId:%d, will add 1 vnode, vn:0 dnode:%d", pVgroup->dbName, pVgroup->vgId,
pVgroup->vnodeGid[0].dnodeId);
diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c
index 3f08db0e98..7862b36f27 100644
--- a/source/libs/executor/src/sysscanoperator.c
+++ b/source/libs/executor/src/sysscanoperator.c
@@ -2543,7 +2543,8 @@ static int32_t doSysTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes)
if (pInfo->showRewrite) {
getDBNameFromCondition(pInfo->pCondition, dbName);
if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, TSDB_TABLE_FNAME_LEN) != 0 &&
- strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, TSDB_TABLE_FNAME_LEN) != 0) {
+ strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, TSDB_TABLE_FNAME_LEN) != 0 &&
+ strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, TSDB_TABLE_FNAME_LEN) != 0) {
TAOS_UNUSED(tsnprintf(pInfo->req.db, sizeof(pInfo->req.db), "%d.%s", pInfo->accountId, dbName));
}
} else if (strncasecmp(name, TSDB_INS_TABLE_COLS, TSDB_TABLE_FNAME_LEN) == 0) {
diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c
index 6d4d89607f..c2290b9eac 100644
--- a/source/libs/nodes/src/nodesCodeFuncs.c
+++ b/source/libs/nodes/src/nodesCodeFuncs.c
@@ -292,6 +292,8 @@ const char* nodesNodeName(ENodeType type) {
return "ShowCompactsStmt";
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
return "ShowCompactDetailsStmt";
+ case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
+ return "ShowTransactionDetailsStmt";
case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
return "ShowGrantsFullStmt";
case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c
index 7beaeaa46c..5bfc35aa9c 100644
--- a/source/libs/nodes/src/nodesUtilFuncs.c
+++ b/source/libs/nodes/src/nodesUtilFuncs.c
@@ -714,6 +714,9 @@ int32_t nodesMakeNode(ENodeType type, SNode** ppNodeOut) {
break;
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
code = makeNode(type, sizeof(SShowCompactDetailsStmt), &pNode);
+ break;
+ case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
+ code = makeNode(type, sizeof(SShowTransactionDetailsStmt), &pNode);
break;
case QUERY_NODE_KILL_QUERY_STMT:
code = makeNode(type, sizeof(SKillQueryStmt), &pNode);
@@ -1562,6 +1565,11 @@ void nodesDestroyNode(SNode* pNode) {
nodesDestroyNode(pStmt->pCompactId);
break;
}
+ case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT: {
+ SShowTransactionDetailsStmt* pStmt = (SShowTransactionDetailsStmt*)pNode;
+ nodesDestroyNode(pStmt->pTransactionId);
+ break;
+ }
case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
taosMemoryFreeClear(((SShowCreateDatabaseStmt*)pNode)->pCfg);
break;
diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h
index e69a3da4a9..8b2a98baf2 100644
--- a/source/libs/parser/inc/parAst.h
+++ b/source/libs/parser/inc/parAst.h
@@ -320,6 +320,7 @@ SNode* createCreateViewStmt(SAstCreateContext* pCxt, bool orReplace, SNode* pVie
SNode* createDropViewStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pView);
SNode* createShowCompactDetailsStmt(SAstCreateContext* pCxt, SNode* pCompactIdNode);
SNode* createShowCompactsStmt(SAstCreateContext* pCxt, ENodeType type);
+SNode* createShowTransactionDetailsStmt(SAstCreateContext* pCxt, SNode* pTransactionIdNode);
SNode* createCreateTSMAStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* tsmaName, SNode* pOptions,
SNode* pRealTable, SNode* pInterval);
diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y
index 63eb09d509..38e93a7ce3 100644
--- a/source/libs/parser/inc/sql.y
+++ b/source/libs/parser/inc/sql.y
@@ -594,6 +594,7 @@ cmd ::= SHOW BNODES.
cmd ::= SHOW SNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); }
cmd ::= SHOW CLUSTER. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); }
cmd ::= SHOW TRANSACTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); }
+cmd ::= SHOW TRANSACTION NK_INTEGER(A). { pCxt->pRootNode = createShowTransactionDetailsStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &A)); }
cmd ::= SHOW TABLE DISTRIBUTED full_table_name(A). { pCxt->pRootNode = createShowTableDistributedStmt(pCxt, A); }
cmd ::= SHOW CONSUMERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); }
cmd ::= SHOW SUBSCRIPTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); }
diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c
index fa656667af..5fc5f5fafe 100644
--- a/source/libs/parser/src/parAstCreater.c
+++ b/source/libs/parser/src/parAstCreater.c
@@ -2931,6 +2931,18 @@ _err:
return NULL;
}
+SNode* createShowTransactionDetailsStmt(SAstCreateContext* pCxt, SNode* pTransactionIdNode) {
+ CHECK_PARSER_STATUS(pCxt);
+ SShowTransactionDetailsStmt* pStmt = NULL;
+ pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT, (SNode**)&pStmt);
+ CHECK_MAKE_NODE(pStmt);
+ pStmt->pTransactionId = pTransactionIdNode;
+ return (SNode*)pStmt;
+_err:
+ nodesDestroyNode(pTransactionIdNode);
+ return NULL;
+}
+
static int32_t getIpV4RangeFromWhitelistItem(char* ipRange, SIpV4Range* pIpRange) {
int32_t code = TSDB_CODE_SUCCESS;
char* ipCopy = taosStrdup(ipRange);
diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c
index 1687916cb0..e876575f48 100644
--- a/source/libs/parser/src/parAstParser.c
+++ b/source/libs/parser/src/parAstParser.c
@@ -770,6 +770,12 @@ static int32_t collectMetaKeyFromShowCompactDetails(SCollectMetaKeyCxt* pCxt, SS
return code;
}
+static int32_t collectMetaKeyFromShowTransactionDetails(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
+ int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
+ TSDB_INS_TABLE_TRANSACTION_DETAILS, pCxt->pMetaCache);
+ return code;
+}
+
static int32_t collectMetaKeyFromShowGrantsFull(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_GRANTS_FULL,
pCxt->pMetaCache);
@@ -1094,6 +1100,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
return collectMetaKeyFromShowCompacts(pCxt, (SShowStmt*)pStmt);
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
return collectMetaKeyFromShowCompactDetails(pCxt, (SShowStmt*)pStmt);
+ case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
+ return collectMetaKeyFromShowTransactionDetails(pCxt, (SShowStmt*)pStmt);
case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
return collectMetaKeyFromShowGrantsFull(pCxt, (SShowStmt*)pStmt);
case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index 9f411c4296..8f3cbd6f8b 100755
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -371,12 +371,40 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = {
.pShowCols = {"*"}
},
{
+ .showType = QUERY_NODE_CREATE_TSMA_STMT,
+ .pDbName = "",
+ .pTableName = "",
+ .numOfShowCols = 1,
+ .pShowCols = {"*"}
+ },
+ {
+ .showType = QUERY_NODE_SHOW_CREATE_TSMA_STMT,
+ .pDbName = "",
+ .pTableName = "",
+ .numOfShowCols = 1,
+ .pShowCols = {"*"}
+ },
+ {
+ .showType = QUERY_NODE_DROP_TSMA_STMT,
+ .pDbName = "",
+ .pTableName = "",
+ .numOfShowCols = 1,
+ .pShowCols = {"*"}
+ },
+ {
.showType = QUERY_NODE_SHOW_FILESETS_STMT,
.pDbName = TSDB_INFORMATION_SCHEMA_DB,
.pTableName = TSDB_INS_TABLE_FILESETS,
.numOfShowCols = 1,
.pShowCols = {"*"}
- },
+ },
+ {
+ .showType = QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
+ .pDbName = TSDB_INFORMATION_SCHEMA_DB,
+ .pTableName = TSDB_INS_TABLE_TRANSACTION_DETAILS,
+ .numOfShowCols = 1,
+ .pShowCols = {"*"}
+ },
};
// clang-format on
@@ -16359,6 +16387,24 @@ static int32_t rewriteShowCompactDetailsStmt(STranslateContext* pCxt, SQuery* pQ
return code;
}
+static int32_t rewriteShowTransactionDetailsStmt(STranslateContext* pCxt, SQuery* pQuery) {
+ SShowTransactionDetailsStmt* pShow = (SShowTransactionDetailsStmt*)(pQuery->pRoot);
+ SSelectStmt* pStmt = NULL;
+ int32_t code = createSelectStmtForShow(QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT, &pStmt);
+ if (TSDB_CODE_SUCCESS == code) {
+ if (NULL != pShow->pTransactionId) {
+ code = createOperatorNode(OP_TYPE_EQUAL, "transaction_id", pShow->pTransactionId, &pStmt->pWhere);
+ }
+ }
+ if (TSDB_CODE_SUCCESS == code) {
+ pCxt->showRewrite = true;
+ pQuery->showRewrite = true;
+ nodesDestroyNode(pQuery->pRoot);
+ pQuery->pRoot = (SNode*)pStmt;
+ }
+ return code;
+}
+
static int32_t createParWhenThenNode(SNode* pWhen, SNode* pThen, SNode** ppResWhenThen) {
SWhenThenNode* pWThen = NULL;
int32_t code = nodesMakeNode(QUERY_NODE_WHEN_THEN, (SNode**)&pWThen);
@@ -16934,6 +16980,9 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
code = rewriteShowCompactDetailsStmt(pCxt, pQuery);
break;
+ case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
+ code = rewriteShowTransactionDetailsStmt(pCxt, pQuery);
+ break;
case QUERY_NODE_SHOW_DB_ALIVE_STMT:
case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
code = rewriteShowAliveStmt(pCxt, pQuery);
diff --git a/source/util/src/terror.c b/source/util/src/terror.c
index b2a8c422f7..feed297f71 100644
--- a/source/util/src/terror.c
+++ b/source/util/src/terror.c
@@ -326,6 +326,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_SYNC_TIMEOUT, "Sync timeout While ex
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_CTX_SWITCH, "Wrong transaction execution context")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_CONFLICT_COMPACT, "Transaction not completed due to conflict with compact")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_UNKNOW_ERROR, "Unknown transaction error")
+TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED, "The transaction is not able to be killed")
// mnode-mq
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOPIC_ALREADY_EXIST, "Topic already exists")
diff --git a/tests/develop-test/2-query/table_count_scan.py b/tests/develop-test/2-query/table_count_scan.py
index 9725c36bee..b5c6140481 100644
--- a/tests/develop-test/2-query/table_count_scan.py
+++ b/tests/develop-test/2-query/table_count_scan.py
@@ -68,7 +68,7 @@ class TDTestCase:
for i in range(0, 3):
db_name = tdSql.getData(i, 1)
if db_name == 'information_schema':
- tdSql.checkData(i, 0, 36)
+ tdSql.checkData(i, 0, 37)
tdSql.checkData(i, 2, None)
elif db_name == 'performance_schema':
tdSql.checkData(i, 0, 5)
@@ -81,7 +81,7 @@ class TDTestCase:
tdSql.query('select count(1) v,db_name, stable_name from information_schema.ins_tables group by db_name, stable_name order by v desc;')
tdSql.checkRows(3)
- tdSql.checkData(0, 0, 36)
+ tdSql.checkData(0, 0, 37)
tdSql.checkData(0, 1, 'information_schema')
tdSql.checkData(0, 2, None)
tdSql.checkData(1, 0, 5)
@@ -97,7 +97,7 @@ class TDTestCase:
tdSql.checkData(1, 1, 'performance_schema')
tdSql.checkData(0, 0, 3)
tdSql.checkData(0, 1, 'tbl_count')
- tdSql.checkData(2, 0, 36)
+ tdSql.checkData(2, 0, 37)
tdSql.checkData(2, 1, 'information_schema')
tdSql.query("select count(*) from information_schema.ins_tables where db_name='tbl_count'")
@@ -110,7 +110,7 @@ class TDTestCase:
tdSql.query('select count(*) from information_schema.ins_tables')
tdSql.checkRows(1)
- tdSql.checkData(0, 0, 44)
+ tdSql.checkData(0, 0, 45)
tdSql.execute('create table stba (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(10), c9 nchar(10), c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned) TAGS(t1 int, t2 binary(10), t3 double);')
@@ -193,7 +193,7 @@ class TDTestCase:
tdSql.checkData(2, 0, 5)
tdSql.checkData(2, 1, 'performance_schema')
tdSql.checkData(2, 2, None)
- tdSql.checkData(3, 0, 36)
+ tdSql.checkData(3, 0, 37)
tdSql.checkData(3, 1, 'information_schema')
tdSql.checkData(3, 2, None)
@@ -208,7 +208,7 @@ class TDTestCase:
tdSql.checkData(2, 0, 5)
tdSql.checkData(2, 1, 'performance_schema')
tdSql.checkData(2, 2, None)
- tdSql.checkData(3, 0, 36)
+ tdSql.checkData(3, 0, 37)
tdSql.checkData(3, 1, 'information_schema')
tdSql.checkData(3, 2, None)
@@ -219,7 +219,7 @@ class TDTestCase:
tdSql.checkData(0, 1, 'tbl_count')
tdSql.checkData(1, 0, 5)
tdSql.checkData(1, 1, 'performance_schema')
- tdSql.checkData(2, 0, 36)
+ tdSql.checkData(2, 0, 37)
tdSql.checkData(2, 1, 'information_schema')
tdSql.query("select count(*) from information_schema.ins_tables where db_name='tbl_count'")
@@ -232,7 +232,7 @@ class TDTestCase:
tdSql.query('select count(*) from information_schema.ins_tables')
tdSql.checkRows(1)
- tdSql.checkData(0, 0, 45)
+ tdSql.checkData(0, 0, 46)
tdSql.execute('drop database tbl_count')
diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task
index ed73a2742c..38dd080ef5 100644
--- a/tests/parallel_test/cases.task
+++ b/tests/parallel_test/cases.task
@@ -408,6 +408,9 @@
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/test_hot_refresh_configurations.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/subscribe_stream_privilege.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/empty_identifier.py
+,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/show_transaction_detail.py -N 3
+# ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/kill_balance_leader.py -N 3
+# ,,y,system-test,./pytest.sh python3 ./test.py -f 3-enterprise/restore/kill_restore_dnode.py -N 5
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/persisit_config.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/qmemCtrl.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/compact_vgroups.py
diff --git a/tests/script/tsim/query/sys_tbname.sim b/tests/script/tsim/query/sys_tbname.sim
index f8c1d6a986..c6c979e97c 100644
--- a/tests/script/tsim/query/sys_tbname.sim
+++ b/tests/script/tsim/query/sys_tbname.sim
@@ -58,7 +58,7 @@ endi
sql select tbname from information_schema.ins_tables;
print $rows $data00
-if $rows != 45 then
+if $rows != 46 then
return -1
endi
if $data00 != @ins_tables@ then
diff --git a/tests/script/tsim/query/tableCount.sim b/tests/script/tsim/query/tableCount.sim
index 49e9126361..19568b42b6 100644
--- a/tests/script/tsim/query/tableCount.sim
+++ b/tests/script/tsim/query/tableCount.sim
@@ -53,7 +53,7 @@ sql select stable_name,count(table_name) from information_schema.ins_tables grou
if $rows != 3 then
return -1
endi
-if $data01 != 42 then
+if $data01 != 43 then
return -1
endi
if $data11 != 10 then
@@ -72,7 +72,7 @@ endi
if $data11 != 5 then
return -1
endi
-if $data21 != 36 then
+if $data21 != 37 then
return -1
endi
if $data31 != 5 then
@@ -97,7 +97,7 @@ endi
if $data42 != 3 then
return -1
endi
-if $data52 != 36 then
+if $data52 != 37 then
return -1
endi
if $data62 != 5 then
diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py
index af0dd6d949..8c25b70b76 100644
--- a/tests/system-test/0-others/information_schema.py
+++ b/tests/system-test/0-others/information_schema.py
@@ -61,7 +61,7 @@ class TDTestCase:
self.ins_list = ['ins_dnodes','ins_mnodes','ins_qnodes','ins_snodes','ins_cluster','ins_databases','ins_functions',\
'ins_indexes','ins_stables','ins_tables','ins_tags','ins_columns','ins_users','ins_grants','ins_vgroups','ins_configs','ins_dnode_variables',\
'ins_topics','ins_subscriptions','ins_streams','ins_stream_tasks','ins_vnodes','ins_user_privileges','ins_views',
- 'ins_compacts', 'ins_compact_details', 'ins_grants_full','ins_grants_logs', 'ins_machines', 'ins_arbgroups', 'ins_tsmas', "ins_encryptions", "ins_anodes", "ins_anodes_full", "ins_disk_usagea", "ins_filesets"]
+ 'ins_compacts', 'ins_compact_details', 'ins_grants_full','ins_grants_logs', 'ins_machines', 'ins_arbgroups', 'ins_tsmas', "ins_encryptions", "ins_anodes", "ins_anodes_full", "ins_disk_usagea", "ins_filesets", "ins_transaction_details"]
self.perf_list = ['perf_connections','perf_queries','perf_consumers','perf_trans','perf_apps']
def insert_data(self,column_dict,tbname,row_num):
insert_sql = self.setsql.set_insertsql(column_dict,tbname,self.binary_str,self.nchar_str)
@@ -222,10 +222,10 @@ class TDTestCase:
tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'")
tdLog.info(len(tdSql.queryResult))
- tdSql.checkEqual(True, len(tdSql.queryResult) in range(303, 304))
+ tdSql.checkEqual(True, len(tdSql.queryResult) in range(309, 310))
tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'")
- tdSql.checkEqual(60, len(tdSql.queryResult))
+ tdSql.checkEqual(61, len(tdSql.queryResult))
def ins_dnodes_check(self):
tdSql.execute('drop database if exists db2')
diff --git a/tests/system-test/0-others/kill_balance_leader.py b/tests/system-test/0-others/kill_balance_leader.py
new file mode 100644
index 0000000000..be86336661
--- /dev/null
+++ b/tests/system-test/0-others/kill_balance_leader.py
@@ -0,0 +1,64 @@
+###################################################################
+# Copyright (c) 2016 by TAOS Technologies, Inc.
+# All rights reserved.
+#
+# This file is proprietary and confidential to TAOS Technologies.
+# No part of this file may be reproduced, stored, transmitted,
+# disclosed or used in any form or by any means other than as
+# expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+from util.log import *
+from util.cases import *
+from util.dnodes import *
+from util.sql import *
+
+
+
+class TDTestCase:
+ def init(self, conn, logSql, replicaVar=1):
+ tdLog.debug(f"start to init {__file__}")
+ self.replicaVar = int(replicaVar)
+ tdSql.init(conn.cursor(), logSql)
+
+ def stop(self):
+ tdSql.close()
+ tdLog.success(f"{__file__} successfully executed")
+
+ def run(self):
+ tdLog.debug(f"start to excute {__file__}")
+
+ tdSql.execute('CREATE DATABASE db vgroups 160 replica 3;')
+
+ tdSql.execute('balance vgroup leader')
+
+ sql ="show transactions;"
+ rows = tdSql.query(sql)
+
+ if rows > 0:
+ tranId = tdSql.getData(0, 0)
+ tdLog.info('kill transaction %d'%tranId)
+ tdSql.execute('kill transaction %d'%tranId, queryTimes=1 )
+
+ if self.waitTransactionZero() is False:
+ tdLog.exit(f"{sql} transaction not finished")
+ return False
+
+ def waitTransactionZero(self, seconds = 300, interval = 1):
+ # wait end
+ for i in range(seconds):
+ sql ="show transactions;"
+ rows = tdSql.query(sql)
+ if rows == 0:
+ tdLog.info("transaction count became zero.")
+ return True
+ #tdLog.info(f"i={i} wait ...")
+ time.sleep(interval)
+
+ return False
+
+
+tdCases.addLinux(__file__, TDTestCase())
+tdCases.addWindows(__file__, TDTestCase())
\ No newline at end of file
diff --git a/tests/system-test/0-others/show_transaction_detail.py b/tests/system-test/0-others/show_transaction_detail.py
new file mode 100644
index 0000000000..ba588f8f01
--- /dev/null
+++ b/tests/system-test/0-others/show_transaction_detail.py
@@ -0,0 +1,115 @@
+###################################################################
+# Copyright (c) 2016 by TAOS Technologies, Inc.
+# All rights reserved.
+#
+# This file is proprietary and confidential to TAOS Technologies.
+# No part of this file may be reproduced, stored, transmitted,
+# disclosed or used in any form or by any means other than as
+# expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+from util.log import *
+from util.cases import *
+from util.dnodes import *
+from util.sql import *
+from util.cluster import *
+import threading
+
+class TDTestCase:
+ def init(self, conn, logSql, replicaVar=1):
+ tdLog.debug(f"start to init {__file__}")
+ self.replicaVar = int(replicaVar)
+ tdSql.init(conn.cursor(), logSql)
+ self.dnodes = cluster.dnodes
+
+ def stop(self):
+ tdSql.close()
+ tdLog.success(f"{__file__} successfully executed")
+
+ def run(self):
+ tdLog.debug(f"start to excute {__file__}")
+
+ tdLog.info("CREATE DATABASE db1 vgroups 16 replica 1;")
+ tdSql.execute('CREATE DATABASE db1 vgroups 16 replica 1;')
+
+ if self.waitTransactionZero() is False:
+ tdLog.exit(f"{sql} transaction not finished")
+ return False
+
+ newTdSql1=tdCom.newTdSql()
+ t1 = threading.Thread(target=self.alterDbThread, args=('', newTdSql1))
+
+ newTdSql2=tdCom.newTdSql()
+ t2 = threading.Thread(target=self.createDbThread, args=('', newTdSql2))
+
+ t1.start()
+ t2.start()
+
+ #time.sleep(1)
+
+ dnode = self.dnodes[2]
+
+ # stop dnode
+ tdLog.info(f"stop dnode 2")
+ dnode.stoptaosd()
+
+ tdLog.info(f"show transactions;")
+ rows = tdSql.query("show transactions;", queryTimes=1)
+ tdLog.info(f"rows={rows}")
+ if rows > 0:
+ tranId1 = tdSql.getData(0, 0)
+ oper1 = tdSql.getData(0, 3)
+ tdLog.info(f"show transaction {tranId1}, {oper1}")
+
+ #tranId2 = tdSql.getData(1, 0)
+ #oper2 = tdSql.getData(1, 3)
+ #tdLog.info(f"show transaction {tranId2}, {oper2}")
+
+ rows = tdSql.query(f"show transaction {tranId1}", queryTimes=1)
+ if rows != 120 and rows != 176:
+ tdLog.exit(f"show transaction detial error, rows={rows}")
+ return False
+
+ #rows = tdSql.query(f"show transaction {tranId2}", queryTimes=1)
+ #if rows != 176 and rows != 120:
+ # tdLog.exit(f"show transaction detial error, rows={rows}")
+ # return False
+
+ tdLog.info(f"select * from ins_transaction_details")
+ rows = tdSql.query(f"select * from information_schema.ins_transaction_details", queryTimes=1)
+
+ #if rows != 296:
+ if rows != 176:
+ tdLog.exit(f"show transaction detial error, rows={rows}")
+ return False
+
+ dnode.starttaosd()
+
+ t1.join()
+ t2.join()
+
+ def createDbThread(self, sql, newTdSql):
+ tdLog.info("CREATE DATABASE db2 vgroups 40 replica 3;")
+ newTdSql.execute('CREATE DATABASE db2 vgroups 40 replica 3;', queryTimes=1)
+
+ def alterDbThread(self, sql, newTdSql):
+ tdLog.info("alter DATABASE db1 replica 3;")
+ newTdSql.execute('alter DATABASE db1 replica 3;', queryTimes=1)
+
+ def waitTransactionZero(self, seconds = 300, interval = 1):
+ # wait end
+ for i in range(seconds):
+ sql ="show transactions;"
+ rows = tdSql.query(sql)
+ if rows == 0:
+ tdLog.info("transaction count became zero.")
+ return True
+ #tdLog.info(f"i={i} wait ...")
+ time.sleep(interval)
+
+ return False
+
+tdCases.addLinux(__file__, TDTestCase())
+tdCases.addWindows(__file__, TDTestCase())
\ No newline at end of file
diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py
index 380b7879c4..1abe2b1a65 100644
--- a/tests/system-test/2-query/union.py
+++ b/tests/system-test/2-query/union.py
@@ -441,7 +441,7 @@ class TDTestCase:
tdSql.checkRows(2)
sql = "select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, stable_name `TABLE_NAME`, 'TABLE' `TABLE_TYPE`, table_comment `REMARKS` from information_schema.ins_stables union all select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, table_name `TABLE_NAME`, case when `type`='SYSTEM_TABLE' then 'TABLE' when `type`='NORMAL_TABLE' then 'TABLE' when `type`='CHILD_TABLE' then 'TABLE' else 'UNKNOWN' end `TABLE_TYPE`, table_comment `REMARKS` from information_schema.ins_tables union all select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, view_name `TABLE_NAME`, 'VIEW' `TABLE_TYPE`, NULL `REMARKS` from information_schema.ins_views"
tdSql.query(sql, queryTimes=1)
- tdSql.checkRows(49)
+ tdSql.checkRows(50)
sql = "select null union select null"
tdSql.query(sql, queryTimes=1)
diff --git a/tests/system-test/3-enterprise/restore/kill_restore_dnode.py b/tests/system-test/3-enterprise/restore/kill_restore_dnode.py
new file mode 100644
index 0000000000..d29a11f159
--- /dev/null
+++ b/tests/system-test/3-enterprise/restore/kill_restore_dnode.py
@@ -0,0 +1,90 @@
+###################################################################
+# Copyright (c) 2016 by TAOS Technologies, Inc.
+# All rights reserved.
+#
+# This file is proprietary and confidential to TAOS Technologies.
+# No part of this file may be reproduced, stored, transmitted,
+# disclosed or used in any form or by any means other than as
+# expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+
+import sys
+
+from util.log import *
+from util.cases import *
+from util.sql import *
+from util.common import *
+sys.path.append("./3-enterprise/restore")
+from restoreBasic import *
+from util.common import tdCom
+import threading
+
+
+class TDTestCase:
+ # init
+ def init(self, conn, logSql, replicaVar=1):
+ tdLog.debug("start to execute %s" % __file__)
+ self.basic = RestoreBasic()
+ self.basic.init(conn, logSql, replicaVar)
+
+ # run
+ def run(self):
+ self.basic.restore_dnode_prepare(2)
+
+ self.execute()
+
+ def execute(self):
+ newTdSql=tdCom.newTdSql()
+ t0 = threading.Thread(target=self.restoreDnodeThread, args=('', newTdSql))
+ t0.start()
+
+ time.sleep(2)
+ sql ="show transactions;"
+ tdLog.info(sql)
+ rows = tdSql.query(sql)
+
+ if rows > 0:
+ self.basic.stop_dnode(2)
+
+ tranId = tdSql.getData(0, 0)
+
+ tdLog.info('show transaction %d'%tranId)
+ rows=tdSql.query('show transaction %d'%tranId, queryTimes=1)
+ if rows != 11:
+ tdLog.exit(f"restore transaction detial error, rows={rows}")
+ return False
+
+ tdLog.info('kill transaction %d'%tranId)
+ tdSql.execute('kill transaction %d'%tranId, queryTimes=1 )
+
+ time.sleep(3)
+ sql ="show transactions;"
+ tdLog.info(sql)
+ rows = tdSql.query(sql)
+ if rows > 0:
+ tdLog.info(f"{sql} transaction not finished")
+ return False
+
+ self.basic.restore_dnode_exec(2)
+ else:
+ tdLog.exit(f"{sql} no transaction exist")
+ return False
+
+ def restoreDnodeThread(self, p, newTdSql):
+ sleep(1)
+
+ sql = f"restore dnode 2"
+ tdLog.info(sql)
+ newTdSql.error(sql, expectErrInfo="Wrong transaction execution context")
+ tdLog.info(f"{sql} finished")
+
+ # stop
+ def stop(self):
+ self.basic.stop()
+ tdLog.success("%s successfully executed" % __file__)
+
+tdCases.addWindows(__file__, TDTestCase())
+tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
diff --git a/tests/system-test/3-enterprise/restore/restoreBasic.py b/tests/system-test/3-enterprise/restore/restoreBasic.py
index 77fa606b9c..74cf572018 100644
--- a/tests/system-test/3-enterprise/restore/restoreBasic.py
+++ b/tests/system-test/3-enterprise/restore/restoreBasic.py
@@ -143,6 +143,34 @@ class RestoreBasic:
tdSql.execute(sql)
self.check_corrent()
+ def restore_dnode_prepare(self, index):
+ tdLog.info(f"start restore dnode {index}")
+ dnode = self.dnodes[index - 1]
+
+ # stop dnode
+ tdLog.info(f"stop dnode {index}")
+ dnode.stoptaosd()
+
+ # remove dnode folder
+ try:
+ shutil.rmtree(dnode.dataDir)
+ tdLog.info(f"delete dir {dnode.dataDir} successful")
+ except OSError as x:
+ tdLog.exit(f"remove path {dnode.dataDir} error : {x.strerror}")
+
+ dnode.starttaosd()
+
+ def restore_dnode_exec(self, index):
+ # exec restore
+ sql = f"restore dnode {index}"
+ tdLog.info(sql)
+ tdSql.execute(sql)
+ self.check_corrent()
+
+ def stop_dnode(self, index):
+ dnode = self.dnodes[index - 1]
+
+ dnode.starttaosd()
# restore vnode
def restore_vnode(self, index):
tdLog.info(f"start restore vnode on dnode {index}")
From 938f6a5fa05068277db223a7b6b26b881367f5d3 Mon Sep 17 00:00:00 2001
From: Shengliang Guan
Date: Fri, 27 Dec 2024 22:28:18 +0800
Subject: [PATCH 33/56] git: set tags
---
cmake/taosadapter_CMakeLists.txt.in | 2 +-
cmake/taostools_CMakeLists.txt.in | 2 +-
cmake/taosws_CMakeLists.txt.in | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/cmake/taosadapter_CMakeLists.txt.in b/cmake/taosadapter_CMakeLists.txt.in
index ef6ed4af1d..13826a1a74 100644
--- a/cmake/taosadapter_CMakeLists.txt.in
+++ b/cmake/taosadapter_CMakeLists.txt.in
@@ -2,7 +2,7 @@
# taosadapter
ExternalProject_Add(taosadapter
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
- GIT_TAG 3.0
+ GIT_TAG main
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
diff --git a/cmake/taostools_CMakeLists.txt.in b/cmake/taostools_CMakeLists.txt.in
index 9a6a5329ae..9bbda8309f 100644
--- a/cmake/taostools_CMakeLists.txt.in
+++ b/cmake/taostools_CMakeLists.txt.in
@@ -2,7 +2,7 @@
# taos-tools
ExternalProject_Add(taos-tools
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
- GIT_TAG 3.0
+ GIT_TAG main
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
diff --git a/cmake/taosws_CMakeLists.txt.in b/cmake/taosws_CMakeLists.txt.in
index 17446d184d..b013d45911 100644
--- a/cmake/taosws_CMakeLists.txt.in
+++ b/cmake/taosws_CMakeLists.txt.in
@@ -2,7 +2,7 @@
# taosws-rs
ExternalProject_Add(taosws-rs
GIT_REPOSITORY https://github.com/taosdata/taos-connector-rust.git
- GIT_TAG 3.0
+ GIT_TAG main
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosws-rs"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
From 5f3e8ef5aa58f47da16e9b3fa2051852a1780f51 Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sat, 28 Dec 2024 15:35:12 +0800
Subject: [PATCH 34/56] test: add test case for auto compact
---
source/dnode/mnode/impl/src/mndDb.c | 2 +-
source/libs/parser/src/parTranslater.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index 432d0329d1..b4f80fa37c 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -2568,7 +2568,7 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
}
len = formatDurationOrKeep(durationStr, sizeof(durationStr), pDb->cfg.compactStartTime);
- formatDurationOrKeep(durationVstr, sizeof(durationVstr), pDb->cfg.compactEndTime);
+ TAOS_UNUSED(formatDurationOrKeep(durationVstr, sizeof(durationVstr), pDb->cfg.compactEndTime));
TAOS_UNUSED(snprintf(durationStr + len, sizeof(durationStr) - len, ",%s", durationVstr));
STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr));
if ((pColInfo = taosArrayGet(pBlock->pDataBlock, cols++))) {
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index 6ed0cc60b2..2e711efa89 100755
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -2033,7 +2033,7 @@ static EDealRes translateDurationValue(STranslateContext* pCxt, SValueNode* pVal
pVal->datum.i = AUTO_DURATION_VALUE;
pVal->unit = getPrecisionUnit(pVal->node.resType.precision);
} else if (parseNatualDuration(pVal->literal, strlen(pVal->literal), &pVal->datum.i, &pVal->unit,
- pVal->node.resType.precision, false) != TSDB_CODE_SUCCESS) {
+ pVal->node.resType.precision, true) != TSDB_CODE_SUCCESS) {
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal);
}
*(int64_t*)&pVal->typeData = pVal->datum.i;
@@ -8268,7 +8268,7 @@ static int32_t checkDbCompactTimeRangeOption(STranslateContext* pCxt, const char
}
if (pOptions->compactStartTime < -keep2 || pOptions->compactStartTime > -days) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
- "Invalid option compact_time_range: %dm, start_time should be in range: [%dm, %dm]",
+ "Invalid option compact_time_range: %dm, start time should be in range: [%dm, %dm]",
pOptions->compactStartTime, -keep2, -days);
}
if (pOptions->compactEndTime < -keep2 || pOptions->compactEndTime > -days) {
From 1bc3c4a44914861cf01c74020735f3a56da6846d Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sat, 28 Dec 2024 19:28:07 +0800
Subject: [PATCH 35/56] test: add test case for auto compact
---
source/libs/parser/inc/sql.y | 21 ++--
source/libs/parser/src/parTranslater.c | 4 +
tests/parallel_test/cases.task | 1 +
tests/system-test/0-others/compact_auto.py | 118 +++++++++++++++++++
tests/system-test/1-insert/alter_database.py | 25 +---
5 files changed, 136 insertions(+), 33 deletions(-)
create mode 100644 tests/system-test/0-others/compact_auto.py
diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y
index 38e93a7ce3..63a6b97bbb 100644
--- a/source/libs/parser/inc/sql.y
+++ b/source/libs/parser/inc/sql.y
@@ -290,8 +290,7 @@ db_options(A) ::= db_options(B) ENCRYPT_ALGORITHM NK_STRING(C).
db_options(A) ::= db_options(B) DNODES NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_DNODES, &C); }
db_options(A) ::= db_options(B) COMPACT_INTERVAL NK_INTEGER (C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_INTERVAL, &C); }
db_options(A) ::= db_options(B) COMPACT_INTERVAL NK_VARIABLE(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_INTERVAL, &C); }
-db_options(A) ::= db_options(B) COMPACT_TIME_RANGE signed_integer_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_TIME_RANGE, C); }
-db_options(A) ::= db_options(B) COMPACT_TIME_RANGE signed_variable_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_TIME_RANGE, C); }
+db_options(A) ::= db_options(B) COMPACT_TIME_RANGE signed_duration_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_TIME_RANGE, C); }
db_options(A) ::= db_options(B) COMPACT_TIME_OFFSET NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_TIME_OFFSET, &C); }
db_options(A) ::= db_options(B) COMPACT_TIME_OFFSET NK_VARIABLE(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_TIME_OFFSET, &C); }
@@ -331,8 +330,7 @@ alter_db_option(A) ::= KEEP_TIME_OFFSET NK_INTEGER(B).
alter_db_option(A) ::= ENCRYPT_ALGORITHM NK_STRING(B). { A.type = DB_OPTION_ENCRYPT_ALGORITHM; A.val = B; }
alter_db_option(A) ::= COMPACT_INTERVAL NK_INTEGER(B). { A.type = DB_OPTION_COMPACT_INTERVAL; A.val = B; }
alter_db_option(A) ::= COMPACT_INTERVAL NK_VARIABLE(B). { A.type = DB_OPTION_COMPACT_INTERVAL; A.val = B; }
-alter_db_option(A) ::= COMPACT_TIME_RANGE signed_integer_list(B). { A.type = DB_OPTION_COMPACT_TIME_RANGE; A.pList = B; }
-alter_db_option(A) ::= COMPACT_TIME_RANGE signed_variable_list(B). { A.type = DB_OPTION_COMPACT_TIME_RANGE; A.pList = B; }
+alter_db_option(A) ::= COMPACT_TIME_RANGE signed_duration_list(B). { A.type = DB_OPTION_COMPACT_TIME_RANGE; A.pList = B; }
alter_db_option(A) ::= COMPACT_TIME_OFFSET NK_INTEGER(B). { A.type = DB_OPTION_COMPACT_TIME_OFFSET; A.val = B; }
alter_db_option(A) ::= COMPACT_TIME_OFFSET NK_VARIABLE(B). { A.type = DB_OPTION_COMPACT_TIME_OFFSET; A.val = B; }
@@ -341,20 +339,17 @@ alter_db_option(A) ::= COMPACT_TIME_OFFSET NK_VARIABLE(B).
integer_list(A) ::= NK_INTEGER(B). { A = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B)); }
integer_list(A) ::= integer_list(B) NK_COMMA NK_INTEGER(C). { A = addNodeToList(pCxt, B, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C)); }
-%type signed_integer_list { SNodeList* }
-%destructor signed_integer_list { nodesDestroyList($$); }
-signed_integer_list(A) ::= signed_integer(B). { A = createNodeList(pCxt, B); }
-signed_integer_list(A) ::= signed_integer_list(B) NK_COMMA signed_integer(C). { A = addNodeToList(pCxt, B, C); }
-
%type variable_list { SNodeList* }
%destructor variable_list { nodesDestroyList($$); }
variable_list(A) ::= NK_VARIABLE(B). { A = createNodeList(pCxt, createDurationValueNode(pCxt, &B)); }
variable_list(A) ::= variable_list(B) NK_COMMA NK_VARIABLE(C). { A = addNodeToList(pCxt, B, createDurationValueNode(pCxt, &C)); }
-%type signed_variable_list { SNodeList* }
-%destructor signed_variable_list { nodesDestroyList($$); }
-signed_variable_list(A) ::= signed_variable(B). { A = createNodeList(pCxt, releaseRawExprNode(pCxt, B)); }
-signed_variable_list(A) ::= signed_variable_list(B) NK_COMMA signed_variable(C). { A = addNodeToList(pCxt, B, releaseRawExprNode(pCxt, C)); }
+%type signed_duration_list { SNodeList* }
+%destructor signed_duration_list { nodesDestroyList($$); }
+signed_duration_list(A) ::= signed_variable(B). { A = createNodeList(pCxt, releaseRawExprNode(pCxt, B)); }
+signed_duration_list(A) ::= signed_integer(B). { A = createNodeList(pCxt, B); }
+signed_duration_list(A) ::= signed_duration_list(B) NK_COMMA signed_integer(C). { A = addNodeToList(pCxt, B, C); }
+signed_duration_list(A) ::= signed_duration_list(B) NK_COMMA signed_variable(C). { A = addNodeToList(pCxt, B, releaseRawExprNode(pCxt, C)); }
%type retention_list { SNodeList* }
%destructor retention_list { nodesDestroyList($$); }
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index 2e711efa89..abd0efa2d8 100755
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -8252,6 +8252,10 @@ static int32_t checkDbCompactTimeRangeOption(STranslateContext* pCxt, const char
pOptions->compactStartTime = getBigintFromValueNode(pStart);
pOptions->compactEndTime = getBigintFromValueNode(pEnd);
+ if (pOptions->compactStartTime == 0 && pOptions->compactEndTime == 0) {
+ return TSDB_CODE_SUCCESS;
+ }
+
if (pOptions->compactStartTime >= pOptions->compactEndTime) {
return generateSyntaxErrMsgExt(
&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task
index 38dd080ef5..786f1f6dde 100644
--- a/tests/parallel_test/cases.task
+++ b/tests/parallel_test/cases.task
@@ -414,6 +414,7 @@
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/persisit_config.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/qmemCtrl.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/compact_vgroups.py
+,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/compact_auto.py
,,n,system-test,python3 ./test.py -f 0-others/dumpsdb.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/compact.py -N 3
diff --git a/tests/system-test/0-others/compact_auto.py b/tests/system-test/0-others/compact_auto.py
new file mode 100644
index 0000000000..615c2bba5b
--- /dev/null
+++ b/tests/system-test/0-others/compact_auto.py
@@ -0,0 +1,118 @@
+import taos
+import sys
+import time
+import socket
+import os
+import threading
+import psutil
+import platform
+from util.log import *
+from util.sql import *
+from util.cases import *
+from util.dnodes import *
+
+
+class TDTestCase:
+ def init(self, conn, logSql, replicaVar=1):
+ self.replicaVar = int(replicaVar)
+ tdLog.debug("start to execute %s" % __file__)
+ tdSql.init(conn.cursor(), logSql)
+ self.default_compact_options = [ "0d", "0d,0d", "0h"]
+ self.compact_options = [["db00", "0m", "-0d,0", "0", "0d", "0d,0d", "0h"],
+ ["db01", "2880m", "-61d,-60", "0", "2d", "-61d,-60d", "0h"],
+ ["db02", "48h", "-87840m,-60", "1h", "2d", "-61d,-60d", "1h"],
+ ["db03", "2d", "-87840m,-1440h", "12", "2d", "-61d,-60d", "12h"],
+ ["db04", "2", "-61,-1440h", "23h", "2d", "-61d,-60d", "23h"],
+ ]
+
+ def create_db_compact(self):
+ for item in self.compact_options:
+ tdSql.execute(f'create database {item[0]} compact_interval {item[1]} compact_time_range {item[2]} compact_time_offset {item[3]}')
+ tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
+ tdSql.checkEqual(tdSql.queryResult[0][34], item[4])
+ tdSql.checkEqual(tdSql.queryResult[0][35], item[5])
+ tdSql.checkEqual(tdSql.queryResult[0][36], item[6])
+ tdSql.query(f'show create database {item[0]}')
+ tdSql.checkEqual(tdSql.queryResult[0][0], item[0])
+ tdSql.checkEqual(True, f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {item[5]} COMPACT_TIME_OFFSET {item[6]}' in tdSql.queryResult[0][1])
+ tdSql.execute(f'drop database {item[0]}')
+
+ def checkShowCreateWithTimeout(self, db, expectResult, timeout=30):
+ result = False
+ for i in range(timeout):
+ tdSql.query(f'show create database `%s`' %(db))
+ tdSql.checkEqual(tdSql.queryResult[0][0], db)
+ if expectResult in tdSql.queryResult[0][1]:
+ result = True
+ break
+ time.sleep(1)
+ if result == False:
+ raise Exception(f"Unexpected result of 'show create database `{db}`':{tdSql.queryResult[0][1]}")
+
+ def alter_db_compact(self):
+ for item in self.compact_options:
+ tdSql.execute(f'create database {item[0]}')
+ tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
+ tdSql.checkEqual(tdSql.queryResult[0][34], self.default_compact_options[0])
+ tdSql.checkEqual(tdSql.queryResult[0][35], self.default_compact_options[1])
+ tdSql.checkEqual(tdSql.queryResult[0][36], self.default_compact_options[2])
+ tdSql.query(f'show create database {item[0]}')
+ tdSql.checkEqual(tdSql.queryResult[0][0], item[0])
+ tdSql.checkEqual(True, f'COMPACT_INTERVAL {self.default_compact_options[0]} COMPACT_TIME_RANGE {self.default_compact_options[1]} COMPACT_TIME_OFFSET {self.default_compact_options[2]}' in tdSql.queryResult[0][1])
+ tdSql.execute(f'alter database {item[0]} compact_interval {item[1]} compact_time_range {item[2]} compact_time_offset {item[3]}')
+ tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
+ tdSql.checkEqual(tdSql.queryResult[0][34], item[4])
+ tdSql.checkEqual(tdSql.queryResult[0][35], item[5])
+ tdSql.checkEqual(tdSql.queryResult[0][36], item[6])
+ for item in self.compact_options:
+ self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {item[5]} COMPACT_TIME_OFFSET {item[6]}')
+ tdSql.execute(f'drop database {item[0]}')
+
+ def compact_error(self):
+ compact_err_list = [["compact_time_range 86400m,61d", "Invalid option compact_time_range: 86400m, start time should be in range: [-5256000m, -14400m]"],
+ ["compact_time_range 60,61", "Invalid option compact_time_range: 86400m, start time should be in range: [-5256000m, -14400m]"],
+ ["compact_time_range 60d,61d", "Invalid option compact_time_range: 86400m, start time should be in range: [-5256000m, -14400m]"],
+ ["compact_time_range -60,-60", "Invalid option compact_time_range: -86400m,-86400m, start time should be less than end time"],
+ ["compact_time_range -60,-1440h", "Invalid option compact_time_range: -86400m,-86400m, start time should be less than end time"],
+ ["compact_time_range -60d,-61d", "Invalid option compact_time_range: -86400m,-87840m, start time should be less than end time"],
+ ["compact_time_range -5256001m,-1", "Invalid option compact_time_range: -5256001m, start time should be in range: [-5256000m, -14400m]"],
+ ["compact_time_range -60d,-1", "Invalid option compact_time_range: -1440m, end time should be in range: [-5256000m, -14400m]"],
+ ["compact_interval 24h compact_time_range -60,61", "Invalid option compact_time_range: 87840m, end time should be in range: [-5256000m, -14400m]"],
+ ["compact_interval 100 compact_time_range -60d,61d", "Invalid option compact_time_range: 87840m, end time should be in range: [-5256000m, -14400m]"],
+ ["compact_time_range -60d,87840m", "Invalid option compact_time_range: 87840m, end time should be in range: [-5256000m, -14400m]"],
+ ["compact_interval 10m compact_time_range -120d,-14400m compact_time_offset -1", "syntax error near"],
+ ["compact_time_range -100,-99d compact_interval -1", "syntax error near"],
+ ["compact_time_range 0", "Invalid option compact_time_range, should have 2 value"],
+ ["compact_time_range -100", "Invalid option compact_time_range, should have 2 value"],
+ ["compact_time_range -100,-90,-80", "Invalid option compact_time_range, should have 2 value"],
+ ["compact_time_range -100;-90", "Invalid option compact_time_range, should have 2 value"],
+ ["compact_time_range -100:-90", "syntax error near"],
+ ["compact_time_range -100 -90", "syntax error near"],
+ ["compact_interval 1m", "Invalid option compact_interval: 1m, valid range: [10m, 5256000m]"],
+ ["compact_interval 5256001m", "Invalid option compact_interval: 5256001m, valid range: [10m, 5256000m]"],
+ ["compact_interval 3651", "Invalid option compact_interval: 5257440m, valid range: [10m, 5256000m]"],
+ ["compact_interval -1", "syntax error near"],
+ ["compact_time_offset -1", "syntax error near"],
+ ["compact_time_offset 1d", "Invalid option compact_time_offset unit: d, only h allowed"],
+ ["compact_time_offset 24", "Invalid option compact_time_offset: 24h, valid range: [0h, 23h]"],
+ ["compact_time_offset 24h", "Invalid option compact_time_offset: 24h, valid range: [0h, 23h]"],
+ ["compact_time_offset 1d", "Invalid option compact_time_offset unit: d, only h allowed"],
+ ["compact_interval 10m compact_time_range -120d,-60 compact_time_offset 1d", "Invalid option compact_time_offset unit: d, only h allowed"],
+ ]
+ tdSql.execute('create database if not exists db')
+ for item in compact_err_list:
+ tdSql.error(f"create database db {item[0]}", expectErrInfo=item[1], fullMatched=False)
+ tdSql.error(f"alter database db {item[0]}", expectErrInfo=item[1], fullMatched=False)
+
+ def run(self):
+ self.create_db_compact()
+ self.alter_db_compact()
+ self.compact_error()
+
+ def stop(self):
+ tdSql.close()
+ tdLog.success(f"{__file__} successfully executed")
+
+
+tdCases.addLinux(__file__, TDTestCase())
+tdCases.addWindows(__file__, TDTestCase())
diff --git a/tests/system-test/1-insert/alter_database.py b/tests/system-test/1-insert/alter_database.py
index c20ace6ff4..55b636f5ea 100644
--- a/tests/system-test/1-insert/alter_database.py
+++ b/tests/system-test/1-insert/alter_database.py
@@ -75,28 +75,14 @@ class TDTestCase:
tdSql.checkEqual("Invalid option encrypt_algorithm: none ", tdSql.error('alter database db encrypt_algorithm \'none \''))
tdSql.execute('drop database db')
- def alter_compact(self):
- tdSql.execute('create database db')
- tdSql.execute('alter database db compact_time_offset 2')
- tdSql.execute('alter database db compact_time_offset 3h')
- tdSql.error('create database db1 compact_time_range 60,61', expectErrInfo="Invalid option compact_time_range: 86400m, start_time should be in range: [-5256000m, -14400m]", fullMatched=False)
- tdSql.error('create database db1 compact_time_offset -1', expectErrInfo="syntax error near", fullMatched=False)
- tdSql.error('create database d3 compact_interval 1m; ', expectErrInfo="Invalid option compact_interval: 1m, valid range: [10m, 5256000m]", fullMatched=False)
- tdSql.error('alter database db compact_time_offset -1', expectErrInfo="syntax error near", fullMatched=False)
- tdSql.error('alter database db compact_time_offset 24', expectErrInfo="Invalid option compact_time_offset: 24h, valid range: [0h, 23h]", fullMatched=False)
- tdSql.error('alter database db compact_time_offset 24h', expectErrInfo="Invalid option compact_time_offset: 24h, valid range: [0h, 23h]", fullMatched=False)
- tdSql.error('alter database db compact_time_offset 1d', expectErrInfo="Invalid option compact_time_offset unit: d, only h allowed", fullMatched=False)
-
-
-
def alter_same_options(self):
tdSql.execute('drop database if exists db')
tdSql.execute('create database db')
tdSql.query('select * from information_schema.ins_databases where name = "db"')
db_options_items = ["replica","keep","buffer","pages","minrows","cachemodel","cachesize","wal_level","wal_fsync_period",
- "wal_retention_period","wal_retention_size","stt_trigger"]
- db_options_result_idx = [4,7,8,10,11,18,19,20,21,22,23,24]
+ "wal_retention_period","wal_retention_size","stt_trigger", "compact_interval", "compact_time_range", "compact_time_offset"]
+ db_options_result_idx = [4,7,8,10,11,18,19,20,21,22,23,24,34,35,36]
self.option_result = []
for idx in db_options_result_idx:
@@ -115,11 +101,10 @@ class TDTestCase:
def run(self):
- self.alter_buffer()
- self.alter_pages()
- self.alter_encrypt_alrogithm()
+ # self.alter_buffer()
+ # self.alter_pages()
+ # self.alter_encrypt_alrogithm()
self.alter_same_options()
- self.alter_compact()
def stop(self):
tdSql.close()
From 0101bfccee5fac89bcf362effa635cf975efa256 Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sat, 28 Dec 2024 19:30:19 +0800
Subject: [PATCH 36/56] test: add test case for auto compact
---
tests/system-test/1-insert/alter_database.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/system-test/1-insert/alter_database.py b/tests/system-test/1-insert/alter_database.py
index 55b636f5ea..17a0664926 100644
--- a/tests/system-test/1-insert/alter_database.py
+++ b/tests/system-test/1-insert/alter_database.py
@@ -101,9 +101,9 @@ class TDTestCase:
def run(self):
- # self.alter_buffer()
- # self.alter_pages()
- # self.alter_encrypt_alrogithm()
+ self.alter_buffer()
+ self.alter_pages()
+ self.alter_encrypt_alrogithm()
self.alter_same_options()
def stop(self):
From 078367d29f529d8ddba3cb7c7d54772baab5b346 Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sat, 28 Dec 2024 20:52:22 +0800
Subject: [PATCH 37/56] test: add test case for auto compact
---
include/libs/nodes/cmdnodes.h | 2 +-
source/libs/parser/src/parTranslater.c | 2 +-
tests/system-test/0-others/compact_auto.py | 10 ++++++++++
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h
index 0f736e7068..7252929e3b 100644
--- a/include/libs/nodes/cmdnodes.h
+++ b/include/libs/nodes/cmdnodes.h
@@ -112,7 +112,7 @@ typedef struct SDatabaseOptions {
int8_t s3Compact;
int8_t withArbitrator;
// for auto-compact
- int8_t compactTimeOffset; // hours
+ int32_t compactTimeOffset; // hours
int32_t compactInterval; // minutes
int32_t compactStartTime; // minutes
int32_t compactEndTime; // minutes
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index abd0efa2d8..2c43059ba0 100755
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -7810,7 +7810,7 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS
static int32_t checkRangeOption(STranslateContext* pCxt, int32_t code, const char* pName, int64_t val, int64_t minVal,
int64_t maxVal, int8_t unit, bool skipUndef) {
- if (skipUndef ? ((val >= 0) && (val < minVal || val > maxVal)) : (val < minVal || val > maxVal)) {
+ if (skipUndef ? ((val >= 0 || val < -2) && (val < minVal || val > maxVal)) : (val < minVal || val > maxVal)) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, code,
"Invalid option %s: %" PRId64 "%c, valid range: [%" PRId64 "%c, %" PRId64 "%c]",
pName, val, unit, minVal, unit, maxVal, unit);
diff --git a/tests/system-test/0-others/compact_auto.py b/tests/system-test/0-others/compact_auto.py
index 615c2bba5b..ea812b3ab7 100644
--- a/tests/system-test/0-others/compact_auto.py
+++ b/tests/system-test/0-others/compact_auto.py
@@ -76,10 +76,13 @@ class TDTestCase:
["compact_time_range -60,-1440h", "Invalid option compact_time_range: -86400m,-86400m, start time should be less than end time"],
["compact_time_range -60d,-61d", "Invalid option compact_time_range: -86400m,-87840m, start time should be less than end time"],
["compact_time_range -5256001m,-1", "Invalid option compact_time_range: -5256001m, start time should be in range: [-5256000m, -14400m]"],
+ ["compact_time_range -199999999999m,-199999999998m", "start time should be in range: [-5256000m, -14400m]"],
+ ["compact_time_range -99999999999999999999m,-99999999999999999998m", "Invalid value type: -99999999999999999999"],
["compact_time_range -60d,-1", "Invalid option compact_time_range: -1440m, end time should be in range: [-5256000m, -14400m]"],
["compact_interval 24h compact_time_range -60,61", "Invalid option compact_time_range: 87840m, end time should be in range: [-5256000m, -14400m]"],
["compact_interval 100 compact_time_range -60d,61d", "Invalid option compact_time_range: 87840m, end time should be in range: [-5256000m, -14400m]"],
["compact_time_range -60d,87840m", "Invalid option compact_time_range: 87840m, end time should be in range: [-5256000m, -14400m]"],
+ ["compact_time_range -100,-90s", "Invalid option compact_time_range end unit: s, only m, h, d allowed"],
["compact_interval 10m compact_time_range -120d,-14400m compact_time_offset -1", "syntax error near"],
["compact_time_range -100,-99d compact_interval -1", "syntax error near"],
["compact_time_range 0", "Invalid option compact_time_range, should have 2 value"],
@@ -89,13 +92,19 @@ class TDTestCase:
["compact_time_range -100:-90", "syntax error near"],
["compact_time_range -100 -90", "syntax error near"],
["compact_interval 1m", "Invalid option compact_interval: 1m, valid range: [10m, 5256000m]"],
+ ["compact_interval 199999999999m", "valid range: [10m, 5256000m]"],
+ ["compact_interval 9999999999999m", "Invalid option compact_interval: 9999999999999m, valid range: [10m, 5256000m]"],
["compact_interval 5256001m", "Invalid option compact_interval: 5256001m, valid range: [10m, 5256000m]"],
["compact_interval 3651", "Invalid option compact_interval: 5257440m, valid range: [10m, 5256000m]"],
+ ["compact_interval 86400s", "Invalid option compact_interval unit: s, only m, h, d allowed"],
["compact_interval -1", "syntax error near"],
["compact_time_offset -1", "syntax error near"],
+ ["compact_time_offset 3600s", "Invalid option compact_time_offset unit: s, only h allowed"],
["compact_time_offset 1d", "Invalid option compact_time_offset unit: d, only h allowed"],
["compact_time_offset 24", "Invalid option compact_time_offset: 24h, valid range: [0h, 23h]"],
["compact_time_offset 24h", "Invalid option compact_time_offset: 24h, valid range: [0h, 23h]"],
+ ["compact_time_offset 9999999999999", "valid range: [0h, 23h]"],
+ ["compact_time_offset 199999999999", "valid range: [0h, 23h]"],
["compact_time_offset 1d", "Invalid option compact_time_offset unit: d, only h allowed"],
["compact_interval 10m compact_time_range -120d,-60 compact_time_offset 1d", "Invalid option compact_time_offset unit: d, only h allowed"],
]
@@ -103,6 +112,7 @@ class TDTestCase:
for item in compact_err_list:
tdSql.error(f"create database db {item[0]}", expectErrInfo=item[1], fullMatched=False)
tdSql.error(f"alter database db {item[0]}", expectErrInfo=item[1], fullMatched=False)
+ tdSql.execute('drop database db')
def run(self):
self.create_db_compact()
From 104f37337f942c02db7a2e0f5610a898aa6f5da1 Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sun, 29 Dec 2024 12:24:15 +0800
Subject: [PATCH 38/56] test: add test case for auto compact
---
source/dnode/mnode/impl/src/mndDb.c | 36 ++++++++++++-
source/libs/parser/src/parTranslater.c | 12 +++--
tests/system-test/0-others/compact_auto.py | 62 +++++++++++++++++++---
3 files changed, 96 insertions(+), 14 deletions(-)
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index b4f80fa37c..2db148ec98 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -499,6 +499,19 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
if (pCfg->s3KeepLocal < TSDB_MIN_S3_KEEP_LOCAL || pCfg->s3KeepLocal > TSDB_MAX_S3_KEEP_LOCAL) return code;
if (pCfg->s3Compact < TSDB_MIN_S3_COMPACT || pCfg->s3Compact > TSDB_MAX_S3_COMPACT) return code;
+ if (pCfg->compactInterval != 0 &&
+ (pCfg->compactInterval < TSDB_MIN_COMPACT_INTERVAL || pCfg->compactInterval > pCfg->daysToKeep2))
+ return code;
+ if (pCfg->compactStartTime != 0 &&
+ (pCfg->compactStartTime < -pCfg->daysToKeep2 || pCfg->compactStartTime > -pCfg->daysPerFile))
+ return code;
+ if (pCfg->compactEndTime != 0 &&
+ (pCfg->compactEndTime < -pCfg->daysToKeep2 || pCfg->compactEndTime > -pCfg->daysPerFile))
+ if (pCfg->compactStartTime != 0 && pCfg->compactEndTime != 0 && pCfg->compactStartTime > pCfg->compactEndTime)
+ return code;
+ if (pCfg->compactTimeOffset < TSDB_MIN_COMPACT_TIME_OFFSET || pCfg->compactTimeOffset > TSDB_MAX_COMPACT_TIME_OFFSET)
+ return code;
+
code = 0;
TAOS_RETURN(code);
}
@@ -564,6 +577,21 @@ static int32_t mndCheckInChangeDbCfg(SMnode *pMnode, SDbCfg *pOldCfg, SDbCfg *pN
if (pNewCfg->s3KeepLocal < TSDB_MIN_S3_KEEP_LOCAL || pNewCfg->s3KeepLocal > TSDB_MAX_S3_KEEP_LOCAL) return code;
if (pNewCfg->s3Compact < TSDB_MIN_S3_COMPACT || pNewCfg->s3Compact > TSDB_MAX_S3_COMPACT) return code;
+ if (pNewCfg->compactInterval != 0 &&
+ (pNewCfg->compactInterval < TSDB_MIN_COMPACT_INTERVAL || pNewCfg->compactInterval > pNewCfg->daysToKeep2))
+ return code;
+ if (pNewCfg->compactStartTime != 0 &&
+ (pNewCfg->compactStartTime < -pNewCfg->daysToKeep2 || pNewCfg->compactStartTime > -pNewCfg->daysPerFile))
+ return code;
+ if (pNewCfg->compactEndTime != 0 &&
+ (pNewCfg->compactEndTime < -pNewCfg->daysToKeep2 || pNewCfg->compactEndTime > -pNewCfg->daysPerFile))
+ if (pNewCfg->compactStartTime != 0 && pNewCfg->compactEndTime != 0 &&
+ pNewCfg->compactStartTime > pNewCfg->compactEndTime)
+ return code;
+ if (pNewCfg->compactTimeOffset < TSDB_MIN_COMPACT_TIME_OFFSET ||
+ pNewCfg->compactTimeOffset > TSDB_MAX_COMPACT_TIME_OFFSET)
+ return code;
+
code = 0;
TAOS_RETURN(code);
}
@@ -1150,20 +1178,24 @@ static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) {
code = 0;
}
+ bool compactTimeRangeChanged = false;
if (pAlter->compactStartTime != pDb->cfg.compactStartTime &&
(pAlter->compactStartTime == TSDB_DEFAULT_COMPACT_START_TIME ||
pAlter->compactStartTime <= -pDb->cfg.daysPerFile)) {
pDb->cfg.compactStartTime = pAlter->compactStartTime;
- pDb->vgVersion++;
+ compactTimeRangeChanged = true;
code = 0;
}
if (pAlter->compactEndTime != pDb->cfg.compactEndTime &&
(pAlter->compactEndTime == TSDB_DEFAULT_COMPACT_END_TIME || pAlter->compactEndTime <= -pDb->cfg.daysPerFile)) {
pDb->cfg.compactEndTime = pAlter->compactEndTime;
- pDb->vgVersion++;
+ compactTimeRangeChanged = true;
code = 0;
}
+ if(compactTimeRangeChanged) {
+ pDb->vgVersion++;
+ }
if (pAlter->compactTimeOffset >= TSDB_MIN_COMPACT_TIME_OFFSET &&
pAlter->compactTimeOffset != pDb->cfg.compactTimeOffset) {
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index 2c43059ba0..c4d6571adc 100755
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -8178,7 +8178,6 @@ static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbNa
static int32_t checkDbCompactIntervalOption(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions) {
int32_t code = 0;
- int64_t interval = 0;
int32_t keep2 = pOptions->keep[2];
if (NULL != pOptions->pCompactIntervalNode) {
@@ -8193,23 +8192,26 @@ static int32_t checkDbCompactIntervalOption(STranslateContext* pCxt, const char*
pOptions->pCompactIntervalNode->unit, TIME_UNIT_MINUTE, TIME_UNIT_HOUR,
TIME_UNIT_DAY);
}
- interval = getBigintFromValueNode(pOptions->pCompactIntervalNode);
+ int64_t interval = getBigintFromValueNode(pOptions->pCompactIntervalNode);
if (interval != 0) {
if (keep2 == -1) { // alter db
TAOS_CHECK_RETURN(translateGetDbCfg(pCxt, pDbName, &pOptions->pDbCfg));
keep2 = pOptions->pDbCfg->daysToKeep2;
}
code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2, TIME_UNIT_MINUTE);
+ TAOS_CHECK_RETURN(code);
}
+ pOptions->compactInterval = (int32_t)interval;
} else if (pOptions->compactInterval > 0) {
- interval = pOptions->compactInterval * 1440; // convert to minutes
- if (keep2 == -1) { // alter db
+ int64_t interval = (int64_t)pOptions->compactInterval * 1440; // convert to minutes
+ if (keep2 == -1) { // alter db
TAOS_CHECK_RETURN(translateGetDbCfg(pCxt, pDbName, &pOptions->pDbCfg));
keep2 = pOptions->pDbCfg->daysToKeep2;
}
code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2, TIME_UNIT_MINUTE);
+ TAOS_CHECK_RETURN(code);
+ pOptions->compactInterval = (int32_t)interval;
}
- if (code == 0) pOptions->compactInterval = interval;
return code;
}
diff --git a/tests/system-test/0-others/compact_auto.py b/tests/system-test/0-others/compact_auto.py
index ea812b3ab7..4cfeec5b62 100644
--- a/tests/system-test/0-others/compact_auto.py
+++ b/tests/system-test/0-others/compact_auto.py
@@ -19,15 +19,17 @@ class TDTestCase:
tdSql.init(conn.cursor(), logSql)
self.default_compact_options = [ "0d", "0d,0d", "0h"]
self.compact_options = [["db00", "0m", "-0d,0", "0", "0d", "0d,0d", "0h"],
- ["db01", "2880m", "-61d,-60", "0", "2d", "-61d,-60d", "0h"],
- ["db02", "48h", "-87840m,-60", "1h", "2d", "-61d,-60d", "1h"],
- ["db03", "2d", "-87840m,-1440h", "12", "2d", "-61d,-60d", "12h"],
- ["db04", "2", "-61,-1440h", "23h", "2d", "-61d,-60d", "23h"],
+ ["db01", "0m", "-2d,-1", "0", "0d", "-2d,-1d", "0h"],
+ ["db02", "2880m", "-61d,-1", "0", "2d", "-61d,-1d", "0h"],
+ ["db03", "48h", "-87840m,-60", "1h", "2d", "-61d,-60d", "1h"],
+ ["db04", "2d", "-87840m,-1440h", "12", "2d", "-61d,-60d", "12h"],
+ ["db05", "2", "-61,-1440h", "23h", "2d", "-61d,-60d", "23h"],
]
def create_db_compact(self):
+ tdLog.info("create db compact options")
for item in self.compact_options:
- tdSql.execute(f'create database {item[0]} compact_interval {item[1]} compact_time_range {item[2]} compact_time_offset {item[3]}')
+ tdSql.execute(f'create database {item[0]} compact_interval {item[1]} compact_time_range {item[2]} compact_time_offset {item[3]} duration 1d')
tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
tdSql.checkEqual(tdSql.queryResult[0][34], item[4])
tdSql.checkEqual(tdSql.queryResult[0][35], item[5])
@@ -47,11 +49,12 @@ class TDTestCase:
break
time.sleep(1)
if result == False:
- raise Exception(f"Unexpected result of 'show create database `{db}`':{tdSql.queryResult[0][1]}")
+ raise Exception(f"Unexpected result of 'show create database `{db}`':{tdSql.queryResult[0][1]}, expect:{expectResult}")
def alter_db_compact(self):
+ tdLog.info("alter db compact options together")
for item in self.compact_options:
- tdSql.execute(f'create database {item[0]}')
+ tdSql.execute(f'create database {item[0]} duration 1d')
tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
tdSql.checkEqual(tdSql.queryResult[0][34], self.default_compact_options[0])
tdSql.checkEqual(tdSql.queryResult[0][35], self.default_compact_options[1])
@@ -67,6 +70,51 @@ class TDTestCase:
for item in self.compact_options:
self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {item[5]} COMPACT_TIME_OFFSET {item[6]}')
tdSql.execute(f'drop database {item[0]}')
+
+ tdLog.info("alter db compact options separately")
+ compact_separate_options = [["db100", "0m", "-0d,0", "0", "0d", "0d,0d", "0h"],
+ ["db101", "10m", "-2d,-1", "1", "10m", "-2d,-1d", "1h"]]
+ index = 0
+ for item in compact_separate_options:
+ tdSql.execute(f'create database {item[0]} duration 1d')
+ tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
+ tdSql.checkEqual(tdSql.queryResult[0][34], self.default_compact_options[0])
+ tdSql.checkEqual(tdSql.queryResult[0][35], self.default_compact_options[1])
+ tdSql.checkEqual(tdSql.queryResult[0][36], self.default_compact_options[2])
+ tdSql.query(f'show create database {item[0]}')
+ tdSql.checkEqual(tdSql.queryResult[0][0], item[0])
+ tdSql.checkEqual(True, f'COMPACT_INTERVAL {self.default_compact_options[0]} COMPACT_TIME_RANGE {self.default_compact_options[1]} COMPACT_TIME_OFFSET {self.default_compact_options[2]}' in tdSql.queryResult[0][1])
+ tdSql.execute(f'alter database {item[0]} compact_time_offset {item[3]}', queryTimes=10)
+ tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
+ tdSql.checkEqual(tdSql.queryResult[0][34], self.default_compact_options[0])
+ tdSql.checkEqual(tdSql.queryResult[0][35], self.default_compact_options[1])
+ tdSql.checkEqual(tdSql.queryResult[0][36], item[6])
+ self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {self.default_compact_options[0]} COMPACT_TIME_RANGE {self.default_compact_options[1]} COMPACT_TIME_OFFSET {item[6]}')
+ tdSql.execute(f'alter database {item[0]} compact_interval {item[1]}', queryTimes=10)
+ tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
+ tdSql.checkEqual(tdSql.queryResult[0][34], item[4])
+ tdSql.checkEqual(tdSql.queryResult[0][35], self.default_compact_options[1])
+ tdSql.checkEqual(tdSql.queryResult[0][36], item[6])
+ if index == 0:
+ self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {self.default_compact_options[1]} COMPACT_TIME_OFFSET {item[6]}')
+ else:
+ self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE -3650d,-1d COMPACT_TIME_OFFSET {item[6]}')
+ tdSql.execute(f'alter database {item[0]} compact_time_range {item[2]}', queryTimes=10)
+ tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
+ tdSql.checkEqual(tdSql.queryResult[0][34], item[4])
+ tdSql.checkEqual(tdSql.queryResult[0][35], item[5])
+ tdSql.checkEqual(tdSql.queryResult[0][36], item[6])
+ self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {item[5]} COMPACT_TIME_OFFSET {item[6]}')
+
+ tdSql.execute(f'alter database {item[0]} compact_time_offset {item[3]}', queryTimes=10)
+ tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
+ tdSql.checkEqual(tdSql.queryResult[0][34], item[4])
+ tdSql.checkEqual(tdSql.queryResult[0][35], item[5])
+ tdSql.checkEqual(tdSql.queryResult[0][36], item[6])
+ self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {item[5]} COMPACT_TIME_OFFSET {item[6]}')
+ index += 1
+ for item in compact_separate_options:
+ tdSql.execute(f'drop database {item[0]}', queryTimes=10)
def compact_error(self):
compact_err_list = [["compact_time_range 86400m,61d", "Invalid option compact_time_range: 86400m, start time should be in range: [-5256000m, -14400m]"],
From 7b69c29c9ea0025e958e377ca20419a0901f14fe Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sun, 29 Dec 2024 12:49:03 +0800
Subject: [PATCH 39/56] test: add test case for auto compact
---
source/dnode/mnode/impl/src/mndDb.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index 2db148ec98..3444b88807 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -507,8 +507,9 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
return code;
if (pCfg->compactEndTime != 0 &&
(pCfg->compactEndTime < -pCfg->daysToKeep2 || pCfg->compactEndTime > -pCfg->daysPerFile))
- if (pCfg->compactStartTime != 0 && pCfg->compactEndTime != 0 && pCfg->compactStartTime > pCfg->compactEndTime)
- return code;
+ return code;
+ if (pCfg->compactStartTime != 0 && pCfg->compactEndTime != 0 && pCfg->compactStartTime >= pCfg->compactEndTime)
+ return code;
if (pCfg->compactTimeOffset < TSDB_MIN_COMPACT_TIME_OFFSET || pCfg->compactTimeOffset > TSDB_MAX_COMPACT_TIME_OFFSET)
return code;
@@ -585,9 +586,10 @@ static int32_t mndCheckInChangeDbCfg(SMnode *pMnode, SDbCfg *pOldCfg, SDbCfg *pN
return code;
if (pNewCfg->compactEndTime != 0 &&
(pNewCfg->compactEndTime < -pNewCfg->daysToKeep2 || pNewCfg->compactEndTime > -pNewCfg->daysPerFile))
- if (pNewCfg->compactStartTime != 0 && pNewCfg->compactEndTime != 0 &&
- pNewCfg->compactStartTime > pNewCfg->compactEndTime)
- return code;
+ return code;
+ if (pNewCfg->compactStartTime != 0 && pNewCfg->compactEndTime != 0 &&
+ pNewCfg->compactStartTime >= pNewCfg->compactEndTime)
+ return code;
if (pNewCfg->compactTimeOffset < TSDB_MIN_COMPACT_TIME_OFFSET ||
pNewCfg->compactTimeOffset > TSDB_MAX_COMPACT_TIME_OFFSET)
return code;
From f529339fb80f5ee4bc0ce6f8a0fe61fe6d27557f Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sun, 29 Dec 2024 13:26:40 +0800
Subject: [PATCH 40/56] test: add test case for auto compact
---
source/dnode/mnode/impl/src/mndDb.c | 12 ++++++++++--
tests/system-test/0-others/compact_auto.py | 4 ++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index 3444b88807..47d9ab12fc 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -2601,8 +2601,16 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER);
}
- len = formatDurationOrKeep(durationStr, sizeof(durationStr), pDb->cfg.compactStartTime);
- TAOS_UNUSED(formatDurationOrKeep(durationVstr, sizeof(durationVstr), pDb->cfg.compactEndTime));
+ int32_t compactStartTime = pDb->cfg.compactStartTime;
+ int32_t compactEndTime = pDb->cfg.compactEndTime;
+ if(compactStartTime == 0 && pDb->cfg.compactInterval > 0) {
+ compactStartTime = -pDb->cfg.daysToKeep2;
+ }
+ if(compactEndTime == 0 && pDb->cfg.compactInterval > 0) {
+ compactEndTime = -pDb->cfg.daysPerFile;
+ }
+ len = formatDurationOrKeep(durationStr, sizeof(durationStr), compactStartTime);
+ TAOS_UNUSED(formatDurationOrKeep(durationVstr, sizeof(durationVstr), compactEndTime));
TAOS_UNUSED(snprintf(durationStr + len, sizeof(durationStr) - len, ",%s", durationVstr));
STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr));
if ((pColInfo = taosArrayGet(pBlock->pDataBlock, cols++))) {
diff --git a/tests/system-test/0-others/compact_auto.py b/tests/system-test/0-others/compact_auto.py
index 4cfeec5b62..c6ef169c8c 100644
--- a/tests/system-test/0-others/compact_auto.py
+++ b/tests/system-test/0-others/compact_auto.py
@@ -93,11 +93,12 @@ class TDTestCase:
tdSql.execute(f'alter database {item[0]} compact_interval {item[1]}', queryTimes=10)
tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
tdSql.checkEqual(tdSql.queryResult[0][34], item[4])
- tdSql.checkEqual(tdSql.queryResult[0][35], self.default_compact_options[1])
tdSql.checkEqual(tdSql.queryResult[0][36], item[6])
if index == 0:
+ tdSql.checkEqual(tdSql.queryResult[0][35], item[5])
self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {self.default_compact_options[1]} COMPACT_TIME_OFFSET {item[6]}')
else:
+ tdSql.checkEqual(tdSql.queryResult[0][35], "-3650d,-1d")
self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE -3650d,-1d COMPACT_TIME_OFFSET {item[6]}')
tdSql.execute(f'alter database {item[0]} compact_time_range {item[2]}', queryTimes=10)
tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
@@ -105,7 +106,6 @@ class TDTestCase:
tdSql.checkEqual(tdSql.queryResult[0][35], item[5])
tdSql.checkEqual(tdSql.queryResult[0][36], item[6])
self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {item[5]} COMPACT_TIME_OFFSET {item[6]}')
-
tdSql.execute(f'alter database {item[0]} compact_time_offset {item[3]}', queryTimes=10)
tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
tdSql.checkEqual(tdSql.queryResult[0][34], item[4])
From 458a72c66ad15c2997ab3aa319688de11b1307e4 Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sun, 29 Dec 2024 13:45:59 +0800
Subject: [PATCH 41/56] test: add test case for auto compact
---
source/dnode/mnode/impl/src/mndDb.c | 20 ++------------------
tests/system-test/0-others/compact_auto.py | 10 ++--------
2 files changed, 4 insertions(+), 26 deletions(-)
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index 47d9ab12fc..43abc842f4 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -1445,14 +1445,6 @@ static void mndDumpDbCfgInfo(SDbCfgRsp *cfgRsp, SDbObj *pDb) {
cfgRsp->compactInterval = pDb->cfg.compactInterval;
cfgRsp->compactStartTime = pDb->cfg.compactStartTime;
cfgRsp->compactEndTime = pDb->cfg.compactEndTime;
- if (cfgRsp->compactInterval > 0) {
- if (cfgRsp->compactStartTime == 0) {
- cfgRsp->compactStartTime = -cfgRsp->daysToKeep2;
- }
- if (cfgRsp->compactEndTime == 0) {
- cfgRsp->compactEndTime = -cfgRsp->daysPerFile;
- }
- }
cfgRsp->compactTimeOffset = pDb->cfg.compactTimeOffset;
}
@@ -2601,16 +2593,8 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER);
}
- int32_t compactStartTime = pDb->cfg.compactStartTime;
- int32_t compactEndTime = pDb->cfg.compactEndTime;
- if(compactStartTime == 0 && pDb->cfg.compactInterval > 0) {
- compactStartTime = -pDb->cfg.daysToKeep2;
- }
- if(compactEndTime == 0 && pDb->cfg.compactInterval > 0) {
- compactEndTime = -pDb->cfg.daysPerFile;
- }
- len = formatDurationOrKeep(durationStr, sizeof(durationStr), compactStartTime);
- TAOS_UNUSED(formatDurationOrKeep(durationVstr, sizeof(durationVstr), compactEndTime));
+ len = formatDurationOrKeep(durationStr, sizeof(durationStr), pDb->cfg.compactStartTime);
+ TAOS_UNUSED(formatDurationOrKeep(durationVstr, sizeof(durationVstr), pDb->cfg.compactEndTime));
TAOS_UNUSED(snprintf(durationStr + len, sizeof(durationStr) - len, ",%s", durationVstr));
STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr));
if ((pColInfo = taosArrayGet(pBlock->pDataBlock, cols++))) {
diff --git a/tests/system-test/0-others/compact_auto.py b/tests/system-test/0-others/compact_auto.py
index c6ef169c8c..dbf050e00a 100644
--- a/tests/system-test/0-others/compact_auto.py
+++ b/tests/system-test/0-others/compact_auto.py
@@ -74,7 +74,6 @@ class TDTestCase:
tdLog.info("alter db compact options separately")
compact_separate_options = [["db100", "0m", "-0d,0", "0", "0d", "0d,0d", "0h"],
["db101", "10m", "-2d,-1", "1", "10m", "-2d,-1d", "1h"]]
- index = 0
for item in compact_separate_options:
tdSql.execute(f'create database {item[0]} duration 1d')
tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
@@ -93,13 +92,9 @@ class TDTestCase:
tdSql.execute(f'alter database {item[0]} compact_interval {item[1]}', queryTimes=10)
tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
tdSql.checkEqual(tdSql.queryResult[0][34], item[4])
+ tdSql.checkEqual(tdSql.queryResult[0][35], self.default_compact_options[1])
tdSql.checkEqual(tdSql.queryResult[0][36], item[6])
- if index == 0:
- tdSql.checkEqual(tdSql.queryResult[0][35], item[5])
- self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {self.default_compact_options[1]} COMPACT_TIME_OFFSET {item[6]}')
- else:
- tdSql.checkEqual(tdSql.queryResult[0][35], "-3650d,-1d")
- self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE -3650d,-1d COMPACT_TIME_OFFSET {item[6]}')
+ self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {self.default_compact_options[1]} COMPACT_TIME_OFFSET {item[6]}')
tdSql.execute(f'alter database {item[0]} compact_time_range {item[2]}', queryTimes=10)
tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"')
tdSql.checkEqual(tdSql.queryResult[0][34], item[4])
@@ -112,7 +107,6 @@ class TDTestCase:
tdSql.checkEqual(tdSql.queryResult[0][35], item[5])
tdSql.checkEqual(tdSql.queryResult[0][36], item[6])
self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {item[5]} COMPACT_TIME_OFFSET {item[6]}')
- index += 1
for item in compact_separate_options:
tdSql.execute(f'drop database {item[0]}', queryTimes=10)
From 28342a0e4472d2ee644b0a1714d8fb82cdab7603 Mon Sep 17 00:00:00 2001
From: WANG Xu
Date: Sun, 29 Dec 2024 15:44:34 +0800
Subject: [PATCH 42/56] refactor: break long lines with backslash
---
.github/workflows/taosd-ci-build.yml | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/.github/workflows/taosd-ci-build.yml b/.github/workflows/taosd-ci-build.yml
index 3adfde3460..d0915b9547 100644
--- a/.github/workflows/taosd-ci-build.yml
+++ b/.github/workflows/taosd-ci-build.yml
@@ -1,4 +1,4 @@
-name: TDengine CI
+name: TDengine Build
on:
pull_request:
@@ -29,14 +29,17 @@ jobs:
- name: Install system dependencies
run: |
sudo apt update -y
- sudo apt install -y build-essential cmake libgeos-dev libjansson-dev libsnappy-dev liblzma-dev libz-dev zlib1g pkg-config libssl-dev gawk
+ sudo apt install -y build-essential cmake \
+ libgeos-dev libjansson-dev libsnappy-dev liblzma-dev libz-dev \
+ zlib1g pkg-config libssl-dev gawk
- - name: Install TDengine
+ - name: Build and install TDengine
run: |
- mkdir debug
- cd debug
- cmake .. -DBUILD_HTTP=false -DBUILD_JDBC=false -DBUILD_TOOLS=true -DBUILD_TEST=off -DBUILD_KEEPER=true -DBUILD_DEPENDENCY_TESTS=false
+ mkdir debug && cd debug
+ cmake .. -DBUILD_HTTP=false -DBUILD_JDBC=false \
+ -DBUILD_TOOLS=true -DBUILD_TEST=off \
+ -DBUILD_KEEPER=true -DBUILD_DEPENDENCY_TESTS=false
make -j 4
sudo make install
which taosd
From a16681fecdac9b83fcefe532448b62a5639ef3ba Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sun, 29 Dec 2024 15:54:00 +0800
Subject: [PATCH 43/56] test: add test case for auto compact
---
source/libs/parser/src/parTranslater.c | 81 ++++++++++++--------------
1 file changed, 38 insertions(+), 43 deletions(-)
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index c4d6571adc..911d4cfe1c 100755
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -7809,23 +7809,23 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS
}
static int32_t checkRangeOption(STranslateContext* pCxt, int32_t code, const char* pName, int64_t val, int64_t minVal,
- int64_t maxVal, int8_t unit, bool skipUndef) {
+ int64_t maxVal, bool skipUndef) {
if (skipUndef ? ((val >= 0 || val < -2) && (val < minVal || val > maxVal)) : (val < minVal || val > maxVal)) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, code,
- "Invalid option %s: %" PRId64 "%c, valid range: [%" PRId64 "%c, %" PRId64 "%c]",
- pName, val, unit, minVal, unit, maxVal, unit);
+ "Invalid option %s: %" PRId64 ", valid range: [%" PRId64 ", %" PRId64 "]",
+ pName, val, minVal, maxVal);
}
return TSDB_CODE_SUCCESS;
}
static int32_t checkDbRangeOption(STranslateContext* pCxt, const char* pName, int64_t val, int64_t minVal,
- int64_t maxVal, int8_t unit) {
- return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_DB_OPTION, pName, val, minVal, maxVal, unit, true);
+ int64_t maxVal) {
+ return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_DB_OPTION, pName, val, minVal, maxVal, true);
}
static int32_t checkTableRangeOption(STranslateContext* pCxt, const char* pName, int64_t val, int64_t minVal,
int64_t maxVal) {
- return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_TABLE_OPTION, pName, val, minVal, maxVal, 0, true);
+ return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_TABLE_OPTION, pName, val, minVal, maxVal, true);
}
static int32_t checkDbS3KeepLocalOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
@@ -7841,8 +7841,8 @@ static int32_t checkDbS3KeepLocalOption(STranslateContext* pCxt, SDatabaseOption
}
pOptions->s3KeepLocal = getBigintFromValueNode(pOptions->s3KeepLocalStr);
}
- return checkDbRangeOption(pCxt, "s3KeepLocal", pOptions->s3KeepLocal, TSDB_MIN_S3_KEEP_LOCAL, TSDB_MAX_S3_KEEP_LOCAL,
- 0);
+ return checkDbRangeOption(pCxt, "s3KeepLocal", pOptions->s3KeepLocal, TSDB_MIN_S3_KEEP_LOCAL,
+ TSDB_MAX_S3_KEEP_LOCAL);
}
static int32_t checkDbDaysOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
@@ -7858,8 +7858,7 @@ static int32_t checkDbDaysOption(STranslateContext* pCxt, SDatabaseOptions* pOpt
}
pOptions->daysPerFile = getBigintFromValueNode(pOptions->pDaysPerFile);
}
- return checkDbRangeOption(pCxt, "daysPerFile", pOptions->daysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE,
- 0);
+ return checkDbRangeOption(pCxt, "daysPerFile", pOptions->daysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE);
}
static int32_t checkDbKeepOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
@@ -8198,7 +8197,7 @@ static int32_t checkDbCompactIntervalOption(STranslateContext* pCxt, const char*
TAOS_CHECK_RETURN(translateGetDbCfg(pCxt, pDbName, &pOptions->pDbCfg));
keep2 = pOptions->pDbCfg->daysToKeep2;
}
- code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2, TIME_UNIT_MINUTE);
+ code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2);
TAOS_CHECK_RETURN(code);
}
pOptions->compactInterval = (int32_t)interval;
@@ -8208,7 +8207,7 @@ static int32_t checkDbCompactIntervalOption(STranslateContext* pCxt, const char*
TAOS_CHECK_RETURN(translateGetDbCfg(pCxt, pDbName, &pOptions->pDbCfg));
keep2 = pOptions->pDbCfg->daysToKeep2;
}
- code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2, TIME_UNIT_MINUTE);
+ code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2);
TAOS_CHECK_RETURN(code);
pOptions->compactInterval = (int32_t)interval;
}
@@ -8299,12 +8298,12 @@ static int32_t checkDbCompactTimeOffsetOption(STranslateContext* pCxt, SDatabase
pOptions->compactTimeOffset = getBigintFromValueNode(pOptions->pCompactTimeOffsetNode) / 60;
}
return checkDbRangeOption(pCxt, "compact_time_offset", pOptions->compactTimeOffset, TSDB_MIN_COMPACT_TIME_OFFSET,
- TSDB_MAX_COMPACT_TIME_OFFSET, TIME_UNIT_HOUR);
+ TSDB_MAX_COMPACT_TIME_OFFSET);
}
static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions) {
int32_t code =
- checkDbRangeOption(pCxt, "buffer", pOptions->buffer, TSDB_MIN_BUFFER_PER_VNODE, TSDB_MAX_BUFFER_PER_VNODE, 0);
+ checkDbRangeOption(pCxt, "buffer", pOptions->buffer, TSDB_MIN_BUFFER_PER_VNODE, TSDB_MAX_BUFFER_PER_VNODE);
if (TSDB_CODE_SUCCESS == code) {
code = checkDbCacheModelOption(pCxt, pOptions);
}
@@ -8312,27 +8311,26 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
code = checkDbEncryptAlgorithmOption(pCxt, pOptions);
}
if (TSDB_CODE_SUCCESS == code) {
- code = checkDbRangeOption(pCxt, "cacheSize", pOptions->cacheLastSize, TSDB_MIN_DB_CACHE_SIZE,
- TSDB_MAX_DB_CACHE_SIZE, 0);
+ code =
+ checkDbRangeOption(pCxt, "cacheSize", pOptions->cacheLastSize, TSDB_MIN_DB_CACHE_SIZE, TSDB_MAX_DB_CACHE_SIZE);
}
if (TSDB_CODE_SUCCESS == code) {
- code = checkDbRangeOption(pCxt, "compression", pOptions->compressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL,
- 0);
+ code =
+ checkDbRangeOption(pCxt, "compression", pOptions->compressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbDaysOption(pCxt, pOptions);
}
if (TSDB_CODE_SUCCESS == code) {
- code =
- checkDbRangeOption(pCxt, "fsyncPeriod", pOptions->fsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD, 0);
+ code = checkDbRangeOption(pCxt, "fsyncPeriod", pOptions->fsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "maxRowsPerBlock", pOptions->maxRowsPerBlock, TSDB_MIN_MAXROWS_FBLOCK,
- TSDB_MAX_MAXROWS_FBLOCK, 0);
+ TSDB_MAX_MAXROWS_FBLOCK);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "minRowsPerBlock", pOptions->minRowsPerBlock, TSDB_MIN_MINROWS_FBLOCK,
- TSDB_MAX_MINROWS_FBLOCK, 0);
+ TSDB_MAX_MINROWS_FBLOCK);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbPrecisionOption(pCxt, pOptions);
@@ -8344,18 +8342,18 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
code = checkDbKeepTimeOffsetOption(pCxt, pOptions);
}
if (TSDB_CODE_SUCCESS == code) {
- code = checkDbRangeOption(pCxt, "pages", pOptions->pages, TSDB_MIN_PAGES_PER_VNODE, TSDB_MAX_PAGES_PER_VNODE, 0);
+ code = checkDbRangeOption(pCxt, "pages", pOptions->pages, TSDB_MIN_PAGES_PER_VNODE, TSDB_MAX_PAGES_PER_VNODE);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "pagesize", pOptions->pagesize, TSDB_MIN_PAGESIZE_PER_VNODE,
- TSDB_MAX_PAGESIZE_PER_VNODE, 0);
+ TSDB_MAX_PAGESIZE_PER_VNODE);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "tsdbPagesize", pOptions->tsdbPageSize, TSDB_MIN_TSDB_PAGESIZE,
- TSDB_MAX_TSDB_PAGESIZE, 0);
+ TSDB_MAX_TSDB_PAGESIZE);
}
if (TSDB_CODE_SUCCESS == code) {
- code = checkDbRangeOption(pCxt, "replications", pOptions->replica, TSDB_MIN_DB_REPLICA, TSDB_MAX_DB_REPLICA, 0);
+ code = checkDbRangeOption(pCxt, "replications", pOptions->replica, TSDB_MIN_DB_REPLICA, TSDB_MAX_DB_REPLICA);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbStrictOption(pCxt, pOptions);
@@ -8365,8 +8363,7 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
TSDB_MAX_WAL_LEVEL);
}
if (TSDB_CODE_SUCCESS == code) {
- code =
- checkDbRangeOption(pCxt, "vgroups", pOptions->numOfVgroups, TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB, 0);
+ code = checkDbRangeOption(pCxt, "vgroups", pOptions->numOfVgroups, TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbEnumOption(pCxt, "singleStable", pOptions->singleStable, TSDB_DB_SINGLE_STABLE_ON,
@@ -8380,23 +8377,21 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "walRetentionPeriod", pOptions->walRetentionPeriod,
- TSDB_DB_MIN_WAL_RETENTION_PERIOD, INT32_MAX, 0);
+ TSDB_DB_MIN_WAL_RETENTION_PERIOD, INT32_MAX);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "walRetentionSize", pOptions->walRetentionSize, TSDB_DB_MIN_WAL_RETENTION_SIZE,
- INT32_MAX, 0);
+ INT32_MAX);
+ }
+ if (TSDB_CODE_SUCCESS == code) {
+ code = checkDbRangeOption(pCxt, "walRollPeriod", pOptions->walRollPeriod, TSDB_DB_MIN_WAL_ROLL_PERIOD, INT32_MAX);
}
if (TSDB_CODE_SUCCESS == code) {
code =
- checkDbRangeOption(pCxt, "walRollPeriod", pOptions->walRollPeriod, TSDB_DB_MIN_WAL_ROLL_PERIOD, INT32_MAX, 0);
+ checkDbRangeOption(pCxt, "walSegmentSize", pOptions->walSegmentSize, TSDB_DB_MIN_WAL_SEGMENT_SIZE, INT32_MAX);
}
if (TSDB_CODE_SUCCESS == code) {
- code = checkDbRangeOption(pCxt, "walSegmentSize", pOptions->walSegmentSize, TSDB_DB_MIN_WAL_SEGMENT_SIZE, INT32_MAX,
- 0);
- }
- if (TSDB_CODE_SUCCESS == code) {
- code =
- checkDbRangeOption(pCxt, "sstTrigger", pOptions->sstTrigger, TSDB_MIN_STT_TRIGGER, TSDB_MAX_STT_TRIGGER, 0);
+ code = checkDbRangeOption(pCxt, "sstTrigger", pOptions->sstTrigger, TSDB_MIN_STT_TRIGGER, TSDB_MAX_STT_TRIGGER);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbEnumOption(pCxt, "withArbitrator", pOptions->withArbitrator, TSDB_MIN_DB_WITH_ARBITRATOR,
@@ -8417,10 +8412,10 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbRangeOption(pCxt, "s3_chunkpages", pOptions->s3ChunkSize, TSDB_MIN_S3_CHUNK_SIZE,
- TSDB_MAX_S3_CHUNK_SIZE, 0);
+ TSDB_MAX_S3_CHUNK_SIZE);
}
if (TSDB_CODE_SUCCESS == code) {
- code = checkDbRangeOption(pCxt, "s3_compact", pOptions->s3Compact, TSDB_MIN_S3_COMPACT, TSDB_MAX_S3_COMPACT, 0);
+ code = checkDbRangeOption(pCxt, "s3_compact", pOptions->s3Compact, TSDB_MIN_S3_COMPACT, TSDB_MAX_S3_COMPACT);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkDbCompactIntervalOption(pCxt, pDbName, pOptions);
@@ -9973,7 +9968,7 @@ static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* p
static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pStmt) {
int32_t code = 0;
SCreateUserReq createReq = {0};
- if ((code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, 0, false))) {
+ if ((code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, false))) {
return code;
}
tstrncpy(createReq.user, pStmt->userName, TSDB_USER_LEN);
@@ -10002,13 +9997,13 @@ static int32_t checkAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt) {
int32_t code = 0;
switch (pStmt->alterType) {
case TSDB_ALTER_USER_ENABLE:
- code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "enable", pStmt->enable, 0, 1, 0, false);
+ code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "enable", pStmt->enable, 0, 1, false);
break;
case TSDB_ALTER_USER_SYSINFO:
- code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, 0, false);
+ code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, false);
break;
case TSDB_ALTER_USER_CREATEDB:
- code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "createdb", pStmt->createdb, 0, 1, 0, false);
+ code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "createdb", pStmt->createdb, 0, 1, false);
break;
}
return code;
From 6987f3692ca1715263435c70e6cdadcc5eaa7115 Mon Sep 17 00:00:00 2001
From: WANG Xu
Date: Sun, 29 Dec 2024 15:57:41 +0800
Subject: [PATCH 44/56] chore: add build badge
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index f827c38975..33a3f948ce 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@
+[]
[](https://coveralls.io/github/taosdata/TDengine?branch=3.0)
[](https://bestpractices.coreinfrastructure.org/projects/4201)
From 7bf2864e8586f6737ee9708c57a3cbb823aea97b Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sun, 29 Dec 2024 15:59:01 +0800
Subject: [PATCH 45/56] test: add test case for auto compact
---
tests/system-test/0-others/compact_auto.py | 18 +++---
.../0-others/compact_auto_dispatch.py | 57 +++++++++++++++++++
2 files changed, 66 insertions(+), 9 deletions(-)
create mode 100644 tests/system-test/0-others/compact_auto_dispatch.py
diff --git a/tests/system-test/0-others/compact_auto.py b/tests/system-test/0-others/compact_auto.py
index dbf050e00a..813be3e9f0 100644
--- a/tests/system-test/0-others/compact_auto.py
+++ b/tests/system-test/0-others/compact_auto.py
@@ -133,20 +133,20 @@ class TDTestCase:
["compact_time_range -100;-90", "Invalid option compact_time_range, should have 2 value"],
["compact_time_range -100:-90", "syntax error near"],
["compact_time_range -100 -90", "syntax error near"],
- ["compact_interval 1m", "Invalid option compact_interval: 1m, valid range: [10m, 5256000m]"],
- ["compact_interval 199999999999m", "valid range: [10m, 5256000m]"],
- ["compact_interval 9999999999999m", "Invalid option compact_interval: 9999999999999m, valid range: [10m, 5256000m]"],
- ["compact_interval 5256001m", "Invalid option compact_interval: 5256001m, valid range: [10m, 5256000m]"],
- ["compact_interval 3651", "Invalid option compact_interval: 5257440m, valid range: [10m, 5256000m]"],
+ ["compact_interval 1m", "Invalid option compact_interval: 1, valid range: [10, 5256000]"],
+ ["compact_interval 199999999999m", "valid range: [10, 5256000]"],
+ ["compact_interval 9999999999999m", "Invalid option compact_interval: 9999999999999, valid range: [10, 5256000]"],
+ ["compact_interval 5256001m", "Invalid option compact_interval: 5256001, valid range: [10, 5256000]"],
+ ["compact_interval 3651", "Invalid option compact_interval: 5257440, valid range: [10, 5256000]"],
["compact_interval 86400s", "Invalid option compact_interval unit: s, only m, h, d allowed"],
["compact_interval -1", "syntax error near"],
["compact_time_offset -1", "syntax error near"],
["compact_time_offset 3600s", "Invalid option compact_time_offset unit: s, only h allowed"],
["compact_time_offset 1d", "Invalid option compact_time_offset unit: d, only h allowed"],
- ["compact_time_offset 24", "Invalid option compact_time_offset: 24h, valid range: [0h, 23h]"],
- ["compact_time_offset 24h", "Invalid option compact_time_offset: 24h, valid range: [0h, 23h]"],
- ["compact_time_offset 9999999999999", "valid range: [0h, 23h]"],
- ["compact_time_offset 199999999999", "valid range: [0h, 23h]"],
+ ["compact_time_offset 24", "Invalid option compact_time_offset: 24, valid range: [0, 23]"],
+ ["compact_time_offset 24h", "Invalid option compact_time_offset: 24, valid range: [0, 23]"],
+ ["compact_time_offset 9999999999999", "valid range: [0, 23]"],
+ ["compact_time_offset 199999999999", "valid range: [0, 23]"],
["compact_time_offset 1d", "Invalid option compact_time_offset unit: d, only h allowed"],
["compact_interval 10m compact_time_range -120d,-60 compact_time_offset 1d", "Invalid option compact_time_offset unit: d, only h allowed"],
]
diff --git a/tests/system-test/0-others/compact_auto_dispatch.py b/tests/system-test/0-others/compact_auto_dispatch.py
new file mode 100644
index 0000000000..0d83974354
--- /dev/null
+++ b/tests/system-test/0-others/compact_auto_dispatch.py
@@ -0,0 +1,57 @@
+import taos
+import sys
+import time
+import socket
+import os
+import threading
+import psutil
+import platform
+from util.log import *
+from util.sql import *
+from util.cases import *
+from util.dnodes import *
+
+
+class TDTestCase:
+ def init(self, conn, logSql, replicaVar=1):
+ self.replicaVar = int(replicaVar)
+ tdLog.debug("start to execute %s" % __file__)
+ tdSql.init(conn.cursor(), logSql)
+
+ def compact_auto_dispatch(self):
+ tdLog.info("compact_auto_dispatch")
+ tdSql.execute("drop database if exists db")
+ tdSql.execute("create database db duration 1d compact_interval 10m compact_time_range -2d,-1d compact_time_offset 10")
+ tdSql.execute("create table db.stb (ts timestamp, a int) tags (tag1 binary(8))")
+ tdSql.execute("create table db.c1 using db.stb tags('c1')")
+ nowSec = time.time()
+ for i in range(2):
+ insertSql = f"insert into db.c1 values (%d, 1) tags('c1')" %(1000*(nowSec - 8640*i))
+ tdLog.info(f"sql: {insertSql}")
+ tdSql.execute(insertSql)
+ tdSql.execute("select count(*) from db.c1")
+ tdSql.checkRows(100)
+
+ def checkShowCreateWithTimeout(self, db, expectResult, timeout=30):
+ result = False
+ for i in range(timeout):
+ tdSql.query(f'show create database `%s`' %(db))
+ tdSql.checkEqual(tdSql.queryResult[0][0], db)
+ if expectResult in tdSql.queryResult[0][1]:
+ result = True
+ break
+ time.sleep(1)
+ if result == False:
+ raise Exception(f"Unexpected result of 'show create database `{db}`':{tdSql.queryResult[0][1]}, expect:{expectResult}")
+
+
+ def run(self):
+ self.compact_auto_dispatch()
+
+ def stop(self):
+ tdSql.close()
+ tdLog.success(f"{__file__} successfully executed")
+
+
+tdCases.addLinux(__file__, TDTestCase())
+tdCases.addWindows(__file__, TDTestCase())
From 4221ee720c89a82deff5ff13f76f0a786ecd3d08 Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sun, 29 Dec 2024 16:01:34 +0800
Subject: [PATCH 46/56] test: add test case for auto compact
---
.../0-others/compact_auto_dispatch.py | 57 -------------------
1 file changed, 57 deletions(-)
delete mode 100644 tests/system-test/0-others/compact_auto_dispatch.py
diff --git a/tests/system-test/0-others/compact_auto_dispatch.py b/tests/system-test/0-others/compact_auto_dispatch.py
deleted file mode 100644
index 0d83974354..0000000000
--- a/tests/system-test/0-others/compact_auto_dispatch.py
+++ /dev/null
@@ -1,57 +0,0 @@
-import taos
-import sys
-import time
-import socket
-import os
-import threading
-import psutil
-import platform
-from util.log import *
-from util.sql import *
-from util.cases import *
-from util.dnodes import *
-
-
-class TDTestCase:
- def init(self, conn, logSql, replicaVar=1):
- self.replicaVar = int(replicaVar)
- tdLog.debug("start to execute %s" % __file__)
- tdSql.init(conn.cursor(), logSql)
-
- def compact_auto_dispatch(self):
- tdLog.info("compact_auto_dispatch")
- tdSql.execute("drop database if exists db")
- tdSql.execute("create database db duration 1d compact_interval 10m compact_time_range -2d,-1d compact_time_offset 10")
- tdSql.execute("create table db.stb (ts timestamp, a int) tags (tag1 binary(8))")
- tdSql.execute("create table db.c1 using db.stb tags('c1')")
- nowSec = time.time()
- for i in range(2):
- insertSql = f"insert into db.c1 values (%d, 1) tags('c1')" %(1000*(nowSec - 8640*i))
- tdLog.info(f"sql: {insertSql}")
- tdSql.execute(insertSql)
- tdSql.execute("select count(*) from db.c1")
- tdSql.checkRows(100)
-
- def checkShowCreateWithTimeout(self, db, expectResult, timeout=30):
- result = False
- for i in range(timeout):
- tdSql.query(f'show create database `%s`' %(db))
- tdSql.checkEqual(tdSql.queryResult[0][0], db)
- if expectResult in tdSql.queryResult[0][1]:
- result = True
- break
- time.sleep(1)
- if result == False:
- raise Exception(f"Unexpected result of 'show create database `{db}`':{tdSql.queryResult[0][1]}, expect:{expectResult}")
-
-
- def run(self):
- self.compact_auto_dispatch()
-
- def stop(self):
- tdSql.close()
- tdLog.success(f"{__file__} successfully executed")
-
-
-tdCases.addLinux(__file__, TDTestCase())
-tdCases.addWindows(__file__, TDTestCase())
From d855b4f59a7991271161da70771abe7a07bf591a Mon Sep 17 00:00:00 2001
From: WANG Xu
Date: Sun, 29 Dec 2024 16:04:48 +0800
Subject: [PATCH 47/56] add link to the build workflow
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 33a3f948ce..ff72412434 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@
-[]
+[](https://github.com/taosdata/TDengine/actions/workflows/taosd-ci-build.yml)
[](https://coveralls.io/github/taosdata/TDengine?branch=3.0)
[](https://bestpractices.coreinfrastructure.org/projects/4201)
From b478a9336cf7d3d3f518df04a67c0ce35ff02e6d Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sun, 29 Dec 2024 16:15:45 +0800
Subject: [PATCH 48/56] test: add test case for auto compact
---
source/libs/parser/src/parTranslater.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index 911d4cfe1c..374212cc52 100755
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -7812,8 +7812,8 @@ static int32_t checkRangeOption(STranslateContext* pCxt, int32_t code, const cha
int64_t maxVal, bool skipUndef) {
if (skipUndef ? ((val >= 0 || val < -2) && (val < minVal || val > maxVal)) : (val < minVal || val > maxVal)) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, code,
- "Invalid option %s: %" PRId64 ", valid range: [%" PRId64 ", %" PRId64 "]",
- pName, val, minVal, maxVal);
+ "Invalid option %s: %" PRId64 ", valid range: [%" PRId64 ", %" PRId64 "]", pName,
+ val, minVal, maxVal);
}
return TSDB_CODE_SUCCESS;
}
@@ -7841,8 +7841,7 @@ static int32_t checkDbS3KeepLocalOption(STranslateContext* pCxt, SDatabaseOption
}
pOptions->s3KeepLocal = getBigintFromValueNode(pOptions->s3KeepLocalStr);
}
- return checkDbRangeOption(pCxt, "s3KeepLocal", pOptions->s3KeepLocal, TSDB_MIN_S3_KEEP_LOCAL,
- TSDB_MAX_S3_KEEP_LOCAL);
+ return checkDbRangeOption(pCxt, "s3KeepLocal", pOptions->s3KeepLocal, TSDB_MIN_S3_KEEP_LOCAL, TSDB_MAX_S3_KEEP_LOCAL);
}
static int32_t checkDbDaysOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
From 1dbf9e1c2275efbfa922d2e1dbe13dfc8263699f Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sun, 29 Dec 2024 16:33:36 +0800
Subject: [PATCH 49/56] test: add test case for auto compact
---
tests/develop-test/2-query/show_create_db.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/develop-test/2-query/show_create_db.py b/tests/develop-test/2-query/show_create_db.py
index e59121f631..16e9b1d62c 100644
--- a/tests/develop-test/2-query/show_create_db.py
+++ b/tests/develop-test/2-query/show_create_db.py
@@ -47,7 +47,7 @@ class TDTestCase:
tdSql.query('show create database scd2;')
tdSql.checkRows(1)
tdSql.checkData(0, 0, 'scd2')
- tdSql.checkData(0, 1, "CREATE DATABASE `scd2` BUFFER 256 CACHESIZE 1 CACHEMODEL 'none' COMP 2 DURATION 10d WAL_FSYNC_PERIOD 3000 MAXROWS 4096 MINROWS 100 STT_TRIGGER 3 KEEP 3650d,3650d,3650d PAGES 256 PAGESIZE 4 PRECISION 'ms' REPLICA 1 WAL_LEVEL 1 VGROUPS 2 SINGLE_STABLE 0 TABLE_PREFIX 0 TABLE_SUFFIX 0 TSDB_PAGESIZE 4 WAL_RETENTION_PERIOD 3600 WAL_RETENTION_SIZE 0 KEEP_TIME_OFFSET 0h ENCRYPT_ALGORITHM 'none' S3_CHUNKPAGES 131072 S3_KEEPLOCAL 525600m S3_COMPACT 1 COMPACT_INTERVAL 1d COMPACT_TIME_RANGE -3650d,-10d COMPACT_TIME_OFFSET 0h")
+ tdSql.checkData(0, 1, "CREATE DATABASE `scd2` BUFFER 256 CACHESIZE 1 CACHEMODEL 'none' COMP 2 DURATION 10d WAL_FSYNC_PERIOD 3000 MAXROWS 4096 MINROWS 100 STT_TRIGGER 3 KEEP 3650d,3650d,3650d PAGES 256 PAGESIZE 4 PRECISION 'ms' REPLICA 1 WAL_LEVEL 1 VGROUPS 2 SINGLE_STABLE 0 TABLE_PREFIX 0 TABLE_SUFFIX 0 TSDB_PAGESIZE 4 WAL_RETENTION_PERIOD 3600 WAL_RETENTION_SIZE 0 KEEP_TIME_OFFSET 0h ENCRYPT_ALGORITHM 'none' S3_CHUNKPAGES 131072 S3_KEEPLOCAL 525600m S3_COMPACT 1 COMPACT_INTERVAL 1d COMPACT_TIME_RANGE 0d,0d COMPACT_TIME_OFFSET 0h")
tdSql.query('show create database scd4')
tdSql.checkRows(1)
@@ -65,7 +65,7 @@ class TDTestCase:
tdSql.query('show create database scd2;')
tdSql.checkRows(1)
tdSql.checkData(0, 0, 'scd2')
- tdSql.checkData(0, 1, "CREATE DATABASE `scd2` BUFFER 256 CACHESIZE 1 CACHEMODEL 'none' COMP 2 DURATION 10d WAL_FSYNC_PERIOD 3000 MAXROWS 4096 MINROWS 100 STT_TRIGGER 3 KEEP 3650d,3650d,3650d PAGES 256 PAGESIZE 4 PRECISION 'ms' REPLICA 1 WAL_LEVEL 1 VGROUPS 2 SINGLE_STABLE 0 TABLE_PREFIX 0 TABLE_SUFFIX 0 TSDB_PAGESIZE 4 WAL_RETENTION_PERIOD 3600 WAL_RETENTION_SIZE 0 KEEP_TIME_OFFSET 0h ENCRYPT_ALGORITHM 'none' S3_CHUNKPAGES 131072 S3_KEEPLOCAL 525600m S3_COMPACT 1 COMPACT_INTERVAL 1d COMPACT_TIME_RANGE -3650d,-10d COMPACT_TIME_OFFSET 0h")
+ tdSql.checkData(0, 1, "CREATE DATABASE `scd2` BUFFER 256 CACHESIZE 1 CACHEMODEL 'none' COMP 2 DURATION 10d WAL_FSYNC_PERIOD 3000 MAXROWS 4096 MINROWS 100 STT_TRIGGER 3 KEEP 3650d,3650d,3650d PAGES 256 PAGESIZE 4 PRECISION 'ms' REPLICA 1 WAL_LEVEL 1 VGROUPS 2 SINGLE_STABLE 0 TABLE_PREFIX 0 TABLE_SUFFIX 0 TSDB_PAGESIZE 4 WAL_RETENTION_PERIOD 3600 WAL_RETENTION_SIZE 0 KEEP_TIME_OFFSET 0h ENCRYPT_ALGORITHM 'none' S3_CHUNKPAGES 131072 S3_KEEPLOCAL 525600m S3_COMPACT 1 COMPACT_INTERVAL 1d COMPACT_TIME_RANGE 0d,0d COMPACT_TIME_OFFSET 0h")
tdSql.query('show create database scd4')
tdSql.checkRows(1)
tdSql.checkData(0, 0, 'scd4')
From 7c2c437a633effe90082ca0c66db85c81ee033ec Mon Sep 17 00:00:00 2001
From: WANG Xu
Date: Sun, 29 Dec 2024 16:40:57 +0800
Subject: [PATCH 50/56] refactor: build trigger [skip ci]
---
.github/workflows/taosd-ci-build.yml | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/.github/workflows/taosd-ci-build.yml b/.github/workflows/taosd-ci-build.yml
index d0915b9547..0876f5b731 100644
--- a/.github/workflows/taosd-ci-build.yml
+++ b/.github/workflows/taosd-ci-build.yml
@@ -6,12 +6,11 @@ on:
- 'main'
- '3.0'
- '3.1'
- push:
- branches:
- - '3.0'
- - '3.1'
- - 'main'
-
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
jobs:
build:
runs-on: ubuntu-latest
From 080ebb1b8f8f488a9d26510c696e33e8abd2ab48 Mon Sep 17 00:00:00 2001
From: Shengliang Guan
Date: Sun, 29 Dec 2024 17:23:22 +0800
Subject: [PATCH 51/56] git: set tags
---
cmake/taosadapter_CMakeLists.txt.in | 2 +-
cmake/taostools_CMakeLists.txt.in | 2 +-
cmake/taosws_CMakeLists.txt.in | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/cmake/taosadapter_CMakeLists.txt.in b/cmake/taosadapter_CMakeLists.txt.in
index 13826a1a74..ef6ed4af1d 100644
--- a/cmake/taosadapter_CMakeLists.txt.in
+++ b/cmake/taosadapter_CMakeLists.txt.in
@@ -2,7 +2,7 @@
# taosadapter
ExternalProject_Add(taosadapter
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
- GIT_TAG main
+ GIT_TAG 3.0
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
diff --git a/cmake/taostools_CMakeLists.txt.in b/cmake/taostools_CMakeLists.txt.in
index 9bbda8309f..9a6a5329ae 100644
--- a/cmake/taostools_CMakeLists.txt.in
+++ b/cmake/taostools_CMakeLists.txt.in
@@ -2,7 +2,7 @@
# taos-tools
ExternalProject_Add(taos-tools
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
- GIT_TAG main
+ GIT_TAG 3.0
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
diff --git a/cmake/taosws_CMakeLists.txt.in b/cmake/taosws_CMakeLists.txt.in
index b013d45911..17446d184d 100644
--- a/cmake/taosws_CMakeLists.txt.in
+++ b/cmake/taosws_CMakeLists.txt.in
@@ -2,7 +2,7 @@
# taosws-rs
ExternalProject_Add(taosws-rs
GIT_REPOSITORY https://github.com/taosdata/taos-connector-rust.git
- GIT_TAG main
+ GIT_TAG 3.0
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosws-rs"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
From 7dffc9388adaf8dcb4b5626f40cacae88edefc74 Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sun, 29 Dec 2024 17:28:23 +0800
Subject: [PATCH 52/56] enh: robustness of test case
---
tests/system-test/2-query/elapsed.py | 2 +-
tests/system-test/2-query/statecount.py | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/system-test/2-query/elapsed.py b/tests/system-test/2-query/elapsed.py
index dc89cd513d..c1191c3441 100644
--- a/tests/system-test/2-query/elapsed.py
+++ b/tests/system-test/2-query/elapsed.py
@@ -1542,7 +1542,7 @@ class TDTestCase:
def query_precision(self):
def generate_data(precision="ms"):
- tdSql.execute("create database if not exists db_%s precision '%s';" %(precision, precision))
+ tdSql.execute("create database if not exists db_%s keep 36500 precision '%s';" %(precision, precision))
tdSql.execute("use db_%s;" %precision)
tdSql.execute("create stable db_%s.st (ts timestamp , id int) tags(ind int);"%precision)
tdSql.execute("create table db_%s.tb1 using st tags(1);"%precision)
diff --git a/tests/system-test/2-query/statecount.py b/tests/system-test/2-query/statecount.py
index 006215956b..f5dba2df4f 100644
--- a/tests/system-test/2-query/statecount.py
+++ b/tests/system-test/2-query/statecount.py
@@ -395,7 +395,7 @@ class TDTestCase:
def query_precision(self):
def generate_data(precision="ms"):
dbname = f"db_{precision}"
- tdSql.execute(f"create database if not exists db_%s precision '%s';" %(precision, precision))
+ tdSql.execute(f"create database if not exists db_%s keep 36500 precision '%s';" %(precision, precision))
tdSql.execute("use db_%s;" %precision)
tdSql.execute(f"create stable db_%s.st (ts timestamp , id int) tags(ind int);"%precision)
tdSql.execute(f"create table db_%s.tb1 using {dbname}.st tags(1);"%precision)
@@ -449,7 +449,7 @@ class TDTestCase:
def check_boundary_values(self, dbname="bound_test"):
tdSql.execute(f"drop database if exists {dbname}")
- tdSql.execute(f"create database if not exists {dbname}")
+ tdSql.execute(f"create database if not exists {dbname} keep 36500")
tdSql.execute(
f"create table {dbname}.stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);"
)
From c5a1f7b791be9a2efe7165b1b1c50aadd63452ef Mon Sep 17 00:00:00 2001
From: kailixu
Date: Sun, 29 Dec 2024 18:36:46 +0800
Subject: [PATCH 53/56] chore: select linux test server
---
Jenkinsfile2 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Jenkinsfile2 b/Jenkinsfile2
index 1b2f28908c..4d74b3d2c2 100644
--- a/Jenkinsfile2
+++ b/Jenkinsfile2
@@ -508,7 +508,7 @@ pipeline {
}
}
stage('linux test') {
- agent{label "slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || slave1_59 || slave1_63 || worker03 || slave215 || slave217 || slave219 "}
+ agent{label "slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_59 || slave1_63 "}
options { skipDefaultCheckout() }
when {
changeRequest()
From 63e3e33f141a3b93d589c9ee578c7170e431e28f Mon Sep 17 00:00:00 2001
From: Shengliang Guan
Date: Sun, 29 Dec 2024 19:37:58 +0800
Subject: [PATCH 54/56] Revert "Revert "Revert "Enh:[td 29974]improve trans"""
---
docs/en/08-operation/04-maintenance.md | 2 +-
docs/en/14-reference/03-taos-sql/24-show.md | 3 +-
docs/zh/08-operation/04-maintenance.md | 2 +-
docs/zh/14-reference/03-taos-sql/24-show.md | 3 +-
include/common/systable.h | 1 -
include/common/tmsg.h | 2 -
include/libs/nodes/cmdnodes.h | 5 -
include/util/taoserror.h | 1 -
include/util/tdef.h | 6 +-
source/common/src/systable.c | 12 -
source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 1 -
source/dnode/mnode/impl/inc/mndDef.h | 8 -
source/dnode/mnode/impl/inc/mndTrans.h | 4 -
.../dnode/mnode/impl/src/mndCompactDetail.c | 2 -
source/dnode/mnode/impl/src/mndDb.c | 3 -
source/dnode/mnode/impl/src/mndShow.c | 5 +-
source/dnode/mnode/impl/src/mndTrans.c | 484 +-----------------
source/dnode/mnode/impl/src/mndVgroup.c | 16 +-
source/libs/executor/src/sysscanoperator.c | 3 +-
source/libs/nodes/src/nodesCodeFuncs.c | 2 -
source/libs/nodes/src/nodesUtilFuncs.c | 8 -
source/libs/parser/inc/parAst.h | 1 -
source/libs/parser/inc/sql.y | 1 -
source/libs/parser/src/parAstCreater.c | 12 -
source/libs/parser/src/parAstParser.c | 8 -
source/libs/parser/src/parTranslater.c | 51 +-
source/util/src/terror.c | 1 -
.../develop-test/2-query/table_count_scan.py | 16 +-
tests/parallel_test/cases.task | 3 -
tests/script/tsim/query/sys_tbname.sim | 2 +-
tests/script/tsim/query/tableCount.sim | 6 +-
.../0-others/information_schema.py | 6 +-
.../0-others/kill_balance_leader.py | 64 ---
.../0-others/show_transaction_detail.py | 115 -----
tests/system-test/2-query/union.py | 2 +-
.../restore/kill_restore_dnode.py | 90 ----
.../3-enterprise/restore/restoreBasic.py | 28 -
37 files changed, 50 insertions(+), 929 deletions(-)
delete mode 100644 tests/system-test/0-others/kill_balance_leader.py
delete mode 100644 tests/system-test/0-others/show_transaction_detail.py
delete mode 100644 tests/system-test/3-enterprise/restore/kill_restore_dnode.py
diff --git a/docs/en/08-operation/04-maintenance.md b/docs/en/08-operation/04-maintenance.md
index 2f6afbf9df..970ee40d18 100644
--- a/docs/en/08-operation/04-maintenance.md
+++ b/docs/en/08-operation/04-maintenance.md
@@ -17,7 +17,7 @@ TDengine is designed for various writing scenarios, and many of these scenarios
```sql
COMPACT DATABASE db_name [start with 'XXXX'] [end with 'YYYY'];
-SHOW COMPACT [compact_id];
+SHOW COMPACTS [compact_id];
KILL COMPACT compact_id;
```
diff --git a/docs/en/14-reference/03-taos-sql/24-show.md b/docs/en/14-reference/03-taos-sql/24-show.md
index b46fb41fa0..36c20df0b4 100644
--- a/docs/en/14-reference/03-taos-sql/24-show.md
+++ b/docs/en/14-reference/03-taos-sql/24-show.md
@@ -304,10 +304,9 @@ Displays information about all topics in the current database.
```sql
SHOW TRANSACTIONS;
-SHOW TRANSACTION [tranaction_id];
```
-Displays information about one of or all transaction(s) currently being executed in the system (these transactions are only for metadata level, not for regular tables).
+Displays information about transactions currently being executed in the system (these transactions are only for metadata level, not for regular tables).
## SHOW USERS
diff --git a/docs/zh/08-operation/04-maintenance.md b/docs/zh/08-operation/04-maintenance.md
index 429542485d..9ef165179d 100644
--- a/docs/zh/08-operation/04-maintenance.md
+++ b/docs/zh/08-operation/04-maintenance.md
@@ -19,7 +19,7 @@ TDengine 面向多种写入场景,而很多写入场景下,TDengine 的存
```SQL
COMPACT DATABASE db_name [start with 'XXXX'] [end with 'YYYY'];
COMPACT [db_name.]VGROUPS IN (vgroup_id1, vgroup_id2, ...) [start with 'XXXX'] [end with 'YYYY'];
-SHOW COMPACT [compact_id];
+SHOW COMPACTS [compact_id];
KILL COMPACT compact_id;
```
diff --git a/docs/zh/14-reference/03-taos-sql/24-show.md b/docs/zh/14-reference/03-taos-sql/24-show.md
index 3898920e65..4596a03281 100644
--- a/docs/zh/14-reference/03-taos-sql/24-show.md
+++ b/docs/zh/14-reference/03-taos-sql/24-show.md
@@ -306,10 +306,9 @@ SHOW TOPICS;
```sql
SHOW TRANSACTIONS;
-SHOW TRANSACTION [tranaction_id];
```
-显示当前系统中正在执行的所有或者某一个事务的信息(该事务仅针对除普通表以外的元数据级别)
+显示当前系统中正在执行的事务的信息(该事务仅针对除普通表以外的元数据级别)
## SHOW USERS
diff --git a/include/common/systable.h b/include/common/systable.h
index fe867c9ad0..bd8ba76f4f 100644
--- a/include/common/systable.h
+++ b/include/common/systable.h
@@ -63,7 +63,6 @@ extern "C" {
#define TSDB_INS_TABLE_TSMAS "ins_tsmas"
#define TSDB_INS_DISK_USAGE "ins_disk_usage"
#define TSDB_INS_TABLE_FILESETS "ins_filesets"
-#define TSDB_INS_TABLE_TRANSACTION_DETAILS "ins_transaction_details"
#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
#define TSDB_PERFS_TABLE_SMAS "perf_smas"
diff --git a/include/common/tmsg.h b/include/common/tmsg.h
index 9488e54615..0b6a8b3f1b 100644
--- a/include/common/tmsg.h
+++ b/include/common/tmsg.h
@@ -163,7 +163,6 @@ typedef enum _mgmt_table {
TSDB_MGMT_TABLE_ANODE_FULL,
TSDB_MGMT_TABLE_USAGE,
TSDB_MGMT_TABLE_FILESETS,
- TSDB_MGMT_TABLE_TRANSACTION_DETAIL,
TSDB_MGMT_TABLE_MAX,
} EShowType;
@@ -406,7 +405,6 @@ typedef enum ENodeType {
QUERY_NODE_SHOW_CREATE_TSMA_STMT,
QUERY_NODE_DROP_TSMA_STMT,
QUERY_NODE_SHOW_FILESETS_STMT,
- QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
// logic plan node
QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h
index 0f736e7068..8eb30b8184 100644
--- a/include/libs/nodes/cmdnodes.h
+++ b/include/libs/nodes/cmdnodes.h
@@ -439,11 +439,6 @@ typedef struct SShowCompactDetailsStmt {
SNode* pCompactId;
} SShowCompactDetailsStmt;
-typedef struct SShowTransactionDetailsStmt {
- ENodeType type;
- SNode* pTransactionId;
-} SShowTransactionDetailsStmt;
-
typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT, INDEX_TYPE_NORMAL } EIndexType;
typedef struct SIndexOptions {
diff --git a/include/util/taoserror.h b/include/util/taoserror.h
index 890758762a..e317fdd65a 100644
--- a/include/util/taoserror.h
+++ b/include/util/taoserror.h
@@ -411,7 +411,6 @@ int32_t taosGetErrSize();
#define TSDB_CODE_MND_TRANS_CTX_SWITCH TAOS_DEF_ERROR_CODE(0, 0x03D8)
#define TSDB_CODE_MND_TRANS_CONFLICT_COMPACT TAOS_DEF_ERROR_CODE(0, 0x03D9)
#define TSDB_CODE_MND_TRANS_UNKNOW_ERROR TAOS_DEF_ERROR_CODE(0, 0x03DF)
-#define TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED TAOS_DEF_ERROR_CODE(0, 0x03D2)
// mnode-mq
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E0)
diff --git a/include/util/tdef.h b/include/util/tdef.h
index 2b0aa00b1a..2ee84b42bd 100644
--- a/include/util/tdef.h
+++ b/include/util/tdef.h
@@ -329,11 +329,7 @@ typedef enum ELogicConditionType {
#define TSDB_TRANS_STAGE_LEN 12
#define TSDB_TRANS_TYPE_LEN 16
-#define TSDB_TRANS_ERROR_LEN 512
-#define TSDB_TRANS_OBJTYPE_LEN 40
-#define TSDB_TRANS_RESULT_LEN 100
-#define TSDB_TRANS_TARGET_LEN 300
-#define TSDB_TRANS_DETAIL_LEN 100
+#define TSDB_TRANS_ERROR_LEN 512
#define TSDB_STEP_NAME_LEN 32
#define TSDB_STEP_DESC_LEN 128
diff --git a/source/common/src/systable.c b/source/common/src/systable.c
index 38dce105bb..cb08046399 100644
--- a/source/common/src/systable.c
+++ b/source/common/src/systable.c
@@ -314,8 +314,6 @@ static const SSysDbTableSchema transSchema[] = {
{.name = "oper", .bytes = TSDB_TRANS_OPER_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "stable", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
- {.name = "killable", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
- //{.name = "kill_mnode", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "failed_times", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
{.name = "last_exec_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
{.name = "last_action_info", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
@@ -405,15 +403,6 @@ static const SSysDbTableSchema userCompactsDetailSchema[] = {
{.name = "remain_time(s)", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = false},
};
-static const SSysDbTableSchema userTransactionDetailSchema[] = {
- {.name = "transaction_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
- {.name = "action", .bytes = 30 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
- {.name = "obj_type", .bytes = TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
- {.name = "result", .bytes = TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
- {.name = "target", .bytes = TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
- {.name = "detail", .bytes = TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
-};
-
static const SSysDbTableSchema anodesSchema[] = {
{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
{.name = "url", .bytes = TSDB_ANALYTIC_ANODE_URL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
@@ -532,7 +521,6 @@ static const SSysTableMeta infosMeta[] = {
{TSDB_INS_TABLE_ANODES_FULL, anodesFullSchema, tListLen(anodesFullSchema), true},
{TSDB_INS_DISK_USAGE, diskUsageSchema, tListLen(diskUsageSchema), false},
{TSDB_INS_TABLE_FILESETS, filesetsFullSchema, tListLen(filesetsFullSchema), false},
- {TSDB_INS_TABLE_TRANSACTION_DETAILS, userTransactionDetailSchema, tListLen(userTransactionDetailSchema), false},
};
static const SSysDbTableSchema connectionsSchema[] = {
diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
index 423268a8cc..9ed4ee83c4 100644
--- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
+++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
@@ -681,7 +681,6 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
return TSDB_CODE_INVALID_MSG;
}
- dInfo("retrieve table:%s, user:%s, compactId:%" PRId64, retrieveReq.tb, retrieveReq.user, retrieveReq.compactId);
#if 0
if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
code = TSDB_CODE_MND_NO_RIGHTS;
diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h
index b32274e0a7..e3d2ad6d34 100644
--- a/source/dnode/mnode/impl/inc/mndDef.h
+++ b/source/dnode/mnode/impl/inc/mndDef.h
@@ -133,12 +133,6 @@ typedef enum {
TRN_EXEC_SERIAL = 1,
} ETrnExec;
-typedef enum {
- TRN_KILL_MODE_SKIP = 0,
- TRN_KILL_MODE_INTERUPT = 1,
- //TRN_KILL_MODE_ROLLBACK = 2,
-} ETrnKillMode;
-
typedef enum {
DND_REASON_ONLINE = 0,
DND_REASON_STATUS_MSG_TIMEOUT,
@@ -207,8 +201,6 @@ typedef struct {
SRWLatch lockRpcArray;
int64_t mTraceId;
TdThreadMutex mutex;
- bool ableToBeKilled;
- ETrnKillMode killMode;
} STrans;
typedef struct {
diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h
index 05280d0d68..7f039bc21f 100644
--- a/source/dnode/mnode/impl/inc/mndTrans.h
+++ b/source/dnode/mnode/impl/inc/mndTrans.h
@@ -54,8 +54,6 @@ typedef struct {
SSdbRaw *pRaw;
int64_t mTraceId;
- int64_t startTime;
- int64_t endTime;
} STransAction;
typedef void (*TransCbFp)(SMnode *pMnode, void *param, int32_t paramLen);
@@ -82,8 +80,6 @@ void mndTransSetCb(STrans *pTrans, ETrnFunc startFunc, ETrnFunc stopFunc, voi
void mndTransSetDbName(STrans *pTrans, const char *dbname, const char *stbname);
void mndTransAddArbGroupId(STrans *pTrans, int32_t groupId);
void mndTransSetSerial(STrans *pTrans);
-void mndTransSetBeKilled(STrans *pTrans, bool ableToBeKilled);
-void mndTransSetKillMode(STrans *pTrans, ETrnKillMode killMode);
void mndTransSetParallel(STrans *pTrans);
void mndTransSetChangeless(STrans *pTrans);
void mndTransSetOper(STrans *pTrans, EOperType oper);
diff --git a/source/dnode/mnode/impl/src/mndCompactDetail.c b/source/dnode/mnode/impl/src/mndCompactDetail.c
index 0052f5de56..9a053066b2 100644
--- a/source/dnode/mnode/impl/src/mndCompactDetail.c
+++ b/source/dnode/mnode/impl/src/mndCompactDetail.c
@@ -45,8 +45,6 @@ int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
char *sep = NULL;
SDbObj *pDb = NULL;
- mInfo("retrieve compact detail");
-
if (strlen(pShow->db) > 0) {
sep = strchr(pShow->db, '.');
if (sep &&
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index 1efbff9d53..c28fd343f0 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -1270,7 +1270,6 @@ static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *p
TAOS_RETURN(code);
}
mInfo("trans:%d, used to alter db:%s", pTrans->id, pOld->name);
- mInfo("trans:%d, used to alter db, ableToBeKilled:%d, killMode:%d", pTrans->id, pTrans->ableToBeKilled, pTrans->killMode);
mndTransSetDbName(pTrans, pOld->name, NULL);
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
@@ -1279,8 +1278,6 @@ static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *p
TAOS_CHECK_GOTO(mndSetAlterDbPrepareLogs(pMnode, pTrans, pOld, pNew), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterDbCommitLogs(pMnode, pTrans, pOld, pNew), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterDbRedoActions(pMnode, pTrans, pOld, pNew), NULL, _OVER);
-
- mInfo("trans:%d, used to alter db, ableToBeKilled:%d, killMode:%d", pTrans->id, pTrans->ableToBeKilled, pTrans->killMode);
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
code = 0;
diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c
index f19eabd885..49dc62d471 100644
--- a/source/dnode/mnode/impl/src/mndShow.c
+++ b/source/dnode/mnode/impl/src/mndShow.c
@@ -132,8 +132,6 @@ static int32_t convertToRetrieveType(char *name, int32_t len) {
type = TSDB_MGMT_TABLE_COMPACT;
} else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
- } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
- type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
} else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
type = TSDB_MGMT_TABLE_GRANTS_FULL;
} else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
@@ -238,8 +236,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
SRetrieveTableReq retrieveReq = {0};
TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq));
- mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
- retrieveReq.compactId);
+ mDebug("process to retrieve systable req db:%s, tb:%s", retrieveReq.db, retrieveReq.tb);
if (retrieveReq.showId == 0) {
STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c
index 83fad45919..718b7d0df6 100644
--- a/source/dnode/mnode/impl/src/mndTrans.c
+++ b/source/dnode/mnode/impl/src/mndTrans.c
@@ -14,21 +14,19 @@
*/
#define _DEFAULT_SOURCE
-#include "mndTrans.h"
#include "mndDb.h"
#include "mndPrivilege.h"
#include "mndShow.h"
#include "mndStb.h"
#include "mndSubscribe.h"
#include "mndSync.h"
+#include "mndTrans.h"
#include "mndUser.h"
-#include "mndVgroup.h"
-#include "osTime.h"
#define TRANS_VER1_NUMBER 1
#define TRANS_VER2_NUMBER 2
#define TRANS_ARRAY_SIZE 8
-#define TRANS_RESERVE_SIZE 42
+#define TRANS_RESERVE_SIZE 44
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans);
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *OldTrans, STrans *pOld);
@@ -72,7 +70,7 @@ static int32_t mndProcessKillTransReq(SRpcMsg *pReq);
static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter);
-static int32_t mndRetrieveTransDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
+
static int32_t tsMaxTransId = 0;
int32_t mndInitTrans(SMnode *pMnode) {
@@ -91,7 +89,6 @@ int32_t mndInitTrans(SMnode *pMnode) {
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndRetrieveTrans);
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndCancelGetNextTrans);
- mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TRANSACTION_DETAIL, mndRetrieveTransDetail);
return sdbSetTable(pMnode->pSdb, table);
}
@@ -159,7 +156,7 @@ SSdbRaw *mndTransEncode(STrans *pTrans) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_INVALID_MSG;
- int8_t sver = TRANS_VER2_NUMBER;
+ int8_t sver = taosArrayGetSize(pTrans->prepareActions) ? TRANS_VER2_NUMBER : TRANS_VER1_NUMBER;
int32_t rawDataLen = sizeof(STrans) + TRANS_RESERVE_SIZE + pTrans->paramLen;
rawDataLen += mndTransGetActionsSize(pTrans->prepareActions);
@@ -223,11 +220,6 @@ SSdbRaw *mndTransEncode(STrans *pTrans) {
pIter = taosHashIterate(pTrans->arbGroupIds, pIter);
}
- if (sver > TRANS_VER1_NUMBER) {
- SDB_SET_INT8(pRaw, dataPos, pTrans->ableToBeKilled, _OVER)
- SDB_SET_INT32(pRaw, dataPos, pTrans->killMode, _OVER)
- }
-
SDB_SET_RESERVE(pRaw, dataPos, TRANS_RESERVE_SIZE, _OVER)
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
@@ -318,7 +310,7 @@ SSdbRow *mndTransDecode(SSdbRaw *pRaw) {
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
- if (sver > TRANS_VER2_NUMBER) {
+ if (sver != TRANS_VER1_NUMBER && sver != TRANS_VER2_NUMBER) {
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
goto _OVER;
}
@@ -397,13 +389,6 @@ SSdbRow *mndTransDecode(SSdbRaw *pRaw) {
if ((terrno = taosHashPut(pTrans->arbGroupIds, &arbGroupId, sizeof(int32_t), NULL, 0)) != 0) goto _OVER;
}
- int8_t ableKill = 0;
- int8_t killMode = 0;
- SDB_GET_INT8(pRaw, dataPos, &ableKill, _OVER)
- SDB_GET_INT8(pRaw, dataPos, &killMode, _OVER)
- pTrans->ableToBeKilled = ableKill;
- pTrans->killMode = killMode;
-
SDB_GET_RESERVE(pRaw, dataPos, TRANS_RESERVE_SIZE, _OVER)
terrno = 0;
@@ -445,25 +430,12 @@ static const char *mndTransStr(ETrnStage stage) {
}
}
-static const char *mndTransTypeStr(ETrnAct actionType) {
- switch (actionType) {
- case TRANS_ACTION_MSG:
- return "msg";
- case TRANS_ACTION_RAW:
- return "sdb";
- default:
- return "invalid";
- }
-}
-
static void mndSetTransLastAction(STrans *pTrans, STransAction *pAction) {
if (pAction != NULL) {
- if (pAction->errCode != TSDB_CODE_ACTION_IN_PROGRESS) {
- pTrans->lastAction = pAction->id;
- pTrans->lastMsgType = pAction->msgType;
- pTrans->lastEpset = pAction->epSet;
- pTrans->lastErrorNo = pAction->errCode;
- }
+ pTrans->lastAction = pAction->id;
+ pTrans->lastMsgType = pAction->msgType;
+ pTrans->lastEpset = pAction->epSet;
+ pTrans->lastErrorNo = pAction->errCode;
} else {
pTrans->lastAction = 0;
pTrans->lastMsgType = 0;
@@ -664,7 +636,6 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnConflct conflict,
pTrans->policy = policy;
pTrans->conflict = conflict;
pTrans->exec = TRN_EXEC_PARALLEL;
- pTrans->ableToBeKilled = false;
pTrans->createdTime = taosGetTimestampMs();
pTrans->prepareActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
pTrans->redoActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
@@ -833,13 +804,6 @@ void mndTransAddArbGroupId(STrans *pTrans, int32_t groupId) {
void mndTransSetSerial(STrans *pTrans) { pTrans->exec = TRN_EXEC_SERIAL; }
-void mndTransSetBeKilled(STrans *pTrans, bool ableToBeKilled) { pTrans->ableToBeKilled = ableToBeKilled; }
-
-void mndTransSetKillMode(STrans *pTrans, ETrnKillMode killMode) {
- pTrans->ableToBeKilled = true;
- pTrans->killMode = killMode;
-}
-
void mndTransSetParallel(STrans *pTrans) { pTrans->exec = TRN_EXEC_PARALLEL; }
void mndTransSetChangeless(STrans *pTrans) { pTrans->changeless = true; }
@@ -1079,39 +1043,6 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
return TSDB_CODE_INVALID_PARA;
}
- mInfo("trans:%d, action list:", pTrans->id);
- int32_t index = 0;
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->prepareActions); ++i, ++index) {
- STransAction *pAction = taosArrayGet(pTrans->prepareActions, i);
- mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index,
- mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
- }
-
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->redoActions); ++i, ++index) {
- STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
- mInfo("trans:%d, action:%d, %s:%d msgType:%s", pTrans->id, index,
- mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType));;
- }
-
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->commitActions); ++i, ++index) {
- STransAction *pAction = taosArrayGet(pTrans->commitActions, i);
- mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index,
- mndTransStr(pAction->stage), i, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
- }
-
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->undoActions); ++i, ++index) {
- STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
- if(pAction->actionType == TRANS_ACTION_MSG){
- mInfo("trans:%d, action:%d, %s:%d msgType:%s", pTrans->id, index,
- mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType));;
- }
- else{
- mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index,
- mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
- }
- }
-
-
TAOS_CHECK_RETURN(mndTransCheckConflict(pMnode, pTrans));
TAOS_CHECK_RETURN(mndTransCheckParallelActions(pMnode, pTrans));
@@ -1329,10 +1260,7 @@ int32_t mndTransProcessRsp(SRpcMsg *pRsp) {
if (pAction != NULL) {
pAction->msgReceived = 1;
pAction->errCode = pRsp->code;
- pAction->endTime = taosGetTimestampMs();
-
- // pTrans->lastErrorNo = pRsp->code;
- mndSetTransLastAction(pTrans, pAction);
+ pTrans->lastErrorNo = pRsp->code;
mInfo("trans:%d, %s:%d response is received, received code:0x%x(%s), accept:0x%x(%s) retry:0x%x(%s)", transId,
mndTransStr(pAction->stage), action, pRsp->code, tstrerror(pRsp->code), pAction->acceptableCode,
@@ -1446,8 +1374,6 @@ static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransActio
pAction->msgSent = 1;
// pAction->msgReceived = 0;
pAction->errCode = TSDB_CODE_ACTION_IN_PROGRESS;
- pAction->startTime = taosGetTimestampMs();
- pAction->endTime = 0;
mInfo("trans:%d, %s:%d is sent, %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, detail);
mndSetTransLastAction(pTrans, pAction);
@@ -1601,9 +1527,8 @@ static int32_t mndTransExecuteActionsSerial(SMnode *pMnode, STrans *pTrans, SArr
for (int32_t action = pTrans->actionPos; action < numOfActions; ++action) {
STransAction *pAction = taosArrayGet(pActions, action);
- mInfo("trans:%d, current action:%d, stage:%s, actionType(1:msg,2:log):%d, msgSent:%d, msgReceived:%d",
- pTrans->id, pTrans->actionPos, mndTransStr(pAction->stage), pAction->actionType, pAction->msgSent,
- pAction->msgReceived);
+ mInfo("trans:%d, current action:%d, stage:%s, actionType(1:msg,2:log):%d", pTrans->id, pTrans->actionPos,
+ mndTransStr(pAction->stage), pAction->actionType);
code = mndTransExecSingleAction(pMnode, pTrans, pAction, topHalf);
if (code == 0) {
@@ -1999,25 +1924,13 @@ int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) {
TAOS_RETURN(TSDB_CODE_MND_TRANS_INVALID_STAGE);
}
- if(pTrans->ableToBeKilled == false){
- return TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED;
- }
-
- if(pTrans->killMode == TRN_KILL_MODE_SKIP){
- for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
- STransAction *pAction = taosArrayGet(pArray, i);
- mInfo("trans:%d, %s:%d set processed for kill msg received, errCode from %s to success", pTrans->id,
- mndTransStr(pAction->stage), i, tstrerror(pAction->errCode));
- pAction->msgSent = 1;
- pAction->msgReceived = 1;
- pAction->errCode = 0;
- }
- }
- else if(pTrans->killMode == TRN_KILL_MODE_INTERUPT){
- pTrans->stage = TRN_STAGE_PRE_FINISH;
- }
- else{
- return TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED;
+ for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
+ STransAction *pAction = taosArrayGet(pArray, i);
+ mInfo("trans:%d, %s:%d set processed for kill msg received, errCode from %s to success", pTrans->id,
+ mndTransStr(pAction->stage), i, tstrerror(pAction->errCode));
+ pAction->msgSent = 1;
+ pAction->msgReceived = 1;
+ pAction->errCode = 0;
}
mndTransExecute(pMnode, pTrans);
@@ -2089,114 +2002,6 @@ void mndTransPullup(SMnode *pMnode) {
taosArrayDestroy(pArray);
}
-static char *formatTimestamp(char *buf, int64_t val, int precision) {
- time_t tt;
- if (precision == TSDB_TIME_PRECISION_MICRO) {
- tt = (time_t)(val / 1000000);
- }
- if (precision == TSDB_TIME_PRECISION_NANO) {
- tt = (time_t)(val / 1000000000);
- } else {
- tt = (time_t)(val / 1000);
- }
-
- struct tm tm;
- if (taosLocalTime(&tt, &tm, NULL, 0, NULL) == NULL) {
- mError("failed to get local time");
- return NULL;
- }
- size_t pos = taosStrfTime(buf, 32, "%Y-%m-%d %H:%M:%S", &tm);
-
- if (precision == TSDB_TIME_PRECISION_MICRO) {
- sprintf(buf + pos, ".%06d", (int)(val % 1000000));
- } else if (precision == TSDB_TIME_PRECISION_NANO) {
- sprintf(buf + pos, ".%09d", (int)(val % 1000000000));
- } else {
- sprintf(buf + pos, ".%03d", (int)(val % 1000));
- }
-
- return buf;
-}
-
-static void mndTransLogAction(STrans *pTrans) {
- char detail[512] = {0};
- int32_t len = 0;
- int32_t index = 0;
-
- if (pTrans->stage == TRN_STAGE_PREPARE) {
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->prepareActions); ++i, ++index) {
- len = 0;
- STransAction *pAction = taosArrayGet(pTrans->prepareActions, i);
- len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
- mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
- sdbStatusName(pAction->pRaw->status));
- mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
- }
- }
-
- if (pTrans->stage == TRN_STAGE_REDO_ACTION) {
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->redoActions); ++i, ++index) {
- len = 0;
- STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
- if (pAction->actionType == TRANS_ACTION_MSG) {
- char bufStart[40] = {0};
- (void)formatTimestamp(bufStart, pAction->startTime, TSDB_TIME_PRECISION_MILLI);
-
- char endStart[40] = {0};
- (void)formatTimestamp(endStart, pAction->endTime, TSDB_TIME_PRECISION_MILLI);
- len += snprintf(detail + len, sizeof(detail) - len,
- "action:%d, %s:%d msgType:%s,"
- "sent:%d, received:%d, startTime:%s, endTime:%s, ",
- index, mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType), pAction->msgSent,
- pAction->msgReceived, bufStart, endStart);
-
- SEpSet epset = pAction->epSet;
- if (epset.numOfEps > 0) {
- len += snprintf(detail + len, sizeof(detail) - len, "numOfEps:%d inUse:%d ", epset.numOfEps, epset.inUse);
- for (int32_t i = 0; i < epset.numOfEps; ++i) {
- len +=
- snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
- }
- }
-
- len += snprintf(detail + len, sizeof(detail) - len, ", errCode:0x%x(%s)\n", pAction->errCode & 0xFFFF,
- tstrerror(pAction->errCode));
- } else {
- len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s, written:%d\n",
- index, mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
- sdbStatusName(pAction->pRaw->status), pAction->rawWritten);
- }
- mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
- }
- }
-
- if (pTrans->stage == TRN_STAGE_COMMIT_ACTION) {
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->commitActions); ++i, ++index) {
- len = 0;
- STransAction *pAction = taosArrayGet(pTrans->commitActions, i);
- len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
- mndTransStr(pAction->stage), i, sdbTableName(pAction->pRaw->type),
- sdbStatusName(pAction->pRaw->status));
- mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
- }
-
- for (int32_t i = 0; i < taosArrayGetSize(pTrans->undoActions); ++i, ++index) {
- len = 0;
- STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
- if (pAction->actionType == TRANS_ACTION_MSG) {
- len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d msgType:%s\n", index,
- mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType));
- ;
- } else {
- len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
- mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
- sdbStatusName(pAction->pRaw->status));
- }
- mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
- }
- }
-}
-
static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
SMnode *pMnode = pReq->info.node;
SSdb *pSdb = pMnode->pSdb;
@@ -2239,20 +2044,6 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)stbname, false), pTrans, &lino, _OVER);
- const char *killableStr = pTrans->ableToBeKilled ? "yes" : "no";
- char killableVstr[10 + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(killableVstr, killableStr, 10 + VARSTR_HEADER_SIZE);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)killableVstr, false), pTrans, &lino, _OVER);
-
- /*
- const char *killModeStr = pTrans->killMode == TRN_KILL_MODE_SKIP ? "skip" : "interrupt";
- char killModeVstr[10 + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(killModeVstr, killModeStr, 24);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)killModeVstr, false), pTrans, &lino, _OVER);
- */
-
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->failedTimes, false), pTrans, &lino,
_OVER);
@@ -2270,15 +2061,13 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
len += tsnprintf(detail + len, sizeof(detail) - len, "msgType:%s numOfEps:%d inUse:%d ",
TMSG_INFO(pTrans->lastMsgType), epset.numOfEps, epset.inUse);
for (int32_t i = 0; i < pTrans->lastEpset.numOfEps; ++i) {
- len += snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
+ len += tsnprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
}
}
STR_WITH_MAXSIZE_TO_VARSTR(lastInfo, detail, pShow->pMeta->pSchemas[cols].bytes);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)lastInfo, false), pTrans, &lino, _OVER);
- mndTransLogAction(pTrans);
-
numOfRows++;
sdbRelease(pSdb, pTrans);
}
@@ -2289,239 +2078,6 @@ _OVER:
return numOfRows;
}
-static int32_t mndShowTransCommonColumns(SShowObj *pShow, SSDataBlock *pBlock, STransAction *pAction,
- int32_t transactionId, int32_t curActionId, int32_t numOfRows, int32_t *cols) {
- int32_t code = 0;
- int32_t lino = 0;
- int32_t len = 0;
-
- SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, (*cols)++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&transactionId, false), &lino, _OVER);
-
- char action[30 + 1] = {0};
- if (curActionId == pAction->id) {
- len += snprintf(action + len, sizeof(action) - len, "%s:%d(%s)<-last", mndTransStr(pAction->stage), pAction->id,
- mndTransTypeStr(pAction->actionType));
- } else {
- len += snprintf(action + len, sizeof(action) - len, "%s:%d(%s)", mndTransStr(pAction->stage), pAction->id,
- mndTransTypeStr(pAction->actionType));
- }
- char actionVStr[30 + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(actionVStr, action, pShow->pMeta->pSchemas[*cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, (*cols)++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)actionVStr, false), &lino, _OVER);
-_OVER:
- if (code != 0) mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
- return code;
-}
-
-static void mndShowTransAction(SShowObj *pShow, SSDataBlock *pBlock, STransAction *pAction, int32_t transactionId,
- int32_t curActionId, int32_t rows, int32_t numOfRows) {
- int32_t code = 0;
- int32_t lino = 0;
- int32_t len = 0;
- int32_t cols = 0;
-
- cols = 0;
-
- if (mndShowTransCommonColumns(pShow, pBlock, pAction, transactionId, curActionId, numOfRows, &cols) != 0) return;
-
- if (pAction->actionType == TRANS_ACTION_MSG) {
- int32_t len = 0;
-
- char objType[TSDB_TRANS_OBJTYPE_LEN + 1] = {0};
- len += snprintf(objType + len, sizeof(objType) - len, "%s(s:%d,r:%d)", TMSG_INFO(pAction->msgType),
- pAction->msgSent, pAction->msgReceived);
- char objTypeVStr[TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(objTypeVStr, objType, pShow->pMeta->pSchemas[cols].bytes);
- SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)objTypeVStr, false), &lino, _OVER);
-
- char result[TSDB_TRANS_RESULT_LEN + 1] = {0};
- len = 0;
- len += snprintf(result + len, sizeof(result) - len, "errCode:0x%x(%s)", pAction->errCode & 0xFFFF,
- tstrerror(pAction->errCode));
- char resultVStr[TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(resultVStr, result, pShow->pMeta->pSchemas[cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)resultVStr, false), &lino, _OVER);
-
- char target[TSDB_TRANS_TARGET_LEN] = {0};
- len = 0;
- SEpSet epset = pAction->epSet;
- if (epset.numOfEps > 0) {
- for (int32_t i = 0; i < epset.numOfEps; ++i) {
- len += snprintf(target + len, sizeof(target) - len, "ep:%d-%s:%u,", i, epset.eps[i].fqdn, epset.eps[i].port);
- }
- len += snprintf(target + len, sizeof(target) - len, "(%d:%d) ", epset.numOfEps, epset.inUse);
- }
- char targetVStr[TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(targetVStr, target, pShow->pMeta->pSchemas[cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)targetVStr, false), &lino, _OVER);
-
- char detail[TSDB_TRANS_DETAIL_LEN] = {0};
- len = 0;
- char bufStart[40] = {0};
- if (pAction->startTime > 0) (void)formatTimestamp(bufStart, pAction->startTime, TSDB_TIME_PRECISION_MILLI);
- char bufEnd[40] = {0};
- if (pAction->endTime > 0) (void)formatTimestamp(bufEnd, pAction->endTime, TSDB_TIME_PRECISION_MILLI);
- len += snprintf(detail + len, sizeof(detail) - len, "startTime:%s, endTime:%s, ", bufStart, bufEnd);
- char detailVStr[TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(detailVStr, detail, pShow->pMeta->pSchemas[cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)detailVStr, false), &lino, _OVER);
-
- } else {
- int32_t len = 0;
-
- char objType[TSDB_TRANS_OBJTYPE_LEN + 1] = {0};
- if (pAction->pRaw->type == SDB_VGROUP) {
- SSdbRow *pRow = mndVgroupActionDecode(pAction->pRaw);
- SVgObj *pVgroup = sdbGetRowObj(pRow);
- len += snprintf(objType + len, sizeof(objType) - len, "%s(%d)", sdbTableName(pAction->pRaw->type), pVgroup->vgId);
- taosMemoryFreeClear(pRow);
- } else {
- strcpy(objType, sdbTableName(pAction->pRaw->type));
- }
- char objTypeVStr[TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(objTypeVStr, objType, pShow->pMeta->pSchemas[cols].bytes);
- SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)objTypeVStr, false), &lino, _OVER);
-
- char result[TSDB_TRANS_RESULT_LEN + 1] = {0};
- len = 0;
- len += snprintf(result + len, sizeof(result) - len, "rawWritten:%d", pAction->rawWritten);
- char resultVStr[TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(resultVStr, result, pShow->pMeta->pSchemas[cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)resultVStr, false), &lino, _OVER);
-
- char target[TSDB_TRANS_TARGET_LEN] = "";
- char targetVStr[TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(targetVStr, target, pShow->pMeta->pSchemas[cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)targetVStr, false), &lino, _OVER);
-
- char detail[TSDB_TRANS_DETAIL_LEN] = {0};
- len = 0;
- len += snprintf(detail + len, sizeof(detail) - len, "sdbStatus:%s", sdbStatusName(pAction->pRaw->status));
- char detailVStr[TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(detailVStr, detail, pShow->pMeta->pSchemas[cols].bytes);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)detailVStr, false), &lino, _OVER);
- }
-
-_OVER:
- if (code != 0) mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
-}
-
-static SArray *mndTransGetAction(STrans *pTrans, ETrnStage stage) {
- if (stage == TRN_STAGE_PREPARE) {
- return pTrans->prepareActions;
- }
- if (stage == TRN_STAGE_REDO_ACTION) {
- return pTrans->redoActions;
- }
- if (stage == TRN_STAGE_COMMIT_ACTION) {
- return pTrans->commitActions;
- }
- if (stage == TRN_STAGE_UNDO_ACTION) {
- return pTrans->undoActions;
- }
- return NULL;
-}
-
-typedef struct STransDetailIter {
- void *pIter;
- STrans *pTrans;
- ETrnStage stage;
- int32_t num;
-} STransDetailIter;
-
-static void mndTransShowActions(SSdb *pSdb, STransDetailIter *pShowIter, SShowObj *pShow, SSDataBlock *pBlock,
- int32_t rows, int32_t *numOfRows, SArray *pActions, int32_t end, int32_t start) {
- int32_t actionNum = taosArrayGetSize(pActions);
- mInfo("stage:%s, Actions num:%d", mndTransStr(pShowIter->stage), actionNum);
-
- for (int32_t i = start; i < actionNum; ++i) {
- STransAction *pAction = taosArrayGet(pShowIter->pTrans->redoActions, i);
- mndShowTransAction(pShow, pBlock, pAction, pShowIter->pTrans->id, pShowIter->pTrans->lastAction, rows, *numOfRows);
- (*numOfRows)++;
- if (*numOfRows >= rows) break;
- }
-
- if (*numOfRows == end) {
- sdbRelease(pSdb, pShowIter->pTrans);
- pShowIter->pTrans = NULL;
- pShowIter->num = 0;
- } else {
- pShowIter->pTrans = pShowIter->pTrans;
- pShowIter->stage = pShowIter->pTrans->stage;
- pShowIter->num += (*numOfRows);
- }
-}
-
-static int32_t mndRetrieveTransDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
- SMnode *pMnode = pReq->info.node;
- SSdb *pSdb = pMnode->pSdb;
- int32_t numOfRows = 0;
-
- int32_t code = 0;
- int32_t lino = 0;
-
- mInfo("start to mndRetrieveTransDetail, rows:%d, pShow->numOfRows:%d, pShow->pIter:%p", rows, pShow->numOfRows,
- pShow->pIter);
-
- if (pShow->pIter == NULL) {
- pShow->pIter = taosMemoryMalloc(sizeof(STransDetailIter));
- if (pShow->pIter == NULL) {
- mError("failed to malloc for pShow->pIter");
- return 0;
- }
- memset(pShow->pIter, 0, sizeof(STransDetailIter));
- }
-
- STransDetailIter *pShowIter = (STransDetailIter *)pShow->pIter;
-
- while (numOfRows < rows) {
- if (pShowIter->pTrans == NULL) {
- pShowIter->pIter = sdbFetch(pSdb, SDB_TRANS, pShowIter->pIter, (void **)&(pShowIter->pTrans));
- mDebug("retrieve trans detail from fetch, pShow->pIter:%p, pTrans:%p", pShowIter->pIter, pShowIter->pTrans);
- if (pShowIter->pIter == NULL) break;
- mInfo("retrieve trans detail from fetch, id:%d, trans stage:%d, IterNum:%d", pShowIter->pTrans->id,
- pShowIter->pTrans->stage, pShowIter->num);
-
- SArray *pActions = mndTransGetAction(pShowIter->pTrans, pShowIter->pTrans->stage);
-
- mndTransShowActions(pSdb, pShowIter, pShow, pBlock, rows, &numOfRows, pActions, taosArrayGetSize(pActions), 0);
- break;
- } else {
- mInfo("retrieve trans detail from iter, id:%d, iterStage:%d, IterNum:%d", pShowIter->pTrans->id, pShowIter->stage,
- pShowIter->num);
- SArray *pActions = mndTransGetAction(pShowIter->pTrans, pShowIter->stage);
-
- mndTransShowActions(pSdb, pShowIter, pShow, pBlock, rows, &numOfRows, pActions,
- taosArrayGetSize(pActions) - pShowIter->num, pShowIter->num);
- break;
- }
- }
-
-_OVER:
- pShow->numOfRows += numOfRows;
-
- if (code != 0) {
- mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
- } else {
- mInfo("retrieve trans detail, numOfRows:%d, pShow->numOfRows:%d", numOfRows, pShow->numOfRows)
- }
- if (numOfRows == 0) {
- taosMemoryFree(pShow->pIter);
- pShow->pIter = NULL;
- }
- return numOfRows;
-}
-
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter) {
SSdb *pSdb = pMnode->pSdb;
sdbCancelFetchByType(pSdb, pIter, SDB_TRANS);
diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c
index e20afb7201..0bce21290b 100644
--- a/source/dnode/mnode/impl/src/mndVgroup.c
+++ b/source/dnode/mnode/impl/src/mndVgroup.c
@@ -2766,14 +2766,12 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
mndTransSetSerial(pTrans);
- if (pNewDb->cfg.replications == 3) {
+ if (pNewVgroup->replica == 1 && pNewDb->cfg.replications == 3) {
mInfo("db:%s, vgId:%d, will add 2 vnodes, vn:0 dnode:%d", pVgroup->dbName, pVgroup->vgId,
pVgroup->vnodeGid[0].dnodeId);
// add second
- if (pNewVgroup->replica == 1){
- TAOS_CHECK_RETURN(mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
- }
+ TAOS_CHECK_RETURN(mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
// learner stage
pNewVgroup->vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
@@ -2792,9 +2790,7 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
TAOS_CHECK_RETURN(mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup));
// add third
- if (pNewVgroup->replica == 2){
- TAOS_CHECK_RETURN (mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
- }
+ TAOS_CHECK_RETURN(mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
pNewVgroup->vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
pNewVgroup->vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_VOTER;
@@ -2806,7 +2802,7 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
TAOS_CHECK_RETURN(mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, pNewVgroup, &pNewVgroup->vnodeGid[2]));
TAOS_CHECK_RETURN(mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup));
- } else if (pNewDb->cfg.replications == 1) {
+ } else if (pNewVgroup->replica == 3 && pNewDb->cfg.replications == 1) {
mInfo("db:%s, vgId:%d, will remove 2 vnodes, vn:0 dnode:%d vn:1 dnode:%d vn:2 dnode:%d", pVgroup->dbName,
pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId, pVgroup->vnodeGid[1].dnodeId, pVgroup->vnodeGid[2].dnodeId);
@@ -2823,9 +2819,9 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
TAOS_CHECK_RETURN(mndRemoveVnodeFromVgroup(pMnode, pTrans, pNewVgroup, pArray, &del2));
TAOS_CHECK_RETURN(mndAddDropVnodeAction(pMnode, pTrans, pNewDb, pNewVgroup, &del2, true));
TAOS_CHECK_RETURN(
- mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId));
+ mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId));
TAOS_CHECK_RETURN(mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup));
- } else if (pNewDb->cfg.replications == 2) {
+ } else if (pNewVgroup->replica == 1 && pNewDb->cfg.replications == 2) {
mInfo("db:%s, vgId:%d, will add 1 vnode, vn:0 dnode:%d", pVgroup->dbName, pVgroup->vgId,
pVgroup->vnodeGid[0].dnodeId);
diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c
index 56060b0061..a556f68c32 100644
--- a/source/libs/executor/src/sysscanoperator.c
+++ b/source/libs/executor/src/sysscanoperator.c
@@ -2545,8 +2545,7 @@ static int32_t doSysTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes)
if (pInfo->showRewrite) {
getDBNameFromCondition(pInfo->pCondition, dbName);
if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, TSDB_TABLE_FNAME_LEN) != 0 &&
- strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, TSDB_TABLE_FNAME_LEN) != 0 &&
- strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, TSDB_TABLE_FNAME_LEN) != 0) {
+ strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, TSDB_TABLE_FNAME_LEN) != 0) {
TAOS_UNUSED(tsnprintf(pInfo->req.db, sizeof(pInfo->req.db), "%d.%s", pInfo->accountId, dbName));
}
} else if (strncasecmp(name, TSDB_INS_TABLE_COLS, TSDB_TABLE_FNAME_LEN) == 0) {
diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c
index c2290b9eac..6d4d89607f 100644
--- a/source/libs/nodes/src/nodesCodeFuncs.c
+++ b/source/libs/nodes/src/nodesCodeFuncs.c
@@ -292,8 +292,6 @@ const char* nodesNodeName(ENodeType type) {
return "ShowCompactsStmt";
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
return "ShowCompactDetailsStmt";
- case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
- return "ShowTransactionDetailsStmt";
case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
return "ShowGrantsFullStmt";
case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c
index 5bfc35aa9c..7beaeaa46c 100644
--- a/source/libs/nodes/src/nodesUtilFuncs.c
+++ b/source/libs/nodes/src/nodesUtilFuncs.c
@@ -714,9 +714,6 @@ int32_t nodesMakeNode(ENodeType type, SNode** ppNodeOut) {
break;
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
code = makeNode(type, sizeof(SShowCompactDetailsStmt), &pNode);
- break;
- case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
- code = makeNode(type, sizeof(SShowTransactionDetailsStmt), &pNode);
break;
case QUERY_NODE_KILL_QUERY_STMT:
code = makeNode(type, sizeof(SKillQueryStmt), &pNode);
@@ -1565,11 +1562,6 @@ void nodesDestroyNode(SNode* pNode) {
nodesDestroyNode(pStmt->pCompactId);
break;
}
- case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT: {
- SShowTransactionDetailsStmt* pStmt = (SShowTransactionDetailsStmt*)pNode;
- nodesDestroyNode(pStmt->pTransactionId);
- break;
- }
case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
taosMemoryFreeClear(((SShowCreateDatabaseStmt*)pNode)->pCfg);
break;
diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h
index 8b2a98baf2..e69a3da4a9 100644
--- a/source/libs/parser/inc/parAst.h
+++ b/source/libs/parser/inc/parAst.h
@@ -320,7 +320,6 @@ SNode* createCreateViewStmt(SAstCreateContext* pCxt, bool orReplace, SNode* pVie
SNode* createDropViewStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pView);
SNode* createShowCompactDetailsStmt(SAstCreateContext* pCxt, SNode* pCompactIdNode);
SNode* createShowCompactsStmt(SAstCreateContext* pCxt, ENodeType type);
-SNode* createShowTransactionDetailsStmt(SAstCreateContext* pCxt, SNode* pTransactionIdNode);
SNode* createCreateTSMAStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* tsmaName, SNode* pOptions,
SNode* pRealTable, SNode* pInterval);
diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y
index 38e93a7ce3..63eb09d509 100644
--- a/source/libs/parser/inc/sql.y
+++ b/source/libs/parser/inc/sql.y
@@ -594,7 +594,6 @@ cmd ::= SHOW BNODES.
cmd ::= SHOW SNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); }
cmd ::= SHOW CLUSTER. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); }
cmd ::= SHOW TRANSACTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); }
-cmd ::= SHOW TRANSACTION NK_INTEGER(A). { pCxt->pRootNode = createShowTransactionDetailsStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &A)); }
cmd ::= SHOW TABLE DISTRIBUTED full_table_name(A). { pCxt->pRootNode = createShowTableDistributedStmt(pCxt, A); }
cmd ::= SHOW CONSUMERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); }
cmd ::= SHOW SUBSCRIPTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); }
diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c
index 5fc5f5fafe..fa656667af 100644
--- a/source/libs/parser/src/parAstCreater.c
+++ b/source/libs/parser/src/parAstCreater.c
@@ -2931,18 +2931,6 @@ _err:
return NULL;
}
-SNode* createShowTransactionDetailsStmt(SAstCreateContext* pCxt, SNode* pTransactionIdNode) {
- CHECK_PARSER_STATUS(pCxt);
- SShowTransactionDetailsStmt* pStmt = NULL;
- pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT, (SNode**)&pStmt);
- CHECK_MAKE_NODE(pStmt);
- pStmt->pTransactionId = pTransactionIdNode;
- return (SNode*)pStmt;
-_err:
- nodesDestroyNode(pTransactionIdNode);
- return NULL;
-}
-
static int32_t getIpV4RangeFromWhitelistItem(char* ipRange, SIpV4Range* pIpRange) {
int32_t code = TSDB_CODE_SUCCESS;
char* ipCopy = taosStrdup(ipRange);
diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c
index e876575f48..1687916cb0 100644
--- a/source/libs/parser/src/parAstParser.c
+++ b/source/libs/parser/src/parAstParser.c
@@ -770,12 +770,6 @@ static int32_t collectMetaKeyFromShowCompactDetails(SCollectMetaKeyCxt* pCxt, SS
return code;
}
-static int32_t collectMetaKeyFromShowTransactionDetails(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
- int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
- TSDB_INS_TABLE_TRANSACTION_DETAILS, pCxt->pMetaCache);
- return code;
-}
-
static int32_t collectMetaKeyFromShowGrantsFull(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_GRANTS_FULL,
pCxt->pMetaCache);
@@ -1100,8 +1094,6 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
return collectMetaKeyFromShowCompacts(pCxt, (SShowStmt*)pStmt);
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
return collectMetaKeyFromShowCompactDetails(pCxt, (SShowStmt*)pStmt);
- case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
- return collectMetaKeyFromShowTransactionDetails(pCxt, (SShowStmt*)pStmt);
case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
return collectMetaKeyFromShowGrantsFull(pCxt, (SShowStmt*)pStmt);
case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index 8f3cbd6f8b..9f411c4296 100755
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -371,40 +371,12 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = {
.pShowCols = {"*"}
},
{
- .showType = QUERY_NODE_CREATE_TSMA_STMT,
- .pDbName = "",
- .pTableName = "",
- .numOfShowCols = 1,
- .pShowCols = {"*"}
- },
- {
- .showType = QUERY_NODE_SHOW_CREATE_TSMA_STMT,
- .pDbName = "",
- .pTableName = "",
- .numOfShowCols = 1,
- .pShowCols = {"*"}
- },
- {
- .showType = QUERY_NODE_DROP_TSMA_STMT,
- .pDbName = "",
- .pTableName = "",
- .numOfShowCols = 1,
- .pShowCols = {"*"}
- },
- {
.showType = QUERY_NODE_SHOW_FILESETS_STMT,
.pDbName = TSDB_INFORMATION_SCHEMA_DB,
.pTableName = TSDB_INS_TABLE_FILESETS,
.numOfShowCols = 1,
.pShowCols = {"*"}
- },
- {
- .showType = QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
- .pDbName = TSDB_INFORMATION_SCHEMA_DB,
- .pTableName = TSDB_INS_TABLE_TRANSACTION_DETAILS,
- .numOfShowCols = 1,
- .pShowCols = {"*"}
- },
+ },
};
// clang-format on
@@ -16387,24 +16359,6 @@ static int32_t rewriteShowCompactDetailsStmt(STranslateContext* pCxt, SQuery* pQ
return code;
}
-static int32_t rewriteShowTransactionDetailsStmt(STranslateContext* pCxt, SQuery* pQuery) {
- SShowTransactionDetailsStmt* pShow = (SShowTransactionDetailsStmt*)(pQuery->pRoot);
- SSelectStmt* pStmt = NULL;
- int32_t code = createSelectStmtForShow(QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT, &pStmt);
- if (TSDB_CODE_SUCCESS == code) {
- if (NULL != pShow->pTransactionId) {
- code = createOperatorNode(OP_TYPE_EQUAL, "transaction_id", pShow->pTransactionId, &pStmt->pWhere);
- }
- }
- if (TSDB_CODE_SUCCESS == code) {
- pCxt->showRewrite = true;
- pQuery->showRewrite = true;
- nodesDestroyNode(pQuery->pRoot);
- pQuery->pRoot = (SNode*)pStmt;
- }
- return code;
-}
-
static int32_t createParWhenThenNode(SNode* pWhen, SNode* pThen, SNode** ppResWhenThen) {
SWhenThenNode* pWThen = NULL;
int32_t code = nodesMakeNode(QUERY_NODE_WHEN_THEN, (SNode**)&pWThen);
@@ -16980,9 +16934,6 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
code = rewriteShowCompactDetailsStmt(pCxt, pQuery);
break;
- case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
- code = rewriteShowTransactionDetailsStmt(pCxt, pQuery);
- break;
case QUERY_NODE_SHOW_DB_ALIVE_STMT:
case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
code = rewriteShowAliveStmt(pCxt, pQuery);
diff --git a/source/util/src/terror.c b/source/util/src/terror.c
index feed297f71..b2a8c422f7 100644
--- a/source/util/src/terror.c
+++ b/source/util/src/terror.c
@@ -326,7 +326,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_SYNC_TIMEOUT, "Sync timeout While ex
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_CTX_SWITCH, "Wrong transaction execution context")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_CONFLICT_COMPACT, "Transaction not completed due to conflict with compact")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_UNKNOW_ERROR, "Unknown transaction error")
-TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED, "The transaction is not able to be killed")
// mnode-mq
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOPIC_ALREADY_EXIST, "Topic already exists")
diff --git a/tests/develop-test/2-query/table_count_scan.py b/tests/develop-test/2-query/table_count_scan.py
index b5c6140481..9725c36bee 100644
--- a/tests/develop-test/2-query/table_count_scan.py
+++ b/tests/develop-test/2-query/table_count_scan.py
@@ -68,7 +68,7 @@ class TDTestCase:
for i in range(0, 3):
db_name = tdSql.getData(i, 1)
if db_name == 'information_schema':
- tdSql.checkData(i, 0, 37)
+ tdSql.checkData(i, 0, 36)
tdSql.checkData(i, 2, None)
elif db_name == 'performance_schema':
tdSql.checkData(i, 0, 5)
@@ -81,7 +81,7 @@ class TDTestCase:
tdSql.query('select count(1) v,db_name, stable_name from information_schema.ins_tables group by db_name, stable_name order by v desc;')
tdSql.checkRows(3)
- tdSql.checkData(0, 0, 37)
+ tdSql.checkData(0, 0, 36)
tdSql.checkData(0, 1, 'information_schema')
tdSql.checkData(0, 2, None)
tdSql.checkData(1, 0, 5)
@@ -97,7 +97,7 @@ class TDTestCase:
tdSql.checkData(1, 1, 'performance_schema')
tdSql.checkData(0, 0, 3)
tdSql.checkData(0, 1, 'tbl_count')
- tdSql.checkData(2, 0, 37)
+ tdSql.checkData(2, 0, 36)
tdSql.checkData(2, 1, 'information_schema')
tdSql.query("select count(*) from information_schema.ins_tables where db_name='tbl_count'")
@@ -110,7 +110,7 @@ class TDTestCase:
tdSql.query('select count(*) from information_schema.ins_tables')
tdSql.checkRows(1)
- tdSql.checkData(0, 0, 45)
+ tdSql.checkData(0, 0, 44)
tdSql.execute('create table stba (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(10), c9 nchar(10), c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned) TAGS(t1 int, t2 binary(10), t3 double);')
@@ -193,7 +193,7 @@ class TDTestCase:
tdSql.checkData(2, 0, 5)
tdSql.checkData(2, 1, 'performance_schema')
tdSql.checkData(2, 2, None)
- tdSql.checkData(3, 0, 37)
+ tdSql.checkData(3, 0, 36)
tdSql.checkData(3, 1, 'information_schema')
tdSql.checkData(3, 2, None)
@@ -208,7 +208,7 @@ class TDTestCase:
tdSql.checkData(2, 0, 5)
tdSql.checkData(2, 1, 'performance_schema')
tdSql.checkData(2, 2, None)
- tdSql.checkData(3, 0, 37)
+ tdSql.checkData(3, 0, 36)
tdSql.checkData(3, 1, 'information_schema')
tdSql.checkData(3, 2, None)
@@ -219,7 +219,7 @@ class TDTestCase:
tdSql.checkData(0, 1, 'tbl_count')
tdSql.checkData(1, 0, 5)
tdSql.checkData(1, 1, 'performance_schema')
- tdSql.checkData(2, 0, 37)
+ tdSql.checkData(2, 0, 36)
tdSql.checkData(2, 1, 'information_schema')
tdSql.query("select count(*) from information_schema.ins_tables where db_name='tbl_count'")
@@ -232,7 +232,7 @@ class TDTestCase:
tdSql.query('select count(*) from information_schema.ins_tables')
tdSql.checkRows(1)
- tdSql.checkData(0, 0, 46)
+ tdSql.checkData(0, 0, 45)
tdSql.execute('drop database tbl_count')
diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task
index 8903ef27a4..ae9918f688 100644
--- a/tests/parallel_test/cases.task
+++ b/tests/parallel_test/cases.task
@@ -408,9 +408,6 @@
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/test_hot_refresh_configurations.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/subscribe_stream_privilege.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/empty_identifier.py
-,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/show_transaction_detail.py -N 3
-# ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/kill_balance_leader.py -N 3
-# ,,y,system-test,./pytest.sh python3 ./test.py -f 3-enterprise/restore/kill_restore_dnode.py -N 5
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/persisit_config.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/qmemCtrl.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/compact_vgroups.py
diff --git a/tests/script/tsim/query/sys_tbname.sim b/tests/script/tsim/query/sys_tbname.sim
index c6c979e97c..f8c1d6a986 100644
--- a/tests/script/tsim/query/sys_tbname.sim
+++ b/tests/script/tsim/query/sys_tbname.sim
@@ -58,7 +58,7 @@ endi
sql select tbname from information_schema.ins_tables;
print $rows $data00
-if $rows != 46 then
+if $rows != 45 then
return -1
endi
if $data00 != @ins_tables@ then
diff --git a/tests/script/tsim/query/tableCount.sim b/tests/script/tsim/query/tableCount.sim
index 19568b42b6..49e9126361 100644
--- a/tests/script/tsim/query/tableCount.sim
+++ b/tests/script/tsim/query/tableCount.sim
@@ -53,7 +53,7 @@ sql select stable_name,count(table_name) from information_schema.ins_tables grou
if $rows != 3 then
return -1
endi
-if $data01 != 43 then
+if $data01 != 42 then
return -1
endi
if $data11 != 10 then
@@ -72,7 +72,7 @@ endi
if $data11 != 5 then
return -1
endi
-if $data21 != 37 then
+if $data21 != 36 then
return -1
endi
if $data31 != 5 then
@@ -97,7 +97,7 @@ endi
if $data42 != 3 then
return -1
endi
-if $data52 != 37 then
+if $data52 != 36 then
return -1
endi
if $data62 != 5 then
diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py
index 8c25b70b76..af0dd6d949 100644
--- a/tests/system-test/0-others/information_schema.py
+++ b/tests/system-test/0-others/information_schema.py
@@ -61,7 +61,7 @@ class TDTestCase:
self.ins_list = ['ins_dnodes','ins_mnodes','ins_qnodes','ins_snodes','ins_cluster','ins_databases','ins_functions',\
'ins_indexes','ins_stables','ins_tables','ins_tags','ins_columns','ins_users','ins_grants','ins_vgroups','ins_configs','ins_dnode_variables',\
'ins_topics','ins_subscriptions','ins_streams','ins_stream_tasks','ins_vnodes','ins_user_privileges','ins_views',
- 'ins_compacts', 'ins_compact_details', 'ins_grants_full','ins_grants_logs', 'ins_machines', 'ins_arbgroups', 'ins_tsmas', "ins_encryptions", "ins_anodes", "ins_anodes_full", "ins_disk_usagea", "ins_filesets", "ins_transaction_details"]
+ 'ins_compacts', 'ins_compact_details', 'ins_grants_full','ins_grants_logs', 'ins_machines', 'ins_arbgroups', 'ins_tsmas', "ins_encryptions", "ins_anodes", "ins_anodes_full", "ins_disk_usagea", "ins_filesets"]
self.perf_list = ['perf_connections','perf_queries','perf_consumers','perf_trans','perf_apps']
def insert_data(self,column_dict,tbname,row_num):
insert_sql = self.setsql.set_insertsql(column_dict,tbname,self.binary_str,self.nchar_str)
@@ -222,10 +222,10 @@ class TDTestCase:
tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'")
tdLog.info(len(tdSql.queryResult))
- tdSql.checkEqual(True, len(tdSql.queryResult) in range(309, 310))
+ tdSql.checkEqual(True, len(tdSql.queryResult) in range(303, 304))
tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'")
- tdSql.checkEqual(61, len(tdSql.queryResult))
+ tdSql.checkEqual(60, len(tdSql.queryResult))
def ins_dnodes_check(self):
tdSql.execute('drop database if exists db2')
diff --git a/tests/system-test/0-others/kill_balance_leader.py b/tests/system-test/0-others/kill_balance_leader.py
deleted file mode 100644
index be86336661..0000000000
--- a/tests/system-test/0-others/kill_balance_leader.py
+++ /dev/null
@@ -1,64 +0,0 @@
-###################################################################
-# Copyright (c) 2016 by TAOS Technologies, Inc.
-# All rights reserved.
-#
-# This file is proprietary and confidential to TAOS Technologies.
-# No part of this file may be reproduced, stored, transmitted,
-# disclosed or used in any form or by any means other than as
-# expressly provided by the written permission from Jianhui Tao
-#
-###################################################################
-
-# -*- coding: utf-8 -*-
-from util.log import *
-from util.cases import *
-from util.dnodes import *
-from util.sql import *
-
-
-
-class TDTestCase:
- def init(self, conn, logSql, replicaVar=1):
- tdLog.debug(f"start to init {__file__}")
- self.replicaVar = int(replicaVar)
- tdSql.init(conn.cursor(), logSql)
-
- def stop(self):
- tdSql.close()
- tdLog.success(f"{__file__} successfully executed")
-
- def run(self):
- tdLog.debug(f"start to excute {__file__}")
-
- tdSql.execute('CREATE DATABASE db vgroups 160 replica 3;')
-
- tdSql.execute('balance vgroup leader')
-
- sql ="show transactions;"
- rows = tdSql.query(sql)
-
- if rows > 0:
- tranId = tdSql.getData(0, 0)
- tdLog.info('kill transaction %d'%tranId)
- tdSql.execute('kill transaction %d'%tranId, queryTimes=1 )
-
- if self.waitTransactionZero() is False:
- tdLog.exit(f"{sql} transaction not finished")
- return False
-
- def waitTransactionZero(self, seconds = 300, interval = 1):
- # wait end
- for i in range(seconds):
- sql ="show transactions;"
- rows = tdSql.query(sql)
- if rows == 0:
- tdLog.info("transaction count became zero.")
- return True
- #tdLog.info(f"i={i} wait ...")
- time.sleep(interval)
-
- return False
-
-
-tdCases.addLinux(__file__, TDTestCase())
-tdCases.addWindows(__file__, TDTestCase())
\ No newline at end of file
diff --git a/tests/system-test/0-others/show_transaction_detail.py b/tests/system-test/0-others/show_transaction_detail.py
deleted file mode 100644
index ba588f8f01..0000000000
--- a/tests/system-test/0-others/show_transaction_detail.py
+++ /dev/null
@@ -1,115 +0,0 @@
-###################################################################
-# Copyright (c) 2016 by TAOS Technologies, Inc.
-# All rights reserved.
-#
-# This file is proprietary and confidential to TAOS Technologies.
-# No part of this file may be reproduced, stored, transmitted,
-# disclosed or used in any form or by any means other than as
-# expressly provided by the written permission from Jianhui Tao
-#
-###################################################################
-
-# -*- coding: utf-8 -*-
-from util.log import *
-from util.cases import *
-from util.dnodes import *
-from util.sql import *
-from util.cluster import *
-import threading
-
-class TDTestCase:
- def init(self, conn, logSql, replicaVar=1):
- tdLog.debug(f"start to init {__file__}")
- self.replicaVar = int(replicaVar)
- tdSql.init(conn.cursor(), logSql)
- self.dnodes = cluster.dnodes
-
- def stop(self):
- tdSql.close()
- tdLog.success(f"{__file__} successfully executed")
-
- def run(self):
- tdLog.debug(f"start to excute {__file__}")
-
- tdLog.info("CREATE DATABASE db1 vgroups 16 replica 1;")
- tdSql.execute('CREATE DATABASE db1 vgroups 16 replica 1;')
-
- if self.waitTransactionZero() is False:
- tdLog.exit(f"{sql} transaction not finished")
- return False
-
- newTdSql1=tdCom.newTdSql()
- t1 = threading.Thread(target=self.alterDbThread, args=('', newTdSql1))
-
- newTdSql2=tdCom.newTdSql()
- t2 = threading.Thread(target=self.createDbThread, args=('', newTdSql2))
-
- t1.start()
- t2.start()
-
- #time.sleep(1)
-
- dnode = self.dnodes[2]
-
- # stop dnode
- tdLog.info(f"stop dnode 2")
- dnode.stoptaosd()
-
- tdLog.info(f"show transactions;")
- rows = tdSql.query("show transactions;", queryTimes=1)
- tdLog.info(f"rows={rows}")
- if rows > 0:
- tranId1 = tdSql.getData(0, 0)
- oper1 = tdSql.getData(0, 3)
- tdLog.info(f"show transaction {tranId1}, {oper1}")
-
- #tranId2 = tdSql.getData(1, 0)
- #oper2 = tdSql.getData(1, 3)
- #tdLog.info(f"show transaction {tranId2}, {oper2}")
-
- rows = tdSql.query(f"show transaction {tranId1}", queryTimes=1)
- if rows != 120 and rows != 176:
- tdLog.exit(f"show transaction detial error, rows={rows}")
- return False
-
- #rows = tdSql.query(f"show transaction {tranId2}", queryTimes=1)
- #if rows != 176 and rows != 120:
- # tdLog.exit(f"show transaction detial error, rows={rows}")
- # return False
-
- tdLog.info(f"select * from ins_transaction_details")
- rows = tdSql.query(f"select * from information_schema.ins_transaction_details", queryTimes=1)
-
- #if rows != 296:
- if rows != 176:
- tdLog.exit(f"show transaction detial error, rows={rows}")
- return False
-
- dnode.starttaosd()
-
- t1.join()
- t2.join()
-
- def createDbThread(self, sql, newTdSql):
- tdLog.info("CREATE DATABASE db2 vgroups 40 replica 3;")
- newTdSql.execute('CREATE DATABASE db2 vgroups 40 replica 3;', queryTimes=1)
-
- def alterDbThread(self, sql, newTdSql):
- tdLog.info("alter DATABASE db1 replica 3;")
- newTdSql.execute('alter DATABASE db1 replica 3;', queryTimes=1)
-
- def waitTransactionZero(self, seconds = 300, interval = 1):
- # wait end
- for i in range(seconds):
- sql ="show transactions;"
- rows = tdSql.query(sql)
- if rows == 0:
- tdLog.info("transaction count became zero.")
- return True
- #tdLog.info(f"i={i} wait ...")
- time.sleep(interval)
-
- return False
-
-tdCases.addLinux(__file__, TDTestCase())
-tdCases.addWindows(__file__, TDTestCase())
\ No newline at end of file
diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py
index 1abe2b1a65..380b7879c4 100644
--- a/tests/system-test/2-query/union.py
+++ b/tests/system-test/2-query/union.py
@@ -441,7 +441,7 @@ class TDTestCase:
tdSql.checkRows(2)
sql = "select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, stable_name `TABLE_NAME`, 'TABLE' `TABLE_TYPE`, table_comment `REMARKS` from information_schema.ins_stables union all select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, table_name `TABLE_NAME`, case when `type`='SYSTEM_TABLE' then 'TABLE' when `type`='NORMAL_TABLE' then 'TABLE' when `type`='CHILD_TABLE' then 'TABLE' else 'UNKNOWN' end `TABLE_TYPE`, table_comment `REMARKS` from information_schema.ins_tables union all select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, view_name `TABLE_NAME`, 'VIEW' `TABLE_TYPE`, NULL `REMARKS` from information_schema.ins_views"
tdSql.query(sql, queryTimes=1)
- tdSql.checkRows(50)
+ tdSql.checkRows(49)
sql = "select null union select null"
tdSql.query(sql, queryTimes=1)
diff --git a/tests/system-test/3-enterprise/restore/kill_restore_dnode.py b/tests/system-test/3-enterprise/restore/kill_restore_dnode.py
deleted file mode 100644
index d29a11f159..0000000000
--- a/tests/system-test/3-enterprise/restore/kill_restore_dnode.py
+++ /dev/null
@@ -1,90 +0,0 @@
-###################################################################
-# Copyright (c) 2016 by TAOS Technologies, Inc.
-# All rights reserved.
-#
-# This file is proprietary and confidential to TAOS Technologies.
-# No part of this file may be reproduced, stored, transmitted,
-# disclosed or used in any form or by any means other than as
-# expressly provided by the written permission from Jianhui Tao
-#
-###################################################################
-
-# -*- coding: utf-8 -*-
-
-import sys
-
-from util.log import *
-from util.cases import *
-from util.sql import *
-from util.common import *
-sys.path.append("./3-enterprise/restore")
-from restoreBasic import *
-from util.common import tdCom
-import threading
-
-
-class TDTestCase:
- # init
- def init(self, conn, logSql, replicaVar=1):
- tdLog.debug("start to execute %s" % __file__)
- self.basic = RestoreBasic()
- self.basic.init(conn, logSql, replicaVar)
-
- # run
- def run(self):
- self.basic.restore_dnode_prepare(2)
-
- self.execute()
-
- def execute(self):
- newTdSql=tdCom.newTdSql()
- t0 = threading.Thread(target=self.restoreDnodeThread, args=('', newTdSql))
- t0.start()
-
- time.sleep(2)
- sql ="show transactions;"
- tdLog.info(sql)
- rows = tdSql.query(sql)
-
- if rows > 0:
- self.basic.stop_dnode(2)
-
- tranId = tdSql.getData(0, 0)
-
- tdLog.info('show transaction %d'%tranId)
- rows=tdSql.query('show transaction %d'%tranId, queryTimes=1)
- if rows != 11:
- tdLog.exit(f"restore transaction detial error, rows={rows}")
- return False
-
- tdLog.info('kill transaction %d'%tranId)
- tdSql.execute('kill transaction %d'%tranId, queryTimes=1 )
-
- time.sleep(3)
- sql ="show transactions;"
- tdLog.info(sql)
- rows = tdSql.query(sql)
- if rows > 0:
- tdLog.info(f"{sql} transaction not finished")
- return False
-
- self.basic.restore_dnode_exec(2)
- else:
- tdLog.exit(f"{sql} no transaction exist")
- return False
-
- def restoreDnodeThread(self, p, newTdSql):
- sleep(1)
-
- sql = f"restore dnode 2"
- tdLog.info(sql)
- newTdSql.error(sql, expectErrInfo="Wrong transaction execution context")
- tdLog.info(f"{sql} finished")
-
- # stop
- def stop(self):
- self.basic.stop()
- tdLog.success("%s successfully executed" % __file__)
-
-tdCases.addWindows(__file__, TDTestCase())
-tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
diff --git a/tests/system-test/3-enterprise/restore/restoreBasic.py b/tests/system-test/3-enterprise/restore/restoreBasic.py
index 74cf572018..77fa606b9c 100644
--- a/tests/system-test/3-enterprise/restore/restoreBasic.py
+++ b/tests/system-test/3-enterprise/restore/restoreBasic.py
@@ -143,34 +143,6 @@ class RestoreBasic:
tdSql.execute(sql)
self.check_corrent()
- def restore_dnode_prepare(self, index):
- tdLog.info(f"start restore dnode {index}")
- dnode = self.dnodes[index - 1]
-
- # stop dnode
- tdLog.info(f"stop dnode {index}")
- dnode.stoptaosd()
-
- # remove dnode folder
- try:
- shutil.rmtree(dnode.dataDir)
- tdLog.info(f"delete dir {dnode.dataDir} successful")
- except OSError as x:
- tdLog.exit(f"remove path {dnode.dataDir} error : {x.strerror}")
-
- dnode.starttaosd()
-
- def restore_dnode_exec(self, index):
- # exec restore
- sql = f"restore dnode {index}"
- tdLog.info(sql)
- tdSql.execute(sql)
- self.check_corrent()
-
- def stop_dnode(self, index):
- dnode = self.dnodes[index - 1]
-
- dnode.starttaosd()
# restore vnode
def restore_vnode(self, index):
tdLog.info(f"start restore vnode on dnode {index}")
From 9a1b80847af1dd1efae96d00993a9c58bec0c1a1 Mon Sep 17 00:00:00 2001
From: Shengliang Guan
Date: Sun, 29 Dec 2024 19:40:32 +0800
Subject: [PATCH 55/56] Revert "Revert "Revert "Revert "Enh:[td 29974]improve
trans""""
---
docs/en/08-operation/04-maintenance.md | 2 +-
docs/en/14-reference/03-taos-sql/24-show.md | 3 +-
docs/zh/08-operation/04-maintenance.md | 2 +-
docs/zh/14-reference/03-taos-sql/24-show.md | 3 +-
include/common/systable.h | 1 +
include/common/tmsg.h | 2 +
include/libs/nodes/cmdnodes.h | 5 +
include/util/taoserror.h | 1 +
include/util/tdef.h | 6 +-
source/common/src/systable.c | 12 +
source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 1 +
source/dnode/mnode/impl/inc/mndDef.h | 8 +
source/dnode/mnode/impl/inc/mndTrans.h | 4 +
.../dnode/mnode/impl/src/mndCompactDetail.c | 2 +
source/dnode/mnode/impl/src/mndDb.c | 3 +
source/dnode/mnode/impl/src/mndShow.c | 5 +-
source/dnode/mnode/impl/src/mndTrans.c | 484 +++++++++++++++++-
source/dnode/mnode/impl/src/mndVgroup.c | 16 +-
source/libs/executor/src/sysscanoperator.c | 3 +-
source/libs/nodes/src/nodesCodeFuncs.c | 2 +
source/libs/nodes/src/nodesUtilFuncs.c | 8 +
source/libs/parser/inc/parAst.h | 1 +
source/libs/parser/inc/sql.y | 1 +
source/libs/parser/src/parAstCreater.c | 12 +
source/libs/parser/src/parAstParser.c | 8 +
source/libs/parser/src/parTranslater.c | 51 +-
source/util/src/terror.c | 1 +
.../develop-test/2-query/table_count_scan.py | 16 +-
tests/parallel_test/cases.task | 3 +
tests/script/tsim/query/sys_tbname.sim | 2 +-
tests/script/tsim/query/tableCount.sim | 6 +-
.../0-others/information_schema.py | 6 +-
.../0-others/kill_balance_leader.py | 64 +++
.../0-others/show_transaction_detail.py | 115 +++++
tests/system-test/2-query/union.py | 2 +-
.../restore/kill_restore_dnode.py | 90 ++++
.../3-enterprise/restore/restoreBasic.py | 28 +
37 files changed, 929 insertions(+), 50 deletions(-)
create mode 100644 tests/system-test/0-others/kill_balance_leader.py
create mode 100644 tests/system-test/0-others/show_transaction_detail.py
create mode 100644 tests/system-test/3-enterprise/restore/kill_restore_dnode.py
diff --git a/docs/en/08-operation/04-maintenance.md b/docs/en/08-operation/04-maintenance.md
index 970ee40d18..2f6afbf9df 100644
--- a/docs/en/08-operation/04-maintenance.md
+++ b/docs/en/08-operation/04-maintenance.md
@@ -17,7 +17,7 @@ TDengine is designed for various writing scenarios, and many of these scenarios
```sql
COMPACT DATABASE db_name [start with 'XXXX'] [end with 'YYYY'];
-SHOW COMPACTS [compact_id];
+SHOW COMPACT [compact_id];
KILL COMPACT compact_id;
```
diff --git a/docs/en/14-reference/03-taos-sql/24-show.md b/docs/en/14-reference/03-taos-sql/24-show.md
index 36c20df0b4..b46fb41fa0 100644
--- a/docs/en/14-reference/03-taos-sql/24-show.md
+++ b/docs/en/14-reference/03-taos-sql/24-show.md
@@ -304,9 +304,10 @@ Displays information about all topics in the current database.
```sql
SHOW TRANSACTIONS;
+SHOW TRANSACTION [tranaction_id];
```
-Displays information about transactions currently being executed in the system (these transactions are only for metadata level, not for regular tables).
+Displays information about one of or all transaction(s) currently being executed in the system (these transactions are only for metadata level, not for regular tables).
## SHOW USERS
diff --git a/docs/zh/08-operation/04-maintenance.md b/docs/zh/08-operation/04-maintenance.md
index 9ef165179d..429542485d 100644
--- a/docs/zh/08-operation/04-maintenance.md
+++ b/docs/zh/08-operation/04-maintenance.md
@@ -19,7 +19,7 @@ TDengine 面向多种写入场景,而很多写入场景下,TDengine 的存
```SQL
COMPACT DATABASE db_name [start with 'XXXX'] [end with 'YYYY'];
COMPACT [db_name.]VGROUPS IN (vgroup_id1, vgroup_id2, ...) [start with 'XXXX'] [end with 'YYYY'];
-SHOW COMPACTS [compact_id];
+SHOW COMPACT [compact_id];
KILL COMPACT compact_id;
```
diff --git a/docs/zh/14-reference/03-taos-sql/24-show.md b/docs/zh/14-reference/03-taos-sql/24-show.md
index 4596a03281..3898920e65 100644
--- a/docs/zh/14-reference/03-taos-sql/24-show.md
+++ b/docs/zh/14-reference/03-taos-sql/24-show.md
@@ -306,9 +306,10 @@ SHOW TOPICS;
```sql
SHOW TRANSACTIONS;
+SHOW TRANSACTION [tranaction_id];
```
-显示当前系统中正在执行的事务的信息(该事务仅针对除普通表以外的元数据级别)
+显示当前系统中正在执行的所有或者某一个事务的信息(该事务仅针对除普通表以外的元数据级别)
## SHOW USERS
diff --git a/include/common/systable.h b/include/common/systable.h
index bd8ba76f4f..fe867c9ad0 100644
--- a/include/common/systable.h
+++ b/include/common/systable.h
@@ -63,6 +63,7 @@ extern "C" {
#define TSDB_INS_TABLE_TSMAS "ins_tsmas"
#define TSDB_INS_DISK_USAGE "ins_disk_usage"
#define TSDB_INS_TABLE_FILESETS "ins_filesets"
+#define TSDB_INS_TABLE_TRANSACTION_DETAILS "ins_transaction_details"
#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
#define TSDB_PERFS_TABLE_SMAS "perf_smas"
diff --git a/include/common/tmsg.h b/include/common/tmsg.h
index 0b6a8b3f1b..9488e54615 100644
--- a/include/common/tmsg.h
+++ b/include/common/tmsg.h
@@ -163,6 +163,7 @@ typedef enum _mgmt_table {
TSDB_MGMT_TABLE_ANODE_FULL,
TSDB_MGMT_TABLE_USAGE,
TSDB_MGMT_TABLE_FILESETS,
+ TSDB_MGMT_TABLE_TRANSACTION_DETAIL,
TSDB_MGMT_TABLE_MAX,
} EShowType;
@@ -405,6 +406,7 @@ typedef enum ENodeType {
QUERY_NODE_SHOW_CREATE_TSMA_STMT,
QUERY_NODE_DROP_TSMA_STMT,
QUERY_NODE_SHOW_FILESETS_STMT,
+ QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
// logic plan node
QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h
index 8eb30b8184..0f736e7068 100644
--- a/include/libs/nodes/cmdnodes.h
+++ b/include/libs/nodes/cmdnodes.h
@@ -439,6 +439,11 @@ typedef struct SShowCompactDetailsStmt {
SNode* pCompactId;
} SShowCompactDetailsStmt;
+typedef struct SShowTransactionDetailsStmt {
+ ENodeType type;
+ SNode* pTransactionId;
+} SShowTransactionDetailsStmt;
+
typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT, INDEX_TYPE_NORMAL } EIndexType;
typedef struct SIndexOptions {
diff --git a/include/util/taoserror.h b/include/util/taoserror.h
index e317fdd65a..890758762a 100644
--- a/include/util/taoserror.h
+++ b/include/util/taoserror.h
@@ -411,6 +411,7 @@ int32_t taosGetErrSize();
#define TSDB_CODE_MND_TRANS_CTX_SWITCH TAOS_DEF_ERROR_CODE(0, 0x03D8)
#define TSDB_CODE_MND_TRANS_CONFLICT_COMPACT TAOS_DEF_ERROR_CODE(0, 0x03D9)
#define TSDB_CODE_MND_TRANS_UNKNOW_ERROR TAOS_DEF_ERROR_CODE(0, 0x03DF)
+#define TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED TAOS_DEF_ERROR_CODE(0, 0x03D2)
// mnode-mq
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E0)
diff --git a/include/util/tdef.h b/include/util/tdef.h
index 2ee84b42bd..2b0aa00b1a 100644
--- a/include/util/tdef.h
+++ b/include/util/tdef.h
@@ -329,7 +329,11 @@ typedef enum ELogicConditionType {
#define TSDB_TRANS_STAGE_LEN 12
#define TSDB_TRANS_TYPE_LEN 16
-#define TSDB_TRANS_ERROR_LEN 512
+#define TSDB_TRANS_ERROR_LEN 512
+#define TSDB_TRANS_OBJTYPE_LEN 40
+#define TSDB_TRANS_RESULT_LEN 100
+#define TSDB_TRANS_TARGET_LEN 300
+#define TSDB_TRANS_DETAIL_LEN 100
#define TSDB_STEP_NAME_LEN 32
#define TSDB_STEP_DESC_LEN 128
diff --git a/source/common/src/systable.c b/source/common/src/systable.c
index cb08046399..38dce105bb 100644
--- a/source/common/src/systable.c
+++ b/source/common/src/systable.c
@@ -314,6 +314,8 @@ static const SSysDbTableSchema transSchema[] = {
{.name = "oper", .bytes = TSDB_TRANS_OPER_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "stable", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "killable", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ //{.name = "kill_mnode", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "failed_times", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
{.name = "last_exec_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
{.name = "last_action_info", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
@@ -403,6 +405,15 @@ static const SSysDbTableSchema userCompactsDetailSchema[] = {
{.name = "remain_time(s)", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = false},
};
+static const SSysDbTableSchema userTransactionDetailSchema[] = {
+ {.name = "transaction_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
+ {.name = "action", .bytes = 30 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "obj_type", .bytes = TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "result", .bytes = TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "target", .bytes = TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "detail", .bytes = TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+};
+
static const SSysDbTableSchema anodesSchema[] = {
{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
{.name = "url", .bytes = TSDB_ANALYTIC_ANODE_URL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
@@ -521,6 +532,7 @@ static const SSysTableMeta infosMeta[] = {
{TSDB_INS_TABLE_ANODES_FULL, anodesFullSchema, tListLen(anodesFullSchema), true},
{TSDB_INS_DISK_USAGE, diskUsageSchema, tListLen(diskUsageSchema), false},
{TSDB_INS_TABLE_FILESETS, filesetsFullSchema, tListLen(filesetsFullSchema), false},
+ {TSDB_INS_TABLE_TRANSACTION_DETAILS, userTransactionDetailSchema, tListLen(userTransactionDetailSchema), false},
};
static const SSysDbTableSchema connectionsSchema[] = {
diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
index 9ed4ee83c4..423268a8cc 100644
--- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
+++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
@@ -681,6 +681,7 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
return TSDB_CODE_INVALID_MSG;
}
+ dInfo("retrieve table:%s, user:%s, compactId:%" PRId64, retrieveReq.tb, retrieveReq.user, retrieveReq.compactId);
#if 0
if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
code = TSDB_CODE_MND_NO_RIGHTS;
diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h
index e3d2ad6d34..b32274e0a7 100644
--- a/source/dnode/mnode/impl/inc/mndDef.h
+++ b/source/dnode/mnode/impl/inc/mndDef.h
@@ -133,6 +133,12 @@ typedef enum {
TRN_EXEC_SERIAL = 1,
} ETrnExec;
+typedef enum {
+ TRN_KILL_MODE_SKIP = 0,
+ TRN_KILL_MODE_INTERUPT = 1,
+ //TRN_KILL_MODE_ROLLBACK = 2,
+} ETrnKillMode;
+
typedef enum {
DND_REASON_ONLINE = 0,
DND_REASON_STATUS_MSG_TIMEOUT,
@@ -201,6 +207,8 @@ typedef struct {
SRWLatch lockRpcArray;
int64_t mTraceId;
TdThreadMutex mutex;
+ bool ableToBeKilled;
+ ETrnKillMode killMode;
} STrans;
typedef struct {
diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h
index 7f039bc21f..05280d0d68 100644
--- a/source/dnode/mnode/impl/inc/mndTrans.h
+++ b/source/dnode/mnode/impl/inc/mndTrans.h
@@ -54,6 +54,8 @@ typedef struct {
SSdbRaw *pRaw;
int64_t mTraceId;
+ int64_t startTime;
+ int64_t endTime;
} STransAction;
typedef void (*TransCbFp)(SMnode *pMnode, void *param, int32_t paramLen);
@@ -80,6 +82,8 @@ void mndTransSetCb(STrans *pTrans, ETrnFunc startFunc, ETrnFunc stopFunc, voi
void mndTransSetDbName(STrans *pTrans, const char *dbname, const char *stbname);
void mndTransAddArbGroupId(STrans *pTrans, int32_t groupId);
void mndTransSetSerial(STrans *pTrans);
+void mndTransSetBeKilled(STrans *pTrans, bool ableToBeKilled);
+void mndTransSetKillMode(STrans *pTrans, ETrnKillMode killMode);
void mndTransSetParallel(STrans *pTrans);
void mndTransSetChangeless(STrans *pTrans);
void mndTransSetOper(STrans *pTrans, EOperType oper);
diff --git a/source/dnode/mnode/impl/src/mndCompactDetail.c b/source/dnode/mnode/impl/src/mndCompactDetail.c
index 9a053066b2..0052f5de56 100644
--- a/source/dnode/mnode/impl/src/mndCompactDetail.c
+++ b/source/dnode/mnode/impl/src/mndCompactDetail.c
@@ -45,6 +45,8 @@ int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
char *sep = NULL;
SDbObj *pDb = NULL;
+ mInfo("retrieve compact detail");
+
if (strlen(pShow->db) > 0) {
sep = strchr(pShow->db, '.');
if (sep &&
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index c28fd343f0..1efbff9d53 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -1270,6 +1270,7 @@ static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *p
TAOS_RETURN(code);
}
mInfo("trans:%d, used to alter db:%s", pTrans->id, pOld->name);
+ mInfo("trans:%d, used to alter db, ableToBeKilled:%d, killMode:%d", pTrans->id, pTrans->ableToBeKilled, pTrans->killMode);
mndTransSetDbName(pTrans, pOld->name, NULL);
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
@@ -1278,6 +1279,8 @@ static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *p
TAOS_CHECK_GOTO(mndSetAlterDbPrepareLogs(pMnode, pTrans, pOld, pNew), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterDbCommitLogs(pMnode, pTrans, pOld, pNew), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterDbRedoActions(pMnode, pTrans, pOld, pNew), NULL, _OVER);
+
+ mInfo("trans:%d, used to alter db, ableToBeKilled:%d, killMode:%d", pTrans->id, pTrans->ableToBeKilled, pTrans->killMode);
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
code = 0;
diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c
index 49dc62d471..f19eabd885 100644
--- a/source/dnode/mnode/impl/src/mndShow.c
+++ b/source/dnode/mnode/impl/src/mndShow.c
@@ -132,6 +132,8 @@ static int32_t convertToRetrieveType(char *name, int32_t len) {
type = TSDB_MGMT_TABLE_COMPACT;
} else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
+ } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
+ type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
} else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
type = TSDB_MGMT_TABLE_GRANTS_FULL;
} else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
@@ -236,7 +238,8 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
SRetrieveTableReq retrieveReq = {0};
TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq));
- mDebug("process to retrieve systable req db:%s, tb:%s", retrieveReq.db, retrieveReq.tb);
+ mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
+ retrieveReq.compactId);
if (retrieveReq.showId == 0) {
STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c
index 718b7d0df6..83fad45919 100644
--- a/source/dnode/mnode/impl/src/mndTrans.c
+++ b/source/dnode/mnode/impl/src/mndTrans.c
@@ -14,19 +14,21 @@
*/
#define _DEFAULT_SOURCE
+#include "mndTrans.h"
#include "mndDb.h"
#include "mndPrivilege.h"
#include "mndShow.h"
#include "mndStb.h"
#include "mndSubscribe.h"
#include "mndSync.h"
-#include "mndTrans.h"
#include "mndUser.h"
+#include "mndVgroup.h"
+#include "osTime.h"
#define TRANS_VER1_NUMBER 1
#define TRANS_VER2_NUMBER 2
#define TRANS_ARRAY_SIZE 8
-#define TRANS_RESERVE_SIZE 44
+#define TRANS_RESERVE_SIZE 42
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans);
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *OldTrans, STrans *pOld);
@@ -70,7 +72,7 @@ static int32_t mndProcessKillTransReq(SRpcMsg *pReq);
static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter);
-
+static int32_t mndRetrieveTransDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
static int32_t tsMaxTransId = 0;
int32_t mndInitTrans(SMnode *pMnode) {
@@ -89,6 +91,7 @@ int32_t mndInitTrans(SMnode *pMnode) {
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndRetrieveTrans);
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndCancelGetNextTrans);
+ mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TRANSACTION_DETAIL, mndRetrieveTransDetail);
return sdbSetTable(pMnode->pSdb, table);
}
@@ -156,7 +159,7 @@ SSdbRaw *mndTransEncode(STrans *pTrans) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_INVALID_MSG;
- int8_t sver = taosArrayGetSize(pTrans->prepareActions) ? TRANS_VER2_NUMBER : TRANS_VER1_NUMBER;
+ int8_t sver = TRANS_VER2_NUMBER;
int32_t rawDataLen = sizeof(STrans) + TRANS_RESERVE_SIZE + pTrans->paramLen;
rawDataLen += mndTransGetActionsSize(pTrans->prepareActions);
@@ -220,6 +223,11 @@ SSdbRaw *mndTransEncode(STrans *pTrans) {
pIter = taosHashIterate(pTrans->arbGroupIds, pIter);
}
+ if (sver > TRANS_VER1_NUMBER) {
+ SDB_SET_INT8(pRaw, dataPos, pTrans->ableToBeKilled, _OVER)
+ SDB_SET_INT32(pRaw, dataPos, pTrans->killMode, _OVER)
+ }
+
SDB_SET_RESERVE(pRaw, dataPos, TRANS_RESERVE_SIZE, _OVER)
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
@@ -310,7 +318,7 @@ SSdbRow *mndTransDecode(SSdbRaw *pRaw) {
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
- if (sver != TRANS_VER1_NUMBER && sver != TRANS_VER2_NUMBER) {
+ if (sver > TRANS_VER2_NUMBER) {
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
goto _OVER;
}
@@ -389,6 +397,13 @@ SSdbRow *mndTransDecode(SSdbRaw *pRaw) {
if ((terrno = taosHashPut(pTrans->arbGroupIds, &arbGroupId, sizeof(int32_t), NULL, 0)) != 0) goto _OVER;
}
+ int8_t ableKill = 0;
+ int8_t killMode = 0;
+ SDB_GET_INT8(pRaw, dataPos, &ableKill, _OVER)
+ SDB_GET_INT8(pRaw, dataPos, &killMode, _OVER)
+ pTrans->ableToBeKilled = ableKill;
+ pTrans->killMode = killMode;
+
SDB_GET_RESERVE(pRaw, dataPos, TRANS_RESERVE_SIZE, _OVER)
terrno = 0;
@@ -430,12 +445,25 @@ static const char *mndTransStr(ETrnStage stage) {
}
}
+static const char *mndTransTypeStr(ETrnAct actionType) {
+ switch (actionType) {
+ case TRANS_ACTION_MSG:
+ return "msg";
+ case TRANS_ACTION_RAW:
+ return "sdb";
+ default:
+ return "invalid";
+ }
+}
+
static void mndSetTransLastAction(STrans *pTrans, STransAction *pAction) {
if (pAction != NULL) {
- pTrans->lastAction = pAction->id;
- pTrans->lastMsgType = pAction->msgType;
- pTrans->lastEpset = pAction->epSet;
- pTrans->lastErrorNo = pAction->errCode;
+ if (pAction->errCode != TSDB_CODE_ACTION_IN_PROGRESS) {
+ pTrans->lastAction = pAction->id;
+ pTrans->lastMsgType = pAction->msgType;
+ pTrans->lastEpset = pAction->epSet;
+ pTrans->lastErrorNo = pAction->errCode;
+ }
} else {
pTrans->lastAction = 0;
pTrans->lastMsgType = 0;
@@ -636,6 +664,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnConflct conflict,
pTrans->policy = policy;
pTrans->conflict = conflict;
pTrans->exec = TRN_EXEC_PARALLEL;
+ pTrans->ableToBeKilled = false;
pTrans->createdTime = taosGetTimestampMs();
pTrans->prepareActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
pTrans->redoActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
@@ -804,6 +833,13 @@ void mndTransAddArbGroupId(STrans *pTrans, int32_t groupId) {
void mndTransSetSerial(STrans *pTrans) { pTrans->exec = TRN_EXEC_SERIAL; }
+void mndTransSetBeKilled(STrans *pTrans, bool ableToBeKilled) { pTrans->ableToBeKilled = ableToBeKilled; }
+
+void mndTransSetKillMode(STrans *pTrans, ETrnKillMode killMode) {
+ pTrans->ableToBeKilled = true;
+ pTrans->killMode = killMode;
+}
+
void mndTransSetParallel(STrans *pTrans) { pTrans->exec = TRN_EXEC_PARALLEL; }
void mndTransSetChangeless(STrans *pTrans) { pTrans->changeless = true; }
@@ -1043,6 +1079,39 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
return TSDB_CODE_INVALID_PARA;
}
+ mInfo("trans:%d, action list:", pTrans->id);
+ int32_t index = 0;
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->prepareActions); ++i, ++index) {
+ STransAction *pAction = taosArrayGet(pTrans->prepareActions, i);
+ mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index,
+ mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
+ }
+
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->redoActions); ++i, ++index) {
+ STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
+ mInfo("trans:%d, action:%d, %s:%d msgType:%s", pTrans->id, index,
+ mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType));;
+ }
+
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->commitActions); ++i, ++index) {
+ STransAction *pAction = taosArrayGet(pTrans->commitActions, i);
+ mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index,
+ mndTransStr(pAction->stage), i, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
+ }
+
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->undoActions); ++i, ++index) {
+ STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
+ if(pAction->actionType == TRANS_ACTION_MSG){
+ mInfo("trans:%d, action:%d, %s:%d msgType:%s", pTrans->id, index,
+ mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType));;
+ }
+ else{
+ mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index,
+ mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
+ }
+ }
+
+
TAOS_CHECK_RETURN(mndTransCheckConflict(pMnode, pTrans));
TAOS_CHECK_RETURN(mndTransCheckParallelActions(pMnode, pTrans));
@@ -1260,7 +1329,10 @@ int32_t mndTransProcessRsp(SRpcMsg *pRsp) {
if (pAction != NULL) {
pAction->msgReceived = 1;
pAction->errCode = pRsp->code;
- pTrans->lastErrorNo = pRsp->code;
+ pAction->endTime = taosGetTimestampMs();
+
+ // pTrans->lastErrorNo = pRsp->code;
+ mndSetTransLastAction(pTrans, pAction);
mInfo("trans:%d, %s:%d response is received, received code:0x%x(%s), accept:0x%x(%s) retry:0x%x(%s)", transId,
mndTransStr(pAction->stage), action, pRsp->code, tstrerror(pRsp->code), pAction->acceptableCode,
@@ -1374,6 +1446,8 @@ static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransActio
pAction->msgSent = 1;
// pAction->msgReceived = 0;
pAction->errCode = TSDB_CODE_ACTION_IN_PROGRESS;
+ pAction->startTime = taosGetTimestampMs();
+ pAction->endTime = 0;
mInfo("trans:%d, %s:%d is sent, %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, detail);
mndSetTransLastAction(pTrans, pAction);
@@ -1527,8 +1601,9 @@ static int32_t mndTransExecuteActionsSerial(SMnode *pMnode, STrans *pTrans, SArr
for (int32_t action = pTrans->actionPos; action < numOfActions; ++action) {
STransAction *pAction = taosArrayGet(pActions, action);
- mInfo("trans:%d, current action:%d, stage:%s, actionType(1:msg,2:log):%d", pTrans->id, pTrans->actionPos,
- mndTransStr(pAction->stage), pAction->actionType);
+ mInfo("trans:%d, current action:%d, stage:%s, actionType(1:msg,2:log):%d, msgSent:%d, msgReceived:%d",
+ pTrans->id, pTrans->actionPos, mndTransStr(pAction->stage), pAction->actionType, pAction->msgSent,
+ pAction->msgReceived);
code = mndTransExecSingleAction(pMnode, pTrans, pAction, topHalf);
if (code == 0) {
@@ -1924,13 +1999,25 @@ int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) {
TAOS_RETURN(TSDB_CODE_MND_TRANS_INVALID_STAGE);
}
- for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
- STransAction *pAction = taosArrayGet(pArray, i);
- mInfo("trans:%d, %s:%d set processed for kill msg received, errCode from %s to success", pTrans->id,
- mndTransStr(pAction->stage), i, tstrerror(pAction->errCode));
- pAction->msgSent = 1;
- pAction->msgReceived = 1;
- pAction->errCode = 0;
+ if(pTrans->ableToBeKilled == false){
+ return TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED;
+ }
+
+ if(pTrans->killMode == TRN_KILL_MODE_SKIP){
+ for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
+ STransAction *pAction = taosArrayGet(pArray, i);
+ mInfo("trans:%d, %s:%d set processed for kill msg received, errCode from %s to success", pTrans->id,
+ mndTransStr(pAction->stage), i, tstrerror(pAction->errCode));
+ pAction->msgSent = 1;
+ pAction->msgReceived = 1;
+ pAction->errCode = 0;
+ }
+ }
+ else if(pTrans->killMode == TRN_KILL_MODE_INTERUPT){
+ pTrans->stage = TRN_STAGE_PRE_FINISH;
+ }
+ else{
+ return TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED;
}
mndTransExecute(pMnode, pTrans);
@@ -2002,6 +2089,114 @@ void mndTransPullup(SMnode *pMnode) {
taosArrayDestroy(pArray);
}
+static char *formatTimestamp(char *buf, int64_t val, int precision) {
+ time_t tt;
+ if (precision == TSDB_TIME_PRECISION_MICRO) {
+ tt = (time_t)(val / 1000000);
+ }
+ if (precision == TSDB_TIME_PRECISION_NANO) {
+ tt = (time_t)(val / 1000000000);
+ } else {
+ tt = (time_t)(val / 1000);
+ }
+
+ struct tm tm;
+ if (taosLocalTime(&tt, &tm, NULL, 0, NULL) == NULL) {
+ mError("failed to get local time");
+ return NULL;
+ }
+ size_t pos = taosStrfTime(buf, 32, "%Y-%m-%d %H:%M:%S", &tm);
+
+ if (precision == TSDB_TIME_PRECISION_MICRO) {
+ sprintf(buf + pos, ".%06d", (int)(val % 1000000));
+ } else if (precision == TSDB_TIME_PRECISION_NANO) {
+ sprintf(buf + pos, ".%09d", (int)(val % 1000000000));
+ } else {
+ sprintf(buf + pos, ".%03d", (int)(val % 1000));
+ }
+
+ return buf;
+}
+
+static void mndTransLogAction(STrans *pTrans) {
+ char detail[512] = {0};
+ int32_t len = 0;
+ int32_t index = 0;
+
+ if (pTrans->stage == TRN_STAGE_PREPARE) {
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->prepareActions); ++i, ++index) {
+ len = 0;
+ STransAction *pAction = taosArrayGet(pTrans->prepareActions, i);
+ len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
+ mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
+ sdbStatusName(pAction->pRaw->status));
+ mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
+ }
+ }
+
+ if (pTrans->stage == TRN_STAGE_REDO_ACTION) {
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->redoActions); ++i, ++index) {
+ len = 0;
+ STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
+ if (pAction->actionType == TRANS_ACTION_MSG) {
+ char bufStart[40] = {0};
+ (void)formatTimestamp(bufStart, pAction->startTime, TSDB_TIME_PRECISION_MILLI);
+
+ char endStart[40] = {0};
+ (void)formatTimestamp(endStart, pAction->endTime, TSDB_TIME_PRECISION_MILLI);
+ len += snprintf(detail + len, sizeof(detail) - len,
+ "action:%d, %s:%d msgType:%s,"
+ "sent:%d, received:%d, startTime:%s, endTime:%s, ",
+ index, mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType), pAction->msgSent,
+ pAction->msgReceived, bufStart, endStart);
+
+ SEpSet epset = pAction->epSet;
+ if (epset.numOfEps > 0) {
+ len += snprintf(detail + len, sizeof(detail) - len, "numOfEps:%d inUse:%d ", epset.numOfEps, epset.inUse);
+ for (int32_t i = 0; i < epset.numOfEps; ++i) {
+ len +=
+ snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
+ }
+ }
+
+ len += snprintf(detail + len, sizeof(detail) - len, ", errCode:0x%x(%s)\n", pAction->errCode & 0xFFFF,
+ tstrerror(pAction->errCode));
+ } else {
+ len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s, written:%d\n",
+ index, mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
+ sdbStatusName(pAction->pRaw->status), pAction->rawWritten);
+ }
+ mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
+ }
+ }
+
+ if (pTrans->stage == TRN_STAGE_COMMIT_ACTION) {
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->commitActions); ++i, ++index) {
+ len = 0;
+ STransAction *pAction = taosArrayGet(pTrans->commitActions, i);
+ len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
+ mndTransStr(pAction->stage), i, sdbTableName(pAction->pRaw->type),
+ sdbStatusName(pAction->pRaw->status));
+ mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
+ }
+
+ for (int32_t i = 0; i < taosArrayGetSize(pTrans->undoActions); ++i, ++index) {
+ len = 0;
+ STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
+ if (pAction->actionType == TRANS_ACTION_MSG) {
+ len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d msgType:%s\n", index,
+ mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType));
+ ;
+ } else {
+ len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
+ mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
+ sdbStatusName(pAction->pRaw->status));
+ }
+ mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
+ }
+ }
+}
+
static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
SMnode *pMnode = pReq->info.node;
SSdb *pSdb = pMnode->pSdb;
@@ -2044,6 +2239,20 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)stbname, false), pTrans, &lino, _OVER);
+ const char *killableStr = pTrans->ableToBeKilled ? "yes" : "no";
+ char killableVstr[10 + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(killableVstr, killableStr, 10 + VARSTR_HEADER_SIZE);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)killableVstr, false), pTrans, &lino, _OVER);
+
+ /*
+ const char *killModeStr = pTrans->killMode == TRN_KILL_MODE_SKIP ? "skip" : "interrupt";
+ char killModeVstr[10 + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(killModeVstr, killModeStr, 24);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)killModeVstr, false), pTrans, &lino, _OVER);
+ */
+
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->failedTimes, false), pTrans, &lino,
_OVER);
@@ -2061,13 +2270,15 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
len += tsnprintf(detail + len, sizeof(detail) - len, "msgType:%s numOfEps:%d inUse:%d ",
TMSG_INFO(pTrans->lastMsgType), epset.numOfEps, epset.inUse);
for (int32_t i = 0; i < pTrans->lastEpset.numOfEps; ++i) {
- len += tsnprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
+ len += snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
}
}
STR_WITH_MAXSIZE_TO_VARSTR(lastInfo, detail, pShow->pMeta->pSchemas[cols].bytes);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)lastInfo, false), pTrans, &lino, _OVER);
+ mndTransLogAction(pTrans);
+
numOfRows++;
sdbRelease(pSdb, pTrans);
}
@@ -2078,6 +2289,239 @@ _OVER:
return numOfRows;
}
+static int32_t mndShowTransCommonColumns(SShowObj *pShow, SSDataBlock *pBlock, STransAction *pAction,
+ int32_t transactionId, int32_t curActionId, int32_t numOfRows, int32_t *cols) {
+ int32_t code = 0;
+ int32_t lino = 0;
+ int32_t len = 0;
+
+ SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, (*cols)++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&transactionId, false), &lino, _OVER);
+
+ char action[30 + 1] = {0};
+ if (curActionId == pAction->id) {
+ len += snprintf(action + len, sizeof(action) - len, "%s:%d(%s)<-last", mndTransStr(pAction->stage), pAction->id,
+ mndTransTypeStr(pAction->actionType));
+ } else {
+ len += snprintf(action + len, sizeof(action) - len, "%s:%d(%s)", mndTransStr(pAction->stage), pAction->id,
+ mndTransTypeStr(pAction->actionType));
+ }
+ char actionVStr[30 + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(actionVStr, action, pShow->pMeta->pSchemas[*cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, (*cols)++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)actionVStr, false), &lino, _OVER);
+_OVER:
+ if (code != 0) mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
+ return code;
+}
+
+static void mndShowTransAction(SShowObj *pShow, SSDataBlock *pBlock, STransAction *pAction, int32_t transactionId,
+ int32_t curActionId, int32_t rows, int32_t numOfRows) {
+ int32_t code = 0;
+ int32_t lino = 0;
+ int32_t len = 0;
+ int32_t cols = 0;
+
+ cols = 0;
+
+ if (mndShowTransCommonColumns(pShow, pBlock, pAction, transactionId, curActionId, numOfRows, &cols) != 0) return;
+
+ if (pAction->actionType == TRANS_ACTION_MSG) {
+ int32_t len = 0;
+
+ char objType[TSDB_TRANS_OBJTYPE_LEN + 1] = {0};
+ len += snprintf(objType + len, sizeof(objType) - len, "%s(s:%d,r:%d)", TMSG_INFO(pAction->msgType),
+ pAction->msgSent, pAction->msgReceived);
+ char objTypeVStr[TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(objTypeVStr, objType, pShow->pMeta->pSchemas[cols].bytes);
+ SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)objTypeVStr, false), &lino, _OVER);
+
+ char result[TSDB_TRANS_RESULT_LEN + 1] = {0};
+ len = 0;
+ len += snprintf(result + len, sizeof(result) - len, "errCode:0x%x(%s)", pAction->errCode & 0xFFFF,
+ tstrerror(pAction->errCode));
+ char resultVStr[TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(resultVStr, result, pShow->pMeta->pSchemas[cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)resultVStr, false), &lino, _OVER);
+
+ char target[TSDB_TRANS_TARGET_LEN] = {0};
+ len = 0;
+ SEpSet epset = pAction->epSet;
+ if (epset.numOfEps > 0) {
+ for (int32_t i = 0; i < epset.numOfEps; ++i) {
+ len += snprintf(target + len, sizeof(target) - len, "ep:%d-%s:%u,", i, epset.eps[i].fqdn, epset.eps[i].port);
+ }
+ len += snprintf(target + len, sizeof(target) - len, "(%d:%d) ", epset.numOfEps, epset.inUse);
+ }
+ char targetVStr[TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(targetVStr, target, pShow->pMeta->pSchemas[cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)targetVStr, false), &lino, _OVER);
+
+ char detail[TSDB_TRANS_DETAIL_LEN] = {0};
+ len = 0;
+ char bufStart[40] = {0};
+ if (pAction->startTime > 0) (void)formatTimestamp(bufStart, pAction->startTime, TSDB_TIME_PRECISION_MILLI);
+ char bufEnd[40] = {0};
+ if (pAction->endTime > 0) (void)formatTimestamp(bufEnd, pAction->endTime, TSDB_TIME_PRECISION_MILLI);
+ len += snprintf(detail + len, sizeof(detail) - len, "startTime:%s, endTime:%s, ", bufStart, bufEnd);
+ char detailVStr[TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(detailVStr, detail, pShow->pMeta->pSchemas[cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)detailVStr, false), &lino, _OVER);
+
+ } else {
+ int32_t len = 0;
+
+ char objType[TSDB_TRANS_OBJTYPE_LEN + 1] = {0};
+ if (pAction->pRaw->type == SDB_VGROUP) {
+ SSdbRow *pRow = mndVgroupActionDecode(pAction->pRaw);
+ SVgObj *pVgroup = sdbGetRowObj(pRow);
+ len += snprintf(objType + len, sizeof(objType) - len, "%s(%d)", sdbTableName(pAction->pRaw->type), pVgroup->vgId);
+ taosMemoryFreeClear(pRow);
+ } else {
+ strcpy(objType, sdbTableName(pAction->pRaw->type));
+ }
+ char objTypeVStr[TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(objTypeVStr, objType, pShow->pMeta->pSchemas[cols].bytes);
+ SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)objTypeVStr, false), &lino, _OVER);
+
+ char result[TSDB_TRANS_RESULT_LEN + 1] = {0};
+ len = 0;
+ len += snprintf(result + len, sizeof(result) - len, "rawWritten:%d", pAction->rawWritten);
+ char resultVStr[TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(resultVStr, result, pShow->pMeta->pSchemas[cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)resultVStr, false), &lino, _OVER);
+
+ char target[TSDB_TRANS_TARGET_LEN] = "";
+ char targetVStr[TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(targetVStr, target, pShow->pMeta->pSchemas[cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)targetVStr, false), &lino, _OVER);
+
+ char detail[TSDB_TRANS_DETAIL_LEN] = {0};
+ len = 0;
+ len += snprintf(detail + len, sizeof(detail) - len, "sdbStatus:%s", sdbStatusName(pAction->pRaw->status));
+ char detailVStr[TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(detailVStr, detail, pShow->pMeta->pSchemas[cols].bytes);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)detailVStr, false), &lino, _OVER);
+ }
+
+_OVER:
+ if (code != 0) mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
+}
+
+static SArray *mndTransGetAction(STrans *pTrans, ETrnStage stage) {
+ if (stage == TRN_STAGE_PREPARE) {
+ return pTrans->prepareActions;
+ }
+ if (stage == TRN_STAGE_REDO_ACTION) {
+ return pTrans->redoActions;
+ }
+ if (stage == TRN_STAGE_COMMIT_ACTION) {
+ return pTrans->commitActions;
+ }
+ if (stage == TRN_STAGE_UNDO_ACTION) {
+ return pTrans->undoActions;
+ }
+ return NULL;
+}
+
+typedef struct STransDetailIter {
+ void *pIter;
+ STrans *pTrans;
+ ETrnStage stage;
+ int32_t num;
+} STransDetailIter;
+
+static void mndTransShowActions(SSdb *pSdb, STransDetailIter *pShowIter, SShowObj *pShow, SSDataBlock *pBlock,
+ int32_t rows, int32_t *numOfRows, SArray *pActions, int32_t end, int32_t start) {
+ int32_t actionNum = taosArrayGetSize(pActions);
+ mInfo("stage:%s, Actions num:%d", mndTransStr(pShowIter->stage), actionNum);
+
+ for (int32_t i = start; i < actionNum; ++i) {
+ STransAction *pAction = taosArrayGet(pShowIter->pTrans->redoActions, i);
+ mndShowTransAction(pShow, pBlock, pAction, pShowIter->pTrans->id, pShowIter->pTrans->lastAction, rows, *numOfRows);
+ (*numOfRows)++;
+ if (*numOfRows >= rows) break;
+ }
+
+ if (*numOfRows == end) {
+ sdbRelease(pSdb, pShowIter->pTrans);
+ pShowIter->pTrans = NULL;
+ pShowIter->num = 0;
+ } else {
+ pShowIter->pTrans = pShowIter->pTrans;
+ pShowIter->stage = pShowIter->pTrans->stage;
+ pShowIter->num += (*numOfRows);
+ }
+}
+
+static int32_t mndRetrieveTransDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
+ SMnode *pMnode = pReq->info.node;
+ SSdb *pSdb = pMnode->pSdb;
+ int32_t numOfRows = 0;
+
+ int32_t code = 0;
+ int32_t lino = 0;
+
+ mInfo("start to mndRetrieveTransDetail, rows:%d, pShow->numOfRows:%d, pShow->pIter:%p", rows, pShow->numOfRows,
+ pShow->pIter);
+
+ if (pShow->pIter == NULL) {
+ pShow->pIter = taosMemoryMalloc(sizeof(STransDetailIter));
+ if (pShow->pIter == NULL) {
+ mError("failed to malloc for pShow->pIter");
+ return 0;
+ }
+ memset(pShow->pIter, 0, sizeof(STransDetailIter));
+ }
+
+ STransDetailIter *pShowIter = (STransDetailIter *)pShow->pIter;
+
+ while (numOfRows < rows) {
+ if (pShowIter->pTrans == NULL) {
+ pShowIter->pIter = sdbFetch(pSdb, SDB_TRANS, pShowIter->pIter, (void **)&(pShowIter->pTrans));
+ mDebug("retrieve trans detail from fetch, pShow->pIter:%p, pTrans:%p", pShowIter->pIter, pShowIter->pTrans);
+ if (pShowIter->pIter == NULL) break;
+ mInfo("retrieve trans detail from fetch, id:%d, trans stage:%d, IterNum:%d", pShowIter->pTrans->id,
+ pShowIter->pTrans->stage, pShowIter->num);
+
+ SArray *pActions = mndTransGetAction(pShowIter->pTrans, pShowIter->pTrans->stage);
+
+ mndTransShowActions(pSdb, pShowIter, pShow, pBlock, rows, &numOfRows, pActions, taosArrayGetSize(pActions), 0);
+ break;
+ } else {
+ mInfo("retrieve trans detail from iter, id:%d, iterStage:%d, IterNum:%d", pShowIter->pTrans->id, pShowIter->stage,
+ pShowIter->num);
+ SArray *pActions = mndTransGetAction(pShowIter->pTrans, pShowIter->stage);
+
+ mndTransShowActions(pSdb, pShowIter, pShow, pBlock, rows, &numOfRows, pActions,
+ taosArrayGetSize(pActions) - pShowIter->num, pShowIter->num);
+ break;
+ }
+ }
+
+_OVER:
+ pShow->numOfRows += numOfRows;
+
+ if (code != 0) {
+ mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
+ } else {
+ mInfo("retrieve trans detail, numOfRows:%d, pShow->numOfRows:%d", numOfRows, pShow->numOfRows)
+ }
+ if (numOfRows == 0) {
+ taosMemoryFree(pShow->pIter);
+ pShow->pIter = NULL;
+ }
+ return numOfRows;
+}
+
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter) {
SSdb *pSdb = pMnode->pSdb;
sdbCancelFetchByType(pSdb, pIter, SDB_TRANS);
diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c
index 0bce21290b..e20afb7201 100644
--- a/source/dnode/mnode/impl/src/mndVgroup.c
+++ b/source/dnode/mnode/impl/src/mndVgroup.c
@@ -2766,12 +2766,14 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
mndTransSetSerial(pTrans);
- if (pNewVgroup->replica == 1 && pNewDb->cfg.replications == 3) {
+ if (pNewDb->cfg.replications == 3) {
mInfo("db:%s, vgId:%d, will add 2 vnodes, vn:0 dnode:%d", pVgroup->dbName, pVgroup->vgId,
pVgroup->vnodeGid[0].dnodeId);
// add second
- TAOS_CHECK_RETURN(mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
+ if (pNewVgroup->replica == 1){
+ TAOS_CHECK_RETURN(mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
+ }
// learner stage
pNewVgroup->vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
@@ -2790,7 +2792,9 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
TAOS_CHECK_RETURN(mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup));
// add third
- TAOS_CHECK_RETURN(mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
+ if (pNewVgroup->replica == 2){
+ TAOS_CHECK_RETURN (mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray));
+ }
pNewVgroup->vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
pNewVgroup->vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_VOTER;
@@ -2802,7 +2806,7 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
TAOS_CHECK_RETURN(mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, pNewVgroup, &pNewVgroup->vnodeGid[2]));
TAOS_CHECK_RETURN(mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup));
- } else if (pNewVgroup->replica == 3 && pNewDb->cfg.replications == 1) {
+ } else if (pNewDb->cfg.replications == 1) {
mInfo("db:%s, vgId:%d, will remove 2 vnodes, vn:0 dnode:%d vn:1 dnode:%d vn:2 dnode:%d", pVgroup->dbName,
pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId, pVgroup->vnodeGid[1].dnodeId, pVgroup->vnodeGid[2].dnodeId);
@@ -2819,9 +2823,9 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
TAOS_CHECK_RETURN(mndRemoveVnodeFromVgroup(pMnode, pTrans, pNewVgroup, pArray, &del2));
TAOS_CHECK_RETURN(mndAddDropVnodeAction(pMnode, pTrans, pNewDb, pNewVgroup, &del2, true));
TAOS_CHECK_RETURN(
- mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId));
+ mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId));
TAOS_CHECK_RETURN(mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup));
- } else if (pNewVgroup->replica == 1 && pNewDb->cfg.replications == 2) {
+ } else if (pNewDb->cfg.replications == 2) {
mInfo("db:%s, vgId:%d, will add 1 vnode, vn:0 dnode:%d", pVgroup->dbName, pVgroup->vgId,
pVgroup->vnodeGid[0].dnodeId);
diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c
index a556f68c32..56060b0061 100644
--- a/source/libs/executor/src/sysscanoperator.c
+++ b/source/libs/executor/src/sysscanoperator.c
@@ -2545,7 +2545,8 @@ static int32_t doSysTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes)
if (pInfo->showRewrite) {
getDBNameFromCondition(pInfo->pCondition, dbName);
if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, TSDB_TABLE_FNAME_LEN) != 0 &&
- strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, TSDB_TABLE_FNAME_LEN) != 0) {
+ strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, TSDB_TABLE_FNAME_LEN) != 0 &&
+ strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, TSDB_TABLE_FNAME_LEN) != 0) {
TAOS_UNUSED(tsnprintf(pInfo->req.db, sizeof(pInfo->req.db), "%d.%s", pInfo->accountId, dbName));
}
} else if (strncasecmp(name, TSDB_INS_TABLE_COLS, TSDB_TABLE_FNAME_LEN) == 0) {
diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c
index 6d4d89607f..c2290b9eac 100644
--- a/source/libs/nodes/src/nodesCodeFuncs.c
+++ b/source/libs/nodes/src/nodesCodeFuncs.c
@@ -292,6 +292,8 @@ const char* nodesNodeName(ENodeType type) {
return "ShowCompactsStmt";
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
return "ShowCompactDetailsStmt";
+ case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
+ return "ShowTransactionDetailsStmt";
case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
return "ShowGrantsFullStmt";
case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c
index 7beaeaa46c..5bfc35aa9c 100644
--- a/source/libs/nodes/src/nodesUtilFuncs.c
+++ b/source/libs/nodes/src/nodesUtilFuncs.c
@@ -714,6 +714,9 @@ int32_t nodesMakeNode(ENodeType type, SNode** ppNodeOut) {
break;
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
code = makeNode(type, sizeof(SShowCompactDetailsStmt), &pNode);
+ break;
+ case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
+ code = makeNode(type, sizeof(SShowTransactionDetailsStmt), &pNode);
break;
case QUERY_NODE_KILL_QUERY_STMT:
code = makeNode(type, sizeof(SKillQueryStmt), &pNode);
@@ -1562,6 +1565,11 @@ void nodesDestroyNode(SNode* pNode) {
nodesDestroyNode(pStmt->pCompactId);
break;
}
+ case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT: {
+ SShowTransactionDetailsStmt* pStmt = (SShowTransactionDetailsStmt*)pNode;
+ nodesDestroyNode(pStmt->pTransactionId);
+ break;
+ }
case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
taosMemoryFreeClear(((SShowCreateDatabaseStmt*)pNode)->pCfg);
break;
diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h
index e69a3da4a9..8b2a98baf2 100644
--- a/source/libs/parser/inc/parAst.h
+++ b/source/libs/parser/inc/parAst.h
@@ -320,6 +320,7 @@ SNode* createCreateViewStmt(SAstCreateContext* pCxt, bool orReplace, SNode* pVie
SNode* createDropViewStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pView);
SNode* createShowCompactDetailsStmt(SAstCreateContext* pCxt, SNode* pCompactIdNode);
SNode* createShowCompactsStmt(SAstCreateContext* pCxt, ENodeType type);
+SNode* createShowTransactionDetailsStmt(SAstCreateContext* pCxt, SNode* pTransactionIdNode);
SNode* createCreateTSMAStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* tsmaName, SNode* pOptions,
SNode* pRealTable, SNode* pInterval);
diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y
index 63eb09d509..38e93a7ce3 100644
--- a/source/libs/parser/inc/sql.y
+++ b/source/libs/parser/inc/sql.y
@@ -594,6 +594,7 @@ cmd ::= SHOW BNODES.
cmd ::= SHOW SNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); }
cmd ::= SHOW CLUSTER. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); }
cmd ::= SHOW TRANSACTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); }
+cmd ::= SHOW TRANSACTION NK_INTEGER(A). { pCxt->pRootNode = createShowTransactionDetailsStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &A)); }
cmd ::= SHOW TABLE DISTRIBUTED full_table_name(A). { pCxt->pRootNode = createShowTableDistributedStmt(pCxt, A); }
cmd ::= SHOW CONSUMERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); }
cmd ::= SHOW SUBSCRIPTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); }
diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c
index fa656667af..5fc5f5fafe 100644
--- a/source/libs/parser/src/parAstCreater.c
+++ b/source/libs/parser/src/parAstCreater.c
@@ -2931,6 +2931,18 @@ _err:
return NULL;
}
+SNode* createShowTransactionDetailsStmt(SAstCreateContext* pCxt, SNode* pTransactionIdNode) {
+ CHECK_PARSER_STATUS(pCxt);
+ SShowTransactionDetailsStmt* pStmt = NULL;
+ pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT, (SNode**)&pStmt);
+ CHECK_MAKE_NODE(pStmt);
+ pStmt->pTransactionId = pTransactionIdNode;
+ return (SNode*)pStmt;
+_err:
+ nodesDestroyNode(pTransactionIdNode);
+ return NULL;
+}
+
static int32_t getIpV4RangeFromWhitelistItem(char* ipRange, SIpV4Range* pIpRange) {
int32_t code = TSDB_CODE_SUCCESS;
char* ipCopy = taosStrdup(ipRange);
diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c
index 1687916cb0..e876575f48 100644
--- a/source/libs/parser/src/parAstParser.c
+++ b/source/libs/parser/src/parAstParser.c
@@ -770,6 +770,12 @@ static int32_t collectMetaKeyFromShowCompactDetails(SCollectMetaKeyCxt* pCxt, SS
return code;
}
+static int32_t collectMetaKeyFromShowTransactionDetails(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
+ int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB,
+ TSDB_INS_TABLE_TRANSACTION_DETAILS, pCxt->pMetaCache);
+ return code;
+}
+
static int32_t collectMetaKeyFromShowGrantsFull(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_GRANTS_FULL,
pCxt->pMetaCache);
@@ -1094,6 +1100,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
return collectMetaKeyFromShowCompacts(pCxt, (SShowStmt*)pStmt);
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
return collectMetaKeyFromShowCompactDetails(pCxt, (SShowStmt*)pStmt);
+ case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
+ return collectMetaKeyFromShowTransactionDetails(pCxt, (SShowStmt*)pStmt);
case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
return collectMetaKeyFromShowGrantsFull(pCxt, (SShowStmt*)pStmt);
case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index 9f411c4296..8f3cbd6f8b 100755
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -371,12 +371,40 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = {
.pShowCols = {"*"}
},
{
+ .showType = QUERY_NODE_CREATE_TSMA_STMT,
+ .pDbName = "",
+ .pTableName = "",
+ .numOfShowCols = 1,
+ .pShowCols = {"*"}
+ },
+ {
+ .showType = QUERY_NODE_SHOW_CREATE_TSMA_STMT,
+ .pDbName = "",
+ .pTableName = "",
+ .numOfShowCols = 1,
+ .pShowCols = {"*"}
+ },
+ {
+ .showType = QUERY_NODE_DROP_TSMA_STMT,
+ .pDbName = "",
+ .pTableName = "",
+ .numOfShowCols = 1,
+ .pShowCols = {"*"}
+ },
+ {
.showType = QUERY_NODE_SHOW_FILESETS_STMT,
.pDbName = TSDB_INFORMATION_SCHEMA_DB,
.pTableName = TSDB_INS_TABLE_FILESETS,
.numOfShowCols = 1,
.pShowCols = {"*"}
- },
+ },
+ {
+ .showType = QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
+ .pDbName = TSDB_INFORMATION_SCHEMA_DB,
+ .pTableName = TSDB_INS_TABLE_TRANSACTION_DETAILS,
+ .numOfShowCols = 1,
+ .pShowCols = {"*"}
+ },
};
// clang-format on
@@ -16359,6 +16387,24 @@ static int32_t rewriteShowCompactDetailsStmt(STranslateContext* pCxt, SQuery* pQ
return code;
}
+static int32_t rewriteShowTransactionDetailsStmt(STranslateContext* pCxt, SQuery* pQuery) {
+ SShowTransactionDetailsStmt* pShow = (SShowTransactionDetailsStmt*)(pQuery->pRoot);
+ SSelectStmt* pStmt = NULL;
+ int32_t code = createSelectStmtForShow(QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT, &pStmt);
+ if (TSDB_CODE_SUCCESS == code) {
+ if (NULL != pShow->pTransactionId) {
+ code = createOperatorNode(OP_TYPE_EQUAL, "transaction_id", pShow->pTransactionId, &pStmt->pWhere);
+ }
+ }
+ if (TSDB_CODE_SUCCESS == code) {
+ pCxt->showRewrite = true;
+ pQuery->showRewrite = true;
+ nodesDestroyNode(pQuery->pRoot);
+ pQuery->pRoot = (SNode*)pStmt;
+ }
+ return code;
+}
+
static int32_t createParWhenThenNode(SNode* pWhen, SNode* pThen, SNode** ppResWhenThen) {
SWhenThenNode* pWThen = NULL;
int32_t code = nodesMakeNode(QUERY_NODE_WHEN_THEN, (SNode**)&pWThen);
@@ -16934,6 +16980,9 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
case QUERY_NODE_SHOW_COMPACT_DETAILS_STMT:
code = rewriteShowCompactDetailsStmt(pCxt, pQuery);
break;
+ case QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT:
+ code = rewriteShowTransactionDetailsStmt(pCxt, pQuery);
+ break;
case QUERY_NODE_SHOW_DB_ALIVE_STMT:
case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
code = rewriteShowAliveStmt(pCxt, pQuery);
diff --git a/source/util/src/terror.c b/source/util/src/terror.c
index b2a8c422f7..feed297f71 100644
--- a/source/util/src/terror.c
+++ b/source/util/src/terror.c
@@ -326,6 +326,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_SYNC_TIMEOUT, "Sync timeout While ex
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_CTX_SWITCH, "Wrong transaction execution context")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_CONFLICT_COMPACT, "Transaction not completed due to conflict with compact")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_UNKNOW_ERROR, "Unknown transaction error")
+TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED, "The transaction is not able to be killed")
// mnode-mq
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOPIC_ALREADY_EXIST, "Topic already exists")
diff --git a/tests/develop-test/2-query/table_count_scan.py b/tests/develop-test/2-query/table_count_scan.py
index 9725c36bee..b5c6140481 100644
--- a/tests/develop-test/2-query/table_count_scan.py
+++ b/tests/develop-test/2-query/table_count_scan.py
@@ -68,7 +68,7 @@ class TDTestCase:
for i in range(0, 3):
db_name = tdSql.getData(i, 1)
if db_name == 'information_schema':
- tdSql.checkData(i, 0, 36)
+ tdSql.checkData(i, 0, 37)
tdSql.checkData(i, 2, None)
elif db_name == 'performance_schema':
tdSql.checkData(i, 0, 5)
@@ -81,7 +81,7 @@ class TDTestCase:
tdSql.query('select count(1) v,db_name, stable_name from information_schema.ins_tables group by db_name, stable_name order by v desc;')
tdSql.checkRows(3)
- tdSql.checkData(0, 0, 36)
+ tdSql.checkData(0, 0, 37)
tdSql.checkData(0, 1, 'information_schema')
tdSql.checkData(0, 2, None)
tdSql.checkData(1, 0, 5)
@@ -97,7 +97,7 @@ class TDTestCase:
tdSql.checkData(1, 1, 'performance_schema')
tdSql.checkData(0, 0, 3)
tdSql.checkData(0, 1, 'tbl_count')
- tdSql.checkData(2, 0, 36)
+ tdSql.checkData(2, 0, 37)
tdSql.checkData(2, 1, 'information_schema')
tdSql.query("select count(*) from information_schema.ins_tables where db_name='tbl_count'")
@@ -110,7 +110,7 @@ class TDTestCase:
tdSql.query('select count(*) from information_schema.ins_tables')
tdSql.checkRows(1)
- tdSql.checkData(0, 0, 44)
+ tdSql.checkData(0, 0, 45)
tdSql.execute('create table stba (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(10), c9 nchar(10), c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned) TAGS(t1 int, t2 binary(10), t3 double);')
@@ -193,7 +193,7 @@ class TDTestCase:
tdSql.checkData(2, 0, 5)
tdSql.checkData(2, 1, 'performance_schema')
tdSql.checkData(2, 2, None)
- tdSql.checkData(3, 0, 36)
+ tdSql.checkData(3, 0, 37)
tdSql.checkData(3, 1, 'information_schema')
tdSql.checkData(3, 2, None)
@@ -208,7 +208,7 @@ class TDTestCase:
tdSql.checkData(2, 0, 5)
tdSql.checkData(2, 1, 'performance_schema')
tdSql.checkData(2, 2, None)
- tdSql.checkData(3, 0, 36)
+ tdSql.checkData(3, 0, 37)
tdSql.checkData(3, 1, 'information_schema')
tdSql.checkData(3, 2, None)
@@ -219,7 +219,7 @@ class TDTestCase:
tdSql.checkData(0, 1, 'tbl_count')
tdSql.checkData(1, 0, 5)
tdSql.checkData(1, 1, 'performance_schema')
- tdSql.checkData(2, 0, 36)
+ tdSql.checkData(2, 0, 37)
tdSql.checkData(2, 1, 'information_schema')
tdSql.query("select count(*) from information_schema.ins_tables where db_name='tbl_count'")
@@ -232,7 +232,7 @@ class TDTestCase:
tdSql.query('select count(*) from information_schema.ins_tables')
tdSql.checkRows(1)
- tdSql.checkData(0, 0, 45)
+ tdSql.checkData(0, 0, 46)
tdSql.execute('drop database tbl_count')
diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task
index ae9918f688..8903ef27a4 100644
--- a/tests/parallel_test/cases.task
+++ b/tests/parallel_test/cases.task
@@ -408,6 +408,9 @@
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/test_hot_refresh_configurations.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/subscribe_stream_privilege.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/empty_identifier.py
+,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/show_transaction_detail.py -N 3
+# ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/kill_balance_leader.py -N 3
+# ,,y,system-test,./pytest.sh python3 ./test.py -f 3-enterprise/restore/kill_restore_dnode.py -N 5
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/persisit_config.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/qmemCtrl.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/compact_vgroups.py
diff --git a/tests/script/tsim/query/sys_tbname.sim b/tests/script/tsim/query/sys_tbname.sim
index f8c1d6a986..c6c979e97c 100644
--- a/tests/script/tsim/query/sys_tbname.sim
+++ b/tests/script/tsim/query/sys_tbname.sim
@@ -58,7 +58,7 @@ endi
sql select tbname from information_schema.ins_tables;
print $rows $data00
-if $rows != 45 then
+if $rows != 46 then
return -1
endi
if $data00 != @ins_tables@ then
diff --git a/tests/script/tsim/query/tableCount.sim b/tests/script/tsim/query/tableCount.sim
index 49e9126361..19568b42b6 100644
--- a/tests/script/tsim/query/tableCount.sim
+++ b/tests/script/tsim/query/tableCount.sim
@@ -53,7 +53,7 @@ sql select stable_name,count(table_name) from information_schema.ins_tables grou
if $rows != 3 then
return -1
endi
-if $data01 != 42 then
+if $data01 != 43 then
return -1
endi
if $data11 != 10 then
@@ -72,7 +72,7 @@ endi
if $data11 != 5 then
return -1
endi
-if $data21 != 36 then
+if $data21 != 37 then
return -1
endi
if $data31 != 5 then
@@ -97,7 +97,7 @@ endi
if $data42 != 3 then
return -1
endi
-if $data52 != 36 then
+if $data52 != 37 then
return -1
endi
if $data62 != 5 then
diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py
index af0dd6d949..8c25b70b76 100644
--- a/tests/system-test/0-others/information_schema.py
+++ b/tests/system-test/0-others/information_schema.py
@@ -61,7 +61,7 @@ class TDTestCase:
self.ins_list = ['ins_dnodes','ins_mnodes','ins_qnodes','ins_snodes','ins_cluster','ins_databases','ins_functions',\
'ins_indexes','ins_stables','ins_tables','ins_tags','ins_columns','ins_users','ins_grants','ins_vgroups','ins_configs','ins_dnode_variables',\
'ins_topics','ins_subscriptions','ins_streams','ins_stream_tasks','ins_vnodes','ins_user_privileges','ins_views',
- 'ins_compacts', 'ins_compact_details', 'ins_grants_full','ins_grants_logs', 'ins_machines', 'ins_arbgroups', 'ins_tsmas', "ins_encryptions", "ins_anodes", "ins_anodes_full", "ins_disk_usagea", "ins_filesets"]
+ 'ins_compacts', 'ins_compact_details', 'ins_grants_full','ins_grants_logs', 'ins_machines', 'ins_arbgroups', 'ins_tsmas', "ins_encryptions", "ins_anodes", "ins_anodes_full", "ins_disk_usagea", "ins_filesets", "ins_transaction_details"]
self.perf_list = ['perf_connections','perf_queries','perf_consumers','perf_trans','perf_apps']
def insert_data(self,column_dict,tbname,row_num):
insert_sql = self.setsql.set_insertsql(column_dict,tbname,self.binary_str,self.nchar_str)
@@ -222,10 +222,10 @@ class TDTestCase:
tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'")
tdLog.info(len(tdSql.queryResult))
- tdSql.checkEqual(True, len(tdSql.queryResult) in range(303, 304))
+ tdSql.checkEqual(True, len(tdSql.queryResult) in range(309, 310))
tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'")
- tdSql.checkEqual(60, len(tdSql.queryResult))
+ tdSql.checkEqual(61, len(tdSql.queryResult))
def ins_dnodes_check(self):
tdSql.execute('drop database if exists db2')
diff --git a/tests/system-test/0-others/kill_balance_leader.py b/tests/system-test/0-others/kill_balance_leader.py
new file mode 100644
index 0000000000..be86336661
--- /dev/null
+++ b/tests/system-test/0-others/kill_balance_leader.py
@@ -0,0 +1,64 @@
+###################################################################
+# Copyright (c) 2016 by TAOS Technologies, Inc.
+# All rights reserved.
+#
+# This file is proprietary and confidential to TAOS Technologies.
+# No part of this file may be reproduced, stored, transmitted,
+# disclosed or used in any form or by any means other than as
+# expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+from util.log import *
+from util.cases import *
+from util.dnodes import *
+from util.sql import *
+
+
+
+class TDTestCase:
+ def init(self, conn, logSql, replicaVar=1):
+ tdLog.debug(f"start to init {__file__}")
+ self.replicaVar = int(replicaVar)
+ tdSql.init(conn.cursor(), logSql)
+
+ def stop(self):
+ tdSql.close()
+ tdLog.success(f"{__file__} successfully executed")
+
+ def run(self):
+ tdLog.debug(f"start to excute {__file__}")
+
+ tdSql.execute('CREATE DATABASE db vgroups 160 replica 3;')
+
+ tdSql.execute('balance vgroup leader')
+
+ sql ="show transactions;"
+ rows = tdSql.query(sql)
+
+ if rows > 0:
+ tranId = tdSql.getData(0, 0)
+ tdLog.info('kill transaction %d'%tranId)
+ tdSql.execute('kill transaction %d'%tranId, queryTimes=1 )
+
+ if self.waitTransactionZero() is False:
+ tdLog.exit(f"{sql} transaction not finished")
+ return False
+
+ def waitTransactionZero(self, seconds = 300, interval = 1):
+ # wait end
+ for i in range(seconds):
+ sql ="show transactions;"
+ rows = tdSql.query(sql)
+ if rows == 0:
+ tdLog.info("transaction count became zero.")
+ return True
+ #tdLog.info(f"i={i} wait ...")
+ time.sleep(interval)
+
+ return False
+
+
+tdCases.addLinux(__file__, TDTestCase())
+tdCases.addWindows(__file__, TDTestCase())
\ No newline at end of file
diff --git a/tests/system-test/0-others/show_transaction_detail.py b/tests/system-test/0-others/show_transaction_detail.py
new file mode 100644
index 0000000000..ba588f8f01
--- /dev/null
+++ b/tests/system-test/0-others/show_transaction_detail.py
@@ -0,0 +1,115 @@
+###################################################################
+# Copyright (c) 2016 by TAOS Technologies, Inc.
+# All rights reserved.
+#
+# This file is proprietary and confidential to TAOS Technologies.
+# No part of this file may be reproduced, stored, transmitted,
+# disclosed or used in any form or by any means other than as
+# expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+from util.log import *
+from util.cases import *
+from util.dnodes import *
+from util.sql import *
+from util.cluster import *
+import threading
+
+class TDTestCase:
+ def init(self, conn, logSql, replicaVar=1):
+ tdLog.debug(f"start to init {__file__}")
+ self.replicaVar = int(replicaVar)
+ tdSql.init(conn.cursor(), logSql)
+ self.dnodes = cluster.dnodes
+
+ def stop(self):
+ tdSql.close()
+ tdLog.success(f"{__file__} successfully executed")
+
+ def run(self):
+ tdLog.debug(f"start to excute {__file__}")
+
+ tdLog.info("CREATE DATABASE db1 vgroups 16 replica 1;")
+ tdSql.execute('CREATE DATABASE db1 vgroups 16 replica 1;')
+
+ if self.waitTransactionZero() is False:
+ tdLog.exit(f"{sql} transaction not finished")
+ return False
+
+ newTdSql1=tdCom.newTdSql()
+ t1 = threading.Thread(target=self.alterDbThread, args=('', newTdSql1))
+
+ newTdSql2=tdCom.newTdSql()
+ t2 = threading.Thread(target=self.createDbThread, args=('', newTdSql2))
+
+ t1.start()
+ t2.start()
+
+ #time.sleep(1)
+
+ dnode = self.dnodes[2]
+
+ # stop dnode
+ tdLog.info(f"stop dnode 2")
+ dnode.stoptaosd()
+
+ tdLog.info(f"show transactions;")
+ rows = tdSql.query("show transactions;", queryTimes=1)
+ tdLog.info(f"rows={rows}")
+ if rows > 0:
+ tranId1 = tdSql.getData(0, 0)
+ oper1 = tdSql.getData(0, 3)
+ tdLog.info(f"show transaction {tranId1}, {oper1}")
+
+ #tranId2 = tdSql.getData(1, 0)
+ #oper2 = tdSql.getData(1, 3)
+ #tdLog.info(f"show transaction {tranId2}, {oper2}")
+
+ rows = tdSql.query(f"show transaction {tranId1}", queryTimes=1)
+ if rows != 120 and rows != 176:
+ tdLog.exit(f"show transaction detial error, rows={rows}")
+ return False
+
+ #rows = tdSql.query(f"show transaction {tranId2}", queryTimes=1)
+ #if rows != 176 and rows != 120:
+ # tdLog.exit(f"show transaction detial error, rows={rows}")
+ # return False
+
+ tdLog.info(f"select * from ins_transaction_details")
+ rows = tdSql.query(f"select * from information_schema.ins_transaction_details", queryTimes=1)
+
+ #if rows != 296:
+ if rows != 176:
+ tdLog.exit(f"show transaction detial error, rows={rows}")
+ return False
+
+ dnode.starttaosd()
+
+ t1.join()
+ t2.join()
+
+ def createDbThread(self, sql, newTdSql):
+ tdLog.info("CREATE DATABASE db2 vgroups 40 replica 3;")
+ newTdSql.execute('CREATE DATABASE db2 vgroups 40 replica 3;', queryTimes=1)
+
+ def alterDbThread(self, sql, newTdSql):
+ tdLog.info("alter DATABASE db1 replica 3;")
+ newTdSql.execute('alter DATABASE db1 replica 3;', queryTimes=1)
+
+ def waitTransactionZero(self, seconds = 300, interval = 1):
+ # wait end
+ for i in range(seconds):
+ sql ="show transactions;"
+ rows = tdSql.query(sql)
+ if rows == 0:
+ tdLog.info("transaction count became zero.")
+ return True
+ #tdLog.info(f"i={i} wait ...")
+ time.sleep(interval)
+
+ return False
+
+tdCases.addLinux(__file__, TDTestCase())
+tdCases.addWindows(__file__, TDTestCase())
\ No newline at end of file
diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py
index 380b7879c4..1abe2b1a65 100644
--- a/tests/system-test/2-query/union.py
+++ b/tests/system-test/2-query/union.py
@@ -441,7 +441,7 @@ class TDTestCase:
tdSql.checkRows(2)
sql = "select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, stable_name `TABLE_NAME`, 'TABLE' `TABLE_TYPE`, table_comment `REMARKS` from information_schema.ins_stables union all select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, table_name `TABLE_NAME`, case when `type`='SYSTEM_TABLE' then 'TABLE' when `type`='NORMAL_TABLE' then 'TABLE' when `type`='CHILD_TABLE' then 'TABLE' else 'UNKNOWN' end `TABLE_TYPE`, table_comment `REMARKS` from information_schema.ins_tables union all select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, view_name `TABLE_NAME`, 'VIEW' `TABLE_TYPE`, NULL `REMARKS` from information_schema.ins_views"
tdSql.query(sql, queryTimes=1)
- tdSql.checkRows(49)
+ tdSql.checkRows(50)
sql = "select null union select null"
tdSql.query(sql, queryTimes=1)
diff --git a/tests/system-test/3-enterprise/restore/kill_restore_dnode.py b/tests/system-test/3-enterprise/restore/kill_restore_dnode.py
new file mode 100644
index 0000000000..d29a11f159
--- /dev/null
+++ b/tests/system-test/3-enterprise/restore/kill_restore_dnode.py
@@ -0,0 +1,90 @@
+###################################################################
+# Copyright (c) 2016 by TAOS Technologies, Inc.
+# All rights reserved.
+#
+# This file is proprietary and confidential to TAOS Technologies.
+# No part of this file may be reproduced, stored, transmitted,
+# disclosed or used in any form or by any means other than as
+# expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+
+import sys
+
+from util.log import *
+from util.cases import *
+from util.sql import *
+from util.common import *
+sys.path.append("./3-enterprise/restore")
+from restoreBasic import *
+from util.common import tdCom
+import threading
+
+
+class TDTestCase:
+ # init
+ def init(self, conn, logSql, replicaVar=1):
+ tdLog.debug("start to execute %s" % __file__)
+ self.basic = RestoreBasic()
+ self.basic.init(conn, logSql, replicaVar)
+
+ # run
+ def run(self):
+ self.basic.restore_dnode_prepare(2)
+
+ self.execute()
+
+ def execute(self):
+ newTdSql=tdCom.newTdSql()
+ t0 = threading.Thread(target=self.restoreDnodeThread, args=('', newTdSql))
+ t0.start()
+
+ time.sleep(2)
+ sql ="show transactions;"
+ tdLog.info(sql)
+ rows = tdSql.query(sql)
+
+ if rows > 0:
+ self.basic.stop_dnode(2)
+
+ tranId = tdSql.getData(0, 0)
+
+ tdLog.info('show transaction %d'%tranId)
+ rows=tdSql.query('show transaction %d'%tranId, queryTimes=1)
+ if rows != 11:
+ tdLog.exit(f"restore transaction detial error, rows={rows}")
+ return False
+
+ tdLog.info('kill transaction %d'%tranId)
+ tdSql.execute('kill transaction %d'%tranId, queryTimes=1 )
+
+ time.sleep(3)
+ sql ="show transactions;"
+ tdLog.info(sql)
+ rows = tdSql.query(sql)
+ if rows > 0:
+ tdLog.info(f"{sql} transaction not finished")
+ return False
+
+ self.basic.restore_dnode_exec(2)
+ else:
+ tdLog.exit(f"{sql} no transaction exist")
+ return False
+
+ def restoreDnodeThread(self, p, newTdSql):
+ sleep(1)
+
+ sql = f"restore dnode 2"
+ tdLog.info(sql)
+ newTdSql.error(sql, expectErrInfo="Wrong transaction execution context")
+ tdLog.info(f"{sql} finished")
+
+ # stop
+ def stop(self):
+ self.basic.stop()
+ tdLog.success("%s successfully executed" % __file__)
+
+tdCases.addWindows(__file__, TDTestCase())
+tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
diff --git a/tests/system-test/3-enterprise/restore/restoreBasic.py b/tests/system-test/3-enterprise/restore/restoreBasic.py
index 77fa606b9c..74cf572018 100644
--- a/tests/system-test/3-enterprise/restore/restoreBasic.py
+++ b/tests/system-test/3-enterprise/restore/restoreBasic.py
@@ -143,6 +143,34 @@ class RestoreBasic:
tdSql.execute(sql)
self.check_corrent()
+ def restore_dnode_prepare(self, index):
+ tdLog.info(f"start restore dnode {index}")
+ dnode = self.dnodes[index - 1]
+
+ # stop dnode
+ tdLog.info(f"stop dnode {index}")
+ dnode.stoptaosd()
+
+ # remove dnode folder
+ try:
+ shutil.rmtree(dnode.dataDir)
+ tdLog.info(f"delete dir {dnode.dataDir} successful")
+ except OSError as x:
+ tdLog.exit(f"remove path {dnode.dataDir} error : {x.strerror}")
+
+ dnode.starttaosd()
+
+ def restore_dnode_exec(self, index):
+ # exec restore
+ sql = f"restore dnode {index}"
+ tdLog.info(sql)
+ tdSql.execute(sql)
+ self.check_corrent()
+
+ def stop_dnode(self, index):
+ dnode = self.dnodes[index - 1]
+
+ dnode.starttaosd()
# restore vnode
def restore_vnode(self, index):
tdLog.info(f"start restore vnode on dnode {index}")
From 4a896d1a394d35bb03e5787be6796b2d6376351b Mon Sep 17 00:00:00 2001
From: Kaili Xu
Date: Sun, 29 Dec 2024 21:19:00 +0800
Subject: [PATCH 56/56] chore: restore Jenkinsfile2
---
Jenkinsfile2 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Jenkinsfile2 b/Jenkinsfile2
index 4d74b3d2c2..1b2f28908c 100644
--- a/Jenkinsfile2
+++ b/Jenkinsfile2
@@ -508,7 +508,7 @@ pipeline {
}
}
stage('linux test') {
- agent{label "slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_59 || slave1_63 "}
+ agent{label "slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || slave1_59 || slave1_63 || worker03 || slave215 || slave217 || slave219 "}
options { skipDefaultCheckout() }
when {
changeRequest()