refactor: do some internal refactor.
This commit is contained in:
parent
27a53a0c64
commit
c597a1e4ce
|
@ -150,14 +150,6 @@ void* taosArrayGetLast(const SArray* pArray);
|
|||
*/
|
||||
size_t taosArrayGetSize(const SArray* pArray);
|
||||
|
||||
/**
|
||||
* set the size of array
|
||||
* @param pArray
|
||||
* @param size size of the array
|
||||
* @return
|
||||
*/
|
||||
void taosArraySetSize(SArray* pArray, size_t size);
|
||||
|
||||
/**
|
||||
* insert data into array
|
||||
* @param pArray
|
||||
|
|
|
@ -2356,9 +2356,7 @@ const char* blockDecode(SSDataBlock* pBlock, const char* pData) {
|
|||
pStart += sizeof(uint64_t);
|
||||
|
||||
if (pBlock->pDataBlock == NULL) {
|
||||
pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData));
|
||||
|
||||
taosArraySetSize(pBlock->pDataBlock, numOfCols);
|
||||
pBlock->pDataBlock = taosArrayInit_s(numOfCols, sizeof(SColumnInfoData), numOfCols);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
|
|
|
@ -477,9 +477,8 @@ static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStre
|
|||
tstrncpy(createReq.name, pStream->targetSTbName, TSDB_TABLE_FNAME_LEN);
|
||||
createReq.numOfColumns = pStream->outputSchema.nCols;
|
||||
createReq.numOfTags = 1; // group id
|
||||
createReq.pColumns = taosArrayInit(createReq.numOfColumns, sizeof(SField));
|
||||
createReq.pColumns = taosArrayInit_s(createReq.numOfColumns, sizeof(SField), createReq.numOfColumns);
|
||||
// build fields
|
||||
taosArraySetSize(createReq.pColumns, createReq.numOfColumns);
|
||||
for (int32_t i = 0; i < createReq.numOfColumns; i++) {
|
||||
SField *pField = taosArrayGet(createReq.pColumns, i);
|
||||
tstrncpy(pField->name, pStream->outputSchema.pSchema[i].name, TSDB_COL_NAME_LEN);
|
||||
|
@ -487,8 +486,8 @@ static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStre
|
|||
pField->type = pStream->outputSchema.pSchema[i].type;
|
||||
pField->bytes = pStream->outputSchema.pSchema[i].bytes;
|
||||
}
|
||||
createReq.pTags = taosArrayInit(createReq.numOfTags, sizeof(SField));
|
||||
taosArraySetSize(createReq.pTags, 1);
|
||||
createReq.pTags = taosArrayInit_s(createReq.numOfTags, sizeof(SField), 1);
|
||||
|
||||
// build tags
|
||||
SField *pField = taosArrayGet(createReq.pTags, 0);
|
||||
strcpy(pField->name, "group_id");
|
||||
|
|
|
@ -1054,9 +1054,7 @@ static int32_t tsdbMergeSkyline(SArray *pSkyline1, SArray *pSkyline2, SArray *pS
|
|||
i2++;
|
||||
}
|
||||
|
||||
taosArraySetSize(pSkyline, TARRAY_ELEM_IDX(pSkyline, pItem));
|
||||
|
||||
_exit:
|
||||
pSkyline->size = TARRAY_ELEM_IDX(pSkyline, pItem);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -759,28 +759,30 @@ int walMetaDeserialize(SWal* pWal, const char* bytes) {
|
|||
// deserialize
|
||||
SArray* pArray = pWal->fileInfoSet;
|
||||
taosArrayEnsureCap(pArray, sz);
|
||||
SWalFileInfo* pData = pArray->pData;
|
||||
|
||||
for (int i = 0; i < sz; i++) {
|
||||
cJSON* pInfoJson = cJSON_GetArrayItem(pFiles, i);
|
||||
pInfoJson = cJSON_GetArrayItem(pFiles, i);
|
||||
if (!pInfoJson) goto _err;
|
||||
SWalFileInfo* pInfo = &pData[i];
|
||||
|
||||
SWalFileInfo info = {0};
|
||||
|
||||
pField = cJSON_GetObjectItem(pInfoJson, "firstVer");
|
||||
if (!pField) goto _err;
|
||||
pInfo->firstVer = atoll(cJSON_GetStringValue(pField));
|
||||
info.firstVer = atoll(cJSON_GetStringValue(pField));
|
||||
pField = cJSON_GetObjectItem(pInfoJson, "lastVer");
|
||||
if (!pField) goto _err;
|
||||
pInfo->lastVer = atoll(cJSON_GetStringValue(pField));
|
||||
info.lastVer = atoll(cJSON_GetStringValue(pField));
|
||||
pField = cJSON_GetObjectItem(pInfoJson, "createTs");
|
||||
if (!pField) goto _err;
|
||||
pInfo->createTs = atoll(cJSON_GetStringValue(pField));
|
||||
info.createTs = atoll(cJSON_GetStringValue(pField));
|
||||
pField = cJSON_GetObjectItem(pInfoJson, "closeTs");
|
||||
if (!pField) goto _err;
|
||||
pInfo->closeTs = atoll(cJSON_GetStringValue(pField));
|
||||
info.closeTs = atoll(cJSON_GetStringValue(pField));
|
||||
pField = cJSON_GetObjectItem(pInfoJson, "fileSize");
|
||||
if (!pField) goto _err;
|
||||
pInfo->fileSize = atoll(cJSON_GetStringValue(pField));
|
||||
info.fileSize = atoll(cJSON_GetStringValue(pField));
|
||||
taosArrayPush(pArray, &info);
|
||||
}
|
||||
taosArraySetSize(pArray, sz);
|
||||
pWal->fileInfoSet = pArray;
|
||||
pWal->writeCur = sz - 1;
|
||||
cJSON_Delete(pRoot);
|
||||
|
|
|
@ -122,16 +122,16 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
|||
|
||||
// delete files in descending order
|
||||
int fileSetSize = taosArrayGetSize(pWal->fileInfoSet);
|
||||
for (int i = fileSetSize - 1; i >= pWal->writeCur + 1; i--) {
|
||||
walBuildLogName(pWal, ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr);
|
||||
for (int i = pWal->writeCur + 1; i < fileSetSize; i++) {
|
||||
SWalFileInfo* pInfo = taosArrayPop(pWal->fileInfoSet);
|
||||
|
||||
walBuildLogName(pWal, pInfo->firstVer, fnameStr);
|
||||
wDebug("vgId:%d, wal remove file %s for rollback", pWal->cfg.vgId, fnameStr);
|
||||
taosRemoveFile(fnameStr);
|
||||
walBuildIdxName(pWal, ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr);
|
||||
walBuildIdxName(pWal, pInfo->firstVer, fnameStr);
|
||||
wDebug("vgId:%d, wal remove file %s for rollback", pWal->cfg.vgId, fnameStr);
|
||||
taosRemoveFile(fnameStr);
|
||||
}
|
||||
// pop from fileInfoSet
|
||||
taosArraySetSize(pWal->fileInfoSet, pWal->writeCur + 1);
|
||||
}
|
||||
|
||||
walBuildIdxName(pWal, walGetCurFileFirstVer(pWal), fnameStr);
|
||||
|
|
|
@ -36,7 +36,7 @@ SArray* taosArrayInit(size_t size, size_t elemSize) {
|
|||
}
|
||||
|
||||
pArray->size = 0;
|
||||
pArray->pData = taosMemoryMalloc(size * elemSize);
|
||||
pArray->pData = taosMemoryCalloc(size, elemSize);
|
||||
if (pArray->pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(pArray);
|
||||
|
@ -258,11 +258,6 @@ size_t taosArrayGetSize(const SArray* pArray) {
|
|||
return pArray->size;
|
||||
}
|
||||
|
||||
void taosArraySetSize(SArray* pArray, size_t size) {
|
||||
assert(size <= pArray->capacity);
|
||||
pArray->size = size;
|
||||
}
|
||||
|
||||
void* taosArrayInsert(SArray* pArray, size_t index, void* pData) {
|
||||
if (pArray == NULL || pData == NULL) {
|
||||
return NULL;
|
||||
|
|
|
@ -325,11 +325,10 @@ int32_t tjsonToTArray(const SJson* pJson, const char* pName, FToObject func, SAr
|
|||
const cJSON* jArray = tjsonGetObjectItem(pJson, pName);
|
||||
int32_t size = tjsonGetArraySize(jArray);
|
||||
if (size > 0) {
|
||||
*pArray = taosArrayInit(size, itemSize);
|
||||
*pArray = taosArrayInit_s(size, itemSize, size);
|
||||
if (NULL == *pArray) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
taosArraySetSize(*pArray, size);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
int32_t code = func(tjsonGetArrayItem(jArray, i), taosArrayGet(*pArray, i));
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
|
|
Loading…
Reference in New Issue