Merge pull request #18345 from taosdata/fix/TD-20591
fix: crash caused by elect null and issues found in asan
This commit is contained in:
commit
e1ea03fbda
|
@ -36,7 +36,7 @@ int32_t colDataGetFullLength(const SColumnInfoData* pColumnInfoData, int32_t num
|
||||||
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
||||||
return pColumnInfoData->varmeta.length + sizeof(int32_t) * numOfRows;
|
return pColumnInfoData->varmeta.length + sizeof(int32_t) * numOfRows;
|
||||||
} else {
|
} else {
|
||||||
return pColumnInfoData->info.bytes * numOfRows + BitmapLen(numOfRows);
|
return ((pColumnInfoData->info.type == TSDB_DATA_TYPE_NULL) ? 0 : pColumnInfoData->info.bytes * numOfRows) + BitmapLen(numOfRows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,12 +36,13 @@ typedef struct SMultiMergeSource {
|
||||||
|
|
||||||
typedef struct SSortSource {
|
typedef struct SSortSource {
|
||||||
SMultiMergeSource src;
|
SMultiMergeSource src;
|
||||||
union {
|
struct {
|
||||||
struct {
|
SArray* pageIdList;
|
||||||
SArray* pageIdList;
|
int32_t pageIndex;
|
||||||
int32_t pageIndex;
|
};
|
||||||
};
|
struct {
|
||||||
void* param;
|
void* param;
|
||||||
|
bool onlyRef;
|
||||||
};
|
};
|
||||||
|
|
||||||
} SSortSource;
|
} SSortSource;
|
||||||
|
|
|
@ -4532,6 +4532,7 @@ int32_t startGroupTableMergeScan(SOperatorInfo* pOperator) {
|
||||||
SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource));
|
SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource));
|
||||||
STableMergeScanSortSourceParam* param = taosArrayGet(pInfo->sortSourceParams, i);
|
STableMergeScanSortSourceParam* param = taosArrayGet(pInfo->sortSourceParams, i);
|
||||||
ps->param = param;
|
ps->param = param;
|
||||||
|
ps->onlyRef = true;
|
||||||
tsortAddSource(pInfo->pSortHandle, ps);
|
tsortAddSource(pInfo->pSortHandle, ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,10 +176,10 @@ int32_t doOpenSortOperator(SOperatorInfo* pOperator) {
|
||||||
|
|
||||||
SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource));
|
SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource));
|
||||||
ps->param = pOperator->pDownstream[0];
|
ps->param = pOperator->pDownstream[0];
|
||||||
|
ps->onlyRef = true;
|
||||||
tsortAddSource(pInfo->pSortHandle, ps);
|
tsortAddSource(pInfo->pSortHandle, ps);
|
||||||
|
|
||||||
int32_t code = tsortOpen(pInfo->pSortHandle);
|
int32_t code = tsortOpen(pInfo->pSortHandle);
|
||||||
taosMemoryFreeClear(ps);
|
|
||||||
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
T_LONG_JMP(pTaskInfo->env, terrno);
|
T_LONG_JMP(pTaskInfo->env, terrno);
|
||||||
|
@ -377,10 +377,10 @@ int32_t beginSortGroup(SOperatorInfo* pOperator) {
|
||||||
param->childOpInfo = pOperator->pDownstream[0];
|
param->childOpInfo = pOperator->pDownstream[0];
|
||||||
param->grpSortOpInfo = pInfo;
|
param->grpSortOpInfo = pInfo;
|
||||||
ps->param = param;
|
ps->param = param;
|
||||||
|
ps->onlyRef = false;
|
||||||
tsortAddSource(pInfo->pCurrSortHandle, ps);
|
tsortAddSource(pInfo->pCurrSortHandle, ps);
|
||||||
|
|
||||||
int32_t code = tsortOpen(pInfo->pCurrSortHandle);
|
int32_t code = tsortOpen(pInfo->pCurrSortHandle);
|
||||||
taosMemoryFreeClear(ps);
|
|
||||||
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
T_LONG_JMP(pTaskInfo->env, terrno);
|
T_LONG_JMP(pTaskInfo->env, terrno);
|
||||||
|
@ -471,6 +471,9 @@ void destroyGroupSortOperatorInfo(void* param) {
|
||||||
taosArrayDestroy(pInfo->pSortInfo);
|
taosArrayDestroy(pInfo->pSortInfo);
|
||||||
taosArrayDestroy(pInfo->matchInfo.pList);
|
taosArrayDestroy(pInfo->matchInfo.pList);
|
||||||
|
|
||||||
|
tsortDestroySortHandle(pInfo->pCurrSortHandle);
|
||||||
|
pInfo->pCurrSortHandle = NULL;
|
||||||
|
|
||||||
taosMemoryFreeClear(param);
|
taosMemoryFreeClear(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,6 +566,7 @@ int32_t doOpenMultiwayMergeOperator(SOperatorInfo* pOperator) {
|
||||||
for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
|
for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
|
||||||
SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource));
|
SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource));
|
||||||
ps->param = pOperator->pDownstream[i];
|
ps->param = pOperator->pDownstream[i];
|
||||||
|
ps->onlyRef = true;
|
||||||
tsortAddSource(pInfo->pSortHandle, ps);
|
tsortAddSource(pInfo->pSortHandle, ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,22 @@ static int32_t sortComparCleanup(SMsortComparParam* cmpParam) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tsortClearOrderdSource(SArray *pOrderedSource) {
|
||||||
|
for (size_t i = 0; i < taosArrayGetSize(pOrderedSource); i++) {
|
||||||
|
SSortSource** pSource = taosArrayGet(pOrderedSource, i);
|
||||||
|
if (NULL == *pSource) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((*pSource)->param && !(*pSource)->onlyRef) {
|
||||||
|
taosMemoryFree((*pSource)->param);
|
||||||
|
}
|
||||||
|
taosMemoryFreeClear(*pSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosArrayClear(pOrderedSource);
|
||||||
|
}
|
||||||
|
|
||||||
void tsortDestroySortHandle(SSortHandle* pSortHandle) {
|
void tsortDestroySortHandle(SSortHandle* pSortHandle) {
|
||||||
if (pSortHandle == NULL) {
|
if (pSortHandle == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -123,10 +139,8 @@ void tsortDestroySortHandle(SSortHandle* pSortHandle) {
|
||||||
destroyDiskbasedBuf(pSortHandle->pBuf);
|
destroyDiskbasedBuf(pSortHandle->pBuf);
|
||||||
taosMemoryFreeClear(pSortHandle->idStr);
|
taosMemoryFreeClear(pSortHandle->idStr);
|
||||||
blockDataDestroy(pSortHandle->pDataBlock);
|
blockDataDestroy(pSortHandle->pDataBlock);
|
||||||
for (size_t i = 0; i < taosArrayGetSize(pSortHandle->pOrderedSource); i++) {
|
|
||||||
SSortSource** pSource = taosArrayGet(pSortHandle->pOrderedSource, i);
|
tsortClearOrderdSource(pSortHandle->pOrderedSource);
|
||||||
taosMemoryFreeClear(*pSource);
|
|
||||||
}
|
|
||||||
taosArrayDestroy(pSortHandle->pOrderedSource);
|
taosArrayDestroy(pSortHandle->pOrderedSource);
|
||||||
taosMemoryFreeClear(pSortHandle);
|
taosMemoryFreeClear(pSortHandle);
|
||||||
}
|
}
|
||||||
|
@ -561,7 +575,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayClear(pHandle->pOrderedSource);
|
tsortClearOrderdSource(pHandle->pOrderedSource);
|
||||||
taosArrayAddAll(pHandle->pOrderedSource, pResList);
|
taosArrayAddAll(pHandle->pOrderedSource, pResList);
|
||||||
taosArrayDestroy(pResList);
|
taosArrayDestroy(pResList);
|
||||||
|
|
||||||
|
@ -598,8 +612,11 @@ static int32_t createInitialSources(SSortHandle* pHandle) {
|
||||||
size_t sortBufSize = pHandle->numOfPages * pHandle->pageSize;
|
size_t sortBufSize = pHandle->numOfPages * pHandle->pageSize;
|
||||||
|
|
||||||
if (pHandle->type == SORT_SINGLESOURCE_SORT) {
|
if (pHandle->type == SORT_SINGLESOURCE_SORT) {
|
||||||
SSortSource* source = taosArrayGetP(pHandle->pOrderedSource, 0);
|
SSortSource** pSource = taosArrayGet(pHandle->pOrderedSource, 0);
|
||||||
taosArrayClear(pHandle->pOrderedSource);
|
SSortSource* source = *pSource;
|
||||||
|
*pSource = NULL;
|
||||||
|
|
||||||
|
tsortClearOrderdSource(pHandle->pOrderedSource);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
SSDataBlock* pBlock = pHandle->fetchfp(source->param);
|
SSDataBlock* pBlock = pHandle->fetchfp(source->param);
|
||||||
|
@ -623,6 +640,10 @@ static int32_t createInitialSources(SSortHandle* pHandle) {
|
||||||
|
|
||||||
int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock);
|
int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
if (source->param && !source->onlyRef) {
|
||||||
|
taosMemoryFree(source->param);
|
||||||
|
}
|
||||||
|
taosMemoryFree(source);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -632,6 +653,10 @@ static int32_t createInitialSources(SSortHandle* pHandle) {
|
||||||
int64_t p = taosGetTimestampUs();
|
int64_t p = taosGetTimestampUs();
|
||||||
code = blockDataSort(pHandle->pDataBlock, pHandle->pSortInfo);
|
code = blockDataSort(pHandle->pDataBlock, pHandle->pSortInfo);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
if (source->param && !source->onlyRef) {
|
||||||
|
taosMemoryFree(source->param);
|
||||||
|
}
|
||||||
|
taosMemoryFree(source);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -642,6 +667,11 @@ static int32_t createInitialSources(SSortHandle* pHandle) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (source->param && !source->onlyRef) {
|
||||||
|
taosMemoryFree(source->param);
|
||||||
|
}
|
||||||
|
taosMemoryFree(source);
|
||||||
|
|
||||||
if (pHandle->pDataBlock != NULL && pHandle->pDataBlock->info.rows > 0) {
|
if (pHandle->pDataBlock != NULL && pHandle->pDataBlock->info.rows > 0) {
|
||||||
size_t size = blockDataGetSize(pHandle->pDataBlock);
|
size_t size = blockDataGetSize(pHandle->pDataBlock);
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ static uint64_t allocatePositionInFile(SDiskbasedBuf* pBuf, size_t size) {
|
||||||
|
|
||||||
static void setPageNotInBuf(SPageInfo* pPageInfo) { pPageInfo->pData = NULL; }
|
static void setPageNotInBuf(SPageInfo* pPageInfo) { pPageInfo->pData = NULL; }
|
||||||
|
|
||||||
static FORCE_INLINE size_t getAllocPageSize(int32_t pageSize) { return pageSize + POINTER_BYTES + 2; }
|
static FORCE_INLINE size_t getAllocPageSize(int32_t pageSize) { return pageSize + POINTER_BYTES + sizeof(SFilePage); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* +--------------------------+-------------------+--------------+
|
* +--------------------------+-------------------+--------------+
|
||||||
|
|
Loading…
Reference in New Issue