提交 eb712702 编写于 作者: H Haojun Liao

[td-11818]fix bug in select * from super_table.

上级 9ef605fa
...@@ -372,11 +372,14 @@ typedef struct STaskParam { ...@@ -372,11 +372,14 @@ typedef struct STaskParam {
typedef struct SExchangeInfo { typedef struct SExchangeInfo {
SArray *pSources; SArray *pSources;
uint64_t bytes; // total load bytes from remote
tsem_t ready; tsem_t ready;
void *pTransporter; void *pTransporter;
SRetrieveTableRsp *pRsp; SRetrieveTableRsp *pRsp;
SSDataBlock *pResult; SSDataBlock *pResult;
int32_t current;
uint64_t rowsOfCurrentSource;
uint64_t bytes; // total load bytes from remote
uint64_t totalRows;
} SExchangeInfo; } SExchangeInfo;
typedef struct STableScanInfo { typedef struct STableScanInfo {
......
...@@ -5144,71 +5144,109 @@ static SSDataBlock* doLoadRemoteData(void* param, bool* newgroup) { ...@@ -5144,71 +5144,109 @@ static SSDataBlock* doLoadRemoteData(void* param, bool* newgroup) {
SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo; SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo;
*newgroup = false; *newgroup = false;
if (pExchangeInfo->pRsp != NULL && pExchangeInfo->pRsp->completed == 1) {
size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources);
if (pExchangeInfo->current >= totalSources) {
return NULL; return NULL;
} }
SResFetchReq *pMsg = calloc(1, sizeof(SResFetchReq)); SResFetchReq* pMsg = NULL;
if (NULL == pMsg) { // todo handle malloc error SMsgSendInfo* pMsgSendInfo = NULL;
pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY;
goto _error;
}
SDownstreamSource* pSource = taosArrayGet(pExchangeInfo->pSources, 0); while(1) {
SEpSet epSet = {0}; pMsg = calloc(1, sizeof(SResFetchReq));
if (NULL == pMsg) { // todo handle malloc error
pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY;
goto _error;
}
epSet.numOfEps = pSource->addr.numOfEps; SDownstreamSource* pSource = taosArrayGet(pExchangeInfo->pSources, pExchangeInfo->current);
epSet.port[0] = pSource->addr.epAddr[0].port; SEpSet epSet = {0};
tstrncpy(epSet.fqdn[0], pSource->addr.epAddr[0].fqdn, tListLen(epSet.fqdn[0]));
pMsg->header.vgId = htonl(pSource->addr.nodeId); epSet.numOfEps = pSource->addr.numOfEps;
pMsg->sId = htobe64(pSource->schedId); epSet.port[0] = pSource->addr.epAddr[0].port;
pMsg->taskId = htobe64(pSource->taskId); tstrncpy(epSet.fqdn[0], pSource->addr.epAddr[0].fqdn, tListLen(epSet.fqdn[0]));
pMsg->queryId = htobe64(pTaskInfo->id.queryId);
// send the fetch remote task result reques qDebug("QID:0x%" PRIx64 " build fetch msg and send to vgId:%d, ep:%s, taskId:0x%" PRIx64 ", %d/%" PRIzu,
SMsgSendInfo* pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo)); GET_TASKID(pTaskInfo), pSource->addr.nodeId, epSet.fqdn[0], pSource->taskId, pExchangeInfo->current, totalSources);
if (NULL == pMsgSendInfo) {
qError("QID:%"PRIx64" calloc %d failed", GET_TASKID(pTaskInfo), (int32_t)sizeof(SMsgSendInfo));
pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY;
goto _error;
}
pMsgSendInfo->param = pExchangeInfo; pMsg->header.vgId = htonl(pSource->addr.nodeId);
pMsgSendInfo->msgInfo.pData = pMsg; pMsg->sId = htobe64(pSource->schedId);
pMsgSendInfo->msgInfo.len = sizeof(SResFetchReq); pMsg->taskId = htobe64(pSource->taskId);
pMsgSendInfo->msgType = TDMT_VND_FETCH; pMsg->queryId = htobe64(pTaskInfo->id.queryId);
pMsgSendInfo->fp = loadRemoteDataCallback;
int64_t transporterId = 0; // send the fetch remote task result reques
int32_t code = asyncSendMsgToServer(pExchangeInfo->pTransporter, &epSet, &transporterId, pMsgSendInfo); pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo));
tsem_wait(&pExchangeInfo->ready); if (NULL == pMsgSendInfo) {
qError("QID:0x%" PRIx64 " prepare message %d failed", GET_TASKID(pTaskInfo), (int32_t)sizeof(SMsgSendInfo));
pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY;
goto _error;
}
if (pExchangeInfo->pRsp->numOfRows == 0) { pMsgSendInfo->param = pExchangeInfo;
return NULL; pMsgSendInfo->msgInfo.pData = pMsg;
} pMsgSendInfo->msgInfo.len = sizeof(SResFetchReq);
pMsgSendInfo->msgType = TDMT_VND_FETCH;
pMsgSendInfo->fp = loadRemoteDataCallback;
SSDataBlock* pRes = pExchangeInfo->pResult; int64_t transporterId = 0;
char* pData = pExchangeInfo->pRsp->data; int32_t code = asyncSendMsgToServer(pExchangeInfo->pTransporter, &epSet, &transporterId, pMsgSendInfo);
tsem_wait(&pExchangeInfo->ready);
for(int32_t i = 0; i < pOperator->numOfOutput; ++i) { SRetrieveTableRsp* pRsp = pExchangeInfo->pRsp;
SColumnInfoData* pColInfoData = taosArrayGet(pRes->pDataBlock, i); if (pRsp->numOfRows == 0) {
char* tmp = realloc(pColInfoData->pData, pColInfoData->info.bytes * pExchangeInfo->pRsp->numOfRows); if (pExchangeInfo->current >= taosArrayGetSize(pExchangeInfo->pSources)) {
if (tmp == NULL) { return NULL;
goto _error; }
qDebug("QID:0x%"PRIx64" vgId:%d, taskID:0x%"PRIx64" %d of total completed, rowsOfSource:%"PRIu64", totalRows:%"PRIu64" try next",
GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pExchangeInfo->current + 1,
pExchangeInfo->rowsOfCurrentSource, pExchangeInfo->totalRows);
pExchangeInfo->rowsOfCurrentSource = 0;
pExchangeInfo->current += 1;
continue;
} }
size_t len = pExchangeInfo->pRsp->numOfRows * pColInfoData->info.bytes; SSDataBlock* pRes = pExchangeInfo->pResult;
memcpy(tmp, pData, len); char* pData = pRsp->data;
pColInfoData->pData = tmp; for (int32_t i = 0; i < pOperator->numOfOutput; ++i) {
pData += len; SColumnInfoData* pColInfoData = taosArrayGet(pRes->pDataBlock, i);
} char* tmp = realloc(pColInfoData->pData, pColInfoData->info.bytes * pRsp->numOfRows);
if (tmp == NULL) {
goto _error;
}
size_t len = pRsp->numOfRows * pColInfoData->info.bytes;
memcpy(tmp, pData, len);
pColInfoData->pData = tmp;
pData += len;
}
pRes->info.numOfCols = pOperator->numOfOutput;
pRes->info.rows = pRsp->numOfRows;
pRes->info.numOfCols = pOperator->numOfOutput; pExchangeInfo->totalRows += pRsp->numOfRows;
pRes->info.rows = pExchangeInfo->pRsp->numOfRows; pExchangeInfo->bytes += pRsp->compLen;
pExchangeInfo->rowsOfCurrentSource += pRsp->numOfRows;
return pExchangeInfo->pResult; if (pRsp->completed == 1) {
qDebug("QID:0x%" PRIx64 " fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, rowsOfSource:%" PRIu64
", totalRows:%" PRIu64 ", totalBytes:%" PRIu64 " try next %d/%" PRIzu,
GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pRes->info.rows, pExchangeInfo->rowsOfCurrentSource, pExchangeInfo->totalRows, pExchangeInfo->bytes,
pExchangeInfo->current + 1, totalSources);
pExchangeInfo->rowsOfCurrentSource = 0;
pExchangeInfo->current += 1;
} else {
qDebug("QID:0x%" PRIx64 " fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, totalRows:%" PRIu64 ", totalBytes:%" PRIu64,
GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pRes->info.rows, pExchangeInfo->totalRows, pExchangeInfo->bytes);
}
return pExchangeInfo->pResult;
}
_error: _error:
tfree(pMsg); tfree(pMsg);
...@@ -7719,7 +7757,6 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhyNode* pPhyNode, SExecTaskInfo* pTask ...@@ -7719,7 +7757,6 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhyNode* pPhyNode, SExecTaskInfo* pTask
SExchangePhyNode* pEx = (SExchangePhyNode*) pPhyNode; SExchangePhyNode* pEx = (SExchangePhyNode*) pPhyNode;
return createExchangeOperatorInfo(pEx->pSrcEndPoints, pEx->node.pTargets, pTaskInfo); return createExchangeOperatorInfo(pEx->pSrcEndPoints, pEx->node.pTargets, pTaskInfo);
} else if (pPhyNode->info.type == OP_StreamScan) { } else if (pPhyNode->info.type == OP_StreamScan) {
size_t numOfCols = taosArrayGetSize(pPhyNode->pTargets);
SScanPhyNode* pScanPhyNode = (SScanPhyNode*)pPhyNode; // simple child table. SScanPhyNode* pScanPhyNode = (SScanPhyNode*)pPhyNode; // simple child table.
return createStreamScanOperatorInfo(readerHandle, pPhyNode->pTargets, pScanPhyNode->uid, pTaskInfo); return createStreamScanOperatorInfo(readerHandle, pPhyNode->pTargets, pScanPhyNode->uid, pTaskInfo);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册