提交 eebc949c 编写于 作者: S shenglian zhou

enhance: add max query time range limit to taosc

上级 3609ff5c
......@@ -6605,6 +6605,18 @@ _ret:
return ret;
}
static int32_t validateMaxQueryTimeRange(SSqlObj* pSql, SQueryInfo* pQueryInfo) {
if (tsMaxQueryTimeRange < 0) {
return TSDB_CODE_SUCCESS;
}
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
int64_t maxTimeRange = convertTimePrecision(tsMaxQueryTimeRange * 1000, TSDB_TIME_PRECISION_MILLI, tinfo.precision);
if (pQueryInfo->window.ekey - pQueryInfo->window.skey > maxTimeRange) {
return TSDB_CODE_TSC_EXCEED_QUERY_TIME_RANGE;
}
return TSDB_CODE_SUCCESS;
}
int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql, bool joinQuery, bool delData) {
......@@ -10665,6 +10677,10 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
if ((code = validateRangeNode(pSql, pQueryInfo, pSqlNode)) != TSDB_CODE_SUCCESS) {
return code;
}
if ((code = validateMaxQueryTimeRange(pSql, pQueryInfo)) != TSDB_CODE_SUCCESS) {
return code;
}
} else {
pQueryInfo->command = TSDB_SQL_SELECT;
......@@ -10819,6 +10835,9 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return code;
}
if ((code = validateMaxQueryTimeRange(pSql, pQueryInfo)) != TSDB_CODE_SUCCESS) {
return code;
}
}
{ // set the query info
......
......@@ -96,6 +96,7 @@ extern int64_t tsMaxRetentWindow;
extern bool tsWriteBatchThreadLocal;
extern int32_t tsWriteBatchSize;
extern int32_t tsWriteBatchTimeout;
extern int32_t tsMaxQueryTimeRange;
// db parameters in client
extern int32_t tsCacheBlockSize;
......
......@@ -135,6 +135,10 @@ bool tsWriteBatchThreadLocal = false; // if thread local enable, each thre
int32_t tsWriteBatchSize = 0; // suggest: 64 - 512, default 0, 0 means disable batching.
int32_t tsWriteBatchTimeout = 10; // suggest: 2 - 100 (unit: milliseconds)
// max query time range
// if less than zero, no limits
int32_t tsMaxQueryTimeRange = -1;
// the maximum allowed query buffer size during query processing for each data node.
// -1 no limit (default)
// 0 no query allowed, queries are disabled
......@@ -1923,6 +1927,16 @@ static void doInitGlobalConfig(void) {
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "maxQueryTimeRange";
cfg.ptr = &tsMaxQueryTimeRange;
cfg.valType = TAOS_CFG_VTYPE_INT32;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
cfg.minValue = -1;
cfg.maxValue = (float)INT32_MAX;
cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM);
#else
// if TD_TSZ macro define, have 5 count configs, so must add 5
......
......@@ -121,7 +121,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_TSC_TOO_MANY_SML_LINES TAOS_DEF_ERROR_CODE(0, 0x0229) //"too many lines in batch")
#define TSDB_CODE_TSC_SEND_DATA_FAILED TAOS_DEF_ERROR_CODE(0, 0x0230) //"Client send request data error"
#define TSDB_CODE_TSC_EXCEED_ROW_BYTES TAOS_DEF_ERROR_CODE(0, 0x0231) //"Columns total length exceeds row bytes
#define TSDB_CODE_TSC_EXCEED_QUERY_TIME_RANGE TAOS_DEF_ERROR_CODE(0, 0x0232) //"Query time range exceeds max query time range"
// mnode
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed"
#define TSDB_CODE_MND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0301) //"Message is progressing"
......
......@@ -128,6 +128,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_RES_TOO_MANY, "Result set too large
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_TOO_MANY_SML_LINES, "Too many lines in batch")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_SEND_DATA_FAILED, "Client send request data failed")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_EXCEED_ROW_BYTES, "Columns total length exceeds row bytes")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_EXCEED_QUERY_TIME_RANGE, "Query time range exceeds max query time range")
// mnode
TAOS_DEFINE_ERROR(TSDB_CODE_MND_MSG_NOT_PROCESSED, "Message not processed")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册