From 5283ca87edacbd0800d346ee01fae597be14a335 Mon Sep 17 00:00:00 2001 From: dmchen Date: Wed, 29 May 2024 03:08:15 +0000 Subject: [PATCH 1/6] fix/TD-30307 --- source/libs/monitorfw/inc/taos_linked_list_i.h | 2 +- source/libs/monitorfw/src/taos_collector.c | 10 +++++++--- .../monitorfw/src/taos_collector_registry.c | 4 ++++ source/libs/monitorfw/src/taos_linked_list.c | 2 ++ source/libs/monitorfw/src/taos_map.c | 4 ++-- source/libs/monitorfw/src/taos_metric.c | 18 ++++++++++++------ 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/source/libs/monitorfw/inc/taos_linked_list_i.h b/source/libs/monitorfw/inc/taos_linked_list_i.h index ed11a76427..015f8a57ad 100644 --- a/source/libs/monitorfw/inc/taos_linked_list_i.h +++ b/source/libs/monitorfw/inc/taos_linked_list_i.h @@ -47,7 +47,7 @@ int taos_linked_list_push(taos_linked_list_t *self, void *item); /** * @brief API PRIVATE Pop the first item off of the list */ -void *taos_linked_list_pop(taos_linked_list_t *self); +//void *taos_linked_list_pop(taos_linked_list_t *self); /** * @brief API PRIVATE Returns the item at the head of the list or NULL if not present diff --git a/source/libs/monitorfw/src/taos_collector.c b/source/libs/monitorfw/src/taos_collector.c index 17d324462c..414c02121d 100644 --- a/source/libs/monitorfw/src/taos_collector.c +++ b/source/libs/monitorfw/src/taos_collector.c @@ -33,6 +33,8 @@ taos_map_t *taos_collector_default_collect(taos_collector_t *self) { return self taos_collector_t *taos_collector_new(const char *name) { int r = 0; taos_collector_t *self = (taos_collector_t *)taos_malloc(sizeof(taos_collector_t)); + if (self == NULL) return NULL; + memset(self, 0, sizeof(taos_collector_t)); self->name = taos_strdup(name); self->metrics = taos_map_new(); if (self->metrics == NULL) { @@ -66,9 +68,11 @@ int taos_collector_destroy(taos_collector_t *self) { if (r) ret = r; self->metrics = NULL; - r = taos_string_builder_destroy(self->string_builder); - if (r) ret = r; - self->string_builder = NULL; + if(self->string_builder != NULL){ + r = taos_string_builder_destroy(self->string_builder); + if (r) ret = r; + self->string_builder = NULL; + } taos_free((char *)self->name); self->name = NULL; diff --git a/source/libs/monitorfw/src/taos_collector_registry.c b/source/libs/monitorfw/src/taos_collector_registry.c index c3ed0112c5..d4838ef301 100644 --- a/source/libs/monitorfw/src/taos_collector_registry.c +++ b/source/libs/monitorfw/src/taos_collector_registry.c @@ -59,6 +59,7 @@ taos_collector_registry_t *taos_collector_registry_new(const char *name) { r = pthread_rwlock_init(self->lock, NULL); if (r) { TAOS_LOG("failed to initialize rwlock"); + taos_free(self); return NULL; } return self; @@ -301,6 +302,9 @@ const char *taos_collector_registry_bridge_new(taos_collector_registry_t *self, _OVER: tjsonDelete(pJson); + if(tmp_builder != NULL){ + taos_string_builder_destroy(tmp_builder); + } return NULL; } diff --git a/source/libs/monitorfw/src/taos_linked_list.c b/source/libs/monitorfw/src/taos_linked_list.c index 675400a6fa..2becb08a07 100644 --- a/source/libs/monitorfw/src/taos_linked_list.c +++ b/source/libs/monitorfw/src/taos_linked_list.c @@ -117,6 +117,7 @@ int taos_linked_list_push(taos_linked_list_t *self, void *item) { return 0; } +/* void *taos_linked_list_pop(taos_linked_list_t *self) { TAOS_ASSERT(self != NULL); if (self == NULL) return NULL; @@ -141,6 +142,7 @@ void *taos_linked_list_pop(taos_linked_list_t *self) { } return item; } +*/ int taos_linked_list_remove(taos_linked_list_t *self, void *item) { TAOS_ASSERT(self != NULL); diff --git a/source/libs/monitorfw/src/taos_map.c b/source/libs/monitorfw/src/taos_map.c index 8f0b83884e..ffb7d000fc 100644 --- a/source/libs/monitorfw/src/taos_map.c +++ b/source/libs/monitorfw/src/taos_map.c @@ -90,7 +90,7 @@ taos_map_t *taos_map_new() { return NULL; } - self->addrs = taos_malloc(sizeof(taos_linked_list_t) * self->max_size); + self->addrs = taos_malloc(sizeof(taos_linked_list_t*) * self->max_size); self->free_value_fn = destroy_map_node_value_no_op; for (int i = 0; i < self->max_size; i++) { @@ -273,7 +273,7 @@ int taos_map_ensure_space(taos_map_t *self) { if (r) return r; // Create a new array of addrs - taos_linked_list_t **new_addrs = taos_malloc(sizeof(taos_linked_list_t) * new_max); + taos_linked_list_t **new_addrs = taos_malloc(sizeof(taos_linked_list_t*) * new_max); // Initialize the new array for (int i = 0; i < new_max; i++) { diff --git a/source/libs/monitorfw/src/taos_metric.c b/source/libs/monitorfw/src/taos_metric.c index 4e9af35f34..5cecbc927f 100644 --- a/source/libs/monitorfw/src/taos_metric.c +++ b/source/libs/monitorfw/src/taos_metric.c @@ -33,6 +33,8 @@ taos_metric_t *taos_metric_new(taos_metric_type_t metric_type, const char *name, size_t label_key_count, const char **label_keys) { int r = 0; taos_metric_t *self = (taos_metric_t *)taos_malloc(sizeof(taos_metric_t)); + if (self == NULL) return NULL; + memset(self, 0, sizeof(taos_metric_t)); self->type = metric_type; int len = strlen(name) + 1; self->name = taos_malloc(len); @@ -79,6 +81,7 @@ taos_metric_t *taos_metric_new(taos_metric_type_t metric_type, const char *name, r = pthread_rwlock_init(self->rwlock, NULL); if (r) { TAOS_LOG(TAOS_PTHREAD_RWLOCK_INIT_ERROR); + taos_free(self); return NULL; } return self; @@ -91,9 +94,11 @@ int taos_metric_destroy(taos_metric_t *self) { int r = 0; int ret = 0; - r = taos_map_destroy(self->samples); - self->samples = NULL; - if (r) ret = r; + if(self->samples != NULL){ + r = taos_map_destroy(self->samples); + self->samples = NULL; + if (r) ret = r; + } r = taos_metric_formatter_destroy(self->formatter); self->formatter = NULL; @@ -152,8 +157,7 @@ taos_metric_sample_t *taos_metric_sample_from_labels(taos_metric_t *self, const return NULL; // Get l_value - r = taos_metric_formatter_load_l_value(self->formatter, self->name, NULL, self->label_key_count, self->label_keys, - label_values); + r = taos_metric_formatter_load_l_value(self->formatter, self->name, NULL, self->label_key_count, self->label_keys, label_values); if (r) { TAOS_METRIC_SAMPLE_FROM_LABELS_HANDLE_UNLOCK(); } @@ -170,10 +174,12 @@ taos_metric_sample_t *taos_metric_sample_from_labels(taos_metric_t *self, const sample = taos_metric_sample_new(self->type, l_value, 0.0); r = taos_map_set(self->samples, l_value, sample); if (r) { + taos_free((void *)l_value); TAOS_METRIC_SAMPLE_FROM_LABELS_HANDLE_UNLOCK(); } } - pthread_rwlock_unlock(self->rwlock); + r = pthread_rwlock_unlock(self->rwlock); + if (r) TAOS_LOG(TAOS_PTHREAD_RWLOCK_UNLOCK_ERROR); taos_free((void *)l_value); return sample; } From 9e842929e81f25e192b2e2dd8eea10549e9b4a27 Mon Sep 17 00:00:00 2001 From: Ping Xiao Date: Wed, 29 May 2024 14:32:21 +0800 Subject: [PATCH 2/6] TS-4847: add test case --- tests/system-test/2-query/interp.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/system-test/2-query/interp.py b/tests/system-test/2-query/interp.py index 81c5b66185..1cb95b59c5 100644 --- a/tests/system-test/2-query/interp.py +++ b/tests/system-test/2-query/interp.py @@ -15,6 +15,30 @@ class TDTestCase: #tdSql.init(conn.cursor()) tdSql.init(conn.cursor(), logSql) # output sql.txt file + def interp_on_empty_table(self): + dbname = "db" + tbname = "t" + + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + + tdSql.execute(f'''create table if not exists {dbname}.{tbname} (ts timestamp, k int)''') + + tdLog.printNoPrefix("==========step2:interp query on empty table") + + tdSql.query(f"select _irowts, interp(k),k from {dbname}.{tbname} partition by k range(now()-1h, now()) every(1m) fill(prev)") + tdSql.checkRows(0) + + tdSql.query(f"select _irowts, interp(k),k from {dbname}.{tbname} partition by k range(now()-1h, now()) every(1m) fill(next)") + tdSql.checkRows(0) + + tdSql.query(f"select _irowts, interp(k),k from {dbname}.{tbname} partition by k range(now()-1h, now()) every(1m) fill(linear)") + tdSql.checkRows(0) + + tdSql.query(f"select _irowts, interp(k),k from {dbname}.{tbname} partition by k range(now()-1h, now()) every(1m) fill(value, 2)") + tdSql.checkRows(0) + def run(self): dbname = "db" tbname = "tb" @@ -5658,6 +5682,7 @@ class TDTestCase: tdSql.checkData(0, 0, '2023-08-06 23:59:00') tdSql.checkData(0, 1, None) + self.interp_on_empty_table() def stop(self): From 003f9138bc145836707723ad2709076e3a5e9065 Mon Sep 17 00:00:00 2001 From: Chris Zhai Date: Wed, 29 May 2024 14:59:22 +0800 Subject: [PATCH 3/6] add test cases for TS-4721 --- tests/army/enterprise/alter/alterConfig.py | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/army/enterprise/alter/alterConfig.py diff --git a/tests/army/enterprise/alter/alterConfig.py b/tests/army/enterprise/alter/alterConfig.py new file mode 100644 index 0000000000..7413e5e5a6 --- /dev/null +++ b/tests/army/enterprise/alter/alterConfig.py @@ -0,0 +1,55 @@ +################################################################### +# 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 +import time + +import taos +import frame +import frame.etool + +from frame.log import * +from frame.cases import * +from frame.sql import * +from frame.caseBase import * +from frame import * + + +class TDTestCase(TBase): + def alterSupportVnodes(self): + tdLog.info(f"test function of altering supportVnodes") + + tdSql.execute("alter dnode 1 'supportVnodes' '128'") + time.sleep(1) + tdSql.query('show dnodes') + tdSql.checkData(0, 3, "128") + + tdSql.execute("alter dnode 1 'supportVnodes' '64'") + time.sleep(1) + tdSql.query('show dnodes') + tdSql.checkData(0, 3, "64") + + # run + def run(self): + tdLog.debug(f"start to excute {__file__}") + + # TS-4721 + self.alterSupportVnodes() + + + tdLog.success(f"{__file__} successfully executed") + + + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) From c9c1e3ec9d1dba9de4822becc5db3c476543bca6 Mon Sep 17 00:00:00 2001 From: Chris Zhai Date: Wed, 29 May 2024 15:01:18 +0800 Subject: [PATCH 4/6] update cases.task to add test cases --- tests/parallel_test/cases.task | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index e989cb20c7..81b720829c 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -25,6 +25,7 @@ ,,y,army,./pytest.sh python3 ./test.py -f community/cluster/splitVgroupByLearner.py -N 3 ,,n,army,python3 ./test.py -f community/cmdline/fullopt.py ,,n,army,python3 ./test.py -f community/query/show.py -N 3 +,,n,army,python3 ./test.py -f enterprise/alter/alterConfig.py -N 3 ,,y,army,./pytest.sh python3 ./test.py -f community/storage/oneStageComp.py -N 3 -L 3 -D 1 ,,y,army,./pytest.sh python3 ./test.py -f community/storage/compressBasic.py -N 3 From a98394949ab3de03d6abd428e380aaa031e54866 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 29 May 2024 17:20:56 +0800 Subject: [PATCH 5/6] fix: add ut thread join --- source/libs/scheduler/test/schedulerTests.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp index c52a8599a0..6d2215264e 100644 --- a/source/libs/scheduler/test/schedulerTests.cpp +++ b/source/libs/scheduler/test/schedulerTests.cpp @@ -798,6 +798,7 @@ TEST(queryTest, normalCase) { schedulerFreeJob(&job, 0); + taosThreadJoin(thread1, NULL); } TEST(queryTest, readyFirstCase) { @@ -907,6 +908,8 @@ TEST(queryTest, readyFirstCase) { schedulerDestroy(); schedulerFreeJob(&job, 0); + + taosThreadJoin(thread1, NULL); } TEST(queryTest, flowCtrlCase) { @@ -1001,6 +1004,8 @@ TEST(queryTest, flowCtrlCase) { schedulerDestroy(); schedulerFreeJob(&job, 0); + + taosThreadJoin(thread1, NULL); } TEST(insertTest, normalCase) { @@ -1061,6 +1066,8 @@ TEST(insertTest, normalCase) { schedulerFreeJob(&insertJobRefId, 0); schedulerDestroy(); + + taosThreadJoin(thread1, NULL); } TEST(multiThread, forceFree) { From 4f49cb7940bd9516e084f933e5579d0e510b7582 Mon Sep 17 00:00:00 2001 From: Ping Xiao Date: Wed, 29 May 2024 17:29:31 +0800 Subject: [PATCH 6/6] coverage: add test case for db encrypt --- tests/army/enterprise/db-encrypt/basic.py | 63 +++++++++++++++++++++++ tests/parallel_test/cases.task | 1 + 2 files changed, 64 insertions(+) create mode 100644 tests/army/enterprise/db-encrypt/basic.py diff --git a/tests/army/enterprise/db-encrypt/basic.py b/tests/army/enterprise/db-encrypt/basic.py new file mode 100644 index 0000000000..8d30bbcfe2 --- /dev/null +++ b/tests/army/enterprise/db-encrypt/basic.py @@ -0,0 +1,63 @@ +import taos +import sys +import os +import subprocess +import glob +import shutil +import time + +from frame.log import * +from frame.cases import * +from frame.sql import * +from frame.srvCtl import * +from frame.caseBase import * +from frame import * +from frame.autogen import * +# from frame.server.dnodes import * +# from frame.server.cluster import * + + +class TDTestCase(TBase): + + def init(self, conn, logSql, replicaVar=1): + super(TDTestCase, self).init(conn, logSql, replicaVar=1, checkColName="c1") + self.valgrind = 0 + self.db = "test" + self.stb = "meters" + self.childtable_count = 10 + tdSql.init(conn.cursor(), logSql) + + def create_encrypt_db(self): + + tdSql.execute("create encrypt_key '1234567890'") + autoGen = AutoGen() + autoGen.create_db(self.db, 2, 1, "ENCRYPT_ALGORITHM 'sm4'") + tdSql.execute(f"use {self.db}") + autoGen.create_stable(self.stb, 2, 3, 8, 8) + autoGen.create_child(self.stb, "d", self.childtable_count) + autoGen.insert_data(1000) + + tdSql.query(f"select * from {self.db}.{self.stb}") + tdSql.checkRows(1000 * self.childtable_count) + + self.timestamp_step = 1000 + self.insert_rows = 1000 + + self.checkInsertCorrect() + + def create_encrypt_db_error(self): + tdSql.error("create encrypt_key '123'") + tdSql.error("create encrypt_key '12345678abcdefghi'") + tdSql.error("create database test ENCRYPT_ALGORITHM 'sm4'") + + def run(self): + self.create_encrypt_db_error() + self.create_encrypt_db() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index e989cb20c7..e29f5ca6bf 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -11,6 +11,7 @@ # army-test # ,,y,army,./pytest.sh python3 ./test.py -f enterprise/multi-level/mlevel_basic.py -N 3 -L 3 -D 2 +,,y,army,./pytest.sh python3 ./test.py -f enterprise/db-encrypt/basic.py ,,n,army,python3 ./test.py -f enterprise/s3/s3Basic.py -N 3 ,,y,army,./pytest.sh python3 ./test.py -f community/cluster/snapshot.py -N 3 -L 3 -D 2 ,,y,army,./pytest.sh python3 ./test.py -f community/query/function/test_func_elapsed.py