From 55cfce602b8da620ea7fdef30b79ea7910968f22 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 8 Jan 2021 16:55:24 +0800 Subject: [PATCH] [TD-2701]: fix crash in cq --- src/client/src/tscStream.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index d1004fff62..1c85938c64 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -65,15 +65,30 @@ static int64_t tscGetRetryDelayTime(SSqlStream* pStream, int64_t slidingTime, in return retryDelta; } +static void setRetryInfo(SSqlStream* pStream, int32_t code) { + SSqlObj* pSql = pStream->pSql; + + pSql->res.code = code; + int64_t retryDelayTime = tscGetRetryDelayTime(pStream, pStream->interval.sliding, pStream->precision); + tscDebug("%p stream:%p, get table Meta failed, retry in %" PRId64 "ms", pSql, pStream, retryDelayTime); + tscSetRetryTimer(pStream, pSql, retryDelayTime); +} + static void doLaunchQuery(void* param, TAOS_RES* tres, int32_t code) { SSqlStream *pStream = (SSqlStream *)param; - assert(pStream->pSql == tres && code == TSDB_CODE_SUCCESS); + assert(pStream->pSql == tres); SSqlObj* pSql = (SSqlObj*) tres; - pSql->fp = doLaunchQuery; + + pSql->fp = doLaunchQuery; pSql->fetchFp = doLaunchQuery; pSql->res.completed = false; + if (code != TSDB_CODE_SUCCESS) { + setRetryInfo(pStream, code); + return; + } + SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); @@ -82,6 +97,10 @@ static void doLaunchQuery(void* param, TAOS_RES* tres, int32_t code) { code = tscGetSTableVgroupInfo(pSql, 0); } + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { + return; + } + // failed to get table Meta or vgroup list, retry in 10sec. if (code == TSDB_CODE_SUCCESS) { tscTansformSQLFuncForSTableQuery(pQueryInfo); @@ -91,11 +110,8 @@ static void doLaunchQuery(void* param, TAOS_RES* tres, int32_t code) { pSql->fetchFp = tscProcessStreamQueryCallback; tscDoQuery(pSql); tscIncStreamExecutionCount(pStream); - } else if (code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) { - pSql->res.code = code; - int64_t retryDelayTime = tscGetRetryDelayTime(pStream, pStream->interval.sliding, pStream->precision); - tscDebug("%p stream:%p, get table Meta failed, retry in %" PRId64 "ms", pSql, pStream, retryDelayTime); - tscSetRetryTimer(pStream, pSql, retryDelayTime); + } else { + setRetryInfo(pStream, code); } } -- GitLab