mem exception handle
This commit is contained in:
parent
98cbb92ad9
commit
83d8e3a524
|
@ -108,7 +108,7 @@ int32_t tBufferReserve(SBuffer *pBuffer, int64_t nData, void **ppData);
|
||||||
int32_t tRowBuild(SArray *aColVal, const STSchema *pTSchema, SRow **ppRow);
|
int32_t tRowBuild(SArray *aColVal, const STSchema *pTSchema, SRow **ppRow);
|
||||||
int32_t tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
int32_t tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
||||||
void tRowDestroy(SRow *pRow);
|
void tRowDestroy(SRow *pRow);
|
||||||
void tRowSort(SArray *aRowP);
|
int32_t tRowSort(SArray *aRowP);
|
||||||
int32_t tRowMerge(SArray *aRowP, STSchema *pTSchema, int8_t flag);
|
int32_t tRowMerge(SArray *aRowP, STSchema *pTSchema, int8_t flag);
|
||||||
int32_t tRowUpsertColData(SRow *pRow, STSchema *pTSchema, SColData *aColData, int32_t nColData, int32_t flag);
|
int32_t tRowUpsertColData(SRow *pRow, STSchema *pTSchema, SColData *aColData, int32_t nColData, int32_t flag);
|
||||||
|
|
||||||
|
|
|
@ -61,8 +61,9 @@ void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __
|
||||||
* @param numOfElem
|
* @param numOfElem
|
||||||
* @param size
|
* @param size
|
||||||
* @param comparFn
|
* @param comparFn
|
||||||
|
* @return int32_t 0 for success, other for failure.
|
||||||
*/
|
*/
|
||||||
void taosMergeSort(void *src, int64_t numOfElem, int64_t size, __compar_fn_t comparFn);
|
int32_t taosMergeSort(void *src, int64_t numOfElem, int64_t size, __compar_fn_t comparFn);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* binary search, with range support
|
* binary search, with range support
|
||||||
|
|
|
@ -225,7 +225,7 @@ void taosArraySort(SArray* pArray, __compar_fn_t comparFn);
|
||||||
* @param pArray
|
* @param pArray
|
||||||
* @param compar
|
* @param compar
|
||||||
*/
|
*/
|
||||||
void taosArrayMSort(SArray* pArray, __compar_fn_t comparFn);
|
int32_t taosArrayMSort(SArray* pArray, __compar_fn_t comparFn);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* search the array
|
* search the array
|
||||||
|
|
|
@ -610,9 +610,13 @@ _exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tRowSort(SArray *aRowP) {
|
int32_t tRowSort(SArray *aRowP) {
|
||||||
if (TARRAY_SIZE(aRowP) <= 1) return;
|
if (TARRAY_SIZE(aRowP) <= 1) return 0;
|
||||||
taosArrayMSort(aRowP, tRowPCmprFn);
|
int32_t code = taosArrayMSort(aRowP, tRowPCmprFn);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
uError("taosArrayMSort failed caused by %d", code);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tRowMerge(SArray *aRowP, STSchema *pTSchema, int8_t flag) {
|
int32_t tRowMerge(SArray *aRowP, STSchema *pTSchema, int8_t flag) {
|
||||||
|
|
|
@ -289,8 +289,8 @@ int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** pp
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disorderTs) {
|
if (disorderTs) {
|
||||||
tRowSort(tbData.aRowP);
|
if ((tRowSort(tbData.aRowP) != TSDB_CODE_SUCCESS) ||
|
||||||
if ((terrno = tRowMerge(tbData.aRowP, (STSchema*)pTSchema, 0)) != 0) {
|
(terrno = tRowMerge(tbData.aRowP, (STSchema*)pTSchema, 0)) != 0) {
|
||||||
goto _end;
|
goto _end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -495,9 +495,9 @@ int32_t insMergeTableDataCxt(SHashObj* pTableHash, SArray** pVgDataBlocks) {
|
||||||
tColDataSortMerge(pTableCxt->pData->aCol);
|
tColDataSortMerge(pTableCxt->pData->aCol);
|
||||||
} else {
|
} else {
|
||||||
if (!pTableCxt->ordered) {
|
if (!pTableCxt->ordered) {
|
||||||
tRowSort(pTableCxt->pData->aRowP);
|
code = tRowSort(pTableCxt->pData->aRowP);
|
||||||
}
|
}
|
||||||
if (!pTableCxt->ordered || pTableCxt->duplicateTs) {
|
if (code == TSDB_CODE_SUCCESS && (!pTableCxt->ordered || pTableCxt->duplicateTs)) {
|
||||||
code = tRowMerge(pTableCxt->pData->aRowP, pTableCxt->pSchema, 0);
|
code = tRowMerge(pTableCxt->pData->aRowP, pTableCxt->pSchema, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -312,10 +312,12 @@ static void taosMerge(void *src, int32_t start, int32_t leftend, int32_t end, in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosMergeSortHelper(void *src, int64_t numOfElem, int64_t size, const void *param, __ext_compar_fn_t comparFn) {
|
static int32_t taosMergeSortHelper(void *src, int64_t numOfElem, int64_t size, const void *param,
|
||||||
|
__ext_compar_fn_t comparFn) {
|
||||||
// short array sort, instead of merge sort process
|
// short array sort, instead of merge sort process
|
||||||
const int32_t THRESHOLD_SIZE = 6;
|
const int32_t THRESHOLD_SIZE = 6;
|
||||||
char *buf = taosMemoryCalloc(1, size); // prepare the swap buffer
|
char *buf = taosMemoryCalloc(1, size); // prepare the swap buffer
|
||||||
|
if (buf == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
for (int32_t start = 0; start < numOfElem - 1; start += THRESHOLD_SIZE) {
|
for (int32_t start = 0; start < numOfElem - 1; start += THRESHOLD_SIZE) {
|
||||||
int32_t end = (start + THRESHOLD_SIZE - 1) <= numOfElem - 1 ? (start + THRESHOLD_SIZE - 1) : numOfElem - 1;
|
int32_t end = (start + THRESHOLD_SIZE - 1) <= numOfElem - 1 ? (start + THRESHOLD_SIZE - 1) : numOfElem - 1;
|
||||||
tInsertSort(src, size, start, end, param, comparFn, buf);
|
tInsertSort(src, size, start, end, param, comparFn, buf);
|
||||||
|
@ -325,6 +327,7 @@ static void taosMergeSortHelper(void *src, int64_t numOfElem, int64_t size, cons
|
||||||
if (numOfElem > THRESHOLD_SIZE) {
|
if (numOfElem > THRESHOLD_SIZE) {
|
||||||
int32_t currSize;
|
int32_t currSize;
|
||||||
void *tmp = taosMemoryMalloc(numOfElem * size);
|
void *tmp = taosMemoryMalloc(numOfElem * size);
|
||||||
|
if (tmp == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
for (currSize = THRESHOLD_SIZE; currSize <= numOfElem - 1; currSize = 2 * currSize) {
|
for (currSize = THRESHOLD_SIZE; currSize <= numOfElem - 1; currSize = 2 * currSize) {
|
||||||
int32_t leftStart;
|
int32_t leftStart;
|
||||||
|
@ -340,6 +343,7 @@ static void taosMergeSortHelper(void *src, int64_t numOfElem, int64_t size, cons
|
||||||
|
|
||||||
taosMemoryFreeClear(tmp);
|
taosMemoryFreeClear(tmp);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t msortHelper(const void *p1, const void *p2, const void *param) {
|
int32_t msortHelper(const void *p1, const void *p2, const void *param) {
|
||||||
|
@ -348,7 +352,7 @@ int32_t msortHelper(const void *p1, const void *p2, const void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void taosMergeSort(void *src, int64_t numOfElem, int64_t size, __compar_fn_t comparFn) {
|
int32_t taosMergeSort(void *src, int64_t numOfElem, int64_t size, __compar_fn_t comparFn) {
|
||||||
void *param = comparFn;
|
void *param = comparFn;
|
||||||
taosMergeSortHelper(src, numOfElem, size, param, msortHelper);
|
return taosMergeSortHelper(src, numOfElem, size, param, msortHelper);
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,8 +417,8 @@ void taosArraySort(SArray* pArray, __compar_fn_t compar) {
|
||||||
taosSort(pArray->pData, pArray->size, pArray->elemSize, compar);
|
taosSort(pArray->pData, pArray->size, pArray->elemSize, compar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosArrayMSort(SArray* pArray, __compar_fn_t compar) {
|
int32_t taosArrayMSort(SArray* pArray, __compar_fn_t compar) {
|
||||||
taosMergeSort(pArray->pData, pArray->size, pArray->elemSize, compar);
|
return taosMergeSort(pArray->pData, pArray->size, pArray->elemSize, compar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags) {
|
void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags) {
|
||||||
|
|
Loading…
Reference in New Issue