Merge pull request #26763 from taosdata/enh/TS-30987-15
enh: refact error code
This commit is contained in:
commit
cd2f039fd9
|
@ -64,10 +64,10 @@ typedef struct TDigest {
|
||||||
} TDigest;
|
} TDigest;
|
||||||
|
|
||||||
TDigest *tdigestNewFrom(void *pBuf, int32_t compression);
|
TDigest *tdigestNewFrom(void *pBuf, int32_t compression);
|
||||||
void tdigestAdd(TDigest *t, double x, int64_t w);
|
int32_t tdigestAdd(TDigest *t, double x, int64_t w);
|
||||||
void tdigestMerge(TDigest *t1, TDigest *t2);
|
int32_t tdigestMerge(TDigest *t1, TDigest *t2);
|
||||||
double tdigestQuantile(TDigest *t, double q);
|
double tdigestQuantile(TDigest *t, double q);
|
||||||
void tdigestCompress(TDigest *t);
|
int32_t tdigestCompress(TDigest *t);
|
||||||
void tdigestFreeFrom(TDigest *t);
|
void tdigestFreeFrom(TDigest *t);
|
||||||
void tdigestAutoFill(TDigest *t, int32_t compression);
|
void tdigestAutoFill(TDigest *t, int32_t compression);
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,7 @@ void *taosMemoryMalloc(int64_t size) {
|
||||||
|
|
||||||
return (char *)tmp + sizeof(TdMemoryInfo);
|
return (char *)tmp + sizeof(TdMemoryInfo);
|
||||||
#else
|
#else
|
||||||
void* p = malloc(size);
|
void *p = malloc(size);
|
||||||
if (NULL == p) {
|
if (NULL == p) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -287,7 +287,7 @@ void *taosMemoryCalloc(int64_t num, int64_t size) {
|
||||||
|
|
||||||
return (char *)tmp + sizeof(TdMemoryInfo);
|
return (char *)tmp + sizeof(TdMemoryInfo);
|
||||||
#else
|
#else
|
||||||
void* p = calloc(num, size);
|
void *p = calloc(num, size);
|
||||||
if (NULL == p) {
|
if (NULL == p) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -317,7 +317,7 @@ void *taosMemoryRealloc(void *ptr, int64_t size) {
|
||||||
|
|
||||||
return (char *)tmp + sizeof(TdMemoryInfo);
|
return (char *)tmp + sizeof(TdMemoryInfo);
|
||||||
#else
|
#else
|
||||||
void* p = realloc(ptr, size);
|
void *p = realloc(ptr, size);
|
||||||
if (size > 0 && NULL == p) {
|
if (size > 0 && NULL == p) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -342,12 +342,12 @@ char *taosStrdup(const char *ptr) {
|
||||||
|
|
||||||
return (char *)tmp + sizeof(TdMemoryInfo);
|
return (char *)tmp + sizeof(TdMemoryInfo);
|
||||||
#else
|
#else
|
||||||
char* p = tstrdup(ptr);
|
char *p = tstrdup(ptr);
|
||||||
if (ptr != NULL && NULL == p) {
|
if (ptr != NULL && NULL == p) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
return p;
|
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) {
|
||||||
|
@ -52,14 +52,12 @@ SArray* taosArrayInit(size_t size, size_t elemSize) {
|
||||||
SArray* taosArrayInit_s(size_t elemSize, size_t initialSize) {
|
SArray* taosArrayInit_s(size_t elemSize, size_t initialSize) {
|
||||||
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 = initialSize;
|
pArray->size = initialSize;
|
||||||
pArray->pData = taosMemoryCalloc(initialSize, elemSize);
|
pArray->pData = taosMemoryCalloc(initialSize, 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 +73,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 terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
pArray->pData = tmp;
|
pArray->pData = tmp;
|
||||||
|
@ -99,7 +97,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 terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
pArray->capacity = tsize;
|
pArray->capacity = tsize;
|
||||||
|
@ -109,10 +107,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +172,9 @@ void* taosArrayAddAll(SArray* pArray, const SArray* pInput) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +201,7 @@ void* taosArrayGet(const SArray* pArray, size_t index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,6 +233,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,7 +243,6 @@ 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) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -316,8 +319,10 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -333,18 +338,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 +515,21 @@ 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) {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,6 +230,7 @@ static FORCE_INLINE void taosCacheReleaseNode(SCacheObj *pCacheObj, SCacheNode *
|
||||||
static FORCE_INLINE STrashElem *doRemoveElemInTrashcan(SCacheObj *pCacheObj, STrashElem *pElem) {
|
static FORCE_INLINE STrashElem *doRemoveElemInTrashcan(SCacheObj *pCacheObj, STrashElem *pElem) {
|
||||||
if (pElem->pData->signature != pElem->pData) {
|
if (pElem->pData->signature != pElem->pData) {
|
||||||
uWarn("key:sig:0x%" PRIx64 " %p data has been released, ignore", (int64_t)pElem->pData->signature, pElem->pData);
|
uWarn("key:sig:0x%" PRIx64 " %p data has been released, ignore", (int64_t)pElem->pData->signature, pElem->pData);
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,6 +359,7 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInMs, bool extendLi
|
||||||
SCacheObj *pCacheObj = (SCacheObj *)taosMemoryCalloc(1, sizeof(SCacheObj));
|
SCacheObj *pCacheObj = (SCacheObj *)taosMemoryCalloc(1, sizeof(SCacheObj));
|
||||||
if (pCacheObj == NULL) {
|
if (pCacheObj == NULL) {
|
||||||
uError("failed to allocate memory, reason:%s", strerror(errno));
|
uError("failed to allocate memory, reason:%s", strerror(errno));
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,6 +395,7 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInMs, bool extendLi
|
||||||
void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const void *pData, size_t dataSize,
|
void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const void *pData, size_t dataSize,
|
||||||
int32_t durationMS) {
|
int32_t durationMS) {
|
||||||
if (pCacheObj == NULL || pCacheObj->pEntryList == NULL || pCacheObj->deleting == 1) {
|
if (pCacheObj == NULL || pCacheObj->pEntryList == NULL || pCacheObj->deleting == 1) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -501,11 +504,15 @@ void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void *taosCacheTransferData(SCacheObj *pCacheObj, void **data) {
|
void *taosCacheTransferData(SCacheObj *pCacheObj, void **data) {
|
||||||
if (pCacheObj == NULL || data == NULL || (*data) == NULL) return NULL;
|
if (pCacheObj == NULL || data == NULL || (*data) == NULL) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SCacheNode *ptNode = (SCacheNode *)((char *)(*data) - sizeof(SCacheNode));
|
SCacheNode *ptNode = (SCacheNode *)((char *)(*data) - sizeof(SCacheNode));
|
||||||
if (ptNode->signature != ptNode) {
|
if (ptNode->signature != ptNode) {
|
||||||
uError("cache:%s, key: %p the data from cache is invalid", pCacheObj->name, ptNode);
|
uError("cache:%s, key: %p the data from cache is invalid", pCacheObj->name, ptNode);
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -702,8 +709,8 @@ SCacheNode *taosCreateCacheNode(const char *key, size_t keyLen, const char *pDat
|
||||||
|
|
||||||
SCacheNode *pNewNode = taosMemoryCalloc(1, sizeInBytes);
|
SCacheNode *pNewNode = taosMemoryCalloc(1, sizeInBytes);
|
||||||
if (pNewNode == NULL) {
|
if (pNewNode == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
uError("failed to allocate memory, reason:%s", strerror(errno));
|
uError("failed to allocate memory, reason:%s", strerror(errno));
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,12 @@ char* taosDesEncode(int64_t key, char* src, int32_t len) {
|
||||||
char* taosDesDecode(int64_t key, char* src, int32_t len) {
|
char* taosDesDecode(int64_t key, char* src, int32_t len) {
|
||||||
uint8_t* keyStr = (uint8_t*)(&key);
|
uint8_t* keyStr = (uint8_t*)(&key);
|
||||||
char* temp = taosMemoryCalloc(len + 8, 1);
|
char* temp = taosMemoryCalloc(len + 8, 1);
|
||||||
|
|
||||||
|
if (!temp) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(temp, src, len);
|
memcpy(temp, src, len);
|
||||||
len += 8;
|
len += 8;
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
|
||||||
#define INTERPOLATE(x, x0, x1) (((x) - (x0)) / ((x1) - (x0)))
|
#define INTERPOLATE(x, x0, x1) (((x) - (x0)) / ((x1) - (x0)))
|
||||||
//#define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (q) - 1) + M_PI / 2) / M_PI)
|
// #define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (q) - 1) + M_PI / 2) / M_PI)
|
||||||
#define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (double)(q)-1) / M_PI + (double)1 / 2))
|
#define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (double)(q)-1) / M_PI + (double)1 / 2))
|
||||||
#define FLOAT_EQ(f1, f2) (fabs((f1) - (f2)) <= FLT_EPSILON)
|
#define FLOAT_EQ(f1, f2) (fabs((f1) - (f2)) <= FLT_EPSILON)
|
||||||
|
|
||||||
|
@ -99,16 +99,19 @@ static void mergeCentroid(SMergeArgs *args, SCentroid *merge) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdigestCompress(TDigest *t) {
|
int32_t tdigestCompress(TDigest *t) {
|
||||||
SCentroid *unmerged_centroids;
|
SCentroid *unmerged_centroids;
|
||||||
int64_t unmerged_weight = 0;
|
int64_t unmerged_weight = 0;
|
||||||
int32_t num_unmerged = t->num_buffered_pts;
|
int32_t num_unmerged = t->num_buffered_pts;
|
||||||
int32_t i, j;
|
int32_t i, j;
|
||||||
SMergeArgs args;
|
SMergeArgs args;
|
||||||
|
|
||||||
if (t->num_buffered_pts <= 0) return;
|
if (t->num_buffered_pts <= 0) return 0;
|
||||||
|
|
||||||
unmerged_centroids = (SCentroid *)taosMemoryMalloc(sizeof(SCentroid) * t->num_buffered_pts);
|
unmerged_centroids = (SCentroid *)taosMemoryMalloc(sizeof(SCentroid) * t->num_buffered_pts);
|
||||||
|
if (unmerged_centroids == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
for (i = 0; i < num_unmerged; i++) {
|
for (i = 0; i < num_unmerged; i++) {
|
||||||
SPt *p = t->buffered_pts + i;
|
SPt *p = t->buffered_pts + i;
|
||||||
SCentroid *c = &unmerged_centroids[i];
|
SCentroid *c = &unmerged_centroids[i];
|
||||||
|
@ -122,6 +125,10 @@ void tdigestCompress(TDigest *t) {
|
||||||
taosSort(unmerged_centroids, num_unmerged, sizeof(SCentroid), cmpCentroid);
|
taosSort(unmerged_centroids, num_unmerged, sizeof(SCentroid), cmpCentroid);
|
||||||
memset(&args, 0, sizeof(SMergeArgs));
|
memset(&args, 0, sizeof(SMergeArgs));
|
||||||
args.centroids = (SCentroid *)taosMemoryMalloc((size_t)(sizeof(SCentroid) * t->size));
|
args.centroids = (SCentroid *)taosMemoryMalloc((size_t)(sizeof(SCentroid) * t->size));
|
||||||
|
if (args.centroids == NULL) {
|
||||||
|
taosMemoryFree((void *)unmerged_centroids);
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
memset(args.centroids, 0, (size_t)(sizeof(SCentroid) * t->size));
|
memset(args.centroids, 0, (size_t)(sizeof(SCentroid) * t->size));
|
||||||
|
|
||||||
args.t = t;
|
args.t = t;
|
||||||
|
@ -167,10 +174,11 @@ void tdigestCompress(TDigest *t) {
|
||||||
|
|
||||||
memcpy(t->centroids, args.centroids, sizeof(SCentroid) * t->num_centroids);
|
memcpy(t->centroids, args.centroids, sizeof(SCentroid) * t->num_centroids);
|
||||||
taosMemoryFree((void *)args.centroids);
|
taosMemoryFree((void *)args.centroids);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdigestAdd(TDigest *t, double x, int64_t w) {
|
int32_t tdigestAdd(TDigest *t, double x, int64_t w) {
|
||||||
if (w == 0) return;
|
if (w == 0) return 0;
|
||||||
|
|
||||||
int32_t i = t->num_buffered_pts;
|
int32_t i = t->num_buffered_pts;
|
||||||
if (i > 0 && t->buffered_pts[i - 1].value == x) {
|
if (i > 0 && t->buffered_pts[i - 1].value == x) {
|
||||||
|
@ -181,7 +189,10 @@ void tdigestAdd(TDigest *t, double x, int64_t w) {
|
||||||
t->num_buffered_pts++;
|
t->num_buffered_pts++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t->num_buffered_pts >= t->threshold) tdigestCompress(t);
|
if (t->num_buffered_pts >= t->threshold) {
|
||||||
|
return tdigestCompress(t);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -284,16 +295,21 @@ double tdigestQuantile(TDigest *t, double q) {
|
||||||
return t->max;
|
return t->max;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdigestMerge(TDigest *t1, TDigest *t2) {
|
int32_t tdigestMerge(TDigest *t1, TDigest *t2) {
|
||||||
|
int32_t code = 0;
|
||||||
// SPoints
|
// SPoints
|
||||||
int32_t num_pts = t2->num_buffered_pts;
|
int32_t num_pts = t2->num_buffered_pts;
|
||||||
for (int32_t i = num_pts - 1; i >= 0; i--) {
|
for (int32_t i = num_pts - 1; i >= 0; i--) {
|
||||||
SPt *p = t2->buffered_pts + i;
|
SPt *p = t2->buffered_pts + i;
|
||||||
tdigestAdd(t1, p->value, p->weight);
|
code = tdigestAdd(t1, p->value, p->weight);
|
||||||
|
if (code) return code;
|
||||||
t2->num_buffered_pts--;
|
t2->num_buffered_pts--;
|
||||||
}
|
}
|
||||||
// centroids
|
// centroids
|
||||||
for (int32_t i = 0; i < t2->num_centroids; i++) {
|
for (int32_t i = 0; i < t2->num_centroids; i++) {
|
||||||
tdigestAdd(t1, t2->centroids[i].mean, t2->centroids[i].weight);
|
code = tdigestAdd(t1, t2->centroids[i].mean, t2->centroids[i].weight);
|
||||||
|
if (code) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t c
|
||||||
// p[cfgNameMaxLen - 1] = '\0';
|
// p[cfgNameMaxLen - 1] = '\0';
|
||||||
// return strlen(cfgNameStr);
|
// return strlen(cfgNameStr);
|
||||||
cfgNameStr[0] = '\0';
|
cfgNameStr[0] = '\0';
|
||||||
return -1;
|
return TSDB_CODE_INVALID_PARA;
|
||||||
}
|
}
|
||||||
envNameStr += 5;
|
envNameStr += 5;
|
||||||
if (*envNameStr != '\0') {
|
if (*envNameStr != '\0') {
|
||||||
|
@ -55,7 +55,7 @@ int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t c
|
||||||
|
|
||||||
int32_t taosEnvToCfg(const char *envStr, char *cfgStr) {
|
int32_t taosEnvToCfg(const char *envStr, char *cfgStr) {
|
||||||
if (envStr == NULL || cfgStr == NULL) {
|
if (envStr == NULL || cfgStr == NULL) {
|
||||||
return -1;
|
return TSDB_CODE_INVALID_PARA;
|
||||||
}
|
}
|
||||||
if (cfgStr != envStr) strcpy(cfgStr, envStr);
|
if (cfgStr != envStr) strcpy(cfgStr, envStr);
|
||||||
char *p = strchr(cfgStr, '=');
|
char *p = strchr(cfgStr, '=');
|
||||||
|
@ -74,7 +74,7 @@ int32_t taosEnvToCfg(const char *envStr, char *cfgStr) {
|
||||||
memset(&cfgStr[cfgNameLen], ' ', p - cfgStr - cfgNameLen + 1);
|
memset(&cfgStr[cfgNameLen], ' ', p - cfgStr - cfgNameLen + 1);
|
||||||
} else {
|
} else {
|
||||||
*cfgStr = '\0';
|
*cfgStr = '\0';
|
||||||
return -1;
|
return TSDB_CODE_INVALID_PARA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return strlen(cfgStr);
|
return strlen(cfgStr);
|
||||||
|
|
|
@ -13,14 +13,12 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tdef.h"
|
|
||||||
#include "tgeosctx.h"
|
#include "tgeosctx.h"
|
||||||
|
#include "tdef.h"
|
||||||
|
|
||||||
static threadlocal SGeosContext tlGeosCtx = {0};
|
static threadlocal SGeosContext tlGeosCtx = {0};
|
||||||
|
|
||||||
SGeosContext* getThreadLocalGeosCtx() {
|
SGeosContext* getThreadLocalGeosCtx() { return &tlGeosCtx; }
|
||||||
return &tlGeosCtx;
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroyThreadLocalGeosCtx() {
|
void destroyThreadLocalGeosCtx() {
|
||||||
if (tlGeosCtx.WKTReader) {
|
if (tlGeosCtx.WKTReader) {
|
||||||
|
@ -47,7 +45,7 @@ void destroyThreadLocalGeosCtx() {
|
||||||
destroyRegexes(tlGeosCtx.WKTRegex, tlGeosCtx.WKTMatchData);
|
destroyRegexes(tlGeosCtx.WKTRegex, tlGeosCtx.WKTMatchData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tlGeosCtx.handle) {
|
if (tlGeosCtx.handle) {
|
||||||
GEOS_finish_r(tlGeosCtx.handle);
|
GEOS_finish_r(tlGeosCtx.handle);
|
||||||
tlGeosCtx.handle = NULL;
|
tlGeosCtx.handle = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ struct SHashObj {
|
||||||
bool enableUpdate; // enable update
|
bool enableUpdate; // enable update
|
||||||
SArray *pMemBlock; // memory block allocated for SHashEntry
|
SArray *pMemBlock; // memory block allocated for SHashEntry
|
||||||
_hash_before_fn_t callbackFp; // function invoked before return the value to caller
|
_hash_before_fn_t callbackFp; // function invoked before return the value to caller
|
||||||
// int64_t compTimes;
|
// int64_t compTimes;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -147,7 +147,7 @@ static FORCE_INLINE SHashNode *doSearchInEntryList(SHashObj *pHashObj, SHashEntr
|
||||||
uint32_t hashVal) {
|
uint32_t hashVal) {
|
||||||
SHashNode *pNode = pe->next;
|
SHashNode *pNode = pe->next;
|
||||||
while (pNode) {
|
while (pNode) {
|
||||||
//atomic_add_fetch_64(&pHashObj->compTimes, 1);
|
// atomic_add_fetch_64(&pHashObj->compTimes, 1);
|
||||||
if ((pNode->keyLen == keyLen) && ((*(pHashObj->equalFp))(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0) &&
|
if ((pNode->keyLen == keyLen) && ((*(pHashObj->equalFp))(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0) &&
|
||||||
pNode->removed == 0) {
|
pNode->removed == 0) {
|
||||||
break;
|
break;
|
||||||
|
@ -243,7 +243,6 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTyp
|
||||||
|
|
||||||
SHashObj *pHashObj = (SHashObj *)taosMemoryMalloc(sizeof(SHashObj));
|
SHashObj *pHashObj = (SHashObj *)taosMemoryMalloc(sizeof(SHashObj));
|
||||||
if (pHashObj == NULL) {
|
if (pHashObj == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +261,6 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTyp
|
||||||
pHashObj->hashList = (SHashEntry **)taosMemoryMalloc(pHashObj->capacity * sizeof(void *));
|
pHashObj->hashList = (SHashEntry **)taosMemoryMalloc(pHashObj->capacity * sizeof(void *));
|
||||||
if (pHashObj->hashList == NULL) {
|
if (pHashObj->hashList == NULL) {
|
||||||
taosMemoryFree(pHashObj);
|
taosMemoryFree(pHashObj);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +268,6 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTyp
|
||||||
if (pHashObj->pMemBlock == NULL) {
|
if (pHashObj->pMemBlock == NULL) {
|
||||||
taosMemoryFree(pHashObj->hashList);
|
taosMemoryFree(pHashObj->hashList);
|
||||||
taosMemoryFree(pHashObj);
|
taosMemoryFree(pHashObj);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +276,6 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTyp
|
||||||
taosArrayDestroy(pHashObj->pMemBlock);
|
taosArrayDestroy(pHashObj->pMemBlock);
|
||||||
taosMemoryFree(pHashObj->hashList);
|
taosMemoryFree(pHashObj->hashList);
|
||||||
taosMemoryFree(pHashObj);
|
taosMemoryFree(pHashObj);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +286,12 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTyp
|
||||||
pHashObj->hashList[i]->next = NULL;
|
pHashObj->hashList[i]->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayPush(pHashObj->pMemBlock, &p);
|
if (taosArrayPush(pHashObj->pMemBlock, &p) == NULL) {
|
||||||
|
taosArrayDestroy(pHashObj->pMemBlock);
|
||||||
|
taosMemoryFree(pHashObj->hashList);
|
||||||
|
taosMemoryFree(pHashObj);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return pHashObj;
|
return pHashObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,8 +316,7 @@ int32_t taosHashGetSize(const SHashObj *pHashObj) {
|
||||||
|
|
||||||
int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, const void *data, size_t size) {
|
int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, const void *data, size_t size) {
|
||||||
if (pHashObj == NULL || key == NULL || keyLen == 0) {
|
if (pHashObj == NULL || key == NULL || keyLen == 0) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
return terrno = TSDB_CODE_INVALID_PTR;
|
||||||
return TSDB_CODE_INVALID_PTR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t hashVal = (*pHashObj->hashFp)(key, (uint32_t)keyLen);
|
uint32_t hashVal = (*pHashObj->hashFp)(key, (uint32_t)keyLen);
|
||||||
|
@ -331,7 +331,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, const vo
|
||||||
// disable resize
|
// disable resize
|
||||||
taosHashRLock(pHashObj);
|
taosHashRLock(pHashObj);
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
uint32_t slot = HASH_INDEX(hashVal, pHashObj->capacity);
|
uint32_t slot = HASH_INDEX(hashVal, pHashObj->capacity);
|
||||||
SHashEntry *pe = pHashObj->hashList[slot];
|
SHashEntry *pe = pHashObj->hashList[slot];
|
||||||
|
|
||||||
|
@ -440,14 +440,12 @@ void *taosHashGetImpl(SHashObj *pHashObj, const void *key, size_t keyLen, void *
|
||||||
*size = pNode->dataLen;
|
*size = pNode->dataLen;
|
||||||
*d = taosMemoryCalloc(1, *size);
|
*d = taosMemoryCalloc(1, *size);
|
||||||
if (*d == NULL) {
|
if (*d == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else if (*size < pNode->dataLen) {
|
} else if (*size < pNode->dataLen) {
|
||||||
*size = pNode->dataLen;
|
*size = pNode->dataLen;
|
||||||
char *tmp = taosMemoryRealloc(*d, *size);
|
char *tmp = taosMemoryRealloc(*d, *size);
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,7 +472,7 @@ void *taosHashGetImpl(SHashObj *pHashObj, const void *key, size_t keyLen, void *
|
||||||
|
|
||||||
int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen) {
|
int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen) {
|
||||||
if (pHashObj == NULL || taosHashTableEmpty(pHashObj) || key == NULL || keyLen == 0) {
|
if (pHashObj == NULL || taosHashTableEmpty(pHashObj) || key == NULL || keyLen == 0) {
|
||||||
return -1;
|
return TSDB_CODE_INVALID_PARA;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t hashVal = (*pHashObj->hashFp)(key, (uint32_t)keyLen);
|
uint32_t hashVal = (*pHashObj->hashFp)(key, (uint32_t)keyLen);
|
||||||
|
@ -615,7 +613,7 @@ void taosHashTableResize(SHashObj *pHashObj) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t st = taosGetTimestampUs();
|
int64_t st = taosGetTimestampUs();
|
||||||
SHashEntry **pNewEntryList = taosMemoryRealloc(pHashObj->hashList, sizeof(SHashEntry *) * newCapacity);
|
SHashEntry **pNewEntryList = taosMemoryRealloc(pHashObj->hashList, sizeof(SHashEntry *) * newCapacity);
|
||||||
if (pNewEntryList == NULL) {
|
if (pNewEntryList == NULL) {
|
||||||
// uDebug("cache resize failed due to out of memory, capacity remain:%zu", pHashObj->capacity);
|
// uDebug("cache resize failed due to out of memory, capacity remain:%zu", pHashObj->capacity);
|
||||||
|
@ -631,7 +629,10 @@ void taosHashTableResize(SHashObj *pHashObj) {
|
||||||
pHashObj->hashList[i + pHashObj->capacity] = (void *)((char *)p + i * sizeof(SHashEntry));
|
pHashObj->hashList[i + pHashObj->capacity] = (void *)((char *)p + i * sizeof(SHashEntry));
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayPush(pHashObj->pMemBlock, &p);
|
if (taosArrayPush(pHashObj->pMemBlock, &p) == NULL) {
|
||||||
|
taosMemoryFree(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
pHashObj->capacity = newCapacity;
|
pHashObj->capacity = newCapacity;
|
||||||
for (int32_t idx = 0; idx < pHashObj->capacity; ++idx) {
|
for (int32_t idx = 0; idx < pHashObj->capacity; ++idx) {
|
||||||
|
@ -681,7 +682,6 @@ SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, s
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (pNewNode == NULL) {
|
if (pNewNode == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,6 @@ void heapRemove(Heap* heap, HeapNode* node) {
|
||||||
|
|
||||||
void heapDequeue(Heap* heap) { heapRemove(heap, heap->min); }
|
void heapDequeue(Heap* heap) { heapRemove(heap, heap->min); }
|
||||||
|
|
||||||
|
|
||||||
struct PriorityQueue {
|
struct PriorityQueue {
|
||||||
SArray* container;
|
SArray* container;
|
||||||
pq_comp_fn fn;
|
pq_comp_fn fn;
|
||||||
|
@ -197,16 +196,23 @@ struct PriorityQueue {
|
||||||
};
|
};
|
||||||
PriorityQueue* createPriorityQueue(pq_comp_fn fn, FDelete deleteFn, void* param) {
|
PriorityQueue* createPriorityQueue(pq_comp_fn fn, FDelete deleteFn, void* param) {
|
||||||
PriorityQueue* pq = (PriorityQueue*)taosMemoryCalloc(1, sizeof(PriorityQueue));
|
PriorityQueue* pq = (PriorityQueue*)taosMemoryCalloc(1, sizeof(PriorityQueue));
|
||||||
|
if (pq == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pq->container = taosArrayInit(1, sizeof(PriorityQueueNode));
|
pq->container = taosArrayInit(1, sizeof(PriorityQueueNode));
|
||||||
|
if (pq->container == NULL) {
|
||||||
|
taosMemoryFree(pq);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pq->fn = fn;
|
pq->fn = fn;
|
||||||
pq->deleteFn = deleteFn;
|
pq->deleteFn = deleteFn;
|
||||||
pq->param = param;
|
pq->param = param;
|
||||||
return pq;
|
return pq;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosPQSetFn(PriorityQueue* pq, pq_comp_fn fn) {
|
void taosPQSetFn(PriorityQueue* pq, pq_comp_fn fn) { pq->fn = fn; }
|
||||||
pq->fn = fn;
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroyPriorityQueue(PriorityQueue* pq) {
|
void destroyPriorityQueue(PriorityQueue* pq) {
|
||||||
if (pq->deleteFn)
|
if (pq->deleteFn)
|
||||||
|
@ -218,15 +224,15 @@ void destroyPriorityQueue(PriorityQueue* pq) {
|
||||||
|
|
||||||
static size_t pqParent(size_t i) { return (--i) >> 1; /* (i - 1) / 2 */ }
|
static size_t pqParent(size_t i) { return (--i) >> 1; /* (i - 1) / 2 */ }
|
||||||
static size_t pqLeft(size_t i) { return (i << 1) | 1; /* i * 2 + 1 */ }
|
static size_t pqLeft(size_t i) { return (i << 1) | 1; /* i * 2 + 1 */ }
|
||||||
static size_t pqRight(size_t i) { return (++i) << 1; /* (i + 1) * 2 */}
|
static size_t pqRight(size_t i) { return (++i) << 1; /* (i + 1) * 2 */ }
|
||||||
static void pqSwapPQNode(PriorityQueueNode* a, PriorityQueueNode* b) {
|
static void pqSwapPQNode(PriorityQueueNode* a, PriorityQueueNode* b) {
|
||||||
void * tmp = a->data;
|
void* tmp = a->data;
|
||||||
a->data = b->data;
|
a->data = b->data;
|
||||||
b->data = tmp;
|
b->data = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define pqContainerGetEle(pq, i) ((PriorityQueueNode*)taosArrayGet((pq)->container, (i)))
|
#define pqContainerGetEle(pq, i) ((PriorityQueueNode*)taosArrayGet((pq)->container, (i)))
|
||||||
#define pqContainerSize(pq) (taosArrayGetSize((pq)->container))
|
#define pqContainerSize(pq) (taosArrayGetSize((pq)->container))
|
||||||
|
|
||||||
size_t taosPQSize(PriorityQueue* pq) { return pqContainerSize(pq); }
|
size_t taosPQSize(PriorityQueue* pq) { return pqContainerSize(pq); }
|
||||||
|
|
||||||
|
@ -288,12 +294,12 @@ static void pqRemove(PriorityQueue* pq, size_t i) {
|
||||||
pqUpdate(pq, i);
|
pqUpdate(pq, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
PriorityQueueNode* taosPQTop(PriorityQueue* pq) {
|
PriorityQueueNode* taosPQTop(PriorityQueue* pq) { return pqContainerGetEle(pq, 0); }
|
||||||
return pqContainerGetEle(pq, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
PriorityQueueNode* taosPQPush(PriorityQueue* pq, const PriorityQueueNode* node) {
|
PriorityQueueNode* taosPQPush(PriorityQueue* pq, const PriorityQueueNode* node) {
|
||||||
taosArrayPush(pq->container, node);
|
if (taosArrayPush(pq->container, node) == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return pqReverseHeapify(pq, pqContainerSize(pq) - 1);
|
return pqReverseHeapify(pq, pqContainerSize(pq) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,15 +316,28 @@ struct BoundedQueue {
|
||||||
|
|
||||||
BoundedQueue* createBoundedQueue(uint32_t maxSize, pq_comp_fn fn, FDelete deleteFn, void* param) {
|
BoundedQueue* createBoundedQueue(uint32_t maxSize, pq_comp_fn fn, FDelete deleteFn, void* param) {
|
||||||
BoundedQueue* q = (BoundedQueue*)taosMemoryCalloc(1, sizeof(BoundedQueue));
|
BoundedQueue* q = (BoundedQueue*)taosMemoryCalloc(1, sizeof(BoundedQueue));
|
||||||
|
if (q == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
q->queue = createPriorityQueue(fn, deleteFn, param);
|
q->queue = createPriorityQueue(fn, deleteFn, param);
|
||||||
taosArrayEnsureCap(q->queue->container, maxSize + 1);
|
if (q->queue == NULL) {
|
||||||
|
taosMemoryFree(q);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t code = taosArrayEnsureCap(q->queue->container, maxSize + 1);
|
||||||
|
if (code) {
|
||||||
|
destroyPriorityQueue(q->queue);
|
||||||
|
taosMemoryFree(q);
|
||||||
|
terrno = code;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
q->maxSize = maxSize;
|
q->maxSize = maxSize;
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosBQSetFn(BoundedQueue* q, pq_comp_fn fn) {
|
void taosBQSetFn(BoundedQueue* q, pq_comp_fn fn) { taosPQSetFn(q->queue, fn); }
|
||||||
taosPQSetFn(q->queue, fn);
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroyBoundedQueue(BoundedQueue* q) {
|
void destroyBoundedQueue(BoundedQueue* q) {
|
||||||
if (!q) return;
|
if (!q) return;
|
||||||
|
@ -343,22 +362,12 @@ PriorityQueueNode* taosBQPush(BoundedQueue* q, PriorityQueueNode* n) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PriorityQueueNode* taosBQTop(BoundedQueue* q) {
|
PriorityQueueNode* taosBQTop(BoundedQueue* q) { return taosPQTop(q->queue); }
|
||||||
return taosPQTop(q->queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
void taosBQBuildHeap(BoundedQueue *q) {
|
void taosBQBuildHeap(BoundedQueue* q) { pqBuildHeap(q->queue); }
|
||||||
pqBuildHeap(q->queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t taosBQMaxSize(BoundedQueue* q) {
|
size_t taosBQMaxSize(BoundedQueue* q) { return q->maxSize; }
|
||||||
return q->maxSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t taosBQSize(BoundedQueue* q) {
|
size_t taosBQSize(BoundedQueue* q) { return taosPQSize(q->queue); }
|
||||||
return taosPQSize(q->queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
void taosBQPop(BoundedQueue* q) {
|
void taosBQPop(BoundedQueue* q) { taosPQPop(q->queue); }
|
||||||
taosPQPop(q->queue);
|
|
||||||
}
|
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
|
|
||||||
void *taosInitIdPool(int32_t maxId) {
|
void *taosInitIdPool(int32_t maxId) {
|
||||||
id_pool_t *pIdPool = taosMemoryCalloc(1, sizeof(id_pool_t));
|
id_pool_t *pIdPool = taosMemoryCalloc(1, sizeof(id_pool_t));
|
||||||
if (pIdPool == NULL) return NULL;
|
if (pIdPool == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pIdPool->freeList = taosMemoryCalloc(maxId, sizeof(bool));
|
pIdPool->freeList = taosMemoryCalloc(maxId, sizeof(bool));
|
||||||
if (pIdPool->freeList == NULL) {
|
if (pIdPool->freeList == NULL) {
|
||||||
|
@ -120,7 +122,7 @@ int32_t taosUpdateIdPool(id_pool_t *pIdPool, int32_t maxId) {
|
||||||
|
|
||||||
bool *idList = taosMemoryCalloc(maxId, sizeof(bool));
|
bool *idList = taosMemoryCalloc(maxId, sizeof(bool));
|
||||||
if (idList == NULL) {
|
if (idList == NULL) {
|
||||||
return -1;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadMutexLock(&pIdPool->mutex);
|
taosThreadMutexLock(&pIdPool->mutex);
|
||||||
|
|
|
@ -67,15 +67,13 @@ int32_t taosOpenRef(int32_t max, RefFp fp) {
|
||||||
|
|
||||||
nodeList = taosMemoryCalloc(sizeof(SRefNode *), (size_t)max);
|
nodeList = taosMemoryCalloc(sizeof(SRefNode *), (size_t)max);
|
||||||
if (nodeList == NULL) {
|
if (nodeList == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lockedBy = taosMemoryCalloc(sizeof(int64_t), (size_t)max);
|
lockedBy = taosMemoryCalloc(sizeof(int64_t), (size_t)max);
|
||||||
if (lockedBy == NULL) {
|
if (lockedBy == NULL) {
|
||||||
taosMemoryFree(nodeList);
|
taosMemoryFree(nodeList);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadMutexLock(&tsRefMutex);
|
taosThreadMutexLock(&tsRefMutex);
|
||||||
|
@ -118,8 +116,7 @@ int32_t taosCloseRef(int32_t rsetId) {
|
||||||
|
|
||||||
if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
|
if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
|
||||||
uTrace("rsetId:%d is invalid, out of range", rsetId);
|
uTrace("rsetId:%d is invalid, out of range", rsetId);
|
||||||
terrno = TSDB_CODE_REF_INVALID_ID;
|
return terrno = TSDB_CODE_REF_INVALID_ID;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pSet = tsRefSetList + rsetId;
|
pSet = tsRefSetList + rsetId;
|
||||||
|
@ -149,8 +146,7 @@ int64_t taosAddRef(int32_t rsetId, void *p) {
|
||||||
|
|
||||||
if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
|
if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
|
||||||
uTrace("rsetId:%d p:%p failed to add, rsetId not valid", rsetId, p);
|
uTrace("rsetId:%d p:%p failed to add, rsetId not valid", rsetId, p);
|
||||||
terrno = TSDB_CODE_REF_INVALID_ID;
|
return terrno = TSDB_CODE_REF_INVALID_ID;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pSet = tsRefSetList + rsetId;
|
pSet = tsRefSetList + rsetId;
|
||||||
|
@ -158,14 +154,12 @@ int64_t taosAddRef(int32_t rsetId, void *p) {
|
||||||
if (pSet->state != TSDB_REF_STATE_ACTIVE) {
|
if (pSet->state != TSDB_REF_STATE_ACTIVE) {
|
||||||
taosDecRsetCount(pSet);
|
taosDecRsetCount(pSet);
|
||||||
uTrace("rsetId:%d p:%p failed to add, not active", rsetId, p);
|
uTrace("rsetId:%d p:%p failed to add, not active", rsetId, p);
|
||||||
terrno = TSDB_CODE_REF_ID_REMOVED;
|
return terrno = TSDB_CODE_REF_ID_REMOVED;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pNode = taosMemoryCalloc(sizeof(SRefNode), 1);
|
pNode = taosMemoryCalloc(sizeof(SRefNode), 1);
|
||||||
if (pNode == NULL) {
|
if (pNode == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rid = atomic_add_fetch_64(&pSet->rid, 1);
|
rid = atomic_add_fetch_64(&pSet->rid, 1);
|
||||||
|
@ -389,21 +383,18 @@ static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove) {
|
||||||
|
|
||||||
if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
|
if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
|
||||||
uTrace("rsetId:%d rid:%" PRId64 " failed to remove, rsetId not valid", rsetId, rid);
|
uTrace("rsetId:%d rid:%" PRId64 " failed to remove, rsetId not valid", rsetId, rid);
|
||||||
terrno = TSDB_CODE_REF_INVALID_ID;
|
return terrno = TSDB_CODE_REF_INVALID_ID;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rid <= 0) {
|
if (rid <= 0) {
|
||||||
uTrace("rsetId:%d rid:%" PRId64 " failed to remove, rid not valid", rsetId, rid);
|
uTrace("rsetId:%d rid:%" PRId64 " failed to remove, rid not valid", rsetId, rid);
|
||||||
terrno = TSDB_CODE_REF_NOT_EXIST;
|
return terrno = TSDB_CODE_REF_NOT_EXIST;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pSet = tsRefSetList + rsetId;
|
pSet = tsRefSetList + rsetId;
|
||||||
if (pSet->state == TSDB_REF_STATE_EMPTY) {
|
if (pSet->state == TSDB_REF_STATE_EMPTY) {
|
||||||
uTrace("rsetId:%d rid:%" PRId64 " failed to remove, cleaned", rsetId, rid);
|
uTrace("rsetId:%d rid:%" PRId64 " failed to remove, cleaned", rsetId, rid);
|
||||||
terrno = TSDB_CODE_REF_ID_REMOVED;
|
return terrno = TSDB_CODE_REF_ID_REMOVED;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hash = rid % pSet->max;
|
hash = rid % pSet->max;
|
||||||
|
|
Loading…
Reference in New Issue