enh: refactor return code
This commit is contained in:
parent
90e4d16fcc
commit
aa064abb47
|
@ -266,7 +266,11 @@ void *taosMemoryMalloc(int64_t size) {
|
||||||
|
|
||||||
return (char *)tmp + sizeof(TdMemoryInfo);
|
return (char *)tmp + sizeof(TdMemoryInfo);
|
||||||
#else
|
#else
|
||||||
return malloc(size);
|
void *p = malloc(size);
|
||||||
|
if (!p) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +287,11 @@ void *taosMemoryCalloc(int64_t num, int64_t size) {
|
||||||
|
|
||||||
return (char *)tmp + sizeof(TdMemoryInfo);
|
return (char *)tmp + sizeof(TdMemoryInfo);
|
||||||
#else
|
#else
|
||||||
return calloc(num, size);
|
void *p = calloc(num, size);
|
||||||
|
if (!p) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,7 +317,11 @@ void *taosMemoryRealloc(void *ptr, int64_t size) {
|
||||||
|
|
||||||
return (char *)tmp + sizeof(TdMemoryInfo);
|
return (char *)tmp + sizeof(TdMemoryInfo);
|
||||||
#else
|
#else
|
||||||
return realloc(ptr, size);
|
void *p = realloc(ptr, size);
|
||||||
|
if (!p) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,9 @@
|
||||||
#include "tcoding.h"
|
#include "tcoding.h"
|
||||||
|
|
||||||
// todo refactor API
|
// todo refactor API
|
||||||
#define BOUNDARY_SIZE 1024*1024*1024 // 1G
|
#define BOUNDARY_SIZE 1024 * 1024 * 1024 // 1G
|
||||||
#define BOUNDARY_SMALL_FACTOR 1.2
|
#define BOUNDARY_SMALL_FACTOR 1.2
|
||||||
#define BOUNDARY_BIG_FACTOR 2
|
#define BOUNDARY_BIG_FACTOR 2
|
||||||
|
|
||||||
SArray* taosArrayInit(size_t size, size_t elemSize) {
|
SArray* taosArrayInit(size_t size, size_t elemSize) {
|
||||||
if (elemSize == 0) {
|
if (elemSize == 0) {
|
||||||
|
@ -34,12 +34,14 @@ SArray* taosArrayInit(size_t size, size_t elemSize) {
|
||||||
|
|
||||||
SArray* pArray = taosMemoryMalloc(sizeof(SArray));
|
SArray* pArray = taosMemoryMalloc(sizeof(SArray));
|
||||||
if (pArray == NULL) {
|
if (pArray == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pArray->size = 0;
|
pArray->size = 0;
|
||||||
pArray->pData = taosMemoryCalloc(size, elemSize);
|
pArray->pData = taosMemoryCalloc(size, elemSize);
|
||||||
if (pArray->pData == NULL) {
|
if (pArray->pData == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
taosMemoryFree(pArray);
|
taosMemoryFree(pArray);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +77,7 @@ static int32_t taosArrayResize(SArray* pArray) {
|
||||||
|
|
||||||
void* tmp = taosMemoryRealloc(pArray->pData, size * pArray->elemSize);
|
void* tmp = taosMemoryRealloc(pArray->pData, size * pArray->elemSize);
|
||||||
if (tmp == NULL) { // reallocate failed, the original buffer remains
|
if (tmp == NULL) { // reallocate failed, the original buffer remains
|
||||||
return -1;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
pArray->pData = tmp;
|
pArray->pData = tmp;
|
||||||
|
@ -99,7 +101,7 @@ int32_t taosArrayEnsureCap(SArray* pArray, size_t newCap) {
|
||||||
|
|
||||||
pArray->pData = taosMemoryRealloc(pArray->pData, tsize * pArray->elemSize);
|
pArray->pData = taosMemoryRealloc(pArray->pData, tsize * pArray->elemSize);
|
||||||
if (pArray->pData == NULL) {
|
if (pArray->pData == NULL) {
|
||||||
return -1;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
pArray->capacity = tsize;
|
pArray->capacity = tsize;
|
||||||
|
@ -109,10 +111,13 @@ int32_t taosArrayEnsureCap(SArray* pArray, size_t newCap) {
|
||||||
|
|
||||||
void* taosArrayAddBatch(SArray* pArray, const void* pData, int32_t nEles) {
|
void* taosArrayAddBatch(SArray* pArray, const void* pData, int32_t nEles) {
|
||||||
if (pData == NULL) {
|
if (pData == NULL) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosArrayEnsureCap(pArray, pArray->size + nEles) != 0) {
|
int32_t code = taosArrayEnsureCap(pArray, pArray->size + nEles);
|
||||||
|
if (code) {
|
||||||
|
terrno = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,12 +171,15 @@ void* taosArrayAddAll(SArray* pArray, const SArray* pInput) {
|
||||||
if (pInput) {
|
if (pInput) {
|
||||||
return taosArrayAddBatch(pArray, pInput->pData, (int32_t)taosArrayGetSize(pInput));
|
return taosArrayAddBatch(pArray, pInput->pData, (int32_t)taosArrayGetSize(pInput));
|
||||||
} else {
|
} else {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void* taosArrayReserve(SArray* pArray, int32_t num) {
|
void* taosArrayReserve(SArray* pArray, int32_t num) {
|
||||||
if (taosArrayEnsureCap(pArray, pArray->size + num) != 0) {
|
int32_t code = taosArrayEnsureCap(pArray, pArray->size + num);
|
||||||
|
if (code) {
|
||||||
|
terrno = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,11 +202,13 @@ void* taosArrayPop(SArray* pArray) {
|
||||||
|
|
||||||
void* taosArrayGet(const SArray* pArray, size_t index) {
|
void* taosArrayGet(const SArray* pArray, size_t index) {
|
||||||
if (NULL == pArray) {
|
if (NULL == pArray) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index >= pArray->size) {
|
if (index >= pArray->size) {
|
||||||
uError("index is out of range, current:%" PRIzu " max:%"PRIzu, index, pArray->size);
|
uError("index is out of range, current:%" PRIzu " max:%" PRIzu, index, pArray->size);
|
||||||
|
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,6 +225,7 @@ void* taosArrayGetP(const SArray* pArray, size_t index) {
|
||||||
|
|
||||||
void* taosArrayGetLast(const SArray* pArray) {
|
void* taosArrayGetLast(const SArray* pArray) {
|
||||||
if (pArray->size == 0) {
|
if (pArray->size == 0) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,6 +241,7 @@ size_t taosArrayGetSize(const SArray* pArray) {
|
||||||
|
|
||||||
void* taosArrayInsert(SArray* pArray, size_t index, const void* pData) {
|
void* taosArrayInsert(SArray* pArray, size_t index, const void* pData) {
|
||||||
if (pArray == NULL || pData == NULL) {
|
if (pArray == NULL || pData == NULL) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,8 +251,8 @@ void* taosArrayInsert(SArray* pArray, size_t index, const void* pData) {
|
||||||
|
|
||||||
if (pArray->size >= pArray->capacity) {
|
if (pArray->size >= pArray->capacity) {
|
||||||
int32_t ret = taosArrayResize(pArray);
|
int32_t ret = taosArrayResize(pArray);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
terrno = ret;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,14 +328,17 @@ SArray* taosArrayFromList(const void* src, size_t size, size_t elemSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* pDst = taosArrayInit(size, elemSize);
|
SArray* pDst = taosArrayInit(size, elemSize);
|
||||||
memcpy(pDst->pData, src, elemSize * size);
|
if (pDst) {
|
||||||
pDst->size = size;
|
memcpy(pDst->pData, src, elemSize * size);
|
||||||
|
pDst->size = size;
|
||||||
|
}
|
||||||
|
|
||||||
return pDst;
|
return pDst;
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* taosArrayDup(const SArray* pSrc, __array_item_dup_fn_t fn) {
|
SArray* taosArrayDup(const SArray* pSrc, __array_item_dup_fn_t fn) {
|
||||||
if (NULL == pSrc) {
|
if (NULL == pSrc) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,18 +348,20 @@ SArray* taosArrayDup(const SArray* pSrc, __array_item_dup_fn_t fn) {
|
||||||
|
|
||||||
SArray* dst = taosArrayInit(pSrc->size, pSrc->elemSize);
|
SArray* dst = taosArrayInit(pSrc->size, pSrc->elemSize);
|
||||||
|
|
||||||
if (fn == NULL) {
|
if (dst) {
|
||||||
memcpy(dst->pData, pSrc->pData, pSrc->elemSize * pSrc->size);
|
if (fn == NULL) {
|
||||||
} else {
|
memcpy(dst->pData, pSrc->pData, pSrc->elemSize * pSrc->size);
|
||||||
ASSERT(pSrc->elemSize == sizeof(void*));
|
} else {
|
||||||
|
ASSERT(pSrc->elemSize == sizeof(void*));
|
||||||
|
|
||||||
for (int32_t i = 0; i < pSrc->size; ++i) {
|
for (int32_t i = 0; i < pSrc->size; ++i) {
|
||||||
void* p = fn(taosArrayGetP(pSrc, i));
|
void* p = fn(taosArrayGetP(pSrc, i));
|
||||||
memcpy(((char*)dst->pData) + i * dst->elemSize, &p, dst->elemSize);
|
memcpy(((char*)dst->pData) + i * dst->elemSize, &p, dst->elemSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
dst->size = pSrc->size;
|
dst->size = pSrc->size;
|
||||||
|
}
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
@ -508,10 +525,22 @@ void* taosDecodeArray(const void* buf, SArray** pArray, FDecode decode, int32_t
|
||||||
int32_t sz;
|
int32_t sz;
|
||||||
buf = taosDecodeFixedI32(buf, &sz);
|
buf = taosDecodeFixedI32(buf, &sz);
|
||||||
*pArray = taosArrayInit(sz, sizeof(void*));
|
*pArray = taosArrayInit(sz, sizeof(void*));
|
||||||
|
if (*pArray == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
for (int32_t i = 0; i < sz; i++) {
|
||||||
void* data = taosMemoryCalloc(1, dataSz);
|
void* data = taosMemoryCalloc(1, dataSz);
|
||||||
|
if (data == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
buf = decode(buf, data, sver);
|
buf = decode(buf, data, sver);
|
||||||
taosArrayPush(*pArray, &data);
|
|
||||||
|
if (taosArrayPush(*pArray, &data) == NULL) {
|
||||||
|
taosMemoryFree(data);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (void*)buf;
|
return (void*)buf;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,10 @@ void tdListInit(SList *list, int32_t eleSize) {
|
||||||
|
|
||||||
SList *tdListNew(int32_t eleSize) {
|
SList *tdListNew(int32_t eleSize) {
|
||||||
SList *list = (SList *)taosMemoryMalloc(sizeof(SList));
|
SList *list = (SList *)taosMemoryMalloc(sizeof(SList));
|
||||||
if (list == NULL) return NULL;
|
if (list == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
tdListInit(list, eleSize);
|
tdListInit(list, eleSize);
|
||||||
return list;
|
return list;
|
||||||
|
@ -70,7 +73,9 @@ void tdListAppendNode(SList *list, SListNode *node) { TD_DLIST_APPEND(list, node
|
||||||
|
|
||||||
int32_t tdListPrepend(SList *list, void *data) {
|
int32_t tdListPrepend(SList *list, void *data) {
|
||||||
SListNode *node = (SListNode *)taosMemoryMalloc(sizeof(SListNode) + list->eleSize);
|
SListNode *node = (SListNode *)taosMemoryMalloc(sizeof(SListNode) + list->eleSize);
|
||||||
if (node == NULL) return -1;
|
if (node == NULL) {
|
||||||
|
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy((void *)(node->data), data, list->eleSize);
|
memcpy((void *)(node->data), data, list->eleSize);
|
||||||
TD_DLIST_PREPEND(list, node);
|
TD_DLIST_PREPEND(list, node);
|
||||||
|
@ -80,7 +85,9 @@ int32_t tdListPrepend(SList *list, void *data) {
|
||||||
|
|
||||||
int32_t tdListAppend(SList *list, const void *data) {
|
int32_t tdListAppend(SList *list, const void *data) {
|
||||||
SListNode *node = (SListNode *)taosMemoryCalloc(1, sizeof(SListNode) + list->eleSize);
|
SListNode *node = (SListNode *)taosMemoryCalloc(1, sizeof(SListNode) + list->eleSize);
|
||||||
if (node == NULL) return -1;
|
if (node == NULL) {
|
||||||
|
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy((void *)(node->data), data, list->eleSize);
|
memcpy((void *)(node->data), data, list->eleSize);
|
||||||
TD_DLIST_APPEND(list, node);
|
TD_DLIST_APPEND(list, node);
|
||||||
|
@ -90,7 +97,10 @@ int32_t tdListAppend(SList *list, const void *data) {
|
||||||
// return the node pointer
|
// return the node pointer
|
||||||
SListNode *tdListAdd(SList *list, const void *data) {
|
SListNode *tdListAdd(SList *list, const void *data) {
|
||||||
SListNode *node = (SListNode *)taosMemoryCalloc(1, sizeof(SListNode) + list->eleSize);
|
SListNode *node = (SListNode *)taosMemoryCalloc(1, sizeof(SListNode) + list->eleSize);
|
||||||
if (node == NULL) return NULL;
|
if (node == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy((void *)(node->data), data, list->eleSize);
|
memcpy((void *)(node->data), data, list->eleSize);
|
||||||
TD_DLIST_APPEND(list, node);
|
TD_DLIST_APPEND(list, node);
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
|
||||||
static int32_t initForwardBackwardPtr(SSkipList *pSkipList);
|
static int32_t initForwardBackwardPtr(SSkipList *pSkipList);
|
||||||
static SSkipListNode * getPriorNode(SSkipList *pSkipList, const char *val, int32_t order, SSkipListNode **pCur);
|
static SSkipListNode *getPriorNode(SSkipList *pSkipList, const char *val, int32_t order, SSkipListNode **pCur);
|
||||||
static void tSkipListRemoveNodeImpl(SSkipList *pSkipList, SSkipListNode *pNode);
|
static void tSkipListRemoveNodeImpl(SSkipList *pSkipList, SSkipListNode *pNode);
|
||||||
static void tSkipListCorrectLevel(SSkipList *pSkipList);
|
static void tSkipListCorrectLevel(SSkipList *pSkipList);
|
||||||
static SSkipListIterator *doCreateSkipListIterator(SSkipList *pSkipList, int32_t order);
|
static SSkipListIterator *doCreateSkipListIterator(SSkipList *pSkipList, int32_t order);
|
||||||
|
@ -40,7 +40,10 @@ static FORCE_INLINE int32_t getSkipListRandLevel(SSkipList *pSkipList);
|
||||||
SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, __compar_fn_t comparFn, uint8_t flags,
|
SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, __compar_fn_t comparFn, uint8_t flags,
|
||||||
__sl_key_fn_t fn) {
|
__sl_key_fn_t fn) {
|
||||||
SSkipList *pSkipList = (SSkipList *)taosMemoryCalloc(1, sizeof(SSkipList));
|
SSkipList *pSkipList = (SSkipList *)taosMemoryCalloc(1, sizeof(SSkipList));
|
||||||
if (pSkipList == NULL) return NULL;
|
if (pSkipList == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (maxLevel > MAX_SKIP_LIST_LEVEL) {
|
if (maxLevel > MAX_SKIP_LIST_LEVEL) {
|
||||||
maxLevel = MAX_SKIP_LIST_LEVEL;
|
maxLevel = MAX_SKIP_LIST_LEVEL;
|
||||||
|
@ -64,7 +67,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _
|
||||||
pSkipList->comparFn = comparFn;
|
pSkipList->comparFn = comparFn;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (initForwardBackwardPtr(pSkipList) < 0) {
|
if (initForwardBackwardPtr(pSkipList) != TSDB_CODE_OUT_OF_MEMORY) {
|
||||||
tSkipListDestroy(pSkipList);
|
tSkipListDestroy(pSkipList);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -73,11 +76,14 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _
|
||||||
pSkipList->lock = (TdThreadRwlock *)taosMemoryCalloc(1, sizeof(TdThreadRwlock));
|
pSkipList->lock = (TdThreadRwlock *)taosMemoryCalloc(1, sizeof(TdThreadRwlock));
|
||||||
if (pSkipList->lock == NULL) {
|
if (pSkipList->lock == NULL) {
|
||||||
tSkipListDestroy(pSkipList);
|
tSkipListDestroy(pSkipList);
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosThreadRwlockInit(pSkipList->lock, NULL) != 0) {
|
int32_t rc = taosThreadRwlockInit(pSkipList->lock, NULL);
|
||||||
|
if (rc) {
|
||||||
tSkipListDestroy(pSkipList);
|
tSkipListDestroy(pSkipList);
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(rc);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,8 +143,8 @@ void tSkipListPutBatchByIter(SSkipList *pSkipList, void *iter, iter_next_fn_t it
|
||||||
SSkipListNode *backward[MAX_SKIP_LIST_LEVEL] = {0};
|
SSkipListNode *backward[MAX_SKIP_LIST_LEVEL] = {0};
|
||||||
SSkipListNode *forward[MAX_SKIP_LIST_LEVEL] = {0};
|
SSkipListNode *forward[MAX_SKIP_LIST_LEVEL] = {0};
|
||||||
bool hasDup = false;
|
bool hasDup = false;
|
||||||
char * pKey = NULL;
|
char *pKey = NULL;
|
||||||
char * pDataKey = NULL;
|
char *pDataKey = NULL;
|
||||||
int32_t compare = 0;
|
int32_t compare = 0;
|
||||||
|
|
||||||
tSkipListWLock(pSkipList);
|
tSkipListWLock(pSkipList);
|
||||||
|
@ -265,13 +271,17 @@ void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNode) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SSkipListIterator *tSkipListCreateIter(SSkipList *pSkipList) {
|
SSkipListIterator *tSkipListCreateIter(SSkipList *pSkipList) {
|
||||||
if (pSkipList == NULL) return NULL;
|
if (pSkipList == NULL) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return doCreateSkipListIterator(pSkipList, TSDB_ORDER_ASC);
|
return doCreateSkipListIterator(pSkipList, TSDB_ORDER_ASC);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSkipListIterator *tSkipListCreateIterFromVal(SSkipList *pSkipList, const char *val, int32_t type, int32_t order) {
|
SSkipListIterator *tSkipListCreateIterFromVal(SSkipList *pSkipList, const char *val, int32_t type, int32_t order) {
|
||||||
if (order != TSDB_ORDER_ASC && order != TSDB_ORDER_DESC) {
|
if (order != TSDB_ORDER_ASC && order != TSDB_ORDER_DESC) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,7 +372,7 @@ void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel) {
|
||||||
SSkipListNode *p = SL_NODE_GET_FORWARD_POINTER(pSkipList->pHead, nlevel - 1);
|
SSkipListNode *p = SL_NODE_GET_FORWARD_POINTER(pSkipList->pHead, nlevel - 1);
|
||||||
|
|
||||||
int32_t id = 1;
|
int32_t id = 1;
|
||||||
char * prev = NULL;
|
char *prev = NULL;
|
||||||
|
|
||||||
while (p != pSkipList->pTail) {
|
while (p != pSkipList->pTail) {
|
||||||
char *key = SL_GET_NODE_KEY(pSkipList, p);
|
char *key = SL_GET_NODE_KEY(pSkipList, p);
|
||||||
|
@ -427,6 +437,10 @@ static void tSkipListDoInsert(SSkipList *pSkipList, SSkipListNode **direction, S
|
||||||
|
|
||||||
static SSkipListIterator *doCreateSkipListIterator(SSkipList *pSkipList, int32_t order) {
|
static SSkipListIterator *doCreateSkipListIterator(SSkipList *pSkipList, int32_t order) {
|
||||||
SSkipListIterator *iter = taosMemoryCalloc(1, sizeof(SSkipListIterator));
|
SSkipListIterator *iter = taosMemoryCalloc(1, sizeof(SSkipListIterator));
|
||||||
|
if (iter == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
iter->pSkipList = pSkipList;
|
iter->pSkipList = pSkipList;
|
||||||
iter->order = order;
|
iter->order = order;
|
||||||
|
@ -465,7 +479,7 @@ static FORCE_INLINE int32_t tSkipListUnlock(SSkipList *pSkipList) {
|
||||||
static bool tSkipListGetPosToPut(SSkipList *pSkipList, SSkipListNode **backward, void *pData) {
|
static bool tSkipListGetPosToPut(SSkipList *pSkipList, SSkipListNode **backward, void *pData) {
|
||||||
int32_t compare = 0;
|
int32_t compare = 0;
|
||||||
bool hasDupKey = false;
|
bool hasDupKey = false;
|
||||||
char * pDataKey = pSkipList->keyFn(pData);
|
char *pDataKey = pSkipList->keyFn(pData);
|
||||||
|
|
||||||
if (pSkipList->size == 0) {
|
if (pSkipList->size == 0) {
|
||||||
for (int32_t i = 0; i < pSkipList->maxLevel; i++) {
|
for (int32_t i = 0; i < pSkipList->maxLevel; i++) {
|
||||||
|
@ -651,13 +665,15 @@ static int32_t initForwardBackwardPtr(SSkipList *pSkipList) {
|
||||||
|
|
||||||
// head info
|
// head info
|
||||||
pSkipList->pHead = tSkipListNewNode(maxLevel);
|
pSkipList->pHead = tSkipListNewNode(maxLevel);
|
||||||
if (pSkipList->pHead == NULL) return -1;
|
if (pSkipList->pHead == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
|
||||||
// tail info
|
// tail info
|
||||||
pSkipList->pTail = tSkipListNewNode(maxLevel);
|
pSkipList->pTail = tSkipListNewNode(maxLevel);
|
||||||
if (pSkipList->pTail == NULL) {
|
if (pSkipList->pTail == NULL) {
|
||||||
tSkipListFreeNode(pSkipList->pHead);
|
tSkipListFreeNode(pSkipList->pHead);
|
||||||
return -1;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < maxLevel; ++i) {
|
for (uint32_t i = 0; i < maxLevel; ++i) {
|
||||||
|
@ -672,7 +688,10 @@ static SSkipListNode *tSkipListNewNode(uint8_t level) {
|
||||||
int32_t tsize = sizeof(SSkipListNode) + sizeof(SSkipListNode *) * level * 2;
|
int32_t tsize = sizeof(SSkipListNode) + sizeof(SSkipListNode *) * level * 2;
|
||||||
|
|
||||||
SSkipListNode *pNode = (SSkipListNode *)taosMemoryCalloc(1, tsize);
|
SSkipListNode *pNode = (SSkipListNode *)taosMemoryCalloc(1, tsize);
|
||||||
if (pNode == NULL) return NULL;
|
if (pNode == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pNode->level = level;
|
pNode->level = level;
|
||||||
return pNode;
|
return pNode;
|
||||||
|
@ -699,6 +718,9 @@ static SSkipListNode *tSkipListPutImpl(SSkipList *pSkipList, void *pData, SSkipL
|
||||||
if (pNode != NULL) {
|
if (pNode != NULL) {
|
||||||
pNode->pData = pData;
|
pNode->pData = pData;
|
||||||
tSkipListDoInsert(pSkipList, direction, pNode, isForward);
|
tSkipListDoInsert(pSkipList, direction, pNode, isForward);
|
||||||
|
} else {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,12 @@
|
||||||
#include "tthread.h"
|
#include "tthread.h"
|
||||||
|
|
||||||
TdThread* taosCreateThread(void* (*__start_routine)(void*), void* param) {
|
TdThread* taosCreateThread(void* (*__start_routine)(void*), void* param) {
|
||||||
TdThread* pthread = (TdThread*)taosMemoryMalloc(sizeof(TdThread));
|
TdThread* pthread = (TdThread*)taosMemoryMalloc(sizeof(TdThread));
|
||||||
|
if (pthread == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
TdThreadAttr thattr;
|
TdThreadAttr thattr;
|
||||||
taosThreadAttrInit(&thattr);
|
taosThreadAttrInit(&thattr);
|
||||||
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
@ -26,6 +31,7 @@ TdThread* taosCreateThread(void* (*__start_routine)(void*), void* param) {
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
taosMemoryFree(pthread);
|
taosMemoryFree(pthread);
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return pthread;
|
return pthread;
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#define UNIT_ONE_PEBIBYTE (UNIT_ONE_TEBIBYTE * UNIT_SIZE_CONVERT_FACTOR)
|
#define UNIT_ONE_PEBIBYTE (UNIT_ONE_TEBIBYTE * UNIT_SIZE_CONVERT_FACTOR)
|
||||||
#define UNIT_ONE_EXBIBYTE (UNIT_ONE_PEBIBYTE * UNIT_SIZE_CONVERT_FACTOR)
|
#define UNIT_ONE_EXBIBYTE (UNIT_ONE_PEBIBYTE * UNIT_SIZE_CONVERT_FACTOR)
|
||||||
|
|
||||||
static int32_t parseCfgIntWithUnit(const char* str, double *res) {
|
static int32_t parseCfgIntWithUnit(const char* str, double* res) {
|
||||||
double val, temp = (double)INT64_MAX;
|
double val, temp = (double)INT64_MAX;
|
||||||
char* endPtr;
|
char* endPtr;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
@ -33,8 +33,7 @@ static int32_t parseCfgIntWithUnit(const char* str, double *res) {
|
||||||
val = taosStr2Double(str, &endPtr);
|
val = taosStr2Double(str, &endPtr);
|
||||||
}
|
}
|
||||||
if (endPtr == str || errno == ERANGE || isnan(val)) {
|
if (endPtr == str || errno == ERANGE || isnan(val)) {
|
||||||
terrno = TSDB_CODE_INVALID_CFG_VALUE;
|
return terrno = TSDB_CODE_INVALID_CFG_VALUE;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
while (isspace((unsigned char)*endPtr)) endPtr++;
|
while (isspace((unsigned char)*endPtr)) endPtr++;
|
||||||
uint64_t factor = 1;
|
uint64_t factor = 1;
|
||||||
|
@ -66,28 +65,25 @@ static int32_t parseCfgIntWithUnit(const char* str, double *res) {
|
||||||
factor = UNIT_ONE_KIBIBYTE;
|
factor = UNIT_ONE_KIBIBYTE;
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_INVALID_CFG_VALUE;
|
return terrno = TSDB_CODE_INVALID_CFG_VALUE;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
if ((val > 0 && val > temp) || (val < 0 && val < -temp)) {
|
if ((val > 0 && val > temp) || (val < 0 && val < -temp)) {
|
||||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
return terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
endPtr++;
|
endPtr++;
|
||||||
val *= factor;
|
val *= factor;
|
||||||
}
|
}
|
||||||
while (isspace((unsigned char)*endPtr)) endPtr++;
|
while (isspace((unsigned char)*endPtr)) endPtr++;
|
||||||
if (*endPtr) {
|
if (*endPtr) {
|
||||||
terrno = TSDB_CODE_INVALID_CFG_VALUE;
|
return terrno = TSDB_CODE_INVALID_CFG_VALUE;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
val = rint(val);
|
val = rint(val);
|
||||||
*res = val;
|
*res = val;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosStrHumanToInt64(const char* str, int64_t *out) {
|
int32_t taosStrHumanToInt64(const char* str, int64_t* out) {
|
||||||
double res;
|
double res;
|
||||||
int32_t code = parseCfgIntWithUnit(str, &res);
|
int32_t code = parseCfgIntWithUnit(str, &res);
|
||||||
if (code == TSDB_CODE_SUCCESS) *out = (int64_t)res;
|
if (code == TSDB_CODE_SUCCESS) *out = (int64_t)res;
|
||||||
return code;
|
return code;
|
||||||
|
@ -113,12 +109,11 @@ void taosInt64ToHumanStr(int64_t val, char* outStr) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t taosStrHumanToInt32(const char* str, int32_t* out) {
|
int32_t taosStrHumanToInt32(const char* str, int32_t* out) {
|
||||||
double res;
|
double res;
|
||||||
int32_t code = parseCfgIntWithUnit(str, &res);
|
int32_t code = parseCfgIntWithUnit(str, &res);
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
if (res < INT32_MIN || res > INT32_MAX) {
|
if (res < INT32_MIN || res > INT32_MAX) {
|
||||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
return terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
*out = (int32_t)res;
|
*out = (int32_t)res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
int32_t taosVersionStrToInt(const char *vstr, int32_t *vint) {
|
int32_t taosVersionStrToInt(const char *vstr, int32_t *vint) {
|
||||||
if (vstr == NULL) {
|
if (vstr == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_VERSION_STRING;
|
return terrno = TSDB_CODE_INVALID_VERSION_STRING;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vnum[4] = {0};
|
int32_t vnum[4] = {0};
|
||||||
|
@ -44,8 +43,7 @@ int32_t taosVersionStrToInt(const char *vstr, int32_t *vint) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vnum[0] <= 0) {
|
if (vnum[0] <= 0) {
|
||||||
terrno = TSDB_CODE_INVALID_VERSION_STRING;
|
return terrno = TSDB_CODE_INVALID_VERSION_STRING;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*vint = vnum[0] * 1000000 + vnum[1] * 10000 + vnum[2] * 100 + vnum[3];
|
*vint = vnum[0] * 1000000 + vnum[1] * 10000 + vnum[2] * 100 + vnum[3];
|
||||||
|
@ -58,8 +56,7 @@ int32_t taosVersionIntToStr(int32_t vint, char *vstr, int32_t len) {
|
||||||
int32_t s3 = (vint % 10000) / 100;
|
int32_t s3 = (vint % 10000) / 100;
|
||||||
int32_t s4 = vint % 100;
|
int32_t s4 = vint % 100;
|
||||||
if (s1 <= 0) {
|
if (s1 <= 0) {
|
||||||
terrno = TSDB_CODE_INVALID_VERSION_NUMBER;
|
return terrno = TSDB_CODE_INVALID_VERSION_NUMBER;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(vstr, len, "%02d.%02d.%02d.%02d", s1, s2, s3, s4);
|
snprintf(vstr, len, "%02d.%02d.%02d.%02d", s1, s2, s3, s4);
|
||||||
|
@ -83,15 +80,13 @@ int32_t taosCheckVersionCompatible(int32_t clientVer, int32_t serverVer, int32_t
|
||||||
serverVer /= 1000000;
|
serverVer /= 1000000;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_INVALID_VERSION_NUMBER;
|
return terrno = TSDB_CODE_INVALID_VERSION_NUMBER;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clientVer == serverVer) {
|
if (clientVer == serverVer) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_VERSION_NOT_COMPATIBLE;
|
return terrno = TSDB_CODE_VERSION_NOT_COMPATIBLE;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,8 +101,5 @@ int32_t taosCheckVersionCompatibleFromStr(const char *pClientVersion, const char
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = taosCheckVersionCompatible(clientVersion, serverVersion, comparedSegments);
|
code = taosCheckVersionCompatible(clientVersion, serverVersion, comparedSegments);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
|
||||||
code = terrno;
|
|
||||||
}
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
|
@ -309,8 +309,7 @@ int32_t tWWorkerInit(SWWorkerPool *pool) {
|
||||||
pool->nextId = 0;
|
pool->nextId = 0;
|
||||||
pool->workers = taosMemoryCalloc(pool->max, sizeof(SWWorker));
|
pool->workers = taosMemoryCalloc(pool->max, sizeof(SWWorker));
|
||||||
if (pool->workers == NULL) {
|
if (pool->workers == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosThreadMutexInit(&pool->mutex, NULL);
|
(void)taosThreadMutexInit(&pool->mutex, NULL);
|
||||||
|
@ -434,6 +433,7 @@ _OVER:
|
||||||
if (queue != NULL) taosCloseQueue(queue);
|
if (queue != NULL) taosCloseQueue(queue);
|
||||||
if (worker->qset != NULL) taosCloseQset(worker->qset);
|
if (worker->qset != NULL) taosCloseQset(worker->qset);
|
||||||
if (worker->qall != NULL) taosFreeQall(worker->qall);
|
if (worker->qall != NULL) taosFreeQall(worker->qall);
|
||||||
|
terrno = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
while (worker->pid <= 0) taosMsleep(10);
|
while (worker->pid <= 0) taosMsleep(10);
|
||||||
|
@ -450,6 +450,7 @@ void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg) {
|
int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg) {
|
||||||
|
int32_t code;
|
||||||
pWorker->poolType = pCfg->poolType;
|
pWorker->poolType = pCfg->poolType;
|
||||||
pWorker->name = pCfg->name;
|
pWorker->name = pCfg->name;
|
||||||
|
|
||||||
|
@ -457,32 +458,38 @@ int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg)
|
||||||
case QWORKER_POOL: {
|
case QWORKER_POOL: {
|
||||||
SQWorkerPool *pPool = taosMemoryCalloc(1, sizeof(SQWorkerPool));
|
SQWorkerPool *pPool = taosMemoryCalloc(1, sizeof(SQWorkerPool));
|
||||||
if (!pPool) {
|
if (!pPool) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
pPool->name = pCfg->name;
|
pPool->name = pCfg->name;
|
||||||
pPool->min = pCfg->min;
|
pPool->min = pCfg->min;
|
||||||
pPool->max = pCfg->max;
|
pPool->max = pCfg->max;
|
||||||
pWorker->pool = pPool;
|
pWorker->pool = pPool;
|
||||||
if (tQWorkerInit(pPool) != 0) return -1;
|
if ((code = tQWorkerInit(pPool))) {
|
||||||
|
return (terrno = code);
|
||||||
|
}
|
||||||
|
|
||||||
pWorker->queue = tQWorkerAllocQueue(pPool, pCfg->param, pCfg->fp);
|
pWorker->queue = tQWorkerAllocQueue(pPool, pCfg->param, pCfg->fp);
|
||||||
if (pWorker->queue == NULL) return -1;
|
if (pWorker->queue == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case QUERY_AUTO_QWORKER_POOL: {
|
case QUERY_AUTO_QWORKER_POOL: {
|
||||||
SQueryAutoQWorkerPool *pPool = taosMemoryCalloc(1, sizeof(SQueryAutoQWorkerPool));
|
SQueryAutoQWorkerPool *pPool = taosMemoryCalloc(1, sizeof(SQueryAutoQWorkerPool));
|
||||||
if (!pPool) {
|
if (!pPool) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return (terrno = TSDB_CODE_OUT_OF_MEMORY);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
pPool->name = pCfg->name;
|
pPool->name = pCfg->name;
|
||||||
pPool->min = pCfg->min;
|
pPool->min = pCfg->min;
|
||||||
pPool->max = pCfg->max;
|
pPool->max = pCfg->max;
|
||||||
pWorker->pool = pPool;
|
pWorker->pool = pPool;
|
||||||
if (tQueryAutoQWorkerInit(pPool) != 0) return -1;
|
|
||||||
|
code = tQueryAutoQWorkerInit(pPool);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
pWorker->queue = tQueryAutoQWorkerAllocQueue(pPool, pCfg->param, pCfg->fp);
|
pWorker->queue = tQueryAutoQWorkerAllocQueue(pPool, pCfg->param, pCfg->fp);
|
||||||
if (!pWorker->queue) return -1;
|
if (!pWorker->queue) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -516,10 +523,14 @@ int32_t tMultiWorkerInit(SMultiWorker *pWorker, const SMultiWorkerCfg *pCfg) {
|
||||||
SWWorkerPool *pPool = &pWorker->pool;
|
SWWorkerPool *pPool = &pWorker->pool;
|
||||||
pPool->name = pCfg->name;
|
pPool->name = pCfg->name;
|
||||||
pPool->max = pCfg->max;
|
pPool->max = pCfg->max;
|
||||||
if (tWWorkerInit(pPool) != 0) return -1;
|
|
||||||
|
int32_t code = tWWorkerInit(pPool);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
pWorker->queue = tWWorkerAllocQueue(pPool, pCfg->param, pCfg->fp);
|
pWorker->queue = tWWorkerAllocQueue(pPool, pCfg->param, pCfg->fp);
|
||||||
if (pWorker->queue == NULL) return -1;
|
if (pWorker->queue == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
|
||||||
pWorker->name = pCfg->name;
|
pWorker->name = pCfg->name;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue