From 34a14a87fec0de21de6afab6f9fe9d550dedea8e Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Fri, 5 Jun 2020 13:53:30 +0800 Subject: [PATCH 01/72] fix multi-thread cases. --- .../random-test/random-test-multi-threading-3.py | 10 ++++++---- .../pytest/random-test/random-test-multi-threading.py | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/pytest/random-test/random-test-multi-threading-3.py b/tests/pytest/random-test/random-test-multi-threading-3.py index 4d1ef3b11d..cd9e1b577a 100644 --- a/tests/pytest/random-test/random-test-multi-threading-3.py +++ b/tests/pytest/random-test/random-test-multi-threading-3.py @@ -179,15 +179,16 @@ class Test (threading.Thread): tdDnodes.forcestop(1) tdDnodes.deploy(1) + tdDnodes.start(1) + tdSql.prepare() last_tb = "" last_stb = "" written = 0 - tdDnodes.start(1) - tdSql.prepare() def delete_datafiles(self): tdLog.info("delete_data_files") global last_tb + global last_stb global written dnodesDir = tdDnodes.getDnodesRootDir() @@ -195,10 +196,11 @@ class Test (threading.Thread): deleteCmd = 'rm -rf %s' % dataDir os.system(deleteCmd) - last_tb = "" - written = 0 tdDnodes.start(1) tdSql.prepare() + last_tb = "" + last_stb = "" + written = 0 def run(self): dataOp = { diff --git a/tests/pytest/random-test/random-test-multi-threading.py b/tests/pytest/random-test/random-test-multi-threading.py index 1c06f3a1dd..32546e0199 100644 --- a/tests/pytest/random-test/random-test-multi-threading.py +++ b/tests/pytest/random-test/random-test-multi-threading.py @@ -181,15 +181,16 @@ class Test (threading.Thread): tdDnodes.forcestop(1) tdDnodes.deploy(1) + tdDnodes.start(1) + tdSql.prepare() last_tb = "" last_stb = "" written = 0 - tdDnodes.start(1) - tdSql.prepare() def delete_datafiles(self): tdLog.info("delete_data_files") global last_tb + global last_stb global written dnodesDir = tdDnodes.getDnodesRootDir() @@ -197,11 +198,12 @@ class Test (threading.Thread): deleteCmd = 'rm -rf %s' % dataDir os.system(deleteCmd) - last_tb = "" - written = 0 tdDnodes.start(1) tdLog.sleep(10) tdSql.prepare() + last_tb = "" + last_stb = "" + written = 0 def run(self): dataOp = { From d232d7133cd32176b6b6371424a41436833a4235 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 5 Jun 2020 06:50:29 +0000 Subject: [PATCH 02/72] extract KV store --- src/util/inc/tkvstore.h | 60 +++++++++ src/util/src/tkvstore.c | 288 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+) create mode 100644 src/util/inc/tkvstore.h create mode 100644 src/util/src/tkvstore.c diff --git a/src/util/inc/tkvstore.h b/src/util/inc/tkvstore.h new file mode 100644 index 0000000000..724c94e21d --- /dev/null +++ b/src/util/inc/tkvstore.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#ifndef _TD_KVSTORE_H_ +#define _TD_KVSTORE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef int (*iterFunc)(void *, void *cont, int contLen); +typedef void (*afterFunc)(void *); + +typedef struct { + int64_t size; + int64_t tombSize; + int64_t nRecords; + int64_t nDels; +} SStoreInfo; + +typedef struct { + char * fname; + int fd; + char * fsnap; + int sfd; + char * fnew; + int nfd; + SHashObj * map; + iterFunc iFunc; + afterFunc aFunc; + void * appH; + SStoreInfo info; +} SKVStore; + +int tdCreateKVStore(char *fname); +int tdDestroyKVStore(); +SKVStore *tdOpenKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH); +void tdCloseKVStore(SKVStore *pStore); +int tdKVStoreStartCommit(SKVStore *pStore); +int tdUpdateRecordInKVStore(SKVStore *pStore, uint64_t uid, void *cont, int contLen); +int tdKVStoreEndCommit(SKVStore *pStore); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/util/src/tkvstore.c b/src/util/src/tkvstore.c new file mode 100644 index 0000000000..30052a379f --- /dev/null +++ b/src/util/src/tkvstore.c @@ -0,0 +1,288 @@ +/* + * 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 +#include +#include +#include +#include + +#include "hash.h" +#include "os.h" +#include "taoserror.h" +#include "tchecksum.h" +#include "tcoding.h" +#include "tkvstore.h" +#include "tulog.h" + +#define TD_KVSTORE_HEADER_SIZE 512 +#define TD_KVSTORE_MAJOR_VERSION 1 +#define TD_KVSTORE_MAINOR_VERSION 0 +#define TD_KVSTORE_SNAP_SUFFIX ".snap" +#define TD_KVSTORE_NEW_SUFFIX ".new" + +static int tdInitKVStoreHeader(int fd, char *fname); +static void * tdEncodeStoreInfo(void *buf, SStoreInfo *pInfo); +// static void * tdDecodeStoreInfo(void *buf, SStoreInfo *pInfo); +static SKVStore *tdNewKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH); +static char * tdGetKVStoreSnapshotFname(char *fdata); +static char * tdGetKVStoreNewFname(char *fdata); +static void tdFreeKVStore(SKVStore *pStore); + +int tdCreateKVStore(char *fname) { + char *tname = strdup(fname); + if (tname == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + + int fd = open(fname, O_RDWR | O_CREAT, 0755); + if (fd < 0) { + uError("failed to open file %s since %s", fname, strerror(errno)); + return TAOS_SYSTEM_ERROR(errno); + } + + int code = tdInitKVStoreHeader(fd, fname); + if (code != TSDB_CODE_SUCCESS) return code; + + if (fsync(fd) < 0) { + uError("failed to fsync file %s since %s", fname, strerror(errno)); + return TAOS_SYSTEM_ERROR(errno); + } + + if (close(fd) < 0) { + uError("failed to close file %s since %s", fname, strerror(errno)); + return TAOS_SYSTEM_ERROR(errno); + } + + return TSDB_CODE_SUCCESS; +} + +SKVStore *tdOpenKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH) { + SKVStore *pStore = tdNewKVStore(fname, iFunc, aFunc, appH); + if (pStore == NULL) return NULL; + + pStore->fd = open(pStore->fname, O_RDWR); + if (pStore->fd < 0) { + uError("failed to open file %s since %s", pStore->fname, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (access(pStore->fsnap, F_OK) == 0) { + uTrace("file %s exists, try to recover the KV store", pStore->fsnap); + pStore->sfd = open(pStore->fsnap, O_RDONLY); + if (pStore->sfd < 0) { + uError("failed to open file %s since %s", pStore->fsnap, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // TODO: rewind the file + + close(pStore->sfd); + pStore->sfd = -1; + remove(pStore->fsnap); + } + + // TODO: Recover from the file + + return pStore; + +_err: + if (pStore->fd > 0) { + close(pStore->fd); + pStore->fd = -1; + } + if (pStore->sfd > 0) { + close(pStore->sfd); + pStore->sfd = -1; + } + tdFreeKVStore(pStore); + return NULL; +} + +int tdKVStoreStartCommit(SKVStore *pStore) { + pStore->fd = open(pStore->fname, O_RDWR); + if (pStore->fd < 0) { + uError("failed to open file %s since %s", pStore->fname, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + pStore->sfd = open(pStore->fsnap, O_WRONLY | O_CREAT, 0755); + if (pStore->sfd < 0) { + uError("failed to open file %s since %s", pStore->fsnap, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (tsendfile(pStore->sfd, pStore->fd, NULL, TD_KVSTORE_HEADER_SIZE) < TD_KVSTORE_HEADER_SIZE) { + uError("failed to send file %d bytes since %s", TD_KVSTORE_HEADER_SIZE, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (fsync(pStore->sfd) < 0) { + uError("failed to fsync file %s since %s", pStore->fsnap, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (close(pStore->sfd) < 0) { + uError("failed to close file %s since %s", pStore->fsnap, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + pStore->sfd = -1; + + return 0; + +_err: + if (pStore->sfd > 0) { + close(pStore->sfd); + pStore->sfd = -1; + remove(pStore->fsnap); + } + if (pStore->fd > 0) { + close(pStore->fd); + pStore->fd = -1; + } + return -1; +} + +int tdKVStoreEndCommit(SKVStore *pStore) { + ASSERT(pStore->fd > 0); + + if (fsync(pStore->fd) < 0) { + uError("failed to fsync file %s since %s", pStore->fname, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + if (close(pStore->fd) < 0) { + uError("failed to close file %s since %s", pStore->fname, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + remove(pStore->fsnap); + return 0; +} + +static int tdUpdateKVStoreHeader(int fd, char *fname, SStoreInfo *pInfo) { + char buf[TD_KVSTORE_HEADER_SIZE] = "\0"; + + if (lseek(fd, 0, SEEK_SET) < 0) { + uError("failed to lseek file %s since %s", fname, strerror(errno)); + return TAOS_SYSTEM_ERROR(errno); + } + + tdEncodeStoreInfo(buf, pInfo); + taosCalcChecksumAppend(0, (uint8_t *)buf, TD_KVSTORE_HEADER_SIZE); + if (twrite(fd, buf, TD_KVSTORE_HEADER_SIZE) < TD_KVSTORE_HEADER_SIZE) { + uError("failed to write file %s %d bytes since %s", fname, TD_KVSTORE_HEADER_SIZE, strerror(errno)); + return TAOS_SYSTEM_ERROR(errno); + } + + return TSDB_CODE_SUCCESS; +} + +static int tdInitKVStoreHeader(int fd, char *fname) { + SStoreInfo info = {TD_KVSTORE_HEADER_SIZE, 0, 0, 0}; + + return tdUpdateKVStoreHeader(fd, fname, &info); +} + +static void *tdEncodeStoreInfo(void *buf, SStoreInfo *pInfo) { + buf = taosEncodeVariantI64(buf, pInfo->size); + buf = taosEncodeVariantI64(buf, pInfo->tombSize); + buf = taosEncodeVariantI64(buf, pInfo->nRecords); + buf = taosEncodeVariantI64(buf, pInfo->nDels); + + return buf; +} + +// static void *tdDecodeStoreInfo(void *buf, SStoreInfo *pInfo) { +// buf = taosDecodeVariantI64(buf, &(pInfo->size)); +// buf = taosDecodeVariantI64(buf, &(pInfo->tombSize)); +// buf = taosDecodeVariantI64(buf, &(pInfo->nRecords)); +// buf = taosDecodeVariantI64(buf, &(pInfo->nDels)); + +// return buf; +// } + +static SKVStore *tdNewKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH) { + SKVStore *pStore = (SKVStore *)malloc(sizeof(SKVStore)); + if (pStore == NULL) goto _err; + + pStore->fname = strdup(fname); + if (pStore->map == NULL) goto _err; + + pStore->fsnap = tdGetKVStoreSnapshotFname(fname); + if (pStore->fsnap == NULL) goto _err; + + pStore->fnew = tdGetKVStoreNewFname(fname); + if (pStore->fnew == NULL) goto _err; + + pStore->fd = -1; + pStore->sfd = -1; + pStore->nfd = -1; + pStore->iFunc = iFunc; + pStore->aFunc = aFunc; + pStore->appH = appH; + pStore->map = taosHashInit(4096, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false); + if (pStore->map == NULL) { + terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + goto _err; + } + + return pStore; + +_err: + terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + tdFreeKVStore(pStore); + return NULL; +} + +static void tdFreeKVStore(SKVStore *pStore) { + if (pStore) { + tfree(pStore->fname); + tfree(pStore->fsnap); + tfree(pStore->fnew); + taosHashCleanup(pStore->map); + free(pStore); + } +} + +static char *tdGetKVStoreSnapshotFname(char *fdata) { + size_t size = strlen(fdata) + strlen(TD_KVSTORE_SNAP_SUFFIX) + 1; + char * fname = malloc(size); + if (fname == NULL) { + terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + return NULL; + } + sprintf(fname, "%s%s", fdata, TD_KVSTORE_SNAP_SUFFIX); + return fname; +} + +static char *tdGetKVStoreNewFname(char *fdata) { + size_t size = strlen(fdata) + strlen(TD_KVSTORE_NEW_SUFFIX) + 1; + char * fname = malloc(size); + if (fname == NULL) { + terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + return NULL; + } + sprintf(fname, "%s%s", fdata, TD_KVSTORE_NEW_SUFFIX); + return fname; +} \ No newline at end of file From 2f354c2174190e4ebfc5b67f758d228fd94285ea Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Sat, 6 Jun 2020 06:08:27 +0000 Subject: [PATCH 03/72] [TD-530] fix query result leaks bug --- src/connector/python/linux/python2/taos/cinterface.py | 2 +- src/connector/python/linux/python2/taos/cursor.py | 5 +++-- src/connector/python/linux/python3/taos/cinterface.py | 2 +- src/connector/python/linux/python3/taos/cursor.py | 6 ++++-- src/connector/python/windows/python2/taos/cinterface.py | 2 +- src/connector/python/windows/python2/taos/cursor.py | 5 +++-- src/connector/python/windows/python3/taos/cinterface.py | 2 +- src/connector/python/windows/python3/taos/cursor.py | 5 +++-- 8 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/connector/python/linux/python2/taos/cinterface.py b/src/connector/python/linux/python2/taos/cinterface.py index e25dad5a73..10df10b31f 100644 --- a/src/connector/python/linux/python2/taos/cinterface.py +++ b/src/connector/python/linux/python2/taos/cinterface.py @@ -413,5 +413,5 @@ if __name__ == '__main__': print(data) - cinter.freeresult(result) + cinter.freeResult(result) cinter.close(conn) \ No newline at end of file diff --git a/src/connector/python/linux/python2/taos/cursor.py b/src/connector/python/linux/python2/taos/cursor.py index 75aa7f69d8..77d517d272 100644 --- a/src/connector/python/linux/python2/taos/cursor.py +++ b/src/connector/python/linux/python2/taos/cursor.py @@ -109,7 +109,6 @@ class TDengineCursor(object): # TODO : change the exception raised here raise ProgrammingError("Cursor is not connected") - self._connection.clear_result_set() self._reset_result() stmt = operation @@ -202,7 +201,7 @@ class TDengineCursor(object): for i in range(len(self._fields)): buffer[i].extend(block[i]) - self._connection.clear_result_set() + self._reset_result() return list(map(tuple, zip(*buffer))) @@ -222,6 +221,8 @@ class TDengineCursor(object): """ self._description = None self._rowcount = -1 + if self._result is not None: + CTaosInterface.freeResult(self._result) self._result = None self._fields = None self._block = None diff --git a/src/connector/python/linux/python3/taos/cinterface.py b/src/connector/python/linux/python3/taos/cinterface.py index be0226447d..c3c8a4603a 100644 --- a/src/connector/python/linux/python3/taos/cinterface.py +++ b/src/connector/python/linux/python3/taos/cinterface.py @@ -413,5 +413,5 @@ if __name__ == '__main__': print(data) - cinter.freeresult(result) + cinter.freeResult(result) cinter.close(conn) \ No newline at end of file diff --git a/src/connector/python/linux/python3/taos/cursor.py b/src/connector/python/linux/python3/taos/cursor.py index 3baca89462..41feaf93b8 100644 --- a/src/connector/python/linux/python3/taos/cursor.py +++ b/src/connector/python/linux/python3/taos/cursor.py @@ -111,7 +111,6 @@ class TDengineCursor(object): # TODO : change the exception raised here raise ProgrammingError("Cursor is not connected") - self._connection.clear_result_set() self._reset_result() stmt = operation @@ -204,7 +203,7 @@ class TDengineCursor(object): for i in range(len(self._fields)): buffer[i].extend(block[i]) - self._connection.clear_result_set() + self._reset_result() return list(map(tuple, zip(*buffer))) @@ -224,6 +223,8 @@ class TDengineCursor(object): """ self._description = None self._rowcount = -1 + if self._result is not None: + CTaosInterface.freeResult(self._result) self._result = None self._fields = None self._block = None @@ -240,3 +241,4 @@ class TDengineCursor(object): (ele['name'], ele['type'], None, None, None, None, False)) return self._result + diff --git a/src/connector/python/windows/python2/taos/cinterface.py b/src/connector/python/windows/python2/taos/cinterface.py index 0b446253b7..06ade4fc35 100644 --- a/src/connector/python/windows/python2/taos/cinterface.py +++ b/src/connector/python/windows/python2/taos/cinterface.py @@ -413,5 +413,5 @@ if __name__ == '__main__': print(data) - cinter.freeresult(result) + cinter.freeResult(result) cinter.close(conn) \ No newline at end of file diff --git a/src/connector/python/windows/python2/taos/cursor.py b/src/connector/python/windows/python2/taos/cursor.py index 6af82e72de..183c42a291 100644 --- a/src/connector/python/windows/python2/taos/cursor.py +++ b/src/connector/python/windows/python2/taos/cursor.py @@ -102,7 +102,6 @@ class TDengineCursor(object): # TODO : change the exception raised here raise ProgrammingError("Cursor is not connected") - self._connection.clear_result_set() self._reset_result() stmt = operation @@ -149,7 +148,7 @@ class TDengineCursor(object): for i in range(len(self._fields)): buffer[i].extend(block[i]) - self._connection.clear_result_set() + self._reset_result() return list(map(tuple, zip(*buffer))) @@ -171,6 +170,8 @@ class TDengineCursor(object): """ self._description = None self._rowcount = -1 + if self._result is not None: + CTaosInterface.freeResult(self._result) self._result = None self._fields = None self._block = None diff --git a/src/connector/python/windows/python3/taos/cinterface.py b/src/connector/python/windows/python3/taos/cinterface.py index 864a2f5ecb..c6218fe9d4 100644 --- a/src/connector/python/windows/python3/taos/cinterface.py +++ b/src/connector/python/windows/python3/taos/cinterface.py @@ -413,5 +413,5 @@ if __name__ == '__main__': print(data) - cinter.freeresult(result) + cinter.freeResult(result) cinter.close(conn) \ No newline at end of file diff --git a/src/connector/python/windows/python3/taos/cursor.py b/src/connector/python/windows/python3/taos/cursor.py index 0ee8af4ed0..ddf6d0b315 100644 --- a/src/connector/python/windows/python3/taos/cursor.py +++ b/src/connector/python/windows/python3/taos/cursor.py @@ -102,7 +102,6 @@ class TDengineCursor(object): # TODO : change the exception raised here raise ProgrammingError("Cursor is not connected") - self._connection.clear_result_set() self._reset_result() stmt = operation @@ -149,7 +148,7 @@ class TDengineCursor(object): for i in range(len(self._fields)): buffer[i].extend(block[i]) - self._connection.clear_result_set() + self._reset_result() return list(map(tuple, zip(*buffer))) @@ -171,6 +170,8 @@ class TDengineCursor(object): """ self._description = None self._rowcount = -1 + if self._result is not None: + CTaosInterface.freeResult(self._result) self._result = None self._fields = None self._block = None From 7e2abf0e08d158f716f8d9d8628c0e0cc0142093 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 6 Jun 2020 06:30:50 +0000 Subject: [PATCH 04/72] [TD-527] Group error codes by module --- src/client/src/TSDBJNIConnector.c | 2 +- src/client/src/tscAsync.c | 34 ++-- src/client/src/tscFunctionImpl.c | 4 +- src/client/src/tscLocal.c | 8 +- src/client/src/tscParseInsert.c | 40 ++-- src/client/src/tscPrepare.c | 40 ++-- src/client/src/tscSQLParser.c | 212 ++++++++++---------- src/client/src/tscSecondaryMerge.c | 22 +-- src/client/src/tscServer.c | 102 +++++----- src/client/src/tscSql.c | 56 +++--- src/client/src/tscStream.c | 12 +- src/client/src/tscSub.c | 6 +- src/client/src/tscSubquery.c | 38 ++-- src/client/src/tscUtil.c | 50 ++--- src/common/src/tglobal.c | 2 +- src/dnode/src/dnodeMPeer.c | 4 +- src/dnode/src/dnodeMRead.c | 6 +- src/dnode/src/dnodeMWrite.c | 6 +- src/dnode/src/dnodeMgmt.c | 6 +- src/dnode/src/dnodePeer.c | 6 +- src/dnode/src/dnodeShell.c | 6 +- src/dnode/src/dnodeVRead.c | 6 +- src/dnode/src/dnodeVWrite.c | 2 +- src/inc/taoserror.h | 271 +++++++++++++++----------- src/kit/shell/src/shellEngine.c | 2 +- src/mnode/src/mnodeAcct.c | 2 +- src/mnode/src/mnodeBalance.c | 2 +- src/mnode/src/mnodeDb.c | 80 ++++---- src/mnode/src/mnodeDnode.c | 34 ++-- src/mnode/src/mnodeInt.c | 2 +- src/mnode/src/mnodeMnode.c | 14 +- src/mnode/src/mnodePeer.c | 6 +- src/mnode/src/mnodeProfile.c | 24 +-- src/mnode/src/mnodeRead.c | 6 +- src/mnode/src/mnodeSdb.c | 6 +- src/mnode/src/mnodeShow.c | 22 +-- src/mnode/src/mnodeTable.c | 150 +++++++------- src/mnode/src/mnodeUser.c | 44 ++--- src/mnode/src/mnodeVgroup.c | 24 +-- src/mnode/src/mnodeWrite.c | 8 +- src/plugins/http/src/httpJson.c | 4 +- src/plugins/http/src/httpSql.c | 6 +- src/plugins/http/src/tgJson.c | 4 +- src/plugins/monitor/src/monitorMain.c | 2 +- src/query/src/qExecutor.c | 44 ++--- src/query/src/qast.c | 6 +- src/query/src/qresultBuf.c | 10 +- src/query/src/tlosertree.c | 2 +- src/query/tests/unitTest.cpp | 104 +++++----- src/rpc/src/rpcMain.c | 82 ++++---- src/tsdb/src/tsdbMain.c | 23 ++- src/tsdb/src/tsdbMeta.c | 12 +- src/tsdb/src/tsdbRead.c | 16 +- src/util/src/tbuffer.c | 6 +- src/util/src/tqueue.c | 4 +- src/util/src/tutil.c | 6 +- src/vnode/src/vnodeMain.c | 22 +-- src/vnode/src/vnodeRead.c | 8 +- src/vnode/src/vnodeWrite.c | 6 +- tests/examples/C#/TDengineDriver.cs | 2 - tests/tsim/src/simExe.c | 8 +- 61 files changed, 885 insertions(+), 859 deletions(-) diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index cec4737226..459b0f2b98 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -309,7 +309,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getErrCodeImp(JNI TAOS *tscon = (TAOS *)con; if (tscon == NULL) { jniError("jobj:%p, connection is closed", jobj); - return (jint)TSDB_CODE_INVALID_CONNECTION; + return (jint)TSDB_CODE_TSC_INVALID_CONNECTION; } if ((void *)tres == NULL) { diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index ebcdddffde..3414ff8d98 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -53,7 +53,7 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const sem_init(&pSql->rspSem, 0, 0); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { tscError("failed to malloc payload"); - tscQueueAsyncError(fp, param, TSDB_CODE_CLI_OUT_OF_MEMORY); + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_OUT_OF_MEMORY); return; } @@ -61,7 +61,7 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const pSql->sqlstr = calloc(1, sqlLen + 1); if (pSql->sqlstr == NULL) { tscError("%p failed to malloc sql string buffer", pSql); - tscQueueAsyncError(fp, param, TSDB_CODE_CLI_OUT_OF_MEMORY); + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_OUT_OF_MEMORY); free(pCmd->payload); return; } @@ -73,7 +73,7 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const tscDump("%p SQL: %s", pSql, pSql->sqlstr); int32_t code = tsParseSql(pSql, true); - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; if (code != TSDB_CODE_SUCCESS) { pSql->res.code = code; @@ -89,16 +89,16 @@ void taos_query_a(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *pa STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { tscError("bug!!! pObj:%p", pObj); - terrno = TSDB_CODE_DISCONNECTED; - tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED); + terrno = TSDB_CODE_TSC_DISCONNECTED; + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_DISCONNECTED); return; } int32_t sqlLen = strlen(sqlstr); if (sqlLen > tsMaxSQLStringLen) { tscError("sql string exceeds max length:%d", tsMaxSQLStringLen); - terrno = TSDB_CODE_INVALID_SQL; - tscQueueAsyncError(fp, param, TSDB_CODE_INVALID_SQL); + terrno = TSDB_CODE_TSC_INVALID_SQL; + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_INVALID_SQL); return; } @@ -107,8 +107,8 @@ void taos_query_a(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *pa SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { tscError("failed to malloc sqlObj"); - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; - tscQueueAsyncError(fp, param, TSDB_CODE_CLI_OUT_OF_MEMORY); + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_OUT_OF_MEMORY); return; } @@ -203,7 +203,7 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi SSqlObj *pSql = (SSqlObj *)taosa; if (pSql == NULL || pSql->signature != pSql) { tscError("sql object is NULL"); - tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED); + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_DISCONNECTED); return; } @@ -212,7 +212,7 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi if (pRes->qhandle == 0) { tscError("qhandle is NULL"); - tscQueueAsyncError(fp, param, TSDB_CODE_INVALID_QHANDLE); + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_INVALID_QHANDLE); return; } @@ -260,7 +260,7 @@ void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW), SSqlObj *pSql = (SSqlObj *)taosa; if (pSql == NULL || pSql->signature != pSql) { tscError("sql object is NULL"); - tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED); + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_DISCONNECTED); return; } @@ -269,7 +269,7 @@ void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW), if (pRes->qhandle == 0) { tscError("qhandle is NULL"); - tscQueueAsyncError(fp, param, TSDB_CODE_INVALID_QHANDLE); + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_INVALID_QHANDLE); return; } @@ -466,7 +466,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { code = tscGetSTableVgroupInfo(pSql, 0); pRes->code = code; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; } else { // normal async query continues if (pCmd->parseFinished) { tscTrace("%p re-send data to vnode in table Meta callback since sql parsed completed", pSql); @@ -491,7 +491,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { return; } - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; } } @@ -500,13 +500,13 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { code = tscGetTableMeta(pSql, pTableMetaInfo); pRes->code = code; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_SUCCESS && UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { code = tscGetSTableVgroupInfo(pSql, pCmd->clauseIndex); pRes->code = code; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; } } diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index baefdbe102..9edb7d59cc 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -156,7 +156,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI int16_t *bytes, int32_t *interBytes, int16_t extLength, bool isSuperTable) { if (!isValidDataType(dataType, dataBytes)) { tscError("Illegal data type %d or data type length %d", dataType, dataBytes); - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY || functionId == TSDB_FUNC_TAG_DUMMY || @@ -325,7 +325,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI *bytes = (int16_t)dataBytes; *interBytes = dataBytes + sizeof(SLastrowInfo); } else { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 5ffdcd2167..d28f7a6673 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -312,12 +312,12 @@ static void tscProcessServStatus(SSqlObj *pSql) { STscObj* pObj = pSql->pTscObj; if (pObj->pHb != NULL) { - if (pObj->pHb->res.code == TSDB_CODE_NETWORK_UNAVAIL) { - pSql->res.code = TSDB_CODE_NETWORK_UNAVAIL; + if (pObj->pHb->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { + pSql->res.code = TSDB_CODE_RPC_NETWORK_UNAVAIL; return; } } else { - if (pSql->res.code == TSDB_CODE_NETWORK_UNAVAIL) { + if (pSql->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { return; } } @@ -378,7 +378,7 @@ int tscProcessLocalCmd(SSqlObj *pSql) { } else if (pCmd->command == TSDB_SQL_SERV_STATUS) { tscProcessServStatus(pSql); } else { - pSql->res.code = TSDB_CODE_INVALID_SQL; + pSql->res.code = TSDB_CODE_TSC_INVALID_SQL; tscError("%p not support command:%d", pSql, pCmd->command); } diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 8f4bcedfd6..abab32d71b 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -134,7 +134,7 @@ int tsParseTime(SSQLToken *pToken, int64_t *time, char **next, char *error, int1 } if (getTimestampInUsFromStr(valueToken.z, valueToken.n, &interval) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (timePrec == TSDB_TIME_PRECISION_MILLI) { @@ -423,7 +423,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[ } strcpy(error, "client out of memory"); - *code = TSDB_CODE_CLI_OUT_OF_MEMORY; + *code = TSDB_CODE_TSC_OUT_OF_MEMORY; return -1; } @@ -431,7 +431,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[ if ((type != TK_NOW && type != TK_INTEGER && type != TK_STRING && type != TK_FLOAT && type != TK_BOOL && type != TK_NULL && type != TK_HEX && type != TK_OCT && type != TK_BIN) || (sToken.n == 0) || (type == TK_RP)) { tscInvalidSQLErrMsg(error, "invalid data or symbol", sToken.z); - *code = TSDB_CODE_INVALID_SQL; + *code = TSDB_CODE_TSC_INVALID_SQL; return -1; } @@ -463,13 +463,13 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[ bool isPrimaryKey = (colIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX); int32_t ret = tsParseOneColumnData(pSchema, &sToken, start, error, str, isPrimaryKey, timePrec); if (ret != TSDB_CODE_SUCCESS) { - *code = TSDB_CODE_INVALID_SQL; + *code = TSDB_CODE_TSC_INVALID_SQL; return -1; // NOTE: here 0 mean error! } if (isPrimaryKey && tsCheckTimestamp(pDataBlocks, start) != TSDB_CODE_SUCCESS) { tscInvalidSQLErrMsg(error, "client time/server time can not be mixed up", sToken.z); - *code = TSDB_CODE_INVALID_TIME_STAMP; + *code = TSDB_CODE_TSC_INVALID_TIME_STAMP; return -1; } } @@ -526,7 +526,7 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, STableMeta *pTableMe if (spd->hasVal[0] == false) { strcpy(error, "primary timestamp column can not be null"); - *code = TSDB_CODE_INVALID_SQL; + *code = TSDB_CODE_TSC_INVALID_SQL; return -1; } @@ -560,7 +560,7 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, STableMeta *pTableMe *str += index; if (sToken.n == 0 || sToken.type != TK_RP) { tscInvalidSQLErrMsg(error, ") expected", *str); - *code = TSDB_CODE_INVALID_SQL; + *code = TSDB_CODE_TSC_INVALID_SQL; return -1; } @@ -569,7 +569,7 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, STableMeta *pTableMe if (numOfRows <= 0) { strcpy(error, "no any data points"); - *code = TSDB_CODE_INVALID_SQL; + *code = TSDB_CODE_TSC_INVALID_SQL; return -1; } else { return numOfRows; @@ -611,7 +611,7 @@ int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int3 // do nothing, if allocate more memory failed pDataBlock->nAllocSize = nAllocSizeOld; *numOfRows = (int32_t)(pDataBlock->nAllocSize - pDataBlock->headerSize) / rowSize; - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } } @@ -687,13 +687,13 @@ static int32_t doParseInsertStatement(SSqlObj *pSql, void *pTableList, char **st int32_t maxNumOfRows; ret = tscAllocateMemIfNeed(dataBuf, tinfo.rowSize, &maxNumOfRows); if (TSDB_CODE_SUCCESS != ret) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } - int32_t code = TSDB_CODE_INVALID_SQL; + int32_t code = TSDB_CODE_TSC_INVALID_SQL; char * tmpTokenBuf = calloc(1, 4096); // used for deleting Escape character: \\, \', \" if (NULL == tmpTokenBuf) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } int32_t numOfRows = tsParseValues(str, dataBuf, pTableMeta, maxNumOfRows, spd, pCmd->payload, &code, tmpTokenBuf); @@ -772,7 +772,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { } if (numOfColList == 0 && cstart != NULL) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, TABLE_INDEX); @@ -954,7 +954,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { createTable = true; code = tscGetMeterMetaEx(pSql, pTableMetaInfo, true); - if (TSDB_CODE_ACTION_IN_PROGRESS == code) { + if (TSDB_CODE_TSC_ACTION_IN_PROGRESS == code) { return code; } @@ -967,7 +967,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { code = tscGetMeterMetaEx(pSql, pTableMetaInfo, false); if (pCmd->curSql == NULL) { - assert(code == TSDB_CODE_ACTION_IN_PROGRESS); + assert(code == TSDB_CODE_TSC_ACTION_IN_PROGRESS); } } @@ -981,7 +981,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { } if (*sqlstr == NULL) { - code = TSDB_CODE_INVALID_SQL; + code = TSDB_CODE_TSC_INVALID_SQL; } return code; @@ -1046,7 +1046,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) { pSql->cmd.pDataBlocks = tscCreateBlockArrayList(); if (NULL == pCmd->pTableList || NULL == pSql->cmd.pDataBlocks) { - code = TSDB_CODE_CLI_OUT_OF_MEMORY; + code = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error_clean; } } else { @@ -1075,7 +1075,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) { * Otherwise, create the first submit block and submit to virtual node. */ if (totalNum == 0) { - code = TSDB_CODE_INVALID_SQL; + code = TSDB_CODE_TSC_INVALID_SQL; goto _error_clean; } else { break; @@ -1103,7 +1103,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) { * And during the getMeterMetaCallback function, the sql string will be parsed from the * interrupted position. */ - if (TSDB_CODE_ACTION_IN_PROGRESS == code) { + if (TSDB_CODE_TSC_ACTION_IN_PROGRESS == code) { tscTrace("%p waiting for get table meta during insert, then resume from offset: %" PRId64 " , %s", pSql, pos, pCmd->curSql); return code; @@ -1297,7 +1297,7 @@ _clean: int tsParseInsertSql(SSqlObj *pSql) { if (!pSql->pTscObj->writeAuth) { - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_TSC_NO_WRITE_AUTH; } int32_t index = 0; diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 1a76bd5e61..ba97c7d00a 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -62,7 +62,7 @@ static int normalStmtAddPart(SNormalStmt* stmt, bool isParam, char* str, uint32_ size *= 2; void* tmp = realloc(stmt->parts, sizeof(SNormalStmtPart) * size); if (tmp == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } stmt->sizeParts = size; stmt->parts = (SNormalStmtPart*)tmp; @@ -133,7 +133,7 @@ static int normalStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) { case TSDB_DATA_TYPE_NCHAR: var->pz = (char*)malloc((*tb->length) + 1); if (var->pz == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } memcpy(var->pz, tb->buffer, (*tb->length)); var->pz[*tb->length] = 0; @@ -142,7 +142,7 @@ static int normalStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) { default: tscTrace("param %d: type mismatch or invalid", i); - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } } @@ -187,7 +187,7 @@ static int normalStmtPrepare(STscStmt* stmt) { if (normal->numParams > 0) { normal->params = calloc(normal->numParams, sizeof(tVariant)); if (normal->params == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } } @@ -273,7 +273,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { } if (bind->buffer_type != param->type) { - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } short size = 0; @@ -300,7 +300,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { case TSDB_DATA_TYPE_BINARY: if ((*bind->length) > param->bytes) { - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } size = (short)*bind->length; STR_WITH_SIZE_TO_VARSTR(data + param->offset, bind->buffer, size); @@ -309,14 +309,14 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { case TSDB_DATA_TYPE_NCHAR: { size_t output = 0; if (!taosMbsToUcs4(bind->buffer, *bind->length, varDataVal(data + param->offset), param->bytes - VARSTR_HEADER_SIZE, &output)) { - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } varDataSetLen(data + param->offset, output); return TSDB_CODE_SUCCESS; } default: assert(false); - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } memcpy(data + param->offset, bind->buffer, size); @@ -344,7 +344,7 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) { const double factor = 1.5; void* tmp = realloc(pBlock->pData, (uint32_t)(totalDataSize * factor)); if (tmp == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } pBlock->pData = (char*)tmp; pBlock->nAllocSize = (uint32_t)(totalDataSize * factor); @@ -416,7 +416,7 @@ static int insertStmtReset(STscStmt* pStmt) { static int insertStmtExecute(STscStmt* stmt) { SSqlCmd* pCmd = &stmt->pSql->cmd; if (pCmd->batchSize == 0) { - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } if ((pCmd->batchSize % 2) == 1) { ++pCmd->batchSize; @@ -470,14 +470,14 @@ static int insertStmtExecute(STscStmt* stmt) { TAOS_STMT* taos_stmt_init(TAOS* taos) { STscObj* pObj = (STscObj*)taos; if (pObj == NULL || pObj->signature != pObj) { - terrno = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; tscError("connection disconnected"); return NULL; } STscStmt* pStmt = calloc(1, sizeof(STscStmt)); if (pStmt == NULL) { - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("failed to allocate memory for statement"); return NULL; } @@ -486,7 +486,7 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) { SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { free(pStmt); - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("failed to allocate memory for statement"); return NULL; } @@ -505,8 +505,8 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) { - terrno = TSDB_CODE_DISCONNECTED; - return TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; + return TSDB_CODE_TSC_DISCONNECTED; } SSqlObj* pSql = pStmt->pSql; @@ -521,7 +521,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { tscError("%p failed to malloc payload buffer", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1); @@ -529,7 +529,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { if (pSql->sqlstr == NULL) { tscError("%p failed to malloc sql string buffer", pSql); free(pCmd->payload); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } pRes->qhandle = 0; @@ -545,7 +545,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { pSql->cmd.batchSize = 0; int32_t code = tsParseSql(pSql, true); - if (code == TSDB_CODE_ACTION_IN_PROGRESS) { + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { // wait for the callback function to post the semaphore tsem_wait(&pSql->rspSem); return pSql->res.code; @@ -590,7 +590,7 @@ int taos_stmt_add_batch(TAOS_STMT* stmt) { if (pStmt->isInsert) { return insertStmtAddBatch(pStmt); } - return TSDB_CODE_OPS_NOT_SUPPORT; + return TSDB_CODE_COM_OPS_NOT_SUPPORT; } int taos_stmt_reset(TAOS_STMT* stmt) { @@ -609,7 +609,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) { } else { char* sql = normalStmtBuildSql(pStmt); if (sql == NULL) { - ret = TSDB_CODE_CLI_OUT_OF_MEMORY; + ret = TSDB_CODE_TSC_OUT_OF_MEMORY; } else { tfree(pStmt->pSql->sqlstr); pStmt->pSql->sqlstr = sql; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index bfa8a93791..e1f7f97637 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -179,7 +179,7 @@ static int32_t handlePassword(SSqlCmd* pCmd, SSQLToken* pPwd) { // todo handle memory leak in error handle function int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pInfo == NULL || pSql == NULL || pSql->signature != pSql) { - return TSDB_CODE_APP_ERROR; + return TSDB_CODE_TSC_APP_ERROR; } SSqlCmd* pCmd = &(pSql->cmd); @@ -264,7 +264,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { case TSDB_SQL_SHOW: { if (setShowInfo(pSql, pInfo) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } break; @@ -286,7 +286,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } if (parseCreateDBOptions(pCmd, pCreateDB) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } break; @@ -314,7 +314,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { SSQLToken* pPwd = &pInfo->pDCLInfo->user.passwd; if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pName->n > TSDB_USER_LEN) { @@ -411,12 +411,12 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pCmd->command == TSDB_SQL_CREATE_USER) { if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else { if (pUser->type == TSDB_ALTER_USER_PASSWD) { if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) { assert(pPwd->type == TSDB_DATA_TYPE_NULL); @@ -577,7 +577,7 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) { // interval is not null SSQLToken* t = &pQuerySql->interval; if (getTimestampInUsFromStr(t->z, t->n, &pQueryInfo->intervalTime) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // if the unit of time window value is millisecond, change the value from microsecond @@ -596,7 +596,7 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) { // for top/bottom + interval query, we do not add additional timestamp column in the front if (isTopBottomQuery(pQueryInfo)) { if (parseSlidingClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; @@ -635,7 +635,7 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) { } if (tableIndex == COLUMN_INDEX_INITIAL_VAL) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SColumnIndex index = {tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX}; @@ -651,7 +651,7 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) { } if (parseSlidingClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; @@ -1040,7 +1040,7 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL /* db name is not specified, the tableName dose not include db name */ if (pDB != NULL) { if (pDB->n > TSDB_DB_NAME_LEN) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } memcpy(&fullName[totalLen], pDB->z, pDB->n); @@ -1054,12 +1054,12 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL /* here we only check the table name length limitation */ if (tableName->n > TSDB_TABLE_NAME_LEN) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else { // pDB == NULL, the db prefix name is specified in tableName /* the length limitation includes tablename + dbname + sep */ if (tableName->n > TSDB_TABLE_NAME_LEN + TSDB_DB_NAME_LEN + tListLen(TS_PATH_DELIMITER)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -1075,7 +1075,7 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL fullName[totalLen] = 0; } - return (totalLen <= TSDB_TABLE_ID_LEN) ? TSDB_CODE_SUCCESS : TSDB_CODE_INVALID_SQL; + return (totalLen <= TSDB_TABLE_ID_LEN) ? TSDB_CODE_SUCCESS : TSDB_CODE_TSC_INVALID_SQL; } static void extractColumnNameFromString(tSQLExprItem* pItem) { @@ -1122,12 +1122,12 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel // select table_name1.field_name1, table_name2.field_name2 from table_name1, table_name2 if (addProjectionExprAndResultField(pQueryInfo, pItem) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else if (pItem->pNode->nSQLOptr >= TK_COUNT && pItem->pNode->nSQLOptr <= TK_TBID) { // sql function in selection clause, append sql function info in pSqlCmd structure sequentially if (addExprAndResultField(pQueryInfo, outputIndex, pItem, true) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else if (pItem->pNode->nSQLOptr >= TK_PLUS && pItem->pNode->nSQLOptr <= TK_REM) { @@ -1154,7 +1154,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel } if (buildArithmeticExprString(pItem->pNode, &p) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // expr string is set as the parameter of function @@ -1230,7 +1230,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel } if (pQueryInfo->fieldsInfo.numOfOutput > TSDB_MAX_COLUMNS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -1246,7 +1246,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel tscTansformSQLFuncForSTableQuery(pQueryInfo); if (hasUnsupportFunctionsForSTableQuery(pQueryInfo)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -1414,7 +1414,7 @@ int32_t addProjectionExprAndResultField(SQueryInfo* pQueryInfo, tSQLExprItem* pI addProjectQueryCol(pQueryInfo, startPos, &index, pItem); } } else { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; @@ -1483,7 +1483,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr int16_t functionID = 0; if (changeFunctionID(optr, &functionID) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SSqlExpr* pExpr = NULL; @@ -1596,12 +1596,12 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr int16_t functionID = 0; if (changeFunctionID(optr, &functionID) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (getResultDataInfo(pSchema->type, pSchema->bytes, functionID, 0, &resultType, &resultSize, &intermediateResSize, 0, false) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // set the first column ts for diff query @@ -1626,14 +1626,14 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr /* set the leastsquares parameters */ char val[8] = {0}; if (tVariantDump(&pParamElem[1].pNode->val, val, TSDB_DATA_TYPE_DOUBLE, true) < 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, DOUBLE_BYTES, 0); memset(val, 0, tListLen(val)); if (tVariantDump(&pParamElem[2].pNode->val, val, TSDB_DATA_TYPE_DOUBLE, true) < 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double), 0); @@ -1698,7 +1698,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr for (int32_t j = 0; j < tscGetNumOfColumns(pTableMetaInfo->pTableMeta); ++j) { index.columnIndex = j; if (setExprInfoForFunctions(pQueryInfo, pSchema, functionID, pItem->aliasName, colIndex++, &index) != 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -1716,7 +1716,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr } if (setExprInfoForFunctions(pQueryInfo, pSchema, functionID, pItem->aliasName, colIndex + i, &index) != 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } } @@ -1733,7 +1733,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr SColumnIndex index = {.tableIndex = j, .columnIndex = i}; if (setExprInfoForFunctions(pQueryInfo, pSchema, functionID, pItem->aliasName, colIndex + i + j, &index) != 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -1809,7 +1809,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr */ int16_t functionId = 0; if (changeFunctionID(optr, &functionId) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pExpr = tscSqlExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, resultSize, false); @@ -1824,7 +1824,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr int16_t functionId = 0; if (changeFunctionID(optr, &functionId) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // set the first column ts for top/bottom query @@ -1914,7 +1914,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr } default: - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -2014,7 +2014,7 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColum if (COLUMN_INDEX_VALIDE(*pIndex)) { return TSDB_CODE_SUCCESS; } else { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -2041,7 +2041,7 @@ int32_t getTableIndexImpl(SSQLToken* pTableToken, SQueryInfo* pQueryInfo, SColum } if (pIndex->tableIndex < 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; @@ -2052,7 +2052,7 @@ int32_t getTableIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIn extractTableNameFromToken(pToken, &tableToken); if (getTableIndexImpl(&tableToken, pQueryInfo, pIndex) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; @@ -2060,13 +2060,13 @@ int32_t getTableIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIn int32_t getColumnIndexByName(const SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex) { if (pQueryInfo->pTableMetaInfo == NULL || pQueryInfo->numOfTables == 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SSQLToken tmpToken = *pToken; if (getTableIndexByName(&tmpToken, pQueryInfo, pIndex) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return doGetColumnIndexByName(&tmpToken, pQueryInfo, pIndex); @@ -2239,7 +2239,7 @@ int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killType) { SSQLToken* idStr = &(pInfo->pDCLInfo->ip); if (idStr->n > TSDB_KILL_MSG_LEN) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } strncpy(pCmd->payload, idStr->z, idStr->n); @@ -2286,7 +2286,7 @@ int32_t tscTansformSQLFuncForSTableQuery(SQueryInfo* pQueryInfo) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); if (pTableMetaInfo->pTableMeta == NULL || !UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } assert(tscGetNumOfTags(pTableMetaInfo->pTableMeta) >= 0); @@ -2308,7 +2308,7 @@ int32_t tscTansformSQLFuncForSTableQuery(SQueryInfo* pQueryInfo) { (functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_AVG_IRATE)) { if (getResultDataInfo(pSrcSchema->type, pSrcSchema->bytes, functionId, pExpr->param[0].i64Key, &type, &bytes, &interBytes, 0, true) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } tscSqlExprUpdate(pQueryInfo, k, functionId, pExpr->colInfo.colIndex, TSDB_DATA_TYPE_BINARY, bytes); @@ -2732,7 +2732,7 @@ static bool isExprDirectParentOfLeaftNode(tSQLExpr* pExpr) { static int32_t tSQLExprLeafToString(tSQLExpr* pExpr, bool addParentheses, char** output) { if (!isExprDirectParentOfLeaftNode(pExpr)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } tSQLExpr* pLeft = pExpr->pLeft; @@ -2745,7 +2745,7 @@ static int32_t tSQLExprLeafToString(tSQLExpr* pExpr, bool addParentheses, char** tSQLExprNodeToString(pLeft, output); if (optrToString(pExpr, output) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } tSQLExprNodeToString(pRight, output); @@ -2811,7 +2811,7 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString) { break; } default: - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } *exprString += 1; @@ -2822,7 +2822,7 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString) { static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) { tSQLExprList* pList = pExpr->pParam; if (pList->nExpr <= 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pList->nExpr > 0) { @@ -2838,7 +2838,7 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) { } if (pSub->val.nLen <= 0 || pSub->val.nLen > TSDB_TABLE_NAME_LEN) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -2886,7 +2886,7 @@ static int32_t extractColumnFilterInfo(SQueryInfo* pQueryInfo, SColumnIndex* pIn // TODO fixme: failed to invalid the filter expression: "col1 = 1 OR col2 = 2" pColFilter = addColumnFilterInfo(pColumn); } else { // error; - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pColFilter->filterstr = @@ -2961,7 +2961,7 @@ static int32_t getTablenameCond(SQueryInfo* pQueryInfo, tSQLExpr* pTableCond, SS tSQLExpr* pRight = pTableCond->pRight; if (!isTablenameToken(&pLeft->colInfo)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t ret = TSDB_CODE_SUCCESS; @@ -2994,7 +2994,7 @@ static int32_t getColumnQueryCondInfo(SQueryInfo* pQueryInfo, tSQLExpr* pExpr, i } else { // handle leaf node SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(&pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return extractColumnFilterInfo(pQueryInfo, &index, pExpr, relOptr); @@ -3018,7 +3018,7 @@ static int32_t getJoinCondInfo(SQueryInfo* pQueryInfo, tSQLExpr* pExpr) { SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(&pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); @@ -3030,7 +3030,7 @@ static int32_t getJoinCondInfo(SQueryInfo* pQueryInfo, tSQLExpr* pExpr) { index = (SColumnIndex)COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(&pExpr->pRight->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); @@ -3056,7 +3056,7 @@ int32_t buildArithmeticExprString(tSQLExpr* pExpr, char** exprString) { } else { int32_t ret = tSQLExprNodeToString(pLeft, exprString); if (ret != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -3067,7 +3067,7 @@ int32_t buildArithmeticExprString(tSQLExpr* pExpr, char** exprString) { } else { int32_t ret = tSQLExprNodeToString(pRight, exprString); if (ret != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -3081,12 +3081,12 @@ static int32_t validateSQLExpr(tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnL if (*type == NON_ARITHMEIC_EXPR) { *type = NORMAL_ARITHMETIC; } else if (*type == AGG_ARIGHTMEIC) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(&pExpr->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // if column is timestamp, bool, binary, nchar, not support arithmetic, so return invalid sql @@ -3095,17 +3095,17 @@ static int32_t validateSQLExpr(tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnL if ((pSchema->type == TSDB_DATA_TYPE_TIMESTAMP) || (pSchema->type == TSDB_DATA_TYPE_BOOL) || (pSchema->type == TSDB_DATA_TYPE_BINARY) || (pSchema->type == TSDB_DATA_TYPE_NCHAR)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pList->ids[pList->num++] = index; } else if (pExpr->nSQLOptr == TK_FLOAT && (isnan(pExpr->val.dKey) || isinf(pExpr->val.dKey))) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } else if (pExpr->nSQLOptr >= TK_COUNT && pExpr->nSQLOptr <= TK_AVG_IRATE) { if (*type == NON_ARITHMEIC_EXPR) { *type = AGG_ARIGHTMEIC; } else if (*type == NORMAL_ARITHMETIC) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t outputIndex = tscSqlExprNumOfExprs(pQueryInfo); @@ -3114,7 +3114,7 @@ static int32_t validateSQLExpr(tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnL // sql function in selection clause, append sql function info in pSqlCmd structure sequentially if (addExprAndResultField(pQueryInfo, outputIndex, &item, false) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -3318,7 +3318,7 @@ static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, S if (index.columnIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX) { // query on time range if (!validateJoinExprNode(pQueryInfo, *pExpr, &index)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // set join query condition @@ -3380,7 +3380,7 @@ static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, S } else { if (pRight->nSQLOptr == TK_ID) { // join on tag columns for stable query if (!validateJoinExprNode(pQueryInfo, *pExpr, &index)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pCondExpr->pJoinExpr != NULL) { @@ -3425,7 +3425,7 @@ int32_t getQueryCondExpr(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SCondExpr* pC tSQLExpr* pRight = (*pExpr)->pRight; if (!isValidExpr(pLeft, pRight, (*pExpr)->nSQLOptr)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t leftType = -1; @@ -3663,7 +3663,7 @@ static int32_t getTimeRangeFromExpr(SQueryInfo* pQueryInfo, tSQLExpr* pExpr) { } else { SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(&pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); @@ -3891,7 +3891,7 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t * where ts in ('2015-12-12 4:8:12') */ if (pRight->nSQLOptr == TK_SET || optr == TK_IN) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int64_t val = 0; @@ -3904,14 +3904,14 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t if (taosParseTime(pRight->val.pz, &val, pRight->val.nLen, TSDB_TIME_PRECISION_MICRO) == TSDB_CODE_SUCCESS) { parsed = true; } else { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else { SSQLToken token = {.z = pRight->val.pz, .n = pRight->val.nLen, .type = TK_ID}; int32_t len = tSQLGetToken(pRight->val.pz, &token.type); if ((token.type != TK_INTEGER && token.type != TK_FLOAT) || len != pRight->val.nLen) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } } else if (pRight->nSQLOptr == TK_INTEGER && timePrecision == TSDB_TIME_PRECISION_MILLI) { @@ -4019,7 +4019,7 @@ int32_t parseFillClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL) { if (pQueryInfo->fillVal == NULL) { pQueryInfo->fillVal = calloc(size, sizeof(int64_t)); if (pQueryInfo->fillVal == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } } @@ -4330,7 +4330,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } if (!validateOneTags(pCmd, &pFieldList->p[0])) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]); @@ -4353,7 +4353,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { SSQLToken name = {.z = pItem->pVar.pz, .n = pItem->pVar.nLen, .type = TK_STRING}; if (getColumnIndexByName(&name, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (index.columnIndex < tscGetNumOfColumns(pTableMeta)) { @@ -4370,7 +4370,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } else if (pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) { tVariantList* pVarList = pAlterSQL->varList; if (pVarList->nExpr > 2) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } tVariantListItem* pSrcItem = &pAlterSQL->varList->a[0]; @@ -4389,12 +4389,12 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { SSQLToken srcToken = {.z = pSrcItem->pVar.pz, .n = pSrcItem->pVar.nLen, .type = TK_STRING}; if (getColumnIndexByName(&srcToken, pQueryInfo, &srcIndex) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SSQLToken destToken = {.z = pDstItem->pVar.pz, .n = pDstItem->pVar.nLen, .type = TK_STRING}; if (getColumnIndexByName(&destToken, pQueryInfo, &destIndex) == TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } char name[TSDB_COL_NAME_LEN + 1] = {0}; @@ -4417,7 +4417,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER; SSQLToken name = {.type = TK_STRING, .z = pTagName->pz, .n = pTagName->nLen}; if (getColumnIndexByName(&name, pQueryInfo, &columnIndex) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (columnIndex.columnIndex < tscGetNumOfColumns(pTableMeta)) { @@ -4440,7 +4440,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { int32_t size = sizeof(SUpdateTableTagValMsg) + pTagsSchema->bytes + TSDB_EXTRA_PAYLOAD_SIZE; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { tscError("%p failed to malloc for alter table msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SUpdateTableTagValMsg* pUpdateMsg = (SUpdateTableTagValMsg*) (pCmd->payload + tsRpcHeadSize); @@ -4474,7 +4474,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } if (!validateOneColumn(pCmd, &pFieldList->p[0])) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]); @@ -4563,7 +4563,7 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SQueryInfo* pQueryInfo) { invalidSqlErrMsg(pQueryInfo->msg, msg1); } - return isProjectionFunction == true ? TSDB_CODE_INVALID_SQL : TSDB_CODE_SUCCESS; + return isProjectionFunction == true ? TSDB_CODE_TSC_INVALID_SQL : TSDB_CODE_SUCCESS; } typedef struct SDNodeDynConfOption { @@ -4573,7 +4573,7 @@ typedef struct SDNodeDynConfOption { int32_t validateDNodeConfig(tDCLSQL* pOptions) { if (pOptions->nTokens < 2 || pOptions->nTokens > 3) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } const int DNODE_DYNAMIC_CFG_OPTIONS_SIZE = 17; @@ -4599,7 +4599,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) { SSQLToken* pValToken = &pOptions->a[2]; int32_t val = strtol(pValToken->z, NULL, 10); if (val != 0 && val != 1) { - return TSDB_CODE_INVALID_SQL; // options value is invalid + return TSDB_CODE_TSC_INVALID_SQL; // options value is invalid } return TSDB_CODE_SUCCESS; } else { @@ -4608,7 +4608,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) { int32_t val = strtol(pValToken->z, NULL, 10); if (val < 131 || val > 199) { /* options value is out of valid range */ - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } for (int32_t i = 2; i < DNODE_DYNAMIC_CFG_OPTIONS_SIZE - 1; ++i) { @@ -4621,12 +4621,12 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) { } } - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t validateLocalConfig(tDCLSQL* pOptions) { if (pOptions->nTokens < 1 || pOptions->nTokens > 2) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SDNodeDynConfOption LOCAL_DYNAMIC_CFG_OPTIONS[6] = {{"resetLog", 8}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12}, @@ -4648,7 +4648,7 @@ int32_t validateLocalConfig(tDCLSQL* pOptions) { int32_t val = strtol(pValToken->z, NULL, 10); if (val < 131 || val > 199) { // options value is out of valid range - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } for (int32_t i = 1; i < tListLen(LOCAL_DYNAMIC_CFG_OPTIONS); ++i) { @@ -4659,20 +4659,20 @@ int32_t validateLocalConfig(tDCLSQL* pOptions) { } } } - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t validateColumnName(char* name) { bool ret = isKeyWord(name, strlen(name)); if (ret) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SSQLToken token = {.z = name}; token.n = tSQLGetToken(name, &token.type); if (token.type != TK_STRING && token.type != TK_ID) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (token.type == TK_STRING) { @@ -4681,13 +4681,13 @@ int32_t validateColumnName(char* name) { int32_t k = tSQLGetToken(token.z, &token.type); if (k != token.n) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return validateColumnName(token.z); } else { if (isNumber(&token)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -4885,15 +4885,15 @@ int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) { setCreateDBOption(pMsg, pCreateDbSql); if (setKeepOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (setTimePrecision(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (tscCheckCreateDbParams(pCmd, pMsg) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; @@ -5324,7 +5324,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { } if (checkUpdateTagPrjFunctions(pQueryInfo) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } /* @@ -5332,7 +5332,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { * divide the subset of final result. */ if (doAddGroupbyColumnsOnDemand(pQueryInfo) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // projection query on super table does not compatible with "group by" syntax @@ -5527,7 +5527,7 @@ int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* p if (!validateTableColumnInfo(pFieldList, pCmd) || (pTagList != NULL && !validateTagParams(pTagList, pFieldList, pCmd))) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t col = 0; @@ -5676,22 +5676,22 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { bool isSTable = UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo); if (parseSelectClause(&pSql->cmd, 0, pQuerySql->pSelection, isSTable) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pQuerySql->pWhere != NULL) { // query condition in stream computing if (parseWhereClause(pQueryInfo, &pQuerySql->pWhere, pSql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } // set interval value if (parseIntervalClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } else { if ((pQueryInfo->intervalTime > 0) && (validateFunctionsInIntervalOrGroupbyQuery(pQueryInfo) != TSDB_CODE_SUCCESS)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -5705,13 +5705,13 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { } if (tsRewriteFieldNameIfNecessary(pQueryInfo) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutput; if (validateSqlFunctionInStreamSql(pQueryInfo) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } /* @@ -5832,26 +5832,26 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) { // parse the group by clause in the first place if (parseGroupbyClause(pQueryInfo, pQuerySql->pGroupby, pCmd) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (parseSelectClause(pCmd, index, pQuerySql->pSelection, isSTable) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // set interval value if (parseIntervalClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } else { if ((pQueryInfo->intervalTime > 0) && (validateFunctionsInIntervalOrGroupbyQuery(pQueryInfo) != TSDB_CODE_SUCCESS)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } // set order by info if (parseOrderbyClause(pQueryInfo, pQuerySql, tscGetTableSchema(pTableMetaInfo->pTableMeta)) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // set where info @@ -5859,7 +5859,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) { if (pQuerySql->pWhere != NULL) { if (parseWhereClause(pQueryInfo, &pQuerySql->pWhere, pSql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pQuerySql->pWhere = NULL; @@ -6008,7 +6008,7 @@ int32_t exprTreeFromSqlExpr(tExprNode **pExpr, const tSQLExpr* pSqlExpr, SArray* return TSDB_CODE_SUCCESS; } else { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else { @@ -6027,9 +6027,9 @@ int32_t exprTreeFromSqlExpr(tExprNode **pExpr, const tSQLExpr* pSqlExpr, SArray* if ((*pExpr)->_node.optr == TSDB_BINARY_OP_DIVIDE) { if (pRight->nodeType == TSQL_NODE_VALUE) { if (pRight->pVal->nType == TSDB_DATA_TYPE_INT && pRight->pVal->i64Key == 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } else if (pRight->pVal->nType == TSDB_DATA_TYPE_FLOAT && pRight->pVal->dKey == 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } } diff --git a/src/client/src/tscSecondaryMerge.c b/src/client/src/tscSecondaryMerge.c index 5737564877..5e6516f898 100644 --- a/src/client/src/tscSecondaryMerge.c +++ b/src/client/src/tscSecondaryMerge.c @@ -161,7 +161,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer); tscError("%p pMemBuffer is NULL", pMemBuffer); - pRes->code = TSDB_CODE_APP_ERROR; + pRes->code = TSDB_CODE_TSC_APP_ERROR; return; } @@ -169,7 +169,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer); tscError("%p no local buffer or intermediate result format model", pSql); - pRes->code = TSDB_CODE_APP_ERROR; + pRes->code = TSDB_CODE_TSC_APP_ERROR; return; } @@ -196,7 +196,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd pMemBuffer[0]->pageSize); tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer); - pRes->code = TSDB_CODE_APP_ERROR; + pRes->code = TSDB_CODE_TSC_APP_ERROR; return; } @@ -207,7 +207,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd tscError("%p failed to create local merge structure, out of memory", pSql); tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return; } @@ -229,7 +229,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd SLocalDataSource *ds = (SLocalDataSource *)malloc(sizeof(SLocalDataSource) + pMemBuffer[0]->pageSize); if (ds == NULL) { tscError("%p failed to create merge structure", pSql); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return; } @@ -326,7 +326,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd // tfree(pReducer->pBufForInterpo); tfree(pReducer->prevRowOfInput); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return; } @@ -560,7 +560,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm int32_t *orderIdx = (int32_t *)calloc(numOfGroupByCols, sizeof(int32_t)); if (orderIdx == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } if (numOfGroupByCols > 0) { @@ -581,7 +581,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm tfree(orderIdx); if (*pOrderDesc == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } else { return TSDB_CODE_SUCCESS; } @@ -641,7 +641,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr (*pMemBuffer) = (tExtMemBuffer **)malloc(POINTER_BYTES * pSql->numOfSubs); if (*pMemBuffer == NULL) { tscError("%p failed to allocate memory", pSql); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pRes->code; } @@ -650,7 +650,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr pSchema = (SSchema *)calloc(1, sizeof(SSchema) * size); if (pSchema == NULL) { tscError("%p failed to allocate memory", pSql); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pRes->code; } @@ -678,7 +678,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr } if (createOrderDescriptor(pOrderDesc, pCmd, pModel) != TSDB_CODE_SUCCESS) { - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pRes->code; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 3fe2dde307..a71a8eca5e 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -179,7 +179,7 @@ int tscSendMsgToServer(SSqlObj *pSql) { char *pMsg = rpcMallocCont(pCmd->payloadLen); if (NULL == pMsg) { tscError("%p msg:%s malloc fail", pSql, taosMsg[pSql->cmd.msgType]); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } if (pSql->cmd.command < TSDB_SQL_MGMT) { @@ -234,11 +234,11 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { } if (rpcMsg->pCont == NULL) { - rpcMsg->code = TSDB_CODE_NETWORK_UNAVAIL; + rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; } else { STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); - if (rpcMsg->code == TSDB_CODE_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_INVALID_VGROUP_ID || - rpcMsg->code == TSDB_CODE_NETWORK_UNAVAIL) { + if (rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID || + rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { /* * not_active_table: 1. the virtual node may fail to create table, since the procedure of create table is asynchronized, * the virtual node may have not create table till now, so try again by using the new metermeta. @@ -250,11 +250,11 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { * not_active_session: db has been move to other node, the vnode does not exist on this dnode anymore. */ if (pCmd->command == TSDB_SQL_CONNECT) { - rpcMsg->code = TSDB_CODE_NETWORK_UNAVAIL; + rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; rpcFreeCont(rpcMsg->pCont); return; } else if (pCmd->command == TSDB_SQL_HB) { - rpcMsg->code = TSDB_CODE_NOT_READY; + rpcMsg->code = TSDB_CODE_RPC_NOT_READY; rpcFreeCont(rpcMsg->pCont); return; } else if (pCmd->command == TSDB_SQL_META) { @@ -281,8 +281,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { pRes->rspLen = 0; - if (pRes->code != TSDB_CODE_QUERY_CANCELLED) { - pRes->code = (rpcMsg->code != TSDB_CODE_SUCCESS) ? rpcMsg->code : TSDB_CODE_NETWORK_UNAVAIL; + if (pRes->code != TSDB_CODE_TSC_QUERY_CANCELLED) { + pRes->code = (rpcMsg->code != TSDB_CODE_SUCCESS) ? rpcMsg->code : TSDB_CODE_RPC_NETWORK_UNAVAIL; } else { tscTrace("%p query is cancelled, code:%d", pSql, tstrerror(pRes->code)); } @@ -292,7 +292,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { pSql->retry = 0; } - if (pRes->code != TSDB_CODE_QUERY_CANCELLED) { + if (pRes->code != TSDB_CODE_TSC_QUERY_CANCELLED) { assert(rpcMsg->msgType == pCmd->msgType + 1); pRes->code = rpcMsg->code; pRes->rspType = rpcMsg->msgType; @@ -301,7 +301,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { if (pRes->rspLen > 0 && rpcMsg->pCont) { char *tmp = (char *)realloc(pRes->pRsp, pRes->rspLen); if (tmp == NULL) { - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; } else { pRes->pRsp = tmp; memcpy(pRes->pRsp, rpcMsg->pCont, pRes->rspLen); @@ -333,7 +333,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { if (pRes->code == TSDB_CODE_SUCCESS && tscProcessMsgRsp[pCmd->command]) rpcMsg->code = (*tscProcessMsgRsp[pCmd->command])(pSql); - if (rpcMsg->code != TSDB_CODE_ACTION_IN_PROGRESS) { + if (rpcMsg->code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) { rpcMsg->code = pRes->code ? pRes->code : pRes->numOfRows; tscTrace("%p SQL result:%s res:%p", pSql, tstrerror(pRes->code), pSql); @@ -402,7 +402,7 @@ int tscProcessSql(SSqlObj *pSql) { tscTrace("%p SQL cmd:%s will be processed, name:%s, type:%d", pSql, sqlCmd[pCmd->command], name, type); if (pCmd->command < TSDB_SQL_MGMT) { // the pTableMetaInfo cannot be NULL if (pTableMetaInfo == NULL) { - pSql->res.code = TSDB_CODE_OTHERS; + pSql->res.code = TSDB_CODE_TSC_APP_ERROR; return pSql->res.code; } } else if (pCmd->command < TSDB_SQL_LOCAL) { @@ -433,7 +433,7 @@ void tscKillSTableQuery(SSqlObj *pSql) { * here, we cannot set the command = TSDB_SQL_KILL_QUERY. Otherwise, it may cause * sub-queries not correctly released and master sql object of metric query reaches an abnormal state. */ - pSql->pSubs[i]->res.code = TSDB_CODE_QUERY_CANCELLED; + pSql->pSubs[i]->res.code = TSDB_CODE_TSC_QUERY_CANCELLED; //taosStopRpcConn(pSql->pSubs[i]->thandle); } @@ -678,7 +678,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex, pColSchema->name); - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pQueryMsg->colList[i].colId = htons(pColSchema->colId); @@ -796,7 +796,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, total, numOfTagColumns, pCol->colIndex, pColSchema->name); - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SColumnInfo* pTagCol = (SColumnInfo*) pMsg; @@ -886,7 +886,7 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pCmd->payloadLen = sizeof(SCMCreateDnodeMsg); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMCreateDnodeMsg *pCreate = (SCMCreateDnodeMsg *)pCmd->payload; @@ -902,7 +902,7 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pCmd->payloadLen = sizeof(SCMCreateAcctMsg); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMCreateAcctMsg *pAlterMsg = (SCMCreateAcctMsg *)pCmd->payload; @@ -948,7 +948,7 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMCreateUserMsg *pAlterMsg = (SCMCreateUserMsg*)pCmd->payload; @@ -987,7 +987,7 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMDropDbMsg *pDropDbMsg = (SCMDropDbMsg*)pCmd->payload; @@ -1006,7 +1006,7 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMDropTableMsg *pDropTableMsg = (SCMDropTableMsg*)pCmd->payload; @@ -1023,7 +1023,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pCmd->payloadLen = sizeof(SCMDropDnodeMsg); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMDropDnodeMsg *pDrop = (SCMDropDnodeMsg *)pCmd->payload; @@ -1041,7 +1041,7 @@ int32_t tscBuildDropUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload; @@ -1058,7 +1058,7 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload; @@ -1074,7 +1074,7 @@ int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMUseDbMsg *pUseDbMsg = (SCMUseDbMsg*)pCmd->payload; @@ -1093,7 +1093,7 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMShowMsg *pShowMsg = (SCMShowMsg*)pCmd->payload; @@ -1177,7 +1177,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { size = tscEstimateCreateTableMsgLength(pSql, pInfo); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { tscError("%p failed to malloc for create table msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -1322,7 +1322,7 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); @@ -1445,7 +1445,7 @@ int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMConnectMsg *pConnect = (SCMConnectMsg*)pCmd->payload; @@ -1470,7 +1470,7 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (len > 0) { tmpData = calloc(1, len); if (NULL == tmpData) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } // STagData is in binary format, strncpy is not available @@ -1792,17 +1792,17 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { if (pMetaMsg->sid < 0 || pMetaMsg->vgroup.numOfIps < 0) { tscError("invalid meter vgId:%d, sid%d", pMetaMsg->vgroup.numOfIps, pMetaMsg->sid); - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } if (pMetaMsg->numOfTags > TSDB_MAX_TAGS || pMetaMsg->numOfTags < 0) { tscError("invalid numOfTags:%d", pMetaMsg->numOfTags); - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } if (pMetaMsg->numOfColumns > TSDB_MAX_COLUMNS || pMetaMsg->numOfColumns <= 0) { tscError("invalid numOfColumns:%d", pMetaMsg->numOfColumns); - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } for (int i = 0; i < pMetaMsg->vgroup.numOfIps; ++i) { @@ -1832,7 +1832,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { // todo handle out of memory case if (pTableMetaInfo->pTableMeta == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } tscTrace("%p recv table meta: %"PRId64 ", tid:%d, name:%s", pSql, pTableMeta->uid, pTableMeta->sid, pTableMetaInfo->name); @@ -1853,9 +1853,9 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) { ieType = *rsp; if (ieType != TSDB_IE_TYPE_META) { tscError("invalid ie type:%d", ieType); - pSql->res.code = TSDB_CODE_INVALID_IE; + pSql->res.code = TSDB_CODE_TSC_INVALID_IE; pSql->res.numOfTotal = 0; - return TSDB_CODE_OTHERS; + return TSDB_CODE_TSC_APP_ERROR; } rsp++; @@ -1875,32 +1875,32 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) { if (pMeta->sid <= 0 || pMeta->vgId < 0) { tscError("invalid meter vgId:%d, sid%d", pMeta->vgId, pMeta->sid); - pSql->res.code = TSDB_CODE_INVALID_VALUE; + pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE; pSql->res.numOfTotal = i; - return TSDB_CODE_OTHERS; + return TSDB_CODE_TSC_APP_ERROR; } // pMeta->numOfColumns = htons(pMeta->numOfColumns); // // if (pMeta->numOfTags > TSDB_MAX_TAGS || pMeta->numOfTags < 0) { // tscError("invalid tag value count:%d", pMeta->numOfTags); - // pSql->res.code = TSDB_CODE_INVALID_VALUE; + // pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE; // pSql->res.numOfTotal = i; - // return TSDB_CODE_OTHERS; + // return TSDB_CODE_TSC_APP_ERROR; // } // // if (pMeta->numOfTags > TSDB_MAX_TAGS || pMeta->numOfTags < 0) { // tscError("invalid numOfTags:%d", pMeta->numOfTags); - // pSql->res.code = TSDB_CODE_INVALID_VALUE; + // pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE; // pSql->res.numOfTotal = i; - // return TSDB_CODE_OTHERS; + // return TSDB_CODE_TSC_APP_ERROR; // } // // if (pMeta->numOfColumns > TSDB_MAX_COLUMNS || pMeta->numOfColumns < 0) { // tscError("invalid numOfColumns:%d", pMeta->numOfColumns); - // pSql->res.code = TSDB_CODE_INVALID_VALUE; + // pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE; // pSql->res.numOfTotal = i; - // return TSDB_CODE_OTHERS; + // return TSDB_CODE_TSC_APP_ERROR; // } // // for (int j = 0; j < TSDB_REPLICA_MAX_NUM; ++j) { @@ -1965,7 +1965,7 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) { if (metricMetaList == NULL || sizes == NULL) { tfree(metricMetaList); tfree(sizes); - pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pSql->res.code; } @@ -1984,7 +1984,7 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) { char *pBuf = calloc(1, size); if (pBuf == NULL) { - pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error_clean; } @@ -2044,7 +2044,7 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) { // failed to put into cache if (pTableMetaInfo->pMetricMeta == NULL) { - pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error_clean; } } @@ -2338,7 +2338,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf SSqlObj *pNew = calloc(1, sizeof(SSqlObj)); if (NULL == pNew) { tscError("%p malloc failed for new sqlobj to get table meta", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } pNew->pTscObj = pSql->pTscObj; @@ -2355,7 +2355,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf tscError("%p malloc failed for payload to get table meta", pSql); free(pNew); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } STableMetaInfo *pNewMeterMetaInfo = tscAddEmptyMetaInfo(pNewQueryInfo); @@ -2371,7 +2371,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf int32_t code = tscProcessSql(pNew); if (code == TSDB_CODE_SUCCESS) { - code = TSDB_CODE_ACTION_IN_PROGRESS; + code = TSDB_CODE_TSC_ACTION_IN_PROGRESS; } return code; @@ -2468,7 +2468,7 @@ static bool allVgroupInfoRetrieved(SSqlCmd* pCmd, int32_t clauseIndex) { } int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) { - int code = TSDB_CODE_NETWORK_UNAVAIL; + int code = TSDB_CODE_RPC_NETWORK_UNAVAIL; SSqlCmd *pCmd = &pSql->cmd; if (allVgroupInfoRetrieved(pCmd, clauseIndex)) { @@ -2505,7 +2505,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) { pNew->param = pSql; code = tscProcessSql(pNew); if (code == TSDB_CODE_SUCCESS) { - code = TSDB_CODE_ACTION_IN_PROGRESS; + code = TSDB_CODE_TSC_ACTION_IN_PROGRESS; } return code; diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 5ff417f7d5..2a861ab533 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -57,12 +57,12 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con taos_init(); if (!validUserName(user)) { - terrno = TSDB_CODE_INVALID_ACCT; + terrno = TSDB_CODE_TSC_INVALID_USER_LENGTH; return NULL; } if (!validPassword(pass)) { - terrno = TSDB_CODE_INVALID_PASS; + terrno = TSDB_CODE_TSC_INVALID_PASS_LENGTH; return NULL; } @@ -73,13 +73,13 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con void *pDnodeConn = NULL; if (tscInitRpc(user, pass, &pDnodeConn) != 0) { - terrno = TSDB_CODE_NETWORK_UNAVAIL; + terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL; return NULL; } STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj)); if (NULL == pObj) { - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; rpcClose(pDnodeConn); return NULL; } @@ -94,7 +94,7 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con int32_t len = strlen(db); /* db name is too long */ if (len > TSDB_DB_NAME_LEN) { - terrno = TSDB_CODE_INVALID_DB; + terrno = TSDB_CODE_TSC_INVALID_DB_LENGTH; rpcClose(pDnodeConn); free(pObj); return NULL; @@ -111,7 +111,7 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); if (NULL == pSql) { - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; rpcClose(pDnodeConn); free(pObj); return NULL; @@ -132,7 +132,7 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con pSql->cmd.command = TSDB_SQL_CONNECT; if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; rpcClose(pDnodeConn); free(pSql); free(pObj); @@ -265,14 +265,14 @@ void waitForQueryRsp(void *param, TAOS_RES *tres, int code) { TAOS_RES* taos_query(TAOS *taos, const char *sqlstr) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { - terrno = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; return NULL; } int32_t sqlLen = strlen(sqlstr); if (sqlLen > tsMaxSQLStringLen) { tscError("sql string exceeds max length:%d", tsMaxSQLStringLen); - terrno = TSDB_CODE_INVALID_SQL; + terrno = TSDB_CODE_TSC_INVALID_SQL; return NULL; } @@ -281,7 +281,7 @@ TAOS_RES* taos_query(TAOS *taos, const char *sqlstr) { SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { tscError("failed to malloc sqlObj"); - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return NULL; } @@ -424,7 +424,7 @@ static void waitForRetrieveRsp(void *param, TAOS_RES *tres, int numOfRows) { TAOS_ROW taos_fetch_row(TAOS_RES *res) { SSqlObj *pSql = (SSqlObj *)res; if (pSql == NULL || pSql->signature != pSql) { - terrno = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; return NULL; } @@ -462,7 +462,7 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { int nRows = 0; if (pSql == NULL || pSql->signature != pSql) { - terrno = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; *rows = NULL; return 0; } @@ -505,8 +505,8 @@ int taos_select_db(TAOS *taos, const char *db) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { - terrno = TSDB_CODE_DISCONNECTED; - return TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; + return TSDB_CODE_TSC_DISCONNECTED; } snprintf(sql, tListLen(sql), "use %s", db); @@ -587,7 +587,7 @@ int taos_errno(TAOS_RES *tres) { * why the sql is invalid */ static bool hasAdditionalErrorInfo(int32_t code, SSqlCmd *pCmd) { - if (code != TSDB_CODE_INVALID_SQL) { + if (code != TSDB_CODE_TSC_INVALID_SQL) { return false; } @@ -649,7 +649,7 @@ void taos_stop_query(TAOS_RES *res) { if (pSql->signature != pSql) return; tscTrace("%p start to cancel query", res); - pSql->res.code = TSDB_CODE_QUERY_CANCELLED; + pSql->res.code = TSDB_CODE_TSC_QUERY_CANCELLED; SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) { @@ -734,8 +734,8 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) int taos_validate_sql(TAOS *taos, const char *sql) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { - terrno = TSDB_CODE_DISCONNECTED; - return TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; + return TSDB_CODE_TSC_DISCONNECTED; } SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); @@ -752,13 +752,13 @@ int taos_validate_sql(TAOS *taos, const char *sql) { int32_t sqlLen = strlen(sql); if (sqlLen > tsMaxSQLStringLen) { tscError("%p sql too long", pSql); - pRes->code = TSDB_CODE_INVALID_SQL; + pRes->code = TSDB_CODE_TSC_INVALID_SQL; return pRes->code; } pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1); if (pSql->sqlstr == NULL) { - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("%p failed to malloc sql string buffer", pSql); tscTrace("%p Valid SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj); return pRes->code; @@ -790,7 +790,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t pCmd->command = TSDB_SQL_MULTI_META; pCmd->count = 0; - int code = TSDB_CODE_INVALID_TABLE_ID; + int code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; char *str = (char *)tblNameList; SQueryInfo *pQueryInfo = NULL; @@ -824,7 +824,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t // Check if the table name available or not if (tscValidateName(&sToken) != TSDB_CODE_SUCCESS) { - code = TSDB_CODE_INVALID_TABLE_ID; + code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; sprintf(pCmd->payload, "table name is invalid"); return code; } @@ -834,7 +834,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t } if (++pCmd->count > TSDB_MULTI_METERMETA_MAX_NUM) { - code = TSDB_CODE_INVALID_TABLE_ID; + code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; sprintf(pCmd->payload, "tables over the max number"); return code; } @@ -842,7 +842,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t if (payloadLen + strlen(pTableMetaInfo->name) + 128 >= pCmd->allocSize) { char *pNewMem = realloc(pCmd->payload, pCmd->allocSize + tblListLen); if (pNewMem == NULL) { - code = TSDB_CODE_CLI_OUT_OF_MEMORY; + code = TSDB_CODE_TSC_OUT_OF_MEMORY; sprintf(pCmd->payload, "failed to allocate memory"); return code; } @@ -866,8 +866,8 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { - terrno = TSDB_CODE_DISCONNECTED; - return TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; + return TSDB_CODE_TSC_DISCONNECTED; } SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); @@ -884,13 +884,13 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { int32_t tblListLen = strlen(tableNameList); if (tblListLen > MAX_TABLE_NAME_LENGTH) { tscError("%p tableNameList too long, length:%d, maximum allowed:%d", pSql, tblListLen, MAX_TABLE_NAME_LENGTH); - pRes->code = TSDB_CODE_INVALID_SQL; + pRes->code = TSDB_CODE_TSC_INVALID_SQL; return pRes->code; } char *str = calloc(1, tblListLen + 1); if (str == NULL) { - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("%p failed to malloc sql string buffer", pSql); return pRes->code; } diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 9e1628bb9b..4e92e9dd70 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -77,13 +77,13 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) { int code = tscGetTableMeta(pSql, pTableMetaInfo); pSql->res.code = code; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; if (code == 0 && UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { code = tscGetSTableVgroupInfo(pSql, 0); pSql->res.code = code; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; } tscTansformSQLFuncForSTableQuery(pQueryInfo); @@ -480,7 +480,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { - setErrorInfo(pSql, TSDB_CODE_CLI_OUT_OF_MEMORY, NULL); + setErrorInfo(pSql, TSDB_CODE_TSC_OUT_OF_MEMORY, NULL); return NULL; } @@ -497,7 +497,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p pSql->sqlstr = strdup(sqlstr); if (pSql->sqlstr == NULL) { - setErrorInfo(pSql, TSDB_CODE_CLI_OUT_OF_MEMORY, NULL); + setErrorInfo(pSql, TSDB_CODE_TSC_OUT_OF_MEMORY, NULL); tfree(pSql); return NULL; @@ -512,7 +512,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p ret = tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE); if (TSDB_CODE_SUCCESS != ret) { setErrorInfo(pSql, ret, NULL); - tscError("%p open stream failed, sql:%s, code:%d", pSql, sqlstr, TSDB_CODE_CLI_OUT_OF_MEMORY); + tscError("%p open stream failed, sql:%s, code:%d", pSql, sqlstr, TSDB_CODE_TSC_OUT_OF_MEMORY); tscFreeSqlObj(pSql); return NULL; } @@ -530,7 +530,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p SSqlStream *pStream = (SSqlStream *)calloc(1, sizeof(SSqlStream)); if (pStream == NULL) { - setErrorInfo(pSql, TSDB_CODE_CLI_OUT_OF_MEMORY, NULL); + setErrorInfo(pSql, TSDB_CODE_TSC_OUT_OF_MEMORY, NULL); tscError("%p open stream failed, sql:%s, reason:%s, code:%d", pSql, sqlstr, pCmd->payload, pRes->code); tscFreeSqlObj(pSql); diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index f6cbe4a42e..9baf49ff21 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -124,7 +124,7 @@ static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* strtolower(pSql->sqlstr, pSql->sqlstr); code = tsParseSql(pSql, false); - if (code == TSDB_CODE_ACTION_IN_PROGRESS) { + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { // wait for the callback function to post the semaphore sem_wait(&pSql->rspSem); code = pSql->res.code; @@ -148,7 +148,7 @@ static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* pSub->topic[sizeof(pSub->topic) - 1] = 0; pSub->progress = taosArrayInit(32, sizeof(SSubscriptionProgress)); if (pSub->progress == NULL) { - THROW(TSDB_CODE_CLI_OUT_OF_MEMORY); + THROW(TSDB_CODE_TSC_OUT_OF_MEMORY); } CLEANUP_EXECUTE(); @@ -324,7 +324,7 @@ void tscSaveSubscriptionProgress(void* sub) { TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) { STscObj* pObj = (STscObj*)taos; if (pObj == NULL || pObj->signature != pObj) { - terrno = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; tscError("connection disconnected"); return NULL; } diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 1fdbd43408..2aad3eafc1 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -348,7 +348,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { //prepare the subqueries object failed, abort if (!success) { - pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("%p failed to prepare subqueries objs for secondary phase query, numOfSub:%d, code:%d", pSql, pSql->numOfSubs, pSql->res.code); freeJoinSubqueryObj(pSql); @@ -698,7 +698,7 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { if (pBuf == NULL) { tscError("%p invalid ts comp file from vnode, abort subquery, file size:%d", pSql, numOfRows); - pSupporter->pState->code = TSDB_CODE_APP_ERROR; // todo set the informative code + pSupporter->pState->code = TSDB_CODE_TSC_APP_ERROR; // todo set the informative code quitAllSubquery(pParentSql, pSupporter); return; } @@ -1019,13 +1019,13 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter if (pSql->pSubs == NULL) { pSql->pSubs = calloc(pSupporter->pState->numOfTotal, POINTER_BYTES); if (pSql->pSubs == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } } SSqlObj *pNew = createSubqueryObj(pSql, tableIndex, tscJoinQueryCallback, pSupporter, TSDB_SQL_SELECT, NULL); if (pNew == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } pSql->pSubs[pSql->numOfSubs++] = pNew; @@ -1163,7 +1163,7 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) { if (pSupporter == NULL) { // failed to create support struct, abort current query tscError("%p tableIndex:%d, failed to allocate join support object, abort further query", pSql, i); pState->numOfCompleted = pQueryInfo->numOfTables - i - 1; - pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pSql->res.code; } @@ -1171,7 +1171,7 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) { int32_t code = tscLaunchJoinSubquery(pSql, i, pSupporter); if (code != TSDB_CODE_SUCCESS) { // failed to create subquery object, quit query tscDestroyJoinSupporter(pSupporter); - pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; break; } @@ -1209,7 +1209,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { SSqlCmd *pCmd = &pSql->cmd; // pRes->code check only serves in launching metric sub-queries - if (pRes->code == TSDB_CODE_QUERY_CANCELLED) { + if (pRes->code == TSDB_CODE_TSC_QUERY_CANCELLED) { pCmd->command = TSDB_SQL_RETRIEVE_LOCALMERGE; // enable the abort of kill super table function. return pRes->code; } @@ -1230,7 +1230,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { int32_t ret = tscLocalReducerEnvCreate(pSql, &pMemoryBuf, &pDesc, &pModel, nBufferSize); if (ret != 0) { - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscQueueAsyncRes(pSql); return ret; } @@ -1291,14 +1291,14 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { if (i < pSql->numOfSubs) { tscError("%p failed to prepare subquery structure and launch subqueries", pSql); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscLocalReducerEnvDestroy(pMemoryBuf, pDesc, pModel, pSql->numOfSubs); doCleanupSubqueries(pSql, i, pState); return pRes->code; // free all allocated resource } - if (pRes->code == TSDB_CODE_QUERY_CANCELLED) { + if (pRes->code == TSDB_CODE_TSC_QUERY_CANCELLED) { tscLocalReducerEnvDestroy(pMemoryBuf, pDesc, pModel, pSql->numOfSubs); doCleanupSubqueries(pSql, i, pState); return pRes->code; @@ -1369,7 +1369,7 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO /* * kill current sub-query connection, which may retrieve data from vnodes; - * Here we get: pPObj->res.code == TSDB_CODE_QUERY_CANCELLED + * Here we get: pPObj->res.code == TSDB_CODE_TSC_QUERY_CANCELLED */ pSql->res.numOfRows = 0; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; // disable retry efforts @@ -1401,7 +1401,7 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO tscError("%p sub:%p failed to create new subquery sqlObj due to out of memory, abort retry", trsupport->pParentSqlObj, pSql); - pState->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pState->code = TSDB_CODE_TSC_OUT_OF_MEMORY; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; return; } @@ -1475,7 +1475,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p if (tsTotalTmpDirGB != 0 && tsAvailTmpDirGB < tsMinimalTmpDirGB) { tscError("%p sub:%p client disk space remain %.3f GB, need at least %.3f GB, stop query", pPObj, pSql, tsAvailTmpDirGB, tsMinimalTmpDirGB); - tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_CLI_NO_DISKSPACE); + tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_TSC_NO_DISKSPACE); return; } @@ -1484,7 +1484,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p int32_t ret = tscFlushTmpBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pQueryInfo->groupbyExpr.orderType); if (ret != 0) { // set no disk space error info, and abort retry - return tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_CLI_NO_DISKSPACE); + return tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_TSC_NO_DISKSPACE); } // keep this value local variable, since the pState variable may be released by other threads, if atomic_add opertion @@ -1563,7 +1563,7 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR if (num > tsMaxNumOfOrderedResults && tscIsProjectionQueryOnSTable(pQueryInfo, 0)) { tscError("%p sub:%p num of OrderedRes is too many, max allowed:%" PRId64 " , current:%" PRId64, pPObj, pSql, tsMaxNumOfOrderedResults, num); - tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_SORTED_RES_TOO_MANY); + tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_SORTED_RES_TOO_MANY); return; } @@ -1578,14 +1578,14 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR if (tsTotalTmpDirGB != 0 && tsAvailTmpDirGB < tsMinimalTmpDirGB) { tscError("%p sub:%p client disk space remain %.3f GB, need at least %.3f GB, stop query", pPObj, pSql, tsAvailTmpDirGB, tsMinimalTmpDirGB); - tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE); + tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_NO_DISKSPACE); return; } int32_t ret = saveToBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pRes->data, pRes->numOfRows, pQueryInfo->groupbyExpr.orderType); if (ret < 0) { // set no disk space error info, and abort retry - tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE); + tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_NO_DISKSPACE); } else if (pRes->completed) { tscAllDataRetrievedFromDnode(trsupport, pSql); @@ -1672,7 +1672,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) { tscError("%p sub:%p failed to create new subquery due to out of memory, abort retry, vgId:%d, orderOfSub:%d", trsupport->pParentSqlObj, pSql, pVgroup->vgId, trsupport->subqueryIndex); - pState->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pState->code = TSDB_CODE_TSC_OUT_OF_MEMORY; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; } else { SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0); @@ -1778,7 +1778,7 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { if (i < pSql->numOfSubs) { tscError("%p failed to prepare subObj structure and launch sub-insertion", pSql); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pRes->code; // free all allocated resource } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 4c158ac77a..56dcc37e25 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -299,7 +299,7 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) { tfree(pRes->buffer); tfree(pRes->length); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pRes->code; } } @@ -576,7 +576,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff STableDataBlocks* dataBuf = (STableDataBlocks*)calloc(1, sizeof(STableDataBlocks)); if (dataBuf == NULL) { tscError("failed to allocated memory, reason:%s", strerror(errno)); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } dataBuf->nAllocSize = (uint32_t)initialSize; @@ -711,7 +711,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi tscDestroyBlockArrayList(pVnodeDataBlockList); tfree(dataBuf->pData); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } } @@ -782,12 +782,12 @@ int tscAllocPayload(SSqlCmd* pCmd, int size) { assert(pCmd->allocSize == 0); pCmd->payload = (char*)calloc(1, size); - if (pCmd->payload == NULL) return TSDB_CODE_CLI_OUT_OF_MEMORY; + if (pCmd->payload == NULL) return TSDB_CODE_TSC_OUT_OF_MEMORY; pCmd->allocSize = size; } else { if (pCmd->allocSize < size) { char* b = realloc(pCmd->payload, size); - if (b == NULL) return TSDB_CODE_CLI_OUT_OF_MEMORY; + if (b == NULL) return TSDB_CODE_TSC_OUT_OF_MEMORY; pCmd->payload = b; pCmd->allocSize = size; } @@ -1242,14 +1242,14 @@ static int32_t validateQuoteToken(SSQLToken* pToken) { } if (k != pToken->n || pToken->type != TK_ID) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; } int32_t tscValidateName(SSQLToken* pToken) { if (pToken->type != TK_STRING && pToken->type != TK_ID) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } char* sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true); @@ -1266,14 +1266,14 @@ int32_t tscValidateName(SSQLToken* pToken) { } else { sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true); if (sep == NULL) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return tscValidateName(pToken); } } else { if (isNumber(pToken)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } } else { // two part @@ -1286,15 +1286,15 @@ int32_t tscValidateName(SSQLToken* pToken) { pToken->n = tSQLGetToken(pToken->z, &pToken->type); if (pToken->z[pToken->n] != TS_PATH_DELIMITER[0]) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pToken->type != TK_STRING && pToken->type != TK_ID) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pToken->type == TK_STRING && validateQuoteToken(pToken) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t firstPartLen = pToken->n; @@ -1303,11 +1303,11 @@ int32_t tscValidateName(SSQLToken* pToken) { pToken->n = oldLen - (sep - pStr) - 1; int32_t len = tSQLGetToken(pToken->z, &pToken->type); if (len != pToken->n || (pToken->type != TK_STRING && pToken->type != TK_ID)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pToken->type == TK_STRING && validateQuoteToken(pToken) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // re-build the whole name string @@ -1576,7 +1576,7 @@ int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) { size_t s = pCmd->numOfClause + 1; char* tmp = realloc(pCmd->pQueryInfo, s * POINTER_BYTES); if (tmp == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } pCmd->pQueryInfo = (SQueryInfo**)tmp; @@ -1944,8 +1944,8 @@ int16_t tscGetJoinTagColIndexByUid(STagCond* pTagCond, uint64_t uid) { bool tscIsUpdateQuery(SSqlObj* pSql) { if (pSql == NULL || pSql->signature != pSql) { - terrno = TSDB_CODE_DISCONNECTED; - return TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; + return TSDB_CODE_TSC_DISCONNECTED; } SSqlCmd* pCmd = &pSql->cmd; @@ -1962,7 +1962,7 @@ int32_t tscInvalidSQLErrMsg(char* msg, const char* additionalInfo, const char* s if (sql == NULL) { assert(additionalInfo != NULL); sprintf(msg, msgFormat1, additionalInfo); - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } char buf[64] = {0}; // only extract part of sql string @@ -1974,7 +1974,7 @@ int32_t tscInvalidSQLErrMsg(char* msg, const char* additionalInfo, const char* s sprintf(msg, msgFormat3, buf); // no additional information for invalid sql error } - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } bool tscHasReachLimitation(SQueryInfo* pQueryInfo, SSqlRes* pRes) { @@ -2143,7 +2143,7 @@ void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pFieldInfo, int32_t column void* malloc_throw(size_t size) { void* p = malloc(size); if (p == NULL) { - THROW(TSDB_CODE_CLI_OUT_OF_MEMORY); + THROW(TSDB_CODE_TSC_OUT_OF_MEMORY); } return p; } @@ -2151,7 +2151,7 @@ void* malloc_throw(size_t size) { void* calloc_throw(size_t nmemb, size_t size) { void* p = calloc(nmemb, size); if (p == NULL) { - THROW(TSDB_CODE_CLI_OUT_OF_MEMORY); + THROW(TSDB_CODE_TSC_OUT_OF_MEMORY); } return p; } @@ -2159,7 +2159,7 @@ void* calloc_throw(size_t nmemb, size_t size) { char* strdup_throw(const char* str) { char* p = strdup(str); if (p == NULL) { - THROW(TSDB_CODE_CLI_OUT_OF_MEMORY); + THROW(TSDB_CODE_TSC_OUT_OF_MEMORY); } return p; } @@ -2170,7 +2170,7 @@ int tscSetMgmtIpListFromCfg(const char *first, const char *second) { if (first && first[0] != 0) { if (strlen(first) >= TSDB_EP_LEN) { - terrno = TSDB_CODE_INVALID_FQDN; + terrno = TSDB_CODE_TSC_INVALID_FQDN; return -1; } taosGetFqdnPortFromEp(first, tscMgmtIpSet.fqdn[tscMgmtIpSet.numOfIps], &tscMgmtIpSet.port[tscMgmtIpSet.numOfIps]); @@ -2179,7 +2179,7 @@ int tscSetMgmtIpListFromCfg(const char *first, const char *second) { if (second && second[0] != 0) { if (strlen(second) >= TSDB_EP_LEN) { - terrno = TSDB_CODE_INVALID_FQDN; + terrno = TSDB_CODE_TSC_INVALID_FQDN; return -1; } taosGetFqdnPortFromEp(second, tscMgmtIpSet.fqdn[tscMgmtIpSet.numOfIps], &tscMgmtIpSet.port[tscMgmtIpSet.numOfIps]); @@ -2187,7 +2187,7 @@ int tscSetMgmtIpListFromCfg(const char *first, const char *second) { } if ( tscMgmtIpSet.numOfIps == 0) { - terrno = TSDB_CODE_INVALID_FQDN; + terrno = TSDB_CODE_TSC_INVALID_FQDN; return -1; } diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 673ba2a6f5..ed1ee3d3d7 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -234,7 +234,7 @@ bool taosCfgDynamicOptions(char *msg) { int32_t vint = 0; paGetToken(msg, &option, &olen); - if (olen == 0) return TSDB_CODE_INVALID_MSG_CONTENT; + if (olen == 0) return TSDB_CODE_COM_INVALID_CFG_MSG; paGetToken(option + olen + 1, &value, &vlen); if (vlen == 0) diff --git a/src/dnode/src/dnodeMPeer.c b/src/dnode/src/dnodeMPeer.c index e3ba5fcf01..71c2d0e65f 100644 --- a/src/dnode/src/dnodeMPeer.c +++ b/src/dnode/src/dnodeMPeer.c @@ -79,7 +79,7 @@ void dnodeCleanupMnodePeer() { int32_t dnodeAllocateMnodePqueue() { tsMPeerQueue = taosOpenQueue(); - if (tsMPeerQueue == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (tsMPeerQueue == NULL) return TSDB_CODE_DND_OUT_OF_MEMORY; taosAddIntoQset(tsMPeerQset, tsMPeerQueue, NULL); @@ -125,7 +125,7 @@ static void dnodeFreeMnodePeerMsg(SMnodeMsg *pPeer) { } static void dnodeSendRpcMnodePeerRsp(SMnodeMsg *pPeer, int32_t code) { - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return; SRpcMsg rpcRsp = { .handle = pPeer->rpcMsg.handle, diff --git a/src/dnode/src/dnodeMRead.c b/src/dnode/src/dnodeMRead.c index f22346b61c..cb02ffbb1d 100644 --- a/src/dnode/src/dnodeMRead.c +++ b/src/dnode/src/dnodeMRead.c @@ -84,7 +84,7 @@ void dnodeCleanupMnodeRead() { int32_t dnodeAllocateMnodeRqueue() { tsMReadQueue = taosOpenQueue(); - if (tsMReadQueue == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (tsMReadQueue == NULL) return TSDB_CODE_DND_OUT_OF_MEMORY; taosAddIntoQset(tsMReadQset, tsMReadQueue, NULL); @@ -130,8 +130,8 @@ static void dnodeFreeMnodeReadMsg(SMnodeMsg *pRead) { } static void dnodeSendRpcMnodeReadRsp(SMnodeMsg *pRead, int32_t code) { - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; - if (code == TSDB_CODE_ACTION_NEED_REPROCESSED) { + if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_MND_ACTION_NEED_REPROCESSED) { // may be a auto create req, should put into write queue dnodeReprocessMnodeWriteMsg(pRead); return; diff --git a/src/dnode/src/dnodeMWrite.c b/src/dnode/src/dnodeMWrite.c index 95fa9f0bdd..eb9d8653e5 100644 --- a/src/dnode/src/dnodeMWrite.c +++ b/src/dnode/src/dnodeMWrite.c @@ -81,7 +81,7 @@ void dnodeCleanupMnodeWrite() { int32_t dnodeAllocateMnodeWqueue() { tsMWriteQueue = taosOpenQueue(); - if (tsMWriteQueue == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (tsMWriteQueue == NULL) return TSDB_CODE_DND_OUT_OF_MEMORY; taosAddIntoQset(tsMWriteQset, tsMWriteQueue, NULL); @@ -128,8 +128,8 @@ static void dnodeFreeMnodeWriteMsg(SMnodeMsg *pWrite) { void dnodeSendRpcMnodeWriteRsp(void *pRaw, int32_t code) { SMnodeMsg *pWrite = pRaw; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; - if (code == TSDB_CODE_ACTION_NEED_REPROCESSED) { + if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_MND_ACTION_NEED_REPROCESSED) { dnodeReprocessMnodeWriteMsg(pWrite); return; } diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index 7c457defca..69e91fd4ee 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -180,7 +180,7 @@ void dnodeDispatchToMgmtQueue(SRpcMsg *pMsg) { SRpcMsg rsp; rsp.handle = pMsg->handle; rsp.pCont = NULL; - rsp.code = TSDB_CODE_SERV_OUT_OF_MEMORY; + rsp.code = TSDB_CODE_DND_OUT_OF_MEMORY; rpcSendResponse(&rsp); rpcFreeCont(pMsg->pCont); } @@ -202,7 +202,7 @@ static void *dnodeProcessMgmtQueue(void *param) { if (dnodeProcessMgmtMsgFp[pMsg->msgType]) { rsp.code = (*dnodeProcessMgmtMsgFp[pMsg->msgType])(pMsg); } else { - rsp.code = TSDB_CODE_MSG_NOT_PROCESSED; + rsp.code = TSDB_CODE_DND_MSG_NOT_PROCESSED; } rsp.handle = pMsg->handle; @@ -219,7 +219,7 @@ static void *dnodeProcessMgmtQueue(void *param) { static int32_t dnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) { DIR *dir = opendir(tsVnodeDir); if (dir == NULL) { - return TSDB_CODE_NO_WRITE_ACCESS; + return TSDB_CODE_DND_NO_WRITE_ACCESS; } *numOfVnodes = 0; diff --git a/src/dnode/src/dnodePeer.c b/src/dnode/src/dnodePeer.c index ea3af08d71..734a2b6aeb 100644 --- a/src/dnode/src/dnodePeer.c +++ b/src/dnode/src/dnodePeer.c @@ -89,7 +89,7 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { rspMsg.contLen = 0; if (dnodeGetRunStatus() != TSDB_DNODE_RUN_STATUS_RUNING) { - rspMsg.code = TSDB_CODE_NOT_READY; + rspMsg.code = TSDB_CODE_RPC_NOT_READY; rpcSendResponse(&rspMsg); rpcFreeCont(pMsg->pCont); dTrace("RPC %p, msg:%s is ignored since dnode not running", pMsg->handle, taosMsg[pMsg->msgType]); @@ -97,7 +97,7 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { } if (pMsg->pCont == NULL) { - rspMsg.code = TSDB_CODE_INVALID_MSG_LEN; + rspMsg.code = TSDB_CODE_DND_INVALID_MSG_LEN; rpcSendResponse(&rspMsg); return; } @@ -106,7 +106,7 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { (*dnodeProcessReqMsgFp[pMsg->msgType])(pMsg); } else { dTrace("RPC %p, message:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]); - rspMsg.code = TSDB_CODE_MSG_NOT_PROCESSED; + rspMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED; rpcSendResponse(&rspMsg); rpcFreeCont(pMsg->pCont); } diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index 074f21f972..8eba1f3775 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -115,7 +115,7 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { if (dnodeGetRunStatus() != TSDB_DNODE_RUN_STATUS_RUNING) { dError("RPC %p, shell msg:%s is ignored since dnode not running", pMsg->handle, taosMsg[pMsg->msgType]); - rpcMsg.code = TSDB_CODE_NOT_READY; + rpcMsg.code = TSDB_CODE_RPC_NOT_READY; rpcSendResponse(&rpcMsg); rpcFreeCont(pMsg->pCont); return; @@ -131,7 +131,7 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { (*dnodeProcessShellMsgFp[pMsg->msgType])(pMsg); } else { dError("RPC %p, shell msg:%s is not processed", pMsg->handle, taosMsg[pMsg->msgType]); - rpcMsg.code = TSDB_CODE_MSG_NOT_PROCESSED; + rpcMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED; rpcSendResponse(&rpcMsg); rpcFreeCont(pMsg->pCont); return; @@ -140,7 +140,7 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey) { int code = mnodeRetriveAuth(user, spi, encrypt, secret, ckey); - if (code != TSDB_CODE_NOT_READY) return code; + if (code != TSDB_CODE_RPC_NOT_READY) return code; SDMAuthMsg *pMsg = rpcMallocCont(sizeof(SDMAuthMsg)); strcpy(pMsg->user, user); diff --git a/src/dnode/src/dnodeVRead.c b/src/dnode/src/dnodeVRead.c index 72882b679b..7f1a5b2580 100644 --- a/src/dnode/src/dnodeVRead.c +++ b/src/dnode/src/dnodeVRead.c @@ -134,7 +134,7 @@ void dnodeDispatchToVnodeReadQueue(SRpcMsg *pMsg) { .handle = pMsg->handle, .pCont = NULL, .contLen = 0, - .code = TSDB_CODE_INVALID_VGROUP_ID, + .code = TSDB_CODE_VND_INVALID_VGROUP_ID, .msgType = 0 }; rpcSendResponse(&rpcRsp); @@ -189,8 +189,8 @@ static void dnodeContinueExecuteQuery(void* pVnode, void* qhandle, SReadMsg *pMs } void dnodeSendRpcReadRsp(void *pVnode, SReadMsg *pRead, int32_t code) { - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; - if (code == TSDB_CODE_ACTION_NEED_REPROCESSED) { + if (code == TSDB_CODE_VND_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_VND_ACTION_NEED_REPROCESSED) { dnodeContinueExecuteQuery(pVnode, pRead->rspRet.qhandle, pRead); } diff --git a/src/dnode/src/dnodeVWrite.c b/src/dnode/src/dnodeVWrite.c index 4b26c05649..53533b8183 100644 --- a/src/dnode/src/dnodeVWrite.c +++ b/src/dnode/src/dnodeVWrite.c @@ -115,7 +115,7 @@ void dnodeDispatchToVnodeWriteQueue(SRpcMsg *pMsg) { .handle = pMsg->handle, .pCont = NULL, .contLen = 0, - .code = TSDB_CODE_INVALID_VGROUP_ID, + .code = TSDB_CODE_VND_INVALID_VGROUP_ID, .msgType = 0 }; rpcSendResponse(&rpcRsp); diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index 62c97c92f1..c1c0d28253 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -46,135 +46,170 @@ static STaosError errors[] = { #endif // rpc -TAOS_DEFINE_ERROR(TSDB_CODE_ACTION_IN_PROGRESS, 0, 0x0001, "action in progress") -TAOS_DEFINE_ERROR(TSDB_CODE_ACTION_NEED_REPROCESSED, 0, 0x0003, "action need to be reprocessed") -TAOS_DEFINE_ERROR(TSDB_CODE_MSG_NOT_PROCESSED, 0, 0x0004, "message not processed") -TAOS_DEFINE_ERROR(TSDB_CODE_ALREADY_PROCESSED, 0, 0x0005, "message already processed") -TAOS_DEFINE_ERROR(TSDB_CODE_REDIRECT, 0, 0x0006, "redirect") -TAOS_DEFINE_ERROR(TSDB_CODE_LAST_SESSION_NOT_FINISHED, 0, 0x0007, "last session not finished") -TAOS_DEFINE_ERROR(TSDB_CODE_MAX_SESSIONS, 0, 0x0008, "max sessions") // too many sessions -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_SESSION_ID, 0, 0x0009, "invalid session id") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TRAN_ID, 0, 0x000A, "invalid transaction id") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG_TYPE, 0, 0x000B, "invalid message type") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG_LEN, 0, 0x000C, "invalid message length") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG_CONTENT, 0, 0x000D, "invalid message content") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG_VERSION, 0, 0x000E, "invalid message version") -TAOS_DEFINE_ERROR(TSDB_CODE_UNEXPECTED_RESPONSE, 0, 0x000F, "unexpected response") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_RESPONSE_TYPE, 0, 0x0010, "invalid response type") -TAOS_DEFINE_ERROR(TSDB_CODE_MISMATCHED_METER_ID, 0, 0x0011, "mismatched meter id") -TAOS_DEFINE_ERROR(TSDB_CODE_DISCONNECTED, 0, 0x0012, "disconnected") -TAOS_DEFINE_ERROR(TSDB_CODE_NOT_READY, 0, 0x0013, "not ready") // peer is not ready to process data -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_SLOW, 0, 0x0014, "too slow") -TAOS_DEFINE_ERROR(TSDB_CODE_OTHERS, 0, 0x0015, "others") -TAOS_DEFINE_ERROR(TSDB_CODE_APP_ERROR, 0, 0x0016, "app error") -TAOS_DEFINE_ERROR(TSDB_CODE_ALREADY_THERE, 0, 0x0017, "already there") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_RESOURCE, 0, 0x0018, "no resource") -TAOS_DEFINE_ERROR(TSDB_CODE_OPS_NOT_SUPPORT, 0, 0x0019, "operations not support") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_OPTION, 0, 0x001A, "invalid option") -TAOS_DEFINE_ERROR(TSDB_CODE_NOT_CONFIGURED, 0, 0x001B, "not configured") -TAOS_DEFINE_ERROR(TSDB_CODE_NETWORK_UNAVAIL, 0, 0x001C, "network unavailable") -TAOS_DEFINE_ERROR(TSDB_CODE_AUTH_REQUIRED, 0, 0x001D, "auth required") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ACTION_IN_PROGRESS, 0, 0x0001, "action in progress") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_AUTH_REQUIRED, 0, 0x0002, "auth required") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_AUTH_FAILURE, 0, 0x0003, "auth failure") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_REDIRECT, 0, 0x0004, "redirect") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NOT_READY, 0, 0x0005, "not ready") // peer is not ready to process data +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ALREADY_PROCESSED, 0, 0x0006, "message already processed") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_LAST_SESSION_NOT_FINISHED,0, 0x0007, "last session not finished") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_MISMATCHED_LINK_ID, 0, 0x0008, "mismatched meter id") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_TOO_SLOW, 0, 0x0009, "too slow") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_MAX_SESSIONS, 0, 0x000A, "max sessions") // too many sessions +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NETWORK_UNAVAIL, 0, 0x000B, "network unavailable") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_APP_ERROR, 0, 0x000C, "rpc app error") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_UNEXPECTED_RESPONSE, 0, 0x000D, "unexpected response") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_VALUE, 0, 0x000E, "invalid value") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_TRAN_ID, 0, 0x000F, "invalid transaction id") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_SESSION_ID, 0, 0x0010, "invalid session id") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_MSG_TYPE, 0, 0x0011, "invalid message type") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_RESPONSE_TYPE, 0, 0x0012, "invalid response type") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_TIME_STAMP, 0, 0x0013, "invalid timestamp") -// db -TAOS_DEFINE_ERROR(TSDB_CODE_DB_NOT_SELECTED, 0, 0x0100, "db not selected") -TAOS_DEFINE_ERROR(TSDB_CODE_DB_ALREADY_EXIST, 0, 0x0101, "database aleady exist") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_DB, 0, 0x0102, "invalid database") -TAOS_DEFINE_ERROR(TSDB_CODE_MONITOR_DB_FORBIDDEN, 0, 0x0103, "monitor db forbidden") +//common & util +TAOS_DEFINE_ERROR(TSDB_CODE_COM_OPS_NOT_SUPPORT, 0, 0x0100, "operations not support") +TAOS_DEFINE_ERROR(TSDB_CODE_COM_MEMORY_CORRUPTED, 0, 0x0101, "memory corrupted") +TAOS_DEFINE_ERROR(TSDB_CODE_COM_OUT_OF_MEMORY, 0, 0x0102, "out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_COM_INVALID_CFG_MSG, 0, 0x0103, "invalid config message") -// user -TAOS_DEFINE_ERROR(TSDB_CODE_USER_ALREADY_EXIST, 0, 0x0180, "user already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_USER, 0, 0x0181, "invalid user") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PASS, 0, 0x0182, "invalid password") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_USER_FORMAT, 0, 0x0183, "invalid user format") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PASS_FORMAT, 0, 0x0184, "invalid password format") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_USER_FROM_CONN, 0, 0x0185, "can not get user from conn") +//client +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_SQL, 0, 0x0200, "invalid sql") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_QHANDLE, 0, 0x0201, "client invalid qhandle") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TIME_STAMP, 0, 0x0202, "client time/server time can not be mixed up") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_VALUE, 0, 0x0203, "clientinvalid value") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_VERSION, 0, 0x0204, "client invalid version") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_IE, 0, 0x0205, "client invalid ie") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_FQDN, 0, 0x0206, "client invalid fqdn") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_USER_LENGTH, 0, 0x0207, "client invalid username length") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_PASS_LENGTH, 0, 0x0208, "client invalid password length") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_DB_LENGTH, 0, 0x0209, "client invalid database length") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH, 0, 0x020A, "client invalid table length") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_CONNECTION, 0, 0x020B, "client invalid connection") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_OUT_OF_MEMORY, 0, 0x020C, "client out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_DISKSPACE, 0, 0x020D, "client no disk space") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_QUERY_CACHE_ERASED, 0, 0x020E, "client query cache erased") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_QUERY_CANCELLED, 0, 0x020F, "client query cancelled") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_SORTED_RES_TOO_MANY, 0, 0x0210, "client sorted res too many") // too many result for ordered super table projection query +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_APP_ERROR, 0, 0x0211, "client app error") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_ACTION_IN_PROGRESS, 0, 0x0212, "client action in progress") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_DISCONNECTED, 0, 0x0213, "client disconnected") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_WRITE_AUTH, 0, 0x0214, "client no write auth") -// table -TAOS_DEFINE_ERROR(TSDB_CODE_TABLE_ALREADY_EXIST, 0, 0x0200, "table already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TABLE_ID, 0, 0x0201, "invalid table id") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TABLE_TYPE, 0, 0x0202, "invalid table type") -TAOS_DEFINE_ERROR(TSDB_CODE_NOT_SUPER_TABLE, 0, 0x0203, "no super table") // operation only available for super table -TAOS_DEFINE_ERROR(TSDB_CODE_TAG_ALREAY_EXIST, 0, 0x0204, "tag already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_TAG_NOT_EXIST, 0, 0x0205, "tag not exist") -TAOS_DEFINE_ERROR(TSDB_CODE_FIELD_ALREAY_EXIST, 0, 0x0206, "field already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_FIELD_NOT_EXIST, 0, 0x0207, "field not exist") -TAOS_DEFINE_ERROR(TSDB_CODE_COL_NAME_TOO_LONG, 0, 0x0208, "column name too long") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TAGS, 0, 0x0209, "too many tags") +// mnode +TAOS_DEFINE_ERROR(TSDB_CODE_MND_MSG_NOT_PROCESSED, 0, 0x0300, "mnode message not processed") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACTION_IN_PROGRESS, 0, 0x0301, "mnode action in progress") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACTION_NEED_REPROCESSED, 0, 0x0302, "mnode action need to be reprocessed") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_RIGHTS, 0, 0x0303, "mnode no rights") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_APP_ERROR, 0, 0x0304, "mnode app error") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CONNECTION, 0, 0x0305, "mnode invalid message connection") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_MSG_VERSION, 0, 0x0306, "mnode invalid message version") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_MSG_LEN, 0, 0x0307, "mnode invalid message length") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_MSG_TYPE, 0, 0x0308, "mnode invalid message type") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_SHELL_CONNS, 0, 0x0309, "mnode too many shell conns") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_OUT_OF_MEMORY, 0, 0x030A, "mnode out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_SHOWOBJ, 0, 0x030B, "mnode invalid show handle") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_QUERY_ID, 0, 0x030C, "mnode invalid query id") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STREAM_ID, 0, 0x030D, "mnode invalid stream id") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CONN_ID, 0, 0x030E, "mnode invalid connection") -// dnode & mnode -TAOS_DEFINE_ERROR(TSDB_CODE_NO_ENOUGH_DNODES, 0, 0x0280, "no enough dnodes") -TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_ALREADY_EXIST, 0, 0x0281, "dnode already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_NOT_EXIST, 0, 0x0282, "dnode not exist") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_MASTER, 0, 0x0283, "no master") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_REMOVE_MASTER, 0, 0x0284, "no remove master") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_ID, 0, 0x0285, "invalid query id") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_STREAM_ID, 0, 0x0286, "invalid stream id") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CONNECTION, 0, 0x0287, "invalid connection") -TAOS_DEFINE_ERROR(TSDB_CODE_SDB_ERROR, 0, 0x0288, "sdb error") -TAOS_DEFINE_ERROR(TSDB_CODE_TIMESTAMP_OUT_OF_RANGE, 0, 0x0289, "timestamp is out of range") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE, 0, 0x0320, "mnode object already there") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_ERROR, 0, 0x0321, "mnode sdb error") -// acct -TAOS_DEFINE_ERROR(TSDB_CODE_ACCT_ALREADY_EXIST, 0, 0x0300, "accounts already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT, 0, 0x0301, "invalid account") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT_PARAMETER, 0, 0x0302, "invalid account parameter") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_ACCTS, 0, 0x0303, "too many accounts") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_USERS, 0, 0x0304, "too many users") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TABLES, 0, 0x0305, "too many tables") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_DATABASES, 0, 0x0306, "too many databases") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TIME_SERIES, 0, 0x0307, "not enough time series") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ALREADY_EXIST, 0, 0x0330, "mnode dnode already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_EXIST, 0, 0x0331, "mnode dnode not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_EXIST, 0, 0x0332, "mnode vgroup not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_REMOVE_MASTER, 0, 0x0333, "mnode cant not remove master") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_ENOUGH_DNODES, 0, 0x0334, "mnode no enough dnodes") -// grant -TAOS_DEFINE_ERROR(TSDB_CODE_AUTH_FAILURE, 0, 0x0380, "auth failure") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_RIGHTS, 0, 0x0381, "no rights") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_WRITE_ACCESS, 0, 0x0382, "no write access") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_READ_ACCESS, 0, 0x0383, "no read access") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 0x0384, "grant expired") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DNODE_LIMITED, 0, 0x0385, "grant dnode limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_ACCT_LIMITED, 0, 0x0386, "grant account limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TIMESERIES_LIMITED, 0, 0x0387, "grant timeseries limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DB_LIMITED, 0, 0x0388, "grant db limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_USER_LIMITED, 0, 0x0389, "grant user limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CONN_LIMITED, 0, 0x038A, "grant conn limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STREAM_LIMITED, 0, 0x038B, "grant stream limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_SPEED_LIMITED, 0, 0x038C, "grant speed limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STORAGE_LIMITED, 0, 0x038D, "grant storage limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, 0, 0x038E, "grant query time limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, 0, 0x038F, "grant cpu limited") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_ALREADY_EXIST, 0, 0x0340, "mnode accounts already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT, 0, 0x0341, "mnode invalid account") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT_PARA, 0, 0x0342, "mnode invalid account parameter") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT_OPTION, 0, 0x0343, "mnode invalid acct option") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_ACCTS, 0, 0x0344, "mnode too many accounts") -// server -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VGROUP_ID, 0, 0x0400, "invalid vgroup id") -TAOS_DEFINE_ERROR(TSDB_CODE_VG_INIT_FAILED, 0, 0x0402, "vgroup init failed") -TAOS_DEFINE_ERROR(TSDB_CODE_SERV_NO_DISKSPACE, 0, 0x0403, "server no diskspace") -TAOS_DEFINE_ERROR(TSDB_CODE_SERV_OUT_OF_MEMORY, 0, 0x0404, "server out of memory") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_DISK_PERMISSIONS, 0, 0x0405, "no disk permissions") -TAOS_DEFINE_ERROR(TSDB_CODE_FILE_CORRUPTED, 0, 0x0406, "file corrupted") -TAOS_DEFINE_ERROR(TSDB_CODE_MEMORY_CORRUPTED, 0, 0x0407, "memory corrupted") -TAOS_DEFINE_ERROR(TSDB_CODE_NOT_SUCH_FILE_OR_DIR, 0, 0x0408, "no such file or directory") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_SHELL_CONNS, 0, 0x0409, "too many shell conns") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_USER_ALREADY_EXIST, 0, 0x0350, "mnode user already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_USER, 0, 0x0351, "mnode invalid user") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_USER_FORMAT, 0, 0x0352, "mnode invalid user format") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_PASS_FORMAT, 0, 0x0353, "mnode invalid password format") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_USER_FROM_CONN, 0, 0x0354, "mnode can not get user from conn") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_USERS, 0, 0x0355, "mnode too many users") -// client -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CLIENT_VERSION, 0, 0x0481, "invalid client version") -TAOS_DEFINE_ERROR(TSDB_CODE_CLI_OUT_OF_MEMORY, 0, 0x0482, "client out of memory") -TAOS_DEFINE_ERROR(TSDB_CODE_CLI_NO_DISKSPACE, 0, 0x0483, "client no disk space") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TIME_STAMP, 0, 0x0484, "invalid timestamp") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_SQL, 0, 0x0485, "invalid sql") -TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CACHE_ERASED, 0, 0x0486, "query cache erased") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_MSG, 0, 0x0487, "invalid query message") // failed to validate the sql expression msg by vnode -TAOS_DEFINE_ERROR(TSDB_CODE_SORTED_RES_TOO_MANY, 0, 0x0488, "sorted res too many") // too many result for ordered super table projection query -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QHANDLE, 0, 0x0489, "invalid handle") -TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CANCELLED, 0, 0x048A, "query cancelled") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_IE, 0, 0x048B, "invalid ie") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VALUE, 0, 0x048C, "invalid value") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_FQDN, 0, 0x048D, "invalid FQDN") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TABLE_ALREADY_EXIST, 0, 0x0360, "mnode table already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_ID, 0, 0x0361, "mnode invalid table id") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_TYPE, 0, 0x0362, "mnode invalid table type") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TAGS, 0, 0x0363, "mnode too many tags") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TABLES, 0, 0x0364, "mnode too many tables") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TIMESERIES, 0, 0x0365, "mnode not enough time series") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_NOT_SUPER_TABLE, 0, 0x0366, "mnode no super table") // operation only available for super table +TAOS_DEFINE_ERROR(TSDB_CODE_MND_COL_NAME_TOO_LONG, 0, 0x0367, "mnode column name too long") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_ALREAY_EXIST, 0, 0x0368, "mnode tag already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_NOT_EXIST, 0, 0x0369, "mnode tag not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_ALREAY_EXIST, 0, 0x036A, "mnode field already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_NOT_EXIST, 0, 0x036B, "mnode field not exist") -// others -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_FILE_FORMAT, 0, 0x0500, "invalid file format") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_NOT_SELECTED, 0, 0x0380, "mnode db not selected") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_ALREADY_EXIST, 0, 0x0381, "mnode database aleady exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB_OPTION, 0, 0x0382, "mnode invalid db option") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB, 0, 0x0383, "mnode invalid database") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_MONITOR_DB_FORBIDDEN, 0, 0x0384, "mnode monitor db forbidden") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_DATABASES, 0, 0x0385, "mnode too many databases") -// TSDB -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CONFIG, 0, 0x0580, "invalid TSDB configuration") -TAOS_DEFINE_ERROR(TSDB_CODE_TAG_VER_OUT_OF_DATE, 0, 0x0581, "tag version is out of date") -TAOS_DEFINE_ERROR(TSDB_CODE_TABLE_SCHEMA_VERSION, 0, 0x0582, "invalid table schema version from client") +// dnode +TAOS_DEFINE_ERROR(TSDB_CODE_DND_MSG_NOT_PROCESSED, 0, 0x0400, "dnode message not processed") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_OUT_OF_MEMORY, 0, 0x0401, "dnode out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_NO_WRITE_ACCESS, 0, 0x0402, "dnode no disk write access") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_INVALID_MSG_LEN, 0, 0x0403, "dnode invalid message length") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_INVALID_FILE_FORMAT, 0, 0x0404, "dnode invalid file format") +// vnode +TAOS_DEFINE_ERROR(TSDB_CODE_VND_ACTION_IN_PROGRESS, 0, 0x0500, "vnode action in progress") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_MSG_NOT_PROCESSED, 0, 0x0501, "vnode message not processed") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_ACTION_NEED_REPROCESSED, 0, 0x0502, "vnode action need to be reprocessed") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_VGROUP_ID, 0, 0x0503, "vnode invalid vgroup id") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_INIT_FAILED, 0, 0x0504, "vnode init failed") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_DISKSPACE, 0, 0x0505, "vnode no diskspace") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_DISK_PERMISSIONS, 0, 0x0506, "vnode no disk permissions") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR, 0, 0x0507, "vnode no such file or directory") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_OUT_OF_MEMORY, 0, 0x0508, "vnode out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_APP_ERROR, 0, 0x0509, "vnode app error") + +// tsdb +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_ID, 0, 0x0600, "tsdb invalid table id") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_TYPE, 0, 0x0601, "tsdb invalid table schema version") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TABLE_SCHEMA_VERSION, 0, 0x0602, "tsdb invalid table schema version") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TABLE_ALREADY_EXIST, 0, 0x0603, "tsdb table already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_CONFIG, 0, 0x0604, "tsdb invalid configuration") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INIT_FAILED, 0, 0x0605, "tsdb init failed") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_DISKSPACE, 0, 0x0606, "tsdb no diskspace") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_DISK_PERMISSIONS, 0, 0x0607, "tsdb no disk permissions") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_FILE_CORRUPTED, 0, 0x0608, "tsdb file corrupted") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_OUT_OF_MEMORY, 0, 0x0609, "tsdb out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE, 0, 0x060A, "tsdb tag version is out of date") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE, 0, 0x060B, "tsdb timestamp is out of range") + +// query +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_QHANDLE, 0, 0x0700, "query invalid handle") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_MSG, 0, 0x0701, "query invalid message") // failed to validate the sql expression msg by vnode +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_NO_DISKSPACE, 0, 0x0702, "query no diskspace") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_OUT_OF_MEMORY, 0, 0x0703, "query out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_APP_ERROR, 0, 0x0704, "query app error") + +// gran +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 0x0800, "grant expired") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DNODE_LIMITED, 0, 0x0801, "grant dnode limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_ACCT_LIMITED, 0, 0x0802, "grant account limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TIMESERIES_LIMITED, 0, 0x0803, "grant timeseries limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DB_LIMITED, 0, 0x0804, "grant db limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_USER_LIMITED, 0, 0x0805, "grant user limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CONN_LIMITED, 0, 0x0806, "grant conn limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STREAM_LIMITED, 0, 0x0807, "grant stream limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_SPEED_LIMITED, 0, 0x0808, "grant speed limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STORAGE_LIMITED, 0, 0x0809, "grant storage limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, 0, 0x080A, "grant query time limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, 0, 0x080B, "grant cpu limited") + +// sync 0x1400 +TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_CONFIG, 0, 0x1900, "sync invalid configuration") #ifdef TAOS_ERROR_C }; diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index a01decc6c6..cc7957f6e1 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -862,7 +862,7 @@ void shellGetGrantInfo(void *con) { int code = taos_errno(pSql); if (code != TSDB_CODE_SUCCESS) { - if (code == TSDB_CODE_OPS_NOT_SUPPORT) { + if (code == TSDB_CODE_COM_OPS_NOT_SUPPORT) { fprintf(stdout, "Server is Community Edition, version is %s\n\n", taos_get_server_info(con)); } else { fprintf(stderr, "Failed to check Server Edition, Reason:%d:%s\n\n", taos_errno(con), taos_errstr(con)); diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c index 3836bcea52..9634d2c645 100644 --- a/src/mnode/src/mnodeAcct.c +++ b/src/mnode/src/mnodeAcct.c @@ -70,7 +70,7 @@ static int32_t mnodeActionActionEncode(SSdbOper *pOper) { static int32_t mnodeAcctActionDecode(SSdbOper *pOper) { SAcctObj *pAcct = (SAcctObj *) calloc(1, sizeof(SAcctObj)); - if (pAcct == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pAcct == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pAcct, pOper->rowData, tsAcctUpdateSize); pOper->pObj = pAcct; diff --git a/src/mnode/src/mnodeBalance.c b/src/mnode/src/mnodeBalance.c index 64d3c6d7c7..14acffdb62 100644 --- a/src/mnode/src/mnodeBalance.c +++ b/src/mnode/src/mnodeBalance.c @@ -56,7 +56,7 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) { if (pSelDnode == NULL) { mError("failed to alloc vnode to vgroup"); - return TSDB_CODE_NO_ENOUGH_DNODES; + return TSDB_CODE_MND_NO_ENOUGH_DNODES; } pVgroup->vnodeGid[0].dnodeId = pSelDnode->dnodeId; diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 23e903dd25..90569b4a95 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -71,7 +71,7 @@ static int32_t mnodeDbActionInsert(SSdbOper *pOper) { } else { mError("db:%s, acct:%s info not exist in sdb", pDb->name, pDb->acct); - return TSDB_CODE_INVALID_ACCT; + return TSDB_CODE_MND_INVALID_ACCT; } return TSDB_CODE_SUCCESS; @@ -111,7 +111,7 @@ static int32_t mnodeDbActionEncode(SSdbOper *pOper) { static int32_t mnodeDbActionDecode(SSdbOper *pOper) { SDbObj *pDb = (SDbObj *) calloc(1, sizeof(SDbObj)); - if (pDb == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pDb == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pDb, pOper->rowData, tsDbUpdateSize); pOper->pObj = pDb; @@ -189,102 +189,102 @@ static int32_t mnodeCheckDbCfg(SDbCfg *pCfg) { if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) { mError("invalid db option cacheBlockSize:%d valid range: [%d, %d]", pCfg->cacheBlockSize, TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) { mError("invalid db option totalBlocks:%d valid range: [%d, %d]", pCfg->totalBlocks, TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->maxTables < TSDB_MIN_TABLES || pCfg->maxTables > TSDB_MAX_TABLES) { mError("invalid db option maxTables:%d valid range: [%d, %d]", pCfg->maxTables, TSDB_MIN_TABLES, TSDB_MAX_TABLES); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) { mError("invalid db option daysPerFile:%d valid range: [%d, %d]", pCfg->daysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->daysToKeep < TSDB_MIN_KEEP || pCfg->daysToKeep > TSDB_MAX_KEEP) { mError("invalid db option daysToKeep:%d valid range: [%d, %d]", pCfg->daysToKeep, TSDB_MIN_KEEP, TSDB_MAX_KEEP); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->daysToKeep < pCfg->daysPerFile) { mError("invalid db option daysToKeep:%d should larger than daysPerFile:%d", pCfg->daysToKeep, pCfg->daysPerFile); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->daysToKeep2 < TSDB_MIN_KEEP || pCfg->daysToKeep2 > pCfg->daysToKeep) { mError("invalid db option daysToKeep2:%d valid range: [%d, %d]", pCfg->daysToKeep, TSDB_MIN_KEEP, pCfg->daysToKeep); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > pCfg->daysToKeep2) { mError("invalid db option daysToKeep1:%d valid range: [%d, %d]", pCfg->daysToKeep1, TSDB_MIN_KEEP, pCfg->daysToKeep2); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->maxRowsPerFileBlock < TSDB_MIN_MAX_ROW_FBLOCK || pCfg->maxRowsPerFileBlock > TSDB_MAX_MAX_ROW_FBLOCK) { mError("invalid db option maxRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->maxRowsPerFileBlock, TSDB_MIN_MAX_ROW_FBLOCK, TSDB_MAX_MAX_ROW_FBLOCK); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->minRowsPerFileBlock < TSDB_MIN_MIN_ROW_FBLOCK || pCfg->minRowsPerFileBlock > TSDB_MAX_MIN_ROW_FBLOCK) { mError("invalid db option minRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->minRowsPerFileBlock, TSDB_MIN_MIN_ROW_FBLOCK, TSDB_MAX_MIN_ROW_FBLOCK); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->minRowsPerFileBlock > pCfg->maxRowsPerFileBlock) { mError("invalid db option minRowsPerFileBlock:%d should smaller than maxRowsPerFileBlock:%d", pCfg->minRowsPerFileBlock, pCfg->maxRowsPerFileBlock); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->commitTime < TSDB_MIN_COMMIT_TIME || pCfg->commitTime > TSDB_MAX_COMMIT_TIME) { mError("invalid db option commitTime:%d valid range: [%d, %d]", pCfg->commitTime, TSDB_MIN_COMMIT_TIME, TSDB_MAX_COMMIT_TIME); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->precision < TSDB_MIN_PRECISION && pCfg->precision > TSDB_MAX_PRECISION) { mError("invalid db option timePrecision:%d valid value: [%d, %d]", pCfg->precision, TSDB_MIN_PRECISION, TSDB_MAX_PRECISION); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) { mError("invalid db option compression:%d valid range: [%d, %d]", pCfg->compression, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL || pCfg->walLevel > TSDB_MAX_WAL_LEVEL) { mError("invalid db option walLevel:%d, valid range: [%d, %d]", pCfg->walLevel, TSDB_MIN_WAL_LEVEL, TSDB_MAX_WAL_LEVEL); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->replications < TSDB_MIN_REPLICA_NUM || pCfg->replications > TSDB_MAX_REPLICA_NUM) { mError("invalid db option replications:%d valid range: [%d, %d]", pCfg->replications, TSDB_MIN_REPLICA_NUM, TSDB_MAX_REPLICA_NUM); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL) { mError("invalid db option walLevel:%d must be greater than 0", pCfg->walLevel); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } #ifndef _SYNC if (pCfg->replications != 1) { mError("invalid db option replications:%d can only be 1 in this version", pCfg->replications); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } #endif @@ -320,7 +320,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { return TSDB_CODE_SUCCESS; } else { mError("db:%s, is already exist, ignore exist not set", pCreate->db); - return TSDB_CODE_DB_ALREADY_EXIST; + return TSDB_CODE_MND_DB_ALREADY_EXIST; } } @@ -366,7 +366,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { tfree(pDb); - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } return code; @@ -743,7 +743,7 @@ static int32_t mnodeSetDbDropping(SDbObj *pDb) { int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } return code; @@ -766,7 +766,7 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) { if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) { code = TSDB_CODE_GRANT_EXPIRED; } else if (!pMsg->pUser->writeAuth) { - code = TSDB_CODE_NO_RIGHTS; + code = TSDB_CODE_MND_NO_RIGHTS; } else { code = mnodeCreateDb(pMsg->pUser->pAcct, pCreate); if (code == TSDB_CODE_SUCCESS) { @@ -800,7 +800,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { if (cacheBlockSize > 0 && cacheBlockSize != pDb->cfg.cacheBlockSize) { mError("db:%s, can't alter cache option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (totalBlocks > 0 && totalBlocks != pDb->cfg.totalBlocks) { @@ -813,13 +813,13 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { newCfg.maxTables = maxTables; if (newCfg.maxTables < pDb->cfg.maxTables) { mError("db:%s, tables:%d should larger than origin:%d", pDb->name, newCfg.maxTables, pDb->cfg.maxTables); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } } if (daysPerFile > 0 && daysPerFile != pDb->cfg.daysPerFile) { mError("db:%s, can't alter days option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (daysToKeep > 0 && daysToKeep != pDb->cfg.daysToKeep) { @@ -839,22 +839,22 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { if (minRows > 0 && minRows != pDb->cfg.minRowsPerFileBlock) { mError("db:%s, can't alter minRows option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (maxRows > 0 && maxRows != pDb->cfg.maxRowsPerFileBlock) { mError("db:%s, can't alter maxRows option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (commitTime > 0 && commitTime != pDb->cfg.commitTime) { mError("db:%s, can't alter commitTime option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (precision > 0 && precision != pDb->cfg.precision) { mError("db:%s, can't alter precision option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (compression >= 0 && compression != pDb->cfg.compression) { @@ -864,7 +864,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { if (walLevel > 0 && walLevel != pDb->cfg.walLevel) { mError("db:%s, can't alter walLevel option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (replications > 0 && replications != pDb->cfg.replications) { @@ -873,17 +873,17 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { if (pDb->cfg.walLevel < TSDB_MIN_WAL_LEVEL) { mError("db:%s, walLevel:%d must be greater than 0", pDb->name, pDb->cfg.walLevel); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (replications > mnodeGetDnodesNum()) { mError("db:%s, no enough dnode to change replica:%d", pDb->name, replications); - terrno = TSDB_CODE_NO_ENOUGH_DNODES; + terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES; } if (pDb->cfg.replications - replications >= 2) { mError("db:%s, replica number can't change from 3 to 1", pDb->name, replications); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } } @@ -914,7 +914,7 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) { int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } } @@ -942,7 +942,7 @@ static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) { if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pAlter->db); if (pMsg->pDb == NULL) { mError("db:%s, failed to alter, invalid db", pAlter->db); - return TSDB_CODE_INVALID_DB; + return TSDB_CODE_MND_INVALID_DB; } int32_t code = mnodeAlterDb(pMsg->pDb, pAlter); @@ -966,7 +966,7 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) { }; int32_t code = sdbDeleteRow(&oper); if (code != 0) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } return code; @@ -983,13 +983,13 @@ static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg) { return TSDB_CODE_SUCCESS; } else { mError("db:%s, failed to drop, invalid db", pDrop->db); - return TSDB_CODE_INVALID_DB; + return TSDB_CODE_MND_INVALID_DB; } } if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) { mError("db:%s, can't drop monitor database", pDrop->db); - return TSDB_CODE_MONITOR_DB_FORBIDDEN; + return TSDB_CODE_MND_MONITOR_DB_FORBIDDEN; } int32_t code = mnodeSetDbDropping(pMsg->pDb); diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 506511ece9..6fd565b5e6 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -107,7 +107,7 @@ static int32_t mnodeDnodeActionEncode(SSdbOper *pOper) { static int32_t mnodeDnodeActionDecode(SSdbOper *pOper) { SDnodeObj *pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj)); - if (pDnode == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pDnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pDnode, pOper->rowData, tsDnodeUpdateSize); pOper->pObj = pDnode; @@ -249,7 +249,7 @@ static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) { } if (strcmp(pMsg->pUser->user, "root") != 0) { - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } SRpcIpSet ipSet = mnodeGetIpSetFromIp(pCmCfgDnode->ep); @@ -286,7 +286,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { uint32_t version = htonl(pStatus->version); if (version != tsVersion) { mError("status msg version:%d not equal with mnode:%d", version, tsVersion); - return TSDB_CODE_INVALID_MSG_VERSION; + return TSDB_CODE_MND_INVALID_MSG_VERSION; } SDnodeObj *pDnode = NULL; @@ -294,13 +294,13 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { pDnode = mnodeGetDnodeByEp(pStatus->dnodeEp); if (pDnode == NULL) { mTrace("dnode %s not created", pStatus->dnodeEp); - return TSDB_CODE_DNODE_NOT_EXIST; + return TSDB_CODE_MND_DNODE_NOT_EXIST; } } else { pDnode = mnodeGetDnode(pStatus->dnodeId); if (pDnode == NULL) { mError("dnode id:%d, %s not exist", pStatus->dnodeId, pStatus->dnodeEp); - return TSDB_CODE_DNODE_NOT_EXIST; + return TSDB_CODE_MND_DNODE_NOT_EXIST; } } @@ -347,7 +347,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { int32_t contLen = sizeof(SDMStatusRsp) + TSDB_MAX_VNODES * sizeof(SDMVgroupAccess); SDMStatusRsp *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } mnodeGetMnodeInfos(&pRsp->mnodes); @@ -376,7 +376,7 @@ static int32_t mnodeCreateDnode(char *ep) { if (pDnode != NULL) { mnodeDecDnodeRef(pDnode); mError("dnode:%d is alredy exist, %s:%d", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodePort); - return TSDB_CODE_DNODE_ALREADY_EXIST; + return TSDB_CODE_MND_DNODE_ALREADY_EXIST; } pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj)); @@ -398,7 +398,7 @@ static int32_t mnodeCreateDnode(char *ep) { int dnodeId = pDnode->dnodeId; tfree(pDnode); mError("failed to create dnode:%d, result:%s", dnodeId, tstrerror(code)); - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("dnode:%d is created, result:%s", pDnode->dnodeId, tstrerror(code)); @@ -414,7 +414,7 @@ int32_t mnodeDropDnode(SDnodeObj *pDnode) { int32_t code = sdbDeleteRow(&oper); if (code != TSDB_CODE_SUCCESS) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } mLPrint("dnode:%d, is dropped from cluster, result:%s", pDnode->dnodeId, tstrerror(code)); @@ -425,13 +425,13 @@ static int32_t mnodeDropDnodeByEp(char *ep) { SDnodeObj *pDnode = mnodeGetDnodeByEp(ep); if (pDnode == NULL) { mError("dnode:%s, is not exist", ep); - return TSDB_CODE_DNODE_NOT_EXIST; + return TSDB_CODE_MND_DNODE_NOT_EXIST; } mnodeDecDnodeRef(pDnode); if (strcmp(pDnode->dnodeEp, dnodeGetMnodeMasterEp()) == 0) { mError("dnode:%d, can't drop dnode:%s which is master", pDnode->dnodeId, ep); - return TSDB_CODE_NO_REMOVE_MASTER; + return TSDB_CODE_MND_NO_REMOVE_MASTER; } mPrint("dnode:%d, start to drop it", pDnode->dnodeId); @@ -446,7 +446,7 @@ static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg) { SCMCreateDnodeMsg *pCreate = pMsg->rpcMsg.pCont; if (strcmp(pMsg->pUser->user, "root") != 0) { - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } else { int32_t code = mnodeCreateDnode(pCreate->ep); @@ -466,7 +466,7 @@ static int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg) { SCMDropDnodeMsg *pDrop = pMsg->rpcMsg.pCont; if (strcmp(pMsg->pUser->user, "root") != 0) { - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } else { int32_t code = mnodeDropDnodeByEp(pDrop->ep); @@ -486,7 +486,7 @@ static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC if (strcmp(pUser->pAcct->user, "root") != 0) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } int32_t cols = 0; @@ -615,7 +615,7 @@ static int32_t mnodeGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p if (strcmp(pUser->user, "root") != 0) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } SSchema *pSchema = pMeta->schema; @@ -725,7 +725,7 @@ static int32_t mnodeGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p if (strcmp(pUser->user, "root") != 0) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } SSchema *pSchema = pMeta->schema; @@ -812,7 +812,7 @@ static int32_t mnodeGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC if (strcmp(pUser->user, "root") != 0) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } SSchema *pSchema = pMeta->schema; diff --git a/src/mnode/src/mnodeInt.c b/src/mnode/src/mnodeInt.c index 1cb421bef7..c2dd46d981 100644 --- a/src/mnode/src/mnodeInt.c +++ b/src/mnode/src/mnodeInt.c @@ -41,7 +41,7 @@ void mnodeCreateMsg(SMnodeMsg *pMsg, SRpcMsg *rpcMsg) { int32_t mnodeInitMsg(SMnodeMsg *pMsg) { pMsg->pUser = mnodeGetUserFromConn(pMsg->rpcMsg.handle); if (pMsg->pUser == NULL) { - return TSDB_CODE_INVALID_USER; + return TSDB_CODE_MND_INVALID_USER; } return TSDB_CODE_SUCCESS; diff --git a/src/mnode/src/mnodeMnode.c b/src/mnode/src/mnodeMnode.c index de1826a174..43ee45f3b1 100644 --- a/src/mnode/src/mnodeMnode.c +++ b/src/mnode/src/mnodeMnode.c @@ -63,7 +63,7 @@ static int32_t mnodeMnodeActionDestroy(SSdbOper *pOper) { static int32_t mnodeMnodeActionInsert(SSdbOper *pOper) { SMnodeObj *pMnode = pOper->pObj; SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); - if (pDnode == NULL) return TSDB_CODE_DNODE_NOT_EXIST; + if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST; pDnode->isMgmt = true; mnodeDecDnodeRef(pDnode); @@ -75,7 +75,7 @@ static int32_t mnodeMnodeActionDelete(SSdbOper *pOper) { SMnodeObj *pMnode = pOper->pObj; SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); - if (pDnode == NULL) return TSDB_CODE_DNODE_NOT_EXIST; + if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST; pDnode->isMgmt = false; mnodeDecDnodeRef(pDnode); @@ -103,7 +103,7 @@ static int32_t mnodeMnodeActionEncode(SSdbOper *pOper) { static int32_t mnodeMnodeActionDecode(SSdbOper *pOper) { SMnodeObj *pMnode = calloc(1, sizeof(SMnodeObj)); - if (pMnode == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pMnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pMnode, pOper->rowData, tsMnodeUpdateSize); pOper->pObj = pMnode; @@ -285,7 +285,7 @@ int32_t mnodeAddMnode(int32_t dnodeId) { int32_t code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { tfree(pMnode); - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } mnodeUpdateMnodeIpSet(); @@ -307,7 +307,7 @@ void mnodeDropMnodeLocal(int32_t dnodeId) { int32_t mnodeDropMnode(int32_t dnodeId) { SMnodeObj *pMnode = mnodeGetMnode(dnodeId); if (pMnode == NULL) { - return TSDB_CODE_DNODE_NOT_EXIST; + return TSDB_CODE_MND_DNODE_NOT_EXIST; } SSdbOper oper = { @@ -318,7 +318,7 @@ int32_t mnodeDropMnode(int32_t dnodeId) { int32_t code = sdbDeleteRow(&oper); if (code != TSDB_CODE_SUCCESS) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } sdbDecRef(tsMnodeSdb, pMnode); @@ -335,7 +335,7 @@ static int32_t mnodeGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC if (strcmp(pUser->pAcct->user, "root") != 0) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } int32_t cols = 0; diff --git a/src/mnode/src/mnodePeer.c b/src/mnode/src/mnodePeer.c index d3699948f2..9aefc73b77 100644 --- a/src/mnode/src/mnodePeer.c +++ b/src/mnode/src/mnodePeer.c @@ -48,7 +48,7 @@ void mnodeAddPeerRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg)) { int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg) { if (pMsg->rpcMsg.pCont == NULL) { mError("%p, msg:%s in mpeer queue, content is null", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_INVALID_MSG_LEN; + return TSDB_CODE_MND_INVALID_MSG_LEN; } if (!sdbIsMaster()) { @@ -63,12 +63,12 @@ int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg) { mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[i])); } - return TSDB_CODE_REDIRECT; + return TSDB_CODE_RPC_REDIRECT; } if (tsMnodeProcessPeerMsgFp[pMsg->rpcMsg.msgType] == NULL) { mError("%p, msg:%s in mpeer queue, not processed", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_MSG_NOT_PROCESSED; + return TSDB_CODE_MND_MSG_NOT_PROCESSED; } return (*tsMnodeProcessPeerMsgFp[pMsg->rpcMsg.msgType])(pMsg); diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index 49f79a54f1..541fc9cbd8 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -84,7 +84,7 @@ SConnObj *mnodeCreateConn(char *user, uint32_t ip, uint16_t port) { if (connSize > tsMaxShellConns) { mError("failed to create conn for user:%s ip:%s:%u, conns:%d larger than maxShellConns:%d, ", user, taosIpStr(ip), port, connSize, tsMaxShellConns); - terrno = TSDB_CODE_TOO_MANY_SHELL_CONNS; + terrno = TSDB_CODE_MND_TOO_MANY_SHELL_CONNS; return NULL; } @@ -168,7 +168,7 @@ static void *mnodeGetNextConn(SHashMutableIterator *pIter, SConnObj **pConn) { static int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; int32_t cols = 0; SSchema *pSchema = pMeta->schema; @@ -282,7 +282,7 @@ int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SCMHeartBeatMsg *pHBMsg) { static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; int32_t cols = 0; SSchema *pSchema = pMeta->schema; @@ -391,7 +391,7 @@ static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, v static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; int32_t cols = 0; SSchema *pSchema = pMeta->schema; @@ -519,7 +519,7 @@ static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, v static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) { SUserObj *pUser = pMsg->pUser; - if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; SCMKillQueryMsg *pKill = pMsg->rpcMsg.pCont; mPrint("kill query msg is received, queryId:%s", pKill->queryId); @@ -530,7 +530,7 @@ static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) { if (queryIdStr == NULL || connIdStr == NULL) { mPrint("failed to kill query, queryId:%s", pKill->queryId); - return TSDB_CODE_INVALID_QUERY_ID; + return TSDB_CODE_MND_INVALID_QUERY_ID; } int32_t queryId = (int32_t)strtol(queryIdStr, NULL, 10); @@ -538,7 +538,7 @@ static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) { SConnObj *pConn = taosCacheAcquireByName(tsMnodeConnCache, connIdStr); if (pConn == NULL) { mError("connId:%s, failed to kill queryId:%d, conn not exist", connIdStr, queryId); - return TSDB_CODE_INVALID_CONNECTION; + return TSDB_CODE_MND_INVALID_CONN_ID; } else { mPrint("connId:%s, queryId:%d is killed by user:%s", connIdStr, queryId, pUser->user); pConn->queryId = queryId; @@ -549,7 +549,7 @@ static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) { SUserObj *pUser = pMsg->pUser; - if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; SCMKillQueryMsg *pKill = pMsg->rpcMsg.pCont; mPrint("kill stream msg is received, streamId:%s", pKill->queryId); @@ -560,7 +560,7 @@ static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) { if (streamIdStr == NULL || connIdStr == NULL) { mPrint("failed to kill stream, streamId:%s", pKill->queryId); - return TSDB_CODE_INVALID_STREAM_ID; + return TSDB_CODE_MND_INVALID_STREAM_ID; } int32_t streamId = (int32_t)strtol(streamIdStr, NULL, 10); @@ -568,7 +568,7 @@ static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) { SConnObj *pConn = taosCacheAcquireByName(tsMnodeConnCache, connIdStr); if (pConn == NULL) { mError("connId:%s, failed to kill streamId:%d, conn not exist", connIdStr, streamId); - return TSDB_CODE_INVALID_CONNECTION; + return TSDB_CODE_MND_INVALID_CONN_ID; } else { mPrint("connId:%s, streamId:%d is killed by user:%s", connIdStr, streamId, pUser->user); pConn->streamId = streamId; @@ -579,13 +579,13 @@ static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessKillConnectionMsg(SMnodeMsg *pMsg) { SUserObj *pUser = pMsg->pUser; - if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; SCMKillConnMsg *pKill = pMsg->rpcMsg.pCont; SConnObj * pConn = taosCacheAcquireByName(tsMnodeConnCache, pKill->queryId); if (pConn == NULL) { mError("connId:%s, failed to kill, conn not exist", pKill->queryId); - return TSDB_CODE_INVALID_CONNECTION; + return TSDB_CODE_MND_INVALID_CONN_ID; } else { mPrint("connId:%s, is killed by user:%s", pKill->queryId, pUser->user); pConn->killed = 1; diff --git a/src/mnode/src/mnodeRead.c b/src/mnode/src/mnodeRead.c index 0ee917f2d1..2c1f204277 100644 --- a/src/mnode/src/mnodeRead.c +++ b/src/mnode/src/mnodeRead.c @@ -44,7 +44,7 @@ void mnodeAddReadMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *pMsg)) { int32_t mnodeProcessRead(SMnodeMsg *pMsg) { if (pMsg->rpcMsg.pCont == NULL) { mError("%p, msg:%s in mread queue, content is null", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_INVALID_MSG_LEN; + return TSDB_CODE_MND_INVALID_MSG_LEN; } if (!sdbIsMaster()) { @@ -59,12 +59,12 @@ int32_t mnodeProcessRead(SMnodeMsg *pMsg) { mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[i])); } - return TSDB_CODE_REDIRECT; + return TSDB_CODE_RPC_REDIRECT; } if (tsMnodeProcessReadMsgFp[pMsg->rpcMsg.msgType] == NULL) { mError("%p, msg:%s in mread queue, not processed", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_MSG_NOT_PROCESSED; + return TSDB_CODE_MND_MSG_NOT_PROCESSED; } int32_t code = mnodeInitMsg(pMsg); diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 51b5fb0d2d..b9033cdf3c 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -518,7 +518,7 @@ static int sdbWrite(void *param, void *data, int type) { sdbError("table:%s, failed to restore %s record:%s from wal, version:%" PRId64 " too large, sdb version:%" PRId64, pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, tsSdbObj.version); - return TSDB_CODE_OTHERS; + return TSDB_CODE_MND_APP_ERROR; } else { tsSdbObj.version = pHead->version; } @@ -561,7 +561,7 @@ static int sdbWrite(void *param, void *data, int type) { SSdbOper oper = {.rowSize = pHead->len, .rowData = pHead->cont, .table = pTable}; code = (*pTable->decodeFp)(&oper); return sdbUpdateHash(pTable, &oper); - } else { return TSDB_CODE_INVALID_MSG_TYPE; } + } else { return TSDB_CODE_MND_INVALID_MSG_TYPE; } } int32_t sdbInsertRow(SSdbOper *pOper) { @@ -571,7 +571,7 @@ int32_t sdbInsertRow(SSdbOper *pOper) { if (sdbGetRowFromObj(pTable, pOper->pObj)) { sdbError("table:%s, failed to insert record:%s, already exist", pTable->tableName, sdbGetKeyStrFromObj(pTable, pOper->pObj)); sdbDecRef(pTable, pOper->pObj); - return TSDB_CODE_ALREADY_THERE; + return TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE; } if (pTable->keyType == SDB_KEY_AUTO) { diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index c1edd309c8..36e7d13a86 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -110,12 +110,12 @@ static char *mnodeGetShowType(int32_t showType) { static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) { SCMShowMsg *pShowMsg = pMsg->rpcMsg.pCont; if (pShowMsg->type >= TSDB_MGMT_TABLE_MAX) { - return TSDB_CODE_INVALID_MSG_TYPE; + return TSDB_CODE_MND_INVALID_MSG_TYPE; } if (!tsMnodeShowMetaFp[pShowMsg->type] || !tsMnodeShowRetrieveFp[pShowMsg->type]) { mError("show type:%s is not support", mnodeGetShowType(pShowMsg->type)); - return TSDB_CODE_OPS_NOT_SUPPORT; + return TSDB_CODE_COM_OPS_NOT_SUPPORT; } int32_t showObjSize = sizeof(SShowObj) + htons(pShowMsg->payloadLen); @@ -127,14 +127,14 @@ static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) { pShow = mnodePutShowObj(pShow, showObjSize); if (pShow == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } int32_t size = sizeof(SCMShowRsp) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_EXTRA_PAYLOAD_SIZE; SCMShowRsp *pShowRsp = rpcMallocCont(size); if (pShowRsp == NULL) { mnodeReleaseShowObj(pShow, true); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } pShowRsp->qhandle = htobe64((uint64_t) pShow); @@ -169,7 +169,7 @@ static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) { */ if (!mnodeAccquireShowObj(pShow)) { mError("%p, show is invalid", pShow); - return TSDB_CODE_INVALID_QHANDLE; + return TSDB_CODE_MND_INVALID_SHOWOBJ; } if (mnodeCheckShowFinished(pShow)) { @@ -202,7 +202,7 @@ static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) { rpcFreeCont(pRsp); mnodeReleaseShowObj(pShow, false); assert(false); - return TSDB_CODE_ACTION_IN_PROGRESS; + return TSDB_CODE_MND_ACTION_IN_PROGRESS; } pRsp->numOfRows = htonl(rowsRead); @@ -224,7 +224,7 @@ static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) { SCMHeartBeatRsp *pHBRsp = (SCMHeartBeatRsp *) rpcMallocCont(sizeof(SCMHeartBeatRsp)); if (pHBRsp == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } SCMHeartBeatMsg *pHBMsg = pMsg->rpcMsg.pCont; @@ -278,7 +278,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { SRpcConnInfo connInfo; if (rpcGetConnInfo(pMsg->rpcMsg.handle, &connInfo) != 0) { mError("thandle:%p is already released while process connect msg", pMsg->rpcMsg.handle); - code = TSDB_CODE_INVALID_MSG_CONTENT; + code = TSDB_CODE_MND_INVALID_CONNECTION; goto connect_over; } @@ -295,7 +295,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { sprintf(dbName, "%x%s%s", pAcct->acctId, TS_PATH_DELIMITER, pConnectMsg->db); SDbObj *pDb = mnodeGetDb(dbName); if (pDb == NULL) { - code = TSDB_CODE_INVALID_DB; + code = TSDB_CODE_MND_INVALID_DB; goto connect_over; } mnodeDecDbRef(pDb); @@ -303,7 +303,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { SCMConnectRsp *pConnectRsp = rpcMallocCont(sizeof(SCMConnectRsp)); if (pConnectRsp == NULL) { - code = TSDB_CODE_SERV_OUT_OF_MEMORY; + code = TSDB_CODE_MND_OUT_OF_MEMORY; goto connect_over; } @@ -340,7 +340,7 @@ static int32_t mnodeProcessUseMsg(SMnodeMsg *pMsg) { int32_t code = TSDB_CODE_SUCCESS; if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pUseDbMsg->db); if (pMsg->pDb == NULL) { - code = TSDB_CODE_INVALID_DB; + code = TSDB_CODE_MND_INVALID_DB; } return code; diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 56592aff4b..73bd883e6c 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -107,21 +107,21 @@ static int32_t mnodeChildTableActionInsert(SSdbOper *pOper) { SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId); if (pVgroup == NULL) { mError("ctable:%s, not in vgId:%d", pTable->info.tableId, pTable->vgId); - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_MND_VGROUP_NOT_EXIST; } mnodeDecVgroupRef(pVgroup); SDbObj *pDb = mnodeGetDb(pVgroup->dbName); if (pDb == NULL) { mError("ctable:%s, vgId:%d not in db:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName); - return TSDB_CODE_INVALID_DB; + return TSDB_CODE_MND_INVALID_DB; } mnodeDecDbRef(pDb); SAcctObj *pAcct = mnodeGetAcct(pDb->acct); if (pAcct == NULL) { mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct); - return TSDB_CODE_INVALID_ACCT; + return TSDB_CODE_MND_INVALID_ACCT; } mnodeDecAcctRef(pAcct); @@ -145,7 +145,7 @@ static int32_t mnodeChildTableActionInsert(SSdbOper *pOper) { static int32_t mnodeChildTableActionDelete(SSdbOper *pOper) { SChildTableObj *pTable = pOper->pObj; if (pTable->vgId == 0) { - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_MND_VGROUP_NOT_EXIST; } SVgObj *pVgroup = NULL; @@ -201,7 +201,7 @@ static int32_t mnodeChildTableActionEncode(SSdbOper *pOper) { assert(pTable != NULL && pOper->rowData != NULL); int32_t len = strlen(pTable->info.tableId); - if (len > TSDB_TABLE_ID_LEN) return TSDB_CODE_INVALID_TABLE_ID; + if (len > TSDB_TABLE_ID_LEN) return TSDB_CODE_MND_INVALID_TABLE_ID; memcpy(pOper->rowData, pTable->info.tableId, len); memset(pOper->rowData + len, 0, 1); @@ -229,12 +229,12 @@ static int32_t mnodeChildTableActionEncode(SSdbOper *pOper) { static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) { assert(pOper->rowData != NULL); SChildTableObj *pTable = calloc(1, sizeof(SChildTableObj)); - if (pTable == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pTable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; int32_t len = strlen(pOper->rowData); if (len > TSDB_TABLE_ID_LEN) { free(pTable); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } pTable->info.tableId = strdup(pOper->rowData); len++; @@ -247,7 +247,7 @@ static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) { pTable->schema = (SSchema *)malloc(schemaSize); if (pTable->schema == NULL) { mnodeDestroyChildTable(pTable); - return TSDB_CODE_INVALID_TABLE_TYPE; + return TSDB_CODE_MND_INVALID_TABLE_TYPE; } memcpy(pTable->schema, pOper->rowData + len, schemaSize); len += schemaSize; @@ -256,7 +256,7 @@ static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) { pTable->sql = malloc(pTable->sqlLen); if (pTable->sql == NULL) { mnodeDestroyChildTable(pTable); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } memcpy(pTable->sql, pOper->rowData + len, pTable->sqlLen); } @@ -453,7 +453,7 @@ static int32_t mnodeSuperTableActionEncode(SSdbOper *pOper) { assert(pOper->pObj != NULL && pOper->rowData != NULL); int32_t len = strlen(pStable->info.tableId); - if (len > TSDB_TABLE_ID_LEN) len = TSDB_CODE_INVALID_TABLE_ID; + if (len > TSDB_TABLE_ID_LEN) len = TSDB_CODE_MND_INVALID_TABLE_ID; memcpy(pOper->rowData, pStable->info.tableId, len); memset(pOper->rowData + len, 0, 1); @@ -474,12 +474,12 @@ static int32_t mnodeSuperTableActionEncode(SSdbOper *pOper) { static int32_t mnodeSuperTableActionDecode(SSdbOper *pOper) { assert(pOper->rowData != NULL); SSuperTableObj *pStable = (SSuperTableObj *) calloc(1, sizeof(SSuperTableObj)); - if (pStable == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pStable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; int32_t len = strlen(pOper->rowData); if (len > TSDB_TABLE_ID_LEN){ free(pStable); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } pStable->info.tableId = strdup(pOper->rowData); len++; @@ -491,7 +491,7 @@ static int32_t mnodeSuperTableActionDecode(SSdbOper *pOper) { pStable->schema = malloc(schemaSize); if (pStable->schema == NULL) { mnodeDestroySuperTable(pStable); - return TSDB_CODE_NOT_SUPER_TABLE; + return TSDB_CODE_MND_NOT_SUPER_TABLE; } memcpy(pStable->schema, pOper->rowData + len, schemaSize); @@ -668,7 +668,7 @@ static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) { if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pCreate->db); if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { mError("table:%s, failed to create, db not selected", pCreate->tableId); - return TSDB_CODE_DB_NOT_SELECTED; + return TSDB_CODE_MND_DB_NOT_SELECTED; } if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pCreate->tableId); @@ -681,7 +681,7 @@ static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) { return TSDB_CODE_SUCCESS; } else { mError("table:%s, failed to create, table already exist", pCreate->tableId); - return TSDB_CODE_TABLE_ALREADY_EXIST; + return TSDB_CODE_MND_TABLE_ALREADY_EXIST; } } @@ -699,12 +699,12 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) { if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pDrop->tableId); if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { mError("table:%s, failed to drop table, db not selected", pDrop->tableId); - return TSDB_CODE_DB_NOT_SELECTED; + return TSDB_CODE_MND_DB_NOT_SELECTED; } if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) { mError("table:%s, failed to drop table, in monitor database", pDrop->tableId); - return TSDB_CODE_MONITOR_DB_FORBIDDEN; + return TSDB_CODE_MND_MONITOR_DB_FORBIDDEN; } if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pDrop->tableId); @@ -714,7 +714,7 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) { return TSDB_CODE_SUCCESS; } else { mError("table:%s, failed to drop table, table not exist", pDrop->tableId); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } } @@ -735,14 +735,14 @@ static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) { if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pInfo->tableId); if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { mError("table:%s, failed to get table meta, db not selected", pInfo->tableId); - return TSDB_CODE_DB_NOT_SELECTED; + return TSDB_CODE_MND_DB_NOT_SELECTED; } if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pInfo->tableId); if (pMsg->pTable == NULL) { if (!pInfo->createFlag) { mError("table:%s, failed to get table meta, table not exist", pInfo->tableId); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } else { mTrace("table:%s, failed to get table meta, start auto create table ", pInfo->tableId); return mnodeAutoCreateChildTable(pMsg); @@ -761,7 +761,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { SSuperTableObj *pStable = calloc(1, sizeof(SSuperTableObj)); if (pStable == NULL) { mError("table:%s, failed to create, no enough memory", pCreate->tableId); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } pStable->info.tableId = strdup(pCreate->tableId); @@ -779,7 +779,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { if (pStable->schema == NULL) { free(pStable); mError("table:%s, failed to create, no schema input", pCreate->tableId); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } memcpy(pStable->schema, pCreate->schema, numOfCols * sizeof(SSchema)); @@ -804,7 +804,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { if (code != TSDB_CODE_SUCCESS) { mnodeDestroySuperTable(pStable); mError("table:%s, failed to create, sdb error", pCreate->tableId); - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } else { mLPrint("table:%s, is created, tags:%d fields:%d", pStable->info.tableId, pStable->numOfTags, pStable->numOfColumns); return TSDB_CODE_SUCCESS; @@ -862,18 +862,18 @@ static int32_t mnodeFindSuperTableTagIndex(SSuperTableObj *pStable, const char * static int32_t mnodeAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], int32_t ntags) { if (pStable->numOfTags + ntags > TSDB_MAX_TAGS) { mError("stable:%s, add tag, too many tags", pStable->info.tableId); - return TSDB_CODE_TOO_MANY_TAGS; + return TSDB_CODE_MND_TOO_MANY_TAGS; } for (int32_t i = 0; i < ntags; i++) { if (mnodeFindSuperTableColumnIndex(pStable, schema[i].name) > 0) { mError("stable:%s, add tag, column:%s already exist", pStable->info.tableId, schema[i].name); - return TSDB_CODE_TAG_ALREAY_EXIST; + return TSDB_CODE_MND_TAG_ALREAY_EXIST; } if (mnodeFindSuperTableTagIndex(pStable, schema[i].name) > 0) { mError("stable:%s, add tag, tag:%s already exist", pStable->info.tableId, schema[i].name); - return TSDB_CODE_FIELD_ALREAY_EXIST; + return TSDB_CODE_MND_FIELD_ALREAY_EXIST; } } @@ -898,7 +898,7 @@ static int32_t mnodeAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("stable %s, succeed to add tag %s", pStable->info.tableId, schema[0].name); @@ -909,7 +909,7 @@ static int32_t mnodeDropSuperTableTag(SSuperTableObj *pStable, char *tagName) { int32_t col = mnodeFindSuperTableTagIndex(pStable, tagName); if (col < 0) { mError("stable:%s, drop tag, tag:%s not exist", pStable->info.tableId, tagName); - return TSDB_CODE_TAG_NOT_EXIST; + return TSDB_CODE_MND_TAG_NOT_EXIST; } memmove(pStable->schema + pStable->numOfColumns + col, pStable->schema + pStable->numOfColumns + col + 1, @@ -925,7 +925,7 @@ static int32_t mnodeDropSuperTableTag(SSuperTableObj *pStable, char *tagName) { int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("stable %s, succeed to drop tag %s", pStable->info.tableId, tagName); @@ -936,17 +936,17 @@ static int32_t mnodeModifySuperTableTagName(SSuperTableObj *pStable, char *oldTa int32_t col = mnodeFindSuperTableTagIndex(pStable, oldTagName); if (col < 0) { mError("stable:%s, failed to modify table tag, oldName: %s, newName: %s", pStable->info.tableId, oldTagName, newTagName); - return TSDB_CODE_TAG_NOT_EXIST; + return TSDB_CODE_MND_TAG_NOT_EXIST; } // int32_t rowSize = 0; uint32_t len = strlen(newTagName); if (len >= TSDB_COL_NAME_LEN) { - return TSDB_CODE_COL_NAME_TOO_LONG; + return TSDB_CODE_MND_COL_NAME_TOO_LONG; } if (mnodeFindSuperTableTagIndex(pStable, newTagName) >= 0) { - return TSDB_CODE_TAG_ALREAY_EXIST; + return TSDB_CODE_MND_TAG_ALREAY_EXIST; } // update @@ -961,7 +961,7 @@ static int32_t mnodeModifySuperTableTagName(SSuperTableObj *pStable, char *oldTa int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("stable %s, succeed to modify tag %s to %s", pStable->info.tableId, oldTagName, newTagName); @@ -982,18 +982,18 @@ static int32_t mnodeFindSuperTableColumnIndex(SSuperTableObj *pStable, char *col static int32_t mnodeAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSchema schema[], int32_t ncols) { if (ncols <= 0) { mError("stable:%s, add column, ncols:%d <= 0", pStable->info.tableId); - return TSDB_CODE_APP_ERROR; + return TSDB_CODE_MND_APP_ERROR; } for (int32_t i = 0; i < ncols; i++) { if (mnodeFindSuperTableColumnIndex(pStable, schema[i].name) > 0) { mError("stable:%s, add column, column:%s already exist", pStable->info.tableId, schema[i].name); - return TSDB_CODE_FIELD_ALREAY_EXIST; + return TSDB_CODE_MND_FIELD_ALREAY_EXIST; } if (mnodeFindSuperTableTagIndex(pStable, schema[i].name) > 0) { mError("stable:%s, add column, tag:%s already exist", pStable->info.tableId, schema[i].name); - return TSDB_CODE_TAG_ALREAY_EXIST; + return TSDB_CODE_MND_TAG_ALREAY_EXIST; } } @@ -1026,7 +1026,7 @@ static int32_t mnodeAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SS int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("stable %s, succeed to add column", pStable->info.tableId); @@ -1037,7 +1037,7 @@ static int32_t mnodeDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, c int32_t col = mnodeFindSuperTableColumnIndex(pStable, colName); if (col <= 0) { mError("stable:%s, drop column, column:%s not exist", pStable->info.tableId, colName); - return TSDB_CODE_FIELD_NOT_EXIST; + return TSDB_CODE_MND_FIELD_NOT_EXIST; } memmove(pStable->schema + col, pStable->schema + col + 1, @@ -1063,7 +1063,7 @@ static int32_t mnodeDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, c int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("stable %s, succeed to delete column", pStable->info.tableId); @@ -1073,7 +1073,7 @@ static int32_t mnodeDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, c // show super tables static int32_t mnodeGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SDbObj *pDb = mnodeGetDb(pShow->db); - if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED; + if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED; int32_t cols = 0; SSchema *pSchema = pMeta->schema; @@ -1277,7 +1277,7 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) { SCMSTableVgroupRspMsg *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } pRsp->numOfTables = 0; @@ -1333,7 +1333,7 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) { if (pRsp->numOfTables != numOfTable) { rpcFreeCont(pRsp); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } else { pRsp->numOfTables = htonl(pRsp->numOfTables); pMsg->rpcRsp.rsp = pRsp; @@ -1367,7 +1367,7 @@ static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableO SMDCreateTableMsg *pCreate = rpcMallocCont(contLen); if (pCreate == NULL) { - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_MND_OUT_OF_MEMORY; return NULL; } @@ -1424,7 +1424,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb SChildTableObj *pTable = calloc(1, sizeof(SChildTableObj)); if (pTable == NULL) { mError("table:%s, failed to alloc memory", pCreate->tableId); - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_MND_OUT_OF_MEMORY; return NULL; } @@ -1445,7 +1445,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb if (pSuperTable == NULL) { mError("table:%s, corresponding super table:%s does not exist", pCreate->tableId, pTagData->name); mnodeDestroyChildTable(pTable); - terrno = TSDB_CODE_INVALID_TABLE_ID; + terrno = TSDB_CODE_MND_INVALID_TABLE_ID; return NULL; } mnodeDecTableRef(pSuperTable); @@ -1465,7 +1465,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb pTable->schema = (SSchema *) calloc(1, schemaSize); if (pTable->schema == NULL) { free(pTable); - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_MND_OUT_OF_MEMORY; return NULL; } memcpy(pTable->schema, pCreate->schema, numOfCols * sizeof(SSchema)); @@ -1482,7 +1482,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb pTable->sql = calloc(1, pTable->sqlLen); if (pTable->sql == NULL) { free(pTable); - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_MND_OUT_OF_MEMORY; return NULL; } memcpy(pTable->sql, (char *) (pCreate->schema) + numOfCols * sizeof(SSchema), pTable->sqlLen); @@ -1499,7 +1499,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb if (sdbInsertRow(&desc) != TSDB_CODE_SUCCESS) { free(pTable); mError("table:%s, update sdb error", pCreate->tableId); - terrno = TSDB_CODE_SDB_ERROR; + terrno = TSDB_CODE_MND_SDB_ERROR; return NULL; } @@ -1560,7 +1560,7 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) { dnodeSendMsgToDnode(&ipSet, &rpcMsg); - return TSDB_CODE_ACTION_IN_PROGRESS; + return TSDB_CODE_MND_ACTION_IN_PROGRESS; } static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { @@ -1568,13 +1568,13 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId); if (pMsg->pVgroup == NULL) { mError("table:%s, failed to drop ctable, vgroup not exist", pTable->info.tableId); - return TSDB_CODE_OTHERS; + return TSDB_CODE_MND_APP_ERROR; } SMDDropTableMsg *pDrop = rpcMallocCont(sizeof(SMDDropTableMsg)); if (pDrop == NULL) { mError("table:%s, failed to drop ctable, no enough memory", pTable->info.tableId); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } strcpy(pDrop->tableId, pTable->info.tableId); @@ -1596,11 +1596,11 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { dnodeSendMsgToDnode(&ipSet, &rpcMsg); - return TSDB_CODE_ACTION_IN_PROGRESS; + return TSDB_CODE_MND_ACTION_IN_PROGRESS; } static int32_t mnodeModifyChildTableTagValue(SChildTableObj *pTable, char *tagName, char *nContent) { - return TSDB_CODE_OPS_NOT_SUPPORT; + return TSDB_CODE_COM_OPS_NOT_SUPPORT; } static int32_t mnodeFindNormalTableColumnIndex(SChildTableObj *pTable, char *colName) { @@ -1617,13 +1617,13 @@ static int32_t mnodeFindNormalTableColumnIndex(SChildTableObj *pTable, char *col static int32_t mnodeAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSchema schema[], int32_t ncols) { if (ncols <= 0) { mError("table:%s, add column, ncols:%d <= 0", pTable->info.tableId); - return TSDB_CODE_APP_ERROR; + return TSDB_CODE_MND_APP_ERROR; } for (int32_t i = 0; i < ncols; i++) { if (mnodeFindNormalTableColumnIndex(pTable, schema[i].name) > 0) { mError("table:%s, add column, column:%s already exist", pTable->info.tableId, schema[i].name); - return TSDB_CODE_FIELD_ALREAY_EXIST; + return TSDB_CODE_MND_FIELD_ALREAY_EXIST; } } @@ -1654,7 +1654,7 @@ static int32_t mnodeAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SS int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("table %s, succeed to add column", pTable->info.tableId); @@ -1665,7 +1665,7 @@ static int32_t mnodeDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, c int32_t col = mnodeFindNormalTableColumnIndex(pTable, colName); if (col <= 0) { mError("table:%s, drop column, column:%s not exist", pTable->info.tableId, colName); - return TSDB_CODE_FIELD_NOT_EXIST; + return TSDB_CODE_MND_FIELD_NOT_EXIST; } memmove(pTable->schema + col, pTable->schema + col + 1, sizeof(SSchema) * (pTable->numOfColumns - col - 1)); @@ -1686,7 +1686,7 @@ static int32_t mnodeDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, c int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("table %s, succeed to drop column %s", pTable->info.tableId, colName); @@ -1732,8 +1732,8 @@ static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) { if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId); if (pMsg->pVgroup == NULL) { - mError("table:%s, failed to get table meta, db not selected", pTable->info.tableId); - return TSDB_CODE_INVALID_VGROUP_ID; + mError("table:%s, failed to get table meta, vgroup not exist", pTable->info.tableId); + return TSDB_CODE_MND_VGROUP_NOT_EXIST; } for (int32_t i = 0; i < pMsg->pVgroup->numOfVnodes; ++i) { @@ -1759,7 +1759,7 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) { SCMCreateTableMsg *pCreateMsg = rpcMallocCont(contLen); if (pCreateMsg == NULL) { mError("table:%s, failed to create table while get meta info, no enough memory", pInfo->tableId); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } strncpy(pCreateMsg->tableId, pInfo->tableId, tListLen(pInfo->tableId)); @@ -1776,14 +1776,14 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) { pMsg->rpcMsg.pCont = pCreateMsg; pMsg->rpcMsg.contLen = contLen; - return TSDB_CODE_ACTION_NEED_REPROCESSED; + return TSDB_CODE_MND_ACTION_NEED_REPROCESSED; } static int32_t mnodeGetChildTableMeta(SMnodeMsg *pMsg) { STableMetaMsg *pMeta = rpcMallocCont(sizeof(STableMetaMsg) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16)); if (pMeta == NULL) { mError("table:%s, failed to get table meta, no enough memory", pMsg->pTable->tableId); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } mnodeDoGetChildTableMeta(pMsg, pMeta); @@ -1902,7 +1902,7 @@ static int32_t mnodeProcessTableCfgMsg(SMnodeMsg *pMsg) { SChildTableObj *pTable = mnodeGetTableByPos(pCfg->vgId, pCfg->sid); if (pTable == NULL) { mError("dnode:%d, vgId:%d sid:%d, table not found", pCfg->dnodeId, pCfg->vgId, pCfg->sid); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } SMDCreateTableMsg *pCreate = NULL; @@ -1936,7 +1936,7 @@ static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg) { if (mnodeMsg->pVgroup == NULL) mnodeMsg->pVgroup = mnodeGetVgroup(pTable->vgId); if (mnodeMsg->pVgroup == NULL) { mError("table:%s, failed to get vgroup", pTable->info.tableId); - dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_INVALID_VGROUP_ID); + dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_MND_VGROUP_NOT_EXIST); return; } @@ -1949,7 +1949,7 @@ static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg) { int32_t code = sdbDeleteRow(&oper); if (code != TSDB_CODE_SUCCESS) { mError("table:%s, update ctables sdb error", pTable->info.tableId); - dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_SDB_ERROR); + dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_MND_SDB_ERROR); return; } @@ -2018,7 +2018,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { int32_t totalMallocLen = 4 * 1024 * 1024; // first malloc 4 MB, subsequent reallocation as twice SMultiTableMeta *pMultiMeta = rpcMallocCont(totalMallocLen); if (pMultiMeta == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } pMultiMeta->contLen = sizeof(SMultiTableMeta); @@ -2041,7 +2041,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { pMultiMeta = rpcReallocCont(pMultiMeta, totalMallocLen); if (pMultiMeta == NULL) { mnodeDecTableRef(pTable); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } else { t--; mnodeDecTableRef(pTable); @@ -2067,7 +2067,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SDbObj *pDb = mnodeGetDb(pShow->db); - if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED; + if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED; int32_t cols = 0; SSchema *pSchema = pMeta->schema; @@ -2194,18 +2194,18 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) { if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pAlter->tableId); if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { mError("table:%s, failed to alter table, db not selected", pAlter->tableId); - return TSDB_CODE_DB_NOT_SELECTED; + return TSDB_CODE_MND_DB_NOT_SELECTED; } if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) { mError("table:%s, failed to alter table, its log db", pAlter->tableId); - return TSDB_CODE_MONITOR_DB_FORBIDDEN; + return TSDB_CODE_MND_MONITOR_DB_FORBIDDEN; } if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pAlter->tableId); if (pMsg->pTable == NULL) { mError("table:%s, failed to alter table, table not exist", pMsg->pTable->tableId); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } pAlter->type = htons(pAlter->type); @@ -2214,14 +2214,14 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) { if (pAlter->numOfCols > 2) { mError("table:%s, error numOfCols:%d in alter table", pAlter->tableId, pAlter->numOfCols); - return TSDB_CODE_APP_ERROR; + return TSDB_CODE_MND_APP_ERROR; } for (int32_t i = 0; i < pAlter->numOfCols; ++i) { pAlter->schema[i].bytes = htons(pAlter->schema[i].bytes); } - int32_t code = TSDB_CODE_OPS_NOT_SUPPORT; + int32_t code = TSDB_CODE_COM_OPS_NOT_SUPPORT; if (pMsg->pTable->type == TSDB_SUPER_TABLE) { SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable; mTrace("table:%s, start to alter stable", pAlter->tableId); @@ -2256,7 +2256,7 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeGetStreamTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SDbObj *pDb = mnodeGetDb(pShow->db); - if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED; + if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED; int32_t cols = 0; SSchema *pSchema = pMeta->schema; diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index 209b439275..aab0847a6b 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -56,7 +56,7 @@ static int32_t mnodeUserActionInsert(SSdbOper *pOper) { mnodeDecAcctRef(pAcct); } else { mError("user:%s, acct:%s info not exist in sdb", pUser->user, pUser->acct); - return TSDB_CODE_INVALID_ACCT; + return TSDB_CODE_MND_INVALID_ACCT; } return TSDB_CODE_SUCCESS; @@ -94,7 +94,7 @@ static int32_t mnodeUserActionEncode(SSdbOper *pOper) { static int32_t mnodeUserActionDecode(SSdbOper *pOper) { SUserObj *pUser = (SUserObj *)calloc(1, sizeof(SUserObj)); - if (pUser == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pUser == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pUser, pOper->rowData, tsUserUpdateSize); pOper->pObj = pUser; @@ -179,7 +179,7 @@ static int32_t mnodeUpdateUser(SUserObj *pUser) { int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } return code; @@ -192,18 +192,18 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass) { } if (name[0] == 0) { - return TSDB_CODE_INVALID_USER_FORMAT; + return TSDB_CODE_MND_INVALID_USER_FORMAT; } if (pass[0] == 0) { - return TSDB_CODE_INVALID_PASS_FORMAT; + return TSDB_CODE_MND_INVALID_PASS_FORMAT; } SUserObj *pUser = mnodeGetUser(name); if (pUser != NULL) { mTrace("user:%s, is already there", name); mnodeDecUserRef(pUser); - return TSDB_CODE_USER_ALREADY_EXIST; + return TSDB_CODE_MND_USER_ALREADY_EXIST; } code = grantCheck(TSDB_GRANT_USER); @@ -232,7 +232,7 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass) { code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { tfree(pUser); - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } return code; @@ -247,7 +247,7 @@ static int32_t mnodeDropUser(SUserObj *pUser) { int32_t code = sdbDeleteRow(&oper); if (code != TSDB_CODE_SUCCESS) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } return code; @@ -256,7 +256,7 @@ static int32_t mnodeDropUser(SUserObj *pUser) { static int32_t mnodeGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) { - return TSDB_CODE_NO_USER_FROM_CONN; + return TSDB_CODE_MND_NO_USER_FROM_CONN; } int32_t cols = 0; @@ -369,7 +369,7 @@ static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) { } } else { mError("user:%s, no rights to create user", pOperUser->user); - code = TSDB_CODE_NO_RIGHTS; + code = TSDB_CODE_MND_NO_RIGHTS; } return code; @@ -382,12 +382,12 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) { SCMAlterUserMsg *pAlter = pMsg->rpcMsg.pCont; SUserObj *pUser = mnodeGetUser(pAlter->user); if (pUser == NULL) { - return TSDB_CODE_INVALID_USER; + return TSDB_CODE_MND_INVALID_USER; } if (strcmp(pUser->user, "monitor") == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } if ((pAlter->flag & TSDB_ALTER_USER_PASSWD) != 0) { @@ -413,7 +413,7 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) { mLPrint("user:%s, password is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code)); } else { mError("user:%s, no rights to alter user", pOperUser->user); - code = TSDB_CODE_NO_RIGHTS; + code = TSDB_CODE_MND_NO_RIGHTS; } } else if ((pAlter->flag & TSDB_ALTER_USER_PRIVILEGES) != 0) { bool hasRight = false; @@ -454,11 +454,11 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) { mLPrint("user:%s, privilege is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code)); } else { mError("user:%s, no rights to alter user", pOperUser->user); - code = TSDB_CODE_NO_RIGHTS; + code = TSDB_CODE_MND_NO_RIGHTS; } } else { mError("user:%s, no rights to alter user", pOperUser->user); - code = TSDB_CODE_NO_RIGHTS; + code = TSDB_CODE_MND_NO_RIGHTS; } mnodeDecUserRef(pUser); @@ -472,13 +472,13 @@ static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg) { SCMDropUserMsg *pDrop = pMsg->rpcMsg.pCont; SUserObj *pUser = mnodeGetUser(pDrop->user); if (pUser == NULL) { - return TSDB_CODE_INVALID_USER; + return TSDB_CODE_MND_INVALID_USER; } if (strcmp(pUser->user, "monitor") == 0 || strcmp(pUser->user, pUser->acct) == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } bool hasRight = false; @@ -502,7 +502,7 @@ static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg) { mLPrint("user:%s, is dropped by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code)); } } else { - code = TSDB_CODE_NO_RIGHTS; + code = TSDB_CODE_MND_NO_RIGHTS; } mnodeDecUserRef(pUser); @@ -540,15 +540,15 @@ void mnodeDropAllUsers(SAcctObj *pAcct) { int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey) { if (!sdbIsMaster()) { *secret = 0; - mTrace("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_NOT_READY)); - return TSDB_CODE_NOT_READY; + mTrace("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_RPC_NOT_READY)); + return TSDB_CODE_RPC_NOT_READY; } SUserObj *pUser = mnodeGetUser(user); if (pUser == NULL) { *secret = 0; - mError("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_INVALID_USER)); - return TSDB_CODE_INVALID_USER; + mError("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_MND_INVALID_USER)); + return TSDB_CODE_MND_INVALID_USER; } else { *spi = 1; *encrypt = 0; diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 920d8503b2..7274c879c6 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -68,7 +68,7 @@ static int32_t mnodeVgroupActionInsert(SSdbOper *pOper) { // refer to db SDbObj *pDb = mnodeGetDb(pVgroup->dbName); if (pDb == NULL) { - return TSDB_CODE_INVALID_DB; + return TSDB_CODE_MND_INVALID_DB; } pVgroup->pDb = pDb; @@ -185,7 +185,7 @@ static int32_t mnodeVgroupActionEncode(SSdbOper *pOper) { static int32_t mnodeVgroupActionDecode(SSdbOper *pOper) { SVgObj *pVgroup = (SVgObj *) calloc(1, sizeof(SVgObj)); - if (pVgroup == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pVgroup == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pVgroup, pOper->rowData, tsVgUpdateSize); pOper->pObj = pVgroup; @@ -307,7 +307,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { if (balanceAllocVnodes(pVgroup) != 0) { mError("db:%s, no enough dnode to alloc %d vnodes to vgroup", pDb->name, pVgroup->numOfVnodes); free(pVgroup); - return TSDB_CODE_NO_ENOUGH_DNODES; + return TSDB_CODE_MND_NO_ENOUGH_DNODES; } SSdbOper oper = { @@ -320,7 +320,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { int32_t code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { tfree(pVgroup); - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("vgId:%d, is created in mnode, db:%s replica:%d", pVgroup->vgId, pDb->name, pVgroup->numOfVnodes); @@ -333,7 +333,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { pMsg->expected = pVgroup->numOfVnodes; mnodeSendCreateVgroupMsg(pVgroup, pMsg); - return TSDB_CODE_ACTION_IN_PROGRESS; + return TSDB_CODE_MND_ACTION_IN_PROGRESS; } void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle) { @@ -358,7 +358,7 @@ void mnodeCleanupVgroups() { int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SDbObj *pDb = mnodeGetDb(pShow->db); if (pDb == NULL) { - return TSDB_CODE_DB_NOT_SELECTED; + return TSDB_CODE_MND_DB_NOT_SELECTED; } int32_t cols = 0; @@ -383,11 +383,11 @@ int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { pTable = mnodeGetTable(pShow->payload); if (NULL == pTable || pTable->type == TSDB_SUPER_TABLE) { mnodeDecTableRef(pTable); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } mnodeDecTableRef(pTable); pVgroup = mnodeGetVgroup(((SChildTableObj*)pTable)->vgId); - if (NULL == pVgroup) return TSDB_CODE_INVALID_TABLE_ID; + if (NULL == pVgroup) return TSDB_CODE_MND_INVALID_TABLE_ID; mnodeDecVgroupRef(pVgroup); maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica; } else { @@ -643,7 +643,7 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { }; int32_t code = sdbDeleteRow(&oper); if (code != 0) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } dnodeSendRpcMnodeWriteRsp(mnodeMsg, code); @@ -704,7 +704,7 @@ static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg) { }; int32_t code = sdbDeleteRow(&oper); if (code != 0) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } dnodeReprocessMnodeWriteMsg(mnodeMsg); @@ -718,14 +718,14 @@ static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) { SDnodeObj *pDnode = mnodeGetDnode(pCfg->dnodeId); if (pDnode == NULL) { mTrace("dnode:%s, invalid dnode", taosIpStr(pCfg->dnodeId), pCfg->vgId); - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_MND_VGROUP_NOT_EXIST; } mnodeDecDnodeRef(pDnode); SVgObj *pVgroup = mnodeGetVgroup(pCfg->vgId); if (pVgroup == NULL) { mTrace("dnode:%s, vgId:%d, no vgroup info", taosIpStr(pCfg->dnodeId), pCfg->vgId); - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_MND_VGROUP_NOT_EXIST; } mnodeDecVgroupRef(pVgroup); diff --git a/src/mnode/src/mnodeWrite.c b/src/mnode/src/mnodeWrite.c index 8b3d82d32a..29b2e6c82b 100644 --- a/src/mnode/src/mnodeWrite.c +++ b/src/mnode/src/mnodeWrite.c @@ -44,7 +44,7 @@ void mnodeAddWriteMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg)) int32_t mnodeProcessWrite(SMnodeMsg *pMsg) { if (pMsg->rpcMsg.pCont == NULL) { mError("%p, msg:%s in mwrite queue, content is null", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_INVALID_MSG_LEN; + return TSDB_CODE_MND_INVALID_MSG_LEN; } if (!sdbIsMaster()) { @@ -59,12 +59,12 @@ int32_t mnodeProcessWrite(SMnodeMsg *pMsg) { mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[i])); } - return TSDB_CODE_REDIRECT; + return TSDB_CODE_RPC_REDIRECT; } if (tsMnodeProcessWriteMsgFp[pMsg->rpcMsg.msgType] == NULL) { mError("%p, msg:%s in mwrite queue, not processed", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_MSG_NOT_PROCESSED; + return TSDB_CODE_MND_MSG_NOT_PROCESSED; } int32_t code = mnodeInitMsg(pMsg); @@ -75,7 +75,7 @@ int32_t mnodeProcessWrite(SMnodeMsg *pMsg) { if (!pMsg->pUser->writeAuth) { mError("%p, msg:%s in mwrite queue, not processed, no write auth", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } return (*tsMnodeProcessWriteMsgFp[pMsg->rpcMsg.msgType])(pMsg); diff --git a/src/plugins/http/src/httpJson.c b/src/plugins/http/src/httpJson.c index 74e3c409a1..950258533f 100644 --- a/src/plugins/http/src/httpJson.c +++ b/src/plugins/http/src/httpJson.c @@ -443,9 +443,9 @@ void httpJsonPairStatus(JsonBuf* buf, int code) { httpJsonPairIntVal(buf, "code", 4, code); if (code >= 0) { httpJsonItemToken(buf); - if (code == TSDB_CODE_DB_NOT_SELECTED) { + if (code == TSDB_CODE_MND_DB_NOT_SELECTED) { httpJsonPair(buf, "desc", 4, "failed to create database", 23); - } else if (code == TSDB_CODE_INVALID_TABLE_ID) { + } else if (code == TSDB_CODE_MND_INVALID_TABLE_ID) { httpJsonPair(buf, "desc", 4, "failed to create table", 22); } else httpJsonPair(buf, "desc", 4, (char*)tstrerror(code), (int)strlen(tstrerror(code))); diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index c82a235eba..af9ad8e38a 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -80,7 +80,7 @@ void httpProcessMultiSqlCallBack(void *param, TAOS_RES *result, int code) { HttpSqlCmd *singleCmd = multiCmds->cmds + multiCmds->pos; char * sql = httpGetCmdsString(pContext, singleCmd->sql); - if (code == TSDB_CODE_ACTION_IN_PROGRESS) { + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { httpWarn("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, code:%s:inprogress, sql:%s", pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, tstrerror(code), sql); return; @@ -234,7 +234,7 @@ void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int code) { HttpEncodeMethod *encode = pContext->encodeMethod; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) { + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%s:inprogress, sqlObj:%p", pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, tstrerror(code), (SSqlObj *)result); return; @@ -242,7 +242,7 @@ void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int code) { if (code < 0) { SSqlObj *pObj = (SSqlObj *)result; - if (code == TSDB_CODE_INVALID_SQL) { + if (code == TSDB_CODE_TSC_INVALID_SQL) { httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%s, sqlObj:%p, error:%s", pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, tstrerror(code), pObj, pObj->cmd.payload); httpSendTaosdInvalidSqlErrorResp(pContext, pObj->cmd.payload); diff --git a/src/plugins/http/src/tgJson.c b/src/plugins/http/src/tgJson.c index 27059010b8..6c0b3c8663 100644 --- a/src/plugins/http/src/tgJson.c +++ b/src/plugins/http/src/tgJson.c @@ -103,7 +103,7 @@ bool tgCheckFinished(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) { if (cmd->cmdType == HTTP_CMD_TYPE_INSERT) { if (cmd->cmdState == HTTP_CMD_STATE_NOT_RUN_YET) { - if (code == TSDB_CODE_DB_NOT_SELECTED || code == TSDB_CODE_INVALID_DB) { + if (code == TSDB_CODE_MND_DB_NOT_SELECTED || code == TSDB_CODE_MND_INVALID_DB) { cmd->cmdState = HTTP_CMD_STATE_RUN_FINISHED; if (multiCmds->cmds[0].cmdState == HTTP_CMD_STATE_NOT_RUN_YET) { multiCmds->pos = (int16_t)-1; @@ -111,7 +111,7 @@ bool tgCheckFinished(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) { pContext->ipstr); return false; } - } else if (code == TSDB_CODE_INVALID_TABLE_ID) { + } else if (code == TSDB_CODE_MND_INVALID_TABLE_ID) { cmd->cmdState = HTTP_CMD_STATE_RUN_FINISHED; if (multiCmds->cmds[multiCmds->pos - 1].cmdState == HTTP_CMD_STATE_NOT_RUN_YET) { multiCmds->pos = (int16_t)(multiCmds->pos - 2); diff --git a/src/plugins/monitor/src/monitorMain.c b/src/plugins/monitor/src/monitorMain.c index 5275dd9d6c..01e276da64 100644 --- a/src/plugins/monitor/src/monitorMain.c +++ b/src/plugins/monitor/src/monitorMain.c @@ -207,7 +207,7 @@ static void monitorInitDatabase() { } static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) { - if (-code == TSDB_CODE_TABLE_ALREADY_EXIST || -code == TSDB_CODE_DB_ALREADY_EXIST || code >= 0) { + if (-code == TSDB_CODE_MND_TABLE_ALREADY_EXIST || -code == TSDB_CODE_MND_DB_ALREADY_EXIST || code >= 0) { monitorTrace("monitor:%p, sql success, reason:%d, %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql); if (tsMonitorConn.cmdIndex == MONITOR_CMD_CREATE_TB_LOG) { monitorPrint("dnode:%s is started", tsLocalEp); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 6824d305c3..f148e25e6a 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1434,7 +1434,7 @@ _clean: tfree(pRuntimeEnv->resultInfo); tfree(pRuntimeEnv->pCtx); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_QRY_OUT_OF_MEMORY; } static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { @@ -1475,7 +1475,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { } static bool isQueryKilled(SQInfo *pQInfo) { - return (pQInfo->code == TSDB_CODE_QUERY_CANCELLED); + return (pQInfo->code == TSDB_CODE_TSC_QUERY_CANCELLED); #if 0 /* * check if the queried meter is going to be deleted. @@ -1491,7 +1491,7 @@ static bool isQueryKilled(SQInfo *pQInfo) { #endif } -static void setQueryKilled(SQInfo *pQInfo) { pQInfo->code = TSDB_CODE_QUERY_CANCELLED; } +static void setQueryKilled(SQInfo *pQInfo) { pQInfo->code = TSDB_CODE_TSC_QUERY_CANCELLED; } static bool isFixedOutputQuery(SQuery *pQuery) { if (pQuery->intervalTime != 0) { @@ -4973,7 +4973,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, // query msg safety check if (!validateQueryMsg(pQueryMsg)) { - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } char *pMsg = (char *)(pQueryMsg->colList) + sizeof(SColumnInfo) * pQueryMsg->numOfCols; @@ -5046,11 +5046,11 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, if (pExprMsg->functionId == TSDB_FUNC_TAG || pExprMsg->functionId == TSDB_FUNC_TAGPRJ || pExprMsg->functionId == TSDB_FUNC_TAG_DUMMY) { if (pExprMsg->colInfo.flag != TSDB_COL_TAG) { // ignore the column index check for arithmetic expression. - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } } else { // if (!validateExprColumnInfo(pQueryMsg, pExprMsg)) { -// return TSDB_CODE_INVALID_QUERY_MSG; +// return TSDB_CODE_QRY_INVALID_MSG; // } } @@ -5060,7 +5060,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, if (!validateQuerySourceCols(pQueryMsg, *pExpr)) { tfree(*pExpr); - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } pMsg = createTableIdList(pQueryMsg, pMsg, pTableIdList); @@ -5149,7 +5149,7 @@ static int32_t buildAirthmeticExprFromMsg(SExprInfo *pArithExprInfo, SQueryTable if (pExprNode == NULL) { qError("qmsg:%p failed to create arithmetic expression string from:%s", pQueryMsg, pArithExprInfo->base.arg[0].argValue.pz); - return TSDB_CODE_APP_ERROR; + return TSDB_CODE_QRY_APP_ERROR; } pArithExprInfo->pExpr = pExprNode; @@ -5163,7 +5163,7 @@ static int32_t createSqlFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo SExprInfo *pExprs = (SExprInfo *)calloc(1, sizeof(SExprInfo) * pQueryMsg->numOfOutput); if (pExprs == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_QRY_OUT_OF_MEMORY; } bool isSuperTable = QUERY_IS_STABLE_QUERY(pQueryMsg->queryType); @@ -5203,7 +5203,7 @@ static int32_t createSqlFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo if (getResultDataInfo(type, bytes, pExprs[i].base.functionId, param, &pExprs[i].type, &pExprs[i].bytes, &pExprs[i].interBytes, 0, isSuperTable) != TSDB_CODE_SUCCESS) { tfree(pExprs); - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } if (pExprs[i].base.functionId == TSDB_FUNC_TAG_DUMMY || pExprs[i].base.functionId == TSDB_FUNC_TS_DUMMY) { @@ -5244,7 +5244,7 @@ static SSqlGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SCol // using group by tag columns SSqlGroupbyExpr *pGroupbyExpr = (SSqlGroupbyExpr *)calloc(1, sizeof(SSqlGroupbyExpr)); if (pGroupbyExpr == NULL) { - *code = TSDB_CODE_SERV_OUT_OF_MEMORY; + *code = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; } @@ -5292,7 +5292,7 @@ static int32_t createFilterInfo(void *pQInfo, SQuery *pQuery) { if (lower == TSDB_RELATION_INVALID && upper == TSDB_RELATION_INVALID) { qError("QInfo:%p invalid filter info", pQInfo); - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } int16_t type = pQuery->colList[i].type; @@ -5304,7 +5304,7 @@ static int32_t createFilterInfo(void *pQInfo, SQuery *pQuery) { if (rangeFilterArray == NULL && filterArray == NULL) { qError("QInfo:%p failed to get filter function, invalid data type:%d", pQInfo, type); - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } if ((lower == TSDB_RELATION_GREATER_EQUAL || lower == TSDB_RELATION_GREATER) && @@ -5328,7 +5328,7 @@ static int32_t createFilterInfo(void *pQInfo, SQuery *pQuery) { if (upper != TSDB_RELATION_INVALID) { qError("pQInfo:%p failed to get filter function, invalid filter condition", pQInfo, type); - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } } else { pSingleColFilter->fp = filterArray[upper]; @@ -5777,13 +5777,13 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi if (pQueryMsg->numOfTables <= 0) { qError("Invalid number of tables to query, numOfTables:%d", pQueryMsg->numOfTables); - code = TSDB_CODE_INVALID_QUERY_MSG; + code = TSDB_CODE_QRY_INVALID_MSG; goto _over; } if (pTableIdList == NULL || taosArrayGetSize(pTableIdList) == 0) { qError("qmsg:%p, SQueryTableMsg wrong format", pQueryMsg); - code = TSDB_CODE_INVALID_QUERY_MSG; + code = TSDB_CODE_QRY_INVALID_MSG; goto _over; } @@ -5846,7 +5846,7 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi (*pQInfo) = createQInfoImpl(pQueryMsg, pTableIdList, pGroupbyExpr, pExprs, &groupInfo, pTagColumnInfo); if ((*pQInfo) == NULL) { - code = TSDB_CODE_SERV_OUT_OF_MEMORY; + code = TSDB_CODE_QRY_OUT_OF_MEMORY; goto _over; } @@ -5905,7 +5905,7 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo) { SQInfo *pQInfo = (SQInfo *)qinfo; if (pQInfo == NULL || !isValidQInfo(pQInfo)) { - return TSDB_CODE_INVALID_QHANDLE; + return TSDB_CODE_QRY_INVALID_QHANDLE; } SQuery *pQuery = pQInfo->runtimeEnv.pQuery; @@ -5944,7 +5944,7 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co SQInfo *pQInfo = (SQInfo *)qinfo; if (pQInfo == NULL || !isValidQInfo(pQInfo)) { - return TSDB_CODE_INVALID_QHANDLE; + return TSDB_CODE_QRY_INVALID_QHANDLE; } SQueryRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv; @@ -5980,12 +5980,6 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co } return code; - - // if (numOfRows == 0 && (pRetrieve->qhandle == (uint64_t)pObj->qhandle) && (code != TSDB_CODE_ACTION_IN_PROGRESS)) { - // qTrace("QInfo:%p %s free qhandle code:%d", pObj->qhandle, __FUNCTION__, code); - // vnodeDecRefCount(pObj->qhandle); - // pObj->qhandle = NULL; - // } } static void buildTagQueryResult(SQInfo* pQInfo) { diff --git a/src/query/src/qast.c b/src/query/src/qast.c index f35f4d0184..0a0fe56ebd 100644 --- a/src/query/src/qast.c +++ b/src/query/src/qast.c @@ -1035,7 +1035,7 @@ void exprTreeToBinary(SBufferWriter* bw, tExprNode* expr) { static void* exception_calloc(size_t nmemb, size_t size) { void* p = calloc(nmemb, size); if (p == NULL) { - THROW(TSDB_CODE_SERV_OUT_OF_MEMORY); + THROW(TSDB_CODE_QRY_OUT_OF_MEMORY); } return p; } @@ -1043,7 +1043,7 @@ static void* exception_calloc(size_t nmemb, size_t size) { static void* exception_malloc(size_t size) { void* p = malloc(size); if (p == NULL) { - THROW(TSDB_CODE_SERV_OUT_OF_MEMORY); + THROW(TSDB_CODE_QRY_OUT_OF_MEMORY); } return p; } @@ -1051,7 +1051,7 @@ static void* exception_malloc(size_t size) { static UNUSED_FUNC char* exception_strdup(const char* str) { char* p = strdup(str); if (p == NULL) { - THROW(TSDB_CODE_SERV_OUT_OF_MEMORY); + THROW(TSDB_CODE_QRY_OUT_OF_MEMORY); } return p; } diff --git a/src/query/src/qresultBuf.c b/src/query/src/qresultBuf.c index 8910d84830..222e922176 100644 --- a/src/query/src/qresultBuf.c +++ b/src/query/src/qresultBuf.c @@ -28,19 +28,19 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t si if (!FD_VALID(pResBuf->fd)) { qError("failed to create tmp file: %s on disk. %s", pResBuf->path, strerror(errno)); - return TSDB_CODE_CLI_NO_DISKSPACE; + return TSDB_CODE_QRY_NO_DISKSPACE; } int32_t ret = ftruncate(pResBuf->fd, pResBuf->numOfPages * DEFAULT_INTERN_BUF_PAGE_SIZE); if (ret != TSDB_CODE_SUCCESS) { qError("failed to create tmp file: %s on disk. %s", pResBuf->path, strerror(errno)); - return TSDB_CODE_CLI_NO_DISKSPACE; + return TSDB_CODE_QRY_NO_DISKSPACE; } pResBuf->pBuf = mmap(NULL, pResBuf->totalBufSize, PROT_READ | PROT_WRITE, MAP_SHARED, pResBuf->fd, 0); if (pResBuf->pBuf == MAP_FAILED) { qError("QInfo:%p failed to map temp file: %s. %s", handle, pResBuf->path, strerror(errno)); - return TSDB_CODE_CLI_OUT_OF_MEMORY; // todo change error code + return TSDB_CODE_QRY_OUT_OF_MEMORY; // todo change error code } qTrace("QInfo:%p create tmp file for output result, %s, %" PRId64 "bytes", handle, pResBuf->path, @@ -74,7 +74,7 @@ static int32_t extendDiskFileSize(SDiskbasedResultBuf* pResultBuf, int32_t numOf if (ret != 0) { // dError("QInfo:%p failed to create intermediate result output file:%s. %s", pQInfo, pSupporter->extBufFile, // strerror(errno)); - return -TSDB_CODE_SERV_NO_DISKSPACE; + return -TSDB_CODE_QRY_NO_DISKSPACE; } pResultBuf->totalBufSize = pResultBuf->numOfPages * DEFAULT_INTERN_BUF_PAGE_SIZE; @@ -82,7 +82,7 @@ static int32_t extendDiskFileSize(SDiskbasedResultBuf* pResultBuf, int32_t numOf if (pResultBuf->pBuf == MAP_FAILED) { // dError("QInfo:%p failed to map temp file: %s. %s", pQInfo, pSupporter->extBufFile, strerror(errno)); - return -TSDB_CODE_SERV_OUT_OF_MEMORY; + return -TSDB_CODE_QRY_OUT_OF_MEMORY; } return TSDB_CODE_SUCCESS; diff --git a/src/query/src/tlosertree.c b/src/query/src/tlosertree.c index 0d81f4604b..5d471bb927 100644 --- a/src/query/src/tlosertree.c +++ b/src/query/src/tlosertree.c @@ -46,7 +46,7 @@ uint32_t tLoserTreeCreate(SLoserTreeInfo** pTree, int32_t numOfEntries, void* pa *pTree = (SLoserTreeInfo*)calloc(1, sizeof(SLoserTreeInfo) + sizeof(SLoserTreeNode) * totalEntries); if ((*pTree) == NULL) { qError("allocate memory for loser-tree failed. reason:%s", strerror(errno)); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_QRY_OUT_OF_MEMORY; } (*pTree)->pNode = (SLoserTreeNode*)(((char*)(*pTree)) + sizeof(SLoserTreeInfo)); diff --git a/src/query/tests/unitTest.cpp b/src/query/tests/unitTest.cpp index df28a3e4d1..c33ebeb58b 100644 --- a/src/query/tests/unitTest.cpp +++ b/src/query/tests/unitTest.cpp @@ -99,47 +99,47 @@ TEST(testCase, db_table_name) { EXPECT_EQ(testValidateName(t4), TSDB_CODE_SUCCESS); char t5[] = "table.'def'"; - EXPECT_EQ(testValidateName(t5), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t5), TSDB_CODE_TSC_INVALID_SQL); char t6[] = "'table'.'def'"; - EXPECT_EQ(testValidateName(t6), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t6), TSDB_CODE_TSC_INVALID_SQL); char t7[] = "'_ab1234'.'def'"; EXPECT_EQ(testValidateName(t7), TSDB_CODE_SUCCESS); printf("%s\n", t7); char t8[] = "'_ab&^%1234'.'def'"; - EXPECT_EQ(testValidateName(t8), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t8), TSDB_CODE_TSC_INVALID_SQL); char t9[] = "'_123'.'gtest中文'"; - EXPECT_EQ(testValidateName(t9), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t9), TSDB_CODE_TSC_INVALID_SQL); char t10[] = "abc.'gtest中文'"; - EXPECT_EQ(testValidateName(t10), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t10), TSDB_CODE_TSC_INVALID_SQL); char t10_1[] = "abc.'中文gtest'"; - EXPECT_EQ(testValidateName(t10_1), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t10_1), TSDB_CODE_TSC_INVALID_SQL); char t11[] = "'192.168.0.1'.abc"; - EXPECT_EQ(testValidateName(t11), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t11), TSDB_CODE_TSC_INVALID_SQL); char t12[] = "192.168.0.1.abc"; - EXPECT_EQ(testValidateName(t12), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t12), TSDB_CODE_TSC_INVALID_SQL); char t13[] = "abc."; - EXPECT_EQ(testValidateName(t13), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t13), TSDB_CODE_TSC_INVALID_SQL); char t14[] = ".abc"; - EXPECT_EQ(testValidateName(t14), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t14), TSDB_CODE_TSC_INVALID_SQL); char t15[] = ".'abc'"; - EXPECT_EQ(testValidateName(t15), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t15), TSDB_CODE_TSC_INVALID_SQL); char t16[] = ".abc'"; - EXPECT_EQ(testValidateName(t16), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t16), TSDB_CODE_TSC_INVALID_SQL); char t17[] = "123a.\"abc\""; - EXPECT_EQ(testValidateName(t17), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t17), TSDB_CODE_TSC_INVALID_SQL); printf("%s\n", t17); char t18[] = "a.\"abc\""; @@ -147,13 +147,13 @@ TEST(testCase, db_table_name) { printf("%s\n", t18); char t19[] = "'_ab1234'.'def'.'ab123'"; - EXPECT_EQ(testValidateName(t19), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t19), TSDB_CODE_TSC_INVALID_SQL); char t20[] = "'_ab1234*&^'"; - EXPECT_EQ(testValidateName(t20), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t20), TSDB_CODE_TSC_INVALID_SQL); char t21[] = "'1234_abc'"; - EXPECT_EQ(testValidateName(t21), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t21), TSDB_CODE_TSC_INVALID_SQL); // =======Containing capital letters================= @@ -167,10 +167,10 @@ TEST(testCase, db_table_name) { EXPECT_EQ(testValidateName(t32), TSDB_CODE_SUCCESS); char t33[] = "'ABC.def"; - EXPECT_EQ(testValidateName(t33), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t33), TSDB_CODE_TSC_INVALID_SQL); char t33_0[] = "abc.DEF'"; - EXPECT_EQ(testValidateName(t33_0), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t33_0), TSDB_CODE_TSC_INVALID_SQL); char t34[] = "'ABC.def'"; //int32_t tmp0 = testValidateName(t34); @@ -193,38 +193,38 @@ TEST(testCase, db_table_name) { // do not use key words char t39[] = "table.'DEF'"; - EXPECT_EQ(testValidateName(t39), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t39), TSDB_CODE_TSC_INVALID_SQL); char t40[] = "'table'.'DEF'"; - EXPECT_EQ(testValidateName(t40), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t40), TSDB_CODE_TSC_INVALID_SQL); char t41[] = "'_abXYZ1234'.'deFF'"; EXPECT_EQ(testValidateName(t41), TSDB_CODE_SUCCESS); char t42[] = "'_abDEF&^%1234'.'DIef'"; - EXPECT_EQ(testValidateName(t42), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t42), TSDB_CODE_TSC_INVALID_SQL); char t43[] = "'_123'.'Gtest中文'"; - EXPECT_EQ(testValidateName(t43), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t43), TSDB_CODE_TSC_INVALID_SQL); char t44[] = "'aABC'.'Gtest中文'"; - EXPECT_EQ(testValidateName(t44), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t44), TSDB_CODE_TSC_INVALID_SQL); char t45[] = "'ABC'."; - EXPECT_EQ(testValidateName(t45), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t45), TSDB_CODE_TSC_INVALID_SQL); char t46[] = ".'ABC'"; - EXPECT_EQ(testValidateName(t46), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t46), TSDB_CODE_TSC_INVALID_SQL); char t47[] = "a.\"aTWc\""; EXPECT_EQ(testValidateName(t47), TSDB_CODE_SUCCESS); // ================has space ================= char t60[] = " ABC "; - EXPECT_EQ(testValidateName(t60), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t60), TSDB_CODE_TSC_INVALID_SQL); char t60_1[] = " ABC "; - EXPECT_EQ(testValidateName(t60_1), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t60_1), TSDB_CODE_TSC_INVALID_SQL); char t61[] = "' ABC '"; EXPECT_EQ(testValidateName(t61), TSDB_CODE_SUCCESS); @@ -233,96 +233,96 @@ TEST(testCase, db_table_name) { EXPECT_EQ(testValidateName(t61_1), TSDB_CODE_SUCCESS); char t62[] = " ABC . def "; - EXPECT_EQ(testValidateName(t62), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t62), TSDB_CODE_TSC_INVALID_SQL); char t63[] = "' ABC . def "; - EXPECT_EQ(testValidateName(t63), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t63), TSDB_CODE_TSC_INVALID_SQL); char t63_0[] = " abc . DEF ' "; - EXPECT_EQ(testValidateName(t63_0), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t63_0), TSDB_CODE_TSC_INVALID_SQL); char t64[] = " ' ABC . def ' "; //int32_t tmp1 = testValidateName(t64); - EXPECT_EQ(testValidateName(t64), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t64), TSDB_CODE_TSC_INVALID_SQL); char t65[] = " ' ABC '. def "; - EXPECT_EQ(testValidateName(t65), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t65), TSDB_CODE_TSC_INVALID_SQL); char t66[] = "' ABC '.' DEF '"; EXPECT_EQ(testValidateName(t66), TSDB_CODE_SUCCESS); char t67[] = "abc . ' DEF '"; - EXPECT_EQ(testValidateName(t67), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t67), TSDB_CODE_TSC_INVALID_SQL); char t68[] = "' abc '.' DEF '"; EXPECT_EQ(testValidateName(t68), TSDB_CODE_SUCCESS); // do not use key words char t69[] = "table.'DEF'"; - EXPECT_EQ(testValidateName(t69), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t69), TSDB_CODE_TSC_INVALID_SQL); char t70[] = "'table'.'DEF'"; - EXPECT_EQ(testValidateName(t70), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t70), TSDB_CODE_TSC_INVALID_SQL); char t71[] = "'_abXYZ1234 '.' deFF '"; EXPECT_EQ(testValidateName(t71), TSDB_CODE_SUCCESS); char t72[] = "'_abDEF&^%1234'.' DIef'"; - EXPECT_EQ(testValidateName(t72), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t72), TSDB_CODE_TSC_INVALID_SQL); char t73[] = "'_123'.' Gtest中文'"; - EXPECT_EQ(testValidateName(t73), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t73), TSDB_CODE_TSC_INVALID_SQL); char t74[] = "' aABC'.'Gtest中文'"; - EXPECT_EQ(testValidateName(t74), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t74), TSDB_CODE_TSC_INVALID_SQL); char t75[] = "' ABC '."; - EXPECT_EQ(testValidateName(t75), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t75), TSDB_CODE_TSC_INVALID_SQL); char t76[] = ".' ABC'"; - EXPECT_EQ(testValidateName(t76), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t76), TSDB_CODE_TSC_INVALID_SQL); char t77[] = " a . \"aTWc\" "; - EXPECT_EQ(testValidateName(t77), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t77), TSDB_CODE_TSC_INVALID_SQL); char t78[] = " a.\"aTWc \""; - EXPECT_EQ(testValidateName(t78), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t78), TSDB_CODE_TSC_INVALID_SQL); // ===============muti string by space =================== // There's no such case. //char t160[] = "A BC"; - //EXPECT_EQ(testValidateName(t160), TSDB_CODE_INVALID_SQL); + //EXPECT_EQ(testValidateName(t160), TSDB_CODE_TSC_INVALID_SQL); //printf("end:%s\n", t160); // There's no such case. //char t161[] = "' A BC '"; - //EXPECT_EQ(testValidateName(t161), TSDB_CODE_INVALID_SQL); + //EXPECT_EQ(testValidateName(t161), TSDB_CODE_TSC_INVALID_SQL); char t162[] = " AB C . de f "; - EXPECT_EQ(testValidateName(t162), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t162), TSDB_CODE_TSC_INVALID_SQL); char t163[] = "' AB C . de f "; - EXPECT_EQ(testValidateName(t163), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t163), TSDB_CODE_TSC_INVALID_SQL); char t163_0[] = " ab c . DE F ' "; - EXPECT_EQ(testValidateName(t163_0), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t163_0), TSDB_CODE_TSC_INVALID_SQL); char t164[] = " ' AB C . de f ' "; //int32_t tmp2 = testValidateName(t164); - EXPECT_EQ(testValidateName(t164), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t164), TSDB_CODE_TSC_INVALID_SQL); char t165[] = " ' A BC '. de f "; - EXPECT_EQ(testValidateName(t165), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t165), TSDB_CODE_TSC_INVALID_SQL); char t166[] = "' AB C '.' DE F '"; - EXPECT_EQ(testValidateName(t166), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t166), TSDB_CODE_TSC_INVALID_SQL); char t167[] = "ab c . ' D EF '"; - EXPECT_EQ(testValidateName(t167), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t167), TSDB_CODE_TSC_INVALID_SQL); char t168[] = "' a bc '.' DE F '"; - EXPECT_EQ(testValidateName(t168), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t168), TSDB_CODE_TSC_INVALID_SQL); } diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index e7861201d3..f245214ed9 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -418,7 +418,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) { rpcFreeMsg(pConn->pRspMsg); pConn->pRspMsg = msg; pConn->rspMsgLen = msgLen; - if (pMsg->code == TSDB_CODE_ACTION_IN_PROGRESS) pConn->inTranId--; + if (pMsg->code == TSDB_CODE_RPC_ACTION_IN_PROGRESS) pConn->inTranId--; SRpcInfo *pRpc = pConn->pRpc; taosTmrStopA(&pConn->pTimer); @@ -443,7 +443,7 @@ void rpcSendRedirectRsp(void *thandle, const SRpcIpSet *pIpSet) { memcpy(rpcMsg.pCont, pIpSet, sizeof(SRpcIpSet)); - rpcMsg.code = TSDB_CODE_REDIRECT; + rpcMsg.code = TSDB_CODE_RPC_REDIRECT; rpcMsg.handle = thandle; rpcSendResponse(&rpcMsg); @@ -496,7 +496,7 @@ static SRpcConn *rpcOpenConn(SRpcInfo *pRpc, char *peerFqdn, uint16_t peerPort, uint32_t peerIp = taosGetIpFromFqdn(peerFqdn); if (peerIp == -1) { tError("%s, failed to resolve FQDN:%s", pRpc->label, peerFqdn); - terrno = TSDB_CODE_APP_ERROR; + terrno = TSDB_CODE_RPC_APP_ERROR; return NULL; } @@ -513,7 +513,7 @@ static SRpcConn *rpcOpenConn(SRpcInfo *pRpc, char *peerFqdn, uint16_t peerPort, void *shandle = (connType & RPC_CONN_TCP)? pRpc->tcphandle:pRpc->udphandle; pConn->chandle = (*taosOpenConn[connType])(shandle, pConn, pConn->peerIp, pConn->peerPort); if (pConn->chandle == NULL) { - terrno = TSDB_CODE_NETWORK_UNAVAIL; + terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL; rpcCloseConn(pConn); pConn = NULL; } @@ -570,7 +570,7 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) { int sid = taosAllocateId(pRpc->idPool); if (sid <= 0) { tError("%s maximum number of sessions:%d is reached", pRpc->label, pRpc->sessions); - terrno = TSDB_CODE_MAX_SESSIONS; + terrno = TSDB_CODE_RPC_MAX_SESSIONS; } else { pConn = pRpc->connList + sid; memset(pConn, 0, sizeof(SRpcConn)); @@ -606,7 +606,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) { int sid = taosAllocateId(pRpc->idPool); if (sid <= 0) { tError("%s maximum number of sessions:%d is reached", pRpc->label, pRpc->sessions); - terrno = TSDB_CODE_MAX_SESSIONS; + terrno = TSDB_CODE_RPC_MAX_SESSIONS; } else { pConn = pRpc->connList + sid; memset(pConn, 0, sizeof(SRpcConn)); @@ -618,7 +618,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) { pConn->linkUid = pHead->linkUid; if (pRpc->afp) { if (pConn->user[0] == 0) { - terrno = TSDB_CODE_AUTH_REQUIRED; + terrno = TSDB_CODE_RPC_AUTH_REQUIRED; } else { terrno = (*pRpc->afp)(pConn->user, &pConn->spi, &pConn->encrypt, pConn->secret, pConn->ckey); } @@ -656,13 +656,13 @@ static SRpcConn *rpcGetConnObj(SRpcInfo *pRpc, int sid, SRecvInfo *pRecv) { if (pRpc->connType == TAOS_CONN_SERVER) { pConn = rpcAllocateServerConn(pRpc, pRecv); } else { - terrno = TSDB_CODE_UNEXPECTED_RESPONSE; + terrno = TSDB_CODE_RPC_UNEXPECTED_RESPONSE; } } if (pConn) { if (pConn->linkUid != pHead->linkUid) { - terrno = TSDB_CODE_MISMATCHED_METER_ID; + terrno = TSDB_CODE_RPC_MISMATCHED_LINK_ID; pConn = NULL; } } @@ -700,7 +700,7 @@ static int rpcProcessReqHead(SRpcConn *pConn, SRpcHead *pHead) { if (pConn->peerId != pHead->sourceId) { tTrace("%s, source Id is changed, old:0x%08x new:0x%08x", pConn->info, pConn->peerId, pHead->sourceId); - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_RPC_INVALID_VALUE; } } @@ -708,7 +708,7 @@ static int rpcProcessReqHead(SRpcConn *pConn, SRpcHead *pHead) { if (pConn->inType == pHead->msgType) { if (pHead->code == 0) { tTrace("%s, %s is retransmitted", pConn->info, taosMsg[pHead->msgType]); - rpcSendQuickRsp(pConn, TSDB_CODE_ACTION_IN_PROGRESS); + rpcSendQuickRsp(pConn, TSDB_CODE_RPC_ACTION_IN_PROGRESS); } else { // do nothing, it is heart beat from client } @@ -720,13 +720,13 @@ static int rpcProcessReqHead(SRpcConn *pConn, SRpcHead *pHead) { } // do not reply any message - return TSDB_CODE_ALREADY_PROCESSED; + return TSDB_CODE_RPC_ALREADY_PROCESSED; } if (pConn->inType != 0) { tTrace("%s, last session is not finished, inTranId:%d tranId:%d", pConn->info, pConn->inTranId, pHead->tranId); - return TSDB_CODE_LAST_SESSION_NOT_FINISHED; + return TSDB_CODE_RPC_LAST_SESSION_NOT_FINISHED; } pConn->inTranId = pHead->tranId; @@ -740,39 +740,39 @@ static int rpcProcessRspHead(SRpcConn *pConn, SRpcHead *pHead) { pConn->peerId = pHead->sourceId; if (pConn->outType == 0 || pConn->pContext == NULL) { - return TSDB_CODE_UNEXPECTED_RESPONSE; + return TSDB_CODE_RPC_UNEXPECTED_RESPONSE; } if (pHead->tranId != pConn->outTranId) { - return TSDB_CODE_INVALID_TRAN_ID; + return TSDB_CODE_RPC_INVALID_TRAN_ID; } if (pHead->msgType != pConn->outType + 1) { - return TSDB_CODE_INVALID_RESPONSE_TYPE; + return TSDB_CODE_RPC_INVALID_RESPONSE_TYPE; } taosTmrStopA(&pConn->pTimer); pConn->retry = 0; - if (pHead->code == TSDB_CODE_AUTH_REQUIRED && pRpc->spi) { + if (pHead->code == TSDB_CODE_RPC_AUTH_REQUIRED && pRpc->spi) { tTrace("%s, authentication shall be restarted", pConn->info); pConn->secured = 0; rpcSendMsgToPeer(pConn, pConn->pReqMsg, pConn->reqMsgLen); pConn->pTimer = taosTmrStart(rpcProcessRetryTimer, tsRpcTimer, pConn, pRpc->tmrCtrl); - return TSDB_CODE_ALREADY_PROCESSED; + return TSDB_CODE_RPC_ALREADY_PROCESSED; } - if (pHead->code == TSDB_CODE_ACTION_IN_PROGRESS) { + if (pHead->code == TSDB_CODE_RPC_ACTION_IN_PROGRESS) { if (pConn->tretry <= tsRpcMaxRetry) { tTrace("%s, peer is still processing the transaction, retry:%d", pConn->info, pConn->tretry); pConn->tretry++; rpcSendReqHead(pConn); pConn->pTimer = taosTmrStart(rpcProcessRetryTimer, tsRpcTimer, pConn, pRpc->tmrCtrl); - return TSDB_CODE_ALREADY_PROCESSED; + return TSDB_CODE_RPC_ALREADY_PROCESSED; } else { // peer still in processing, give up tTrace("%s, server processing takes too long time, give up", pConn->info); - pHead->code = TSDB_CODE_TOO_SLOW; + pHead->code = TSDB_CODE_RPC_TOO_SLOW; } } @@ -793,13 +793,13 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv) { if (pHead->msgType >= TSDB_MSG_TYPE_MAX || pHead->msgType <= 0) { tTrace("%s sid:%d, invalid message type:%d", pRpc->label, sid, pHead->msgType); - terrno = TSDB_CODE_INVALID_MSG_TYPE; return NULL; + terrno = TSDB_CODE_RPC_INVALID_MSG_TYPE; return NULL; } if (sid < 0 || sid >= pRpc->sessions) { tTrace("%s sid:%d, sid is out of range, max sid:%d, %s discarded", pRpc->label, sid, pRpc->sessions, taosMsg[pHead->msgType]); - terrno = TSDB_CODE_INVALID_SESSION_ID; return NULL; + terrno = TSDB_CODE_RPC_INVALID_SESSION_ID; return NULL; } pConn = rpcGetConnObj(pRpc, sid, pRecv); @@ -855,7 +855,7 @@ static void rpcProcessBrokenLink(SRpcConn *pConn) { if (pConn->outType) { SRpcReqContext *pContext = pConn->pContext; - pContext->code = TSDB_CODE_NETWORK_UNAVAIL; + pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; taosTmrStart(rpcProcessConnError, 0, pContext, pRpc->tmrCtrl); } @@ -868,7 +868,7 @@ static void rpcProcessBrokenLink(SRpcConn *pConn) { rpcMsg.contLen = 0; rpcMsg.handle = pConn; rpcMsg.msgType = pConn->inType; - rpcMsg.code = TSDB_CODE_NETWORK_UNAVAIL; + rpcMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL; (*(pRpc->cfp))(&rpcMsg); */ } @@ -901,7 +901,7 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { } int32_t code = terrno; - if (code != TSDB_CODE_ALREADY_PROCESSED) { + if (code != TSDB_CODE_RPC_ALREADY_PROCESSED) { if (code != 0) { // parsing error if (rpcIsReq(pHead->msgType)) { rpcSendErrorMsgToPeer(pRecv, code); @@ -960,28 +960,28 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead) { pConn->pContext = NULL; // for UDP, port may be changed by server, the port in ipSet shall be used for cache - if (pHead->code != TSDB_CODE_TOO_SLOW) { + if (pHead->code != TSDB_CODE_RPC_TOO_SLOW) { rpcAddConnIntoCache(pRpc->pCache, pConn, pConn->peerFqdn, pContext->ipSet.port[pContext->ipSet.inUse], pConn->connType); } else { rpcCloseConn(pConn); } - if (pHead->code == TSDB_CODE_REDIRECT) { + if (pHead->code == TSDB_CODE_RPC_REDIRECT) { pContext->redirect++; if (pContext->redirect > TSDB_MAX_REPLICA) { - pHead->code = TSDB_CODE_NETWORK_UNAVAIL; + pHead->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; tWarn("%s, too many redirects, quit", pConn->info); } } - if (pHead->code == TSDB_CODE_REDIRECT) { + if (pHead->code == TSDB_CODE_RPC_REDIRECT) { pContext->numOfTry = 0; memcpy(&pContext->ipSet, pHead->content, sizeof(pContext->ipSet)); tTrace("%s, redirect is received, numOfIps:%d", pConn->info, pContext->ipSet.numOfIps); for (int i=0; iipSet.numOfIps; ++i) pContext->ipSet.port[i] = htons(pContext->ipSet.port[i]); rpcSendReqToServer(pRpc, pContext); - } else if (pHead->code == TSDB_CODE_NOT_READY) { + } else if (pHead->code == TSDB_CODE_RPC_NOT_READY) { pContext->code = pHead->code; rpcProcessConnError(pContext, NULL); } else { @@ -1058,7 +1058,7 @@ static void rpcSendErrorMsgToPeer(SRecvInfo *pRecv, int32_t code) { pReplyHead->code = htonl(code); msgLen = sizeof(SRpcHead); - if (code == TSDB_CODE_INVALID_TIME_STAMP) { + if (code == TSDB_CODE_RPC_INVALID_TIME_STAMP) { // include a time stamp if client's time is not synchronized well uint8_t *pContent = pReplyHead->content; timeStamp = htonl(taosGetTimestampSec()); @@ -1200,7 +1200,7 @@ static void rpcProcessRetryTimer(void *param, void *tmrId) { rpcUnlockConn(pConn); if (reportDisc && pConn->pContext) { - pConn->pContext->code = TSDB_CODE_NETWORK_UNAVAIL; + pConn->pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; rpcProcessConnError(pConn->pContext, NULL); rpcCloseConn(pConn); } @@ -1221,7 +1221,7 @@ static void rpcProcessIdleTimer(void *param, void *tmrId) { rpcMsg.contLen = 0; rpcMsg.handle = pConn; rpcMsg.msgType = pConn->inType; - rpcMsg.code = TSDB_CODE_NETWORK_UNAVAIL; + rpcMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL; (*(pRpc->cfp))(&rpcMsg); */ } @@ -1239,7 +1239,7 @@ static void rpcProcessProgressTimer(void *param, void *tmrId) { if (pConn->inType && pConn->user[0]) { tTrace("%s, progress timer expired, send progress", pConn->info); - rpcSendQuickRsp(pConn, TSDB_CODE_ACTION_IN_PROGRESS); + rpcSendQuickRsp(pConn, TSDB_CODE_RPC_ACTION_IN_PROGRESS); pConn->pTimer = taosTmrStart(rpcProcessProgressTimer, tsProgressTimer, pConn, pRpc->tmrCtrl); } else { tTrace("%s, progress timer:%p not processed", pConn->info, tmrId); @@ -1379,12 +1379,12 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) { if ( !rpcIsReq(pHead->msgType) ) { // for response, if code is auth failure, it shall bypass the auth process code = htonl(pHead->code); - if (code==TSDB_CODE_INVALID_TIME_STAMP || code==TSDB_CODE_AUTH_FAILURE || code == TSDB_CODE_AUTH_REQUIRED || - code==TSDB_CODE_INVALID_USER || code == TSDB_CODE_NOT_READY) { + if (code == TSDB_CODE_RPC_INVALID_TIME_STAMP || code == TSDB_CODE_RPC_AUTH_FAILURE || + code == TSDB_CODE_RPC_AUTH_REQUIRED || code == TSDB_CODE_MND_INVALID_USER || code == TSDB_CODE_RPC_NOT_READY) { pHead->msgLen = (int32_t)htonl((uint32_t)pHead->msgLen); // tTrace("%s, dont check authentication since code is:0x%x", pConn->info, code); return 0; - } + } } code = 0; @@ -1397,11 +1397,11 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) { delta -= (int32_t)taosGetTimestampSec(); if (abs(delta) > 900) { tWarn("%s, time diff:%d is too big, msg discarded", pConn->info, delta); - code = TSDB_CODE_INVALID_TIME_STAMP; + code = TSDB_CODE_RPC_INVALID_TIME_STAMP; } else { if (rpcAuthenticateMsg(pHead, msgLen-TSDB_AUTH_LEN, pDigest->auth, pConn->secret) < 0) { tTrace("%s, authentication failed, msg discarded", pConn->info); - code = TSDB_CODE_AUTH_FAILURE; + code = TSDB_CODE_RPC_AUTH_FAILURE; } else { pHead->msgLen = (int32_t)htonl((uint32_t)pHead->msgLen) - sizeof(SRpcDigest); if ( !rpcIsReq(pHead->msgType) ) pConn->secured = 1; // link is secured for client @@ -1410,7 +1410,7 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) { } } else { tTrace("%s, auth spi:%d not matched with received:%d", pConn->info, pConn->spi, pHead->spi); - code = pHead->spi ? TSDB_CODE_AUTH_FAILURE : TSDB_CODE_AUTH_REQUIRED; + code = pHead->spi ? TSDB_CODE_RPC_AUTH_FAILURE : TSDB_CODE_RPC_AUTH_REQUIRED; } return code; diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 0efb477e73..8f102795b5 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -92,16 +92,15 @@ STsdbCfg *tsdbGetCfg(const TsdbRepoT *repo) { * @return a TSDB repository handle on success, NULL for failure */ int32_t tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter /* TODO */) { - if (mkdir(rootDir, 0755) != 0) { tsdbError("vgId:%d, failed to create rootDir! rootDir:%s, reason:%s", pCfg->tsdbId, rootDir, strerror(errno)); if (errno == EACCES) { - return TSDB_CODE_NO_DISK_PERMISSIONS; + return TSDB_CODE_TDB_NO_DISK_PERMISSIONS; } else if (errno == ENOSPC) { - return TSDB_CODE_SERV_NO_DISKSPACE; + return TSDB_CODE_TDB_NO_DISKSPACE; } else if (errno == EEXIST) { } else { - return TSDB_CODE_VG_INIT_FAILED; + return TSDB_CODE_TDB_INIT_FAILED; } } @@ -315,7 +314,7 @@ int32_t tsdbConfigRepo(TsdbRepoT *repo, STsdbCfg *pCfg) { STsdbRepo *pRepo = (STsdbRepo *)repo; STsdbCfg * pRCfg = &pRepo->config; - if (tsdbCheckAndSetDefaultCfg(pCfg) < 0) return TSDB_CODE_INVALID_CONFIG; + if (tsdbCheckAndSetDefaultCfg(pCfg) < 0) return TSDB_CODE_TDB_INVALID_CONFIG; ASSERT(pRCfg->tsdbId == pCfg->tsdbId); ASSERT(pRCfg->cacheBlockSize == pCfg->cacheBlockSize); @@ -416,13 +415,13 @@ int tsdbUpdateTagValue(TsdbRepoT *repo, SUpdateTableTagValMsg *pMsg) { int16_t tversion = htons(pMsg->tversion); STable *pTable = tsdbGetTableByUid(pMeta, htobe64(pMsg->uid)); - if (pTable == NULL) return TSDB_CODE_INVALID_TABLE_ID; - if (pTable->tableId.tid != htonl(pMsg->tid)) return TSDB_CODE_INVALID_TABLE_ID; + if (pTable == NULL) return TSDB_CODE_TDB_INVALID_TABLE_ID; + if (pTable->tableId.tid != htonl(pMsg->tid)) return TSDB_CODE_TDB_INVALID_TABLE_ID; if (pTable->type != TSDB_CHILD_TABLE) { tsdbError("vgId:%d failed to update tag value of table %s since its type is %d", pRepo->config.tsdbId, varDataVal(pTable->name), pTable->type); - return TSDB_CODE_INVALID_TABLE_TYPE; + return TSDB_CODE_TDB_INVALID_TABLE_TYPE; } if (schemaVersion(tsdbGetTableTagSchema(pMeta, pTable)) < tversion) { @@ -452,7 +451,7 @@ int tsdbUpdateTagValue(TsdbRepoT *repo, SUpdateTableTagValMsg *pMsg) { "vgId:%d failed to update tag value of table %s since version out of date, client tag version:%d server tag " "version:%d", pRepo->config.tsdbId, varDataVal(pTable->name), tversion, schemaVersion(pTable->tagSchema)); - return TSDB_CODE_TAG_VER_OUT_OF_DATE; + return TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE; } if (schemaColAt(pTagSchema, DEFAULT_TAG_INDEX_COLUMN)->colId == htons(pMsg->colId)) { tsdbRemoveTableFromIndex(pMeta, pTable); @@ -948,7 +947,7 @@ static int32_t tsdbInsertDataToTable(TsdbRepoT *repo, SSubmitBlk *pBlock, TSKEY if (pTable == NULL) { tsdbError("vgId:%d, failed to get table for insert, uid:" PRIu64 ", tid:%d", pRepo->config.tsdbId, pBlock->uid, pBlock->tid); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_TDB_INVALID_TABLE_ID; } // Check schema version @@ -980,7 +979,7 @@ static int32_t tsdbInsertDataToTable(TsdbRepoT *repo, SSubmitBlk *pBlock, TSKEY if (tsdbGetTableSchemaByVersion(pMeta, pTable, tversion) == NULL) { tsdbError("vgId:%d table:%s tid:%d invalid schema version %d from client", pRepo->config.tsdbId, varDataVal(pTable->name), pTable->tableId.tid, tversion); - return TSDB_CODE_TABLE_SCHEMA_VERSION; + return TSDB_CODE_TDB_TABLE_SCHEMA_VERSION; } } @@ -996,7 +995,7 @@ static int32_t tsdbInsertDataToTable(TsdbRepoT *repo, SSubmitBlk *pBlock, TSKEY tsdbError("vgId:%d, table:%s, tid:%d, talbe uid:%ld timestamp is out of range. now:" PRId64 ", maxKey:" PRId64 ", minKey:" PRId64, pRepo->config.tsdbId, varDataVal(pTable->name), pTable->tableId.tid, pTable->tableId.uid, now, minKey, maxKey); - return TSDB_CODE_TIMESTAMP_OUT_OF_RANGE; + return TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE; } if (tdInsertRowToTable(pRepo, row, pTable) < 0) { diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 9f1e507d54..34d3c27893 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -323,7 +323,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) { pTable = (STable *)calloc(1, sizeof(STable)); if (pTable == NULL) { - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; } @@ -343,7 +343,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) { tsize = strnlen(pCfg->sname, TSDB_TABLE_NAME_LEN); pTable->name = calloc(1, tsize + VARSTR_HEADER_SIZE + 1); if (pTable->name == NULL) { - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; } STR_WITH_SIZE_TO_VARSTR(pTable->name, pCfg->sname, tsize); @@ -352,7 +352,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) { pTable->pIndex = tSkipListCreate(TSDB_SUPER_TABLE_SL_LEVEL, pColSchema->type, pColSchema->bytes, 1, 0, 0, getTagIndexKey); // Allow duplicate key, no lock if (pTable->pIndex == NULL) { - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; } } else { @@ -364,7 +364,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) { tsize = strnlen(pCfg->name, TSDB_TABLE_NAME_LEN); pTable->name = calloc(1, tsize + VARSTR_HEADER_SIZE + 1); if (pTable->name == NULL) { - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; } STR_WITH_SIZE_TO_VARSTR(pTable->name, pCfg->name, tsize); @@ -399,7 +399,7 @@ static int tsdbUpdateTableTagSchema(STable *pTable, STSchema *newSchema) { ASSERT(schemaVersion(pTable->tagSchema) < schemaVersion(newSchema)); STSchema *pOldSchema = pTable->tagSchema; STSchema *pNewSchema = tdDupSchema(newSchema); - if (pNewSchema == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pNewSchema == NULL) return TSDB_CODE_TDB_OUT_OF_MEMORY; pTable->tagSchema = pNewSchema; tdFreeSchema(pOldSchema); @@ -454,7 +454,7 @@ int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg) { if (pTable != NULL) { tsdbError("vgId:%d table %s already exists, tid %d uid %" PRId64, pRepo->config.tsdbId, varDataVal(pTable->name), pTable->tableId.tid, pTable->tableId.uid); - return TSDB_CODE_TABLE_ALREADY_EXIST; + return TSDB_CODE_TDB_TABLE_ALREADY_EXIST; } STable *super = NULL; diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 4a48bcefe7..ef0e2ab3f6 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -1147,7 +1147,7 @@ static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void* static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numOfBlocks, int32_t* numOfAllocBlocks) { char* tmp = realloc(pQueryHandle->pDataBlockInfo, sizeof(STableBlockInfo) * numOfBlocks); if (tmp == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_TDB_OUT_OF_MEMORY; } pQueryHandle->pDataBlockInfo = (STableBlockInfo*) tmp; @@ -1164,7 +1164,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO if (sup.numOfBlocksPerTable == NULL || sup.blockIndexArray == NULL || sup.pDataBlockInfo == NULL) { cleanBlockOrderSupporter(&sup, 0); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_TDB_OUT_OF_MEMORY; } int32_t cnt = 0; @@ -1182,7 +1182,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO char* buf = calloc(1, sizeof(STableBlockInfo) * pTableCheck->numOfBlocks); if (buf == NULL) { cleanBlockOrderSupporter(&sup, numOfQualTables); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_TDB_OUT_OF_MEMORY; } sup.pDataBlockInfo[numOfQualTables] = (STableBlockInfo*)buf; @@ -1209,7 +1209,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO uint8_t ret = tLoserTreeCreate(&pTree, sup.numOfTables, &sup, dataBlockOrderCompar); if (ret != TSDB_CODE_SUCCESS) { cleanBlockOrderSupporter(&sup, numOfTables); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_TDB_OUT_OF_MEMORY; } int32_t numOfTotal = 0; @@ -2070,14 +2070,14 @@ int32_t tsdbQuerySTableByTagCond(TsdbRepoT* tsdb, uint64_t uid, const char* pTag STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid); if (pTable == NULL) { tsdbError("%p failed to get stable, uid:%" PRIu64, tsdb, uid); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_TDB_INVALID_TABLE_ID; } if (pTable->type != TSDB_SUPER_TABLE) { tsdbError("%p query normal tag not allowed, uid:%" PRIu64 ", tid:%d, name:%s", tsdb, uid, pTable->tableId.tid, pTable->name); - return TSDB_CODE_OPS_NOT_SUPPORT; //basically, this error is caused by invalid sql issued by client + return TSDB_CODE_COM_OPS_NOT_SUPPORT; //basically, this error is caused by invalid sql issued by client } SArray* res = taosArrayInit(8, sizeof(STableId)); @@ -2114,7 +2114,7 @@ int32_t tsdbQuerySTableByTagCond(TsdbRepoT* tsdb, uint64_t uid, const char* pTag tExprNode* tbnameExpr = expr; expr = calloc(1, sizeof(tExprNode)); if (expr == NULL) { - THROW( TSDB_CODE_SERV_OUT_OF_MEMORY ); + THROW( TSDB_CODE_TDB_OUT_OF_MEMORY ); } expr->nodeType = TSQL_NODE_EXPR; expr->_node.optr = tagNameRelType; @@ -2141,7 +2141,7 @@ int32_t tsdbQuerySTableByTagCond(TsdbRepoT* tsdb, uint64_t uid, const char* pTag int32_t tsdbGetOneTableGroup(TsdbRepoT* tsdb, uint64_t uid, STableGroupInfo* pGroupInfo) { STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid); if (pTable == NULL) { - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_TDB_INVALID_TABLE_ID; } //todo assert table type, add the table ref count diff --git a/src/util/src/tbuffer.c b/src/util/src/tbuffer.c index 3b4cc74cc3..4b37cbd2d5 100644 --- a/src/util/src/tbuffer.c +++ b/src/util/src/tbuffer.c @@ -26,7 +26,7 @@ size_t tbufSkip(SBufferReader* buf, size_t size) { if( (buf->pos + size) > buf->size ) { - THROW( TSDB_CODE_MEMORY_CORRUPTED ); + THROW( TSDB_CODE_COM_MEMORY_CORRUPTED ); } size_t old = buf->pos; buf->pos += size; @@ -58,7 +58,7 @@ const char* tbufReadString( SBufferReader* buf, size_t* len ) { const char* ret = buf->data + buf->pos; tbufSkip( buf, l + 1 ); if( ret[l] != 0 ) { - THROW( TSDB_CODE_MEMORY_CORRUPTED ); + THROW( TSDB_CODE_COM_MEMORY_CORRUPTED ); } if( len != NULL ) { *len = l; @@ -204,7 +204,7 @@ void tbufEnsureCapacity( SBufferWriter* buf, size_t size ) { char* data = (*buf->allocator)( buf->data, nsize ); // TODO: the exception should be thrown by the allocator function if( data == NULL ) { - THROW( TSDB_CODE_SERV_OUT_OF_MEMORY ); + THROW( TSDB_CODE_COM_OUT_OF_MEMORY ); } buf->data = data; buf->size = nsize; diff --git a/src/util/src/tqueue.c b/src/util/src/tqueue.c index 4cf7eb3164..7e9392f410 100644 --- a/src/util/src/tqueue.c +++ b/src/util/src/tqueue.c @@ -55,7 +55,7 @@ taos_queue taosOpenQueue() { STaosQueue *queue = (STaosQueue *) calloc(sizeof(STaosQueue), 1); if (queue == NULL) { - terrno = TSDB_CODE_NO_RESOURCE; + terrno = TSDB_CODE_COM_OUT_OF_MEMORY; return NULL; } @@ -216,7 +216,7 @@ taos_qset taosOpenQset() { STaosQset *qset = (STaosQset *) calloc(sizeof(STaosQset), 1); if (qset == NULL) { - terrno = TSDB_CODE_NO_RESOURCE; + terrno = TSDB_CODE_COM_OUT_OF_MEMORY; return NULL; } diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 6a5c8b6799..383d9b8f98 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -582,18 +582,18 @@ int taosCheckVersion(char *input_client_version, char *input_server_version, int if (!taosGetVersionNumber(client_version, clientVersionNumber)) { uError("invalid client version:%s", client_version); - return TSDB_CODE_INVALID_CLIENT_VERSION; + return TSDB_CODE_TSC_INVALID_VERSION; } if (!taosGetVersionNumber(server_version, serverVersionNumber)) { uError("invalid server version:%s", server_version); - return TSDB_CODE_INVALID_CLIENT_VERSION; + return TSDB_CODE_TSC_INVALID_VERSION; } for(int32_t i = 0; i < comparedSegments; ++i) { if (clientVersionNumber[i] != serverVersionNumber[i]) { uError("the %d-th number of server version:%s not matched with client version:%s", i, server_version, version); - return TSDB_CODE_INVALID_CLIENT_VERSION; + return TSDB_CODE_TSC_INVALID_VERSION; } } diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 3d8cf67d02..d1dfa24cbe 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -82,14 +82,14 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { if (mkdir(rootDir, 0755) != 0) { vPrint("vgId:%d, failed to create vnode, reason:%s dir:%s", pVnodeCfg->cfg.vgId, strerror(errno), rootDir); if (errno == EACCES) { - return TSDB_CODE_NO_DISK_PERMISSIONS; + return TSDB_CODE_VND_NO_DISK_PERMISSIONS; } else if (errno == ENOSPC) { - return TSDB_CODE_SERV_NO_DISKSPACE; + return TSDB_CODE_VND_NO_DISKSPACE; } else if (errno == ENOENT) { - return TSDB_CODE_NOT_SUCH_FILE_OR_DIR; + return TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR; } else if (errno == EEXIST) { } else { - return TSDB_CODE_VG_INIT_FAILED; + return TSDB_CODE_VND_INIT_FAILED; } } @@ -116,7 +116,7 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { code = tsdbCreateRepo(tsdbDir, &tsdbCfg, NULL); if (code != TSDB_CODE_SUCCESS) { vError("vgId:%d, failed to create tsdb in vnode, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(code)); - return TSDB_CODE_VG_INIT_FAILED; + return TSDB_CODE_VND_INIT_FAILED; } vPrint("vgId:%d, vnode is created, clog:%d", pVnodeCfg->cfg.vgId, pVnodeCfg->cfg.walLevel); @@ -128,13 +128,13 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { int32_t vnodeDrop(int32_t vgId) { if (tsDnodeVnodesHash == NULL) { vTrace("vgId:%d, failed to drop, vgId not exist", vgId); - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_VND_INVALID_VGROUP_ID; } SVnodeObj **ppVnode = (SVnodeObj **)taosHashGet(tsDnodeVnodesHash, (const char *)&vgId, sizeof(int32_t)); if (ppVnode == NULL || *ppVnode == NULL) { vTrace("vgId:%d, failed to drop, vgId not find", vgId); - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_VND_INVALID_VGROUP_ID; } SVnodeObj *pVnode = *ppVnode; @@ -326,7 +326,7 @@ void *vnodeGetVnode(int32_t vgId) { SVnodeObj **ppVnode = (SVnodeObj **)taosHashGet(tsDnodeVnodesHash, (const char *)&vgId, sizeof(int32_t)); if (ppVnode == NULL || *ppVnode == NULL) { - terrno = TSDB_CODE_INVALID_VGROUP_ID; + terrno = TSDB_CODE_VND_INVALID_VGROUP_ID; vPrint("vgId:%d, not exist", vgId); return NULL; } @@ -494,7 +494,7 @@ static int32_t vnodeSaveCfg(SMDCreateVnodeMsg *pVnodeCfg) { char * content = calloc(1, maxLen + 1); if (content == NULL) { fclose(fp); - return TSDB_CODE_NO_RESOURCE; + return TSDB_CODE_VND_OUT_OF_MEMORY; } len += snprintf(content + len, maxLen - len, "{\n"); @@ -545,7 +545,7 @@ static int32_t vnodeReadCfg(SVnodeObj *pVnode) { char cfgFile[TSDB_FILENAME_LEN + 30] = {0}; int maxLen = 1000; - terrno = TSDB_CODE_OTHERS; + terrno = TSDB_CODE_VND_APP_ERROR; sprintf(cfgFile, "%s/vnode%d/config.json", tsVnodeDir, pVnode->vgId); FILE *fp = fopen(cfgFile, "r"); if (!fp) { @@ -777,7 +777,7 @@ static int32_t vnodeReadVersion(SVnodeObj *pVnode) { cJSON *root = NULL; int maxLen = 100; - terrno = TSDB_CODE_OTHERS; + terrno = TSDB_CODE_VND_APP_ERROR; sprintf(versionFile, "%s/vnode%d/version.json", tsVnodeDir, pVnode->vgId); FILE *fp = fopen(versionFile, "r"); if (!fp) { diff --git a/src/vnode/src/vnodeRead.c b/src/vnode/src/vnodeRead.c index ef2cb20171..af8052b0c7 100644 --- a/src/vnode/src/vnodeRead.c +++ b/src/vnode/src/vnodeRead.c @@ -40,10 +40,10 @@ int32_t vnodeProcessRead(void *param, int msgType, void *pCont, int32_t contLen, SVnodeObj *pVnode = (SVnodeObj *)param; if (vnodeProcessReadMsgFp[msgType] == NULL) - return TSDB_CODE_MSG_NOT_PROCESSED; + return TSDB_CODE_VND_MSG_NOT_PROCESSED; if (pVnode->status == TAOS_VN_STATUS_DELETING || pVnode->status == TAOS_VN_STATUS_CLOSING) - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_VND_INVALID_VGROUP_ID; return (*vnodeProcessReadMsgFp[msgType])(pVnode, pCont, contLen, ret); } @@ -69,7 +69,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, void *pCont, int32_t cont } else { assert(pCont != NULL); pQInfo = pCont; - code = TSDB_CODE_ACTION_IN_PROGRESS; + code = TSDB_CODE_VND_ACTION_IN_PROGRESS; } if (pQInfo != NULL) { @@ -99,7 +99,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, void *pCont, int32_t cont if (qHasMoreResultsToRetrieve(pQInfo)) { pRet->qhandle = pQInfo; - code = TSDB_CODE_ACTION_NEED_REPROCESSED; + code = TSDB_CODE_VND_ACTION_NEED_REPROCESSED; } else { // no further execution invoked, release the ref to vnode qDestroyQueryInfo(pQInfo); diff --git a/src/vnode/src/vnodeWrite.c b/src/vnode/src/vnodeWrite.c index 4dfe492932..fa322757e2 100644 --- a/src/vnode/src/vnodeWrite.c +++ b/src/vnode/src/vnodeWrite.c @@ -51,14 +51,14 @@ int32_t vnodeProcessWrite(void *param1, int qtype, void *param2, void *item) { SWalHead *pHead = param2; if (vnodeProcessWriteMsgFp[pHead->msgType] == NULL) - return TSDB_CODE_MSG_NOT_PROCESSED; + return TSDB_CODE_VND_MSG_NOT_PROCESSED; if (pHead->version == 0) { // from client or CQ if (pVnode->status != TAOS_VN_STATUS_READY) - return TSDB_CODE_INVALID_VGROUP_ID; // it may be in deleting or closing state + return TSDB_CODE_VND_INVALID_VGROUP_ID; // it may be in deleting or closing state if (pVnode->syncCfg.replica > 1 && pVnode->role != TAOS_SYNC_ROLE_MASTER) - return TSDB_CODE_NOT_READY; + return TSDB_CODE_RPC_NOT_READY; // assign version pVnode->version++; diff --git a/tests/examples/C#/TDengineDriver.cs b/tests/examples/C#/TDengineDriver.cs index a11dae8e48..2797c362c1 100644 --- a/tests/examples/C#/TDengineDriver.cs +++ b/tests/examples/C#/TDengineDriver.cs @@ -79,8 +79,6 @@ namespace TDengineDriver class TDengine { public const int TSDB_CODE_SUCCESS = 0; - public const int TSDB_CODE_DB_ALREADY_EXIST = 33; - public const int TSDB_CODE_TABLE_ALREADY_EXIST = 34; [DllImport("taos.dll", EntryPoint = "taos_init", CallingConvention = CallingConvention.StdCall)] static extern public void Init(); diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 1230f52f63..f13e861907 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -538,7 +538,7 @@ int simExecuteRestFulCommand(SScript *script, char *command) { FILE *fp = popen(buf, "r"); if (fp == NULL) { simError("failed to execute %s", buf); - return TSDB_CODE_OTHERS; + return -1; } int mallocSize = 2000; @@ -642,7 +642,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { pSql = taos_query(script->taos, rest); ret = taos_errno(pSql); - if (ret == TSDB_CODE_TABLE_ALREADY_EXIST || ret == TSDB_CODE_DB_ALREADY_EXIST) { + if (ret == TSDB_CODE_MND_TABLE_ALREADY_EXIST || ret == TSDB_CODE_MND_DB_ALREADY_EXIST) { simTrace("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret, tstrerror(ret)); ret = 0; break; @@ -791,8 +791,8 @@ bool simExecuteRestFulSqlCommand(SScript *script, char *rest) { int ret = -1; for (int attempt = 0; attempt < 10; ++attempt) { ret = simExecuteRestFulCommand(script, command); - if (ret == TSDB_CODE_TABLE_ALREADY_EXIST || - ret == TSDB_CODE_DB_ALREADY_EXIST) { + if (ret == TSDB_CODE_MND_TABLE_ALREADY_EXIST || + ret == TSDB_CODE_MND_DB_ALREADY_EXIST) { simTrace("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret, tstrerror(ret)); ret = 0; break; From d34cabf2c1a782fe7001e3f82699aadfd6f3911c Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Fri, 29 May 2020 17:15:09 +0800 Subject: [PATCH 05/72] TD-449: fix several bugs --- src/cq/src/cqMain.c | 6 ++++-- src/dnode/inc/dnodeModule.h | 3 ++- src/dnode/src/dnodeMain.c | 1 + src/dnode/src/dnodeMgmt.c | 18 +++++++++++++++++- src/inc/tcq.h | 1 + src/inc/tsdb.h | 1 + src/inc/vnode.h | 1 + src/tsdb/src/tsdbMain.c | 12 ++++++++++++ src/tsdb/src/tsdbMeta.c | 8 -------- src/vnode/src/vnodeMain.c | 12 +++++++++++- 10 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index 9406a2fdce..799a0b0514 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -38,6 +38,7 @@ typedef struct { int vgId; char user[TSDB_USER_LEN]; char pass[TSDB_PASSWORD_LEN]; + char db[TSDB_DB_NAME_LEN]; FCqWrite cqWrite; void *ahandle; int num; // number of continuous streams @@ -73,6 +74,7 @@ void *cqOpen(void *ahandle, const SCqCfg *pCfg) { strcpy(pContext->user, pCfg->user); strcpy(pContext->pass, pCfg->pass); + strcpy(pContext->db, pCfg->db); pContext->vgId = pCfg->vgId; pContext->cqWrite = pCfg->cqWrite; pContext->ahandle = ahandle; @@ -207,9 +209,8 @@ void cqDrop(void *handle) { } static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { - if (pContext->dbConn == NULL) { - pContext->dbConn = taos_connect("localhost", pContext->user, pContext->pass, NULL, 0); + pContext->dbConn = taos_connect("localhost", pContext->user, pContext->pass, pContext->db, 0); if (pContext->dbConn == NULL) { cError("vgId:%d, failed to connect to TDengine(%s)", pContext->vgId, tstrerror(terrno)); } @@ -217,6 +218,7 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { } int64_t lastKey = 0; + pObj->pContext = pContext; pObj->pStream = taos_open_stream(pContext->dbConn, pObj->sqlStr, cqProcessStreamRes, lastKey, pObj, NULL); if (pObj->pStream) { pContext->num++; diff --git a/src/dnode/inc/dnodeModule.h b/src/dnode/inc/dnodeModule.h index 8618de3244..fb529ee67c 100644 --- a/src/dnode/inc/dnodeModule.h +++ b/src/dnode/inc/dnodeModule.h @@ -22,7 +22,8 @@ extern "C" { int32_t dnodeInitModules(); void dnodeStartModules(); -void dnodeCleanupModules(); +void dnodeStartStream(); +void dnodeCleanUpModules(); void dnodeProcessModuleStatus(uint32_t moduleStatus); #ifdef __cplusplus diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 7683843371..73bc2923b2 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -124,6 +124,7 @@ int32_t dnodeInitSystem() { dnodeStartModules(); dnodeSetRunStatus(TSDB_DNODE_RUN_STATUS_RUNING); + dnodeStartStream(); dPrint("TDengine is initialized successfully"); diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index 7c457defca..a29f99dda6 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -260,11 +260,27 @@ static int32_t dnodeOpenVnodes() { } free(vnodeList); - dPrint("there are total vnodes:%d, openned:%d failed:%d", numOfVnodes, numOfVnodes-failed, failed); return TSDB_CODE_SUCCESS; } +void dnodeStartStream() { + int32_t vnodeList[TSDB_MAX_VNODES]; + int32_t numOfVnodes = 0; + int32_t status = dnodeGetVnodeList(vnodeList, &numOfVnodes); + + if (status != TSDB_CODE_SUCCESS) { + dPrint("Get dnode list failed"); + return; + } + + for (int32_t i = 0; i < numOfVnodes; ++i) { + vnodeStartStream(vnodeList[i]); + } + + dPrint("streams started"); +} + static void dnodeCloseVnodes() { int32_t *vnodeList = (int32_t *)malloc(sizeof(int32_t) * TSDB_MAX_VNODES); int32_t numOfVnodes; diff --git a/src/inc/tcq.h b/src/inc/tcq.h index e025afaa0a..ba198ab66e 100644 --- a/src/inc/tcq.h +++ b/src/inc/tcq.h @@ -27,6 +27,7 @@ typedef struct { int vgId; char user[TSDB_USER_LEN]; char pass[TSDB_PASSWORD_LEN]; + char db[TSDB_DB_NAME_LEN]; FCqWrite cqWrite; } SCqCfg; diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 2dc9b977b4..d3ec96acf6 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -118,6 +118,7 @@ int tsdbDropTable(TsdbRepoT *pRepo, STableId tableId); int tsdbAlterTable(TsdbRepoT *repo, STableCfg *pCfg); int tsdbUpdateTagValue(TsdbRepoT *repo, SUpdateTableTagValMsg *pMsg); TSKEY tsdbGetTableLastKey(TsdbRepoT *repo, uint64_t uid); +void tsdbStartStream(TsdbRepoT *repo); uint32_t tsdbGetFileInfo(TsdbRepoT *repo, char *name, uint32_t *index, uint32_t eindex, int32_t *size); diff --git a/src/inc/vnode.h b/src/inc/vnode.h index f4fb8060fe..e507c55942 100644 --- a/src/inc/vnode.h +++ b/src/inc/vnode.h @@ -38,6 +38,7 @@ typedef struct { int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg); int32_t vnodeDrop(int32_t vgId); int32_t vnodeOpen(int32_t vgId, char *rootDir); +int32_t vnodeStartStream(int32_t vgId); int32_t vnodeAlter(void *pVnode, SMDCreateVnodeMsg *pVnodeCfg); int32_t vnodeClose(int32_t vgId); diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 0efb477e73..632c1dd34e 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -474,6 +474,18 @@ TSKEY tsdbGetTableLastKey(TsdbRepoT *repo, uint64_t uid) { return TSDB_GET_TABLE_LAST_KEY(pTable); } +void tsdbStartStream(TsdbRepoT *repo) { + STsdbRepo *pRepo = (STsdbRepo *)repo; + STsdbMeta *pMeta = pRepo->tsdbMeta; + + for (int i = 0; i < pRepo->config.maxTables; i++) { + STable *pTable = pMeta->tables[i]; + if (pTable && pTable->type == TSDB_STREAM_TABLE) { + pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, pTable->tableId.tid, pTable->sql, tsdbGetTableSchema(pMeta, pTable)); + } + } +} + STableInfo *tsdbGetTableInfo(TsdbRepoT *pRepo, STableId tableId) { // TODO return NULL; diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 9f1e507d54..bf5fac4e45 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -150,7 +150,6 @@ int tsdbRestoreTable(void *pHandle, void *cont, int contLen) { void tsdbOrgMeta(void *pHandle) { STsdbMeta *pMeta = (STsdbMeta *)pHandle; - STsdbRepo *pRepo = (STsdbRepo *)pMeta->pRepo; for (int i = 1; i < pMeta->maxTables; i++) { STable *pTable = pMeta->tables[i]; @@ -158,13 +157,6 @@ void tsdbOrgMeta(void *pHandle) { tsdbAddTableIntoIndex(pMeta, pTable); } } - - for (int i = 0; i < pMeta->maxTables; i++) { - STable *pTable = pMeta->tables[i]; - if (pTable && pTable->type == TSDB_STREAM_TABLE) { - pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, i, pTable->sql, tsdbGetTableSchema(pMeta, pTable)); - } - } } /** diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 3d8cf67d02..037dadb8fd 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -208,8 +208,9 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) { } SCqCfg cqCfg = {0}; - sprintf(cqCfg.user, "root"); + sprintf(cqCfg.user, "_root"); strcpy(cqCfg.pass, tsInternalPass); + strcpy(cqCfg.db, "s1_db0"); // TODO: replace hard coded db name cqCfg.vgId = vnode; cqCfg.cqWrite = vnodeWriteToQueue; pVnode->cq = cqOpen(pVnode, &cqCfg); @@ -277,6 +278,15 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) { return TSDB_CODE_SUCCESS; } +int32_t vnodeStartStream(int32_t vnode) { + SVnodeObj* pVnode = vnodeAccquireVnode(vnode); + if (pVnode != NULL) { + tsdbStartStream(pVnode->tsdb); + vnodeRelease(pVnode); + } + return TSDB_CODE_SUCCESS; +} + int32_t vnodeClose(int32_t vgId) { SVnodeObj **ppVnode = (SVnodeObj **)taosHashGet(tsDnodeVnodesHash, (const char *)&vgId, sizeof(int32_t)); if (ppVnode == NULL || *ppVnode == NULL) return 0; From 69142ea5aaa29af8fca4dea9115d88665abcd307 Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Mon, 1 Jun 2020 17:17:22 +0800 Subject: [PATCH 06/72] TD-449: data is written to TSDB --- src/client/src/tscStream.c | 8 ++++-- src/common/inc/tdataformat.h | 1 + src/cq/src/cqMain.c | 50 ++++++++++++++++++++++++++---------- src/cq/test/cqtest.c | 2 +- src/inc/tcq.h | 2 +- src/inc/tsdb.h | 2 +- src/tsdb/src/tsdbMain.c | 2 +- src/tsdb/src/tsdbMeta.c | 2 +- src/vnode/src/vnodeMain.c | 2 +- 9 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 9e1628bb9b..3c7cd3e1eb 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -19,6 +19,7 @@ #include "tscLog.h" #include "tscUtil.h" #include "tsched.h" +#include "tcache.h" #include "tsclient.h" #include "ttime.h" #include "ttimer.h" @@ -147,7 +148,8 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf retryDelay); STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pStream->pSql->cmd, 0, 0); - tscClearTableMetaInfo(pTableMetaInfo, true); + taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), true); + tfree(pTableMetaInfo->vgroupList); tscSetRetryTimer(pStream, pStream->pSql, retryDelay); return; @@ -259,7 +261,9 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf pStream->numOfRes); // release the metric/meter meta information reference, so data in cache can be updated - tscClearTableMetaInfo(pTableMetaInfo, false); + + taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), false); + tfree(pTableMetaInfo->vgroupList); tscSetNextLaunchTimer(pStream, pSql); } } diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index 3a84ce8f6f..e706f9a9d5 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -70,6 +70,7 @@ typedef struct { int numOfCols; // Number of columns appended int tlen; // maximum length of a SDataRow without the header part int flen; // First part length in a SDataRow after the header part + int32_t version; STColumn columns[]; } STSchema; diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index 799a0b0514..d96e0fe6a7 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -49,7 +49,8 @@ typedef struct { } SCqContext; typedef struct SCqObj { - int tid; // table ID + uint64_t uid; + int32_t tid; // table ID int rowSize; // bytes of a row char * sqlStr; // SQL string STSchema * pSchema; // pointer to schema array @@ -155,17 +156,19 @@ void cqStop(void *handle) { pthread_mutex_unlock(&pContext->mutex); } -void *cqCreate(void *handle, int tid, char *sqlStr, STSchema *pSchema) { +void *cqCreate(void *handle, uint64_t uid, int tid, char *sqlStr, STSchema *pSchema) { SCqContext *pContext = handle; SCqObj *pObj = calloc(sizeof(SCqObj), 1); if (pObj == NULL) return NULL; + pObj->uid = uid; pObj->tid = tid; pObj->sqlStr = malloc(strlen(sqlStr)+1); strcpy(pObj->sqlStr, sqlStr); pObj->pSchema = tdDupSchema(pSchema); + pObj->rowSize = pSchema->tlen; cTrace("vgId:%d, id:%d CQ:%s is created", pContext->vgId, pObj->tid, pObj->sqlStr); @@ -213,8 +216,8 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { pContext->dbConn = taos_connect("localhost", pContext->user, pContext->pass, pContext->db, 0); if (pContext->dbConn == NULL) { cError("vgId:%d, failed to connect to TDengine(%s)", pContext->vgId, tstrerror(terrno)); + return; } - return; } int64_t lastKey = 0; @@ -231,6 +234,7 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { SCqObj *pObj = (SCqObj *)param; SCqContext *pContext = pObj->pContext; + STSchema *pSchema = pObj->pSchema; if (pObj->pStream == NULL) return; cTrace("vgId:%d, id:%d CQ:%s stream result is ready", pContext->vgId, pObj->tid, pObj->sqlStr); @@ -240,18 +244,38 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { char *buffer = calloc(size, 1); SWalHead *pHead = (SWalHead *)buffer; + SSubmitMsg *pMsg = (SSubmitMsg *) (buffer + sizeof(SWalHead)); + SSubmitBlk *pBlk = (SSubmitBlk *) (buffer + sizeof(SWalHead) + sizeof(SSubmitMsg)); + + int32_t flen = 0; + for (int32_t i = 0; i < pSchema->numOfCols; i++) { + flen += TYPE_BYTES[pSchema->columns[i].type]; + } + + SDataRow trow = (SDataRow)pBlk->data; + dataRowSetLen(trow, TD_DATA_ROW_HEAD_SIZE + flen); + + int toffset = 0; + for (int32_t i = 0; i < pSchema->numOfCols; i++) { + tdAppendColVal(trow, row[i], pSchema->columns[i].type, pSchema->columns[i].bytes, toffset); + toffset += TYPE_BYTES[pSchema->columns[i].type]; + } + pBlk->len = htonl(dataRowLen(trow)); + + pBlk->uid = htobe64(pObj->uid); + pBlk->tid = htonl(pObj->tid); + pBlk->numOfRows = htons(1); + pBlk->sversion = htonl(pSchema->version); + pBlk->padding = 0; + + pMsg->header.vgId = htonl(pContext->vgId); + pMsg->header.contLen = htonl(size - sizeof(SWalHead)); + pMsg->length = pMsg->header.contLen; + pMsg->numOfBlocks = htonl(1); + pHead->msgType = TSDB_MSG_TYPE_SUBMIT; pHead->len = size - sizeof(SWalHead); - - SSubmitMsg *pSubmit = (SSubmitMsg *) (buffer + sizeof(SWalHead)); - // to do: fill in the SSubmitMsg structure - pSubmit->numOfBlocks = 1; - - - SSubmitBlk *pBlk = (SSubmitBlk *) (buffer + sizeof(SWalHead) + sizeof(SSubmitMsg)); - // to do: fill in the SSubmitBlk strucuture - pBlk->tid = pObj->tid; - + pHead->version = 0; // write into vnode write queue pContext->cqWrite(pContext->ahandle, pHead, TAOS_QTYPE_CQ); diff --git a/src/cq/test/cqtest.c b/src/cq/test/cqtest.c index fbe3c95b86..1416a591be 100644 --- a/src/cq/test/cqtest.c +++ b/src/cq/test/cqtest.c @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) { tdDestroyTSchemaBuilder(&schemaBuilder); for (int sid =1; sid<10; ++sid) { - cqCreate(pCq, sid, "select avg(speed) from demo.t1 sliding(1s) interval(5s)", pSchema); + cqCreate(pCq, sid, sid, "select avg(speed) from demo.t1 sliding(1s) interval(5s)", pSchema); } tdFreeSchema(pSchema); diff --git a/src/inc/tcq.h b/src/inc/tcq.h index ba198ab66e..32b75674c3 100644 --- a/src/inc/tcq.h +++ b/src/inc/tcq.h @@ -42,7 +42,7 @@ void cqStart(void *handle); void cqStop(void *handle); // cqCreate is called by TSDB to start an instance of CQ -void *cqCreate(void *handle, int sid, char *sqlStr, STSchema *pSchema); +void *cqCreate(void *handle, uint64_t uid, int sid, char *sqlStr, STSchema *pSchema); // cqDrop is called by TSDB to stop an instance of CQ, handle is the return value of cqCreate void cqDrop(void *handle); diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index d3ec96acf6..a678f213bb 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -43,7 +43,7 @@ typedef struct { void *cqH; int (*notifyStatus)(void *, int status); int (*eventCallBack)(void *); - void *(*cqCreateFunc)(void *handle, int sid, char *sqlStr, STSchema *pSchema); + void *(*cqCreateFunc)(void *handle, uint64_t uid, int sid, char *sqlStr, STSchema *pSchema); void (*cqDropFunc)(void *handle); void *(*configFunc)(int32_t vgId, int32_t sid); } STsdbAppH; diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 632c1dd34e..f8fea779f3 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -481,7 +481,7 @@ void tsdbStartStream(TsdbRepoT *repo) { for (int i = 0; i < pRepo->config.maxTables; i++) { STable *pTable = pMeta->tables[i]; if (pTable && pTable->type == TSDB_STREAM_TABLE) { - pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, pTable->tableId.tid, pTable->sql, tsdbGetTableSchema(pMeta, pTable)); + pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, pTable->tableId.uid, pTable->tableId.tid, pTable->sql, tsdbGetTableSchema(pMeta, pTable)); } } } diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index bf5fac4e45..ac0f6b26ac 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -675,7 +675,7 @@ static int tsdbAddTableToMeta(STsdbMeta *pMeta, STable *pTable, bool addIdx) { tsdbAddTableIntoIndex(pMeta, pTable); } if (pTable->type == TSDB_STREAM_TABLE && addIdx) { - pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, pTable->tableId.tid, pTable->sql, tsdbGetTableSchema(pMeta, pTable)); + pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, pTable->tableId.uid, pTable->tableId.tid, pTable->sql, tsdbGetTableSchema(pMeta, pTable)); } pMeta->nTables++; diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 037dadb8fd..26ba392a76 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -210,7 +210,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) { SCqCfg cqCfg = {0}; sprintf(cqCfg.user, "_root"); strcpy(cqCfg.pass, tsInternalPass); - strcpy(cqCfg.db, "s1_db0"); // TODO: replace hard coded db name + strcpy(cqCfg.db, "db"); // TODO: replace hard coded db name cqCfg.vgId = vnode; cqCfg.cqWrite = vnodeWriteToQueue; pVnode->cq = cqOpen(pVnode, &cqCfg); From 40c1d665b5481850c4a0e0604675f5eedf648e03 Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Tue, 2 Jun 2020 18:12:33 +0800 Subject: [PATCH 07/72] fix some issues --- src/client/src/tscStream.c | 14 ++++++++++++++ src/common/inc/tdataformat.h | 1 - src/cq/src/cqMain.c | 13 +++++++------ src/dnode/inc/dnodeModule.h | 2 +- src/inc/tcq.h | 2 +- src/vnode/src/vnodeMain.c | 2 +- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 3c7cd3e1eb..83a097f2f5 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -477,6 +477,14 @@ static void setErrorInfo(SSqlObj* pSql, int32_t code, char* info) { } } +static void asyncCallback(void *param, TAOS_RES *tres, int code) { + assert(param != NULL); + SSqlObj *pSql = ((SSqlObj *)param); + + pSql->res.code = code; + sem_post(&pSql->rspSem); +} + TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), int64_t stime, void *param, void (*callback)(void *)) { STscObj *pObj = (STscObj *)taos; @@ -521,7 +529,13 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p return NULL; } + pSql->param = pSql; + pSql->fp = asyncCallback; pRes->code = tscToSQLCmd(pSql, &SQLInfo); + if (pRes->code == TSDB_CODE_ACTION_IN_PROGRESS) { + sem_wait(&pSql->rspSem); + } + SQLInfoDestroy(&SQLInfo); if (pRes->code != TSDB_CODE_SUCCESS) { diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index e706f9a9d5..3a84ce8f6f 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -70,7 +70,6 @@ typedef struct { int numOfCols; // Number of columns appended int tlen; // maximum length of a SDataRow without the header part int flen; // First part length in a SDataRow after the header part - int32_t version; STColumn columns[]; } STSchema; diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index d96e0fe6a7..401d61b7a2 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -239,19 +239,19 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { cTrace("vgId:%d, id:%d CQ:%s stream result is ready", pContext->vgId, pObj->tid, pObj->sqlStr); + int32_t flen = 0; + for (int32_t i = 0; i < pSchema->numOfCols; i++) { + flen += TYPE_BYTES[pSchema->columns[i].type]; + } + // construct data - int size = sizeof(SWalHead) + sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + pObj->rowSize; + int size = sizeof(SWalHead) + sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + TD_DATA_ROW_HEAD_SIZE + flen; char *buffer = calloc(size, 1); SWalHead *pHead = (SWalHead *)buffer; SSubmitMsg *pMsg = (SSubmitMsg *) (buffer + sizeof(SWalHead)); SSubmitBlk *pBlk = (SSubmitBlk *) (buffer + sizeof(SWalHead) + sizeof(SSubmitMsg)); - int32_t flen = 0; - for (int32_t i = 0; i < pSchema->numOfCols; i++) { - flen += TYPE_BYTES[pSchema->columns[i].type]; - } - SDataRow trow = (SDataRow)pBlk->data; dataRowSetLen(trow, TD_DATA_ROW_HEAD_SIZE + flen); @@ -279,5 +279,6 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { // write into vnode write queue pContext->cqWrite(pContext->ahandle, pHead, TAOS_QTYPE_CQ); + free(buffer); } diff --git a/src/dnode/inc/dnodeModule.h b/src/dnode/inc/dnodeModule.h index fb529ee67c..6a6da0a2a5 100644 --- a/src/dnode/inc/dnodeModule.h +++ b/src/dnode/inc/dnodeModule.h @@ -23,7 +23,7 @@ extern "C" { int32_t dnodeInitModules(); void dnodeStartModules(); void dnodeStartStream(); -void dnodeCleanUpModules(); +void dnodeCleanupModules(); void dnodeProcessModuleStatus(uint32_t moduleStatus); #ifdef __cplusplus diff --git a/src/inc/tcq.h b/src/inc/tcq.h index 32b75674c3..9d987da468 100644 --- a/src/inc/tcq.h +++ b/src/inc/tcq.h @@ -27,7 +27,7 @@ typedef struct { int vgId; char user[TSDB_USER_LEN]; char pass[TSDB_PASSWORD_LEN]; - char db[TSDB_DB_NAME_LEN]; + char db[TSDB_DB_NAME_LEN + 1]; FCqWrite cqWrite; } SCqCfg; diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 26ba392a76..e4f1f7d2f5 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -210,7 +210,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) { SCqCfg cqCfg = {0}; sprintf(cqCfg.user, "_root"); strcpy(cqCfg.pass, tsInternalPass); - strcpy(cqCfg.db, "db"); // TODO: replace hard coded db name + strcpy(cqCfg.db, pVnode->db); cqCfg.vgId = vnode; cqCfg.cqWrite = vnodeWriteToQueue; pVnode->cq = cqOpen(pVnode, &cqCfg); From 81ea4a8a8617d03d301935529ee2e7c7d9ff9bbb Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Wed, 3 Jun 2020 16:16:41 +0800 Subject: [PATCH 08/72] first test case passed --- src/client/inc/tsclient.h | 1 + src/client/src/tscAsync.c | 37 +++++----- src/client/src/tscStream.c | 39 ++-------- src/cq/src/cqMain.c | 9 ++- tests/pytest/stream/stream1.py | 131 +++++++++++++++++++++++++++++++++ 5 files changed, 166 insertions(+), 51 deletions(-) create mode 100644 tests/pytest/stream/stream1.py diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index d7f1881209..e92bb5e64e 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -404,6 +404,7 @@ TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void *param, void **taos); void waitForQueryRsp(void *param, TAOS_RES *tres, int code) ; +int doAsyncParseSql(SSqlObj* pSql, const char* sqlstr, size_t sqlLen); void doAsyncQuery(STscObj *pObj, SSqlObj *pSql, void (*fp)(), void *param, const char *sqlstr, size_t sqlLen); void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql); diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index ebcdddffde..bd2dc64ef0 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -40,30 +40,23 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo static void tscAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOfRows); static void tscAsyncFetchSingleRowProxy(void *param, TAOS_RES *tres, int numOfRows); -void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const char* sqlstr, size_t sqlLen) { - SSqlCmd *pCmd = &pSql->cmd; - SSqlRes *pRes = &pSql->res; - - pSql->signature = pSql; - pSql->param = param; - pSql->pTscObj = pObj; - pSql->maxRetry = TSDB_MAX_REPLICA_NUM; - pSql->fp = fp; - - sem_init(&pSql->rspSem, 0, 0); - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { +int doAsyncParseSql(SSqlObj* pSql, const char* sqlstr, size_t sqlLen) { + SSqlCmd* pCmd = &pSql->cmd; + SSqlRes* pRes = &pSql->res; + int32_t code = tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE); + if (code != TSDB_CODE_SUCCESS) { tscError("failed to malloc payload"); - tscQueueAsyncError(fp, param, TSDB_CODE_CLI_OUT_OF_MEMORY); - return; + tscQueueAsyncError(pSql->fp, pSql->param, TSDB_CODE_CLI_OUT_OF_MEMORY); + return code; } // todo check for OOM problem pSql->sqlstr = calloc(1, sqlLen + 1); if (pSql->sqlstr == NULL) { tscError("%p failed to malloc sql string buffer", pSql); - tscQueueAsyncError(fp, param, TSDB_CODE_CLI_OUT_OF_MEMORY); + tscQueueAsyncError(pSql->fp, pSql->param, TSDB_CODE_CLI_OUT_OF_MEMORY); free(pCmd->payload); - return; + return TSDB_CODE_CLI_OUT_OF_MEMORY; } pRes->qhandle = 0; @@ -72,7 +65,17 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const strtolower(pSql->sqlstr, sqlstr); tscDump("%p SQL: %s", pSql, pSql->sqlstr); - int32_t code = tsParseSql(pSql, true); + return tsParseSql(pSql, true); +} + +void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const char* sqlstr, size_t sqlLen) { + pSql->signature = pSql; + pSql->param = param; + pSql->pTscObj = pObj; + pSql->maxRetry = TSDB_MAX_REPLICA_NUM; + pSql->fp = fp; + + int32_t code = doAsyncParseSql(pSql, sqlstr, sqlLen); if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; if (code != TSDB_CODE_SUCCESS) { diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 83a097f2f5..028ae0592a 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -497,46 +497,18 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p } pSql->signature = pSql; + pSql->param = pSql; pSql->pTscObj = pObj; + pSql->fp = asyncCallback; + SSqlCmd *pCmd = &pSql->cmd; SSqlRes *pRes = &pSql->res; - int ret = tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE); - if (TSDB_CODE_SUCCESS != ret) { - setErrorInfo(pSql, ret, NULL); - free(pSql); - return NULL; - } - - pSql->sqlstr = strdup(sqlstr); - if (pSql->sqlstr == NULL) { - setErrorInfo(pSql, TSDB_CODE_CLI_OUT_OF_MEMORY, NULL); - - tfree(pSql); - return NULL; - } tsem_init(&pSql->rspSem, 0, 0); - - SSqlInfo SQLInfo = {0}; - tSQLParse(&SQLInfo, pSql->sqlstr); - - tscResetSqlCmdObj(&pSql->cmd); - ret = tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE); - if (TSDB_CODE_SUCCESS != ret) { - setErrorInfo(pSql, ret, NULL); - tscError("%p open stream failed, sql:%s, code:%d", pSql, sqlstr, TSDB_CODE_CLI_OUT_OF_MEMORY); - tscFreeSqlObj(pSql); - return NULL; - } - - pSql->param = pSql; - pSql->fp = asyncCallback; - pRes->code = tscToSQLCmd(pSql, &SQLInfo); - if (pRes->code == TSDB_CODE_ACTION_IN_PROGRESS) { + int32_t code = doAsyncParseSql(pSql, sqlstr, strlen(sqlstr)); + if (code == TSDB_CODE_ACTION_IN_PROGRESS) { sem_wait(&pSql->rspSem); } - - SQLInfoDestroy(&SQLInfo); if (pRes->code != TSDB_CODE_SUCCESS) { setErrorInfo(pSql, pRes->code, pCmd->payload); @@ -575,6 +547,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p pStream->stime = tscGetStreamStartTimestamp(pSql, pStream, stime); int64_t starttime = tscGetLaunchTimestamp(pStream); + pCmd->command = TSDB_SQL_SELECT; taosTmrReset(tscProcessStreamTimer, starttime, pStream, tscTmr, &pStream->pTimer); tscTrace("%p stream:%p is opened, query on:%s, interval:%" PRId64 ", sliding:%" PRId64 ", first launched in:%" PRId64 ", sql:%s", pSql, diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index 401d61b7a2..5c936388dd 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -75,7 +75,14 @@ void *cqOpen(void *ahandle, const SCqCfg *pCfg) { strcpy(pContext->user, pCfg->user); strcpy(pContext->pass, pCfg->pass); - strcpy(pContext->db, pCfg->db); + const char* db = pCfg->db; + for (const char* p = db; *p != 0; p++) { + if (*p == '.') { + db = p + 1; + break; + } + } + strcpy(pContext->db, db); pContext->vgId = pCfg->vgId; pContext->cqWrite = pCfg->cqWrite; pContext->ahandle = ahandle; diff --git a/tests/pytest/stream/stream1.py b/tests/pytest/stream/stream1.py new file mode 100644 index 0000000000..7a9d88da3b --- /dev/null +++ b/tests/pytest/stream/stream1.py @@ -0,0 +1,131 @@ +################################################################### +# 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 +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tbNum = 10 + rowNum = 20 + + tdSql.prepare() + + tdLog.info("===== step1 =====") + tdSql.execute("create table stb0(ts timestamp, col1 int, col2 float) tags(tgcol int)") + for i in range(tbNum): + tdSql.execute("create table tb%d using stb0 tags(%d)" % (i, i)) + for j in range(rowNum): + tdSql.execute("insert into tb%d values (now - %dm, %d, %d)" % (i, 1440 - j, j, j)) + time.sleep(0.1) + + tdLog.info("===== step2 =====") + tdSql.query("select count(*), count(col1), count(col2) from tb0 interval(1d)") + tdSql.checkData(0, 1, rowNum) + tdSql.checkData(0, 2, rowNum) + tdSql.checkData(0, 3, rowNum) + tdSql.query("show tables") + tdSql.checkRows(tbNum) + tdSql.execute("create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)") + tdSql.query("show tables") + tdSql.checkRows(tbNum + 1) + + tdLog.info("===== step3 =====") + tdLog.info("sleeping 120 seconds") + time.sleep(120) + tdSql.query("select * from s0") + tdSql.checkData(0, 1, rowNum) + tdSql.checkData(0, 2, rowNum) + tdSql.checkData(0, 3, rowNum) + + tdLog.info("===== step4 =====") + tdSql.execute("drop table s0") + tdSql.query("show tables") + tdSql.checkRows(tbNum) + + tdLog.info("===== step5 =====") + tdSql.error("select * from s0") + + tdLog.info("===== step6 =====") + time.sleep(0.1) + tdSql.execute("create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)") + tdSql.query("show tables") + tdSql.checkRows(tbNum + 1) + + tdLog.info("===== step7 =====") + tdLog.info("sleeping 120 seconds") + time.sleep(120) + + tdSql.query("select * from s0") + tdSql.checkData(0, 1, rowNum) + tdSql.checkData(0, 2, rowNum) + tdSql.checkData(0, 3, rowNum) + + tdLog.info("===== step8 =====") + tdSql.query("select count(*), count(col1), count(col2) from stb0 interval(1d)") + tdSql.checkData(0, 1, rowNum * tbNum) + tdSql.checkData(0, 2, rowNum * tbNum) + tdSql.checkData(0, 3, rowNum * tbNum) + tdSql.query("show tables") + tdSql.checkRows(tbNum + 1) + + tdSql.execute("create table s1 as select count(*), count(col1), count(col2) from stb0 interval(1d)") + tdSql.query("show tables") + tdSql.checkRows(tbNum + 2) + + tdLog.info("===== step9 =====") + tdLog.info("sleeping 120 seconds") + time.sleep(120) + + tdSql.query("select * from s1") + tdSql.checkData(0, 1, rowNum * tbNum) + tdSql.checkData(0, 2, rowNum * tbNum) + tdSql.checkData(0, 3, rowNum * tbNum) + + tdLog.info("===== step10 =====") + tdSql.execute("drop table s1") + tdSql.query("show tables") + tdSql.checkRows(tbNum + 1) + + tdLog.info("===== step11 =====") + tdSql.error("select * from s1") + + tdLog.info("===== step12 =====") + tdSql.execute("create table s1 as select count(*), count(col1), count(col2) from stb0 interval(1d)") + tdSql.query("show tables") + tdSql.checkRows(tbNum + 2) + + tdLog.info("===== step13 =====") + tdLog.info("sleeping 120 seconds") + time.sleep(120) + tdSql.query("select * from s1") + tdSql.checkData(0, 1, rowNum * tbNum) + tdSql.checkData(0, 2, rowNum * tbNum) + tdSql.checkData(0, 3, rowNum * tbNum) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) From efcb54acf1a1822f063ef7f8ad3cb471a240ea37 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Sat, 6 Jun 2020 06:56:26 +0000 Subject: [PATCH 09/72] [TD-530] fix python connector free result behavior --- src/connector/python/linux/python2/taos/cursor.py | 2 -- src/connector/python/linux/python3/taos/cursor.py | 3 --- src/connector/python/windows/python2/taos/cursor.py | 2 -- src/connector/python/windows/python3/taos/cursor.py | 2 -- 4 files changed, 9 deletions(-) diff --git a/src/connector/python/linux/python2/taos/cursor.py b/src/connector/python/linux/python2/taos/cursor.py index 77d517d272..f7c840442e 100644 --- a/src/connector/python/linux/python2/taos/cursor.py +++ b/src/connector/python/linux/python2/taos/cursor.py @@ -93,7 +93,6 @@ class TDengineCursor(object): if self._connection is None: return False - self._connection.clear_result_set() self._reset_result() self._connection = None @@ -201,7 +200,6 @@ class TDengineCursor(object): for i in range(len(self._fields)): buffer[i].extend(block[i]) - self._reset_result() return list(map(tuple, zip(*buffer))) diff --git a/src/connector/python/linux/python3/taos/cursor.py b/src/connector/python/linux/python3/taos/cursor.py index 41feaf93b8..5db5365eb3 100644 --- a/src/connector/python/linux/python3/taos/cursor.py +++ b/src/connector/python/linux/python3/taos/cursor.py @@ -95,7 +95,6 @@ class TDengineCursor(object): if self._connection is None: return False - self._connection.clear_result_set() self._reset_result() self._connection = None @@ -203,8 +202,6 @@ class TDengineCursor(object): for i in range(len(self._fields)): buffer[i].extend(block[i]) - self._reset_result() - return list(map(tuple, zip(*buffer))) def nextset(self): diff --git a/src/connector/python/windows/python2/taos/cursor.py b/src/connector/python/windows/python2/taos/cursor.py index 183c42a291..1da726638a 100644 --- a/src/connector/python/windows/python2/taos/cursor.py +++ b/src/connector/python/windows/python2/taos/cursor.py @@ -86,7 +86,6 @@ class TDengineCursor(object): if self._connection is None: return False - self._connection.clear_result_set() self._reset_result() self._connection = None @@ -148,7 +147,6 @@ class TDengineCursor(object): for i in range(len(self._fields)): buffer[i].extend(block[i]) - self._reset_result() return list(map(tuple, zip(*buffer))) diff --git a/src/connector/python/windows/python3/taos/cursor.py b/src/connector/python/windows/python3/taos/cursor.py index ddf6d0b315..2dcd0aaccb 100644 --- a/src/connector/python/windows/python3/taos/cursor.py +++ b/src/connector/python/windows/python3/taos/cursor.py @@ -86,7 +86,6 @@ class TDengineCursor(object): if self._connection is None: return False - self._connection.clear_result_set() self._reset_result() self._connection = None @@ -148,7 +147,6 @@ class TDengineCursor(object): for i in range(len(self._fields)): buffer[i].extend(block[i]) - self._reset_result() return list(map(tuple, zip(*buffer))) From 51de20d2e0c0dea8bec77be77258c2db2283c328 Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Fri, 5 Jun 2020 19:00:04 +0800 Subject: [PATCH 10/72] td-449: more cases passedcurrently, only below four cases fail:* agg_stream.sim ('us' ?)* column_stream.sim ('us' ?)* table_replica1_vnoden.sim (crash)* new_stream.sim (failed at line 101) --- src/client/inc/tsclient.h | 2 +- src/client/src/tscAsync.c | 34 ++--- src/client/src/tscStream.c | 40 +++--- src/common/inc/tdataformat.h | 1 + src/cq/src/cqMain.c | 19 ++- tests/pytest/stream/stream2.py | 122 ++++++++++++++++++ tests/script/general/stream/metrics_1.sim | 4 +- tests/script/general/stream/metrics_del.sim | 10 +- tests/script/general/stream/metrics_n.sim | 4 +- .../stream/metrics_replica1_vnoden.sim | 4 +- .../script/general/stream/restart_stream.sim | 8 +- tests/script/general/stream/stream_1.sim | 16 +-- tests/script/general/stream/stream_2.sim | 20 +-- tests/script/general/stream/stream_3.sim | 8 +- .../script/general/stream/stream_restart.sim | 4 +- tests/script/general/stream/table_1.sim | 4 +- tests/script/general/stream/table_del.sim | 10 +- tests/script/general/stream/table_n.sim | 4 +- 18 files changed, 210 insertions(+), 104 deletions(-) create mode 100644 tests/pytest/stream/stream2.py diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index e92bb5e64e..5356a71579 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -404,7 +404,7 @@ TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void *param, void **taos); void waitForQueryRsp(void *param, TAOS_RES *tres, int code) ; -int doAsyncParseSql(SSqlObj* pSql, const char* sqlstr, size_t sqlLen); +int doAsyncParseSql(SSqlObj* pSql); void doAsyncQuery(STscObj *pObj, SSqlObj *pSql, void (*fp)(), void *param, const char *sqlstr, size_t sqlLen); void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql); diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index bd2dc64ef0..3cf9e0daa5 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -40,7 +40,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo static void tscAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOfRows); static void tscAsyncFetchSingleRowProxy(void *param, TAOS_RES *tres, int numOfRows); -int doAsyncParseSql(SSqlObj* pSql, const char* sqlstr, size_t sqlLen) { +int doAsyncParseSql(SSqlObj* pSql) { SSqlCmd* pCmd = &pSql->cmd; SSqlRes* pRes = &pSql->res; int32_t code = tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE); @@ -50,21 +50,10 @@ int doAsyncParseSql(SSqlObj* pSql, const char* sqlstr, size_t sqlLen) { return code; } - // todo check for OOM problem - pSql->sqlstr = calloc(1, sqlLen + 1); - if (pSql->sqlstr == NULL) { - tscError("%p failed to malloc sql string buffer", pSql); - tscQueueAsyncError(pSql->fp, pSql->param, TSDB_CODE_CLI_OUT_OF_MEMORY); - free(pCmd->payload); - return TSDB_CODE_CLI_OUT_OF_MEMORY; - } - pRes->qhandle = 0; pRes->numOfRows = 1; - strtolower(pSql->sqlstr, sqlstr); tscDump("%p SQL: %s", pSql, pSql->sqlstr); - return tsParseSql(pSql, true); } @@ -74,8 +63,15 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const pSql->pTscObj = pObj; pSql->maxRetry = TSDB_MAX_REPLICA_NUM; pSql->fp = fp; + pSql->sqlstr = calloc(1, sqlLen + 1); + if (pSql->sqlstr == NULL) { + tscError("%p failed to malloc sql string buffer", pSql); + tscQueueAsyncError(pSql->fp, pSql->param, TSDB_CODE_CLI_OUT_OF_MEMORY); + return; + } + strtolower(pSql->sqlstr, sqlstr); - int32_t code = doAsyncParseSql(pSql, sqlstr, sqlLen); + int32_t code = doAsyncParseSql(pSql); if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; if (code != TSDB_CODE_SUCCESS) { @@ -521,15 +517,9 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { if (pSql->pStream) { tscTrace("%p stream:%p meta is updated, start new query, command:%d", pSql, pSql->pStream, pSql->cmd.command); - /* - * NOTE: - * transfer the sql function for super table query before get meter/metric meta, - * since in callback functions, only tscProcessSql(pStream->pSql) is executed! - */ - SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); - - tscTansformSQLFuncForSTableQuery(pQueryInfo); - tscIncStreamExecutionCount(pSql->pStream); + tsParseSql(pSql, false); + sem_post(&pSql->rspSem); + return; } else { tscTrace("%p get tableMeta successfully", pSql); } diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 028ae0592a..c4c9860f3b 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -99,7 +99,7 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) { } tscTrace("%p stream:%p start stream query on:%s", pSql, pStream, pTableMetaInfo->name); - tscProcessSql(pStream->pSql); + tscDoQuery(pStream->pSql); tscIncStreamExecutionCount(pStream); } @@ -477,14 +477,6 @@ static void setErrorInfo(SSqlObj* pSql, int32_t code, char* info) { } } -static void asyncCallback(void *param, TAOS_RES *tres, int code) { - assert(param != NULL); - SSqlObj *pSql = ((SSqlObj *)param); - - pSql->res.code = code; - sem_post(&pSql->rspSem); -} - TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), int64_t stime, void *param, void (*callback)(void *)) { STscObj *pObj = (STscObj *)taos; @@ -492,20 +484,34 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { - setErrorInfo(pSql, TSDB_CODE_CLI_OUT_OF_MEMORY, NULL); return NULL; } pSql->signature = pSql; pSql->param = pSql; pSql->pTscObj = pObj; - pSql->fp = asyncCallback; SSqlCmd *pCmd = &pSql->cmd; SSqlRes *pRes = &pSql->res; + SSqlStream *pStream = (SSqlStream *)calloc(1, sizeof(SSqlStream)); + if (pStream == NULL) { + tscError("%p open stream failed, sql:%s, reason:%s, code:%d", pSql, sqlstr, pCmd->payload, pRes->code); + tscFreeSqlObj(pSql); + return NULL; + } + pSql->pStream = pStream; + + pSql->sqlstr = calloc(1, strlen(sqlstr) + 1); + if (pSql->sqlstr == NULL) { + tscError("%p failed to malloc sql string buffer", pSql); + tscFreeSqlObj(pSql); + return NULL;; + } + strtolower(pSql->sqlstr, sqlstr); + tsem_init(&pSql->rspSem, 0, 0); - int32_t code = doAsyncParseSql(pSql, sqlstr, strlen(sqlstr)); + int32_t code = doAsyncParseSql(pSql); if (code == TSDB_CODE_ACTION_IN_PROGRESS) { sem_wait(&pSql->rspSem); } @@ -518,15 +524,6 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p return NULL; } - SSqlStream *pStream = (SSqlStream *)calloc(1, sizeof(SSqlStream)); - if (pStream == NULL) { - setErrorInfo(pSql, TSDB_CODE_CLI_OUT_OF_MEMORY, NULL); - - tscError("%p open stream failed, sql:%s, reason:%s, code:%d", pSql, sqlstr, pCmd->payload, pRes->code); - tscFreeSqlObj(pSql); - return NULL; - } - SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); @@ -540,7 +537,6 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p pStream->ctime = taosGetTimestamp(pStream->precision); pStream->etime = pQueryInfo->window.ekey; - pSql->pStream = pStream; tscAddIntoStreamList(pStream); tscSetSlidingWindowInfo(pSql, pStream); diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index 3a84ce8f6f..ec4e544e18 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -145,6 +145,7 @@ void tdFreeDataRow(SDataRow row); void tdInitDataRow(SDataRow row, STSchema *pSchema); SDataRow tdDataRowDup(SDataRow row); +// offset here not include dataRow header length static FORCE_INLINE int tdAppendColVal(SDataRow row, void *value, int8_t type, int32_t bytes, int32_t offset) { ASSERT(value != NULL); int32_t toffset = offset + TD_DATA_ROW_HEAD_SIZE; diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index 5c936388dd..23455b6f50 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -246,13 +246,7 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { cTrace("vgId:%d, id:%d CQ:%s stream result is ready", pContext->vgId, pObj->tid, pObj->sqlStr); - int32_t flen = 0; - for (int32_t i = 0; i < pSchema->numOfCols; i++) { - flen += TYPE_BYTES[pSchema->columns[i].type]; - } - - // construct data - int size = sizeof(SWalHead) + sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + TD_DATA_ROW_HEAD_SIZE + flen; + int size = sizeof(SWalHead) + sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + TD_DATA_ROW_HEAD_SIZE + pObj->rowSize; char *buffer = calloc(size, 1); SWalHead *pHead = (SWalHead *)buffer; @@ -260,12 +254,15 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { SSubmitBlk *pBlk = (SSubmitBlk *) (buffer + sizeof(SWalHead) + sizeof(SSubmitMsg)); SDataRow trow = (SDataRow)pBlk->data; - dataRowSetLen(trow, TD_DATA_ROW_HEAD_SIZE + flen); + tdInitDataRow(trow, pSchema); - int toffset = 0; for (int32_t i = 0; i < pSchema->numOfCols; i++) { - tdAppendColVal(trow, row[i], pSchema->columns[i].type, pSchema->columns[i].bytes, toffset); - toffset += TYPE_BYTES[pSchema->columns[i].type]; + STColumn *c = pSchema->columns + i; + char* val = (char*)row[i]; + if (IS_VAR_DATA_TYPE(c->type)) { + val -= sizeof(VarDataLenT); + } + tdAppendColVal(trow, val, c->type, c->bytes, c->offset); } pBlk->len = htonl(dataRowLen(trow)); diff --git a/tests/pytest/stream/stream2.py b/tests/pytest/stream/stream2.py new file mode 100644 index 0000000000..96eff3131d --- /dev/null +++ b/tests/pytest/stream/stream2.py @@ -0,0 +1,122 @@ +################################################################### +# 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 +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + + def run(self): + tbNum = 10 + rowNum = 20 + totalNum = tbNum * rowNum + + tdSql.prepare() + + tdLog.info("===== step1 =====") + tdSql.execute("create table stb0(ts timestamp, col1 int, col2 float) tags(tgcol int)") + for i in range(tbNum): + tdSql.execute("create table tb%d using stb0 tags(%d)" % (i, i)) + for j in range(rowNum): + tdSql.execute("insert into tb%d values (now - %dm, %d, %d)" % (i, 1440 - j, j, j)) + time.sleep(0.1) + + tdLog.info("===== step2 =====") + tdSql.query("select count(col1) from tb0 interval(1d)") + tdSql.checkData(0, 1, rowNum) + tdSql.query("show tables") + tdSql.checkRows(tbNum) + tdSql.execute("create table s0 as select count(col1) from tb0 interval(1d)") + tdSql.query("show tables") + tdSql.checkRows(tbNum + 1) + + tdLog.info("===== step3 =====") + time.sleep(120) + tdSql.query("select * from s0") + tdSql.checkData(0, 1, rowNum) + + tdLog.info("===== step4 =====") + tdSql.execute("drop table s0") + tdSql.query("show tables") + tdSql.checkRows(tbNum) + + tdLog.info("===== step5 =====") + tdSql.error("select * from s0") + + tdLog.info("===== step6 =====") + tdSql.execute("create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)") + tdSql.query("show tables") + tdSql.checkRows(tbNum + 1) + + tdLog.info("===== step7 =====") + time.sleep(120) + tdSql.query("select * from s0") + tdSql.checkData(0, 1, rowNum) + tdSql.checkData(0, 2, rowNum) + tdSql.checkData(0, 3, rowNum) + + tdLog.info("===== step8 =====") + tdSql.query("select count(*), count(col1), count(col2) from stb0 interval(1d)") + tdSql.checkData(0, 1, totalNum) + tdSql.checkData(0, 2, totalNum) + tdSql.checkData(0, 3, totalNum) + tdSql.query("show tables") + tdSql.checkRows(tbNum + 1) + tdSql.execute("create table s1 as select count(*), count(col1), count(col2) from stb0 interval(1d)") + tdSql.query("show tables") + tdSql.checkRows(tbNum + 2) + + tdLog.info("===== step9 =====") + time.sleep(120) + tdSql.query("select * from s1") + tdSql.checkData(0, 1, totalNum) + tdSql.checkData(0, 2, totalNum) + tdSql.checkData(0, 3, totalNum) + + tdLog.info("===== step10 =====") + tdSql.execute("drop table s1") + tdSql.query("show tables") + tdSql.checkRows(tbNum + 1) + + tdLog.info("===== step11 =====") + tdSql.error("select * from s1") + + tdLog.info("===== step12 =====") + tdSql.execute("create table s1 as select count(col1) from stb0 interval(1d)") + tdSql.query("show tables") + tdSql.checkRows(tbNum + 2) + + tdLog.info("===== step13 =====") + time.sleep(120) + tdSql.query("select * from s1") + tdSql.checkData(0, 1, totalNum) + #tdSql.checkData(0, 2, None) + #tdSql.checkData(0, 3, None) + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/script/general/stream/metrics_1.sim b/tests/script/general/stream/metrics_1.sim index c60bde6b2f..94498cb925 100644 --- a/tests/script/general/stream/metrics_1.sim +++ b/tests/script/general/stream/metrics_1.sim @@ -205,8 +205,8 @@ if $data01 != 20 then endi print =============== step21 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 print =============== step22 $st = $stPrefix . c1 diff --git a/tests/script/general/stream/metrics_del.sim b/tests/script/general/stream/metrics_del.sim index c856871e93..e21fa5999a 100644 --- a/tests/script/general/stream/metrics_del.sim +++ b/tests/script/general/stream/metrics_del.sim @@ -76,20 +76,20 @@ endw sql drop table $mt print =============== step4 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 print =============== step5 $st = $stPrefix . c3 sql select * from $st print ===> select * from $st print ===> $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 -if $data01 != NULL then +if $data01 != null then return -1 endi -if $data02 != NULL then +if $data02 != null then return -1 endi -if $data03 != NULL then +if $data03 != null then return -1 endi diff --git a/tests/script/general/stream/metrics_n.sim b/tests/script/general/stream/metrics_n.sim index 47089403dd..7fc08064b2 100644 --- a/tests/script/general/stream/metrics_n.sim +++ b/tests/script/general/stream/metrics_n.sim @@ -187,8 +187,8 @@ $st = $stPrefix . as #sql create table $st as select avg(tbcol) as a1, sum(tbcol) as a2, min(tbcol) as a3, max(tbcol) as a4, first(tbcol) as a5, last(tbcol) as a6, count(tbcol) as a7, avg(tbcol) as a8, sum(tbcol) as a9, min(tbcol) as a3, max(tbcol) as a4, first(tbcol) as a5, last(tbcol) as a6, count(tbcol) as a7 from $mt where ts < now + 4m interval(1d) print =============== step9 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 print =============== step10 $st = $stPrefix . c3 diff --git a/tests/script/general/stream/metrics_replica1_vnoden.sim b/tests/script/general/stream/metrics_replica1_vnoden.sim index 13cd18adf3..ee071fd681 100644 --- a/tests/script/general/stream/metrics_replica1_vnoden.sim +++ b/tests/script/general/stream/metrics_replica1_vnoden.sim @@ -163,8 +163,8 @@ $st = $stPrefix . as sql create table $st as select count(tbcol) as c from $mt interval(1d) print =============== step13 -print sleep 22 seconds -sleep 32000 +print sleep 120 seconds +sleep 120000 print =============== step14 $st = $stPrefix . c1 diff --git a/tests/script/general/stream/restart_stream.sim b/tests/script/general/stream/restart_stream.sim index aa16934f33..138e2a6e2e 100644 --- a/tests/script/general/stream/restart_stream.sim +++ b/tests/script/general/stream/restart_stream.sim @@ -73,8 +73,8 @@ print =============== step3 sql create table $stt as select count(*) from $tb interval(1d) sql create table $stm as select count(*) from $mt interval(1d) -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 sql select * from $stt print select count(*) from $stt ===> $data00 $data01 @@ -152,8 +152,8 @@ print =============== step8 sql create table $stt as select count(*) from $tb interval(1d) sql create table $stm as select count(*) from $mt interval(1d) -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 sql select * from $stt sleep 1000 diff --git a/tests/script/general/stream/stream_1.sim b/tests/script/general/stream/stream_1.sim index 2309d341c1..958c877ee5 100644 --- a/tests/script/general/stream/stream_1.sim +++ b/tests/script/general/stream/stream_1.sim @@ -78,8 +78,8 @@ if $rows != 11 then endi print =============== step3 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 sql select * from $st print select * from $st => $data01 if $data01 != 20 then @@ -112,8 +112,8 @@ if $rows != 11 then endi print =============== step7 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 sql select * from $st print select * from $st => $data01 if $data01 != 20 then @@ -155,8 +155,8 @@ if $rows != 12 then endi print =============== step9 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 sql select * from $st print select * from $st => $data01 if $data01 != 200 then @@ -190,8 +190,8 @@ if $rows != 12 then endi print =============== step13 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 sql select * from $st print select * from $st => $data01 if $data01 != 200 then diff --git a/tests/script/general/stream/stream_2.sim b/tests/script/general/stream/stream_2.sim index 13aac98337..057529b427 100644 --- a/tests/script/general/stream/stream_2.sim +++ b/tests/script/general/stream/stream_2.sim @@ -72,8 +72,8 @@ if $rows != 11 then endi print =============== step3 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 sql select * from $st print select * from $st => $data01 if $data01 != 20 then @@ -100,8 +100,8 @@ if $rows != 11 then endi print =============== step7 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 sql select * from $st print select * from $st => $data01 if $data01 != 20 then @@ -143,8 +143,8 @@ if $rows != 12 then endi print =============== step9 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 sql select * from $st print select * from $st => $data01 $data02, $data03 if $data01 != 200 then @@ -178,17 +178,17 @@ if $rows != 12 then endi print =============== step13 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 sql select * from $st print select * from $st => $data01 $data02, $data03 if $data01 != 200 then return -1 endi -if $data02 != NULL then +if $data02 != null then return -1 endi -if $data03 != NULL then +if $data03 != null then return -1 endi diff --git a/tests/script/general/stream/stream_3.sim b/tests/script/general/stream/stream_3.sim index 914ecd8484..88105a77d6 100644 --- a/tests/script/general/stream/stream_3.sim +++ b/tests/script/general/stream/stream_3.sim @@ -79,8 +79,8 @@ $st = $stPrefix . c3 sql create table $st as select count(tbcol2) from $tb interval(1d) print =============== step5 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 print =============== step6 $st = $stPrefix . c1 @@ -173,8 +173,8 @@ $st = $stPrefix . c3 sql create table $st as select count(*), count(tbcol), count(tbcol2) from $tb interval(1d) print =============== step10 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 print =============== step11 #$st = $stPrefix . c3 diff --git a/tests/script/general/stream/stream_restart.sim b/tests/script/general/stream/stream_restart.sim index d5fbef4908..480b23055e 100644 --- a/tests/script/general/stream/stream_restart.sim +++ b/tests/script/general/stream/stream_restart.sim @@ -79,8 +79,8 @@ sleep 1000 system sh/exec.sh -n dnode1 -s start print =============== step4 -print sleep 23 seconds -sleep 23000 +print sleep 120 seconds +sleep 120000 print =============== step5 $i = 1 diff --git a/tests/script/general/stream/table_1.sim b/tests/script/general/stream/table_1.sim index efc7c370ca..f028b1626d 100644 --- a/tests/script/general/stream/table_1.sim +++ b/tests/script/general/stream/table_1.sim @@ -214,8 +214,8 @@ sql select count(tbcol) from $tb where ts < now + 4m interval(1d) group by tgcol step20: print =============== step21 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 print =============== step22 $st = $stPrefix . c1 diff --git a/tests/script/general/stream/table_del.sim b/tests/script/general/stream/table_del.sim index 66fd58308f..ce4065a1a8 100644 --- a/tests/script/general/stream/table_del.sim +++ b/tests/script/general/stream/table_del.sim @@ -71,20 +71,20 @@ print =============== step3 sql drop table $tb print =============== step4 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 print =============== step5 $st = $stPrefix . c3 sql select * from $st print ===> select * from $st print ===> $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 -if $data01 != NULL then +if $data01 != null then return -1 endi -if $data02 != NULL then +if $data02 != null then return -1 endi -if $data03 != NULL then +if $data03 != null then return -1 endi diff --git a/tests/script/general/stream/table_n.sim b/tests/script/general/stream/table_n.sim index e6037c5292..d1b4a87a9e 100644 --- a/tests/script/general/stream/table_n.sim +++ b/tests/script/general/stream/table_n.sim @@ -191,8 +191,8 @@ $st = $stPrefix . as #sql create table $st as select avg(tbcol) as a1, sum(tbcol) as a2, min(tbcol) as a3, max(tbcol) as a4, first(tbcol) as a5, last(tbcol) as a6, stddev(tbcol) as a7, percentile(tbcol, 1) as a8, count(tbcol) as a9, leastsquares(tbcol, 1, 1) as a10 from $tb where ts < now + 4m interval(1d) print =============== step10 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 print =============== step11 $st = $stPrefix . c3 From 6520c28514cfacf88eacc69f3e9d5931d836ad1c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 6 Jun 2020 07:17:57 +0000 Subject: [PATCH 11/72] update kv store header --- src/util/src/tkvstore.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/src/tkvstore.c b/src/util/src/tkvstore.c index 30052a379f..741f953310 100644 --- a/src/util/src/tkvstore.c +++ b/src/util/src/tkvstore.c @@ -41,6 +41,7 @@ static SKVStore *tdNewKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void static char * tdGetKVStoreSnapshotFname(char *fdata); static char * tdGetKVStoreNewFname(char *fdata); static void tdFreeKVStore(SKVStore *pStore); +static int tdUpdateKVStoreHeader(int fd, char *fname, SStoreInfo *pInfo); int tdCreateKVStore(char *fname) { char *tname = strdup(fname); @@ -164,6 +165,9 @@ _err: int tdKVStoreEndCommit(SKVStore *pStore) { ASSERT(pStore->fd > 0); + terrno = tdUpdateKVStoreHeader(pStore->fd, pStore->fname, &(pStore->info)); + if (terrno != TSDB_CODE_SUCCESS) return -1; + if (fsync(pStore->fd) < 0) { uError("failed to fsync file %s since %s", pStore->fname, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); From 086a3a4a79cb1b17e62891e56abf61a5b90c6936 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 6 Jun 2020 15:47:28 +0800 Subject: [PATCH 12/72] [td-428] --- src/client/src/tscPrepare.c | 1 - src/client/src/tscSQLParser.c | 19 ++++--- src/client/src/tscServer.c | 2 +- src/client/src/tscSql.c | 42 -------------- src/client/src/tscUtil.c | 14 +++-- src/kit/shell/src/shellEngine.c | 6 +- src/kit/shell/src/shellMain.c | 11 ++-- src/query/src/qExecutor.c | 98 +++++++++++++++++++++------------ 8 files changed, 94 insertions(+), 99 deletions(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 519d7da4fb..2093e8f741 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -24,7 +24,6 @@ #include "tscSubquery.h" int tsParseInsertSql(SSqlObj *pSql); -int taos_query_imp(STscObj* pObj, SSqlObj* pSql); //////////////////////////////////////////////////////////////////////////////// // functions for normal statement preparation diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 32ec0a0db1..d6136a2ad1 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -41,7 +41,7 @@ #define COLUMN_INDEX_VALIDE(index) (((index).tableIndex >= 0) && ((index).columnIndex >= TSDB_TBNAME_COLUMN_INDEX)) #define TBNAME_LIST_SEP "," -typedef struct SColumnList { +typedef struct SColumnList { // todo refactor int32_t num; SColumnIndex ids[TSDB_MAX_COLUMNS]; } SColumnList; @@ -1517,12 +1517,14 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); // count tag is equalled to count(tbname) - if (index.columnIndex >= tscGetNumOfColumns(pTableMetaInfo->pTableMeta)) { + bool isTag = false; + if (index.columnIndex >= tscGetNumOfColumns(pTableMetaInfo->pTableMeta) || index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { index.columnIndex = TSDB_TBNAME_COLUMN_INDEX; + isTag = true; } int32_t size = tDataTypeDesc[TSDB_DATA_TYPE_BIGINT].nSize; - pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size, false); + pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size, isTag); } } else { // count(*) is equalled to count(primary_timestamp_key) index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX}; @@ -1543,10 +1545,13 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr tscColumnListInsert(pQueryInfo->colList, &(ids.ids[i])); } } - - SColumnIndex tsCol = {.tableIndex = index.tableIndex, .columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX}; - tscColumnListInsert(pQueryInfo->colList, &tsCol); - + + // the time stamp may be always needed + if (index.tableIndex > 0 && index.tableIndex < tscGetNumOfColumns(pTableMetaInfo->pTableMeta)) { + SColumnIndex tsCol = {.tableIndex = index.tableIndex, .columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX}; + tscColumnListInsert(pQueryInfo->colList, &tsCol); + } + return TSDB_CODE_SUCCESS; } case TK_SUM: diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index d2e6e0ac3f..39b9350284 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -605,7 +605,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { tscError("%p failed to malloc for query msg", pSql); - return -1; + return -1; // todo add test for this } SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index e5832bacfc..dd0b0627ac 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -213,48 +213,6 @@ void taos_close(TAOS *taos) { } } -int taos_query_imp(STscObj *pObj, SSqlObj *pSql) { - SSqlRes *pRes = &pSql->res; - SSqlCmd *pCmd = &pSql->cmd; - - pRes->numOfRows = 1; - pRes->numOfTotal = 0; - pRes->numOfClauseTotal = 0; - - pCmd->curSql = NULL; - if (NULL != pCmd->pTableList) { - taosHashCleanup(pCmd->pTableList); - pCmd->pTableList = NULL; - } - - tscDump("%p pObj:%p, SQL: %s", pSql, pObj, pSql->sqlstr); - - pRes->code = (uint8_t)tsParseSql(pSql, false); - - /* - * set the qhandle to 0 before return in order to erase the qhandle value assigned in the previous successful query. - * If qhandle is NOT set 0, the function of taos_free_result() will send message to server by calling tscProcessSql() - * to free connection, which may cause segment fault, when the parse phrase is not even successfully executed. - */ - pRes->qhandle = 0; - - if (pRes->code == TSDB_CODE_SUCCESS) { - tscDoQuery(pSql); - } - - if (pRes->code == TSDB_CODE_SUCCESS) { - tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(pObj), pObj); - } else { - tscError("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(pObj), pObj); - } - - if (pRes->code != TSDB_CODE_SUCCESS) { - tscPartiallyFreeSqlObj(pSql); - } - - return pRes->code; -} - void waitForQueryRsp(void *param, TAOS_RES *tres, int code) { assert(tres != NULL); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 811d0920f9..d494700715 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -79,8 +79,14 @@ bool tscQueryOnSTable(SSqlCmd* pCmd) { bool tscQueryTags(SQueryInfo* pQueryInfo) { for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { - int32_t functId = tscSqlExprGet(pQueryInfo, i)->functionId; - + SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i); + int32_t functId = pExpr->functionId; + + // "select count(tbname)" query + if (functId == TSDB_FUNC_COUNT && pExpr->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { + continue; + } + if (functId != TSDB_FUNC_TAGPRJ && functId != TSDB_FUNC_TID_TAG) { return false; } @@ -208,13 +214,14 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { return true; } +// not order by timestamp projection query on super table bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { if (!tscIsProjectionQueryOnSTable(pQueryInfo, tableIndex)) { return false; } // order by columnIndex exists, not a non-ordered projection query - return pQueryInfo->order.orderColId < 0; + return pQueryInfo->order.orderColId < 0 && pQueryInfo->order.orderColId != TSDB_TBNAME_COLUMN_INDEX; } bool tscOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { @@ -984,7 +991,6 @@ static SSqlExpr* doBuildSqlExpr(SQueryInfo* pQueryInfo, int16_t functionId, SCol pExpr->uid = pTableMetaInfo->pTableMeta->uid; } - return pExpr; } diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index a01decc6c6..6dfe424fbc 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -858,9 +858,9 @@ void shellGetGrantInfo(void *con) { char sql[] = "show grants"; - TAOS_RES* pSql = taos_query(con, sql); - int code = taos_errno(pSql); - + result = taos_query(con, sql); + + int code = taos_errno(result); if (code != TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_OPS_NOT_SUPPORT) { fprintf(stdout, "Server is Community Edition, version is %s\n\n", taos_get_server_info(con)); diff --git a/src/kit/shell/src/shellMain.c b/src/kit/shell/src/shellMain.c index 1fbe04208c..92474bdd03 100644 --- a/src/kit/shell/src/shellMain.c +++ b/src/kit/shell/src/shellMain.c @@ -16,21 +16,19 @@ #include "os.h" #include "shell.h" #include "tsclient.h" -#include "tutil.h" -TAOS_RES* con; pthread_t pid; // TODO: IMPLEMENT INTERRUPT HANDLER. void interruptHandler(int signum) { #ifdef LINUX - taos_stop_query(con); - if (con != NULL) { + taos_stop_query(result); + if (result != NULL) { /* * we need to free result in async model, in order to avoid free * results while the master thread is waiting for server response. */ - tscQueueAsyncFreeResult(con); + tscQueueAsyncFreeResult(result); } result = NULL; @@ -88,7 +86,7 @@ int main(int argc, char* argv[]) { shellParseArgument(argc, argv, &args); /* Initialize the shell */ - con = shellInit(&args); + TAOS* con = shellInit(&args); if (con == NULL) { exit(EXIT_FAILURE); } @@ -109,5 +107,4 @@ int main(int argc, char* argv[]) { pthread_create(&pid, NULL, shellLoopQuery, con); pthread_join(pid, NULL); } - return 0; } diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index fd718f4ac0..ce5286af58 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1590,8 +1590,11 @@ static bool needReverseScan(SQuery *pQuery) { static bool onlyQueryTags(SQuery* pQuery) { for(int32_t i = 0; i < pQuery->numOfOutput; ++i) { - int32_t functionId = pQuery->pSelectExpr[i].base.functionId; - if (functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TID_TAG) { + SExprInfo* pExprInfo = &pQuery->pSelectExpr[i]; + + int32_t functionId = pExprInfo->base.functionId; + if (functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TID_TAG && + (!(functionId == TSDB_FUNC_COUNT && pExprInfo->base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX))) { return false; } } @@ -4885,6 +4888,10 @@ static int32_t getColumnIndexInSource(SQueryTableMsg *pQueryMsg, SSqlFuncMsg *pE int32_t j = 0; if (TSDB_COL_IS_TAG(pExprMsg->colInfo.flag)) { + if (pExprMsg->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { + return -1; + } + while(j < pQueryMsg->numOfTags) { if (pExprMsg->colInfo.colId == pTagCols[j].colId) { return j; @@ -4942,8 +4949,11 @@ static bool validateQuerySourceCols(SQueryTableMsg *pQueryMsg, SSqlFuncMsg** pEx return false; } else if (numOfTotal == 0) { for(int32_t i = 0; i < pQueryMsg->numOfOutput; ++i) { - if ((pExprMsg[i]->functionId == TSDB_FUNC_TAGPRJ) || - (pExprMsg[i]->functionId == TSDB_FUNC_TID_TAG && pExprMsg[i]->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX)) { + SSqlFuncMsg* pFuncMsg = pExprMsg[i]; + + if ((pFuncMsg->functionId == TSDB_FUNC_TAGPRJ) || + (pFuncMsg->functionId == TSDB_FUNC_TID_TAG && pFuncMsg->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) || + (pFuncMsg->functionId == TSDB_FUNC_COUNT && pFuncMsg->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX)) { continue; } @@ -5079,8 +5089,8 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, } } - if (pExprMsg->functionId == TSDB_FUNC_TAG || pExprMsg->functionId == TSDB_FUNC_TAGPRJ || - pExprMsg->functionId == TSDB_FUNC_TAG_DUMMY) { + int16_t functionId = pExprMsg->functionId; + if (functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_TAG_DUMMY) { if (pExprMsg->colInfo.flag != TSDB_COL_TAG) { // ignore the column index check for arithmetic expression. return TSDB_CODE_INVALID_QUERY_MSG; } @@ -5192,12 +5202,12 @@ static int32_t buildAirthmeticExprFromMsg(SExprInfo *pArithExprInfo, SQueryTable return TSDB_CODE_SUCCESS; } -static int32_t createSqlFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg, +static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg, SColumnInfo* pTagCols) { *pExprInfo = NULL; int32_t code = TSDB_CODE_SUCCESS; - SExprInfo *pExprs = (SExprInfo *)calloc(1, sizeof(SExprInfo) * pQueryMsg->numOfOutput); + SExprInfo *pExprs = (SExprInfo *)calloc(pQueryMsg->numOfOutput, sizeof(SExprInfo)); if (pExprs == NULL) { return TSDB_CODE_SERV_OUT_OF_MEMORY; } @@ -5223,16 +5233,22 @@ static int32_t createSqlFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo type = TSDB_DATA_TYPE_DOUBLE; bytes = tDataTypeDesc[type].nSize; - } else if (pExprs[i].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { // parse the normal column + } else if (pExprs[i].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX && pExprs[i].base.functionId == TSDB_FUNC_TAGPRJ) { // parse the normal column type = TSDB_DATA_TYPE_BINARY; bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; - } else{ + } else { int32_t j = getColumnIndexInSource(pQueryMsg, &pExprs[i].base, pTagCols); - assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags); + assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags || j == TSDB_TBNAME_COLUMN_INDEX); + + if (pExprs[i].base.colInfo.colId != TSDB_TBNAME_COLUMN_INDEX) { + SColumnInfo* pCol = (TSDB_COL_IS_TAG(pExprs[i].base.colInfo.flag))? &pTagCols[j]:&pQueryMsg->colList[j]; + type = pCol->type; + bytes = pCol->bytes; + } else { + type = TSDB_DATA_TYPE_BINARY; + bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + } - SColumnInfo* pCol = (TSDB_COL_IS_TAG(pExprs[i].base.colInfo.flag))? &pTagCols[j]:&pQueryMsg->colList[j]; - type = pCol->type; - bytes = pCol->bytes; } int32_t param = pExprs[i].base.arg[0].argValue.i64; @@ -5485,7 +5501,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, } // set the output buffer capacity - pQuery->rec.capacity = 4096; + pQuery->rec.capacity = 2; pQuery->rec.threshold = 4000; for (int32_t col = 0; col < pQuery->numOfOutput; ++col) { @@ -5824,7 +5840,7 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi } SExprInfo *pExprs = NULL; - if ((code = createSqlFunctionExprFromMsg(pQueryMsg, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) { + if ((code = createQFunctionExprFromMsg(pQueryMsg, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) { goto _over; } @@ -5926,6 +5942,7 @@ void qTableQuery(qinfo_t qinfo) { qTrace("QInfo:%p query task is launched", pQInfo); if (onlyQueryTags(pQInfo->runtimeEnv.pQuery)) { + assert(pQInfo->runtimeEnv.pQueryHandle == NULL); buildTagQueryResult(pQInfo); // todo support the limit/offset } else if (pQInfo->runtimeEnv.stableQuery) { stableQueryImpl(pQInfo); @@ -6028,24 +6045,29 @@ static void buildTagQueryResult(SQInfo* pQInfo) { SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQuery * pQuery = pRuntimeEnv->pQuery; - size_t num = taosArrayGetSize(pQInfo->groupInfo.pGroupList); - assert(num == 0 || num == 1); - if (num == 0) { + size_t numOfGroup = taosArrayGetSize(pQInfo->groupInfo.pGroupList); + assert(numOfGroup == 0 || numOfGroup == 1); + + if (numOfGroup == 0) { return; } SArray* pa = taosArrayGetP(pQInfo->groupInfo.pGroupList, 0); - num = taosArrayGetSize(pa); - + + size_t num = taosArrayGetSize(pa); assert(num == pQInfo->groupInfo.numOfTables); + + int32_t count = 0; int32_t functionId = pQuery->pSelectExpr[0].base.functionId; if (functionId == TSDB_FUNC_TID_TAG) { // return the tags & table Id assert(pQuery->numOfOutput == 1); SExprInfo* pExprInfo = &pQuery->pSelectExpr[0]; int32_t rsize = pExprInfo->bytes; - - for(int32_t i = 0; i < num; ++i) { + count = 0; + + while(pQInfo->tableIndex < num && count < pQuery->rec.capacity) { + int32_t i = pQInfo->tableIndex++; SGroupItem *item = taosArrayGet(pa, i); char *output = pQuery->sdata[0]->data + i * rsize; @@ -6085,30 +6107,38 @@ static void buildTagQueryResult(SQInfo* pQInfo) { } } } + + count += 1; } - pQInfo->tableIndex = pQInfo->groupInfo.numOfTables; - qTrace("QInfo:%p create (tableId, tag) info completed, rows:%d", pQInfo, num); + qTrace("QInfo:%p create (tableId, tag) info completed, rows:%d", pQInfo, count); + } else if (functionId == TSDB_FUNC_COUNT) {// handle the "count(tbname)" query + *(int64_t*) pQuery->sdata[0]->data = num; + + count = 1; + pQInfo->tableIndex = num; //set query completed + qTrace("QInfo:%p create count(tbname) query, res:%d rows:1", pQInfo, count); } else { // return only the tags|table name etc. - for(int32_t i = 0; i < num; ++i) { + count = 0; + while(pQInfo->tableIndex < num && count < pQuery->rec.capacity) { + int32_t i = pQInfo->tableIndex++; + SExprInfo* pExprInfo = pQuery->pSelectExpr; SGroupItem* item = taosArrayGet(pa, i); for(int32_t j = 0; j < pQuery->numOfOutput; ++j) { - // todo check the return value, refactor codes if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { char* data = tsdbGetTableName(pQInfo->tsdb, &item->id); - - char* dst = pQuery->sdata[j]->data + i * (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE); + char* dst = pQuery->sdata[j]->data + count * (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE); memcpy(dst, data, varDataTLen(data)); } else {// todo refactor int16_t type = pExprInfo[j].type; int16_t bytes = pExprInfo[j].bytes; char* data = tsdbGetTableTagVal(pQInfo->tsdb, &item->id, pExprInfo[j].base.colInfo.colId, type, bytes); + char* dst = pQuery->sdata[j]->data + count * pExprInfo[j].bytes; - char* dst = pQuery->sdata[j]->data + i * pExprInfo[j].bytes; if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { if (data == NULL) { setVardataNull(dst, type); @@ -6124,13 +6154,13 @@ static void buildTagQueryResult(SQInfo* pQInfo) { } } } + count += 1; } - - pQInfo->tableIndex = pQInfo->groupInfo.numOfTables; - qTrace("QInfo:%p create tag values results completed, rows:%d", pQInfo, num); + + qTrace("QInfo:%p create tag values results completed, rows:%d", pQInfo, count); } - pQuery->rec.rows = num; + pQuery->rec.rows = count; setQueryStatus(pQuery, QUERY_COMPLETED); } From 8f7c2713445262a6c8bdca6d41487843bf25bc74 Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Sat, 6 Jun 2020 07:47:41 +0000 Subject: [PATCH 13/72] add reference count for RpcInfo --- src/rpc/src/rpcMain.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 1da4c3f529..fe07e616a1 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -58,6 +58,7 @@ typedef struct { void (*cfp)(SRpcMsg *, SRpcIpSet *); int (*afp)(char *user, char *spi, char *encrypt, char *secret, char *ckey); + int refCount; void *idPool; // handle to ID pool void *tmrCtrl; // handle to timer SHashObj *hash; // handle returned by hash utility @@ -199,6 +200,8 @@ static int rpcAddAuthPart(SRpcConn *pConn, char *msg, int msgLen); static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen); static void rpcLockConn(SRpcConn *pConn); static void rpcUnlockConn(SRpcConn *pConn); +static void rpcAddRef(SRpcInfo *pRpc); +static void rpcDecRef(SRpcInfo *pRpc); void *rpcOpen(const SRpcInit *pInit) { SRpcInfo *pRpc; @@ -224,6 +227,7 @@ void *rpcOpen(const SRpcInit *pInit) { pRpc->spi = pInit->spi; pRpc->cfp = pInit->cfp; pRpc->afp = pInit->afp; + pRpc->refCount = 1; size_t size = sizeof(SRpcConn) * pRpc->sessions; pRpc->connList = (SRpcConn *)calloc(1, size); @@ -293,15 +297,8 @@ void rpcClose(void *param) { (*taosCleanUpConn[pRpc->connType | RPC_CONN_TCP])(pRpc->tcphandle); (*taosCleanUpConn[pRpc->connType])(pRpc->udphandle); - taosHashCleanup(pRpc->hash); - taosTmrCleanUp(pRpc->tmrCtrl); - taosIdPoolCleanUp(pRpc->idPool); - rpcCloseConnCache(pRpc->pCache); - - tfree(pRpc->connList); - pthread_mutex_destroy(&pRpc->mutex); tTrace("%s rpc is closed", pRpc->label); - tfree(pRpc); + rpcDecRef(pRpc); } void *rpcMallocCont(int contLen) { @@ -378,6 +375,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) { SRpcConn *pConn = (SRpcConn *)pRsp->handle; SRpcMsg rpcMsg = *pRsp; SRpcMsg *pMsg = &rpcMsg; + SRpcInfo *pRpc = pConn->pRpc; if ( pMsg->pCont == NULL ) { pMsg->pCont = rpcMallocCont(0); @@ -395,6 +393,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) { if ( pConn->inType == 0 || pConn->user[0] == 0 ) { tTrace("%s, connection is already released, rsp wont be sent", pConn->info); rpcUnlockConn(pConn); + rpcDecRef(pRpc); return; } @@ -420,7 +419,6 @@ void rpcSendResponse(const SRpcMsg *pRsp) { pConn->rspMsgLen = msgLen; if (pMsg->code == TSDB_CODE_ACTION_IN_PROGRESS) pConn->inTranId--; - SRpcInfo *pRpc = pConn->pRpc; taosTmrStopA(&pConn->pTimer); // set the idle timer to monitor the activity @@ -429,6 +427,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) { pConn->secured = 1; // connection shall be secured rpcUnlockConn(pConn); + rpcDecRef(pRpc); // decrease the referene count return; } @@ -951,6 +950,7 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead) { if ( rpcIsReq(pHead->msgType) ) { rpcMsg.handle = pConn; + rpcAddRef(pRpc); // add the refCount for requests pConn->pTimer = taosTmrStart(rpcProcessProgressTimer, tsProgressTimer, pConn, pRpc->tmrCtrl); (*(pRpc->cfp))(&rpcMsg, NULL); } else { @@ -1433,3 +1433,23 @@ static void rpcUnlockConn(SRpcConn *pConn) { } } +static void rpcAddRef(SRpcInfo *pRpc) +{ + atomic_add_fetch_8(&pRpc->refCount, 1); +} + +static void rpcDecRef(SRpcInfo *pRpc) +{ + if (atomic_sub_fetch_8(&pRpc->refCount, 1) == 0) { + taosHashCleanup(pRpc->hash); + taosTmrCleanUp(pRpc->tmrCtrl); + taosIdPoolCleanUp(pRpc->idPool); + rpcCloseConnCache(pRpc->pCache); + + tfree(pRpc->connList); + pthread_mutex_destroy(&pRpc->mutex); + tTrace("%s rpc resources are released", pRpc->label); + tfree(pRpc); + } +} + From f4b2dfc3a98412b7024481613c706d2e00ebd390 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 6 Jun 2020 07:58:19 +0000 Subject: [PATCH 14/72] [TD-527] fix compile error --- src/inc/taoserror.h | 9 ++++++--- src/wal/src/walMain.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index c1c0d28253..6012efa359 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -194,7 +194,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_NO_DISKSPACE, 0, 0x0702, "query no d TAOS_DEFINE_ERROR(TSDB_CODE_QRY_OUT_OF_MEMORY, 0, 0x0703, "query out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_APP_ERROR, 0, 0x0704, "query app error") -// gran +// grant TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 0x0800, "grant expired") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DNODE_LIMITED, 0, 0x0801, "grant dnode limited") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_ACCT_LIMITED, 0, 0x0802, "grant account limited") @@ -208,8 +208,11 @@ TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STORAGE_LIMITED, 0, 0x0809, "grant stor TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, 0, 0x080A, "grant query time limited") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, 0, 0x080B, "grant cpu limited") -// sync 0x1400 -TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_CONFIG, 0, 0x1900, "sync invalid configuration") +// sync +TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_CONFIG, 0, 0x0900, "sync invalid configuration") + +// wal +TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, 0, 0x1000, "wal app error") #ifdef TAOS_ERROR_C }; diff --git a/src/wal/src/walMain.c b/src/wal/src/walMain.c index d8f0d59afd..09225984c4 100644 --- a/src/wal/src/walMain.c +++ b/src/wal/src/walMain.c @@ -240,7 +240,7 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *, int)) if ( count != (maxId-minId+1) ) { wError("wal:%s, messed up, count:%d max:%d min:%d", opath, count, maxId, minId); - terrno = TAOS_SYSTEM_ERROR(TSDB_CODE_APP_ERROR); + terrno = TSDB_CODE_WAL_APP_ERROR; } else { wTrace("wal:%s, %d files will be restored", opath, count); From f1af16c62c49210bdac0f006e4562b159af99232 Mon Sep 17 00:00:00 2001 From: Hui Li Date: Sat, 6 Jun 2020 16:53:53 +0800 Subject: [PATCH 15/72] [TD-529] --- src/vnode/src/vnodeRead.c | 4 + .../arbitrator/dn3_mn1_vnode_nomaster.sim | 269 ++++++++++++++++++ 2 files changed, 273 insertions(+) create mode 100644 tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim diff --git a/src/vnode/src/vnodeRead.c b/src/vnode/src/vnodeRead.c index ef2cb20171..e1c81df310 100644 --- a/src/vnode/src/vnodeRead.c +++ b/src/vnode/src/vnodeRead.c @@ -45,6 +45,10 @@ int32_t vnodeProcessRead(void *param, int msgType, void *pCont, int32_t contLen, if (pVnode->status == TAOS_VN_STATUS_DELETING || pVnode->status == TAOS_VN_STATUS_CLOSING) return TSDB_CODE_INVALID_VGROUP_ID; + // TODO: Later, let slave to support query + if (pVnode->syncCfg.replica > 1 && pVnode->role != TAOS_SYNC_ROLE_MASTER) + return TSDB_CODE_NOT_READY; + return (*vnodeProcessReadMsgFp[msgType])(pVnode, pCont, contLen, ret); } diff --git a/tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim new file mode 100644 index 0000000000..b6a2b7e1d5 --- /dev/null +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim @@ -0,0 +1,269 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/deploy.sh -n dnode4 -i 4 + +system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 + +system sh/cfg.sh -n dnode1 -c walLevel -v 2 +system sh/cfg.sh -n dnode2 -c walLevel -v 2 +system sh/cfg.sh -n dnode3 -c walLevel -v 2 +system sh/cfg.sh -n dnode4 -c walLevel -v 2 + +system sh/cfg.sh -n dnode1 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode2 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode3 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode4 -c balanceInterval -v 10 + +system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4 +system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4 +system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4 +system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4 + +system sh/cfg.sh -n dnode1 -c alternativeRole -v 1 +system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 +system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 +system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 + +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 + +system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator + +print ============== step0: start tarbitrator +system sh/exec_tarbitrator.sh -s start + +print ============== step1: start dnode1, only deploy mnode +system sh/exec.sh -n dnode1 -s start +sleep 3000 +sql connect + +print ============== step2: start dnode2/dnode3/dnode4 and add into cluster , then create database with replica 3, and create table, insert data +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start +sql create dnode $hostname2 +sql create dnode $hostname3 +sql create dnode $hostname4 +sleep 3000 + +$totalTableNum = 100 +$sleepTimer = 3000 + +$db = db +sql create database $db replica 3 maxTables $totalTableNum +sql use $db + +# create table , insert data +$stb = stb +sql create table $stb (ts timestamp, c1 int) tags(t1 int) +$rowNum = 100 +$tblNum = $totalTableNum +$totalRows = 0 +$tsStart = 1420041600000 + +$i = 0 +while $i < $tblNum + $tb = tb . $i + sql create table $tb using $stb tags( $i ) + + $x = 0 + while $x < $rowNum + $ts = $tsStart + $x + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 1a , $x ) ( $ts + 2a , $x ) ( $ts + 3a , $x ) ( $ts + 4a , $x ) ( $ts + 5a , $x ) ( $ts + 6a , $x ) ( $ts + 7a , $x ) ( $ts + 8a , $x ) ( $ts + 9a , $x ) ( $ts + 10a , $x ) ( $ts + 11a , $x ) ( $ts + 12a , $x ) ( $ts + 13a , $x ) ( $ts + 14a , $x ) ( $ts + 15a , $x ) ( $ts + 16a , $x ) ( $ts + 17a , $x ) ( $ts + 18a , $x ) ( $ts + 19a , $x ) ( $ts + 20a , $x ) ( $ts + 21a , $x ) ( $ts + 22a , $x ) ( $ts + 23a , $x ) ( $ts + 24a , $x ) ( $ts + 25a , $x ) ( $ts + 26a , $x ) ( $ts + 27a , $x ) ( $ts + 28a , $x ) ( $ts + 29a , $x ) ( $ts + 30a , $x ) ( $ts + 31a , $x ) ( $ts + 32a , $x ) ( $ts + 33a , $x ) ( $ts + 34a , $x ) ( $ts + 25a , $x ) ( $ts + 26a , $x ) ( $ts + 27a , $x ) ( $ts + 28a , $x ) ( $ts + 29a , $x ) ( $ts + 30a , $x ) ( $ts + 31a , $x ) ( $ts + 32a , $x ) ( $ts + 33a , $x ) ( $ts + 34a , $x ) ( $ts + 35a , $x ) ( $ts + 36a , $x ) ( $ts + 37a , $x ) ( $ts + 38a , $x ) ( $ts + 39a , $x ) ( $ts + 40a , $x ) ( $ts + 41a , $x ) ( $ts + 42a , $x ) ( $ts + 43a , $x ) ( $ts + 44a , $x ) ( $ts + 45a , $x ) ( $ts + 46a , $x ) ( $ts + 47a , $x ) ( $ts + 48a , $x ) ( $ts + 49a , $x ) ( $ts + 50a , $x ) ( $ts + 51a , $x ) ( $ts + 52a , $x ) ( $ts + 53a , $x ) ( $ts + 54a , $x ) ( $ts + 55a , $x ) ( $ts + 56a , $x ) ( $ts + 57a , $x ) ( $ts + 58a , $x ) ( $ts + 59a , $x ) + $x = $x + 60 + endw + $totalRows = $totalRows + $x + print info: inserted $x rows into $tb and totalRows: $totalRows + $i = $i + 1 +endw + +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + +print ============== step3: stop dnode4/dnode2 +system sh/exec.sh -n dnode4 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +sleep $sleepTimer +wait_dnode4_offline_0: +sql show dnodes +if $rows != 4 then + sleep 2000 + goto wait_dnode4_offline_0 +endi +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +#print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +#print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +#print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +#$dnode1Status = $data4_1 +$dnode2Status = $data4_2 +$dnode3Status = $data4_3 +$dnode4Status = $data4_4 +#$dnode5Status = $data4_5 + +if $dnode4Status != offline then + sleep 2000 + goto wait_dnode4_offline_0 +endi +if $dnode2Status != offline then + sleep 2000 + goto wait_dnode4_offline_0 +endi + +wait_dnode4_vgroup_offline: +sql show vgroups +if $rows != 1 then + sleep 2000 + goto wait_dnode4_vgroup_offline +endi +print show vgroups: +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 +$dnode4Vtatus = $data4_2 +$dnode3Vtatus = $data7_2 + +if $dnode4Vtatus != offline then + sleep 2000 + goto wait_dnode4_vgroup_offline +endi +if $dnode3Vtatus != unsynced then + sleep 2000 + goto wait_dnode4_vgroup_offline +endi + +sql_error select count(*) from $stb +sql_error insert into $tb values (now, 9988) + +print ============== step4: restart dnode2, then create database with replica 2, and create table, insert data +system sh/exec.sh -n dnode2 -s start +sleep 3000 + +$totalTableNum = 100 +$sleepTimer = 3000 + +$db = db1 +sql create database $db replica 2 maxTables $totalTableNum +sql use $db + +# create table , insert data +$stb = stb +sql create table $stb (ts timestamp, c1 int) tags(t1 int) +$rowNum = 100 +$tblNum = $totalTableNum +$totalRows = 0 +$tsStart = 1420041600000 + +$i = 0 +while $i < $tblNum + $tb = tb . $i + sql create table $tb using $stb tags( $i ) + + $x = 0 + while $x < $rowNum + $ts = $tsStart + $x + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 1a , $x ) ( $ts + 2a , $x ) ( $ts + 3a , $x ) ( $ts + 4a , $x ) ( $ts + 5a , $x ) ( $ts + 6a , $x ) ( $ts + 7a , $x ) ( $ts + 8a , $x ) ( $ts + 9a , $x ) ( $ts + 10a , $x ) ( $ts + 11a , $x ) ( $ts + 12a , $x ) ( $ts + 13a , $x ) ( $ts + 14a , $x ) ( $ts + 15a , $x ) ( $ts + 16a , $x ) ( $ts + 17a , $x ) ( $ts + 18a , $x ) ( $ts + 19a , $x ) ( $ts + 20a , $x ) ( $ts + 21a , $x ) ( $ts + 22a , $x ) ( $ts + 23a , $x ) ( $ts + 24a , $x ) ( $ts + 25a , $x ) ( $ts + 26a , $x ) ( $ts + 27a , $x ) ( $ts + 28a , $x ) ( $ts + 29a , $x ) ( $ts + 30a , $x ) ( $ts + 31a , $x ) ( $ts + 32a , $x ) ( $ts + 33a , $x ) ( $ts + 34a , $x ) ( $ts + 25a , $x ) ( $ts + 26a , $x ) ( $ts + 27a , $x ) ( $ts + 28a , $x ) ( $ts + 29a , $x ) ( $ts + 30a , $x ) ( $ts + 31a , $x ) ( $ts + 32a , $x ) ( $ts + 33a , $x ) ( $ts + 34a , $x ) ( $ts + 35a , $x ) ( $ts + 36a , $x ) ( $ts + 37a , $x ) ( $ts + 38a , $x ) ( $ts + 39a , $x ) ( $ts + 40a , $x ) ( $ts + 41a , $x ) ( $ts + 42a , $x ) ( $ts + 43a , $x ) ( $ts + 44a , $x ) ( $ts + 45a , $x ) ( $ts + 46a , $x ) ( $ts + 47a , $x ) ( $ts + 48a , $x ) ( $ts + 49a , $x ) ( $ts + 50a , $x ) ( $ts + 51a , $x ) ( $ts + 52a , $x ) ( $ts + 53a , $x ) ( $ts + 54a , $x ) ( $ts + 55a , $x ) ( $ts + 56a , $x ) ( $ts + 57a , $x ) ( $ts + 58a , $x ) ( $ts + 59a , $x ) + $x = $x + 60 + endw + $totalRows = $totalRows + $x + print info: inserted $x rows into $tb and totalRows: $totalRows + $i = $i + 1 +endw + +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + +print ============== step5: stop dnode3 +system sh/exec.sh -n dnode3 -s stop -x SIGINT +sleep $sleepTimer +wait_dnode3_offline_0: +sql show dnodes +if $rows != 4 then + sleep 2000 + goto wait_dnode3_offline_0 +endi +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 + +$dnode1Status = $data4_1 +$dnode2Status = $data4_2 +$dnode3Status = $data4_3 +$dnode4Status = $data4_4 +print dnode1Status $dnode1Status +print dnode2Status $dnode2Status +print dnode3Status $dnode3Status +print dnode4Status $dnode4Status + +if $dnode3Status != offline then + sleep 2000 + goto wait_dnode3_offline_0 +endi +if $dnode2Status != ready then + sleep 2000 + goto wait_dnode3_offline_0 +endi + +wait_dnode2_vgroup_master: +sql show vgroups +if $rows != 1 then + sleep 2000 + goto wait_dnode2_vgroup_master +endi +print show vgroups: +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 +$dnode3Vtatus = $data4_3 +$dnode2Vtatus = $data7_3 + +if $dnode3Vtatus != offline then + sleep 2000 + goto wait_dnode2_vgroup_master +endi +if $dnode2Vtatus != master then + sleep 2000 + goto wait_dnode2_vgroup_master +endi + +sql insert into tb98 values (now, 9000) (now + 1s, 9001) (now + 2s, 9002) tb99 values (now, 9000) (now + 1s, 9001) (now + 2s, 9002) +$totalRows = $totalRows + 6 +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + + + + + + + + + + + + + + + + + From 06ac5328ec801a07c18e38416e823814ef40934e Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Sat, 6 Jun 2020 16:55:31 +0800 Subject: [PATCH 16/72] td-449: fix invalid write --- src/cq/src/cqMain.c | 7 ++++--- tests/script/general/stream/table_replica1_vnoden.sim | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index 23455b6f50..edb588b554 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -175,7 +175,7 @@ void *cqCreate(void *handle, uint64_t uid, int tid, char *sqlStr, STSchema *pSch strcpy(pObj->sqlStr, sqlStr); pObj->pSchema = tdDupSchema(pSchema); - pObj->rowSize = pSchema->tlen; + pObj->rowSize = schemaTLen(pSchema); cTrace("vgId:%d, id:%d CQ:%s is created", pContext->vgId, pObj->tid, pObj->sqlStr); @@ -272,13 +272,14 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { pBlk->sversion = htonl(pSchema->version); pBlk->padding = 0; + pHead->len = sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + dataRowLen(trow); + pMsg->header.vgId = htonl(pContext->vgId); - pMsg->header.contLen = htonl(size - sizeof(SWalHead)); + pMsg->header.contLen = htonl(pHead->len); pMsg->length = pMsg->header.contLen; pMsg->numOfBlocks = htonl(1); pHead->msgType = TSDB_MSG_TYPE_SUBMIT; - pHead->len = size - sizeof(SWalHead); pHead->version = 0; // write into vnode write queue diff --git a/tests/script/general/stream/table_replica1_vnoden.sim b/tests/script/general/stream/table_replica1_vnoden.sim index 44d4008dbd..e1d5a9babf 100644 --- a/tests/script/general/stream/table_replica1_vnoden.sim +++ b/tests/script/general/stream/table_replica1_vnoden.sim @@ -196,8 +196,8 @@ $st = $stPrefix . as sql create table $st as select count(tbcol) as c from $tb interval(1d) print =============== step16 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 print =============== step17 $st = $stPrefix . c1 From 6e0556d540327afca07d155fa73be4dbdc4a19fa Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 6 Jun 2020 17:29:16 +0800 Subject: [PATCH 17/72] [td-428] --- src/client/src/tscUtil.c | 9 ++------- src/query/src/qExecutor.c | 8 ++++---- src/query/src/qsyntaxtreefunction.c | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index d494700715..810ad6347c 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -189,7 +189,7 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { /* * In following cases, return false for non ordered project query on super table - * 1. failed to get metermeta from server; 2. not a super table; 3. limitation is 0; + * 1. failed to get tableMeta from server; 2. not a super table; 3. limitation is 0; * 4. show queries, instead of a select query */ size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo); @@ -198,11 +198,6 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { return false; } - // only query on tag, a project query - if (tscQueryTags(pQueryInfo)) { - return true; - } - for (int32_t i = 0; i < numOfExprs; ++i) { int32_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId; if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TAG && @@ -221,7 +216,7 @@ bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableI } // order by columnIndex exists, not a non-ordered projection query - return pQueryInfo->order.orderColId < 0 && pQueryInfo->order.orderColId != TSDB_TBNAME_COLUMN_INDEX; + return pQueryInfo->order.orderColId < 0; } bool tscOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index ce5286af58..534ed4bfd4 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -789,11 +789,10 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas sas->data = calloc(pQuery->numOfCols, POINTER_BYTES); // here the pQuery->colList and sas->colList are identical + int32_t numOfCols = taosArrayGetSize(pDataBlock); for (int32_t i = 0; i < pQuery->numOfCols; ++i) { SColumnInfo *pColMsg = &pQuery->colList[i]; - int32_t numOfCols = taosArrayGetSize(pDataBlock); - dataBlock = NULL; for (int32_t k = 0; k < numOfCols; ++k) { //todo refactor SColumnInfoData *p = taosArrayGet(pDataBlock, k); @@ -2102,7 +2101,8 @@ static void ensureOutputBuffer(SQueryRuntimeEnv* pRuntimeEnv, SDataBlockInfo* pB for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { int32_t bytes = pQuery->pSelectExpr[i].bytes; - + assert(bytes > 0 && newSize > 0); + char *tmp = realloc(pQuery->sdata[i], bytes * newSize + sizeof(tFilePage)); if (tmp == NULL) { // todo handle the oom assert(0); @@ -5501,7 +5501,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, } // set the output buffer capacity - pQuery->rec.capacity = 2; + pQuery->rec.capacity = 4096; pQuery->rec.threshold = 4000; for (int32_t col = 0; col < pQuery->numOfOutput; ++col) { diff --git a/src/query/src/qsyntaxtreefunction.c b/src/query/src/qsyntaxtreefunction.c index 41e84b5ab0..5719bb0188 100644 --- a/src/query/src/qsyntaxtreefunction.c +++ b/src/query/src/qsyntaxtreefunction.c @@ -311,7 +311,7 @@ void calc_fn_i32_i32_sub(void *left, void *right, int32_t numLeft, int32_t numRi if (numLeft == numRight) { for (; i >= 0 && i < numRight; i += step, pOutput += 1) { if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) { - setNull((char *)&(pOutput[i]), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize); + setNull((char *)(pOutput), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize); continue; } *pOutput = (double)pLeft[i] - pRight[i]; From b9ffc2099e839251d52da68257e69d36e1c4c433 Mon Sep 17 00:00:00 2001 From: Hui Li Date: Sat, 6 Jun 2020 17:53:46 +0800 Subject: [PATCH 18/72] [TD-529] --- src/vnode/src/vnodeRead.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vnode/src/vnodeRead.c b/src/vnode/src/vnodeRead.c index 2dc06a2a24..2cf72bb15d 100644 --- a/src/vnode/src/vnodeRead.c +++ b/src/vnode/src/vnodeRead.c @@ -47,7 +47,7 @@ int32_t vnodeProcessRead(void *param, int msgType, void *pCont, int32_t contLen, // TODO: Later, let slave to support query if (pVnode->syncCfg.replica > 1 && pVnode->role != TAOS_SYNC_ROLE_MASTER) - return TSDB_CODE_NOT_READY; + return TSDB_CODE_RPC_NOT_READY; return (*vnodeProcessReadMsgFp[msgType])(pVnode, pCont, contLen, ret); } From 805ed16570adf4164dcda596535f0e2500a18ebd Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Fri, 5 Jun 2020 13:53:30 +0800 Subject: [PATCH 19/72] fix multi-thread cases. --- .../random-test/random-test-multi-threading-3.py | 10 ++++++---- .../pytest/random-test/random-test-multi-threading.py | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/pytest/random-test/random-test-multi-threading-3.py b/tests/pytest/random-test/random-test-multi-threading-3.py index 4d1ef3b11d..cd9e1b577a 100644 --- a/tests/pytest/random-test/random-test-multi-threading-3.py +++ b/tests/pytest/random-test/random-test-multi-threading-3.py @@ -179,15 +179,16 @@ class Test (threading.Thread): tdDnodes.forcestop(1) tdDnodes.deploy(1) + tdDnodes.start(1) + tdSql.prepare() last_tb = "" last_stb = "" written = 0 - tdDnodes.start(1) - tdSql.prepare() def delete_datafiles(self): tdLog.info("delete_data_files") global last_tb + global last_stb global written dnodesDir = tdDnodes.getDnodesRootDir() @@ -195,10 +196,11 @@ class Test (threading.Thread): deleteCmd = 'rm -rf %s' % dataDir os.system(deleteCmd) - last_tb = "" - written = 0 tdDnodes.start(1) tdSql.prepare() + last_tb = "" + last_stb = "" + written = 0 def run(self): dataOp = { diff --git a/tests/pytest/random-test/random-test-multi-threading.py b/tests/pytest/random-test/random-test-multi-threading.py index 1c06f3a1dd..32546e0199 100644 --- a/tests/pytest/random-test/random-test-multi-threading.py +++ b/tests/pytest/random-test/random-test-multi-threading.py @@ -181,15 +181,16 @@ class Test (threading.Thread): tdDnodes.forcestop(1) tdDnodes.deploy(1) + tdDnodes.start(1) + tdSql.prepare() last_tb = "" last_stb = "" written = 0 - tdDnodes.start(1) - tdSql.prepare() def delete_datafiles(self): tdLog.info("delete_data_files") global last_tb + global last_stb global written dnodesDir = tdDnodes.getDnodesRootDir() @@ -197,11 +198,12 @@ class Test (threading.Thread): deleteCmd = 'rm -rf %s' % dataDir os.system(deleteCmd) - last_tb = "" - written = 0 tdDnodes.start(1) tdLog.sleep(10) tdSql.prepare() + last_tb = "" + last_stb = "" + written = 0 def run(self): dataOp = { From 2c4482d7bc884b7cc6ddf222c25d17ad508bf93c Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Sat, 6 Jun 2020 18:57:02 +0800 Subject: [PATCH 20/72] refactor multi-threading random test cases. --- .../random-test-multi-threading-3.py | 72 ++++++++++++------- .../random-test-multi-threading.py | 44 +++++++----- tests/pytest/util/dnodes.py | 2 +- 3 files changed, 77 insertions(+), 41 deletions(-) diff --git a/tests/pytest/random-test/random-test-multi-threading-3.py b/tests/pytest/random-test/random-test-multi-threading-3.py index cd9e1b577a..db85ce2fe0 100644 --- a/tests/pytest/random-test/random-test-multi-threading-3.py +++ b/tests/pytest/random-test/random-test-multi-threading-3.py @@ -13,7 +13,7 @@ import sys import random -import threading +from threading import Thread, Event from util.log import * from util.cases import * @@ -23,15 +23,15 @@ from util.dnodes import * last_tb = "" last_stb = "" written = 0 +last_timestamp = 0 -class Test (threading.Thread): - def __init__(self, threadId, name): - threading.Thread.__init__(self) +class Test (Thread): + def __init__(self, threadId, name, events): + Thread.__init__(self) self.threadId = threadId self.name = name - - self.threadLock = threading.Lock() + self.dataEvent, self.dbEvent, self.queryEvent = events def create_table(self): tdLog.info("create_table") @@ -47,7 +47,7 @@ class Test (threading.Thread): try: tdSql.execute( - 'create table %s (ts timestamp, speed int)' % + 'create table %s (ts timestamp, speed int, c2 nchar(10))' % current_tb) last_tb = current_tb written = 0 @@ -58,21 +58,28 @@ class Test (threading.Thread): tdLog.info("insert_data") global last_tb global written + global last_timestamp if (last_tb == ""): tdLog.info("no table, create first") self.create_table() + start_time = 1500000000000 + tdLog.info("will insert data to table") for i in range(0, 10): insertRows = 1000 tdLog.info("insert %d rows to %s" % (insertRows, last_tb)) for j in range(0, insertRows): - ret = tdSql.execute( - 'insert into %s values (now + %dm, %d)' % - (last_tb, j, j)) + if (last_tb == ""): + tdLog.info("no table, return") + return + tdSql.execute( + 'insert into %s values (%d + %da, %d, "test")' % + (last_tb, start_time, last_timestamp, last_timestamp)) written = written + 1 + last_timestamp = last_timestamp + 1 def query_data(self): tdLog.info("query_data") @@ -89,6 +96,7 @@ class Test (threading.Thread): global last_tb global last_stb global written + global last_timestamp current_stb = "stb%d" % int(round(time.time() * 1000)) @@ -106,10 +114,15 @@ class Test (threading.Thread): "create table %s using %s tags (1, '表1')" % (current_tb, last_stb)) last_tb = current_tb + written = 0 + + start_time = 1500000000000 + tdSql.execute( - "insert into %s values (now, 27, '我是nchar字符串')" % - last_tb) + "insert into %s values (%d+%da, 27, '我是nchar字符串')" % + (last_tb, start_time, last_timestamp)) written = written + 1 + last_timestamp = last_timestamp + 1 def drop_stable(self): tdLog.info("drop_stable") @@ -205,8 +218,6 @@ class Test (threading.Thread): def run(self): dataOp = { 1: self.insert_data, - 2: self.query_data, - 3: self.query_data_from_stable, } dbOp = { @@ -228,26 +239,33 @@ class Test (threading.Thread): if (self.threadId == 1): while True: - self.threadLock.acquire() + self.dataEvent.wait() tdLog.notice("first thread") - randDataOp = random.randint(1, 3) + randDataOp = random.randint(1, 1) dataOp.get(randDataOp, lambda: "ERROR")() - self.threadLock.release() + self.dataEvent.clear() + self.queryEvent.clear() + self.dbEvent.set() elif (self.threadId == 2): while True: + self.dbEvent.wait() tdLog.notice("second thread") - self.threadLock.acquire() randDbOp = random.randint(1, 9) dbOp.get(randDbOp, lambda: "ERROR")() - self.threadLock.release() + self.dbEvent.clear() + self.dataEvent.clear() + self.queryEvent.set() + elif (self.threadId == 3): while True: + self.queryEvent.wait() tdLog.notice("third thread") - self.threadLock.acquire() randQueryOp = random.randint(1, 9) queryOp.get(randQueryOp, lambda: "ERROR")() - self.threadLock.release() + self.queryEvent.clear() + self.dbEvent.clear() + self.dataEvent.set() class TDTestCase: @@ -258,13 +276,19 @@ class TDTestCase: def run(self): tdSql.prepare() - test1 = Test(1, "data operation") - test2 = Test(2, "db operation") - test2 = Test(3, "query operation") + events = [Event() for _ in range(3)] + events[0].set() + events[1].clear() + events[1].clear() + + test1 = Test(1, "data operation", events) + test2 = Test(2, "db operation", events) + test3 = Test(3, "query operation", events) test1.start() test2.start() test3.start() + test1.join() test2.join() test3.join() diff --git a/tests/pytest/random-test/random-test-multi-threading.py b/tests/pytest/random-test/random-test-multi-threading.py index 32546e0199..fed9b035c2 100644 --- a/tests/pytest/random-test/random-test-multi-threading.py +++ b/tests/pytest/random-test/random-test-multi-threading.py @@ -23,6 +23,7 @@ from util.dnodes import * last_tb = "" last_stb = "" written = 0 +last_timestamp = 0 class Test (threading.Thread): @@ -47,7 +48,7 @@ class Test (threading.Thread): try: tdSql.execute( - 'create table %s (ts timestamp, speed int)' % + 'create table %s (ts timestamp, speed int, c1 nchar(10))' % current_tb) last_tb = current_tb written = 0 @@ -58,21 +59,28 @@ class Test (threading.Thread): tdLog.info("insert_data") global last_tb global written + global last_timestamp if (last_tb == ""): tdLog.info("no table, create first") self.create_table() + start_time = 1500000000000 + tdLog.info("will insert data to table") for i in range(0, 10): insertRows = 1000 tdLog.info("insert %d rows to %s" % (insertRows, last_tb)) for j in range(0, insertRows): - ret = tdSql.execute( - 'insert into %s values (now + %dm, %d)' % - (last_tb, j, j)) + if (last_tb == ""): + tdLog.info("no table, return") + return + tdSql.execute( + 'insert into %s values (%d + %da, %d, "test")' % + (last_tb, start_time, last_timestamp, last_timestamp)) written = written + 1 + last_timestamp = last_timestamp + 1 def query_data(self): tdLog.info("query_data") @@ -89,6 +97,7 @@ class Test (threading.Thread): global last_tb global last_stb global written + global last_timestamp current_stb = "stb%d" % int(round(time.time() * 1000)) @@ -106,10 +115,15 @@ class Test (threading.Thread): "create table %s using %s tags (1, '表1')" % (current_tb, last_stb)) last_tb = current_tb + written = 0 + + start_time = 1500000000000 + tdSql.execute( - "insert into %s values (now, 27, '我是nchar字符串')" % - last_tb) + "insert into %s values (%d+%da, 27, '我是nchar字符串')" % + (last_tb, start_time, last_timestamp)) written = written + 1 + last_timestamp = last_timestamp + 1 def drop_stable(self): tdLog.info("drop_stable") @@ -130,7 +144,7 @@ class Test (threading.Thread): tdDnodes.stop(1) tdDnodes.start(1) - tdLog.sleep(5) +# tdLog.sleep(5) def force_restart_database(self): tdLog.info("force_restart_database") @@ -139,7 +153,7 @@ class Test (threading.Thread): tdDnodes.forcestop(1) tdDnodes.start(1) - tdLog.sleep(10) +# tdLog.sleep(10) def drop_table(self): tdLog.info("drop_table") @@ -171,7 +185,7 @@ class Test (threading.Thread): tdLog.info("reset query cache") tdSql.execute("reset query cache") - tdLog.sleep(1) +# tdLog.sleep(1) def reset_database(self): tdLog.info("reset_database") @@ -181,16 +195,15 @@ class Test (threading.Thread): tdDnodes.forcestop(1) tdDnodes.deploy(1) - tdDnodes.start(1) - tdSql.prepare() last_tb = "" last_stb = "" written = 0 + tdDnodes.start(1) + tdSql.prepare() def delete_datafiles(self): tdLog.info("delete_data_files") global last_tb - global last_stb global written dnodesDir = tdDnodes.getDnodesRootDir() @@ -198,12 +211,11 @@ class Test (threading.Thread): deleteCmd = 'rm -rf %s' % dataDir os.system(deleteCmd) - tdDnodes.start(1) - tdLog.sleep(10) - tdSql.prepare() last_tb = "" - last_stb = "" written = 0 + tdDnodes.start(1) +# tdLog.sleep(10) + tdSql.prepare() def run(self): dataOp = { diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 4c839d87a3..50d054a301 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -160,7 +160,7 @@ class TDDnode: self.cfg("logDir", self.logDir) self.cfg("numOfLogLines", "100000000") self.cfg("mnodeEqualVnodeNum", "0") - self.cfg("clog", "1") + self.cfg("walLevel", "1") self.cfg("statusInterval", "1") self.cfg("numOfTotalVnodes", "64") self.cfg("numOfMnodes", "3") From 7ba8c232126b0887b6a3f0454aee2f01f824c4ef Mon Sep 17 00:00:00 2001 From: freemine Date: Sun, 7 Jun 2020 10:23:18 +0800 Subject: [PATCH 21/72] replace gethostbyname with getaddrinfo --- src/util/src/tsocket.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c index 86ae77b54c..00c8bba94e 100644 --- a/src/util/src/tsocket.c +++ b/src/util/src/tsocket.c @@ -24,25 +24,37 @@ int taosGetFqdn(char *fqdn) { hostname[1023] = '\0'; gethostname(hostname, 1023); - struct hostent* h; - h = gethostbyname(hostname); - if (h != NULL) { - strcpy(fqdn, h->h_name); + struct addrinfo hints = {0}; + struct addrinfo *result = NULL; + + hints.ai_flags = AI_CANONNAME; + + getaddrinfo(hostname, NULL, &hints, &result); + if (result) { + strcpy(fqdn, result->ai_canonname); + freeaddrinfo(result); } else { - uError("failed to get host name(%s)", strerror(errno)); code = -1; } - // to do: free the resources - // free(h); - return code; } uint32_t taosGetIpFromFqdn(const char *fqdn) { - struct hostent * record = gethostbyname(fqdn); - if(record == NULL) return -1; - return ((struct in_addr *)record->h_addr)->s_addr; + struct addrinfo hints = {0}; + struct addrinfo *result = NULL; + + getaddrinfo(fqdn, NULL, &hints, &result); + if (result) { + struct sockaddr *sa = result->ai_addr; + struct sockaddr_in *si = (struct sockaddr_in*)sa; + struct in_addr ia = si->sin_addr; + uint32_t ip = ia.s_addr; + freeaddrinfo(result); + return ip; + } else { + return -1; + } } // Function converting an IP address string to an unsigned int. From 51d9d54ddcea0c364e97cdba357f345bb461792f Mon Sep 17 00:00:00 2001 From: freemine Date: Sun, 7 Jun 2020 11:00:22 +0800 Subject: [PATCH 22/72] allocate enough space to holding null-terminator, especially in case of wchar_t --- src/client/src/tscUtil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 2bde10f076..caf424080d 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1153,7 +1153,7 @@ SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numO for (int32_t j = 0; j < numOfFilters; ++j) { if (pFilter[j].filterstr) { - size_t len = (size_t) pFilter[j].len + 1; + size_t len = (size_t) pFilter[j].len + 1 * TSDB_NCHAR_SIZE; pFilter[j].pz = (int64_t) calloc(1, len); memcpy((char*)pFilter[j].pz, (char*)src[j].pz, (size_t)len); From 6f29506e178b5bc269eed82e358bc70a99cb764e Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Sun, 7 Jun 2020 03:21:30 +0000 Subject: [PATCH 23/72] make rpcTcp multi-thread safe --- src/rpc/src/rpcMain.c | 24 ++++--- src/rpc/src/rpcTcp.c | 147 +++++++++++++++++++++++++++-------------- src/util/src/tsocket.c | 24 ++++++- 3 files changed, 130 insertions(+), 65 deletions(-) diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index fe07e616a1..9c90a90fc0 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -805,16 +805,16 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv) { if (pConn == NULL) { tTrace("%s %p, failed to get connection obj(%s)", pRpc->label, (void *)pHead->ahandle, tstrerror(terrno)); return NULL; - } else { - if (rpcIsReq(pHead->msgType)) { - pConn->ahandle = (void *)pHead->ahandle; - sprintf(pConn->info, "%s %p %p", pRpc->label, pConn, pConn->ahandle); - } - } + } rpcLockConn(pConn); - sid = pConn->sid; + if (rpcIsReq(pHead->msgType)) { + pConn->ahandle = (void *)pHead->ahandle; + sprintf(pConn->info, "%s %p %p", pRpc->label, pConn, pConn->ahandle); + } + + sid = pConn->sid; pConn->chandle = pRecv->chandle; pConn->peerIp = pRecv->ip; pConn->peerPort = pRecv->port; @@ -847,10 +847,11 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv) { } static void rpcProcessBrokenLink(SRpcConn *pConn) { + if (pConn == NULL) return; SRpcInfo *pRpc = pConn->pRpc; - tTrace("%s, link is broken", pConn->info); - // pConn->chandle = NULL; + + rpcLockConn(pConn); if (pConn->outType) { SRpcReqContext *pContext = pConn->pContext; @@ -871,7 +872,8 @@ static void rpcProcessBrokenLink(SRpcConn *pConn) { (*(pRpc->cfp))(&rpcMsg); */ } - + + rpcUnlockConn(pConn); rpcCloseConn(pConn); } @@ -885,7 +887,7 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { // underlying UDP layer does not know it is server or client pRecv->connType = pRecv->connType | pRpc->connType; - if (pRecv->ip == 0 && pConn) { + if (pRecv->ip == 0) { rpcProcessBrokenLink(pConn); return NULL; } diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 511a57f3fe..151f5db65f 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -16,6 +16,7 @@ #include "os.h" #include "tsocket.h" #include "tutil.h" +#include "taoserror.h" #include "rpcLog.h" #include "rpcHead.h" #include "rpcTcp.h" @@ -26,8 +27,9 @@ typedef struct SFdObj { void *signature; - int fd; // TCP socket FD - void *thandle; // handle from upper layer, like TAOS + int fd; // TCP socket FD + int closedByApp; // 1: already closed by App + void *thandle; // handle from upper layer, like TAOS uint32_t ip; uint16_t port; struct SThreadObj *pThreadObj; @@ -71,6 +73,12 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread SThreadObj *pThreadObj; pServerObj = (SServerObj *)calloc(sizeof(SServerObj), 1); + if (pServerObj == NULL) { + tError("TCP:%s no enough memory", label); + terrno = TAOS_SYSTEM_ERROR(errno); + return NULL; + } + pServerObj->ip = ip; pServerObj->port = port; tstrncpy(pServerObj->label, label, sizeof(pServerObj->label)); @@ -79,6 +87,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread pServerObj->pThreadObj = (SThreadObj *)calloc(sizeof(SThreadObj), numOfThreads); if (pServerObj->pThreadObj == NULL) { tError("TCP:%s no enough memory", label); + terrno = TAOS_SYSTEM_ERROR(errno); free(pServerObj); return NULL; } @@ -93,12 +102,14 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread code = pthread_mutex_init(&(pThreadObj->mutex), NULL); if (code < 0) { tError("%s failed to init TCP process data mutex(%s)", label, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); break;; } pThreadObj->pollFd = epoll_create(10); // size does not matter if (pThreadObj->pollFd < 0) { tError("%s failed to create TCP epoll", label); + terrno = TAOS_SYSTEM_ERROR(errno); code = -1; break; } @@ -110,6 +121,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread pthread_attr_destroy(&thattr); if (code != 0) { tError("%s failed to create TCP process data thread(%s)", label, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); break; } @@ -124,6 +136,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread code = pthread_create(&(pServerObj->thread), &thattr, (void *)taosAcceptTcpConnection, (void *)(pServerObj)); pthread_attr_destroy(&thattr); if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); tError("%s failed to create TCP accept thread(%s)", label, strerror(errno)); } } @@ -147,10 +160,12 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) { struct epoll_event event = { .events = EPOLLIN }; eventfd_t fd = eventfd(1, 0); if (fd == -1) { - tError("%s, failed to create eventfd, will call pthread_cancel instead, which may result in data corruption: %s", pThreadObj->label, strerror(errno)); + // failed to create eventfd, call pthread_cancel instead, which may result in data corruption: + tError("%s, failed to create eventfd(%s)", pThreadObj->label, strerror(errno)); pthread_cancel(pThreadObj->thread); } else if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { - tError("%s, failed to call epoll_ctl, will call pthread_cancel instead, which may result in data corruption: %s", pThreadObj->label, strerror(errno)); + // failed to call epoll_ctl, call pthread_cancel instead, which may result in data corruption: + tError("%s, failed to call epoll_ctl(%s)", pThreadObj->label, strerror(errno)); pthread_cancel(pThreadObj->thread); } @@ -211,6 +226,7 @@ static void* taosAcceptTcpConnection(void *arg) { tTrace("%s TCP server socket was shutdown, exiting...", pServerObj->label); break; } + tError("%s TCP accept failure(%s)", pServerObj->label, strerror(errno)); continue; } @@ -254,6 +270,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void * if (pthread_mutex_init(&(pThreadObj->mutex), NULL) < 0) { tError("%s failed to init TCP client mutex(%s)", label, strerror(errno)); free(pThreadObj); + terrno = TAOS_SYSTEM_ERROR(errno); return NULL; } @@ -261,6 +278,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void * if (pThreadObj->pollFd < 0) { tError("%s failed to create TCP client epoll", label); free(pThreadObj); + terrno = TAOS_SYSTEM_ERROR(errno); return NULL; } @@ -273,6 +291,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void * if (code != 0) { close(pThreadObj->pollFd); free(pThreadObj); + terrno = TAOS_SYSTEM_ERROR(errno); tError("%s failed to create TCP read data thread(%s)", label, strerror(errno)); return NULL; } @@ -287,7 +306,7 @@ void taosCleanUpTcpClient(void *chandle) { if (pThreadObj == NULL) return; taosStopTcpThread(pThreadObj); - tTrace (":%s, all connections are cleaned up", pThreadObj->label); + tTrace ("%s, all connections are cleaned up", pThreadObj->label); tfree(pThreadObj); } @@ -318,7 +337,9 @@ void taosCloseTcpConnection(void *chandle) { SFdObj *pFdObj = chandle; if (pFdObj == NULL) return; - taosFreeFdObj(pFdObj); + pFdObj->thandle = NULL; + pFdObj->closedByApp = 1; + shutdown(pFdObj->fd, SHUT_WR); } int taosSendTcpData(uint32_t ip, uint16_t port, void *data, int len, void *chandle) { @@ -334,7 +355,9 @@ static void taosReportBrokenLink(SFdObj *pFdObj) { SThreadObj *pThreadObj = pFdObj->pThreadObj; // notify the upper layer, so it will clean the associated context - if (pFdObj->thandle) { + if (pFdObj->closedByApp == 0) { + shutdown(pFdObj->fd, SHUT_WR); + SRecvInfo recvInfo; recvInfo.msg = NULL; recvInfo.msgLen = 0; @@ -345,9 +368,59 @@ static void taosReportBrokenLink(SFdObj *pFdObj) { recvInfo.chandle = NULL; recvInfo.connType = RPC_CONN_TCP; (*(pThreadObj->processData))(&recvInfo); - } else { - taosFreeFdObj(pFdObj); + } + + taosFreeFdObj(pFdObj); +} + +static int taosReadTcpData(SFdObj *pFdObj, SRecvInfo *pInfo) { + SRpcHead rpcHead; + int32_t msgLen, leftLen, retLen, headLen; + char *buffer, *msg; + + SThreadObj *pThreadObj = pFdObj->pThreadObj; + + headLen = taosReadMsg(pFdObj->fd, &rpcHead, sizeof(SRpcHead)); + if (headLen != sizeof(SRpcHead)) { + tTrace("%s %p, read error, headLen:%d", pThreadObj->label, pFdObj->thandle, headLen); + return -1; } + + msgLen = (int32_t)htonl((uint32_t)rpcHead.msgLen); + buffer = malloc(msgLen + tsRpcOverhead); + if ( NULL == buffer) { + tError("%s %p, TCP malloc(size:%d) fail", pThreadObj->label, pFdObj->thandle, msgLen); + return -1; + } + + msg = buffer + tsRpcOverhead; + leftLen = msgLen - headLen; + retLen = taosReadMsg(pFdObj->fd, msg + headLen, leftLen); + + if (leftLen != retLen) { + tError("%s %p, read error, leftLen:%d retLen:%d", + pThreadObj->label, pFdObj->thandle, leftLen, retLen); + free(buffer); + return -1; + } + + memcpy(msg, &rpcHead, sizeof(SRpcHead)); + + pInfo->msg = msg; + pInfo->msgLen = msgLen; + pInfo->ip = pFdObj->ip; + pInfo->port = pFdObj->port; + pInfo->shandle = pThreadObj->shandle; + pInfo->thandle = pFdObj->thandle;; + pInfo->chandle = pFdObj; + pInfo->connType = RPC_CONN_TCP; + + if (pFdObj->closedByApp) { + free(buffer); + return -1; + } + + return 0; } #define maxEvents 10 @@ -357,7 +430,6 @@ static void *taosProcessTcpData(void *param) { SFdObj *pFdObj; struct epoll_event events[maxEvents]; SRecvInfo recvInfo; - SRpcHead rpcHead; while (1) { int fdNum = epoll_wait(pThreadObj->pollFd, events, maxEvents, -1); @@ -376,51 +448,23 @@ static void *taosProcessTcpData(void *param) { continue; } + if (events[i].events & EPOLLRDHUP) { + tTrace("%s %p, FD RD hang up", pThreadObj->label, pFdObj->thandle); + taosReportBrokenLink(pFdObj); + continue; + } + if (events[i].events & EPOLLHUP) { tTrace("%s %p, FD hang up", pThreadObj->label, pFdObj->thandle); taosReportBrokenLink(pFdObj); continue; } - int32_t headLen = taosReadMsg(pFdObj->fd, &rpcHead, sizeof(SRpcHead)); - if (headLen != sizeof(SRpcHead)) { - tTrace("%s %p, read error, headLen:%d", pThreadObj->label, pFdObj->thandle, headLen); - taosReportBrokenLink(pFdObj); + if (taosReadTcpData(pFdObj, &recvInfo) < 0) { + shutdown(pFdObj->fd, SHUT_WR); continue; } - int32_t msgLen = (int32_t)htonl((uint32_t)rpcHead.msgLen); - char *buffer = malloc(msgLen + tsRpcOverhead); - if ( NULL == buffer) { - tError("%s %p, TCP malloc(size:%d) fail", pThreadObj->label, pFdObj->thandle, msgLen); - taosReportBrokenLink(pFdObj); - continue; - } - - char *msg = buffer + tsRpcOverhead; - int32_t leftLen = msgLen - headLen; - int32_t retLen = taosReadMsg(pFdObj->fd, msg + headLen, leftLen); - - if (leftLen != retLen) { - tError("%s %p, read error, leftLen:%d retLen:%d", - pThreadObj->label, pFdObj->thandle, leftLen, retLen); - taosReportBrokenLink(pFdObj); - tfree(buffer); - continue; - } - - // tTrace("%s TCP data is received, ip:0x%x:%u len:%d", pThreadObj->label, pFdObj->ip, pFdObj->port, msgLen); - - memcpy(msg, &rpcHead, sizeof(SRpcHead)); - recvInfo.msg = msg; - recvInfo.msgLen = msgLen; - recvInfo.ip = pFdObj->ip; - recvInfo.port = pFdObj->port; - recvInfo.shandle = pThreadObj->shandle; - recvInfo.thandle = pFdObj->thandle;; - recvInfo.chandle = pFdObj; - recvInfo.connType = RPC_CONN_TCP; - pFdObj->thandle = (*(pThreadObj->processData))(&recvInfo); if (pFdObj->thandle == NULL) taosFreeFdObj(pFdObj); } @@ -433,16 +477,20 @@ static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, int fd) { struct epoll_event event; SFdObj *pFdObj = (SFdObj *)calloc(sizeof(SFdObj), 1); - if (pFdObj == NULL) return NULL; + if (pFdObj == NULL) { + return NULL; + } + pFdObj->closedByApp = 0; pFdObj->fd = fd; pFdObj->pThreadObj = pThreadObj; pFdObj->signature = pFdObj; - event.events = EPOLLIN | EPOLLPRI | EPOLLWAKEUP; + event.events = EPOLLIN | EPOLLRDHUP; event.data.ptr = pFdObj; if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { tfree(pFdObj); + terrno = TAOS_SYSTEM_ERROR(errno); return NULL; } @@ -475,13 +523,10 @@ static void taosFreeFdObj(SFdObj *pFdObj) { taosCloseSocket(pFdObj->fd); pThreadObj->numOfFds--; - if (pThreadObj->numOfFds < 0) tError("%s %p, TCP thread:%d, number of FDs is negative!!!", pThreadObj->label, pFdObj->thandle, pThreadObj->threadId); - // remove from the FdObject list - if (pFdObj->prev) { (pFdObj->prev)->next = pFdObj->next; } else { diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c index 86ae77b54c..24186cafd0 100644 --- a/src/util/src/tsocket.c +++ b/src/util/src/tsocket.c @@ -40,9 +40,27 @@ int taosGetFqdn(char *fqdn) { } uint32_t taosGetIpFromFqdn(const char *fqdn) { - struct hostent * record = gethostbyname(fqdn); - if(record == NULL) return -1; - return ((struct in_addr *)record->h_addr)->s_addr; + struct addrinfo hints, *servinfo, *p; + struct sockaddr_in *h; + uint32_t ip = -1; + + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; // use AF_INET6 to force IPv6 + hints.ai_socktype = SOCK_STREAM; + + if (getaddrinfo(fqdn, "http", &hints, &servinfo) != 0) { + uError("failed to get IP from %s(%s)", fqdn, strerror(errno)); + return -1; + } + + // to do: loop through all the results and connect to the first we can + for(p = servinfo; p != NULL; p = p->ai_next) { + h = (struct sockaddr_in *) p->ai_addr; + ip = h->sin_addr.s_addr; + } + + freeaddrinfo(servinfo); // all done with this structure + return ip; } // Function converting an IP address string to an unsigned int. From dad3b9f19c25c2220f6e08a59b39e842a322ee46 Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Sun, 7 Jun 2020 06:07:15 +0000 Subject: [PATCH 24/72] add a new definition foe label length --- src/inc/taosdef.h | 1 + src/rpc/src/rpcMain.c | 4 +-- src/rpc/src/rpcTcp.c | 64 +++++++++++++++++++++---------------------- src/rpc/src/rpcUdp.c | 7 +++-- src/util/src/tsched.c | 3 +- 5 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 29181ed78f..c75fc70d75 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -221,6 +221,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_COUNTRY_LEN 20 #define TSDB_LOCALE_LEN 64 #define TSDB_TIMEZONE_LEN 64 +#define TSDB_LABEL_LEN 8 #define TSDB_FQDN_LEN 128 #define TSDB_EP_LEN (TSDB_FQDN_LEN+6) diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 9c90a90fc0..ecbc470945 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -47,7 +47,7 @@ typedef struct { uint16_t localPort; int8_t connType; int index; // for UDP server only, round robin for multiple threads - char label[12]; + char label[TSDB_LABEL_LEN]; char user[TSDB_UNI_LEN]; // meter ID char spi; // security parameter index @@ -88,7 +88,7 @@ typedef struct { } SRpcReqContext; typedef struct SRpcConn { - char info[50];// debug info: label + pConn + ahandle + char info[48];// debug info: label + pConn + ahandle int sid; // session ID uint32_t ownId; // own link ID uint32_t peerId; // peer link ID diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 151f5db65f..04a269502e 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -16,6 +16,7 @@ #include "os.h" #include "tsocket.h" #include "tutil.h" +#include "taosdef.h" #include "taoserror.h" #include "rpcLog.h" #include "rpcHead.h" @@ -46,7 +47,7 @@ typedef struct SThreadObj { int pollFd; int numOfFds; int threadId; - char label[12]; + char label[TSDB_LABEL_LEN]; void *shandle; // handle passed by upper layer during server initialization void *(*processData)(SRecvInfo *pPacket); } SThreadObj; @@ -55,7 +56,7 @@ typedef struct { int fd; uint32_t ip; uint16_t port; - char label[12]; + char label[TSDB_LABEL_LEN]; int numOfThreads; void * shandle; SThreadObj *pThreadObj; @@ -79,6 +80,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread return NULL; } + pServerObj->thread = 0; pServerObj->ip = ip; pServerObj->port = port; tstrncpy(pServerObj->label, label, sizeof(pServerObj->label)); @@ -93,8 +95,14 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread } int code = 0; + pthread_attr_t thattr; + pthread_attr_init(&thattr); + pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); + pThreadObj = pServerObj->pThreadObj; for (int i = 0; i < numOfThreads; ++i) { + pThreadObj->pollFd = -1; + pThreadObj->thread = 0; pThreadObj->processData = fp; tstrncpy(pThreadObj->label, label, sizeof(pThreadObj->label)); pThreadObj->shandle = shandle; @@ -114,11 +122,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread break; } - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); code = pthread_create(&(pThreadObj->thread), &thattr, taosProcessTcpData, (void *)(pThreadObj)); - pthread_attr_destroy(&thattr); if (code != 0) { tError("%s failed to create TCP process data thread(%s)", label, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); @@ -130,11 +134,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread } if (code == 0) { - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); code = pthread_create(&(pServerObj->thread), &thattr, (void *)taosAcceptTcpConnection, (void *)(pServerObj)); - pthread_attr_destroy(&thattr); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(errno); tError("%s failed to create TCP accept thread(%s)", label, strerror(errno)); @@ -142,38 +142,39 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread } if (code != 0) { - free(pServerObj->pThreadObj); - free(pServerObj); + taosCleanUpTcpServer(pServerObj); pServerObj = NULL; } else { tTrace("%s TCP server is initialized, ip:0x%x port:%hu numOfThreads:%d", label, ip, port, numOfThreads); } + pthread_attr_destroy(&thattr); return (void *)pServerObj; } static void taosStopTcpThread(SThreadObj* pThreadObj) { pThreadObj->stop = true; + eventfd_t fd = -1; - // signal the thread to stop, try graceful method first, - // and use pthread_cancel when failed - struct epoll_event event = { .events = EPOLLIN }; - eventfd_t fd = eventfd(1, 0); - if (fd == -1) { - // failed to create eventfd, call pthread_cancel instead, which may result in data corruption: - tError("%s, failed to create eventfd(%s)", pThreadObj->label, strerror(errno)); - pthread_cancel(pThreadObj->thread); - } else if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { - // failed to call epoll_ctl, call pthread_cancel instead, which may result in data corruption: - tError("%s, failed to call epoll_ctl(%s)", pThreadObj->label, strerror(errno)); - pthread_cancel(pThreadObj->thread); + if (pThreadObj->thread && pThreadObj->pollFd >=0) { + // signal the thread to stop, try graceful method first, + // and use pthread_cancel when failed + struct epoll_event event = { .events = EPOLLIN }; + fd = eventfd(1, 0); + if (fd == -1) { + // failed to create eventfd, call pthread_cancel instead, which may result in data corruption: + tError("%s, failed to create eventfd(%s)", pThreadObj->label, strerror(errno)); + pthread_cancel(pThreadObj->thread); + } else if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { + // failed to call epoll_ctl, call pthread_cancel instead, which may result in data corruption: + tError("%s, failed to call epoll_ctl(%s)", pThreadObj->label, strerror(errno)); + pthread_cancel(pThreadObj->thread); + } } - pthread_join(pThreadObj->thread, NULL); - close(pThreadObj->pollFd); - if (fd != -1) { - close(fd); - } + if (pThreadObj->thread) pthread_join(pThreadObj->thread, NULL); + if (pThreadObj->pollFd >=0) close(pThreadObj->pollFd); + if (fd != -1) close(fd); while (pThreadObj->pHead) { SFdObj *pFdObj = pThreadObj->pHead; @@ -188,9 +189,8 @@ void taosCleanUpTcpServer(void *handle) { SThreadObj *pThreadObj; if (pServerObj == NULL) return; - - shutdown(pServerObj->fd, SHUT_RD); - pthread_join(pServerObj->thread, NULL); + if(pServerObj->fd >=0) shutdown(pServerObj->fd, SHUT_RD); + if(pServerObj->thread) pthread_join(pServerObj->thread, NULL); for (int i = 0; i < pServerObj->numOfThreads; ++i) { pThreadObj = pServerObj->pThreadObj + i; diff --git a/src/rpc/src/rpcUdp.c b/src/rpc/src/rpcUdp.c index a8811f4136..7e2fe0db61 100644 --- a/src/rpc/src/rpcUdp.c +++ b/src/rpc/src/rpcUdp.c @@ -18,6 +18,7 @@ #include "tsystem.h" #include "ttimer.h" #include "tutil.h" +#include "taosdef.h" #include "rpcLog.h" #include "rpcUdp.h" #include "rpcHead.h" @@ -33,7 +34,7 @@ typedef struct { int fd; uint16_t port; // peer port uint16_t localPort; // local port - char label[12]; // copy from udpConnSet; + char label[TSDB_LABEL_LEN]; // copy from udpConnSet; pthread_t thread; void *hash; void *shandle; // handle passed by upper layer during server initialization @@ -49,7 +50,7 @@ typedef struct { uint16_t port; // local Port void *shandle; // handle passed by upper layer during server initialization int threads; - char label[12]; + char label[TSDB_LABEL_LEN]; void *(*fp)(SRecvInfo *pPacket); SUdpConn udpConn[]; } SUdpConnSet; @@ -93,7 +94,7 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads } struct sockaddr_in sin; - unsigned int addrlen = sizeof(sin); + unsigned int addrlen = sizeof(sin); if (getsockname(pConn->fd, (struct sockaddr *)&sin, &addrlen) == 0 && sin.sin_family == AF_INET && addrlen == sizeof(sin)) { pConn->localPort = (uint16_t)ntohs(sin.sin_port); diff --git a/src/util/src/tsched.c b/src/util/src/tsched.c index 25893969e4..898ab70876 100644 --- a/src/util/src/tsched.c +++ b/src/util/src/tsched.c @@ -14,6 +14,7 @@ */ #include "os.h" +#include "taosdef.h" #include "tulog.h" #include "tsched.h" #include "ttimer.h" @@ -21,7 +22,7 @@ #define DUMP_SCHEDULER_TIME_WINDOW 30000 //every 30sec, take a snap shot of task queue. typedef struct { - char label[16]; + char label[TSDB_LABEL_LEN]; tsem_t emptySem; tsem_t fullSem; pthread_mutex_t queueMutex; From 85261cbfed5097a8e863a05b1a2e16650cc132cd Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Sun, 7 Jun 2020 06:52:42 +0000 Subject: [PATCH 25/72] initialize secret --- src/dnode/src/dnodePeer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dnode/src/dnodePeer.c b/src/dnode/src/dnodePeer.c index ea3af08d71..77a7b0dff4 100644 --- a/src/dnode/src/dnodePeer.c +++ b/src/dnode/src/dnodePeer.c @@ -113,6 +113,7 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { } int32_t dnodeInitClient() { + char secret[TSDB_KEY_LEN] = "secret"; SRpcInit rpcInit; memset(&rpcInit, 0, sizeof(rpcInit)); rpcInit.label = "DND-C"; @@ -123,7 +124,7 @@ int32_t dnodeInitClient() { rpcInit.idleTime = tsShellActivityTimer * 1000; rpcInit.user = "t"; rpcInit.ckey = "key"; - rpcInit.secret = "secret"; + rpcInit.secret = secret; tsDnodeClientRpc = rpcOpen(&rpcInit); if (tsDnodeClientRpc == NULL) { From aca961cceaa39152396223ad006b0416569c819d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 7 Jun 2020 13:53:13 +0000 Subject: [PATCH 26/72] [TD-537] the heartbeat sometimes crashes, limit size to 20 --- src/mnode/src/mnodeProfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index 541fc9cbd8..ed0e717c43 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -264,13 +264,13 @@ static int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, voi // not thread safe, need optimized int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SCMHeartBeatMsg *pHBMsg) { pConn->numOfQueries = htonl(pHBMsg->numOfQueries); - if (pConn->numOfQueries > 0) { + if (pConn->numOfQueries > 0 && pConn->numOfQueries < 20) { pConn->pQueries = calloc(sizeof(SQueryDesc), pConn->numOfQueries); memcpy(pConn->pQueries, pHBMsg->pData, pConn->numOfQueries * sizeof(SQueryDesc)); } pConn->numOfStreams = htonl(pHBMsg->numOfStreams); - if (pConn->numOfStreams > 0) { + if (pConn->numOfStreams > 0 && pConn->numOfStreams < 20) { pConn->pStreams = calloc(sizeof(SStreamDesc), pConn->numOfStreams); memcpy(pConn->pStreams, pHBMsg->pData + pConn->numOfQueries * sizeof(SQueryDesc), pConn->numOfStreams * sizeof(SStreamDesc)); From c9bcdf418521b41e0abc55ae72a392d8beef4885 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 7 Jun 2020 13:55:50 +0000 Subject: [PATCH 27/72] [TD-527] script error while change errno --- tests/script/general/http/grafana.sim | 4 ++-- tests/script/general/http/restful_full.sim | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/script/general/http/grafana.sim b/tests/script/general/http/grafana.sim index a08c07a841..dac7552edf 100644 --- a/tests/script/general/http/grafana.sim +++ b/tests/script/general/http/grafana.sim @@ -66,7 +66,7 @@ endi system_content curl 127.0.0.1:6020/grafana/login/xx/xx/ print 3-> $system_content -if $system_content != @{"status":"error","code":1000,"desc":"invalid user"}@ then +if $system_content != @{"status":"error","code":1000,"desc":"mnode invalid user"}@ then return -1 endi @@ -78,7 +78,7 @@ endi system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:6020/grafana/login/1/root/1/ print 5-> $system_content -if $system_content != @{"status":"error","code":1000,"desc":"invalid user"}@ then +if $system_content != @{"status":"error","code":1000,"desc":"mnode invalid user"}@ then return -1 endi diff --git a/tests/script/general/http/restful_full.sim b/tests/script/general/http/restful_full.sim index 0ae6873503..7194f7cbe0 100644 --- a/tests/script/general/http/restful_full.sim +++ b/tests/script/general/http/restful_full.sim @@ -93,7 +93,7 @@ endi system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database d1' 127.0.0.1:6020/rest/sql print 13-> $system_content -if $system_content != @{"status":"error","code":1000,"desc":"database aleady exist"}@ then +if $system_content != @{"status":"error","code":1000,"desc":"mnode database aleady exist"}@ then return -1 endi @@ -126,7 +126,7 @@ endi #18 system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' show tables;' 127.0.0.1:6020/rest/sql print 18-> $system_content -if $system_content != @{"status":"error","code":1000,"desc":"db not selected"}@ then +if $system_content != @{"status":"error","code":1000,"desc":"mnode db not selected"}@ then return -1 endi @@ -147,7 +147,7 @@ print =============== step3 - db system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1;' 127.0.0.1:6020/rest/sql print 21-> $system_content -if $system_content != @{"status":"error","code":1000,"desc":"invalid table id"}@ then +if $system_content != @{"status":"error","code":1000,"desc":"mnode invalid table id"}@ then return -1 endi From b907acf13a9a4d1465121d074ee6ff3dc6b4b465 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 7 Jun 2020 15:39:40 +0000 Subject: [PATCH 28/72] Bump websocket-extensions in /src/connector/grafana/tdengine Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4. - [Release notes](https://github.com/faye/websocket-extensions-node/releases) - [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md) - [Commits](https://github.com/faye/websocket-extensions-node/compare/0.1.3...0.1.4) Signed-off-by: dependabot[bot] --- src/connector/grafana/tdengine/package-lock.json | 6 +++--- src/connector/grafana/tdengine/yarn.lock | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/connector/grafana/tdengine/package-lock.json b/src/connector/grafana/tdengine/package-lock.json index f8d2df1150..7c8853b99c 100644 --- a/src/connector/grafana/tdengine/package-lock.json +++ b/src/connector/grafana/tdengine/package-lock.json @@ -3724,9 +3724,9 @@ } }, "websocket-extensions": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/websocket-extensions/-/websocket-extensions-0.1.3.tgz", - "integrity": "sha512-nqHUnMXmBzT0w570r2JpJxfiSD1IzoI+HGVdd3aZ0yNi3ngvQ4jv1dtHt5VGxfI2yj5yqImPhOK4vmIh2xMbGg==", + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/websocket-extensions/-/websocket-extensions-0.1.4.tgz", + "integrity": "sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==", "dev": true }, "whatwg-encoding": { diff --git a/src/connector/grafana/tdengine/yarn.lock b/src/connector/grafana/tdengine/yarn.lock index fe7e8122ec..f785e4e478 100644 --- a/src/connector/grafana/tdengine/yarn.lock +++ b/src/connector/grafana/tdengine/yarn.lock @@ -2839,8 +2839,9 @@ websocket-driver@>=0.5.1: websocket-extensions ">=0.1.1" websocket-extensions@>=0.1.1: - version "0.1.3" - resolved "https://registry.yarnpkg.com/websocket-extensions/-/websocket-extensions-0.1.3.tgz#5d2ff22977003ec687a4b87073dfbbac146ccf29" + version "0.1.4" + resolved "https://registry.yarnpkg.com/websocket-extensions/-/websocket-extensions-0.1.4.tgz#7f8473bc839dfd87608adb95d7eb075211578a42" + integrity sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg== whatwg-encoding@^1.0.1: version "1.0.3" From 519cd6aee706726246c6f2cda8c560db92368aa1 Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Mon, 8 Jun 2020 09:44:25 +0800 Subject: [PATCH 29/72] td-449: set parse finsish flag in select statement --- src/client/src/tscAsync.c | 6 ++++-- src/client/src/tscSQLParser.c | 3 ++- src/client/src/tscStream.c | 19 ++++++------------- tests/script/general/stream/new_stream.sim | 22 +++++++++++----------- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 3723c0cf65..a9c170f197 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -517,8 +517,10 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { if (pSql->pStream) { tscTrace("%p stream:%p meta is updated, start new query, command:%d", pSql, pSql->pStream, pSql->cmd.command); - tsParseSql(pSql, false); - sem_post(&pSql->rspSem); + if (!pSql->cmd.parseFinished) { + tsParseSql(pSql, false); + sem_post(&pSql->rspSem); + } return; } else { tscTrace("%p get tableMeta successfully", pSql); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 68980bef98..1584b52e9f 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -515,8 +515,9 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (ret != 0) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); } - } + } + pCmd->parseFinished = 1; return TSDB_CODE_SUCCESS; // do not build query message here } diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index f13e99d7b3..c4413f8541 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -78,30 +78,23 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) { int code = tscGetTableMeta(pSql, pTableMetaInfo); pSql->res.code = code; - if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; - if (code == 0 && UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { code = tscGetSTableVgroupInfo(pSql, 0); pSql->res.code = code; - - if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; } - tscTansformSQLFuncForSTableQuery(pQueryInfo); - // failed to get meter/metric meta, retry in 10sec. if (code != TSDB_CODE_SUCCESS) { int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision); tscError("%p stream:%p,get metermeta failed, retry in %" PRId64 "ms", pStream->pSql, pStream, retryDelayTime); - tscSetRetryTimer(pStream, pSql, retryDelayTime); - return; + + } else { + tscTansformSQLFuncForSTableQuery(pQueryInfo); + tscTrace("%p stream:%p start stream query on:%s", pSql, pStream, pTableMetaInfo->name); + tscDoQuery(pStream->pSql); + tscIncStreamExecutionCount(pStream); } - - tscTrace("%p stream:%p start stream query on:%s", pSql, pStream, pTableMetaInfo->name); - tscDoQuery(pStream->pSql); - - tscIncStreamExecutionCount(pStream); } static void tscProcessStreamTimer(void *handle, void *tmrId) { diff --git a/tests/script/general/stream/new_stream.sim b/tests/script/general/stream/new_stream.sim index 8aa0a89870..abc06faaef 100644 --- a/tests/script/general/stream/new_stream.sim +++ b/tests/script/general/stream/new_stream.sim @@ -1,12 +1,12 @@ -system sh/stop_dnodes.sh +#system sh/stop_dnodes.sh -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c walLevel -v 0 -system sh/cfg.sh -n dnode1 -c tableMetaKeepTimer -v 10 -system sh/exec.sh -n dnode1 -s start +#system sh/deploy.sh -n dnode1 -i 1 +#system sh/cfg.sh -n dnode1 -c walLevel -v 0 +#system sh/cfg.sh -n dnode1 -c tableMetaKeepTimer -v 10 +#system sh/exec.sh -n dnode1 -s start -sleep 3000 +#sleep 3000 sql connect print ======================== dnode1 start @@ -56,14 +56,14 @@ print $data00 $data01 $data02 $data03 sql create table $st as select count(*), count(tbcol), count(tbcol2) from $mt interval(10s) print =============== step3 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 print =============== step4 sql select * from $st print $st ==> $rows1 $data00 $data01 $data02 $data03 -if $data13 >= 51 then +if $data03 >= 51 then return -1 endi @@ -90,8 +90,8 @@ while $i < $tbNum endw print =============== step6 -print sleep 22 seconds -sleep 22000 +print sleep 120 seconds +sleep 120000 print =============== step7 From b08c2b97a16e9d299e52dcf6b02c9bd6a5e52a08 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 11:13:08 +0800 Subject: [PATCH 30/72] [TD-545] scripts --- tests/script/general/parser/limit2.sim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/script/general/parser/limit2.sim b/tests/script/general/parser/limit2.sim index 61f817644a..5f71232585 100644 --- a/tests/script/general/parser/limit2.sim +++ b/tests/script/general/parser/limit2.sim @@ -69,6 +69,8 @@ print ====== tables created print ================== restart server to commit data into disk system sh/exec.sh -n dnode1 -s stop -x SIGINT + +return sleep 3000 system sh/exec.sh -n dnode1 -s start print ================== server restart completed From fb1f837d280d69fa10a0d277ed410102fffb1e32 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Mon, 8 Jun 2020 11:16:13 +0800 Subject: [PATCH 31/72] update script to support wal param --- .../perftest-scripts/perftest-csv2png.gnuplot | 2 +- tests/perftest-scripts/perftest-daily.sh | 74 +++++++++++++++---- tests/perftest-scripts/perftest-taosdemo.sh | 72 +++++++++++------- .../perftest-tsdb-compare-13d.sh | 12 +-- .../perftest-tsdb-compare-1d.sh | 12 +-- tests/perftest-scripts/runreal-13d-csv.sh | 2 +- tests/perftest-scripts/runreal-1d-csv.sh | 2 +- .../perftest-scripts/taosdemo-csv2png.gnuplot | 10 +-- 8 files changed, 124 insertions(+), 62 deletions(-) diff --git a/tests/perftest-scripts/perftest-csv2png.gnuplot b/tests/perftest-scripts/perftest-csv2png.gnuplot index 9c34ebe403..eabab268ca 100644 --- a/tests/perftest-scripts/perftest-csv2png.gnuplot +++ b/tests/perftest-scripts/perftest-csv2png.gnuplot @@ -2,7 +2,7 @@ reset set terminal png -set title "Performance Test Report" font ",20" +set title filename font ",20" set ylabel "Time in Seconds" diff --git a/tests/perftest-scripts/perftest-daily.sh b/tests/perftest-scripts/perftest-daily.sh index db9de11381..b44387047c 100755 --- a/tests/perftest-scripts/perftest-daily.sh +++ b/tests/perftest-scripts/perftest-daily.sh @@ -16,9 +16,26 @@ function echoInfo { local args="$@"; white_brackets $(green_printf "INFO") && function echoWarn { local args="$@"; echo "$(white_brackets "$(yellow_printf "WARN")" && echo " ${args}";)" 1>&2; } # function echoError { local args="$@"; echo "$(white_brackets "$(red_printf "ERROR")" && echo " ${args}";)" 1>&2; } # -function set-Wal { +function setMaxConnections { + echo "/etc/taos/taos.cfg maxConnection will be set to $1" + + hasText=`grep "maxConnections" /etc/taos/taos.cfg` + if [[ -z "$hasText" ]]; then + echo "maxConnections $1" >> /etc/taos/taos.cfg + else + sed -i 's/^maxConnections.*$/maxConnections '"$1"'/g' /etc/taos/taos.cfg + fi +} + +function setWal { echo "/etc/taos/taos.cfg walLevel will be set to $1" - sed -i 's/^walLevel.*$/walLevel '"$1"'/g' /etc/taos/taos.cfg + + hasText=`grep "walLevel" /etc/taos/taos.cfg` + if [[ -z "$hasText" ]]; then + echo "walLevel $1" >> /etc/taos/taos.cfg + else + sed -i 's/^walLevel.*$/walLevel '"$1"'/g' /etc/taos/taos.cfg + fi } function collectSysInfo { @@ -70,15 +87,25 @@ function sendReport { mimebody="MIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n" echo -e "to: ${receiver}\nsubject: Perf test report ${today}, commit ID: ${LOCAL_COMMIT}\n" | \ - (cat - && uuencode perftest-1d-$today.log perftest-1d-$today.log)| \ - (cat - && uuencode perftest-1d-report.csv perftest-1d-report-$today.csv) | \ - (cat - && uuencode perftest-1d-report.png perftest-1d-report-$today.png) | \ - (cat - && uuencode perftest-13d-$today.log perftest-13d-$today.log)| \ - (cat - && uuencode perftest-13d-report.csv perftest-13d-report-$today.csv) | \ - (cat - && uuencode perftest-13d-report.png perftest-13d-report-$today.png) | \ - (cat - && uuencode taosdemo-$today.log taosdemo-$today.log) | \ - (cat - && uuencode taosdemo-report.csv taosdemo-report-$today.csv) | \ - (cat - && uuencode taosdemo-report.png taosdemo-report-$today.png) | \ + (cat - && uuencode perftest-1d-wal1-$today.log perftest-1d-wal1-$today.log)| \ + (cat - && uuencode perftest-1d-wal1-report.csv perftest-1d-wal1-report-$today.csv) | \ + (cat - && uuencode perftest-1d-wal1-report.png perftest-1d-wal1-report-$today.png) | \ + (cat - && uuencode perftest-13d-wal1-$today.log perftest-13d-wal1-$today.log)| \ + (cat - && uuencode perftest-13d-wal1-report.csv perftest-13d-wal1-report-$today.csv) | \ + (cat - && uuencode perftest-13d-wal1-report.png perftest-13d-wal1-report-$today.png) | \ + (cat - && uuencode taosdemo-wal1-$today.log taosdemo-wal1-$today.log) | \ + (cat - && uuencode taosdemo-wal1-report.csv taosdemo-wal1-report-$today.csv) | \ + (cat - && uuencode taosdemo-rps-wal1-report.csv taosdemo-rps-wal1-report-$today.csv) | \ + (cat - && uuencode taosdemo-wal1-report.png taosdemo-wal1-report-$today.png) | \ + (cat - && uuencode perftest-1d-wal2-$today.log perftest-1d-wal2-$today.log)| \ + (cat - && uuencode perftest-1d-wal2-report.csv perftest-1d-wal2-report-$today.csv) | \ + (cat - && uuencode perftest-1d-wal2-report.png perftest-1d-wal2-report-$today.png) | \ + (cat - && uuencode perftest-13d-wal2-$today.log perftest-13d-wal2-$today.log)| \ + (cat - && uuencode perftest-13d-wal2-report.csv perftest-13d-wal2-report-$today.csv) | \ + (cat - && uuencode perftest-13d-wal2-report.png perftest-13d-wal2-report-$today.png) | \ + (cat - && uuencode taosdemo-wal2-$today.log taosdemo-wal2-$today.log) | \ + (cat - && uuencode taosdemo-wal2-report.csv taosdemo-wal2-report-$today.csv) | \ + (cat - && uuencode taosdemo-rps-wal2-report.csv taosdemo-rps-wal2-report-$today.csv) | \ (cat - && uuencode sysinfo.log sysinfo.txt) | \ (cat - && uuencode taos.cfg taos-cfg-$today.txt) | \ ssmtp "${receiver}" @@ -91,17 +118,34 @@ echo -e "cron-ran-at-${today}" >> cron.log echoInfo "Build TDengine" buildTDengine -set-Wal "2" +############################ +setMaxConnections 100 + +############################ +setWal "2" cd /root -./perftest-tsdb-compare-1d.sh +./perftest-tsdb-compare-1d.sh "wal2" cd /root -./perftest-tsdb-compare-13d.sh +./perftest-tsdb-compare-13d.sh "wal2" cd /root -./perftest-taosdemo.sh +./perftest-taosdemo.sh "wal2" +############################# +setWal "1" + +cd /root +./perftest-tsdb-compare-1d.sh "wal1" + +cd /root +./perftest-tsdb-compare-13d.sh "wal1" + +cd /root +./perftest-taosdemo.sh "wal1" + +############################# collectSysInfo echoInfo "Send Report" diff --git a/tests/perftest-scripts/perftest-taosdemo.sh b/tests/perftest-scripts/perftest-taosdemo.sh index 511ec22fec..0dd9a0572a 100755 --- a/tests/perftest-scripts/perftest-taosdemo.sh +++ b/tests/perftest-scripts/perftest-taosdemo.sh @@ -1,20 +1,20 @@ #!/bin/bash -# Coloured Echoes # -function red_echo { echo -e "\033[31m$@\033[0m"; } # -function green_echo { echo -e "\033[32m$@\033[0m"; } # -function yellow_echo { echo -e "\033[33m$@\033[0m"; } # -function white_echo { echo -e "\033[1;37m$@\033[0m"; } # -# Coloured Printfs # -function red_printf { printf "\033[31m$@\033[0m"; } # -function green_printf { printf "\033[32m$@\033[0m"; } # -function yellow_printf { printf "\033[33m$@\033[0m"; } # -function white_printf { printf "\033[1;37m$@\033[0m"; } # -# Debugging Outputs # -function white_brackets { local args="$@"; white_printf "["; printf "${args}"; white_printf "]"; } # -function echoInfo { local args="$@"; white_brackets $(green_printf "INFO") && echo " ${args}"; } # -function echoWarn { local args="$@"; echo "$(white_brackets "$(yellow_printf "WARN")" && echo " ${args}";)" 1>&2; } # -function echoError { local args="$@"; echo "$(white_brackets "$(red_printf "ERROR")" && echo " ${args}";)" 1>&2; } # +# Coloured Echoes +function red_echo { echo -e "\033[31m$@\033[0m"; } +function green_echo { echo -e "\033[32m$@\033[0m"; } +function yellow_echo { echo -e "\033[33m$@\033[0m"; } +function white_echo { echo -e "\033[1;37m$@\033[0m"; } +# Coloured Printfs +function red_printf { printf "\033[31m$@\033[0m"; } +function green_printf { printf "\033[32m$@\033[0m"; } +function yellow_printf { printf "\033[33m$@\033[0m"; } +function white_printf { printf "\033[1;37m$@\033[0m"; } +# Debugging Outputs +function white_brackets { local args="$@"; white_printf "["; printf "${args}"; white_printf "]"; } +function echoInfo { local args="$@"; white_brackets $(green_printf "INFO") && echo " ${args}"; } +function echoWarn { local args="$@"; echo "$(white_brackets "$(yellow_printf "WARN")" && echo " ${args}";)" 1>&2; } +function echoError { local args="$@"; echo "$(white_brackets "$(red_printf "ERROR")" && echo " ${args}";)" 1>&2; } function restartTaosd { systemctl stop taosd @@ -32,39 +32,57 @@ function runCreateTableOnly { echoInfo "Restart Taosd" restartTaosd - /usr/bin/time -f "Total: %e" -o totaltime.out bash -c "yes | taosdemo -n 0 2>&1 | tee taosdemo-$today.log" - demoTableOnly=`grep "Total:" totaltime.out|awk '{print $2}'` + /usr/bin/time -f "Total: %e" -o totaltime.out bash -c "yes | taosdemo -n 0 2>&1 | tee taosdemo-$1-$today.log" + demoCreateTableOnly=`grep "Total:" totaltime.out|awk '{print $2}'` +} + +function runDeleteTableOnly { + echoInfo "Restart Taosd" + restartTaosd + + /usr/bin/time -f "Total: %e" -o totaltime.out bash -c "yes | taosdemo -t 0 -D 1 2>&1 | tee taosdemo-$1-$today.log" + demoDeleteTableOnly=`grep "Total:" totaltime.out|awk '{print $2}'` } function runCreateTableThenInsert { echoInfo "Restart Taosd" restartTaosd - /usr/bin/time -f "Total: %e" -o totaltime.out bash -c "yes | taosdemo 2>&1 | tee -a taosdemo-$today.log" + /usr/bin/time -f "Total: %e" -o totaltime.out bash -c "yes | taosdemo 2>&1 | tee -a taosdemo-$1-$today.log" demoTableAndInsert=`grep "Total:" totaltime.out|awk '{print $2}'` - demoRPS=`grep "records\/second" taosdemo-$today.log | tail -n1 | awk '{print $13}'` + demoRPS=`grep "records\/second" taosdemo-$1-$today.log | tail -n1 | awk '{print $13}'` } function generateTaosdemoPlot { - echo "${today}, demoTableOnly: ${demoTableOnly}, demoTableAndInsert: ${demoTableAndInsert}" | tee -a taosdemo-$today.log - echo "${today}, ${demoTableOnly}, ${demoTableAndInsert}, ${demoRPS}" >> taosdemo-report.csv + echo "${today} $1, demoCreateTableOnly: ${demoCreateTableOnly}, demoDeleteTableOnly: ${demoDeleteTableOnly}, demoTableAndInsert: ${demoTableAndInsert}" | tee -a taosdemo-$today.log + echo "${today}, ${demoCreateTableOnly}, ${demoDeleteTableOnly}, ${demoTableAndInsert}">> taosdemo-$1-report.csv + echo "${today}, ${demoRPS}" >> taosdemo-rps-$1-report.csv - csvLines=`cat taosdemo-report.csv | wc -l` + csvLines=`cat taosdemo-$1-report.csv | wc -l` if [ "$csvLines" -gt "10" ]; then - sed -i '1d' taosdemo-report.csv + sed -i '1d' taosdemo-$1-report.csv fi - gnuplot -p taosdemo-csv2png.gnuplot + csvLines=`cat taosdemo-rps-$1-report.csv | wc -l` + + if [ "$csvLines" -gt "10" ]; then + sed -i '1d' taosdemo-rps-$1-report.csv + fi + + gnuplot -e "filename='taosdemo-$1-report'" -p taosdemo-csv2png.gnuplot + gnuplot -e "filename='taosdemo-rps-$1-report'" -p taosdemo-rps-csv2png.gnuplot } today=`date +"%Y%m%d"` cd /root echoInfo "Test Create Table Only " -runCreateTableOnly +runCreateTableOnly $1 echoInfo "Test Create Table then Insert data" -runCreateTableThenInsert +runDeleteTableOnly $1 +echoInfo "Test Create Table then Insert data" +runCreateTableThenInsert $1 echoInfo "Generate plot for taosdemo" -generateTaosdemoPlot +generateTaosdemoPlot $1 echoInfo "End of TaosDemo Test" diff --git a/tests/perftest-scripts/perftest-tsdb-compare-13d.sh b/tests/perftest-scripts/perftest-tsdb-compare-13d.sh index 4b3ed6818c..8b326d2d41 100755 --- a/tests/perftest-scripts/perftest-tsdb-compare-13d.sh +++ b/tests/perftest-scripts/perftest-tsdb-compare-13d.sh @@ -33,26 +33,26 @@ function runPerfTest13d { restartTaosd cd /home/taos/tliu/timeseriesdatabase-comparisons/build/tsdbcompare - ./runreal-13d-csv.sh 2>&1 | tee /root/perftest-13d-$today.log + ./runreal-13d-csv.sh $1 2>&1 | tee /root/perftest-13d-$1-$today.log } function generatePerfPlot13d { cd /root - csvLines=`cat perftest-13d-report.csv | wc -l` + csvLines=`cat perftest-13d-$1-report.csv | wc -l` if [ "$csvLines" -gt "10" ]; then - sed -i '1d' perftest-13d-report.csv + sed -i '1d' perftest-13d-$1-report.csv fi - gnuplot -e "filename='perftest-13d-report'" -p perftest-csv2png.gnuplot + gnuplot -e "filename='perftest-13d-$1-report'" -p perftest-csv2png.gnuplot } today=`date +"%Y%m%d"` cd /root echoInfo "run Performance Test with 13 days data" -runPerfTest13d +runPerfTest13d $1 echoInfo "Generate plot of 13 days data" -generatePerfPlot13d +generatePerfPlot13d $1 echoInfo "End of TSDB-Compare 13-days-data Test" diff --git a/tests/perftest-scripts/perftest-tsdb-compare-1d.sh b/tests/perftest-scripts/perftest-tsdb-compare-1d.sh index ebe34cde72..0931480e21 100755 --- a/tests/perftest-scripts/perftest-tsdb-compare-1d.sh +++ b/tests/perftest-scripts/perftest-tsdb-compare-1d.sh @@ -33,26 +33,26 @@ function runPerfTest1d { restartTaosd cd /home/taos/tliu/timeseriesdatabase-comparisons/build/tsdbcompare - ./runreal-1d-csv.sh 2>&1 | tee /root/perftest-1d-$today.log + ./runreal-1d-csv.sh $1 2>&1 | tee /root/perftest-1d-$1-$today.log } function generatePerfPlot1d { cd /root - csvLines=`cat perftest-1d-report.csv | wc -l` + csvLines=`cat perftest-1d-$1-report.csv | wc -l` if [ "$csvLines" -gt "10" ]; then - sed -i '2d' perftest-1d-report.csv + sed -i '2d' perftest-1d-$1-report.csv fi - gnuplot -e "filename='perftest-1d-report'" -p perftest-csv2png.gnuplot + gnuplot -e "filename='perftest-1d-$1-report'" -p perftest-csv2png.gnuplot } today=`date +"%Y%m%d"` cd /root echoInfo "run Performance Test with 1 day data" -runPerfTest1d +runPerfTest1d $1 echoInfo "Generate plot of 1 day data" -generatePerfPlot1d +generatePerfPlot1d $1 echoInfo "End of TSDB-Compare 1-day-data Test" diff --git a/tests/perftest-scripts/runreal-13d-csv.sh b/tests/perftest-scripts/runreal-13d-csv.sh index ff7ce41d4b..48ef01e6a0 100755 --- a/tests/perftest-scripts/runreal-13d-csv.sh +++ b/tests/perftest-scripts/runreal-13d-csv.sh @@ -143,7 +143,7 @@ echo "------------------------------------------------------" echo today=`date +"%Y%m%d"` -echo "${today}, ${TDWTM}, ${TDQ1}, ${TDQ2}, ${TDQ3}, ${TDQ4}" >> /root/perftest-13d-report.csv +echo "${today}, ${TDWTM}, ${TDQ1}, ${TDQ2}, ${TDQ3}, ${TDQ4}" >> /root/perftest-13d-$1-report.csv #bulk_query_gen/bulk_query_gen -format influx-http -query-type 1-host-1-hr -scale-var 10 -queries 1000 | query_benchmarker_influxdb/query_benchmarker_influxdb -urls="http://172.26.89.231:8086" #bulk_query_gen/bulk_query_gen -format tdengine -query-type 1-host-1-hr -scale-var 10 -queries 1000 | query_benchmarker_tdengine/query_benchmarker_tdengine -urls="http://172.26.89.231:6020" diff --git a/tests/perftest-scripts/runreal-1d-csv.sh b/tests/perftest-scripts/runreal-1d-csv.sh index 5cd113aadf..20c8b4138c 100755 --- a/tests/perftest-scripts/runreal-1d-csv.sh +++ b/tests/perftest-scripts/runreal-1d-csv.sh @@ -143,7 +143,7 @@ echo "------------------------------------------------------" echo today=`date +"%Y%m%d"` -echo "${today}, ${TDWTM}, ${TDQ1}, ${TDQ2}, ${TDQ3}, ${TDQ4}" >> /root/perftest-1d-report.csv +echo "${today}, ${TDWTM}, ${TDQ1}, ${TDQ2}, ${TDQ3}, ${TDQ4}" >> /root/perftest-1d-$1-report.csv #bulk_query_gen/bulk_query_gen -format influx-http -query-type 1-host-1-hr -scale-var 10 -queries 1000 | query_benchmarker_influxdb/query_benchmarker_influxdb -urls="http://172.26.89.231:8086" #bulk_query_gen/bulk_query_gen -format tdengine -query-type 1-host-1-hr -scale-var 10 -queries 1000 | query_benchmarker_tdengine/query_benchmarker_tdengine -urls="http://172.26.89.231:6020" diff --git a/tests/perftest-scripts/taosdemo-csv2png.gnuplot b/tests/perftest-scripts/taosdemo-csv2png.gnuplot index 9fcd4bb3d9..7cdcb84fce 100644 --- a/tests/perftest-scripts/taosdemo-csv2png.gnuplot +++ b/tests/perftest-scripts/taosdemo-csv2png.gnuplot @@ -2,7 +2,7 @@ reset set terminal png -set title "TaosDemo Performance Report" font ",20" +set title filename font ",20" set ylabel "Time in Seconds" @@ -14,13 +14,13 @@ set xlabel "Date" set style data linespoints set terminal pngcairo size 1024,768 enhanced font 'Segoe UI, 10' -set output 'taosdemo-report.png' +set output filename . '.png' set datafile separator ',' set key reverse Left outside set grid -plot 'taosdemo-report.csv' using 1:2 title "Create 10,000 Table", \ - "" using 1:3 title "Create 10,000 Table and Insert 100,000 data", \ - "" using 1:4 title "Request Per Second of Insert 100,000 data" +plot filename . '.csv' using 1:2 title "Create 10,000 Tables", \ + "" using 1:3 title "Delete 10,000 Tables", \ + "" using 1:4 title "Create 10,000 Tables and Insert 100,000 records" From 353dc70f4b1f6509920eda7346b6f4d5d1d1f648 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 12:16:55 +0800 Subject: [PATCH 32/72] scripts --- tests/script/bug.sim | 2 + tests/script/general/compress/commitlog.sim | 12 ++--- tests/script/general/compress/compress.sim | 12 ++--- tests/script/general/compress/compress2.sim | 12 ++--- tests/script/general/compress/uncompress.sim | 12 ++--- tests/script/jenkins/simple.txt | 48 ++++++++++++++++++++ 6 files changed, 74 insertions(+), 24 deletions(-) create mode 100644 tests/script/bug.sim create mode 100644 tests/script/jenkins/simple.txt diff --git a/tests/script/bug.sim b/tests/script/bug.sim new file mode 100644 index 0000000000..625b9b0cad --- /dev/null +++ b/tests/script/bug.sim @@ -0,0 +1,2 @@ +run general/parser/projection_limit_offset.sim +run general/parser/limit2.sim \ No newline at end of file diff --git a/tests/script/general/compress/commitlog.sim b/tests/script/general/compress/commitlog.sim index 2c69b809d1..7c167db3f3 100644 --- a/tests/script/general/compress/commitlog.sim +++ b/tests/script/general/compress/commitlog.sim @@ -25,8 +25,8 @@ sql create table $tb (ts timestamp, b bool, t tinyint, s smallint, i int, big bi $count = 0 while $count < $N - $ms = $count . a - sql insert into $tb values( now+ $ms , 1, 0, $count , $count , $count ,'it is a string') + $ms = 1591200000000 + $count + sql insert into $tb values( $ms , 1, 0, $count , $count , $count ,'it is a string') $count = $count + 1 endw @@ -46,8 +46,8 @@ sql create table $tb (ts timestamp, f float, d double, str binary(256)) $count = 0 while $count < $N - $ms = $count . a - sql insert into $tb values( now+ $ms , $count , $count ,'it is a string') + $ms = 1591286400000 + $count + sql insert into $tb values( $ms , $count , $count ,'it is a string') $count = $count + 1 endw @@ -75,8 +75,8 @@ sql create table $tb (ts timestamp, b bool, t tinyint, s smallint, i int, big bi $count = 0 while $count < $N - $ms = $count . a - sql insert into $tb values( now+ $ms , 1 , 0 , $count , $count , $count , $count , $count ,'it is a string') + $ms = 1591372800000 + $count + sql insert into $tb values( $ms , 1 , 0 , $count , $count , $count , $count , $count ,'it is a string') $count = $count + 1 endw diff --git a/tests/script/general/compress/compress.sim b/tests/script/general/compress/compress.sim index bc56227c74..93fdcbaafa 100644 --- a/tests/script/general/compress/compress.sim +++ b/tests/script/general/compress/compress.sim @@ -26,8 +26,8 @@ sql create table $tb (ts timestamp, b bool, t tinyint, s smallint, i int, big bi $count = 0 while $count < $N - $ms = $count . a - sql insert into $tb values( now+ $ms , 1, 0, $count , $count , $count ,'it is a string') + $ms = 1591200000000 + $count + sql insert into $tb values( $ms , 1, 0, $count , $count , $count ,'it is a string') $count = $count + 1 endw @@ -48,8 +48,8 @@ sql create table $tb (ts timestamp, f float, d double, str binary(256)) $count = 0 while $count < $N - $ms = $count . a - sql insert into $tb values( now+ $ms , $count , $count ,'it is a string') + $ms = 1591286400000 + $count + sql insert into $tb values( $ms , $count , $count ,'it is a string') $count = $count + 1 endw @@ -70,8 +70,8 @@ sql create table $tb (ts timestamp, b bool, t tinyint, s smallint, i int, big bi $count = 0 while $count < $N - $ms = $count . a - sql insert into $tb values( now+ $ms , 1 , 0 , $count , $count , $count , $count , $count ,'it is a string') + $ms = 1591372800000 + $count + sql insert into $tb values( $ms , 1 , 0 , $count , $count , $count , $count , $count ,'it is a string') $count = $count + 1 endw diff --git a/tests/script/general/compress/compress2.sim b/tests/script/general/compress/compress2.sim index c3b445c04c..0eb58bd94b 100644 --- a/tests/script/general/compress/compress2.sim +++ b/tests/script/general/compress/compress2.sim @@ -26,8 +26,8 @@ sql create table $tb (ts timestamp, b bool, t tinyint, s smallint, i int, big bi $count = 0 while $count < $N - $ms = $count . a - sql insert into $tb values( now+ $ms , 1, 0, $count , $count , $count ,'it is a string') + $ms = 1591200000000 + $count + sql insert into $tb values( $ms , 1, 0, $count , $count , $count ,'it is a string') $count = $count + 1 endw @@ -48,8 +48,8 @@ sql create table $tb (ts timestamp, f float, d double, str binary(256)) $count = 0 while $count < $N - $ms = $count . a - sql insert into $tb values( now+ $ms , $count , $count ,'it is a string') + $ms = 1591286400000 + $count + sql insert into $tb values( $ms , $count , $count ,'it is a string') $count = $count + 1 endw @@ -70,8 +70,8 @@ sql create table $tb (ts timestamp, b bool, t tinyint, s smallint, i int, big bi $count = 0 while $count < $N - $ms = $count . a - sql insert into $tb values( now+ $ms , 1 , 0 , $count , $count , $count , $count , $count ,'it is a string') + $ms = 1591372800000 + $count + sql insert into $tb values( $ms , 1 , 0 , $count , $count , $count , $count , $count ,'it is a string') $count = $count + 1 endw diff --git a/tests/script/general/compress/uncompress.sim b/tests/script/general/compress/uncompress.sim index 8dde7fae34..13d288451c 100644 --- a/tests/script/general/compress/uncompress.sim +++ b/tests/script/general/compress/uncompress.sim @@ -25,8 +25,8 @@ sql create table $tb (ts timestamp, b bool, t tinyint, s smallint, i int, big bi $count = 0 while $count < $N - $ms = $count . a - sql insert into $tb values( now+ $ms , 1, 0, $count , $count , $count ,'it is a string') + $ms = 1591200000000 + $count + sql insert into $tb values( $ms , 1, 0, $count , $count , $count ,'it is a string') $count = $count + 1 endw @@ -47,8 +47,8 @@ sql create table $tb (ts timestamp, f float, d double, str binary(256)) $count = 0 while $count < $N - $ms = $count . a - sql insert into $tb values( now+ $ms , $count , $count ,'it is a string') + $ms = 1591286400000 + $count + sql insert into $tb values( $ms , $count , $count ,'it is a string') $count = $count + 1 endw @@ -69,8 +69,8 @@ sql create table $tb (ts timestamp, b bool, t tinyint, s smallint, i int, big bi $count = 0 while $count < $N - $ms = $count . a - sql insert into $tb values( now+ $ms , 1 , 0 , $count , $count , $count , $count , $count ,'it is a string') + $ms = 1591372800000 + $count + sql insert into $tb values( $ms , 1 , 0 , $count , $count , $count , $count , $count ,'it is a string') $count = $count + 1 endw diff --git a/tests/script/jenkins/simple.txt b/tests/script/jenkins/simple.txt new file mode 100644 index 0000000000..ae48994c2a --- /dev/null +++ b/tests/script/jenkins/simple.txt @@ -0,0 +1,48 @@ +cd ../../../debug; cmake .. +cd ../../../debug; make + +#./test.sh -f general/parser/lastrow.sim +#./test.sh -f general/parser/nchar.sim +#./test.sh -f general/parser/limit.sim +#./test.sh -f general/parser/limit1.sim +#./test.sh -f general/parser/limit1_tblocks100.sim +#./test.sh -f general/parser/binary_escapeCharacter.sim +#./test.sh -f general/parser/projection_limit_offset.sim +#./test.sh -f general/parser/limit2.sim +#./test.sh -f general/stable/metrics.sim +#./test.sh -f general/table/date.sim +#./test.sh -f unique/big/balance.sim +#./test.sh -f unique/column/replica3.sim +#./test.sh -f unique/db/commit.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim +./test.sh -f unique/db/delete.sim + +#./test.sh -f unique/db/replica_add12.sim +#./test.sh -f unique/db/replica_add13.sim +#./test.sh -f unique/vnode/replica3_basic.sim +#./test.sh -f unique/dnode/balance1.sim +#./test.sh -f unique/dnode/balance2.sim +#./test.sh -f unique/dnode/balance3.sim +#./test.sh -f unique/cluster/balance1.sim +#./test.sh -f unique/cluster/balance2.sim +#./test.sh -f unique/cluster/balance3.sim \ No newline at end of file From fa2a96e520f37976c5f81fb8320fb6741cb62910 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 13:03:49 +0800 Subject: [PATCH 33/72] [TD-549] fix crash while vread return TSDB_CODE_NOT_READY errno --- src/dnode/src/dnodeVRead.c | 5 +++-- src/dnode/src/dnodeVWrite.c | 2 +- src/inc/vnode.h | 1 - src/vnode/src/vnodeRead.c | 26 ++++++++++++++++---------- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/dnode/src/dnodeVRead.c b/src/dnode/src/dnodeVRead.c index 7f1a5b2580..2f9e9a0af9 100644 --- a/src/dnode/src/dnodeVRead.c +++ b/src/dnode/src/dnodeVRead.c @@ -192,13 +192,14 @@ void dnodeSendRpcReadRsp(void *pVnode, SReadMsg *pRead, int32_t code) { if (code == TSDB_CODE_VND_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_VND_ACTION_NEED_REPROCESSED) { dnodeContinueExecuteQuery(pVnode, pRead->rspRet.qhandle, pRead); + code = TSDB_CODE_SUCCESS; } SRpcMsg rpcRsp = { .handle = pRead->rpcMsg.handle, .pCont = pRead->rspRet.rsp, .contLen = pRead->rspRet.len, - .code = pRead->rspRet.code, + .code = code, }; rpcSendResponse(&rpcRsp); @@ -216,7 +217,7 @@ static void *dnodeProcessReadQueue(void *param) { break; } - dTrace("%p, msg:%s will be processed", pReadMsg->rpcMsg.ahandle, taosMsg[pReadMsg->rpcMsg.msgType]); + dTrace("%p, msg:%s will be processed in vread queue", pReadMsg->rpcMsg.ahandle, taosMsg[pReadMsg->rpcMsg.msgType]); int32_t code = vnodeProcessRead(pVnode, pReadMsg->rpcMsg.msgType, pReadMsg->pCont, pReadMsg->contLen, &pReadMsg->rspRet); dnodeSendRpcReadRsp(pVnode, pReadMsg, code); taosFreeQitem(pReadMsg); diff --git a/src/dnode/src/dnodeVWrite.c b/src/dnode/src/dnodeVWrite.c index 53533b8183..e61364355d 100644 --- a/src/dnode/src/dnodeVWrite.c +++ b/src/dnode/src/dnodeVWrite.c @@ -216,7 +216,7 @@ static void *dnodeProcessWriteQueue(void *param) { pHead->msgType = pWrite->rpcMsg.msgType; pHead->version = 0; pHead->len = pWrite->contLen; - dTrace("%p, msg:%s will be processed", pWrite->rpcMsg.ahandle, taosMsg[pWrite->rpcMsg.msgType]); + dTrace("%p, msg:%s will be processed in vwrite queue", pWrite->rpcMsg.ahandle, taosMsg[pWrite->rpcMsg.msgType]); } else { pHead = (SWalHead *)item; } diff --git a/src/inc/vnode.h b/src/inc/vnode.h index f4fb8060fe..4d482afa02 100644 --- a/src/inc/vnode.h +++ b/src/inc/vnode.h @@ -30,7 +30,6 @@ typedef enum _VN_STATUS { typedef struct { int len; - int code; void *rsp; void *qhandle; //used by query and retrieve msg } SRspRet; diff --git a/src/vnode/src/vnodeRead.c b/src/vnode/src/vnodeRead.c index 2cf72bb15d..f198c2ffe4 100644 --- a/src/vnode/src/vnodeRead.c +++ b/src/vnode/src/vnodeRead.c @@ -39,15 +39,21 @@ void vnodeInitReadFp(void) { int32_t vnodeProcessRead(void *param, int msgType, void *pCont, int32_t contLen, SRspRet *ret) { SVnodeObj *pVnode = (SVnodeObj *)param; - if (vnodeProcessReadMsgFp[msgType] == NULL) + if (vnodeProcessReadMsgFp[msgType] == NULL) { + vTrace("vgId:%d, msgType:%s not processed, no handle", pVnode->vgId, taosMsg[msgType]); return TSDB_CODE_VND_MSG_NOT_PROCESSED; + } - if (pVnode->status == TAOS_VN_STATUS_DELETING || pVnode->status == TAOS_VN_STATUS_CLOSING) + if (pVnode->status == TAOS_VN_STATUS_DELETING || pVnode->status == TAOS_VN_STATUS_CLOSING) { + vTrace("vgId:%d, msgType:%s not processed, vnode status is %d", pVnode->vgId, taosMsg[msgType], pVnode->status); return TSDB_CODE_VND_INVALID_VGROUP_ID; + } // TODO: Later, let slave to support query - if (pVnode->syncCfg.replica > 1 && pVnode->role != TAOS_SYNC_ROLE_MASTER) + if (pVnode->syncCfg.replica > 1 && pVnode->role != TAOS_SYNC_ROLE_MASTER) { + vTrace("vgId:%d, msgType:%s not processed, replica:%d role:%d", pVnode->vgId, taosMsg[msgType], pVnode->syncCfg.replica, pVnode->role); return TSDB_CODE_RPC_NOT_READY; + } return (*vnodeProcessReadMsgFp[msgType])(pVnode, pCont, contLen, ret); } @@ -60,11 +66,11 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, void *pCont, int32_t cont qinfo_t pQInfo = NULL; if (contLen != 0) { - pRet->code = qCreateQueryInfo(pVnode->tsdb, pVnode->vgId, pQueryTableMsg, &pQInfo); + code = qCreateQueryInfo(pVnode->tsdb, pVnode->vgId, pQueryTableMsg, &pQInfo); SQueryTableRsp *pRsp = (SQueryTableRsp *) rpcMallocCont(sizeof(SQueryTableRsp)); pRsp->qhandle = htobe64((uint64_t) (pQInfo)); - pRsp->code = pRet->code; + pRsp->code = code; pRet->len = sizeof(SQueryTableRsp); pRet->rsp = pRsp; @@ -74,9 +80,11 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, void *pCont, int32_t cont assert(pCont != NULL); pQInfo = pCont; code = TSDB_CODE_VND_ACTION_IN_PROGRESS; + vTrace("vgId:%d, QInfo:%p, dnode query msg in progress", pVnode->vgId, pQInfo); } if (pQInfo != NULL) { + vTrace("vgId:%d, QInfo:%p, do qTableQuery", pVnode->vgId, pQInfo); qTableQuery(pQInfo); // do execute query } @@ -88,18 +96,16 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, void *pCont, int32_t cont void *pQInfo = (void*) htobe64(pRetrieve->qhandle); memset(pRet, 0, sizeof(SRspRet)); - int32_t code = TSDB_CODE_SUCCESS; - vTrace("vgId:%d, QInfo:%p, retrieve msg is received", pVnode->vgId, pQInfo); - pRet->code = qRetrieveQueryResultInfo(pQInfo); - if (pRet->code != TSDB_CODE_SUCCESS) { + int32_t code = qRetrieveQueryResultInfo(pQInfo); + if (code != TSDB_CODE_SUCCESS) { //TODO pRet->rsp = (SRetrieveTableRsp *)rpcMallocCont(sizeof(SRetrieveTableRsp)); memset(pRet->rsp, 0, sizeof(SRetrieveTableRsp)); } else { // todo check code and handle error in build result set - pRet->code = qDumpRetrieveResult(pQInfo, (SRetrieveTableRsp **)&pRet->rsp, &pRet->len); + code = qDumpRetrieveResult(pQInfo, (SRetrieveTableRsp **)&pRet->rsp, &pRet->len); if (qHasMoreResultsToRetrieve(pQInfo)) { pRet->qhandle = pQInfo; From b3389e268c83992012adbd5eecfc9bcca84eb341 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 8 Jun 2020 14:25:18 +0800 Subject: [PATCH 34/72] [td-535] --- src/client/src/tscAsync.c | 47 +++++++++++++++++++--------------- src/client/src/tscServer.c | 52 ++++++++------------------------------ 2 files changed, 38 insertions(+), 61 deletions(-) diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index ebcdddffde..6d591f3615 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -443,15 +443,17 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { } if (pSql->pStream == NULL) { - // check if it is a sub-query of super table query first, if true, enter another routine SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); - - if ((pQueryInfo->type & TSDB_QUERY_TYPE_STABLE_SUBQUERY) == TSDB_QUERY_TYPE_STABLE_SUBQUERY) { + + // check if it is a sub-query of super table query first, if true, enter another routine + if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_STABLE_SUBQUERY)) { + tscTrace("%p update table meta in local cache, continue to process sql and send corresponding subquery", pSql); + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); if (pTableMetaInfo->pTableMeta == NULL){ code = tscGetTableMeta(pSql, pTableMetaInfo); assert(code == TSDB_CODE_SUCCESS); - } + } assert((tscGetNumOfTags(pTableMetaInfo->pTableMeta) != 0) && pTableMetaInfo->vgroupIndex >= 0 && pSql->param != NULL); @@ -461,32 +463,37 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { assert(pParObj->signature == pParObj && trs->subqueryIndex == pTableMetaInfo->vgroupIndex && tscGetNumOfTags(pTableMetaInfo->pTableMeta) != 0); - tscTrace("%p get metricMeta during super table query successfully", pSql); - - code = tscGetSTableVgroupInfo(pSql, 0); - pRes->code = code; - - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; - } else { // normal async query continues + // NOTE: the vgroupInfo for the queried super table must be existed here. + assert(pTableMetaInfo->vgroupList != NULL); + if ((code = tscProcessSql(pSql)) == TSDB_CODE_SUCCESS) { + return; + } + } else { // continue to process normal async query if (pCmd->parseFinished) { - tscTrace("%p re-send data to vnode in table Meta callback since sql parsed completed", pSql); - + tscTrace("%p update table meta in local cache, continue to process sql and send corresponding query", pSql); + STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); code = tscGetTableMeta(pSql, pTableMetaInfo); assert(code == TSDB_CODE_SUCCESS); - - if (pTableMetaInfo->pTableMeta) { - // todo update the submit message according to the new table meta - // 1. table uid, 2. ip address - code = tscSendMsgToServer(pSql); - if (code == TSDB_CODE_SUCCESS) return; + + // if failed to process sql, go to error handler + if ((code = tscProcessSql(pSql)) == TSDB_CODE_SUCCESS) { + return; } +// // todo update the submit message according to the new table meta +// // 1. table uid, 2. ip address +// code = tscSendMsgToServer(pSql); +// if (code == TSDB_CODE_SUCCESS) return; +// } } else { + tscTrace("%p continue parse sql after get table meta", pSql); + code = tsParseSql(pSql, false); - if ((pQueryInfo->type & TSDB_QUERY_TYPE_STMT_INSERT) == TSDB_QUERY_TYPE_STMT_INSERT) { + if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_STMT_INSERT)) { STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); code = tscGetTableMeta(pSql, pTableMetaInfo); assert(code == TSDB_CODE_SUCCESS && pTableMetaInfo->pTableMeta != NULL); + (*pSql->fp)(pSql->param, pSql, code); return; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 39b9350284..d0f6d6f171 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -430,7 +430,7 @@ void tscKillSTableQuery(SSqlObj *pSql) { /* * here, we cannot set the command = TSDB_SQL_KILL_QUERY. Otherwise, it may cause - * sub-queries not correctly released and master sql object of metric query reaches an abnormal state. + * sub-queries not correctly released and master sql object of super table query reaches an abnormal state. */ pSql->pSubs[i]->res.code = TSDB_CODE_QUERY_CANCELLED; //taosStopRpcConn(pSql->pSubs[i]->thandle); @@ -564,7 +564,7 @@ static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char pQueryMsg->numOfTables = htonl(1); // set the number of tables pMsg += sizeof(STableIdInfo); - } else { + } else { // it is a subquery of the super table query, this IP info is acquired from vgroupInfo int32_t index = pTableMetaInfo->vgroupIndex; int32_t numOfVgroups = taosArrayGetSize(pTableMetaInfo->pVgroupTables); assert(index >= 0 && index < numOfVgroups); @@ -1821,7 +1821,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { return TSDB_CODE_CLI_OUT_OF_MEMORY; } - tscTrace("%p recv table meta: %"PRId64 ", tid:%d, name:%s", pSql, pTableMeta->uid, pTableMeta->sid, pTableMetaInfo->name); + tscTrace("%p recv table meta, uid:%"PRId64 ", tid:%d, name:%s", pSql, pTableMeta->uid, pTableMeta->sid, pTableMetaInfo->name); free(pTableMeta); return TSDB_CODE_SUCCESS; @@ -2388,56 +2388,26 @@ int tscGetMeterMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool create return tscGetTableMeta(pSql, pTableMetaInfo); } -/* - * in handling the renew metermeta problem during insertion, - * - * If the meter is created on demand during insertion, the routine usually waits for a short - * period to re-issue the getMeterMeta msg, in which makes a greater change that vnode has - * successfully created the corresponding table. - */ -static void tscWaitingForCreateTable(SSqlCmd *pCmd) { - if (pCmd->command == TSDB_SQL_INSERT) { - taosMsleep(50); // todo: global config - } -} - /** - * in renew metermeta, do not retrieve metadata in cache. + * retrieve table meta from mnode, and update the local table meta cache. * @param pSql sql object - * @param tableId meter id + * @param tableId table full name * @return status code */ int tscRenewMeterMeta(SSqlObj *pSql, char *tableId) { - int code = 0; - - // handle table meta renew process SSqlCmd *pCmd = &pSql->cmd; SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - /* - * 1. only update the metermeta in force model metricmeta is not updated - * 2. if get metermeta failed, still get the metermeta - */ - if (pTableMetaInfo->pTableMeta == NULL || !tscQueryOnSTable(pCmd)) { - STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; - if (pTableMetaInfo->pTableMeta) { - tscTrace("%p update table meta, old: numOfTags:%d, numOfCols:%d, uid:%" PRId64 ", addr:%p", pSql, - tscGetNumOfTags(pTableMeta), tscGetNumOfColumns(pTableMeta), pTableMeta->uid, pTableMeta); - } - - tscWaitingForCreateTable(pCmd); - taosCacheRelease(tscCacheHandle, (void **)&(pTableMetaInfo->pTableMeta), true); - - code = getTableMetaFromMgmt(pSql, pTableMetaInfo); // todo ?? - } else { - tscTrace("%p metric query not update metric meta, numOfTags:%d, numOfCols:%d, uid:%" PRId64 ", addr:%p", pSql, - tscGetNumOfTags(pTableMetaInfo->pTableMeta), pCmd->numOfCols, pTableMetaInfo->pTableMeta->uid, - pTableMetaInfo->pTableMeta); + STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; + if (pTableMetaInfo->pTableMeta) { + tscTrace("%p update table meta, old meta numOfTags:%d, numOfCols:%d, uid:%" PRId64 ", addr:%p", pSql, + tscGetNumOfTags(pTableMeta), tscGetNumOfColumns(pTableMeta), pTableMeta->uid, pTableMeta); } - return code; + taosCacheRelease(tscCacheHandle, (void **)&(pTableMetaInfo->pTableMeta), true); + return getTableMetaFromMgmt(pSql, pTableMetaInfo); } static bool allVgroupInfoRetrieved(SSqlCmd* pCmd, int32_t clauseIndex) { From 7402afb6080ef7b1b9769ab9eb6f5658afdbd7d5 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 14:42:51 +0800 Subject: [PATCH 35/72] [TD-549] scripts change --- tests/script/jenkins/basic.txt | 75 ------------------- tests/script/unique/vnode/many.sim | 10 +-- tests/script/unique/vnode/replica2_basic2.sim | 64 ++++++++-------- tests/script/unique/vnode/replica2_repeat.sim | 10 +-- 4 files changed, 40 insertions(+), 119 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index c6f3082a88..191e3212b6 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -307,78 +307,3 @@ cd ../../../debug; make ./test.sh -f unique/vnode/replica3_basic.sim ./test.sh -f unique/vnode/replica3_repeat.sim ./test.sh -f unique/vnode/replica3_vgroup.sim - -./test.sh -f unique/account/account_create.sim -./test.sh -f unique/account/account_delete.sim -./test.sh -f unique/account/account_len.sim -./test.sh -f unique/account/authority.sim -./test.sh -f unique/account/basic.sim -./test.sh -f unique/account/paras.sim -./test.sh -f unique/account/pass_alter.sim -./test.sh -f unique/account/pass_len.sim -./test.sh -f unique/account/usage.sim -./test.sh -f unique/account/user_create.sim -./test.sh -f unique/account/user_len.sim - -./test.sh -f unique/big/balance.sim -./test.sh -f unique/big/maxvnodes.sim -./test.sh -f unique/big/tcp.sim - -./test.sh -f unique/cluster/balance1.sim -./test.sh -f unique/cluster/balance2.sim -./test.sh -f unique/cluster/balance3.sim -./test.sh -f unique/cluster/cache.sim - -./test.sh -f unique/column/replica3.sim - -./test.sh -f unique/db/commit.sim -./test.sh -f unique/db/delete.sim -./test.sh -f unique/db/delete_part.sim -./test.sh -f unique/db/replica_add12.sim -./test.sh -f unique/db/replica_add13.sim -./test.sh -f unique/db/replica_add23.sim -./test.sh -f unique/db/replica_reduce21.sim -./test.sh -f unique/db/replica_reduce32.sim -./test.sh -f unique/db/replica_reduce31.sim -./test.sh -f unique/db/replica_part.sim - -./test.sh -f unique/dnode/balance1.sim -./test.sh -f unique/dnode/balance2.sim -./test.sh -f unique/dnode/balance3.sim -./test.sh -f unique/dnode/balancex.sim -./test.sh -f unique/dnode/offline1.sim -./test.sh -f unique/dnode/offline2.sim -./test.sh -f unique/dnode/remove1.sim -./test.sh -f unique/dnode/remove2.sim -./test.sh -f unique/dnode/vnode_clean.sim - -./test.sh -f unique/http/admin.sim -./test.sh -f unique/http/opentsdb.sim - -./test.sh -f unique/import/replica2.sim -./test.sh -f unique/import/replica3.sim - -./test.sh -f unique/stable/balance_replica1.sim -./test.sh -f unique/stable/dnode2_stop.sim -./test.sh -f unique/stable/dnode2.sim -./test.sh -f unique/stable/dnode3.sim -./test.sh -f unique/stable/replica2_dnode4.sim -./test.sh -f unique/stable/replica2_vnode3.sim -./test.sh -f unique/stable/replica3_dnode6.sim -./test.sh -f unique/stable/replica3_vnode3.sim - -./test.sh -f unique/mnode/mgmt22.sim -./test.sh -f unique/mnode/mgmt23.sim -./test.sh -f unique/mnode/mgmt24.sim -./test.sh -f unique/mnode/mgmt25.sim -./test.sh -f unique/mnode/mgmt26.sim -./test.sh -f unique/mnode/mgmt33.sim -./test.sh -f unique/mnode/mgmt34.sim -./test.sh -f unique/mnode/mgmtr2.sim - -./test.sh -f unique/vnode/many.sim -./test.sh -f unique/vnode/replica2_basic2.sim -./test.sh -f unique/vnode/replica2_repeat.sim -./test.sh -f unique/vnode/replica3_basic.sim -./test.sh -f unique/vnode/replica3_repeat.sim -./test.sh -f unique/vnode/replica3_vgroup.sim diff --git a/tests/script/unique/vnode/many.sim b/tests/script/unique/vnode/many.sim index bd07d5f171..2ac203a9b7 100644 --- a/tests/script/unique/vnode/many.sim +++ b/tests/script/unique/vnode/many.sim @@ -57,23 +57,21 @@ run_back unique/vnode/back_insert_many.sim sleep 5000 print ======== step3 -system sh/exec.sh -n dnode2 -s stop -sleep 5000 $x = 0 loop: print ======== step4 -system sh/exec.sh -n dnode2 -s start -sleep 5000 system sh/exec.sh -n dnode3 -s stop sleep 5000 +system sh/exec.sh -n dnode3 -s start +sleep 5000 print ======== step5 -system sh/exec.sh -n dnode3 -s start -sleep 5000 system sh/exec.sh -n dnode2 -s stop sleep 5000 +system sh/exec.sh -n dnode2 -s start +sleep 5000 print ======== step6 sql select count(*) from db1.tb1 diff --git a/tests/script/unique/vnode/replica2_basic2.sim b/tests/script/unique/vnode/replica2_basic2.sim index 5bd35159d5..2aa470843a 100644 --- a/tests/script/unique/vnode/replica2_basic2.sim +++ b/tests/script/unique/vnode/replica2_basic2.sim @@ -138,25 +138,25 @@ sleep 5000 #sql insert into d3.t3 values(now, 3) #sql insert into d4.t4 values(now, 3) -sql select * from d1.t1 -if $rows != 2 then - return -1 -endi +#sql select * from d1.t1 +#if $rows != 2 then +# return -1 +#endi -sql select * from d2.t2 -if $rows != 2 then - return -1 -endi +#sql select * from d2.t2 +#if $rows != 2 then +# return -1 +#endi -sql select * from d3.t3 -if $rows != 2 then - return -1 -endi +#sql select * from d3.t3 +#if $rows != 2 then +# return -1 +#endi -sql select * from d4.t4 -if $rows != 2 then - return -1 -endi +#sql select * from d4.t4 +#if $rows != 2 then +# return -1 +#endi print ========= step4 system sh/exec.sh -n dnode2 -s start @@ -169,25 +169,25 @@ sleep 5000 #sql insert into d3.t3 values(now, 4) #sql insert into d4.t4 values(now, 4) -sql select * from d1.t1 -if $rows != 2 then - return -1 -endi +#sql select * from d1.t1 +#if $rows != 2 then +# return -1 +#endi -sql select * from d2.t2 -if $rows != 2 then - return -1 -endi +#sql select * from d2.t2 +#if $rows != 2 then +# return -1 +#endi -sql select * from d3.t3 -if $rows != 2 then - return -1 -endi +#sql select * from d3.t3 +#if $rows != 2 then +# return -1 +#endi -sql select * from d4.t4 -if $rows != 2 then - return -1 -endi +#sql select * from d4.t4 +#if $rows != 2 then +# return -1 +#endi print ========= step5 system sh/exec.sh -n dnode3 -s start diff --git a/tests/script/unique/vnode/replica2_repeat.sim b/tests/script/unique/vnode/replica2_repeat.sim index 73e71c149e..44a86763ed 100644 --- a/tests/script/unique/vnode/replica2_repeat.sim +++ b/tests/script/unique/vnode/replica2_repeat.sim @@ -37,22 +37,20 @@ run_back unique/vnode/back_insert.sim sleep 3000 print ======== step3 -system sh/exec.sh -n dnode2 -s stop -sleep 5000 $x = 0 loop: print ======== step4 -system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode2 -s stop sleep 5000 -system sh/exec.sh -n dnode3 -s stop +system sh/exec.sh -n dnode2 -s start sleep 5000 print ======== step5 -system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode3 -s stop sleep 5000 -system sh/exec.sh -n dnode2 -s stop +system sh/exec.sh -n dnode3 -s start sleep 5000 print ======== step6 From a3b1dbb8458058828cb5f7ee13c51de889af332b Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 8 Jun 2020 14:50:47 +0800 Subject: [PATCH 36/72] [td-225] fix bugs in group by normal columns --- src/client/inc/tsclient.h | 37 +++++----- src/client/src/tscFunctionImpl.c | 4 +- src/client/src/tscParseInsert.c | 8 +-- src/client/src/tscPrepare.c | 4 +- src/client/src/tscSQLParser.c | 2 + src/client/src/tscSecondaryMerge.c | 4 +- src/client/src/tscStream.c | 5 +- src/query/inc/qsqlparser.h | 2 +- src/query/src/qExecutor.c | 95 ++----------------------- src/query/src/qparserImpl.c | 20 +++--- tests/script/general/parser/groupby.sim | 18 ++++- 11 files changed, 63 insertions(+), 136 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index d7f1881209..4e42bcfdf7 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -191,14 +191,14 @@ typedef struct SDataBlockList { // todo remove } SDataBlockList; typedef struct SQueryInfo { - int16_t command; // the command may be different for each subclause, so keep it seperately. - uint32_t type; // query/insert/import type - char slidingTimeUnit; - - STimeWindow window; - int64_t intervalTime; // aggregation time interval - int64_t slidingTime; // sliding window in mseconds - SSqlGroupbyExpr groupbyExpr; // group by tags info + int16_t command; // the command may be different for each subclause, so keep it seperately. + uint32_t type; // query/insert/import type + char slidingTimeUnit; + + STimeWindow window; + int64_t intervalTime; // aggregation time interval + int64_t slidingTime; // sliding window in mseconds + SSqlGroupbyExpr groupbyExpr; // group by tags info SArray * colList; // SArray SFieldInfo fieldsInfo; @@ -207,11 +207,11 @@ typedef struct SQueryInfo { SLimitVal slimit; STagCond tagCond; SOrderVal order; - int16_t fillType; // interpolate type + int16_t fillType; // final result fill type int16_t numOfTables; STableMetaInfo **pTableMetaInfo; struct STSBuf * tsBuf; - int64_t * fillVal; // default value for interpolation + int64_t * fillVal; // default value for fill char * msg; // pointer to the pCmd->payload to keep error message temporarily int64_t clauseLimit; // limit for current sub clause @@ -222,15 +222,15 @@ typedef struct SQueryInfo { typedef struct { int command; uint8_t msgType; - - bool autoCreated; // if the table is missing, on-the-fly create it. during getmeterMeta - int8_t dataSourceType; // load data from file or not + bool autoCreated; // if the table is missing, on-the-fly create it. during getmeterMeta + int8_t dataSourceType; // load data from file or not union { int32_t count; int32_t numOfTablesInSubmit; }; + int32_t insertType; int32_t clauseIndex; // index of multiple subclause query int8_t parseFinished; short numOfCols; @@ -239,14 +239,12 @@ typedef struct { int32_t payloadLen; SQueryInfo **pQueryInfo; int32_t numOfClause; + char * curSql; // current sql, resume position of sql after parsing paused + void * pTableList; // referred table involved in sql + int32_t batchSize; // for parameter ('?') binding and batch processing + int32_t numOfParams; SDataBlockList *pDataBlocks; // submit data blocks after parsing sql - char * curSql; // current sql, resume position of sql after parsing paused - void * pTableList; // referred table involved in sql - - // for parameter ('?') binding and batch processing - int32_t batchSize; - int32_t numOfParams; } SSqlCmd; typedef struct SResRec { @@ -316,7 +314,6 @@ typedef struct SSqlObj { SRpcIpSet ipList; char freed : 4; char listed : 4; - uint32_t insertType; tsem_t rspSem; SSqlCmd cmd; SSqlRes res; diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index 1cb9ef0d10..b05e82b39a 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -1293,7 +1293,7 @@ static void max_function_f(SQLFunctionCtx *pCtx, int32_t index) { minMax_function_f(pCtx, index, 0); SResultInfo *pResInfo = GET_RES_INFO(pCtx); - if (pResInfo->hasResult == DATA_SET_FLAG) { + if (pResInfo->hasResult == DATA_SET_FLAG && pResInfo->superTableQ) { char *flag = pCtx->aOutputBuf + pCtx->inputBytes; *flag = DATA_SET_FLAG; } @@ -1309,7 +1309,7 @@ static void min_function_f(SQLFunctionCtx *pCtx, int32_t index) { minMax_function_f(pCtx, index, 1); SResultInfo *pResInfo = GET_RES_INFO(pCtx); - if (pResInfo->hasResult == DATA_SET_FLAG) { + if (pResInfo->hasResult == DATA_SET_FLAG && pResInfo->superTableQ) { char *flag = pCtx->aOutputBuf + pCtx->inputBytes; *flag = DATA_SET_FLAG; } diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index e058483781..cbc83c6e75 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1314,7 +1314,7 @@ int tsParseInsertSql(SSqlObj *pSql) { tscGetQueryInfoDetailSafely(pCmd, pCmd->clauseIndex, &pQueryInfo); TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_INSERT); - TSDB_QUERY_SET_TYPE(pQueryInfo->type, pSql->insertType); + TSDB_QUERY_SET_TYPE(pQueryInfo->type, pCmd->insertType); sToken = tStrGetToken(pSql->sqlstr, &index, false, 0, NULL); if (sToken.type != TK_INTO) { @@ -1342,7 +1342,7 @@ int tsParseSql(SSqlObj *pSql, bool initialParse) { * Set the fp before parse the sql string, in case of getTableMeta failed, in which * the error handle callback function can rightfully restore the user-defined callback function (fp). */ - if (initialParse && (pSql->insertType != TSDB_QUERY_TYPE_STMT_INSERT)) { + if (initialParse && (pSql->cmd.insertType != TSDB_QUERY_TYPE_STMT_INSERT)) { pSql->fetchFp = pSql->fp; pSql->fp = (void(*)())tscHandleMultivnodeInsert; } @@ -1354,9 +1354,7 @@ int tsParseSql(SSqlObj *pSql, bool initialParse) { return ret; } - SSqlInfo SQLInfo = {0}; - tSQLParse(&SQLInfo, pSql->sqlstr); - + SSqlInfo SQLInfo = qSQLParse(pSql->sqlstr); ret = tscToSQLCmd(pSql, &SQLInfo); SQLInfoDestroy(&SQLInfo); } diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 12d2980038..3c9e0cdd3b 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -451,7 +451,7 @@ static int insertStmtExecute(STscStmt* stmt) { pRes->qhandle = 0; - pSql->insertType = 0; + pSql->cmd.insertType = 0; pSql->fetchFp = waitForQueryRsp; pSql->fp = (void(*)())tscHandleMultivnodeInsert; @@ -515,7 +515,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { SSqlRes *pRes = &pSql->res; pSql->param = (void*) pSql; pSql->fp = waitForQueryRsp; - pSql->insertType = TSDB_QUERY_TYPE_STMT_INSERT; + pSql->cmd.insertType = TSDB_QUERY_TYPE_STMT_INSERT; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { tscError("%p failed to malloc payload buffer", pSql); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 15706e3235..8375552b93 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -517,6 +517,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } } + pSql->cmd.parseFinished = true; return TSDB_CODE_SUCCESS; // do not build query message here } @@ -542,6 +543,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "not support sql expression"); } + pSql->cmd.parseFinished = true; return tscBuildMsg[pCmd->command](pSql, pInfo); } diff --git a/src/client/src/tscSecondaryMerge.c b/src/client/src/tscSecondaryMerge.c index 5114f97f8f..95d559b4fa 100644 --- a/src/client/src/tscSecondaryMerge.c +++ b/src/client/src/tscSecondaryMerge.c @@ -1185,7 +1185,9 @@ bool needToMerge(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer, tFilePage int32_t ret = 0; // merge all result by default int16_t functionId = pLocalReducer->pCtx[0].functionId; - if (functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_ARITHM) { // column projection query + + // todo opt performance + if ((/*functionId == TSDB_FUNC_PRJ || */functionId == TSDB_FUNC_ARITHM) || (tscIsProjectionQueryOnSTable(pQueryInfo, 0))) { // column projection query ret = 1; // disable merge procedure } else { tOrderDescriptor *pDesc = pLocalReducer->pDesc; diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 4e92e9dd70..b8b2a0f8eb 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -505,10 +505,9 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p tsem_init(&pSql->rspSem, 0, 0); - SSqlInfo SQLInfo = {0}; - tSQLParse(&SQLInfo, pSql->sqlstr); - + SSqlInfo SQLInfo = qSQLParse(pSql->sqlstr); tscResetSqlCmdObj(&pSql->cmd); + ret = tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE); if (TSDB_CODE_SUCCESS != ret) { setErrorInfo(pSql, ret, NULL); diff --git a/src/query/inc/qsqlparser.h b/src/query/inc/qsqlparser.h index d2fad227e6..704f3e7418 100644 --- a/src/query/inc/qsqlparser.h +++ b/src/query/inc/qsqlparser.h @@ -322,7 +322,7 @@ enum { #define NORMAL_ARITHMETIC 1 #define AGG_ARIGHTMEIC 2 -int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pSql); +SSqlInfo qSQLParse(const char *str); #ifdef __cplusplus } diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 5dff47121b..0ff9a7e480 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -373,7 +373,6 @@ static SWindowResult *doSetTimeWindowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SWin SPosInfo pos = {-1, -1}; createQueryResultInfo(pQuery, &pWindowResInfo->pResult[i], pRuntimeEnv->stableQuery, &pos); } - pWindowResInfo->capacity = newCap; } @@ -1566,11 +1565,6 @@ static bool isFirstLastRowQuery(SQuery *pQuery) { return false; } -static UNUSED_FUNC bool notHasQueryTimeRange(SQuery *pQuery) { - return (pQuery->window.skey == 0 && pQuery->window.ekey == INT64_MAX && QUERY_IS_ASC_QUERY(pQuery)) || - (pQuery->window.skey == INT64_MAX && pQuery->window.ekey == 0 && (!QUERY_IS_ASC_QUERY(pQuery))); -} - static bool needReverseScan(SQuery *pQuery) { for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { int32_t functionId = pQuery->pSelectExpr[i].base.functionId; @@ -1768,61 +1762,6 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool stableQuery) { } } -static UNUSED_FUNC void doSetInterpVal(SQLFunctionCtx *pCtx, TSKEY ts, int16_t type, int32_t index, char *data) { - assert(pCtx->param[index].pz == NULL); - - int32_t len = 0; - size_t t = 0; - - if (type == TSDB_DATA_TYPE_BINARY) { - t = strlen(data); - - len = t + 1 + TSDB_KEYSIZE; - pCtx->param[index].pz = calloc(1, len); - } else if (type == TSDB_DATA_TYPE_NCHAR) { - t = wcslen((const wchar_t *)data); - - len = (t + 1) * TSDB_NCHAR_SIZE + TSDB_KEYSIZE; - pCtx->param[index].pz = calloc(1, len); - } else { - len = TSDB_KEYSIZE * 2; - pCtx->param[index].pz = malloc(len); - } - - pCtx->param[index].nType = TSDB_DATA_TYPE_BINARY; - - char *z = pCtx->param[index].pz; - *(TSKEY *)z = ts; - z += TSDB_KEYSIZE; - - switch (type) { - case TSDB_DATA_TYPE_FLOAT: - *(double *)z = GET_FLOAT_VAL(data); - break; - case TSDB_DATA_TYPE_DOUBLE: - *(double *)z = GET_DOUBLE_VAL(data); - break; - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_BOOL: - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_TIMESTAMP: - *(int64_t *)z = GET_INT64_VAL(data); - break; - case TSDB_DATA_TYPE_BINARY: - strncpy(z, data, t); - break; - case TSDB_DATA_TYPE_NCHAR: { - wcsncpy((wchar_t *)z, (const wchar_t *)data, t); - } break; - default: - assert(0); - } - - pCtx->param[index].nLen = len; -} - static int32_t getInitialPageNum(SQInfo *pQInfo) { SQuery *pQuery = pQInfo->runtimeEnv.pQuery; int32_t INITIAL_RESULT_ROWS_VALUE = 16; @@ -4071,45 +4010,19 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, int32_t vgId, bool initWindowResInfo(&pRuntimeEnv->windowResInfo, pRuntimeEnv, rows, 4096, type); } - setQueryStatus(pQuery, QUERY_NOT_COMPLETED); - - /* - * in case of last_row query without query range, we set the query timestamp to be - * STable->lastKey. Otherwise, keep the initial query time range unchanged. - */ -// if (isFirstLastRowQuery(pQuery)) { -// if (!normalizeUnBoundLastRowQuery(pQInfo, &interpInfo)) { -// sem_post(&pQInfo->dataReady); -// pointInterpSupporterDestroy(&interpInfo); -// return TSDB_CODE_SUCCESS; -// } -// } - if (pQuery->fillType != TSDB_FILL_NONE && !isPointInterpoQuery(pQuery)) { SFillColInfo* pColInfo = taosCreateFillColInfo(pQuery); pRuntimeEnv->pFillInfo = taosInitFillInfo(pQuery->order.order, 0, 0, pQuery->rec.capacity, pQuery->numOfOutput, pQuery->slidingTime, pQuery->fillType, pColInfo); } - + + // todo refactor pRuntimeEnv->topBotQuery = isTopBottomQuery(pQuery); + setQueryStatus(pQuery, QUERY_NOT_COMPLETED); + return TSDB_CODE_SUCCESS; } -static UNUSED_FUNC bool isGroupbyEachTable(SSqlGroupbyExpr *pGroupbyExpr, STableGroupInfo *pSidset) { - if (pGroupbyExpr == NULL || pGroupbyExpr->numOfGroupCols == 0) { - return false; - } - - for (int32_t i = 0; i < pGroupbyExpr->numOfGroupCols; ++i) { - SColIndex* pColIndex = taosArrayGet(pGroupbyExpr->columnInfo, i); - if (pColIndex->flag == TSDB_COL_TAG) { - return true; - } - } - - return false; -} - static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) { SQuery *pQuery = pRuntimeEnv->pQuery; diff --git a/src/query/src/qparserImpl.c b/src/query/src/qparserImpl.c index 9589be86e4..4a3cb8adda 100644 --- a/src/query/src/qparserImpl.c +++ b/src/query/src/qparserImpl.c @@ -26,16 +26,18 @@ #include "tstrbuild.h" #include "queryLog.h" -int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) { +SSqlInfo qSQLParse(const char *pStr) { void *pParser = ParseAlloc(malloc); - pSQLInfo->valid = true; + + SSqlInfo sqlInfo = {0}; + sqlInfo.valid = true; int32_t i = 0; while (1) { SSQLToken t0 = {0}; if (pStr[i] == 0) { - Parse(pParser, 0, t0, pSQLInfo); + Parse(pParser, 0, t0, &sqlInfo); goto abort_parse; } @@ -49,19 +51,19 @@ int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) { break; } case TK_SEMI: { - Parse(pParser, 0, t0, pSQLInfo); + Parse(pParser, 0, t0, &sqlInfo); goto abort_parse; } case TK_QUESTION: case TK_ILLEGAL: { - snprintf(pSQLInfo->pzErrMsg, tListLen(pSQLInfo->pzErrMsg), "unrecognized token: \"%s\"", t0.z); - pSQLInfo->valid = false; + snprintf(sqlInfo.pzErrMsg, tListLen(sqlInfo.pzErrMsg), "unrecognized token: \"%s\"", t0.z); + sqlInfo.valid = false; goto abort_parse; } default: - Parse(pParser, t0.type, t0, pSQLInfo); - if (pSQLInfo->valid == false) { + Parse(pParser, t0.type, t0, &sqlInfo); + if (sqlInfo.valid == false) { goto abort_parse; } } @@ -69,7 +71,7 @@ int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) { abort_parse: ParseFree(pParser, free); - return 0; + return sqlInfo; } tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SSQLToken *pToken) { diff --git a/tests/script/general/parser/groupby.sim b/tests/script/general/parser/groupby.sim index 9788e4d484..513b3cbbbe 100644 --- a/tests/script/general/parser/groupby.sim +++ b/tests/script/general/parser/groupby.sim @@ -180,7 +180,7 @@ if $data03 != 0 then endi print $data04 -if $data04 != 0.0000 then +if $data04 != 0.00000 then return -1 endi @@ -201,7 +201,8 @@ if $data13 != 1 then return -1 endi -if $data14 != 1.0000 then +if $data14 != 1.00000 then + print expect 1.00000, actual:$data14 return -1 endi @@ -345,6 +346,19 @@ if $data94 != 9 then return -1 endi +sql select c1,sum(c1),avg(c1),count(*) from group_mt0 where c1<5 group by c1; +if $row != 5 then + return -1 +endi + +if $data00 != 0 then + return -1 +endi + +if $data01 != 800 then + return -1 +endi + sql select first(c1), last(ts), first(ts), last(c1),sum(c1),avg(c1),count(*) from group_mt0 where c1<20 group by tbname,c1; if $row != 160 then return -1 From 0fc652a4b6abc07fc3effc5bf6e3a4b84bebf4b7 Mon Sep 17 00:00:00 2001 From: Hui Li Date: Mon, 8 Jun 2020 15:06:24 +0800 Subject: [PATCH 37/72] [modify str len for version] --- packaging/release.sh | 12 ++++++------ src/util/src/version.c | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packaging/release.sh b/packaging/release.sh index a4562d21d2..7a585431a2 100755 --- a/packaging/release.sh +++ b/packaging/release.sh @@ -162,18 +162,18 @@ done # output the version info to the buildinfo file. build_time=$(date +"%F %R") -echo "char version[64] = \"${version}\";" > ${versioninfo} -echo "char compatible_version[64] = \"${compatible_version}\";" >> ${versioninfo} -echo "char gitinfo[128] = \"$(git rev-parse --verify HEAD)\";" >> ${versioninfo} +echo "char version[12] = \"${version}\";" > ${versioninfo} +echo "char compatible_version[12] = \"${compatible_version}\";" >> ${versioninfo} +echo "char gitinfo[48] = \"$(git rev-parse --verify HEAD)\";" >> ${versioninfo} if [ "$verMode" != "cluster" ]; then - echo "char gitinfoOfInternal[128] = \"\";" >> ${versioninfo} + echo "char gitinfoOfInternal[48] = \"\";" >> ${versioninfo} else enterprise_dir="${top_dir}/../enterprise" cd ${enterprise_dir} - echo "char gitinfoOfInternal[128] = \"$(git rev-parse --verify HEAD)\";" >> ${versioninfo} + echo "char gitinfoOfInternal[48] = \"$(git rev-parse --verify HEAD)\";" >> ${versioninfo} cd ${curr_dir} fi -echo "char buildinfo[512] = \"Built by ${USER} at ${build_time}\";" >> ${versioninfo} +echo "char buildinfo[64] = \"Built by ${USER} at ${build_time}\";" >> ${versioninfo} echo "" >> ${versioninfo} tmp_version=$(echo $version | tr -s "." "_") if [ "$verMode" == "cluster" ]; then diff --git a/src/util/src/version.c b/src/util/src/version.c index b6e10d8b7e..753cf71bc8 100644 --- a/src/util/src/version.c +++ b/src/util/src/version.c @@ -1,7 +1,7 @@ -char version[64] = "2.0.0.0"; -char compatible_version[64] = "2.0.0.0"; -char gitinfo[128] = "3264067e97300c84caa61ac909d548c9ca56de6b"; -char gitinfoOfInternal[128] = "da88f4a2474737d1f9c76adcf0ff7fd0975e7342"; -char buildinfo[512] = "Built by root at 2020-04-01 14:38"; +char version[TSDB_VERSION_LEN] = "2.0.0.0"; +char compatible_version[TSDB_VERSION_LEN] = "2.0.0.0"; +char gitinfo[48] = "3264067e97300c84caa61ac909d548c9ca56de6b"; +char gitinfoOfInternal[48] = "da88f4a2474737d1f9c76adcf0ff7fd0975e7342"; +char buildinfo[64] = "Built by root at 2020-04-01 14:38"; void libtaos_1_6_5_4_Linux_x64() {}; From 0177f0df71f3f9626bf8c22e8d183ad55e147192 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Mon, 8 Jun 2020 15:09:30 +0800 Subject: [PATCH 38/72] add slguan@taosdata.com to coverity scan notification --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b0911716c5..a356dbab10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -111,7 +111,7 @@ matrix: description: TDengine # Where email notification of build analysis results will be sent - notification_email: sdsang@taosdata.com + notification_email: sdsang@taosdata.com, slguan@taosdata.com # Commands to prepare for build_command # ** likely specific to your build ** From 370c67361c20d63c8913bb9afa00efc585bea3c0 Mon Sep 17 00:00:00 2001 From: Hui Li Date: Mon, 8 Jun 2020 15:12:50 +0800 Subject: [PATCH 39/72] [modify string len for version] --- src/util/src/version.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/src/version.c b/src/util/src/version.c index 753cf71bc8..0d5e08ce75 100644 --- a/src/util/src/version.c +++ b/src/util/src/version.c @@ -1,5 +1,5 @@ -char version[TSDB_VERSION_LEN] = "2.0.0.0"; -char compatible_version[TSDB_VERSION_LEN] = "2.0.0.0"; +char version[12] = "2.0.0.0"; +char compatible_version[12] = "2.0.0.0"; char gitinfo[48] = "3264067e97300c84caa61ac909d548c9ca56de6b"; char gitinfoOfInternal[48] = "da88f4a2474737d1f9c76adcf0ff7fd0975e7342"; char buildinfo[64] = "Built by root at 2020-04-01 14:38"; From ddb82b1dfc5bdc47bf5885fe7da66e87213d8e3b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 8 Jun 2020 07:27:35 +0000 Subject: [PATCH 40/72] fix a commit bug --- src/tsdb/src/tsdbRWHelper.c | 21 +++++++++++---------- src/util/src/tkvstore.c | 10 +++++----- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/tsdb/src/tsdbRWHelper.c b/src/tsdb/src/tsdbRWHelper.c index eab70b5913..ed0122b6eb 100644 --- a/src/tsdb/src/tsdbRWHelper.c +++ b/src/tsdb/src/tsdbRWHelper.c @@ -764,8 +764,8 @@ static bool tsdbShouldCreateNewLast(SRWHelper *pHelper) { static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDataCols, int rowsToWrite, SCompBlock *pCompBlock, bool isLast, bool isSuperBlock) { - ASSERT(rowsToWrite > 0 && rowsToWrite <= pDataCols->numOfRows && - rowsToWrite <= pHelper->config.maxRowsPerFileBlock); + ASSERT(rowsToWrite > 0 && rowsToWrite <= pDataCols->numOfRows && rowsToWrite <= pHelper->config.maxRowsPerFileBlock); + ASSERT(isLast ? rowsToWrite < pHelper->config.minRowsPerFileBlock : true); SCompData *pCompData = (SCompData *)(pHelper->pBuffer); int64_t offset = 0; @@ -905,7 +905,8 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa rowsWritten = MIN((defaultRowsToWrite - blockAtIdx(pHelper, blkIdx)->numOfRows), pDataCols->numOfRows); if ((blockAtIdx(pHelper, blkIdx)->numOfSubBlocks < TSDB_MAX_SUBBLOCKS) && - (blockAtIdx(pHelper, blkIdx)->numOfRows + rowsWritten < pHelper->config.minRowsPerFileBlock) && (pHelper->files.nLastF.fd) > 0) { + (blockAtIdx(pHelper, blkIdx)->numOfRows + rowsWritten < pHelper->config.minRowsPerFileBlock) && + (pHelper->files.nLastF.fd) < 0) { if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.lastF), pDataCols, rowsWritten, &compBlock, true, false) < 0) goto _err; if (tsdbAddSubBlock(pHelper, &compBlock, blkIdx, rowsWritten) < 0) goto _err; @@ -936,21 +937,21 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa // Key must overlap with the block ASSERT(keyFirst <= blockAtIdx(pHelper, blkIdx)->keyLast); - TSKEY keyLimit = - (blkIdx == pIdx->numOfBlocks - 1) ? INT64_MAX : pHelper->pCompInfo->blocks[blkIdx + 1].keyFirst - 1; + TSKEY keyLimit = (blkIdx == pIdx->numOfBlocks - 1) ? INT64_MAX : blockAtIdx(pHelper, blkIdx + 1)->keyFirst - 1; // rows1: number of rows must merge in this block int rows1 = tsdbGetRowsInRange(pDataCols, blockAtIdx(pHelper, blkIdx)->keyFirst, blockAtIdx(pHelper, blkIdx)->keyLast); - // rows2: max nuber of rows the block can have more + // rows2: max number of rows the block can have more int rows2 = pHelper->config.maxRowsPerFileBlock - blockAtIdx(pHelper, blkIdx)->numOfRows; // rows3: number of rows between this block and the next block int rows3 = tsdbGetRowsInRange(pDataCols, blockAtIdx(pHelper, blkIdx)->keyFirst, keyLimit); ASSERT(rows3 >= rows1); - if ((rows2 >= rows1) && - (( blockAtIdx(pHelper, blkIdx)->last) || - ((rows1 + blockAtIdx(pHelper, blkIdx)->numOfRows < pHelper->config.minRowsPerFileBlock) && (pHelper->files.nLastF.fd < 0)))) { + if ((rows2 >= rows1) && (blockAtIdx(pHelper, blkIdx)->numOfSubBlocks < TSDB_MAX_SUBBLOCKS) && + ((!blockAtIdx(pHelper, blkIdx)->last) || + ((rows1 + blockAtIdx(pHelper, blkIdx)->numOfRows < pHelper->config.minRowsPerFileBlock) && + (pHelper->files.nLastF.fd < 0)))) { rowsWritten = rows1; bool isLast = false; SFile *pFile = NULL; @@ -964,7 +965,7 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa if (tsdbWriteBlockToFile(pHelper, pFile, pDataCols, rows1, &compBlock, isLast, false) < 0) goto _err; if (tsdbAddSubBlock(pHelper, &compBlock, blkIdx, rowsWritten) < 0) goto _err; - } else { // Load-Merge-Write + } else { // Load-Merge-Write // Load if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, blkIdx), NULL) < 0) goto _err; if (blockAtIdx(pHelper, blkIdx)->last) pHelper->hasOldLastBlock = false; diff --git a/src/util/src/tkvstore.c b/src/util/src/tkvstore.c index 741f953310..148d8235a6 100644 --- a/src/util/src/tkvstore.c +++ b/src/util/src/tkvstore.c @@ -45,7 +45,7 @@ static int tdUpdateKVStoreHeader(int fd, char *fname, SStoreInfo *pInfo); int tdCreateKVStore(char *fname) { char *tname = strdup(fname); - if (tname == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (tname == NULL) return TSDB_CODE_COM_OUT_OF_MEMORY; int fd = open(fname, O_RDWR | O_CREAT, 0755); if (fd < 0) { @@ -247,14 +247,14 @@ static SKVStore *tdNewKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void pStore->appH = appH; pStore->map = taosHashInit(4096, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false); if (pStore->map == NULL) { - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_COM_OUT_OF_MEMORY; goto _err; } return pStore; _err: - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_COM_OUT_OF_MEMORY; tdFreeKVStore(pStore); return NULL; } @@ -273,7 +273,7 @@ static char *tdGetKVStoreSnapshotFname(char *fdata) { size_t size = strlen(fdata) + strlen(TD_KVSTORE_SNAP_SUFFIX) + 1; char * fname = malloc(size); if (fname == NULL) { - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_COM_OUT_OF_MEMORY; return NULL; } sprintf(fname, "%s%s", fdata, TD_KVSTORE_SNAP_SUFFIX); @@ -284,7 +284,7 @@ static char *tdGetKVStoreNewFname(char *fdata) { size_t size = strlen(fdata) + strlen(TD_KVSTORE_NEW_SUFFIX) + 1; char * fname = malloc(size); if (fname == NULL) { - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_COM_OUT_OF_MEMORY; return NULL; } sprintf(fname, "%s%s", fdata, TD_KVSTORE_NEW_SUFFIX); From 2241cf0629fa677ff5513ecdb6794606c66b5bba Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 07:48:18 +0000 Subject: [PATCH 41/72] [TD-543] fix erro in coverity scan --- .gitignore | 3 ++- src/mnode/src/mnodeAcct.c | 15 ++++++++++----- src/mnode/src/mnodeMain.c | 6 +++--- src/mnode/src/mnodeShow.c | 2 +- src/vnode/src/vnodeMain.c | 24 +++++++++++++++++------- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index bb9a70e9b2..77c52b2ee2 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,5 @@ CMakeError.log /out/isenseconfig/WSL-Clang-Debug /out/isenseconfig/WSL-GCC-Debug /test/cfg -/src/.vs +/src/.vs +*.o diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c index 9634d2c645..7ea5188b96 100644 --- a/src/mnode/src/mnodeAcct.c +++ b/src/mnode/src/mnodeAcct.c @@ -27,7 +27,7 @@ void * tsAcctSdb = NULL; static int32_t tsAcctUpdateSize; -static void mnodeCreateRootAcct(); +static int32_t mnodeCreateRootAcct(); static int32_t mnodeAcctActionDestroy(SSdbOper *pOper) { SAcctObj *pAcct = pOper->pObj; @@ -79,7 +79,11 @@ static int32_t mnodeAcctActionDecode(SSdbOper *pOper) { static int32_t mnodeAcctActionRestored() { if (dnodeIsFirstDeploy()) { - mnodeCreateRootAcct(); + int32_t code = mnodeCreateRootAcct(); + if (code != TSDB_CODE_SUCCESS) { + mError("failed to create root account, reason:%s", tstrerror(code)); + return code; + } } acctInit(); @@ -161,9 +165,9 @@ void mnodeDropUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) { mnodeDecAcctRef(pAcct); } -static void mnodeCreateRootAcct() { +static int32_t mnodeCreateRootAcct() { int32_t numOfAccts = sdbGetNumOfRows(tsAcctSdb); - if (numOfAccts != 0) return; + if (numOfAccts != 0) return TSDB_CODE_SUCCESS; SAcctObj *pAcct = malloc(sizeof(SAcctObj)); memset(pAcct, 0, sizeof(SAcctObj)); @@ -190,7 +194,8 @@ static void mnodeCreateRootAcct() { .table = tsAcctSdb, .pObj = pAcct, }; - sdbInsertRow(&oper); + + return sdbInsertRow(&oper); } #ifndef _ACCT diff --git a/src/mnode/src/mnodeMain.c b/src/mnode/src/mnodeMain.c index 298d10993b..57bb1b2bac 100644 --- a/src/mnode/src/mnodeMain.c +++ b/src/mnode/src/mnodeMain.c @@ -88,9 +88,9 @@ int32_t mnodeStartSystem() { } mPrint("starting to initialize mnode ..."); - struct stat dirstat; - if (stat(tsMnodeDir, &dirstat) < 0) { - mkdir(tsMnodeDir, 0755); + if (mkdir(tsMnodeDir, 0755) != 0 && errno != EEXIST) { + mError("failed to init mnode dir:%s, reason:%s", tsMnodeDir, strerror(errno)); + return -1; } dnodeAllocateMnodeWqueue(); diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index 36e7d13a86..30f491ec03 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -316,7 +316,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { } sprintf(pConnectRsp->acctId, "%x", pAcct->acctId); - strcpy(pConnectRsp->serverVersion, version); + memcpy(pConnectRsp->serverVersion, version, TSDB_VERSION_LEN); pConnectRsp->writeAuth = pUser->writeAuth; pConnectRsp->superAuth = pUser->superAuth; diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 256ef3c72b..9ec982b1de 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -75,19 +75,29 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { return TSDB_CODE_SUCCESS; } - mkdir(tsVnodeDir, 0755); - - char rootDir[TSDB_FILENAME_LEN] = {0}; - sprintf(rootDir, "%s/vnode%d", tsVnodeDir, pVnodeCfg->cfg.vgId); - if (mkdir(rootDir, 0755) != 0) { - vPrint("vgId:%d, failed to create vnode, reason:%s dir:%s", pVnodeCfg->cfg.vgId, strerror(errno), rootDir); + if (mkdir(tsVnodeDir, 0755) != 0 && errno != EEXIST) { + vError("vgId:%d, failed to create vnode, reason:%s dir:%s", pVnodeCfg->cfg.vgId, strerror(errno), tsVnodeDir); + if (errno == EACCES) { + return TSDB_CODE_VND_NO_DISK_PERMISSIONS; + } else if (errno == ENOSPC) { + return TSDB_CODE_VND_NO_DISKSPACE; + } else if (errno == ENOENT) { + return TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR; + } else { + return TSDB_CODE_VND_INIT_FAILED; + } + } + + char rootDir[TSDB_FILENAME_LEN] = {0}; + sprintf(rootDir, "%s/vnode%d", tsVnodeDir, pVnodeCfg->cfg.vgId); + if (mkdir(rootDir, 0755) != 0 && errno != EEXIST) { + vError("vgId:%d, failed to create vnode, reason:%s dir:%s", pVnodeCfg->cfg.vgId, strerror(errno), rootDir); if (errno == EACCES) { return TSDB_CODE_VND_NO_DISK_PERMISSIONS; } else if (errno == ENOSPC) { return TSDB_CODE_VND_NO_DISKSPACE; } else if (errno == ENOENT) { return TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR; - } else if (errno == EEXIST) { } else { return TSDB_CODE_VND_INIT_FAILED; } From 47b3df8cdd21f65b879cafeba1c429f6ff13a755 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 8 Jun 2020 15:50:21 +0800 Subject: [PATCH 42/72] [td-225] --- tests/examples/c/demo.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tests/examples/c/demo.c b/tests/examples/c/demo.c index 89dd3527c6..55a19eb5f9 100644 --- a/tests/examples/c/demo.c +++ b/tests/examples/c/demo.c @@ -21,14 +21,16 @@ #include #include #include // TAOS header file -#include - -void taosMsleep(int mseconds); +#include +#include static int32_t doQuery(TAOS* taos, const char* sql) { + struct timeval t1 = {0}; + gettimeofday(&t1, NULL); + TAOS_RES* res = taos_query(taos, sql); if (taos_errno(res) != 0) { - printf("failed to execute query, reason:%s\n", taos_errstr(taos)); + printf("failed to execute query, reason:%s\n", taos_errstr(res)); return -1; } @@ -38,13 +40,19 @@ static int32_t doQuery(TAOS* taos, const char* sql) { int32_t numOfFields = taos_num_fields(res); TAOS_FIELD* pFields = taos_fetch_fields(res); + int32_t i = 0; while((row = taos_fetch_row(res)) != NULL) { taos_print_row(buf, row, pFields, numOfFields); - printf("%s\n", buf); + printf("%d:%s\n", ++i, buf); memset(buf, 0, 512); } taos_free_result(res); + + struct timeval t2 = {0}; + gettimeofday(&t2, NULL); + + printf("elapsed time:%"PRId64 " ms\n", ((t2.tv_sec*1000000 + t2.tv_usec) - (t1.tv_sec*1000000 + t1.tv_usec))/1000); return 0; } @@ -101,14 +109,18 @@ int main(int argc, char *argv[]) { taos = taos_connect(argv[1], "root", "taosdata", NULL, 0); if (taos == NULL) { - printf("failed to connect to server, reason:%s\n", taos_errstr(taos)); + printf("failed to connect to server, reason:%s\n", taos_errstr(NULL)); exit(1); } - printf("success to connect to server\n"); + printf("success to connect to server\n"); +// doQuery(taos, "select c1,count(*) from group_db0.group_mt0 where c1<8 group by c1"); + doQuery(taos, "select * from test.m1"); + // multiThreadTest(1, taos); - doQuery(taos, "use test"); - doQuery(taos, "alter table tm99 set tag a=99"); +// doQuery(taos, "select tbname from test.m1"); +// doQuery(taos, "select max(c1), min(c2), sum(c3), avg(c4), first(c7), last(c8), first(c9) from lm2_db0.lm2_stb0 where ts >= 1537146000000 and ts <= 1543145400000 and tbname in ('lm2_tb0') interval(1s) group by t1"); +// doQuery(taos, "select max(c1), min(c2), sum(c3), avg(c4), first(c7), last(c8), first(c9) from lm2_db0.lm2_stb0 where ts >= 1537146000000 and ts <= 1543145400000 and tbname in ('lm2_tb0', 'lm2_tb1', 'lm2_tb2') interval(1s)"); // for(int32_t i = 0; i < 100000; ++i) { // doQuery(taos, "insert into t1 values(now, 2)"); // } From b70a71196ead45ac29486788be1f766842334b18 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Mon, 8 Jun 2020 16:11:00 +0800 Subject: [PATCH 43/72] add */test/* to exclude path --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a356dbab10..2e268ae04a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -178,7 +178,7 @@ matrix: cd ${TRAVIS_BUILD_DIR} lcov -d . --capture --rc lcov_branch_coverage=1 -o coverage.info - lcov --remove coverage.info '*tests*' '*deps*' -o coverage.info + lcov --remove coverage.info '*/tests/*' '*/test/*' '*/deps/*' -o coverage.info lcov -l --rc lcov_branch_coverage=1 coverage.info || travis_terminate $? gem install coveralls-lcov From 95986f9de295f479fd4c9764051f2733ce25e356 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 08:38:19 +0000 Subject: [PATCH 44/72] [TD_543] fix coverity scan, cid:267715 --- src/kit/taosdemo/taosdemo.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 81426b683a..ca0af96145 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -43,6 +43,7 @@ extern char configDir[]; #define MAX_DATA_SIZE 1024 #define MAX_NUM_DATATYPE 8 #define OPT_ABORT 1 /* –abort */ +#define STRING_LEN 512 /* The options we understand. */ static struct argp_option options[] = { @@ -380,10 +381,11 @@ int main(int argc, char *argv[]) { bool insert_only = arguments.insert_only; char **data_type = arguments.datatype; int count_data_type = 0; - char dataString[512]; + char dataString[STRING_LEN]; bool do_aggreFunc = true; - memset(dataString, 0, 512); + memset(dataString, 0, STRING_LEN); + int len = 0; if (strcasecmp(data_type[0], "BINARY") == 0 || strcasecmp(data_type[0], "BOOL") == 0) { do_aggreFunc = false; @@ -392,8 +394,8 @@ int main(int argc, char *argv[]) { if (strcasecmp(data_type[count_data_type], "") == 0) { break; } - strcat(dataString, data_type[count_data_type]); - strcat(dataString, " "); + + len += snprintf(dataString + len, STRING_LEN - len, "%s ", data_type[count_data_type]); } FILE *fp = fopen(arguments.output_file, "a"); @@ -473,32 +475,29 @@ int main(int argc, char *argv[]) { sprintf(command, "create database %s;", db_name); taos_query(taos, command); - char cols[512] = "\0"; + char cols[STRING_LEN] = "\0"; int colIndex = 0; + len = 0; for (; colIndex < ncols_per_record - 1; colIndex++) { if (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0) { - sprintf(command, ",f%d %s", colIndex + 1, data_type[colIndex % count_data_type]); - strcat(cols, command); + len += snprintf(cols + len, STRING_LEN - len, ",f%d %s", colIndex + 1, data_type[colIndex % count_data_type]); } else { - sprintf(command, ",f%d %s(%d)", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary); - strcat(cols, command); + len += snprintf(cols + len, STRING_LEN - len, ",f%d %s(%d)", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary); } } if (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0) { - sprintf(command, ",f%d %s)", colIndex + 1, data_type[colIndex % count_data_type]); + len += snprintf(cols + len, STRING_LEN - len, ",f%d %s)", colIndex + 1, data_type[colIndex % count_data_type]); } else { - sprintf(command, ",f%d %s(%d))", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary); + len += snprintf(cols + len, STRING_LEN - len, ",f%d %s(%d))", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary); } - strcat(cols, command); - if (!use_metric) { /* Create all the tables; */ printf("Creating %d table(s)......\n", ntables); for (int i = 0; i < ntables; i++) { - sprintf(command, "create table %s.%s%d (ts timestamp%s;", db_name, tb_prefix, i, cols); + snprintf(command, BUFFER_SIZE, "create table %s.%s%d (ts timestamp%s;", db_name, tb_prefix, i, cols); queryDB(taos, command); } @@ -508,7 +507,7 @@ int main(int argc, char *argv[]) { } else { /* Create metric table */ printf("Creating meters super table...\n"); - sprintf(command, "create table %s.meters (ts timestamp%s tags (areaid int, loc binary(10))", db_name, cols); + snprintf(command, BUFFER_SIZE, "create table %s.meters (ts timestamp%s tags (areaid int, loc binary(10))", db_name, cols); queryDB(taos, command); printf("meters created!\n"); @@ -522,10 +521,10 @@ int main(int argc, char *argv[]) { j = i % 10; } if (j % 2 == 0) { - sprintf(command, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j,"shanghai"); - } else { - sprintf(command, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j,"beijing"); - } + snprintf(command, BUFFER_SIZE, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j, "shanghai"); + } else { + snprintf(command, BUFFER_SIZE, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j, "beijing"); + } queryDB(taos, command); } From 9ccf152f429c14918b4bbd5a370c75f76f83c839 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Mon, 8 Jun 2020 16:50:42 +0800 Subject: [PATCH 45/72] make pytest support both TDinternal and community [TD-555] --- tests/pytest/util/dnodes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 50d054a301..f3ccd58432 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -194,13 +194,13 @@ class TDDnode: selfPath = os.path.dirname(os.path.realpath(__file__)) binPath = "" - if ("TDinternal" in selfPath): + if ("community" in selfPath): projPath = selfPath + "/../../../../" for root, dirs, files in os.walk(projPath): if ("taosd" in files): rootRealPath = os.path.dirname(os.path.realpath(root)) - if ("community" not in rootRealPath): + if ("packaging" not in rootRealPath): binPath = os.path.join(root, "taosd") break else: @@ -213,7 +213,7 @@ class TDDnode: break if (binPath == ""): - tdLog.exit("taosd not found!s") + tdLog.exit("taosd not found!") else: tdLog.info("taosd found in %s" % rootRealPath) From 2a209718d7d4d15f7edc5b84acae105e590435ca Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Mon, 8 Jun 2020 08:59:53 +0000 Subject: [PATCH 46/72] add regression test suite [TD-551] --- tests/pytest/regressiontest.sh | 136 ++++++++++++++++++++ tests/script/regressionSuite.sim | 213 +++++++++++++++++++++++++++++++ tests/test-all.sh | 14 +- 3 files changed, 361 insertions(+), 2 deletions(-) create mode 100755 tests/pytest/regressiontest.sh create mode 100644 tests/script/regressionSuite.sim diff --git a/tests/pytest/regressiontest.sh b/tests/pytest/regressiontest.sh new file mode 100755 index 0000000000..e1d4c6348b --- /dev/null +++ b/tests/pytest/regressiontest.sh @@ -0,0 +1,136 @@ +#!/bin/bash +ulimit -c unlimited + +python3 ./test.py -f insert/basic.py +python3 ./test.py -f insert/int.py +python3 ./test.py -f insert/float.py +python3 ./test.py -f insert/bigint.py +python3 ./test.py -f insert/bool.py +python3 ./test.py -f insert/double.py +python3 ./test.py -f insert/smallint.py +python3 ./test.py -f insert/tinyint.py +python3 ./test.py -f insert/date.py +python3 ./test.py -f insert/binary.py +python3 ./test.py -f insert/nchar.py +# python3 ./test.py -f insert/nchar-boundary.py +# python3 ./test.py -f insert/nchar-unicode.py +python3 ./test.py -f insert/multi.py +python3 ./test.py -f insert/randomNullCommit.py + +python3 ./test.py -f table/column_name.py +python3 ./test.py -f table/column_num.py +python3 ./test.py -f table/db_table.py +# python3 ./test.py -f table/tablename-boundary.py + +# tag +python3 ./test.py -f tag_lite/filter.py +python3 ./test.py -f tag_lite/create-tags-boundary.py +python3 ./test.py -f tag_lite/3.py +python3 ./test.py -f tag_lite/4.py +python3 ./test.py -f tag_lite/5.py +python3 ./test.py -f tag_lite/6.py +# python3 ./test.py -f tag_lite/add.py +python3 ./test.py -f tag_lite/bigint.py +python3 ./test.py -f tag_lite/binary_binary.py +python3 ./test.py -f tag_lite/binary.py +python3 ./test.py -f tag_lite/bool_binary.py +python3 ./test.py -f tag_lite/bool_int.py +python3 ./test.py -f tag_lite/bool.py +python3 ./test.py -f tag_lite/change.py +python3 ./test.py -f tag_lite/column.py +# python3 ./test.py -f tag_lite/commit.py +python3 ./test.py -f tag_lite/create.py +# python3 ./test.py -f tag_lite/datatype.py +python3 ./test.py -f tag_lite/datatype-without-alter.py +# python3 ./test.py -f tag_lite/delete.py +python3 ./test.py -f tag_lite/double.py +python3 ./test.py -f tag_lite/float.py +python3 ./test.py -f tag_lite/int_binary.py +python3 ./test.py -f tag_lite/int_float.py +python3 ./test.py -f tag_lite/int.py +# python3 ./test.py -f tag_lite/set.py +python3 ./test.py -f tag_lite/smallint.py +python3 ./test.py -f tag_lite/tinyint.py + +# python3 ./test.py -f dbmgmt/database-name-boundary.py + +python3 ./test.py -f import_merge/importBlock1HO.py +python3 ./test.py -f import_merge/importBlock1HPO.py +python3 ./test.py -f import_merge/importBlock1H.py +python3 ./test.py -f import_merge/importBlock1S.py +python3 ./test.py -f import_merge/importBlock1Sub.py +python3 ./test.py -f import_merge/importBlock1TO.py +python3 ./test.py -f import_merge/importBlock1TPO.py +python3 ./test.py -f import_merge/importBlock1T.py +python3 ./test.py -f import_merge/importBlock2HO.py +python3 ./test.py -f import_merge/importBlock2HPO.py +python3 ./test.py -f import_merge/importBlock2H.py +python3 ./test.py -f import_merge/importBlock2S.py +python3 ./test.py -f import_merge/importBlock2Sub.py +python3 ./test.py -f import_merge/importBlock2TO.py +python3 ./test.py -f import_merge/importBlock2TPO.py +python3 ./test.py -f import_merge/importBlock2T.py +python3 ./test.py -f import_merge/importBlockbetween.py +python3 ./test.py -f import_merge/importCacheFileHO.py +python3 ./test.py -f import_merge/importCacheFileHPO.py +python3 ./test.py -f import_merge/importCacheFileH.py +python3 ./test.py -f import_merge/importCacheFileS.py +python3 ./test.py -f import_merge/importCacheFileSub.py +python3 ./test.py -f import_merge/importCacheFileTO.py +python3 ./test.py -f import_merge/importCacheFileTPO.py +python3 ./test.py -f import_merge/importCacheFileT.py +python3 ./test.py -f import_merge/importDataH2.py +# python3 ./test.py -f import_merge/importDataHO2.py +# python3 ./test.py -f import_merge/importDataHO.py +python3 ./test.py -f import_merge/importDataHPO.py +python3 ./test.py -f import_merge/importDataLastHO.py +python3 ./test.py -f import_merge/importDataLastHPO.py +python3 ./test.py -f import_merge/importDataLastH.py +python3 ./test.py -f import_merge/importDataLastS.py +python3 ./test.py -f import_merge/importDataLastSub.py +python3 ./test.py -f import_merge/importDataLastTO.py +python3 ./test.py -f import_merge/importDataLastTPO.py +python3 ./test.py -f import_merge/importDataLastT.py +python3 ./test.py -f import_merge/importDataS.py +# python3 ./test.py -f import_merge/importDataSub.py +python3 ./test.py -f import_merge/importDataTO.py +python3 ./test.py -f import_merge/importDataTPO.py +python3 ./test.py -f import_merge/importDataT.py +python3 ./test.py -f import_merge/importHeadOverlap.py +python3 ./test.py -f import_merge/importHeadPartOverlap.py +python3 ./test.py -f import_merge/importHead.py +python3 ./test.py -f import_merge/importHORestart.py +python3 ./test.py -f import_merge/importHPORestart.py +python3 ./test.py -f import_merge/importHRestart.py +python3 ./test.py -f import_merge/importLastHO.py +python3 ./test.py -f import_merge/importLastHPO.py +python3 ./test.py -f import_merge/importLastH.py +python3 ./test.py -f import_merge/importLastS.py +python3 ./test.py -f import_merge/importLastSub.py +python3 ./test.py -f import_merge/importLastTO.py +python3 ./test.py -f import_merge/importLastTPO.py +python3 ./test.py -f import_merge/importLastT.py +python3 ./test.py -f import_merge/importSpan.py +python3 ./test.py -f import_merge/importSRestart.py +python3 ./test.py -f import_merge/importSubRestart.py +python3 ./test.py -f import_merge/importTailOverlap.py +python3 ./test.py -f import_merge/importTailPartOverlap.py +python3 ./test.py -f import_merge/importTail.py +python3 ./test.py -f import_merge/importToCommit.py +python3 ./test.py -f import_merge/importTORestart.py +python3 ./test.py -f import_merge/importTPORestart.py +python3 ./test.py -f import_merge/importTRestart.py +python3 ./test.py -f import_merge/importInsertThenImport.py + +# user +python3 ./test.py -f user/user_create.py +python3 ./test.py -f user/pass_len.py + +# table +#python3 ./test.py -f table/del_stable.py + +#query +python3 ./test.py -f query/filter.py +# python3 ./test.py -f query/filterCombo.py +# python3 ./test.py -f query/queryNormal.py +# python3 ./test.py -f query/queryError.py diff --git a/tests/script/regressionSuite.sim b/tests/script/regressionSuite.sim new file mode 100644 index 0000000000..67f54523df --- /dev/null +++ b/tests/script/regressionSuite.sim @@ -0,0 +1,213 @@ +#unsupport run general/alter/cached_schema_after_alter.sim +#unsupport run general/alter/count.sim +#unsupport run general/alter/import.sim +#unsupport run general/alter/insert1.sim +#unsupport run general/alter/insert2.sim +#unsupport run general/alter/metrics.sim +#unsupport run general/alter/table.sim +run general/cache/new_metrics.sim +run general/cache/restart_metrics.sim +run general/cache/restart_table.sim +run general/connection/connection.sim +run general/column/commit.sim +run general/column/metrics.sim +run general/column/table.sim +run general/compress/commitlog.sim +run general/compress/compress.sim +run general/compress/compress2.sim +run general/compress/uncompress.sim +run general/compute/avg.sim +run general/compute/bottom.sim +run general/compute/count.sim +run general/compute/diff.sim +run general/compute/diff2.sim +run general/compute/first.sim +run general/compute/interval.sim +run general/compute/last.sim +run general/compute/leastsquare.sim +run general/compute/max.sim +run general/compute/min.sim +run general/compute/null.sim +run general/compute/percentile.sim +run general/compute/stddev.sim +run general/compute/sum.sim +run general/compute/top.sim +run general/db/alter_option.sim +run general/db/alter_tables_d2.sim +run general/db/alter_tables_v1.sim +run general/db/alter_tables_v4.sim +run general/db/alter_vgroups.sim +run general/db/basic.sim +run general/db/basic1.sim +run general/db/basic2.sim +run general/db/basic3.sim +run general/db/basic4.sim +run general/db/basic5.sim +run general/db/delete_reuse1.sim +run general/db/delete_reuse2.sim +run general/db/delete_reusevnode.sim +run general/db/delete_reusevnode2.sim +run general/db/delete_writing1.sim +run general/db/delete_writing2.sim +run general/db/delete.sim +run general/db/len.sim +run general/db/repeat.sim +run general/db/tables.sim +run general/db/vnodes.sim +run general/field/2.sim +run general/field/3.sim +run general/field/4.sim +run general/field/5.sim +run general/field/6.sim +run general/field/bigint.sim +run general/field/binary.sim +run general/field/bool.sim +run general/field/single.sim +run general/field/smallint.sim +run general/field/tinyint.sim +run general/http/restful.sim +run general/http/restful_insert.sim +run general/http/restful_limit.sim +run general/http/restful_full.sim +run general/http/prepare.sim +run general/http/telegraf.sim +# run general/http/grafana_bug.sim +# run general/http/grafana.sim +run general/import/basic.sim +run general/import/commit.sim +run general/import/large.sim +run general/import/replica1.sim +run general/insert/basic.sim +run general/insert/insert_drop.sim +run general/insert/query_block1_memory.sim +run general/insert/query_block2_memory.sim +run general/insert/query_block1_file.sim +run general/insert/query_block2_file.sim +run general/insert/query_file_memory.sim +run general/insert/query_multi_file.sim +run general/insert/tcp.sim +#unsupport run general/parser/alter.sim +#unsupport run general/parser/alter1.sim +#unsupport run general/parser/alter_stable.sim +run general/parser/auto_create_tb.sim +run general/parser/auto_create_tb_drop_tb.sim +run general/parser/col_arithmetic_operation.sim +run general/parser/columnValue.sim +# run general/parser/commit.sim +run general/parser/create_db.sim +run general/parser/create_mt.sim +run general/parser/create_tb.sim +run general/parser/dbtbnameValidate.sim +run general/parser/import_commit1.sim +run general/parser/import_commit2.sim +run general/parser/import_commit3.sim +run general/parser/insert_tb.sim +# run general/parser/first_last.sim +#unsupport run general/parser/import_file.sim +# run general/parser/lastrow.sim +run general/parser/nchar.sim +#unsupport run general/parser/null_char.sim +# run general/parser/single_row_in_tb.sim +run general/parser/select_from_cache_disk.sim +# run general/parser/limit.sim +# run general/parser/limit1.sim +# run general/parser/limit1_tblocks100.sim +# run general/parser/mixed_blocks.sim +# run general/parser/selectResNum.sim +run general/parser/select_across_vnodes.sim +run general/parser/slimit1.sim +run general/parser/tbnameIn.sim +run general/parser/binary_escapeCharacter.sim +# run general/parser/projection_limit_offset.sim +run general/parser/limit2.sim +# run general/parser/slimit.sim +run general/parser/fill.sim +# run general/parser/fill_stb.sim +# run general/parser/interp.sim +# run general/parser/where.sim +#unsupport run general/parser/join.sim +#unsupport run general/parser/join_multivnode.sim +# run general/parser/select_with_tags.sim +#unsupport run general/parser/groupby.sim +#unsupport run general/parser/bug.sim +#unsupport run general/parser/tags_dynamically_specifiy.sim +#unsupport run general/parser/set_tag_vals.sim +#unsupport run general/parser/repeatAlter.sim +#unsupport run general/parser/slimit_alter_tags.sim +#unsupport run general/parser/stream_on_sys.sim +#unsupport run general/parser/stream.sim +#unsupport run general/parser/repeatStream.sim +run general/stable/disk.sim +run general/stable/dnode3.sim +run general/stable/metrics.sim +run general/stable/values.sim +run general/stable/vnode3.sim +# run general/table/autocreate.sim +run general/table/basic1.sim +run general/table/basic2.sim +run general/table/basic3.sim +run general/table/bigint.sim +run general/table/binary.sim +run general/table/bool.sim +run general/table/column_name.sim +run general/table/column_num.sim +run general/table/column_value.sim +run general/table/column2.sim +run general/table/date.sim +run general/table/db.table.sim +run general/table/delete_reuse1.sim +run general/table/delete_reuse2.sim +run general/table/delete_writing.sim +run general/table/describe.sim +run general/table/double.sim +run general/table/fill.sim +run general/table/float.sim +run general/table/int.sim +run general/table/limit.sim +run general/table/smallint.sim +run general/table/table_len.sim +# run general/table/table.sim +run general/table/tinyint.sim +run general/table/vgroup.sim +run general/tag/3.sim +run general/tag/4.sim +run general/tag/5.sim +run general/tag/6.sim +#unsupport run general/tag/add.sim +run general/tag/bigint.sim +run general/tag/binary_binary.sim +run general/tag/binary.sim +run general/tag/bool_binary.sim +run general/tag/bool_int.sim +run general/tag/bool.sim +#unsupport run general/tag/change.sim +run general/tag/column.sim +#unsupport run general/tag/commit.sim +run general/tag/create.sim +#unsupport run general/tag/delete.sim +run general/tag/double.sim +run general/tag/filter.sim +run general/tag/float.sim +run general/tag/int_binary.sim +run general/tag/int_float.sim +run general/tag/int.sim +#unsupport run general/tag/set.sim +run general/tag/smallint.sim +run general/tag/tinyint.sim +run general/user/authority.sim +run general/user/monitor.sim +run general/user/pass_alter.sim +run general/user/pass_len.sim +run general/user/user_create.sim +run general/user/user_len.sim +run general/vector/metrics_field.sim +run general/vector/metrics_mix.sim +run general/vector/metrics_query.sim +run general/vector/metrics_tag.sim +run general/vector/metrics_time.sim +run general/vector/multi.sim +run general/vector/single.sim +run general/vector/table_field.sim +run general/vector/table_mix.sim +run general/vector/table_query.sim +run general/vector/table_time.sim diff --git a/tests/test-all.sh b/tests/test-all.sh index cd5444858e..cee638e03c 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -24,14 +24,19 @@ GREEN_DARK='\033[0;32m' GREEN_UNDERLINE='\033[4;32m' NC='\033[0m' -echo "### run TSIM script ###" +echo "### run TSIM test case ###" cd script [ -f out.log ] && rm -f out.log if [ "$1" == "cron" ]; then + echo "### run TSIM regression test ###" + runSimCaseOneByOne regressionSuite.sim +elif [ "$1" == "full" ]; then + echo "### run TSIM full test ###" runSimCaseOneByOne fullGeneralSuite.sim else + echo "### run TSIM smoke test ###" runSimCaseOneByOne basicSuite.sim fi @@ -53,14 +58,19 @@ if [ "$totalFailed" -ne "0" ]; then # exit $totalFailed fi -echo "### run Python script ###" +echo "### run Python test case ###" cd ../pytest [ -f pytest-out.log ] && rm -f pytest-out.log if [ "$1" == "cron" ]; then + echo "### run Python regression test ###" + runPyCaseOneByOne regressiontest.sh +elif [ "$1" == "full" ]; then + echo "### run Python full test ###" runPyCaseOneByOne fulltest.sh else + echo "### run Python smoke test ###" runPyCaseOneByOne smoketest.sh fi totalPySuccess=`grep 'successfully executed' pytest-out.log | wc -l` From 3c14c89b49511c4e4097c9ceb22ec7ae93400990 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 8 Jun 2020 09:01:04 +0000 Subject: [PATCH 47/72] fix another commit bug --- src/tsdb/src/tsdbRWHelper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tsdb/src/tsdbRWHelper.c b/src/tsdb/src/tsdbRWHelper.c index ed0122b6eb..add484b5f4 100644 --- a/src/tsdb/src/tsdbRWHelper.c +++ b/src/tsdb/src/tsdbRWHelper.c @@ -913,7 +913,7 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa } else { // Load if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, blkIdx), NULL) < 0) goto _err; - ASSERT(pHelper->pDataCols[0]->numOfRows == blockAtIdx(pHelper, blkIdx)->numOfRows); + ASSERT(pHelper->pDataCols[0]->numOfRows <= blockAtIdx(pHelper, blkIdx)->numOfRows); // Merge if (tdMergeDataCols(pHelper->pDataCols[0], pDataCols, rowsWritten) < 0) goto _err; // Write @@ -1107,16 +1107,16 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId for (int i = blkIdx + 1; i < pIdx->numOfBlocks; i++) { SCompBlock *pTCompBlock = pHelper->pCompInfo->blocks + i; if (pTCompBlock->numOfSubBlocks > 1) { - ptr = (void *)((char *)(pHelper->pCompInfo) + pTCompBlock->offset + pTCompBlock->len); + ptr = POINTER_SHIFT(pHelper->pCompInfo, pTCompBlock->offset); break; } } - if (ptr == NULL) ptr = (void *)((char *)(pHelper->pCompInfo) + pIdx->len - sizeof(TSCKSUM)); + if (ptr == NULL) ptr = POINTER_SHIFT(pHelper->pCompInfo, pIdx->len-sizeof(TSCKSUM)); size_t tsize = pIdx->len - ((char *)ptr - (char *)(pHelper->pCompInfo)); if (tsize > 0) { - memmove((void *)((char *)ptr + sizeof(SCompBlock) * 2), ptr, tsize); + memmove(POINTER_SHIFT(ptr, sizeof(SCompBlock) * 2), ptr, tsize); for (int i = blkIdx + 1; i < pIdx->numOfBlocks; i++) { SCompBlock *pTCompBlock = pHelper->pCompInfo->blocks + i; if (pTCompBlock->numOfSubBlocks > 1) pTCompBlock->offset += (sizeof(SCompBlock) * 2); From 5711ef3efd7da28ee96aa4a8fe18290b23c2611c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 09:01:46 +0000 Subject: [PATCH 48/72] [TD_543] fix coverity scan, cid:267728 --- src/util/src/tnote.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/src/tnote.c b/src/util/src/tnote.c index 91d586322d..31ed6e2f7b 100644 --- a/src/util/src/tnote.c +++ b/src/util/src/tnote.c @@ -87,6 +87,10 @@ void *taosThreadToOpenNewNote(void *param) umask(0); int fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); + if (fd < 0) { + return NULL; + } + taosLockNote(fd, pNote); lseek(fd, 0, SEEK_SET); From 894ad481f452340be399070f9ae4f2dcf1fa2313 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 09:01:52 +0000 Subject: [PATCH 49/72] [TD_543] fix coverity scan, cid:267731 --- src/kit/shell/src/shellImport.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/kit/shell/src/shellImport.c b/src/kit/shell/src/shellImport.c index 1dea6bca70..cd8b06c91c 100644 --- a/src/kit/shell/src/shellImport.c +++ b/src/kit/shell/src/shellImport.c @@ -169,6 +169,7 @@ static void shellSourceFile(TAOS *con, char *fptr) { if (f == NULL) { fprintf(stderr, "ERROR: failed to open file %s\n", fname); wordfree(&full_path); + free(cmd); return; } From 9e221b8a53c10d94b086730af3937bc92ac5c4c1 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 09:09:34 +0000 Subject: [PATCH 50/72] [TD_543] fix coverity scan, cid:267747 --- src/kit/shell/src/shellImport.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/kit/shell/src/shellImport.c b/src/kit/shell/src/shellImport.c index cd8b06c91c..347f99671d 100644 --- a/src/kit/shell/src/shellImport.c +++ b/src/kit/shell/src/shellImport.c @@ -148,7 +148,11 @@ static void shellSourceFile(TAOS *con, char *fptr) { } char *fname = full_path.we_wordv[0]; - + if (fname == NULL) { + fprintf(stderr, "ERROR: invalid filename\n"); + return; + } + if (access(fname, F_OK) != 0) { fprintf(stderr, "ERROR: file %s is not exist\n", fptr); From 73cdb81e1259147e37f318ba6d208d95de1627d0 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 09:10:49 +0000 Subject: [PATCH 51/72] [TD_543] fix coverity scan, cid:267750 --- src/os/linux/src/linuxSysPara.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/linux/src/linuxSysPara.c b/src/os/linux/src/linuxSysPara.c index af2d3c2633..ca244dcd94 100644 --- a/src/os/linux/src/linuxSysPara.c +++ b/src/os/linux/src/linuxSysPara.c @@ -229,7 +229,7 @@ static void taosGetSystemLocale() { // get and set default locale uError("can't get locale from system, set it to en_US.UTF-8"); strcpy(tsLocale, "en_US.UTF-8"); } else { - strncpy(tsLocale, locale, tListLen(tsLocale)); + tstrncpy(tsLocale, locale, tListLen(tsLocale)); uError("locale not configured, set to system default:%s", tsLocale); } } From ac26d4ab4dd2ad8ae3f70803c61bd87eec1b1dfc Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 09:11:46 +0000 Subject: [PATCH 52/72] [TD_543] fix coverity scan, cid:267752 --- src/plugins/http/src/tgHandle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index 61f9da6368..ffb2ccb2f9 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -313,7 +313,7 @@ bool tgGetPassFromUrl(HttpContext *pContext) { return false; } - strcpy(pContext->pass, pParser->path[TG_PASS_URL_POS].pos); + tstrncpy(pContext->pass, pParser->path[TG_PASS_URL_POS].pos, TSDB_PASSWORD_LEN); return true; } From b56bac84e8a9c9df3df3df2b1e3b20ccaba14a0c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 8 Jun 2020 09:12:36 +0000 Subject: [PATCH 53/72] TD-546 --- src/tsdb/src/tsdbMeta.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 05c3b30377..820d2df888 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -620,7 +620,10 @@ static int tsdbFreeTable(STable *pTable) { if (pTable->type == TSDB_CHILD_TABLE) { kvRowFree(pTable->tagVal); } else { - for (int i = 0; i < pTable->numOfSchemas; i++) tdFreeSchema(pTable->schema[i]); + if (pTable->schema) { + for (int i = 0; i < pTable->numOfSchemas; i++) tdFreeSchema(pTable->schema[i]); + free(pTable->schema); + } } if (pTable->type == TSDB_STREAM_TABLE) { From d27dcd5e358daf7c94eae8be77626f3c1ec85d2f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 09:22:50 +0000 Subject: [PATCH 54/72] [TD_543] fix coverity scan, cid:267764 --- src/kit/taosdump/taosdump.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 7875ef732c..f03b46ac47 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -117,8 +117,8 @@ typedef struct { } SDbInfo; typedef struct { - char name[TSDB_TABLE_NAME_LEN + 1]; - char metric[TSDB_TABLE_NAME_LEN + 1]; + char name[TSDB_TABLE_NAME_LEN]; + char metric[TSDB_TABLE_NAME_LEN]; } STableRecord; typedef struct { @@ -871,7 +871,7 @@ int32_t taosDumpMetric(char *metric, SDumpArguments *arguments, FILE *fp) { int fd = -1; STableRecord tableRecord; - strcpy(tableRecord.metric, metric); + tstrncpy(tableRecord.metric, metric, TSDB_TABLE_NAME_LEN); sprintf(command, "select tbname from %s", metric); result = taos_query(taos, command); From 86a63d250ef9d42570058e18f44df131eaa5d30b Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 8 Jun 2020 17:23:45 +0800 Subject: [PATCH 55/72] [td-225] --- src/client/inc/tsclient.h | 2 +- src/client/src/tscServer.c | 35 +++++++++++++---------------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 4e42bcfdf7..b82551dd94 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -358,7 +358,7 @@ int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion); void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet); int tscProcessSql(SSqlObj *pSql); -int tscRenewMeterMeta(SSqlObj *pSql, char *tableId); +int tscRenewTableMeta(SSqlObj *pSql, char *tableId); void tscQueueAsyncRes(SSqlObj *pSql); void tscQueueAsyncError(void(*fp), void *param, int32_t code); diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 089c951af3..e9daf1dfc1 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -239,16 +239,6 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); if (rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID || rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { - /* - * not_active_table: 1. the virtual node may fail to create table, since the procedure of create table is asynchronized, - * the virtual node may have not create table till now, so try again by using the new metermeta. - * 2. this requested table may have been removed by other client, so we need to renew the - * metermeta here. - * - * not_active_vnode: current vnode is move to other node due to node balance procedure or virtual node have been - * removed. So, renew metermeta and try again. - * not_active_session: db has been move to other node, the vnode does not exist on this dnode anymore. - */ if (pCmd->command == TSDB_SQL_CONNECT) { rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; rpcFreeCont(rpcMsg->pCont); @@ -258,8 +248,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { rpcFreeCont(rpcMsg->pCont); return; } else if (pCmd->command == TSDB_SQL_META) { -// rpcFreeCont(rpcMsg->pCont); -// return; + // get table meta query will not retry, do nothing } else { tscWarn("%p it shall renew table meta, code:%s, retry:%d", pSql, tstrerror(rpcMsg->code), ++pSql->retry); @@ -267,13 +256,14 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { if (pSql->retry > pSql->maxRetry) { tscError("%p max retry %d reached, give up", pSql, pSql->maxRetry); } else { - rpcMsg->code = tscRenewMeterMeta(pSql, pTableMetaInfo->name); - if (pTableMetaInfo->pTableMeta) { - tscSendMsgToServer(pSql); + rpcMsg->code = tscRenewTableMeta(pSql, pTableMetaInfo->name); + + // if there is an error occurring, proceed to the following error handling procedure. + // todo add test cases + if (rpcMsg->code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { + rpcFreeCont(rpcMsg->pCont); + return; } - - rpcFreeCont(rpcMsg->pCont); - return; } } } @@ -330,9 +320,10 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { } } - if (pRes->code == TSDB_CODE_SUCCESS && tscProcessMsgRsp[pCmd->command]) + if (pRes->code == TSDB_CODE_SUCCESS && tscProcessMsgRsp[pCmd->command]) { + assert(pRes->pRsp != NULL); rpcMsg->code = (*tscProcessMsgRsp[pCmd->command])(pSql); - + } if (rpcMsg->code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) { rpcMsg->code = (pRes->code == TSDB_CODE_SUCCESS) ? pRes->numOfRows: pRes->code; @@ -2358,7 +2349,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf int32_t code = tscProcessSql(pNew); if (code == TSDB_CODE_SUCCESS) { - code = TSDB_CODE_TSC_ACTION_IN_PROGRESS; + code = TSDB_CODE_TSC_ACTION_IN_PROGRESS; // notify upper application that current process need to be terminated } return code; @@ -2395,7 +2386,7 @@ int tscGetMeterMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool create * @param tableId table full name * @return status code */ -int tscRenewMeterMeta(SSqlObj *pSql, char *tableId) { +int tscRenewTableMeta(SSqlObj *pSql, char *tableId) { SSqlCmd *pCmd = &pSql->cmd; SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); From aab502f2710971df305697a25382e29ccae6ad52 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 8 Jun 2020 09:25:48 +0000 Subject: [PATCH 56/72] TD-545 --- src/tsdb/src/tsdbMeta.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 820d2df888..40e5667893 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -74,14 +74,16 @@ void tsdbEncodeTable(STable *pTable, char *buf, int *contLen) { STable *tsdbDecodeTable(void *cont, int contLen) { STable *pTable = (STable *)calloc(1, sizeof(STable)); if (pTable == NULL) return NULL; - pTable->schema = (STSchema **)malloc(sizeof(STSchema *) * TSDB_MAX_TABLE_SCHEMAS); - if (pTable->schema == NULL) { - free(pTable); - return NULL; - } void *ptr = cont; T_READ_MEMBER(ptr, int8_t, pTable->type); + if (pTable->type != TSDB_CHILD_TABLE) { + pTable->schema = (STSchema **)malloc(sizeof(STSchema *) * TSDB_MAX_TABLE_SCHEMAS); + if (pTable->schema == NULL) { + free(pTable); + return NULL; + } + } int len = *(int *)ptr; ptr = (char *)ptr + sizeof(int); pTable->name = calloc(1, len + VARSTR_HEADER_SIZE + 1); From fb9057648bf4849f8e772110e0f1c8748b01b6fa Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 09:26:57 +0000 Subject: [PATCH 57/72] [TD_543] fix coverity scan, cid:267767 --- src/plugins/http/src/httpUtil.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/http/src/httpUtil.c b/src/plugins/http/src/httpUtil.c index 77fc399272..b91b89e21c 100644 --- a/src/plugins/http/src/httpUtil.c +++ b/src/plugins/http/src/httpUtil.c @@ -32,12 +32,12 @@ bool httpCheckUsedbSql(char *sql) { void httpTimeToString(time_t t, char *buf, int buflen) { memset(buf, 0, (size_t)buflen); - char ts[30] = {0}; + char ts[32] = {0}; struct tm *ptm; time_t tt = t / 1000; ptm = localtime(&tt); - strftime(ts, 64, "%Y-%m-%d %H:%M:%S", ptm); + strftime(ts, 31, "%Y-%m-%d %H:%M:%S", ptm); sprintf(buf, "%s.%03ld", ts, t % 1000); } From 422e45bd250697994538b9c70ea03fb0d58c7aa2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 09:30:57 +0000 Subject: [PATCH 58/72] [TD_543] fix coverity scan, cid:267773 --- src/util/src/tdes.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/src/tdes.c b/src/util/src/tdes.c index 00474e4ae2..3112fb4111 100644 --- a/src/util/src/tdes.c +++ b/src/util/src/tdes.c @@ -18,6 +18,7 @@ void generate_key(unsigned char* key); void generate_sub_keys(unsigned char* main_key, key_set* key_sets); void process_message(unsigned char* message_piece, unsigned char* processed_piece, key_set* key_sets, int mode); +#if 0 int64_t taosDesGenKey() { unsigned int iseed = (unsigned int)time(NULL); srand(iseed); @@ -27,6 +28,7 @@ int64_t taosDesGenKey() { return *((int64_t*)key); } +#endif char* taosDesImp(unsigned char* key, char* src, unsigned int len, int process_mode) { unsigned int number_of_blocks = len / 8; From 06467c3e937322271afbbdd5863bfb313dfae391 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 8 Jun 2020 17:36:49 +0800 Subject: [PATCH 59/72] [td-547] --- src/query/src/qExecutor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 0ff9a7e480..26502a7408 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -5820,10 +5820,11 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi _over: tfree(tagCond); tfree(tbnameCond); + tfree(pGroupColIndex); taosArrayDestroy(pTableIdList); + //pQInfo already freed in initQInfo, but *pQInfo may not pointer to null; if (code != TSDB_CODE_SUCCESS) { - //pQInfo already freed in initQInfo, but *pQInfo may not pointer to null; *pQInfo = NULL; } From 628bb01969186927ef4902e77b927bfec300688e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 09:46:21 +0000 Subject: [PATCH 60/72] [TD_543] fix coverity scan, cid:267787 --- src/client/src/tscSub.c | 4 +++- src/client/src/tscSystem.c | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index 9baf49ff21..1a1305825b 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -301,7 +301,9 @@ void tscSaveSubscriptionProgress(void* sub) { char path[256]; sprintf(path, "%s/subscribe", tsDataDir); if (access(path, 0) != 0) { - mkdir(path, 0777); + if (mkdir(path, 0777) != 0 && errno != EEXIST) { + tscError("failed to create subscribe dir: %s", path); + } } sprintf(path, "%s/subscribe/%s", tsDataDir, pSub->topic); diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 75249e44ee..d3c8eefbb9 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -80,9 +80,8 @@ int32_t tscInitRpc(const char *user, const char *secret, void** pDnodeConn) { } void taos_init_imp() { - char temp[128]; - struct stat dirstat; - + char temp[128]; + errno = TSDB_CODE_SUCCESS; srand(taosGetTimestampSec()); deltaToUtcInitOnce(); @@ -94,7 +93,9 @@ void taos_init_imp() { taosReadGlobalLogCfg(); // For log directory - if (stat(tsLogDir, &dirstat) < 0) mkdir(tsLogDir, 0755); + if (mkdir(tsLogDir, 0755) != 0 && errno != EEXIST) { + printf("failed to create log dir:%s\n", tsLogDir); + } sprintf(temp, "%s/taoslog", tsLogDir); if (taosInitLog(temp, tsNumOfLogLines, 10) < 0) { From cf0a90ceee78696466ba17b6ba601e9113daad1b Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 8 Jun 2020 18:16:23 +0800 Subject: [PATCH 61/72] [td-225] remove an assert --- src/client/src/tscServer.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index e9daf1dfc1..f96b979105 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -321,7 +321,6 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { } if (pRes->code == TSDB_CODE_SUCCESS && tscProcessMsgRsp[pCmd->command]) { - assert(pRes->pRsp != NULL); rpcMsg->code = (*tscProcessMsgRsp[pCmd->command])(pSql); } From 49eeb2abdbecf4df736ca1e796291178e361c881 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Mon, 8 Jun 2020 18:32:21 +0800 Subject: [PATCH 62/72] fix delete_datafiles issue. --- .../random-test-multi-threading-3.py | 2 +- .../random-test-multi-threading.py | 2 +- tests/pytest/stream/stream1.py | 25 +++++++++++++------ tests/pytest/stream/stream2.py | 24 +++++++++++------- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/tests/pytest/random-test/random-test-multi-threading-3.py b/tests/pytest/random-test/random-test-multi-threading-3.py index db85ce2fe0..cab17c4c1a 100644 --- a/tests/pytest/random-test/random-test-multi-threading-3.py +++ b/tests/pytest/random-test/random-test-multi-threading-3.py @@ -205,7 +205,7 @@ class Test (Thread): global written dnodesDir = tdDnodes.getDnodesRootDir() - dataDir = dnodesDir + '/dnode1/*' + dataDir = dnodesDir + '/dnode1/data/*' deleteCmd = 'rm -rf %s' % dataDir os.system(deleteCmd) diff --git a/tests/pytest/random-test/random-test-multi-threading.py b/tests/pytest/random-test/random-test-multi-threading.py index 7d1a8a155d..1d8a5c3c82 100644 --- a/tests/pytest/random-test/random-test-multi-threading.py +++ b/tests/pytest/random-test/random-test-multi-threading.py @@ -208,7 +208,7 @@ class Test (threading.Thread): global written dnodesDir = tdDnodes.getDnodesRootDir() - dataDir = dnodesDir + '/dnode1/*' + dataDir = dnodesDir + '/dnode1/data/*' deleteCmd = 'rm -rf %s' % dataDir os.system(deleteCmd) diff --git a/tests/pytest/stream/stream1.py b/tests/pytest/stream/stream1.py index 7a9d88da3b..3b88b4f9f3 100644 --- a/tests/pytest/stream/stream1.py +++ b/tests/pytest/stream/stream1.py @@ -31,21 +31,26 @@ class TDTestCase: tdSql.prepare() tdLog.info("===== step1 =====") - tdSql.execute("create table stb0(ts timestamp, col1 int, col2 float) tags(tgcol int)") + tdSql.execute( + "create table stb0(ts timestamp, col1 int, col2 float) tags(tgcol int)") for i in range(tbNum): tdSql.execute("create table tb%d using stb0 tags(%d)" % (i, i)) for j in range(rowNum): - tdSql.execute("insert into tb%d values (now - %dm, %d, %d)" % (i, 1440 - j, j, j)) + tdSql.execute( + "insert into tb%d values (now - %dm, %d, %d)" % + (i, 1440 - j, j, j)) time.sleep(0.1) tdLog.info("===== step2 =====") - tdSql.query("select count(*), count(col1), count(col2) from tb0 interval(1d)") + tdSql.query( + "select count(*), count(col1), count(col2) from tb0 interval(1d)") tdSql.checkData(0, 1, rowNum) tdSql.checkData(0, 2, rowNum) tdSql.checkData(0, 3, rowNum) tdSql.query("show tables") tdSql.checkRows(tbNum) - tdSql.execute("create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)") + tdSql.execute( + "create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)") tdSql.query("show tables") tdSql.checkRows(tbNum + 1) @@ -67,7 +72,8 @@ class TDTestCase: tdLog.info("===== step6 =====") time.sleep(0.1) - tdSql.execute("create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)") + tdSql.execute( + "create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)") tdSql.query("show tables") tdSql.checkRows(tbNum + 1) @@ -81,14 +87,16 @@ class TDTestCase: tdSql.checkData(0, 3, rowNum) tdLog.info("===== step8 =====") - tdSql.query("select count(*), count(col1), count(col2) from stb0 interval(1d)") + tdSql.query( + "select count(*), count(col1), count(col2) from stb0 interval(1d)") tdSql.checkData(0, 1, rowNum * tbNum) tdSql.checkData(0, 2, rowNum * tbNum) tdSql.checkData(0, 3, rowNum * tbNum) tdSql.query("show tables") tdSql.checkRows(tbNum + 1) - tdSql.execute("create table s1 as select count(*), count(col1), count(col2) from stb0 interval(1d)") + tdSql.execute( + "create table s1 as select count(*), count(col1), count(col2) from stb0 interval(1d)") tdSql.query("show tables") tdSql.checkRows(tbNum + 2) @@ -110,7 +118,8 @@ class TDTestCase: tdSql.error("select * from s1") tdLog.info("===== step12 =====") - tdSql.execute("create table s1 as select count(*), count(col1), count(col2) from stb0 interval(1d)") + tdSql.execute( + "create table s1 as select count(*), count(col1), count(col2) from stb0 interval(1d)") tdSql.query("show tables") tdSql.checkRows(tbNum + 2) diff --git a/tests/pytest/stream/stream2.py b/tests/pytest/stream/stream2.py index 96eff3131d..7b77dc7793 100644 --- a/tests/pytest/stream/stream2.py +++ b/tests/pytest/stream/stream2.py @@ -24,7 +24,6 @@ class TDTestCase: tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) - def run(self): tbNum = 10 rowNum = 20 @@ -33,11 +32,14 @@ class TDTestCase: tdSql.prepare() tdLog.info("===== step1 =====") - tdSql.execute("create table stb0(ts timestamp, col1 int, col2 float) tags(tgcol int)") + tdSql.execute( + "create table stb0(ts timestamp, col1 int, col2 float) tags(tgcol int)") for i in range(tbNum): tdSql.execute("create table tb%d using stb0 tags(%d)" % (i, i)) for j in range(rowNum): - tdSql.execute("insert into tb%d values (now - %dm, %d, %d)" % (i, 1440 - j, j, j)) + tdSql.execute( + "insert into tb%d values (now - %dm, %d, %d)" % + (i, 1440 - j, j, j)) time.sleep(0.1) tdLog.info("===== step2 =====") @@ -45,7 +47,8 @@ class TDTestCase: tdSql.checkData(0, 1, rowNum) tdSql.query("show tables") tdSql.checkRows(tbNum) - tdSql.execute("create table s0 as select count(col1) from tb0 interval(1d)") + tdSql.execute( + "create table s0 as select count(col1) from tb0 interval(1d)") tdSql.query("show tables") tdSql.checkRows(tbNum + 1) @@ -63,7 +66,8 @@ class TDTestCase: tdSql.error("select * from s0") tdLog.info("===== step6 =====") - tdSql.execute("create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)") + tdSql.execute( + "create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)") tdSql.query("show tables") tdSql.checkRows(tbNum + 1) @@ -75,13 +79,15 @@ class TDTestCase: tdSql.checkData(0, 3, rowNum) tdLog.info("===== step8 =====") - tdSql.query("select count(*), count(col1), count(col2) from stb0 interval(1d)") + tdSql.query( + "select count(*), count(col1), count(col2) from stb0 interval(1d)") tdSql.checkData(0, 1, totalNum) tdSql.checkData(0, 2, totalNum) tdSql.checkData(0, 3, totalNum) tdSql.query("show tables") tdSql.checkRows(tbNum + 1) - tdSql.execute("create table s1 as select count(*), count(col1), count(col2) from stb0 interval(1d)") + tdSql.execute( + "create table s1 as select count(*), count(col1), count(col2) from stb0 interval(1d)") tdSql.query("show tables") tdSql.checkRows(tbNum + 2) @@ -101,7 +107,8 @@ class TDTestCase: tdSql.error("select * from s1") tdLog.info("===== step12 =====") - tdSql.execute("create table s1 as select count(col1) from stb0 interval(1d)") + tdSql.execute( + "create table s1 as select count(col1) from stb0 interval(1d)") tdSql.query("show tables") tdSql.checkRows(tbNum + 2) @@ -112,7 +119,6 @@ class TDTestCase: #tdSql.checkData(0, 2, None) #tdSql.checkData(0, 3, None) - def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) From 4dea07b26fd0bee54d046ba58593de52c0a56a04 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 10:43:55 +0000 Subject: [PATCH 63/72] [TD_543] change invalid table id to invalid table name --- src/inc/taoserror.h | 21 +++++++++++---------- src/mnode/src/mnodeTable.c | 12 ++++++------ src/mnode/src/mnodeVgroup.c | 4 ++-- src/plugins/http/src/httpJson.c | 2 +- src/plugins/http/src/tgJson.c | 2 +- tests/script/general/http/restful_full.sim | 2 +- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index 6012efa359..5379b371ef 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -136,16 +136,17 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_USERS, 0, 0x0355, "mnode too TAOS_DEFINE_ERROR(TSDB_CODE_MND_TABLE_ALREADY_EXIST, 0, 0x0360, "mnode table already exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_ID, 0, 0x0361, "mnode invalid table id") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_TYPE, 0, 0x0362, "mnode invalid table type") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TAGS, 0, 0x0363, "mnode too many tags") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TABLES, 0, 0x0364, "mnode too many tables") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TIMESERIES, 0, 0x0365, "mnode not enough time series") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_NOT_SUPER_TABLE, 0, 0x0366, "mnode no super table") // operation only available for super table -TAOS_DEFINE_ERROR(TSDB_CODE_MND_COL_NAME_TOO_LONG, 0, 0x0367, "mnode column name too long") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_ALREAY_EXIST, 0, 0x0368, "mnode tag already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_NOT_EXIST, 0, 0x0369, "mnode tag not exist") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_ALREAY_EXIST, 0, 0x036A, "mnode field already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_NOT_EXIST, 0, 0x036B, "mnode field not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_NAME, 0, 0x0362, "mnode invalid table name") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_TYPE, 0, 0x0363, "mnode invalid table type") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TAGS, 0, 0x0364, "mnode too many tags") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TABLES, 0, 0x0365, "mnode too many tables") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TIMESERIES, 0, 0x0366, "mnode not enough time series") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_NOT_SUPER_TABLE, 0, 0x0367, "mnode no super table") // operation only available for super table +TAOS_DEFINE_ERROR(TSDB_CODE_MND_COL_NAME_TOO_LONG, 0, 0x0368, "mnode column name too long") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_ALREAY_EXIST, 0, 0x0369, "mnode tag already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_NOT_EXIST, 0, 0x036A, "mnode tag not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_ALREAY_EXIST, 0, 0x036B, "mnode field already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_NOT_EXIST, 0, 0x036C, "mnode field not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_NOT_SELECTED, 0, 0x0380, "mnode db not selected") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_ALREADY_EXIST, 0, 0x0381, "mnode database aleady exist") diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 2077d6f43e..119ba1627d 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -714,7 +714,7 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) { return TSDB_CODE_SUCCESS; } else { mError("table:%s, failed to drop table, table not exist", pDrop->tableId); - return TSDB_CODE_MND_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_NAME; } } @@ -742,7 +742,7 @@ static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) { if (pMsg->pTable == NULL) { if (!pInfo->createFlag) { mError("table:%s, failed to get table meta, table not exist", pInfo->tableId); - return TSDB_CODE_MND_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_NAME; } else { mTrace("table:%s, failed to get table meta, start auto create table ", pInfo->tableId); return mnodeAutoCreateChildTable(pMsg); @@ -779,7 +779,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { if (pStable->schema == NULL) { free(pStable); mError("table:%s, failed to create, no schema input", pCreate->tableId); - return TSDB_CODE_MND_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_NAME; } memcpy(pStable->schema, pCreate->schema, numOfCols * sizeof(SSchema)); @@ -1340,7 +1340,7 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) { if (pRsp->numOfTables != numOfTable) { rpcFreeCont(pRsp); - return TSDB_CODE_MND_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_NAME; } else { pRsp->numOfTables = htonl(pRsp->numOfTables); pMsg->rpcRsp.rsp = pRsp; @@ -1452,7 +1452,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb if (pSuperTable == NULL) { mError("table:%s, corresponding super table:%s does not exist", pCreate->tableId, pTagData->name); mnodeDestroyChildTable(pTable); - terrno = TSDB_CODE_MND_INVALID_TABLE_ID; + terrno = TSDB_CODE_MND_INVALID_TABLE_NAME; return NULL; } mnodeDecTableRef(pSuperTable); @@ -2212,7 +2212,7 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) { if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pAlter->tableId); if (pMsg->pTable == NULL) { mError("table:%s, failed to alter table, table not exist", pMsg->pTable->tableId); - return TSDB_CODE_MND_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_NAME; } pAlter->type = htons(pAlter->type); diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 7274c879c6..25b9daf00c 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -383,11 +383,11 @@ int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { pTable = mnodeGetTable(pShow->payload); if (NULL == pTable || pTable->type == TSDB_SUPER_TABLE) { mnodeDecTableRef(pTable); - return TSDB_CODE_MND_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_NAME; } mnodeDecTableRef(pTable); pVgroup = mnodeGetVgroup(((SChildTableObj*)pTable)->vgId); - if (NULL == pVgroup) return TSDB_CODE_MND_INVALID_TABLE_ID; + if (NULL == pVgroup) return TSDB_CODE_MND_INVALID_TABLE_NAME; mnodeDecVgroupRef(pVgroup); maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica; } else { diff --git a/src/plugins/http/src/httpJson.c b/src/plugins/http/src/httpJson.c index 950258533f..e5e69ae02a 100644 --- a/src/plugins/http/src/httpJson.c +++ b/src/plugins/http/src/httpJson.c @@ -445,7 +445,7 @@ void httpJsonPairStatus(JsonBuf* buf, int code) { httpJsonItemToken(buf); if (code == TSDB_CODE_MND_DB_NOT_SELECTED) { httpJsonPair(buf, "desc", 4, "failed to create database", 23); - } else if (code == TSDB_CODE_MND_INVALID_TABLE_ID) { + } else if (code == TSDB_CODE_MND_INVALID_TABLE_NAME) { httpJsonPair(buf, "desc", 4, "failed to create table", 22); } else httpJsonPair(buf, "desc", 4, (char*)tstrerror(code), (int)strlen(tstrerror(code))); diff --git a/src/plugins/http/src/tgJson.c b/src/plugins/http/src/tgJson.c index 6c0b3c8663..ed33f51d46 100644 --- a/src/plugins/http/src/tgJson.c +++ b/src/plugins/http/src/tgJson.c @@ -111,7 +111,7 @@ bool tgCheckFinished(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) { pContext->ipstr); return false; } - } else if (code == TSDB_CODE_MND_INVALID_TABLE_ID) { + } else if (code == TSDB_CODE_MND_INVALID_TABLE_NAME) { cmd->cmdState = HTTP_CMD_STATE_RUN_FINISHED; if (multiCmds->cmds[multiCmds->pos - 1].cmdState == HTTP_CMD_STATE_NOT_RUN_YET) { multiCmds->pos = (int16_t)(multiCmds->pos - 2); diff --git a/tests/script/general/http/restful_full.sim b/tests/script/general/http/restful_full.sim index 7194f7cbe0..aa667daee4 100644 --- a/tests/script/general/http/restful_full.sim +++ b/tests/script/general/http/restful_full.sim @@ -147,7 +147,7 @@ print =============== step3 - db system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1;' 127.0.0.1:6020/rest/sql print 21-> $system_content -if $system_content != @{"status":"error","code":1000,"desc":"mnode invalid table id"}@ then +if $system_content != @{"status":"error","code":1000,"desc":"mnode invalid table name"}@ then return -1 endi From aaba26a52e0864ef0777b8e91ee7b0a0f568da44 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Mon, 8 Jun 2020 11:27:28 +0000 Subject: [PATCH 64/72] fix issue that dnodes reploy delete psim log file [TD-561] --- tests/pytest/util/dnodes.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index f3ccd58432..e24af473f3 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -319,6 +319,7 @@ class TDDnodes: self.dnodes.append(TDDnode(8)) self.dnodes.append(TDDnode(9)) self.dnodes.append(TDDnode(10)) + self.simDeployed = False def init(self, path): psCmd = "ps -ef|grep -w taosd| grep -v grep | awk '{print $2}'" @@ -378,7 +379,10 @@ class TDDnodes: self.sim = TDSimClient() self.sim.init(self.path) self.sim.setTestCluster(self.testCluster) - self.sim.deploy() + + if (self.simDeployed == False): + self.sim.deploy() + self.simDeployed = True self.check(index) self.dnodes[index - 1].setTestCluster(self.testCluster) From 0f928893e0afbcaade07743a4fa73c0369dc5cb1 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 14:27:37 +0000 Subject: [PATCH 65/72] [TD_543] fix coverity scan, cid:267815 --- src/plugins/http/src/tgHandle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index ffb2ccb2f9..ac3df051fd 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -303,7 +303,7 @@ bool tgGetUserFromUrl(HttpContext *pContext) { return false; } - strcpy(pContext->user, pParser->path[TG_USER_URL_POS].pos); + tstrncpy(pContext->user, pParser->path[TG_USER_URL_POS].pos, TSDB_USER_LEN); return true; } From dadb3adecc12178a97b4521680f3108c8507259e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 14:29:43 +0000 Subject: [PATCH 66/72] [TD_543] fix coverity scan, cid:267813 --- src/kit/taosdump/taosdump.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index f03b46ac47..d96f80ed20 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -646,10 +646,9 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) { taosDumpTable(tableRecord.name, tableRecord.metric, arguments, fp); } - tclose(fd); - remove(".table.tmp"); + close(fd); - return 0; + return remove(".table.tmp"); } void taosDumpCreateTableClause(STableDef *tableDes, int numOfCols, SDumpArguments *arguments, FILE *fp) { From a8d35dbc49785d280866d61dfaecc942a594b063 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 14:44:55 +0000 Subject: [PATCH 67/72] [TD_543] fix coverity scan, cid:267820 267853 --- src/kit/shell/src/shellEngine.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 954f2cb8a3..f04607f6fa 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -727,10 +727,6 @@ void read_history() { char f_history[TSDB_FILENAME_LEN]; get_history_path(f_history); - if (access(f_history, R_OK) == -1) { - return; - } - FILE *f = fopen(f_history, "r"); if (f == NULL) { fprintf(stderr, "Opening file %s\n", f_history); @@ -809,14 +805,6 @@ void source_file(TAOS *con, char *fptr) { return; } - if (access(fname, R_OK) != 0) { - fprintf(stderr, "ERROR: file %s is not readable\n", fptr); - - wordfree(&full_path); - free(cmd); - return; - } - FILE *f = fopen(fname, "r"); if (f == NULL) { fprintf(stderr, "ERROR: failed to open file %s\n", fname); From 45f66a9498267ac106cf1a478fd9b00b07c09377 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 15:07:48 +0000 Subject: [PATCH 68/72] [TD_543] fix coverity scan, cid:267826 --- src/util/src/tlog.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 47521fc36e..01a0eabbca 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -191,15 +191,14 @@ void taosResetLog() { } static bool taosCheckFileIsOpen(char *logFileName) { - int32_t exist = access(logFileName, F_OK); - if (exist != 0) { - return false; - } - - int32_t fd = open(logFileName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); + int32_t fd = open(logFileName, O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); if (fd < 0) { - printf("\nfailed to open log file:%s, reason:%s\n", logFileName, strerror(errno)); - return true; + if (errno == ENOENT) { + return false; + } else { + printf("\nfailed to open log file:%s, reason:%s\n", logFileName, strerror(errno)); + return true; + } } if (taosLockFile(fd)) { From 5580212d045b825999ebac3a6b1b3a25d02588f3 Mon Sep 17 00:00:00 2001 From: Steven Li Date: Mon, 8 Jun 2020 17:37:31 -0700 Subject: [PATCH 69/72] Added errno to Python client, plus minor tweaks --- src/connector/python/linux/python2/taos/cursor.py | 2 +- src/connector/python/linux/python3/taos/cursor.py | 2 +- src/connector/python/windows/python2/taos/cursor.py | 2 +- src/connector/python/windows/python3/taos/cursor.py | 2 +- tests/pytest/crash_gen.py | 10 ++++++---- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/connector/python/linux/python2/taos/cursor.py b/src/connector/python/linux/python2/taos/cursor.py index f7c840442e..8c268d8afb 100644 --- a/src/connector/python/linux/python2/taos/cursor.py +++ b/src/connector/python/linux/python2/taos/cursor.py @@ -137,7 +137,7 @@ class TDengineCursor(object): else: raise ProgrammingError( CTaosInterface.errStr( - self._result )) + self._result ), errno) def executemany(self, operation, seq_of_parameters): """Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. diff --git a/src/connector/python/linux/python3/taos/cursor.py b/src/connector/python/linux/python3/taos/cursor.py index 5db5365eb3..06d6a19462 100644 --- a/src/connector/python/linux/python3/taos/cursor.py +++ b/src/connector/python/linux/python3/taos/cursor.py @@ -139,7 +139,7 @@ class TDengineCursor(object): else: raise ProgrammingError( CTaosInterface.errStr( - self._result )) + self._result), errno) def executemany(self, operation, seq_of_parameters): """Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. diff --git a/src/connector/python/windows/python2/taos/cursor.py b/src/connector/python/windows/python2/taos/cursor.py index 1da726638a..7eee3bfc8f 100644 --- a/src/connector/python/windows/python2/taos/cursor.py +++ b/src/connector/python/windows/python2/taos/cursor.py @@ -117,7 +117,7 @@ class TDengineCursor(object): self._fields = CTaosInterface.useResult(self._result) return self._handle_result() else: - raise ProgrammingError(CTaosInterface.errStr(self._result)) + raise ProgrammingError(CTaosInterface.errStr(self._result), errno) def executemany(self, operation, seq_of_parameters): """Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. diff --git a/src/connector/python/windows/python3/taos/cursor.py b/src/connector/python/windows/python3/taos/cursor.py index 2dcd0aaccb..5f5aa4e1d7 100644 --- a/src/connector/python/windows/python3/taos/cursor.py +++ b/src/connector/python/windows/python3/taos/cursor.py @@ -117,7 +117,7 @@ class TDengineCursor(object): self._fields = CTaosInterface.useResult(self._result ) return self._handle_result() else: - raise ProgrammingError(CTaosInterface.errStr(self._result )) + raise ProgrammingError(CTaosInterface.errStr(self._result ), errno) def executemany(self, operation, seq_of_parameters): """Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. diff --git a/tests/pytest/crash_gen.py b/tests/pytest/crash_gen.py index dfd2034f7e..c88683aa09 100755 --- a/tests/pytest/crash_gen.py +++ b/tests/pytest/crash_gen.py @@ -730,13 +730,15 @@ class DbState(): # when we re-run the test in 3 minutes (180 seconds), basically we should expand time duration # by a factor of 500. # TODO: what if it goes beyond 10 years into the future + # TODO: fix the error as result of above: "tsdb timestamp is out of range" def setupLastTick(self): - t1 = datetime.datetime(2020, 5, 30) + t1 = datetime.datetime(2020, 6, 1) t2 = datetime.datetime.now() - elSec = t2.timestamp() - t1.timestamp() + elSec = int(t2.timestamp() - t1.timestamp()) # maybe a very large number, takes 69 years to exceed Python int range + elSec2 = ( elSec % (8 * 12 * 30 * 24 * 60 * 60 / 500 ) ) * 500 # a number representing seconds within 10 years # print("elSec = {}".format(elSec)) t3 = datetime.datetime(2012, 1, 1) # default "keep" is 10 years - t4 = datetime.datetime.fromtimestamp( t3.timestamp() + elSec * 500) # see explanation above + t4 = datetime.datetime.fromtimestamp( t3.timestamp() + elSec2) # see explanation above logger.info("Setting up TICKS to start from: {}".format(t4)) return t4 @@ -963,7 +965,7 @@ class Task(): try: self._executeInternal(te, wt) # TODO: no return value? except taos.error.ProgrammingError as err: - self.logDebug("[=] Taos library exception: errno={}, msg: {}".format(err.errno, err)) + self.logDebug("[=] Taos library exception: errno={:X}, msg: {}".format(err.errno, err)) self._err = err except: self.logDebug("[=] Unexpected exception") From 78c1351f9932ea20dccb4dc3385cda253282e80d Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Tue, 9 Jun 2020 00:58:04 +0000 Subject: [PATCH 70/72] failed to open TCP server socket, return error for RPC initialization --- src/dnode/src/dnodeSystem.c | 1 + src/rpc/src/rpcTcp.c | 25 +++++++++-------- src/rpc/src/rpcUdp.c | 54 ++++++++++++++++++++----------------- 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/src/dnode/src/dnodeSystem.c b/src/dnode/src/dnodeSystem.c index 97cf6f7eeb..0a983362c2 100644 --- a/src/dnode/src/dnodeSystem.c +++ b/src/dnode/src/dnodeSystem.c @@ -92,6 +92,7 @@ int32_t main(int32_t argc, char *argv[]) { // Initialize the system if (dnodeInitSystem() < 0) { syslog(LOG_ERR, "Error initialize TDengine system"); + dPrint("Failed to start TDengine, please check the log at:%s", tsLogDir); closelog(); exit(EXIT_FAILURE); } diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 04a269502e..7035b30b66 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -67,7 +67,7 @@ static void *taosProcessTcpData(void *param); static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, int fd); static void taosFreeFdObj(SFdObj *pFdObj); static void taosReportBrokenLink(SFdObj *pFdObj); -static void* taosAcceptTcpConnection(void *arg); +static void *taosAcceptTcpConnection(void *arg); void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThreads, void *fp, void *shandle) { SServerObj *pServerObj; @@ -80,6 +80,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread return NULL; } + pServerObj->fd = -1; pServerObj->thread = 0; pServerObj->ip = ip; pServerObj->port = port; @@ -99,6 +100,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread pthread_attr_init(&thattr); pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); + // initialize parameters in case it may encounter error later pThreadObj = pServerObj->pThreadObj; for (int i = 0; i < numOfThreads; ++i) { pThreadObj->pollFd = -1; @@ -106,18 +108,21 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread pThreadObj->processData = fp; tstrncpy(pThreadObj->label, label, sizeof(pThreadObj->label)); pThreadObj->shandle = shandle; + pThreadObj++; + } + // initialize mutex, thread, fd which may fail + pThreadObj = pServerObj->pThreadObj; + for (int i = 0; i < numOfThreads; ++i) { code = pthread_mutex_init(&(pThreadObj->mutex), NULL); if (code < 0) { tError("%s failed to init TCP process data mutex(%s)", label, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); break;; } pThreadObj->pollFd = epoll_create(10); // size does not matter if (pThreadObj->pollFd < 0) { tError("%s failed to create TCP epoll", label); - terrno = TAOS_SYSTEM_ERROR(errno); code = -1; break; } @@ -125,7 +130,6 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread code = pthread_create(&(pThreadObj->thread), &thattr, taosProcessTcpData, (void *)(pThreadObj)); if (code != 0) { tError("%s failed to create TCP process data thread(%s)", label, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); break; } @@ -133,15 +137,18 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread pThreadObj++; } + pServerObj->fd = taosOpenTcpServerSocket(pServerObj->ip, pServerObj->port); + if (pServerObj->fd < 0) code = -1; + if (code == 0) { - code = pthread_create(&(pServerObj->thread), &thattr, (void *)taosAcceptTcpConnection, (void *)(pServerObj)); + code = pthread_create(&pServerObj->thread, &thattr, taosAcceptTcpConnection, (void *)pServerObj); if (code != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); tError("%s failed to create TCP accept thread(%s)", label, strerror(errno)); } } if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); taosCleanUpTcpServer(pServerObj); pServerObj = NULL; } else { @@ -204,7 +211,7 @@ void taosCleanUpTcpServer(void *handle) { tfree(pServerObj); } -static void* taosAcceptTcpConnection(void *arg) { +static void *taosAcceptTcpConnection(void *arg) { int connFd = -1; struct sockaddr_in caddr; int threadId = 0; @@ -212,10 +219,6 @@ static void* taosAcceptTcpConnection(void *arg) { SServerObj *pServerObj; pServerObj = (SServerObj *)arg; - - pServerObj->fd = taosOpenTcpServerSocket(pServerObj->ip, pServerObj->port); - if (pServerObj->fd < 0) return NULL; - tTrace("%s TCP server is ready, ip:0x%x:%hu", pServerObj->label, pServerObj->ip, pServerObj->port); while (1) { diff --git a/src/rpc/src/rpcUdp.c b/src/rpc/src/rpcUdp.c index 7e2fe0db61..279cf7ed49 100644 --- a/src/rpc/src/rpcUdp.c +++ b/src/rpc/src/rpcUdp.c @@ -19,6 +19,7 @@ #include "ttimer.h" #include "tutil.h" #include "taosdef.h" +#include "taoserror.h" #include "rpcLog.h" #include "rpcUdp.h" #include "rpcHead.h" @@ -65,6 +66,7 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads pSet = (SUdpConnSet *)malloc((size_t)size); if (pSet == NULL) { tError("%s failed to allocate UdpConn", label); + terrno = TAOS_SYSTEM_ERROR(errno); return NULL; } @@ -73,30 +75,34 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads pSet->port = port; pSet->shandle = shandle; pSet->fp = fp; + pSet->threads = threads; tstrncpy(pSet->label, label, sizeof(pSet->label)); + pthread_attr_t thAttr; + pthread_attr_init(&thAttr); + pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE); + + int i; uint16_t ownPort; - for (int i = 0; i < threads; ++i) { + for (i = 0; i < threads; ++i) { pConn = pSet->udpConn + i; ownPort = (port ? port + i : 0); pConn->fd = taosOpenUdpSocket(ip, ownPort); if (pConn->fd < 0) { tError("%s failed to open UDP socket %x:%hu", label, ip, port); - taosCleanUpUdpConnection(pSet); - return NULL; + break; } pConn->buffer = malloc(RPC_MAX_UDP_SIZE); if (NULL == pConn->buffer) { tError("%s failed to malloc recv buffer", label); - taosCleanUpUdpConnection(pSet); - return NULL; + break; } struct sockaddr_in sin; unsigned int addrlen = sizeof(sin); - if (getsockname(pConn->fd, (struct sockaddr *)&sin, &addrlen) == 0 && sin.sin_family == AF_INET && - addrlen == sizeof(sin)) { + if (getsockname(pConn->fd, (struct sockaddr *)&sin, &addrlen) == 0 && + sin.sin_family == AF_INET && addrlen == sizeof(sin)) { pConn->localPort = (uint16_t)ntohs(sin.sin_port); } @@ -107,23 +113,22 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads pConn->pSet = pSet; pConn->signature = pConn; - pthread_attr_t thAttr; - pthread_attr_init(&thAttr); - pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE); int code = pthread_create(&pConn->thread, &thAttr, taosRecvUdpData, pConn); - pthread_attr_destroy(&thAttr); if (code != 0) { - tError("%s failed to create thread to process UDP data, reason:%s", label, strerror(errno)); - taosCloseSocket(pConn->fd); - taosCleanUpUdpConnection(pSet); - return NULL; + tError("%s failed to create thread to process UDP data(%s)", label, strerror(errno)); + break; } - - ++pSet->threads; } - tTrace("%s UDP connection is initialized, ip:%x port:%hu threads:%d", label, ip, port, threads); + pthread_attr_destroy(&thAttr); + if (i != threads) { + terrno = TAOS_SYSTEM_ERROR(errno); + taosCleanUpUdpConnection(pSet); + return NULL; + } + + tTrace("%s UDP connection is initialized, ip:%x:%hu threads:%d", label, ip, port, threads); return pSet; } @@ -136,16 +141,17 @@ void taosCleanUpUdpConnection(void *handle) { for (int i = 0; i < pSet->threads; ++i) { pConn = pSet->udpConn + i; pConn->signature = NULL; + // shutdown to signal the thread to exit - shutdown(pConn->fd, SHUT_RD); + if ( pConn->fd >=0) shutdown(pConn->fd, SHUT_RD); } for (int i = 0; i < pSet->threads; ++i) { pConn = pSet->udpConn + i; - pthread_join(pConn->thread, NULL); - free(pConn->buffer); - taosCloseSocket(pConn->fd); - tTrace("chandle:%p is closed", pConn); + if (pConn->thread) pthread_join(pConn->thread, NULL); + if (pConn->fd >=0) taosCloseSocket(pConn->fd); + tfree(pConn->buffer); + tTrace("UDP chandle:%p is closed", pConn); } tfree(pSet); @@ -159,7 +165,7 @@ void *taosOpenUdpConnection(void *shandle, void *thandle, uint32_t ip, uint16_t SUdpConn *pConn = pSet->udpConn + pSet->index; pConn->port = port; - tTrace("%s UDP connection is setup, ip:%x:%hu, local:%x:%d", pConn->label, ip, port, pSet->ip, pConn->localPort); + tTrace("%s UDP connection is setup, ip:%x:%hu", pConn->label, ip, port); return pConn; } From da7fd6459a955b21942f567eb1c8b76d079bea4d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 9 Jun 2020 02:40:31 +0000 Subject: [PATCH 71/72] [TD_543] fix coverity scan, cid:267831 --- src/plugins/http/src/gcHandle.c | 22 +++++++++++++++++++-- src/plugins/http/src/httpSql.c | 2 +- src/plugins/http/src/restHandle.c | 32 ++++++++++++++++++++++++++++--- src/plugins/http/src/tgHandle.c | 13 ++++++++++--- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/plugins/http/src/gcHandle.c b/src/plugins/http/src/gcHandle.c index fbe6757ccb..4120980123 100644 --- a/src/plugins/http/src/gcHandle.c +++ b/src/plugins/http/src/gcHandle.c @@ -22,9 +22,27 @@ #include "taosdef.h" static HttpDecodeMethod gcDecodeMethod = {"grafana", gcProcessRequest}; -static HttpEncodeMethod gcHeartBeatMethod = {NULL, gcSendHeartBeatResp, NULL, NULL, NULL, NULL, NULL, NULL}; +static HttpEncodeMethod gcHeartBeatMethod = { + .startJsonFp = NULL, + .stopJsonFp = gcSendHeartBeatResp, + .buildQueryJsonFp = NULL, + .buildAffectRowJsonFp = NULL, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod gcQueryMethod = { - NULL, gcStopQueryJson, gcBuildQueryJson, NULL, gcInitQueryJson, gcCleanQueryJson, NULL, NULL}; + .startJsonFp = NULL, + .stopJsonFp = gcStopQueryJson, + .buildQueryJsonFp = gcBuildQueryJson, + .buildAffectRowJsonFp = NULL, + .initJsonFp = gcInitQueryJson, + .cleanJsonFp = gcCleanQueryJson, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; void gcInitHandle(HttpServer* pServer) { httpAddMethod(pServer, &gcDecodeMethod); } diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index af9ad8e38a..6ff93b3e8a 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -87,7 +87,7 @@ void httpProcessMultiSqlCallBack(void *param, TAOS_RES *result, int code) { } if (code < 0) { - if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, code >= 0 ? 0 : code)) { + if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, -code)) { singleCmd->code = code; httpTrace("context:%p, fd:%d, ip:%s, user:%s, process pos jump to:%d, last code:%s, last sql:%s", pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos + 1, tstrerror(code), sql); diff --git a/src/plugins/http/src/restHandle.c b/src/plugins/http/src/restHandle.c index a2dc7d06a1..d481a654d8 100644 --- a/src/plugins/http/src/restHandle.c +++ b/src/plugins/http/src/restHandle.c @@ -22,11 +22,37 @@ static HttpDecodeMethod restDecodeMethod = {"rest", restProcessRequest}; static HttpDecodeMethod restDecodeMethod2 = {"restful", restProcessRequest}; static HttpEncodeMethod restEncodeSqlTimestampMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlTimestampJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlTimestampJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod restEncodeSqlLocalTimeStringMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlLocalTimeStringJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlLocalTimeStringJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod restEncodeSqlUtcTimeStringMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlUtcTimeStringJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlUtcTimeStringJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; void restInitHandle(HttpServer* pServer) { httpAddMethod(pServer, &restDecodeMethod); diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index ac3df051fd..c6a2230bfb 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -62,9 +62,16 @@ #define TG_MAX_SORT_TAG_SIZE 20 static HttpDecodeMethod tgDecodeMethod = {"telegraf", tgProcessRquest}; -static HttpEncodeMethod tgQueryMethod = {tgStartQueryJson, tgStopQueryJson, NULL, - tgBuildSqlAffectRowsJson, tgInitQueryJson, tgCleanQueryJson, - tgCheckFinished, tgSetNextCmd}; +static HttpEncodeMethod tgQueryMethod = { + .startJsonFp = tgStartQueryJson, + .stopJsonFp = tgStopQueryJson, + .buildQueryJsonFp = NULL, + .buildAffectRowJsonFp = tgBuildSqlAffectRowsJson, + .initJsonFp = tgInitQueryJson, + .cleanJsonFp = tgCleanQueryJson, + .checkFinishedFp = tgCheckFinished, + .setNextCmdFp = tgSetNextCmd +}; static const char DEFAULT_TELEGRAF_CFG[] = "{\"metrics\":[" From 0495644242a932c29699b1143a6b2f3307151e73 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 9 Jun 2020 03:18:51 +0000 Subject: [PATCH 72/72] [TD_543] fix coverity scan, cid:267845 267846 --- src/client/src/tscSystem.c | 2 +- src/os/linux/src/linuxSysPara.c | 93 ++++++--------------------------- 2 files changed, 18 insertions(+), 77 deletions(-) diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index d3c8eefbb9..fd7d31aa9f 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -201,7 +201,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { tscPrint("set shellActivityTimer:%d", tsShellActivityTimer); } else { tscWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, pStr, - tsCfgStatusStr[cfg->cfgStatus], (int32_t *)cfg->ptr); + tsCfgStatusStr[cfg->cfgStatus], *(int32_t *)cfg->ptr); } break; diff --git a/src/os/linux/src/linuxSysPara.c b/src/os/linux/src/linuxSysPara.c index ca244dcd94..b270eb14cf 100644 --- a/src/os/linux/src/linuxSysPara.c +++ b/src/os/linux/src/linuxSysPara.c @@ -331,66 +331,7 @@ bool taosGetDisk() { return true; } -static bool taosGetCardName(char *ip, char *name) { - struct ifaddrs *ifaddr, *ifa; - int family, s; - char host[NI_MAXHOST]; - bool ret = false; - - if (getifaddrs(&ifaddr) == -1) { - return false; - } - - /* Walk through linked list, maintaining head pointer so we can free list - * later */ - for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) continue; - - family = ifa->ifa_addr->sa_family; - if (family != AF_INET) { - continue; - } - - s = getnameinfo(ifa->ifa_addr, (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), host, - NI_MAXHOST, NULL, 0, NI_NUMERICHOST); - if (s != 0) { - break; - } - - if (strcmp(host, "127.0.0.1") == 0) { - continue; - } - - // TODO: the ip not config - // if (strcmp(host, ip) == 0) { - strcpy(name, ifa->ifa_name); - ret = true; - // } - } - - freeifaddrs(ifaddr); - return ret; -} - static bool taosGetCardInfo(int64_t *bytes) { - static char tsPublicCard[1000] = {0}; - static char tsPrivateIp[40]; - - if (tsPublicCard[0] == 0) { - if (!taosGetCardName(tsPrivateIp, tsPublicCard)) { - uError("can't get card name from ip:%s", tsPrivateIp); - return false; - } - int cardNameLen = (int)strlen(tsPublicCard); - for (int i = 0; i < cardNameLen; ++i) { - if (tsPublicCard[i] == ':') { - tsPublicCard[i] = 0; - break; - } - } - // uTrace("card name of public ip:%s is %s", tsPublicIp, tsPublicCard); - } - FILE *fp = fopen(tsSysNetFile, "r"); if (fp == NULL) { uError("open file:%s failed", tsSysNetFile); @@ -403,6 +344,7 @@ static bool taosGetCardInfo(int64_t *bytes) { size_t len; char * line = NULL; + *bytes = 0; while (!feof(fp)) { tfree(line); @@ -411,23 +353,20 @@ static bool taosGetCardInfo(int64_t *bytes) { if (line == NULL) { break; } - if (strstr(line, tsPublicCard) != NULL) { - break; + if (strstr(line, "lo:") != NULL) { + continue; } + + sscanf(line, + "%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64, + nouse0, &rbytes, &rpackts, &nouse1, &nouse2, &nouse3, &nouse4, &nouse5, &nouse6, &tbytes, &tpackets); + *bytes += (rbytes + tbytes); } - if (line != NULL) { - sscanf(line, "%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64, nouse0, &rbytes, &rpackts, &nouse1, &nouse2, &nouse3, - &nouse4, &nouse5, &nouse6, &tbytes, &tpackets); - *bytes = rbytes + tbytes; - tfree(line); - fclose(fp); - return true; - } else { - uWarn("can't get card:%s info from device:%s", tsPublicCard, tsSysNetFile); - *bytes = 0; - fclose(fp); - return false; - } + + tfree(line); + fclose(fp); + + return true; } bool taosGetBandSpeed(float *bandSpeedKb) { @@ -443,13 +382,15 @@ bool taosGetBandSpeed(float *bandSpeedKb) { if (lastTime == 0 || lastBytes == 0) { lastTime = curTime; lastBytes = curBytes; - return false; + *bandSpeedKb = 0; + return true; } if (lastTime >= curTime || lastBytes > curBytes) { lastTime = curTime; lastBytes = curBytes; - return false; + *bandSpeedKb = 0; + return true; } double totalBytes = (double)(curBytes - lastBytes) / 1024 * 8; // Kb