memory alloc may fail
This commit is contained in:
parent
c3413fd830
commit
e11ae1f46e
|
@ -328,11 +328,11 @@ static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; }
|
||||||
int tdAllocMemForCol(SDataCol *pCol, int maxPoints);
|
int tdAllocMemForCol(SDataCol *pCol, int maxPoints);
|
||||||
|
|
||||||
void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints);
|
void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints);
|
||||||
void dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints);
|
int dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints);
|
||||||
void dataColSetOffset(SDataCol *pCol, int nEle);
|
void dataColSetOffset(SDataCol *pCol, int nEle);
|
||||||
|
|
||||||
bool isNEleNull(SDataCol *pCol, int nEle);
|
bool isNEleNull(SDataCol *pCol, int nEle);
|
||||||
void dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints);
|
int dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints);
|
||||||
|
|
||||||
// Get the data pointer from a column-wised data
|
// Get the data pointer from a column-wised data
|
||||||
static FORCE_INLINE const void *tdGetColDataOfRow(SDataCol *pCol, int row) {
|
static FORCE_INLINE const void *tdGetColDataOfRow(SDataCol *pCol, int row) {
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2,
|
static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2,
|
||||||
int limit2, int tRows, bool forceSetNull);
|
int limit2, int tRows, bool forceSetNull);
|
||||||
|
|
||||||
//TODO: change caller to use return val
|
|
||||||
int tdAllocMemForCol(SDataCol *pCol, int maxPoints) {
|
int tdAllocMemForCol(SDataCol *pCol, int maxPoints) {
|
||||||
int spaceNeeded = pCol->bytes * maxPoints;
|
int spaceNeeded = pCol->bytes * maxPoints;
|
||||||
if(IS_VAR_DATA_TYPE(pCol->type)) {
|
if(IS_VAR_DATA_TYPE(pCol->type)) {
|
||||||
|
@ -31,7 +30,7 @@ int tdAllocMemForCol(SDataCol *pCol, int maxPoints) {
|
||||||
if(pCol->spaceSize < spaceNeeded) {
|
if(pCol->spaceSize < spaceNeeded) {
|
||||||
void* ptr = realloc(pCol->pData, spaceNeeded);
|
void* ptr = realloc(pCol->pData, spaceNeeded);
|
||||||
if(ptr == NULL) {
|
if(ptr == NULL) {
|
||||||
uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)pCol->spaceSize,
|
uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)spaceNeeded,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -239,20 +238,22 @@ void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints) {
|
||||||
pDataCol->len = 0;
|
pDataCol->len = 0;
|
||||||
}
|
}
|
||||||
// value from timestamp should be TKEY here instead of TSKEY
|
// value from timestamp should be TKEY here instead of TSKEY
|
||||||
void dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints) {
|
int dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints) {
|
||||||
ASSERT(pCol != NULL && value != NULL);
|
ASSERT(pCol != NULL && value != NULL);
|
||||||
|
|
||||||
if (isAllRowsNull(pCol)) {
|
if (isAllRowsNull(pCol)) {
|
||||||
if (isNull(value, pCol->type)) {
|
if (isNull(value, pCol->type)) {
|
||||||
// all null value yet, just return
|
// all null value yet, just return
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numOfRows > 0) {
|
if (numOfRows > 0) {
|
||||||
// Find the first not null value, fill all previouse values as NULL
|
// Find the first not null value, fill all previouse values as NULL
|
||||||
dataColSetNEleNull(pCol, numOfRows, maxPoints);
|
if(dataColSetNEleNull(pCol, numOfRows, maxPoints) < 0)
|
||||||
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
tdAllocMemForCol(pCol, maxPoints);
|
if(tdAllocMemForCol(pCol, maxPoints) < 0)
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,6 +269,7 @@ void dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxP
|
||||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, pCol->bytes);
|
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, pCol->bytes);
|
||||||
pCol->len += pCol->bytes;
|
pCol->len += pCol->bytes;
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNEleNull(SDataCol *pCol, int nEle) {
|
bool isNEleNull(SDataCol *pCol, int nEle) {
|
||||||
|
@ -290,8 +292,10 @@ static FORCE_INLINE void dataColSetNullAt(SDataCol *pCol, int index) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints) {
|
int dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints) {
|
||||||
tdAllocMemForCol(pCol, maxPoints);
|
if(tdAllocMemForCol(pCol, maxPoints)){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||||
pCol->len = 0;
|
pCol->len = 0;
|
||||||
|
@ -302,6 +306,7 @@ void dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints) {
|
||||||
setNullN(pCol->pData, pCol->type, pCol->bytes, nEle);
|
setNullN(pCol->pData, pCol->type, pCol->bytes, nEle);
|
||||||
pCol->len = TYPE_BYTES[pCol->type] * nEle;
|
pCol->len = TYPE_BYTES[pCol->type] * nEle;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dataColSetOffset(SDataCol *pCol, int nEle) {
|
void dataColSetOffset(SDataCol *pCol, int nEle) {
|
||||||
|
@ -414,7 +419,10 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) {
|
||||||
|
|
||||||
if (keepData) {
|
if (keepData) {
|
||||||
if (pDataCols->cols[i].len > 0) {
|
if (pDataCols->cols[i].len > 0) {
|
||||||
tdAllocMemForCol(&pRet->cols[i], pRet->maxPoints);
|
if(tdAllocMemForCol(&pRet->cols[i], pRet->maxPoints) < 0) {
|
||||||
|
tdFreeDataCols(pRet);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
pRet->cols[i].len = pDataCols->cols[i].len;
|
pRet->cols[i].len = pDataCols->cols[i].len;
|
||||||
memcpy(pRet->cols[i].pData, pDataCols->cols[i].pData, pDataCols->cols[i].len);
|
memcpy(pRet->cols[i].pData, pDataCols->cols[i].pData, pDataCols->cols[i].len);
|
||||||
if (IS_VAR_DATA_TYPE(pRet->cols[i].type)) {
|
if (IS_VAR_DATA_TYPE(pRet->cols[i].type)) {
|
||||||
|
|
|
@ -1277,6 +1277,7 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
||||||
|
|
||||||
if (key1 < key2) {
|
if (key1 < key2) {
|
||||||
for (int i = 0; i < pDataCols->numOfCols; i++) {
|
for (int i = 0; i < pDataCols->numOfCols; i++) {
|
||||||
|
//TODO: dataColAppendVal may fail
|
||||||
dataColAppendVal(pTarget->cols + i, tdGetColDataOfRow(pDataCols->cols + i, *iter), pTarget->numOfRows,
|
dataColAppendVal(pTarget->cols + i, tdGetColDataOfRow(pDataCols->cols + i, *iter), pTarget->numOfRows,
|
||||||
pTarget->maxPoints);
|
pTarget->maxPoints);
|
||||||
}
|
}
|
||||||
|
@ -1308,6 +1309,7 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
||||||
ASSERT(!isRowDel);
|
ASSERT(!isRowDel);
|
||||||
|
|
||||||
for (int i = 0; i < pDataCols->numOfCols; i++) {
|
for (int i = 0; i < pDataCols->numOfCols; i++) {
|
||||||
|
//TODO: dataColAppendVal may fail
|
||||||
dataColAppendVal(pTarget->cols + i, tdGetColDataOfRow(pDataCols->cols + i, *iter), pTarget->numOfRows,
|
dataColAppendVal(pTarget->cols + i, tdGetColDataOfRow(pDataCols->cols + i, *iter), pTarget->numOfRows,
|
||||||
pTarget->maxPoints);
|
pTarget->maxPoints);
|
||||||
}
|
}
|
||||||
|
|
|
@ -751,7 +751,6 @@ static SMemRow tsdbInsertDupKeyMerge(SMemRow row1, SMemRow row2, STsdbRepo* pRep
|
||||||
memRowCpy(pMem, tmp);
|
memRowCpy(pMem, tmp);
|
||||||
|
|
||||||
(*pPoints)++;
|
(*pPoints)++;
|
||||||
|
|
||||||
*pLastRow = pMem;
|
*pLastRow = pMem;
|
||||||
return pMem;
|
return pMem;
|
||||||
}
|
}
|
||||||
|
|
|
@ -463,6 +463,7 @@ static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDat
|
||||||
SDataCol *pDataCol = &(pDataCols->cols[dcol]);
|
SDataCol *pDataCol = &(pDataCols->cols[dcol]);
|
||||||
if (dcol != 0 && ccol >= pBlockData->numOfCols) {
|
if (dcol != 0 && ccol >= pBlockData->numOfCols) {
|
||||||
// Set current column as NULL and forward
|
// Set current column as NULL and forward
|
||||||
|
// TODO: dataColSetNEleNull may fail
|
||||||
dataColSetNEleNull(pDataCol, pBlock->numOfRows, pDataCols->maxPoints);
|
dataColSetNEleNull(pDataCol, pBlock->numOfRows, pDataCols->maxPoints);
|
||||||
dcol++;
|
dcol++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -503,6 +504,7 @@ static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDat
|
||||||
ccol++;
|
ccol++;
|
||||||
} else {
|
} else {
|
||||||
// Set current column as NULL and forward
|
// Set current column as NULL and forward
|
||||||
|
// TODO: dataColSetNEleNull may fail
|
||||||
dataColSetNEleNull(pDataCol, pBlock->numOfRows, pDataCols->maxPoints);
|
dataColSetNEleNull(pDataCol, pBlock->numOfRows, pDataCols->maxPoints);
|
||||||
dcol++;
|
dcol++;
|
||||||
}
|
}
|
||||||
|
@ -608,6 +610,7 @@ static int tsdbLoadBlockDataColsImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBlockCol == NULL) {
|
if (pBlockCol == NULL) {
|
||||||
|
// TODO: dataColSetNEleNull may fail
|
||||||
dataColSetNEleNull(pDataCol, pBlock->numOfRows, pDataCols->maxPoints);
|
dataColSetNEleNull(pDataCol, pBlock->numOfRows, pDataCols->maxPoints);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue