未验证 提交 42e1cd74 编写于 作者: H Haojun Liao 提交者: GitHub

Merge pull request #21935 from taosdata/fix/3_liaohj

fix(stream): fix message lost bug during pause stream.
...@@ -318,78 +318,78 @@ int32_t updateCheckPointInfo(SStreamTask* pTask) { ...@@ -318,78 +318,78 @@ int32_t updateCheckPointInfo(SStreamTask* pTask) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
/** static int32_t extractMsgFromInputQ(SStreamTask* pTask, SStreamQueueItem** pInput, int32_t* numOfBlocks,
* todo: the batch of blocks should be tuned dynamic, according to the total elapsed time of each batch of blocks, the const char* id) {
* appropriate batch of blocks should be handled in 5 to 10 sec. int32_t retryTimes = 0;
*/ int32_t MAX_RETRY_TIMES = 5;
int32_t streamExecForAll(SStreamTask* pTask) {
const char* id = pTask->id.idStr;
while (1) {
int32_t batchSize = 1;
int16_t times = 0;
SStreamQueueItem* pInput = NULL;
// merge multiple input data if possible in the input queue.
qDebug("s-task:%s start to extract data block from inputQ", id);
while (1) { while (1) {
if (streamTaskShouldPause(&pTask->status)) { if (streamTaskShouldPause(&pTask->status)) {
if (batchSize > 1) { qDebug("s-task:%s task should pause, input blocks:%d", pTask->id.idStr, *numOfBlocks);
break; return TSDB_CODE_SUCCESS;
} else {
return 0;
}
} }
SStreamQueueItem* qItem = streamQueueNextItem(pTask->inputQueue); SStreamQueueItem* qItem = streamQueueNextItem(pTask->inputQueue);
if (qItem == NULL) { if (qItem == NULL) {
if (pTask->taskLevel == TASK_LEVEL__SOURCE && batchSize < MIN_STREAM_EXEC_BATCH_NUM && times < 5) { if (pTask->taskLevel == TASK_LEVEL__SOURCE && (++retryTimes) < MAX_RETRY_TIMES) {
times++;
taosMsleep(10); taosMsleep(10);
qDebug("===stream===try again batchSize:%d", batchSize); qDebug("===stream===try again batchSize:%d, retry:%d", *numOfBlocks, retryTimes);
continue; continue;
} }
qDebug("===stream===break batchSize:%d", batchSize); qDebug("===stream===break batchSize:%d", *numOfBlocks);
break; return TSDB_CODE_SUCCESS;
} }
if (pInput == NULL) { // do not merge blocks for sink node
pInput = qItem;
streamQueueProcessSuccess(pTask->inputQueue);
if (pTask->taskLevel == TASK_LEVEL__SINK) { if (pTask->taskLevel == TASK_LEVEL__SINK) {
break; *numOfBlocks = 1;
*pInput = qItem;
return TSDB_CODE_SUCCESS;
} }
if (*pInput == NULL) {
ASSERT((*numOfBlocks) == 0);
*pInput = qItem;
} else { } else {
// todo we need to sort the data block, instead of just appending into the array list. // todo we need to sort the data block, instead of just appending into the array list.
void* newRet = NULL; void* newRet = streamMergeQueueItem(*pInput, qItem);
if ((newRet = streamMergeQueueItem(pInput, qItem)) == NULL) { if (newRet == NULL) {
qError("s-task:%s failed to merge blocks from inputQ, numOfBlocks:%d", id, *numOfBlocks);
streamQueueProcessFail(pTask->inputQueue); streamQueueProcessFail(pTask->inputQueue);
break; return TSDB_CODE_SUCCESS;
} else {
batchSize++;
pInput = newRet;
streamQueueProcessSuccess(pTask->inputQueue);
if (batchSize > MAX_STREAM_EXEC_BATCH_NUM) {
qDebug("s-task:%s batch size limit:%d reached, start to process blocks", id,
MAX_STREAM_EXEC_BATCH_NUM);
break;
}
}
} }
*pInput = newRet;
} }
if (streamTaskShouldStop(&pTask->status)) { *numOfBlocks += 1;
if (pInput) { streamQueueProcessSuccess(pTask->inputQueue);
streamFreeQitem(pInput);
if (*numOfBlocks >= MAX_STREAM_EXEC_BATCH_NUM) {
qDebug("s-task:%s batch size limit:%d reached, start to process blocks", id, MAX_STREAM_EXEC_BATCH_NUM);
return TSDB_CODE_SUCCESS;
} }
return 0;
} }
}
/**
* todo: the batch of blocks should be tuned dynamic, according to the total elapsed time of each batch of blocks, the
* appropriate batch of blocks should be handled in 5 to 10 sec.
*/
int32_t streamExecForAll(SStreamTask* pTask) {
const char* id = pTask->id.idStr;
while (1) {
int32_t batchSize = 0;
SStreamQueueItem* pInput = NULL;
// merge multiple input data if possible in the input queue.
qDebug("s-task:%s start to extract data block from inputQ", id);
/*int32_t code = */extractMsgFromInputQ(pTask, &pInput, &batchSize, id);
if (pInput == NULL) { if (pInput == NULL) {
ASSERT(batchSize == 0);
break; break;
} }
...@@ -404,8 +404,7 @@ int32_t streamExecForAll(SStreamTask* pTask) { ...@@ -404,8 +404,7 @@ int32_t streamExecForAll(SStreamTask* pTask) {
while (pTask->taskLevel == TASK_LEVEL__SOURCE) { while (pTask->taskLevel == TASK_LEVEL__SOURCE) {
int8_t status = atomic_load_8(&pTask->status.taskStatus); int8_t status = atomic_load_8(&pTask->status.taskStatus);
if (status != TASK_STATUS__NORMAL && status != TASK_STATUS__PAUSE) { if (status != TASK_STATUS__NORMAL && status != TASK_STATUS__PAUSE) {
qError("stream task wait for the end of fill history, s-task:%s, status:%d", id, qError("stream task wait for the end of fill history, s-task:%s, status:%d", id, status);
atomic_load_8(&pTask->status.taskStatus));
taosMsleep(100); taosMsleep(100);
} else { } else {
break; break;
...@@ -458,6 +457,7 @@ int32_t streamExecForAll(SStreamTask* pTask) { ...@@ -458,6 +457,7 @@ int32_t streamExecForAll(SStreamTask* pTask) {
double el = (taosGetTimestampMs() - st) / 1000.0; double el = (taosGetTimestampMs() - st) / 1000.0;
qDebug("s-task:%s batch of input blocks exec end, elapsed time:%.2fs, result size:%.2fMiB, numOfBlocks:%d", qDebug("s-task:%s batch of input blocks exec end, elapsed time:%.2fs, result size:%.2fMiB, numOfBlocks:%d",
id, el, resSize / 1048576.0, totalBlocks); id, el, resSize / 1048576.0, totalBlocks);
streamFreeQitem(pInput); streamFreeQitem(pInput);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册