diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index bcc0d68f95cbd9ec884df5e87b3ec10bd5463883..fc014df6359116b55e156cf738d82957c3d8845b 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -69,6 +69,7 @@ extern char tsTempDir[]; extern int32_t tsShortcutFlag; extern int32_t tsMaxSqlGroups; extern int8_t tsSortWhenGroupBy; +extern int32_t tsQueryRssThreshold; // query buffer management extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index e49ed4caa54a73e79bbb2ee745dfb4a4b96360c5..537d1eafc0e6c4eb99b0cfa36b3ac31f46dd8b18 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -124,6 +124,9 @@ int32_t tsMaxSqlGroups = 1000000; // order by first group by column when group by int8_t tsSortWhenGroupBy = 1; +// memory rss thresold for creating new query in MB. 0 means no threshold limitation +int32_t tsQueryRssThreshold = 0; + int32_t tsProjectExecInterval = 10000; // every 10sec, the projection will be executed once int64_t tsMaxRetentWindow = 24 * 3600L; // maximum time window tolerance @@ -1828,6 +1831,16 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); + cfg.option = "queryRssThresold"; + cfg.ptr = &tsQueryRssThreshold; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = 2048*1024; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + #ifdef TD_TSZ // lossy compress cfg.option = "lossyColumns"; diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index fc387d331b07fcf407ade3305d1874ef2b5c8c31..40f1c3096ea025fe7ec16b3696eab6248644bb50 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -298,6 +298,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_QRY_INVALID_TIME_CONDITION TAOS_DEF_ERROR_CODE(0, 0x070E) //"invalid time condition") #define TSDB_CODE_QRY_INVALID_SCHEMA_VERSION TAOS_DEF_ERROR_CODE(0, 0x0710) //"invalid schema version") #define TSDB_CODE_QRY_RESULT_TOO_LARGE TAOS_DEF_ERROR_CODE(0, 0x0711) //"result num is too large") +#define TSDB_CODE_QRY_RSS_THRESHOLD TAOS_DEF_ERROR_CODE(0, 0x0712) //"query memory rss threshold") // grant #define TSDB_CODE_GRANT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0800) //"License expired" diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index cb89649c3cc93f00021bd9a1c747d44b5e699a23..23e65cd281039c872b5f0d8cc069dd2be02998b8 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -71,6 +71,13 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi assert(pQueryMsg != NULL && tsdb != NULL); int32_t code = TSDB_CODE_SUCCESS; + float procMemory = 0; + if (taosGetProcMemory(&procMemory)) { + if (tsQueryRssThreshold > 0 && procMemory >= tsQueryRssThreshold) { + code = TSDB_CODE_QRY_RSS_THRESHOLD; + goto _over; + } + } SQueryParam param = {0}; code = convertQueryMsg(pQueryMsg, ¶m); diff --git a/src/util/inc/tconfig.h b/src/util/inc/tconfig.h index d6f4c79ddd8c0d22149eeead5ef23887aae69b04..78e3a782bb226d2cbbaf4bc40579d7fed076e327 100644 --- a/src/util/inc/tconfig.h +++ b/src/util/inc/tconfig.h @@ -20,7 +20,7 @@ extern "C" { #endif -#define TSDB_CFG_MAX_NUM 141 +#define TSDB_CFG_MAX_NUM 142 #define TSDB_CFG_PRINT_LEN 23 #define TSDB_CFG_OPTION_LEN 24 #define TSDB_CFG_VALUE_LEN 41 diff --git a/src/util/src/terror.c b/src/util/src/terror.c index f66152988ee31543cd559c050fba82d3353aa9fa..c217d97b54586e6e63ef7b447e62290d350ead33 100644 --- a/src/util/src/terror.c +++ b/src/util/src/terror.c @@ -304,6 +304,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INCONSISTAN, "File inconsistance in TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_TIME_CONDITION, "One valid time range condition expected") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_SYS_ERROR, "System error") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_RESULT_TOO_LARGE, "result num is too large") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_RSS_THRESHOLD, "Exceed Memory RSS thresold when creating query") // grant TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, "License expired")