diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 50614d2501178bac429987341e233119bdfe5bba..01a0da4e0c7080c7f86cb0b0b233d9291b726cfa 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1174,10 +1174,18 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) { if (numOfRows > 0) { assert(pRes->numOfRows == numOfRows); - atomic_add_fetch_64(&pState->numOfRetrievedRows, numOfRows); + int64_t num = atomic_add_fetch_64(&pState->numOfRetrievedRows, numOfRows); tscTrace("%p sub:%p retrieve numOfRows:%d totalNumOfRows:%d from ip:%u,vid:%d,orderOfSub:%d", pPObj, pSql, pRes->numOfRows, pState->numOfRetrievedRows, pSvd->ip, pSvd->vnode, idx); + + if (num > tsMaxNumOfOrderedResults) { + 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); + return; + } + #ifdef _DEBUG_VIEW printf("received data from vnode: %d rows\n", pRes->numOfRows); @@ -1213,12 +1221,11 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) { #ifdef _DEBUG_VIEW printf("%" PRIu64 " rows data flushed to disk:\n", trsupport->localBuffer->numOfElems); SSrcColumnInfo colInfo[256] = {0}; - SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(&pPObj->cmd, 0); - tscGetSrcColumnInfo(colInfo, pQueryInfo); tColModelDisplayEx(pDesc->pSchema, trsupport->localBuffer->data, trsupport->localBuffer->numOfElems, trsupport->localBuffer->numOfElems, colInfo); #endif + 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); @@ -1251,7 +1258,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) { tscTrace("%p retrieve from %d vnodes completed.final NumOfRows:%d,start to build loser tree", pPObj, pState->numOfTotal, pState->numOfRetrievedRows); - + SQueryInfo *pPQueryInfo = tscGetQueryInfoDetail(&pPObj->cmd, 0); tscClearInterpInfo(pPQueryInfo); @@ -1674,6 +1681,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pQueryMsg->nAggTimeInterval = htobe64(pQueryInfo->nAggTimeInterval); pQueryMsg->intervalTimeUnit = pQueryInfo->intervalTimeUnit; + pQueryMsg->slidingTime = htobe64(pQueryInfo->nSlidingTime); + if (pQueryInfo->nAggTimeInterval < 0) { tscError("%p illegal value of aggregation time interval in query msg: %ld", pSql, pQueryInfo->nAggTimeInterval); return -1; diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index 3394a87f8ffff6fd98522f1044801ed56ef32bd5..edf0ab24a169c0a24ab1f8e554e7c0282c92a47f 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -125,7 +125,7 @@ extern "C" { #define TSDB_CODE_BATCH_SIZE_TOO_BIG 104 #define TSDB_CODE_TIMESTAMP_OUT_OF_RANGE 105 #define TSDB_CODE_INVALID_QUERY_MSG 106 // failed to validate the sql expression msg by vnode -#define TSDB_CODE_CACHE_BLOCK_TS_DISORDERED 107 // time stamp in cache block is disordered +#define TSDB_CODE_SORTED_RES_TOO_MANY 107 // too many result for ordered super table projection query #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_SERV_NO_DISKSPACE 110 @@ -137,7 +137,7 @@ extern "C" { #define TSDB_CODE_INVALID_VNODE_STATUS 116 #define TSDB_CODE_FAILED_TO_LOCK_RESOURCES 117 #define TSDB_CODE_TABLE_ID_MISMATCH 118 -#define TSDB_CODE_QUERY_CACHE_ERASED 119 +#define TSDB_CODE_QUERY_CACHE_ERASED 119 #define TSDB_CODE_MAX_ERROR_CODE 120 diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 7f1ba7a8369149f87c88637e48d34d46d9a012a6..3b4db01755655f81482c0685e2ea694336976203 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -514,7 +514,8 @@ typedef struct { char intervalTimeUnit; // time interval type, for revisement of interval(1d) int64_t nAggTimeInterval; // time interval for aggregation, in million second - + int64_t slidingTime; // value for sliding window + // tag schema, used to parse tag information in pSidExtInfo uint64_t pTagSchema; diff --git a/src/inc/tglobalcfg.h b/src/inc/tglobalcfg.h index 75d1b9c7110e14b2053cd178cc4f4714d8070a88..40fe0deaf4852e8cbbd12af9fd4e1fc10881705d 100644 --- a/src/inc/tglobalcfg.h +++ b/src/inc/tglobalcfg.h @@ -126,6 +126,7 @@ extern int tsEnableMonitorModule; extern int tsRestRowLimit; extern int tsCompressMsgSize; extern int tsMaxSQLStringLen; +extern int tsMaxNumOfOrderedResults; extern char tsSocketType[4]; diff --git a/src/rpc/src/tstring.c b/src/rpc/src/tstring.c index cc14205b03e234b7907cf287c99c350bad8f6ca3..a254ceecfd1f6ce13b1cc30f8c0c87b6b8edfca9 100644 --- a/src/rpc/src/tstring.c +++ b/src/rpc/src/tstring.c @@ -231,7 +231,7 @@ char *tsError[] = {"success", "batch size too big", "timestamp out of range", //105 "invalid query message", - "timestamp disordered in cache block", + "too many results from vnodes for sort", "timestamp disordered in file block", "invalid commit log", "no disk space on server", //110 diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index 20175f2dc72f338526b137b8a762a418dbff321d..7928c6a0c475efe925fe6dd6c0b0632856616ab0 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -124,6 +124,10 @@ int tsEnableMonitorModule = 1; int tsRestRowLimit = 10240; int tsMaxSQLStringLen = TSDB_MAX_SQL_LEN; +// the maximum number of results for projection query on super table that are returned from +// one virtual node, to order according to timestamp +int tsMaxNumOfOrderedResults = 100000; + /* * denote if the server needs to compress response message at the application layer to client, including query rsp, * metricmeta rsp, and multi-meter query rsp message body. The client compress the submit message to server. @@ -672,6 +676,10 @@ static void doInitGlobalConfig() { 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); + tsInitConfigOption(cfg++, "maxNumOfOrderedRes", &tsMaxNumOfOrderedResults, 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_NONE); + // locale & charset tsInitConfigOption(cfg++, "timezone", tsTimezone, TSDB_CFG_VTYPE_STRING, TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT,