diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h
index 6666fa24a605c186678b2642b9735432b75a8df4..0c485894e66bc27db892e831019e6e23c114299b 100644
--- a/src/client/inc/tscUtil.h
+++ b/src/client/inc/tscUtil.h
@@ -107,14 +107,6 @@ void tscAddSpecialColumnForSelect(SSqlCmd* pCmd, int32_t outputColIndex, int16_t
void addRequiredTagColumn(SSqlCmd* pCmd, int32_t tagColIndex, int32_t tableIndex);
-//TODO refactor, remove
-void SStringFree(SString* str);
-void SStringCopy(SString* pDest, const SString* pSrc);
-SString SStringCreate(const char* str);
-
-int32_t SStringAlloc(SString* pStr, int32_t size);
-int32_t SStringEnsureRemain(SString* pStr, int32_t size);
-
int32_t setMeterID(SSqlObj* pSql, SSQLToken* pzTableName, int32_t tableIndex);
void tscClearInterpInfo(SSqlCmd* pCmd);
diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h
index 6226cf1f1d836c8ba42d131b42c03a644ba0ce74..d439ba9929ac7c58eb08d946cc7289fd1d8dbee7 100644
--- a/src/client/inc/tsclient.h
+++ b/src/client/inc/tsclient.h
@@ -188,7 +188,7 @@ typedef struct SString {
typedef struct SCond {
uint64_t uid;
- SString cond;
+ char* cond;
} SCond;
typedef struct SJoinNode {
diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c
index d11a279247ff170ba4b931b11a93589e3e2b3693..abf91e7c4339bdebe7c72f14551da0e1d53132c5 100644
--- a/src/client/src/tscAsync.c
+++ b/src/client/src/tscAsync.c
@@ -51,7 +51,7 @@ void taos_query_a(TAOS *taos, const char *sqlstr, void (*fp)(void *, TAOS_RES *,
}
int32_t sqlLen = strlen(sqlstr);
- if (sqlLen > TSDB_MAX_SQL_LEN) {
+ if (sqlLen > tsMaxSQLStringLen) {
tscError("sql string too long");
tscQueueAsyncError(fp, param);
return;
diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c
index 233a37dc5930f8b5d16d608882ced99148493c4f..4d7f2734a940500f04af0c2cf1abb4ac8f6e6335 100644
--- a/src/client/src/tscSql.c
+++ b/src/client/src/tscSql.c
@@ -270,7 +270,7 @@ int taos_query(TAOS *taos, const char *sqlstr) {
SSqlRes *pRes = &pSql->res;
size_t sqlLen = strlen(sqlstr);
- if (sqlLen > TSDB_MAX_SQL_LEN) {
+ if (sqlLen > tsMaxSQLStringLen) {
pRes->code = tscInvalidSQLErrMsg(pSql->cmd.payload, "sql too long", NULL); // set the additional error msg for invalid sql
tscError("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
@@ -786,7 +786,6 @@ int taos_errno(TAOS *taos) {
char *taos_errstr(TAOS *taos) {
STscObj *pObj = (STscObj *)taos;
uint8_t code;
-// char temp[256] = {0};
if (pObj == NULL || pObj->signature != pObj) return tsError[globalCode];
@@ -797,11 +796,13 @@ char *taos_errstr(TAOS *taos) {
// for invalid sql, additional information is attached to explain why the sql is invalid
if (code == TSDB_CODE_INVALID_SQL) {
-// snprintf(temp, tListLen(temp), "invalid SQL: %s", pObj->pSql->cmd.payload);
-// strcpy(pObj->pSql->cmd.payload, temp);
return pObj->pSql->cmd.payload;
} else {
- return tsError[code];
+ if (code < 0 || code > TSDB_CODE_MAX_ERROR_CODE) {
+ return tsError[TSDB_CODE_SUCCESS];
+ } else {
+ return tsError[code];
+ }
}
}
@@ -924,7 +925,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) {
tscTrace("%p Valid SQL: %s pObj:%p", pSql, sql, pObj);
int32_t sqlLen = strlen(sql);
- if (sqlLen > TSDB_MAX_SQL_LEN) {
+ if (sqlLen > tsMaxSQLStringLen) {
tscError("%p sql too long", pSql);
pRes->code = TSDB_CODE_INVALID_SQL;
return pRes->code;
diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c
index baafb57f6a57b924b22abe71460ed5cd034ff853..7fd3d7706bc4bf7234593b29f51bff7fc04f417d 100644
--- a/src/client/src/tscUtil.c
+++ b/src/client/src/tscUtil.c
@@ -51,7 +51,6 @@ void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* str, uint64_t uid) {
assert(len < tListLen(tagIdBuf));
const int32_t maxKeySize = TSDB_MAX_TAGS_LEN; // allowed max key size
- char* tmp = calloc(1, TSDB_MAX_SQL_LEN);
SCond* cond = tsGetMetricQueryCondPos(pTagCond, uid);
@@ -60,12 +59,24 @@ void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* str, uint64_t uid) {
sprintf(join, "%s,%s", pTagCond->joinInfo.left.meterId, pTagCond->joinInfo.right.meterId);
}
- int32_t keyLen =
- snprintf(tmp, TSDB_MAX_SQL_LEN, "%s,%s,%s,%d,%s,[%s],%d", pMeterMetaInfo->name,
- (cond != NULL ? cond->cond.z : NULL), pTagCond->tbnameCond.cond.n > 0 ? pTagCond->tbnameCond.cond.z : NULL,
+ // estimate the buffer size
+ size_t tbnameCondLen = pTagCond->tbnameCond.cond != NULL? strlen(pTagCond->tbnameCond.cond):0;
+ size_t redundantLen = 20;
+
+ size_t bufSize = strlen(pMeterMetaInfo->name) + tbnameCondLen + strlen(join) + strlen(tagIdBuf);
+ if (cond != NULL) {
+ bufSize += strlen(cond->cond);
+ }
+
+ bufSize = (size_t) ((bufSize + redundantLen) * 1.5);
+ char* tmp = calloc(1, bufSize);
+
+ int32_t keyLen = snprintf(tmp, bufSize, "%s,%s,%s,%d,%s,[%s],%d", pMeterMetaInfo->name,
+ (cond != NULL ? cond->cond : NULL),
+ (tbnameCondLen > 0 ? pTagCond->tbnameCond.cond : NULL),
pTagCond->relType, join, tagIdBuf, pCmd->groupbyExpr.orderType);
- assert(keyLen <= TSDB_MAX_SQL_LEN);
+ assert(keyLen <= bufSize);
if (keyLen < maxKeySize) {
strcpy(str, tmp);
@@ -99,7 +110,7 @@ void tsSetMetricQueryCond(STagCond* pTagCond, uint64_t uid, const char* str) {
SCond* pDest = &pTagCond->cond[pTagCond->numOfTagCond];
pDest->uid = uid;
- pDest->cond = SStringCreate(str);
+ pDest->cond = strdup(str);
pTagCond->numOfTagCond += 1;
}
@@ -1340,14 +1351,20 @@ bool tscValidateColumnId(SSqlCmd* pCmd, int32_t colId) {
void tscTagCondCopy(STagCond* dest, const STagCond* src) {
memset(dest, 0, sizeof(STagCond));
+
+ if (src->tbnameCond.cond != NULL) {
+ dest->tbnameCond.cond = strdup(src->tbnameCond.cond);
+ }
- SStringCopy(&dest->tbnameCond.cond, &src->tbnameCond.cond);
dest->tbnameCond.uid = src->tbnameCond.uid;
memcpy(&dest->joinInfo, &src->joinInfo, sizeof(SJoinInfo));
for (int32_t i = 0; i < src->numOfTagCond; ++i) {
- SStringCopy(&dest->cond[i].cond, &src->cond[i].cond);
+ if (src->cond[i].cond != NULL) {
+ dest->cond[i].cond = strdup(src->cond[i].cond);
+ }
+
dest->cond[i].uid = src->cond[i].uid;
}
@@ -1356,10 +1373,9 @@ void tscTagCondCopy(STagCond* dest, const STagCond* src) {
}
void tscTagCondRelease(STagCond* pCond) {
- SStringFree(&pCond->tbnameCond.cond);
-
+ free(pCond->tbnameCond.cond);
for (int32_t i = 0; i < pCond->numOfTagCond; ++i) {
- SStringFree(&pCond->cond[i].cond);
+ free(pCond->cond[i].cond);
}
memset(pCond, 0, sizeof(STagCond));
@@ -1571,123 +1587,6 @@ void tscResetForNextRetrieve(SSqlRes* pRes) {
pRes->numOfRows = 0;
}
-SString SStringCreate(const char* str) {
- size_t len = strlen(str);
-
- SString dest = {.n = len, .alloc = len + 1};
- dest.z = calloc(1, dest.alloc);
- strcpy(dest.z, str);
-
- return dest;
-}
-
-void SStringCopy(SString* pDest, const SString* pSrc) {
- if (pSrc->n > 0) {
- pDest->n = pSrc->n;
- pDest->alloc = pDest->n + 1; // one additional space for null terminate
-
- pDest->z = calloc(1, pDest->alloc);
-
- memcpy(pDest->z, pSrc->z, pDest->n);
- } else {
- memset(pDest, 0, sizeof(SString));
- }
-}
-
-void SStringFree(SString* pStr) {
- if (pStr->alloc > 0) {
- tfree(pStr->z);
- pStr->alloc = 0;
- }
-}
-
-void SStringShrink(SString* pStr) {
- if (pStr->alloc > (pStr->n + 1) && pStr->alloc > (pStr->n * 2)) {
- pStr->z = realloc(pStr->z, pStr->n + 1);
- assert(pStr->z != NULL);
-
- pStr->alloc = pStr->n + 1;
- }
-}
-
-int32_t SStringAlloc(SString* pStr, int32_t size) {
- if (pStr->alloc >= size) {
- return TSDB_CODE_SUCCESS;
- }
-
- size = ALIGN8(size);
-
- char* tmp = NULL;
- if (pStr->z != NULL) {
- tmp = realloc(pStr->z, size);
- memset(pStr->z + pStr->n, 0, size - pStr->n);
- } else {
- tmp = calloc(1, size);
- }
-
- if (tmp == NULL) {
-#ifdef WINDOWS
- LPVOID lpMsgBuf;
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
- GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR)&lpMsgBuf, 0, NULL);
- tscTrace("failed to allocate memory, reason:%s", lpMsgBuf);
- LocalFree(lpMsgBuf);
-#else
- char errmsg[256] = {0};
- strerror_r(errno, errmsg, tListLen(errmsg));
- tscTrace("failed to allocate memory, reason:%s", errmsg);
-#endif
- return TSDB_CODE_CLI_OUT_OF_MEMORY;
- }
-
- pStr->z = tmp;
- pStr->alloc = size;
-
- return TSDB_CODE_SUCCESS;
-}
-
-#define MIN_ALLOC_SIZE 8
-
-int32_t SStringEnsureRemain(SString* pStr, int32_t size) {
- if (pStr->alloc - pStr->n > size) {
- return TSDB_CODE_SUCCESS;
- }
-
- // remain space is insufficient, allocate more spaces
- int32_t inc = (size >= MIN_ALLOC_SIZE) ? size : MIN_ALLOC_SIZE;
- if (inc < (pStr->alloc >> 1)) {
- inc = (pStr->alloc >> 1);
- }
-
- // get the new size
- int32_t newsize = pStr->alloc + inc;
-
- char* tmp = realloc(pStr->z, newsize);
- if (tmp == NULL) {
-#ifdef WINDOWS
- LPVOID lpMsgBuf;
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
- GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR)&lpMsgBuf, 0, NULL);
- tscTrace("failed to allocate memory, reason:%s", lpMsgBuf);
- LocalFree(lpMsgBuf);
-#else
- char errmsg[256] = {0};
- strerror_r(errno, errmsg, tListLen(errmsg));
- tscTrace("failed to allocate memory, reason:%s", errmsg);
-#endif
-
- return TSDB_CODE_CLI_OUT_OF_MEMORY;
- }
-
- memset(tmp + pStr->n, 0, inc);
- pStr->alloc = newsize;
- pStr->z = tmp;
-
- return TSDB_CODE_SUCCESS;
-}
-
SSqlObj* createSubqueryObj(SSqlObj* pSql, int32_t vnodeIndex, int16_t tableIndex, void (*fp)(), void* param,
SSqlObj* pPrevSql) {
SSqlCmd* pCmd = &pSql->cmd;
@@ -1822,9 +1721,7 @@ void tscDoQuery(SSqlObj* pSql) {
}
}
-int16_t tscGetJoinTagColIndexByUid(SSqlCmd* pCmd, uint64_t uid) {
- STagCond* pTagCond = &pCmd->tagCond;
-
+int16_t tscGetJoinTagColIndexByUid(STagCond* pTagCond, uint64_t uid) {
if (pTagCond->joinInfo.left.uid == uid) {
return pTagCond->joinInfo.left.tagCol;
} else {
diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h
index 5510212dbc37f6ce3ebb33c43d34ca93fc0649c1..5fee1d7da563eac57f3cb482ca12869e2b8bafe7 100644
--- a/src/inc/taoserror.h
+++ b/src/inc/taoserror.h
@@ -128,7 +128,7 @@ extern "C" {
#define TSDB_CODE_CACHE_BLOCK_TS_DISORDERED 107 // time stamp in cache block is disordered
#define TSDB_CODE_FILE_BLOCK_TS_DISORDERED 108 // time stamp in file block is disordered
#define TSDB_CODE_INVALID_COMMIT_LOG 109 // commit log init failed
-#define TSDB_CODE_SERVER_NO_SPACE 110
+#define TSDB_CODE_SERV_NO_DISKSPACE 110
#define TSDB_CODE_NOT_SUPER_TABLE 111 // operation only available for super table
#define TSDB_CODE_DUPLICATE_TAGS 112 // tags value for join not unique
#define TSDB_CODE_INVALID_SUBMIT_MSG 113
@@ -137,6 +137,8 @@ extern "C" {
#define TSDB_CODE_INVALID_VNODE_STATUS 116
#define TSDB_CODE_FAILED_TO_LOCK_RESOURCES 117
+#define TSDB_CODE_MAX_ERROR_CODE 118
+
#ifdef __cplusplus
}
#endif
diff --git a/src/inc/tglobalcfg.h b/src/inc/tglobalcfg.h
index ede3c97ce9f874152e8b81d78b6b1b19adc49b49..ed91964d611ccd4e578007794fcf9c9940123cf0 100644
--- a/src/inc/tglobalcfg.h
+++ b/src/inc/tglobalcfg.h
@@ -106,7 +106,6 @@ extern int tsMaxDbs;
extern int tsMaxTables;
extern int tsMaxDnodes;
extern int tsMaxVGroups;
-extern int tsShellActivityTimer;
extern char tsMgmtZone[];
extern char tsLocalIp[];
@@ -127,6 +126,7 @@ extern int tsEnableHttpModule;
extern int tsEnableMonitorModule;
extern int tsRestRowLimit;
extern int tsCompressMsgSize;
+extern int tsMaxSQLStringLen;
extern char tsSocketType[4];
diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h
index ea356a257a31dea67ccf7b06dcb057d02adeba93..58055fd8c9743596fc236f5a13256f3698a54140 100644
--- a/src/inc/tsdb.h
+++ b/src/inc/tsdb.h
@@ -100,6 +100,7 @@ extern "C" {
#define TSDB_COL_NAME_LEN 64
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 16
#define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE
+#define TSDB_MAX_ALLOWED_SQL_LEN (8*1024*1024U) // sql length should be less than 6mb
#define TSDB_MAX_BYTES_PER_ROW TSDB_MAX_COLUMNS * 16
#define TSDB_MAX_TAGS_LEN 512
diff --git a/src/rpc/src/tstring.c b/src/rpc/src/tstring.c
index e3daca130a83c1c363dad3eeb9bef1d2394842b2..63f65b882f59b07b434d908e33aba455c43b5178 100644
--- a/src/rpc/src/tstring.c
+++ b/src/rpc/src/tstring.c
@@ -238,7 +238,7 @@ char *tsError[] = {"success",
"only super table has metric meta info",
"tags value not unique for join",
"invalid submit message",
- "not active table(not created yet or deleted already)", //114
+ "not active table(not created yet or dropped already)", //114
"invalid table id",
"invalid vnode status", //116
"failed to lock resources",
diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c
index cef11d30cba8fe4488a0cc6adcad7b4143f4fe8d..80f76a3d25be300866f4f90c0ebb444242402185 100644
--- a/src/util/src/tglobalcfg.c
+++ b/src/util/src/tglobalcfg.c
@@ -124,6 +124,7 @@ int tsMgmtEqualVnodeNum = 0;
int tsEnableHttpModule = 1;
int tsEnableMonitorModule = 1;
int tsRestRowLimit = 10240;
+int tsMaxSQLStringLen = TSDB_MAX_SQL_LEN;
/*
* denote if the server needs to compress response message at the application layer to client, including query rsp,
@@ -653,7 +654,11 @@ static void doInitGlobalConfig() {
tsInitConfigOption(cfg++, "compressMsgSize", &tsCompressMsgSize, TSDB_CFG_VTYPE_INT,
TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW,
-1, 10000000, 0, TSDB_CFG_UTYPE_NONE);
-
+
+ tsInitConfigOption(cfg++, "maxSQLLength", &tsMaxSQLStringLen, TSDB_CFG_VTYPE_INT,
+ TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW,
+ TSDB_MAX_SQL_LEN, TSDB_MAX_ALLOWED_SQL_LEN, 0, TSDB_CFG_UTYPE_BYTE);
+
// locale & charset
tsInitConfigOption(cfg++, "timezone", tsTimezone, TSDB_CFG_VTYPE_STRING,
TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT,
diff --git a/src/util/src/tstrbuild.c b/src/util/src/tstrbuild.c
index 6fb970bd6e3de13d6119089759fcf030d6c618fc..691435749317f637b28140a30808f2896c8c04f6 100644
--- a/src/util/src/tstrbuild.c
+++ b/src/util/src/tstrbuild.c
@@ -13,10 +13,8 @@
* along with this program. If not, see .
*/
+#include "os.h"
#include "tstrbuild.h"
-#include
-#include
-#include
void taosStringBuilderEnsureCapacity(SStringBuilder* sb, size_t size) {
size += sb->pos;