Merge branch '3.0' of https://github.com/taosdata/TDengine into fix/TD-30967

This commit is contained in:
54liuyao 2024-07-24 08:44:33 +08:00
commit e7413f2f78
27 changed files with 509 additions and 311 deletions

View File

@ -97,6 +97,7 @@ extern "C" {
#include <nmmintrin.h> #include <nmmintrin.h>
#endif #endif
#include "osThread.h" #include "osThread.h"
#include "osAtomic.h" #include "osAtomic.h"

View File

@ -54,7 +54,7 @@ extern SDiskSpace tsDataSpace;
extern SDiskSpace tsLogSpace; extern SDiskSpace tsLogSpace;
extern SDiskSpace tsTempSpace; extern SDiskSpace tsTempSpace;
void osDefaultInit(); int32_t osDefaultInit();
void osUpdate(); void osUpdate();
void osCleanup(); void osCleanup();
@ -66,7 +66,7 @@ bool osLogSpaceSufficient();
bool osDataSpaceSufficient(); bool osDataSpaceSufficient();
bool osTempSpaceSufficient(); bool osTempSpaceSufficient();
void osSetTimezone(const char *timezone); int32_t osSetTimezone(const char *timezone);
void osSetSystemLocale(const char *inLocale, const char *inCharSet); void osSetSystemLocale(const char *inLocale, const char *inCharSet);
void osSetProcPath(int32_t argc, char **argv); void osSetProcPath(int32_t argc, char **argv);

View File

@ -65,28 +65,28 @@ int32_t taosGetTimestampSec();
//@return timestamp in millisecond //@return timestamp in millisecond
static FORCE_INLINE int64_t taosGetTimestampMs() { static FORCE_INLINE int64_t taosGetTimestampMs() {
struct timeval systemTime; struct timeval systemTime;
taosGetTimeOfDay(&systemTime); (void)taosGetTimeOfDay(&systemTime);
return (int64_t)systemTime.tv_sec * 1000LL + (int64_t)systemTime.tv_usec / 1000; return (int64_t)systemTime.tv_sec * 1000LL + (int64_t)systemTime.tv_usec / 1000;
} }
//@return timestamp in microsecond //@return timestamp in microsecond
static FORCE_INLINE int64_t taosGetTimestampUs() { static FORCE_INLINE int64_t taosGetTimestampUs() {
struct timeval systemTime; struct timeval systemTime;
taosGetTimeOfDay(&systemTime); (void)taosGetTimeOfDay(&systemTime);
return (int64_t)systemTime.tv_sec * 1000000LL + (int64_t)systemTime.tv_usec; return (int64_t)systemTime.tv_sec * 1000000LL + (int64_t)systemTime.tv_usec;
} }
//@return timestamp in nanosecond //@return timestamp in nanosecond
static FORCE_INLINE int64_t taosGetTimestampNs() { static FORCE_INLINE int64_t taosGetTimestampNs() {
struct timespec systemTime = {0}; struct timespec systemTime = {0};
taosClockGetTime(CLOCK_REALTIME, &systemTime); (void)taosClockGetTime(CLOCK_REALTIME, &systemTime);
return (int64_t)systemTime.tv_sec * 1000000000LL + (int64_t)systemTime.tv_nsec; return (int64_t)systemTime.tv_sec * 1000000000LL + (int64_t)systemTime.tv_nsec;
} }
//@return timestamp of monotonic clock in millisecond //@return timestamp of monotonic clock in millisecond
static FORCE_INLINE int64_t taosGetMonoTimestampMs() { static FORCE_INLINE int64_t taosGetMonoTimestampMs() {
struct timespec systemTime = {0}; struct timespec systemTime = {0};
taosClockGetTime(CLOCK_MONOTONIC, &systemTime); (void)taosClockGetTime(CLOCK_MONOTONIC, &systemTime);
return (int64_t)systemTime.tv_sec * 1000LL + (int64_t)systemTime.tv_nsec / 1000000; return (int64_t)systemTime.tv_sec * 1000LL + (int64_t)systemTime.tv_nsec / 1000000;
} }

View File

@ -55,7 +55,7 @@ enum TdTimezone {
}; };
void taosGetSystemTimezone(char *outTimezone, enum TdTimezone *tsTimezone); void taosGetSystemTimezone(char *outTimezone, enum TdTimezone *tsTimezone);
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight, enum TdTimezone *tsTimezone); int32_t taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight, enum TdTimezone *tsTimezone);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -801,9 +801,8 @@ int32_t monitorInit() {
} }
if (taosMulModeMkDir(tmpSlowLogPath, 0777, true) != 0) { if (taosMulModeMkDir(tmpSlowLogPath, 0777, true) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
tscError("failed to create dir:%s since %s", tmpSlowLogPath, terrstr()); tscError("failed to create dir:%s since %s", tmpSlowLogPath, terrstr());
return -1; return terrno;
} }
if (tsem2_init(&monitorSem, 0, 0) != 0) { if (tsem2_init(&monitorSem, 0, 0) != 0) {

View File

@ -1306,7 +1306,6 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
taosSetAllDebugFlag(pCfg, cfgGetItem(pCfg, "debugFlag")->i32); taosSetAllDebugFlag(pCfg, cfgGetItem(pCfg, "debugFlag")->i32);
if (taosMulModeMkDir(tsLogDir, 0777, true) != 0) { if (taosMulModeMkDir(tsLogDir, 0777, true) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
printf("failed to create dir:%s since %s", tsLogDir, terrstr()); printf("failed to create dir:%s since %s", tsLogDir, terrstr());
cfgCleanup(pCfg); cfgCleanup(pCfg);
return -1; return -1;

View File

@ -262,7 +262,7 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
pWrapper = &pDnode->wrappers[ntype]; pWrapper = &pDnode->wrappers[ntype];
if (taosMkDir(pWrapper->path) != 0) { if (taosMkDir(pWrapper->path) != 0) {
dmReleaseWrapper(pWrapper); dmReleaseWrapper(pWrapper);
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to create dir:%s since %s", pWrapper->path, tstrerror(code)); dError("failed to create dir:%s since %s", pWrapper->path, tstrerror(code));
return code; return code;
} }
@ -333,7 +333,7 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
pWrapper = &pDnode->wrappers[ntype]; pWrapper = &pDnode->wrappers[ntype];
if (taosMkDir(pWrapper->path) != 0) { if (taosMkDir(pWrapper->path) != 0) {
taosThreadMutexUnlock(&pDnode->mutex); taosThreadMutexUnlock(&pDnode->mutex);
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to create dir:%s since %s", pWrapper->path, tstrerror(code)); dError("failed to create dir:%s since %s", pWrapper->path, tstrerror(code));
return code; return code;
} }

View File

@ -21,7 +21,7 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
SDnode *pDnode = pWrapper->pDnode; SDnode *pDnode = pWrapper->pDnode;
if (taosMkDir(pWrapper->path) != 0) { if (taosMkDir(pWrapper->path) != 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, tstrerror(code)); dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, tstrerror(code));
return code; return code;
} }

View File

@ -417,7 +417,7 @@ int32_t dmUpdateEncryptKey(char *key, bool toLogFile) {
} }
if (taosMkDir(folder) != 0) { if (taosMkDir(folder) != 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
encryptError("failed to create dir:%s since %s", folder, tstrerror(code)); encryptError("failed to create dir:%s since %s", folder, tstrerror(code));
goto _OVER; goto _OVER;
} }

View File

@ -457,7 +457,7 @@ static int32_t mndCreateDir(SMnode *pMnode, const char *path) {
} }
if (taosMkDir(pMnode->path) != 0) { if (taosMkDir(pMnode->path) != 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
TAOS_RETURN(code); TAOS_RETURN(code);
} }

View File

@ -226,7 +226,7 @@ void tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32
int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItemFn)(uint8_t *, void *), int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItemFn)(uint8_t *, void *),
int32_t (*tItemCmprFn)(const void *, const void *), void *pItem); int32_t (*tItemCmprFn)(const void *, const void *), void *pItem);
int32_t tPutMapData(uint8_t *p, SMapData *pMapData); int32_t tPutMapData(uint8_t *p, SMapData *pMapData);
int32_t tGetMapData(uint8_t *p, SMapData *pMapData); int32_t tGetMapData(uint8_t *p, SMapData *pMapData, int32_t *decodedSize);
int32_t tMapDataToArray(SMapData *pMapData, int32_t itemSize, int32_t (*tGetItemFn)(uint8_t *, void *), int32_t tMapDataToArray(SMapData *pMapData, int32_t itemSize, int32_t (*tGetItemFn)(uint8_t *, void *),
SArray **ppArray); SArray **ppArray);
// other // other
@ -706,7 +706,6 @@ typedef TARRAY2(STsdbFSetPartition *) STsdbFSetPartList;
STsdbFSetPartList *tsdbFSetPartListCreate(); STsdbFSetPartList *tsdbFSetPartListCreate();
void tsdbFSetPartListDestroy(STsdbFSetPartList **ppList); void tsdbFSetPartListDestroy(STsdbFSetPartList **ppList);
int32_t tSerializeTsdbFSetPartList(void *buf, int32_t bufLen, STsdbFSetPartList *pList);
int32_t tDeserializeTsdbFSetPartList(void *buf, int32_t bufLen, STsdbFSetPartList *pList); int32_t tDeserializeTsdbFSetPartList(void *buf, int32_t bufLen, STsdbFSetPartList *pList);
int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList *pList, TFileSetRangeArray **ppRanges); int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList *pList, TFileSetRangeArray **ppRanges);

View File

@ -757,10 +757,9 @@ int32_t tsdbReadDataBlk(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *m
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
// decode // decode
int64_t n = tGetMapData(pReader->aBuf[0], mDataBlk); int32_t n;
if (n < 0) { code = tGetMapData(pReader->aBuf[0], mDataBlk, &n);
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit); if (code) goto _exit;
}
ASSERT(n == size); ASSERT(n == size);
_exit: _exit:

View File

@ -81,7 +81,7 @@ static int32_t tsdbFTypeToFRangeType(tsdb_ftype_t ftype) {
static int32_t tsdbTFileSetToFSetPartition(STFileSet* fset, STsdbFSetPartition** ppSP) { static int32_t tsdbTFileSetToFSetPartition(STFileSet* fset, STsdbFSetPartition** ppSP) {
STsdbFSetPartition* p = tsdbFSetPartitionCreate(); STsdbFSetPartition* p = tsdbFSetPartitionCreate();
if (p == NULL) { if (p == NULL) {
goto _err; return terrno;
} }
p->fid = fset->fid; p->fid = fset->fid;
@ -134,10 +134,6 @@ static int32_t tsdbTFileSetToFSetPartition(STFileSet* fset, STsdbFSetPartition**
} }
ppSP[0] = p; ppSP[0] = p;
return 0; return 0;
_err:
tsdbFSetPartitionClear(&p);
return -1;
} }
// fset partition list // fset partition list
@ -160,9 +156,11 @@ void tsdbFSetPartListDestroy(STsdbFSetPartList** ppList) {
} }
int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList* pList, TFileSetRangeArray** ppRanges) { int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList* pList, TFileSetRangeArray** ppRanges) {
int32_t code = 0;
TFileSetRangeArray* pDiff = taosMemoryCalloc(1, sizeof(TFileSetRangeArray)); TFileSetRangeArray* pDiff = taosMemoryCalloc(1, sizeof(TFileSetRangeArray));
if (pDiff == NULL) { if (pDiff == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; code = TSDB_CODE_OUT_OF_MEMORY;
goto _err; goto _err;
} }
TARRAY2_INIT(pDiff); TARRAY2_INIT(pDiff);
@ -171,7 +169,7 @@ int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList* pList, TFileSetRangeArray
TARRAY2_FOREACH(pList, part) { TARRAY2_FOREACH(pList, part) {
STFileSetRange* r = taosMemoryCalloc(1, sizeof(STFileSetRange)); STFileSetRange* r = taosMemoryCalloc(1, sizeof(STFileSetRange));
if (r == NULL) { if (r == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; code = TSDB_CODE_OUT_OF_MEMORY;
goto _err; goto _err;
} }
int64_t maxVerValid = -1; int64_t maxVerValid = -1;
@ -202,7 +200,7 @@ _err:
if (pDiff) { if (pDiff) {
tsdbTFileSetRangeArrayDestroy(&pDiff); tsdbTFileSetRangeArrayDestroy(&pDiff);
} }
return -1; return code;
} }
// serialization // serialization
@ -235,96 +233,103 @@ int32_t tTsdbFSetPartListDataLenCalc(STsdbFSetPartList* pList) {
return datLen; return datLen;
} }
int32_t tSerializeTsdbFSetPartList(void* buf, int32_t bufLen, STsdbFSetPartList* pList) { static int32_t tSerializeTsdbFSetPartList(void* buf, int32_t bufLen, STsdbFSetPartList* pList, int32_t* encodeSize) {
SEncoder encoder = {0}; SEncoder encoder = {0};
tEncoderInit(&encoder, buf, bufLen);
int8_t reserved8 = 0; int8_t reserved8 = 0;
int16_t reserved16 = 0; int16_t reserved16 = 0;
int64_t reserved64 = 0; int64_t reserved64 = 0;
int8_t msgVer = TSDB_SNAP_MSG_VER; int8_t msgVer = TSDB_SNAP_MSG_VER;
int32_t len = TARRAY2_SIZE(pList); int32_t len = TARRAY2_SIZE(pList);
int32_t code = 0;
if (tStartEncode(&encoder) < 0) goto _err; tEncoderInit(&encoder, buf, bufLen);
if (tEncodeI8(&encoder, msgVer) < 0) goto _err; if ((code = tStartEncode(&encoder))) goto _exit;
if (tEncodeI32(&encoder, len) < 0) goto _err; if ((code = tEncodeI8(&encoder, msgVer))) goto _exit;
if ((code = tEncodeI32(&encoder, len))) goto _exit;
for (int32_t u = 0; u < len; u++) { for (int32_t u = 0; u < len; u++) {
STsdbFSetPartition* p = TARRAY2_GET(pList, u); STsdbFSetPartition* p = TARRAY2_GET(pList, u);
if (tEncodeI64(&encoder, p->fid) < 0) goto _err; if ((code = tEncodeI64(&encoder, p->fid))) goto _exit;
if (tEncodeI8(&encoder, p->stat) < 0) goto _err; if ((code = tEncodeI8(&encoder, p->stat))) goto _exit;
if (tEncodeI8(&encoder, reserved8) < 0) goto _err; if ((code = tEncodeI8(&encoder, reserved8))) goto _exit;
if (tEncodeI16(&encoder, reserved16) < 0) goto _err; if ((code = tEncodeI16(&encoder, reserved16))) goto _exit;
int32_t typMax = TSDB_FSET_RANGE_TYP_MAX; int32_t typMax = TSDB_FSET_RANGE_TYP_MAX;
if (tEncodeI32(&encoder, typMax) < 0) goto _err; if ((code = tEncodeI32(&encoder, typMax))) goto _exit;
for (int32_t i = 0; i < typMax; i++) { for (int32_t i = 0; i < typMax; i++) {
SVerRangeList* iList = &p->verRanges[i]; SVerRangeList* iList = &p->verRanges[i];
int32_t iLen = TARRAY2_SIZE(iList); int32_t iLen = TARRAY2_SIZE(iList);
if (tEncodeI32(&encoder, iLen) < 0) goto _err; if ((code = tEncodeI32(&encoder, iLen))) goto _exit;
for (int32_t j = 0; j < iLen; j++) { for (int32_t j = 0; j < iLen; j++) {
SVersionRange r = TARRAY2_GET(iList, j); SVersionRange r = TARRAY2_GET(iList, j);
if (tEncodeI64(&encoder, r.minVer) < 0) goto _err; if ((code = tEncodeI64(&encoder, r.minVer))) goto _exit;
if (tEncodeI64(&encoder, r.maxVer) < 0) goto _err; if ((code = tEncodeI64(&encoder, r.maxVer))) goto _exit;
if (tEncodeI64(&encoder, reserved64) < 0) goto _err; if ((code = tEncodeI64(&encoder, reserved64))) goto _exit;
} }
} }
} }
tEndEncode(&encoder); tEndEncode(&encoder);
int32_t tlen = encoder.pos;
tEncoderClear(&encoder);
return tlen;
_err: if (encodeSize) {
encodeSize[0] = encoder.pos;
}
_exit:
tEncoderClear(&encoder); tEncoderClear(&encoder);
return -1; return code;
} }
int32_t tDeserializeTsdbFSetPartList(void* buf, int32_t bufLen, STsdbFSetPartList* pList) { int32_t tDeserializeTsdbFSetPartList(void* buf, int32_t bufLen, STsdbFSetPartList* pList) {
SDecoder decoder = {0}; SDecoder decoder = {0};
tDecoderInit(&decoder, buf, bufLen);
int8_t reserved8 = 0; int8_t reserved8 = 0;
int16_t reserved16 = 0; int16_t reserved16 = 0;
int64_t reserved64 = 0; int64_t reserved64 = 0;
int32_t code = 0;
STsdbFSetPartition* p = NULL; STsdbFSetPartition* p = NULL;
tDecoderInit(&decoder, buf, bufLen);
int8_t msgVer = 0; int8_t msgVer = 0;
int32_t len = 0; int32_t len = 0;
if (tStartDecode(&decoder) < 0) goto _err; if ((code = tStartDecode(&decoder))) goto _err;
if (tDecodeI8(&decoder, &msgVer) < 0) goto _err; if ((code = tDecodeI8(&decoder, &msgVer))) goto _err;
if (msgVer != TSDB_SNAP_MSG_VER) goto _err; if (msgVer != TSDB_SNAP_MSG_VER) {
if (tDecodeI32(&decoder, &len) < 0) goto _err; code = TSDB_CODE_INVALID_MSG;
goto _err;
}
if ((code = tDecodeI32(&decoder, &len))) goto _err;
for (int32_t u = 0; u < len; u++) { for (int32_t u = 0; u < len; u++) {
p = tsdbFSetPartitionCreate(); p = tsdbFSetPartitionCreate();
if (p == NULL) goto _err; if (p == NULL) {
if (tDecodeI64(&decoder, &p->fid) < 0) goto _err; code = terrno;
if (tDecodeI8(&decoder, &p->stat) < 0) goto _err; goto _err;
if (tDecodeI8(&decoder, &reserved8) < 0) goto _err; }
if (tDecodeI16(&decoder, &reserved16) < 0) goto _err;
if ((code = tDecodeI64(&decoder, &p->fid))) goto _err;
if ((code = tDecodeI8(&decoder, &p->stat))) goto _err;
if ((code = tDecodeI8(&decoder, &reserved8))) goto _err;
if ((code = tDecodeI16(&decoder, &reserved16))) goto _err;
int32_t typMax = 0; int32_t typMax = 0;
if (tDecodeI32(&decoder, &typMax) < 0) goto _err; if ((code = tDecodeI32(&decoder, &typMax))) goto _err;
for (int32_t i = 0; i < typMax; i++) { for (int32_t i = 0; i < typMax; i++) {
SVerRangeList* iList = &p->verRanges[i]; SVerRangeList* iList = &p->verRanges[i];
int32_t iLen = 0; int32_t iLen = 0;
if (tDecodeI32(&decoder, &iLen) < 0) goto _err; if ((code = tDecodeI32(&decoder, &iLen))) goto _err;
for (int32_t j = 0; j < iLen; j++) { for (int32_t j = 0; j < iLen; j++) {
SVersionRange r = {0}; SVersionRange r = {0};
if (tDecodeI64(&decoder, &r.minVer) < 0) goto _err; if ((code = tDecodeI64(&decoder, &r.minVer))) goto _err;
if (tDecodeI64(&decoder, &r.maxVer) < 0) goto _err; if ((code = tDecodeI64(&decoder, &r.maxVer))) goto _err;
if (tDecodeI64(&decoder, &reserved64) < 0) goto _err; if ((code = tDecodeI64(&decoder, &reserved64))) goto _err;
if (TARRAY2_APPEND(iList, r)) goto _err; if ((code = TARRAY2_APPEND(iList, r))) goto _err;
} }
} }
if (TARRAY2_APPEND(pList, p)) goto _err; if ((code = TARRAY2_APPEND(pList, p))) goto _err;
p = NULL; p = NULL;
} }
@ -337,7 +342,7 @@ _err:
tsdbFSetPartitionClear(&p); tsdbFSetPartitionClear(&p);
} }
tDecoderClear(&decoder); tDecoderClear(&decoder);
return -1; return code;
} }
// fs state // fs state
@ -352,8 +357,9 @@ static STsdbFSetPartList* tsdbSnapGetFSetPartList(STFileSystem* fs) {
STFileSet* fset; STFileSet* fset;
TARRAY2_FOREACH(fs->fSetArr, fset) { TARRAY2_FOREACH(fs->fSetArr, fset) {
STsdbFSetPartition* pItem = NULL; STsdbFSetPartition* pItem = NULL;
if (tsdbTFileSetToFSetPartition(fset, &pItem) < 0) { code = tsdbTFileSetToFSetPartition(fset, &pItem);
code = -1; if (code) {
terrno = code;
break; break;
} }
ASSERT(pItem != NULL); ASSERT(pItem != NULL);
@ -404,7 +410,9 @@ static int32_t tsdbPartitionInfoInit(SVnode* pVnode, STsdbPartitionInfo* pInfo)
for (int32_t j = 0; j < pInfo->tsdbMaxCnt; ++j) { for (int32_t j = 0; j < pInfo->tsdbMaxCnt; ++j) {
STsdb* pTsdb = SMA_RSMA_GET_TSDB(pVnode, j); STsdb* pTsdb = SMA_RSMA_GET_TSDB(pVnode, j);
pInfo->pLists[j] = tsdbSnapGetFSetPartList(pTsdb->pFS); pInfo->pLists[j] = tsdbSnapGetFSetPartList(pTsdb->pFS);
if (pInfo->pLists[j] == NULL) return -1; if (pInfo->pLists[j] == NULL) {
return terrno;
}
} }
return 0; return 0;
} }
@ -432,9 +440,10 @@ static int32_t tsdbPartitionInfoSerialize(STsdbPartitionInfo* pInfo, uint8_t* bu
SSyncTLV* pSubHead = (void*)((char*)buf + offset); SSyncTLV* pSubHead = (void*)((char*)buf + offset);
int32_t valOffset = offset + sizeof(*pSubHead); int32_t valOffset = offset + sizeof(*pSubHead);
ASSERT(pSubHead->val == (char*)buf + valOffset); ASSERT(pSubHead->val == (char*)buf + valOffset);
if ((tlen = tSerializeTsdbFSetPartList(pSubHead->val, bufLen - valOffset, pInfo->pLists[j])) < 0) { int32_t code = tSerializeTsdbFSetPartList(pSubHead->val, bufLen - valOffset, pInfo->pLists[j], &tlen);
if (code) {
tsdbError("vgId:%d, failed to serialize fset partition list of tsdb %d since %s", pInfo->vgId, j, terrstr()); tsdbError("vgId:%d, failed to serialize fset partition list of tsdb %d since %s", pInfo->vgId, j, terrstr());
return -1; return code;
} }
pSubHead->typ = pInfo->subTyps[j]; pSubHead->typ = pInfo->subTyps[j];
pSubHead->len = tlen; pSubHead->len = tlen;
@ -460,17 +469,18 @@ static int32_t tTsdbRepOptsDataLenCalc(STsdbRepOpts* pInfo) {
} }
int32_t tSerializeTsdbRepOpts(void* buf, int32_t bufLen, STsdbRepOpts* pOpts) { int32_t tSerializeTsdbRepOpts(void* buf, int32_t bufLen, STsdbRepOpts* pOpts) {
int32_t code = 0;
SEncoder encoder = {0}; SEncoder encoder = {0};
tEncoderInit(&encoder, buf, bufLen);
int64_t reserved64 = 0; int64_t reserved64 = 0;
int8_t msgVer = TSDB_SNAP_MSG_VER; int8_t msgVer = TSDB_SNAP_MSG_VER;
if (tStartEncode(&encoder) < 0) goto _err; tEncoderInit(&encoder, buf, bufLen);
if (tEncodeI8(&encoder, msgVer) < 0) goto _err;
if ((code = tStartEncode(&encoder))) goto _err;
if ((code = tEncodeI8(&encoder, msgVer))) goto _err;
int16_t format = pOpts->format; int16_t format = pOpts->format;
if (tEncodeI16(&encoder, format) < 0) goto _err; if ((code = tEncodeI16(&encoder, format))) goto _err;
if (tEncodeI64(&encoder, reserved64) < 0) goto _err; if ((code = tEncodeI64(&encoder, reserved64))) goto _err;
tEndEncode(&encoder); tEndEncode(&encoder);
int32_t tlen = encoder.pos; int32_t tlen = encoder.pos;
@ -479,23 +489,24 @@ int32_t tSerializeTsdbRepOpts(void* buf, int32_t bufLen, STsdbRepOpts* pOpts) {
_err: _err:
tEncoderClear(&encoder); tEncoderClear(&encoder);
return -1; return code;
} }
int32_t tDeserializeTsdbRepOpts(void* buf, int32_t bufLen, STsdbRepOpts* pOpts) { int32_t tDeserializeTsdbRepOpts(void* buf, int32_t bufLen, STsdbRepOpts* pOpts) {
int32_t code;
SDecoder decoder = {0}; SDecoder decoder = {0};
tDecoderInit(&decoder, buf, bufLen);
int64_t reserved64 = 0; int64_t reserved64 = 0;
int8_t msgVer = 0; int8_t msgVer = 0;
if (tStartDecode(&decoder) < 0) goto _err; tDecoderInit(&decoder, buf, bufLen);
if (tDecodeI8(&decoder, &msgVer) < 0) goto _err;
if ((code = tStartDecode(&decoder))) goto _err;
if ((code = tDecodeI8(&decoder, &msgVer))) goto _err;
if (msgVer != TSDB_SNAP_MSG_VER) goto _err; if (msgVer != TSDB_SNAP_MSG_VER) goto _err;
int16_t format = 0; int16_t format = 0;
if (tDecodeI16(&decoder, &format) < 0) goto _err; if ((code = tDecodeI16(&decoder, &format))) goto _err;
pOpts->format = format; pOpts->format = format;
if (tDecodeI64(&decoder, &reserved64) < 0) goto _err; if ((code = tDecodeI64(&decoder, &reserved64))) goto _err;
tEndDecode(&decoder); tEndDecode(&decoder);
tDecoderClear(&decoder); tDecoderClear(&decoder);
@ -503,7 +514,7 @@ int32_t tDeserializeTsdbRepOpts(void* buf, int32_t bufLen, STsdbRepOpts* pOpts)
_err: _err:
tDecoderClear(&decoder); tDecoderClear(&decoder);
return -1; return code;
} }
static int32_t tsdbRepOptsEstSize(STsdbRepOpts* pOpts) { static int32_t tsdbRepOptsEstSize(STsdbRepOpts* pOpts) {
@ -518,7 +529,7 @@ static int32_t tsdbRepOptsSerialize(STsdbRepOpts* pOpts, void* buf, int32_t bufL
int32_t offset = 0; int32_t offset = 0;
int32_t tlen = 0; int32_t tlen = 0;
if ((tlen = tSerializeTsdbRepOpts(pSubHead->val, bufLen, pOpts)) < 0) { if ((tlen = tSerializeTsdbRepOpts(pSubHead->val, bufLen, pOpts)) < 0) {
return -1; return tlen;
} }
pSubHead->typ = SNAP_DATA_RAW; pSubHead->typ = SNAP_DATA_RAW;
pSubHead->len = tlen; pSubHead->len = tlen;
@ -528,8 +539,10 @@ static int32_t tsdbRepOptsSerialize(STsdbRepOpts* pOpts, void* buf, int32_t bufL
// snap info // snap info
static int32_t tsdbSnapPrepDealWithSnapInfo(SVnode* pVnode, SSnapshot* pSnap, STsdbRepOpts* pInfo) { static int32_t tsdbSnapPrepDealWithSnapInfo(SVnode* pVnode, SSnapshot* pSnap, STsdbRepOpts* pInfo) {
if (!pSnap->data) return 0; if (!pSnap->data) {
int32_t code = -1; return 0;
}
int32_t code = 0;
SSyncTLV* pHead = (void*)pSnap->data; SSyncTLV* pHead = (void*)pSnap->data;
int32_t offset = 0; int32_t offset = 0;
@ -546,30 +559,30 @@ static int32_t tsdbSnapPrepDealWithSnapInfo(SVnode* pVnode, SSnapshot* pSnap, ST
case SNAP_DATA_RSMA2: { case SNAP_DATA_RSMA2: {
} break; } break;
case SNAP_DATA_RAW: { case SNAP_DATA_RAW: {
if (tDeserializeTsdbRepOpts(buf, bufLen, pInfo) < 0) { code = tDeserializeTsdbRepOpts(buf, bufLen, pInfo);
terrno = TSDB_CODE_INVALID_DATA_FMT; if (code < 0) {
tsdbError("vgId:%d, failed to deserialize tsdb rep opts since %s", TD_VID(pVnode), terrstr()); tsdbError("vgId:%d, failed to deserialize tsdb rep opts since %s", TD_VID(pVnode), terrstr());
goto _out; return code;
} }
} break; } break;
default: default:
code = TSDB_CODE_INVALID_MSG;
tsdbError("vgId:%d, unexpected subfield type of snap info. typ:%d", TD_VID(pVnode), pField->typ); tsdbError("vgId:%d, unexpected subfield type of snap info. typ:%d", TD_VID(pVnode), pField->typ);
goto _out; return code;
} }
} }
code = 0;
_out:
return code; return code;
} }
int32_t tsdbSnapPrepDescription(SVnode* pVnode, SSnapshot* pSnap) { int32_t tsdbSnapPrepDescription(SVnode* pVnode, SSnapshot* pSnap) {
ASSERT(pSnap->type == TDMT_SYNC_PREP_SNAPSHOT || pSnap->type == TDMT_SYNC_PREP_SNAPSHOT_REPLY); ASSERT(pSnap->type == TDMT_SYNC_PREP_SNAPSHOT || pSnap->type == TDMT_SYNC_PREP_SNAPSHOT_REPLY);
STsdbPartitionInfo partitionInfo = {0}; STsdbPartitionInfo partitionInfo = {0};
int code = -1; int code = 0;
STsdbPartitionInfo* pInfo = &partitionInfo; STsdbPartitionInfo* pInfo = &partitionInfo;
if (tsdbPartitionInfoInit(pVnode, pInfo) != 0) { code = tsdbPartitionInfoInit(pVnode, pInfo);
if (code) {
goto _out; goto _out;
} }
@ -577,7 +590,7 @@ int32_t tsdbSnapPrepDescription(SVnode* pVnode, SSnapshot* pSnap) {
STsdbRepOpts opts = {.format = TSDB_SNAP_REP_FMT_RAW}; STsdbRepOpts opts = {.format = TSDB_SNAP_REP_FMT_RAW};
if (pSnap->type == TDMT_SYNC_PREP_SNAPSHOT_REPLY) { if (pSnap->type == TDMT_SYNC_PREP_SNAPSHOT_REPLY) {
STsdbRepOpts leaderOpts = {0}; STsdbRepOpts leaderOpts = {0};
if (tsdbSnapPrepDealWithSnapInfo(pVnode, pSnap, &leaderOpts) < 0) { if ((code = tsdbSnapPrepDealWithSnapInfo(pVnode, pSnap, &leaderOpts)) < 0) {
tsdbError("vgId:%d, failed to deal with snap info for reply since %s", TD_VID(pVnode), terrstr()); tsdbError("vgId:%d, failed to deal with snap info for reply since %s", TD_VID(pVnode), terrstr());
goto _out; goto _out;
} }
@ -589,7 +602,7 @@ int32_t tsdbSnapPrepDescription(SVnode* pVnode, SSnapshot* pSnap) {
int32_t bufLen = headLen; int32_t bufLen = headLen;
bufLen += tsdbPartitionInfoEstSize(pInfo); bufLen += tsdbPartitionInfoEstSize(pInfo);
bufLen += tsdbRepOptsEstSize(&opts); bufLen += tsdbRepOptsEstSize(&opts);
if (syncSnapInfoDataRealloc(pSnap, bufLen) != 0) { if ((code = syncSnapInfoDataRealloc(pSnap, bufLen)) != 0) {
tsdbError("vgId:%d, failed to realloc memory for data of snap info. bytes:%d", TD_VID(pVnode), bufLen); tsdbError("vgId:%d, failed to realloc memory for data of snap info. bytes:%d", TD_VID(pVnode), bufLen);
goto _out; goto _out;
} }
@ -599,7 +612,8 @@ int32_t tsdbSnapPrepDescription(SVnode* pVnode, SSnapshot* pSnap) {
int32_t offset = headLen; int32_t offset = headLen;
int32_t tlen = 0; int32_t tlen = 0;
if ((tlen = tsdbPartitionInfoSerialize(pInfo, buf + offset, bufLen - offset)) < 0) { if ((tlen = tsdbPartitionInfoSerialize(pInfo, (uint8_t*)(buf + offset), bufLen - offset)) < 0) {
code = tlen;
tsdbError("vgId:%d, failed to serialize tsdb partition info since %s", TD_VID(pVnode), terrstr()); tsdbError("vgId:%d, failed to serialize tsdb partition info since %s", TD_VID(pVnode), terrstr());
goto _out; goto _out;
} }
@ -607,6 +621,7 @@ int32_t tsdbSnapPrepDescription(SVnode* pVnode, SSnapshot* pSnap) {
ASSERT(offset <= bufLen); ASSERT(offset <= bufLen);
if ((tlen = tsdbRepOptsSerialize(&opts, buf + offset, bufLen - offset)) < 0) { if ((tlen = tsdbRepOptsSerialize(&opts, buf + offset, bufLen - offset)) < 0) {
code = tlen;
tsdbError("vgId:%d, failed to serialize tsdb rep opts since %s", TD_VID(pVnode), terrstr()); tsdbError("vgId:%d, failed to serialize tsdb rep opts since %s", TD_VID(pVnode), terrstr());
goto _out; goto _out;
} }
@ -620,7 +635,7 @@ int32_t tsdbSnapPrepDescription(SVnode* pVnode, SSnapshot* pSnap) {
tsdbInfo("vgId:%d, tsdb snap info prepared. type:%s, val length:%d", TD_VID(pVnode), TMSG_INFO(pHead->typ), tsdbInfo("vgId:%d, tsdb snap info prepared. type:%s, val length:%d", TD_VID(pVnode), TMSG_INFO(pHead->typ),
pHead->len); pHead->len);
code = 0;
_out: _out:
tsdbPartitionInfoClear(pInfo); tsdbPartitionInfoClear(pInfo);
return code; return code;

View File

@ -152,7 +152,7 @@ int32_t tPutMapData(uint8_t *p, SMapData *pMapData) {
} }
#endif #endif
int32_t tGetMapData(uint8_t *p, SMapData *pMapData) { int32_t tGetMapData(uint8_t *p, SMapData *pMapData, int32_t *decodedSize) {
int32_t n = 0; int32_t n = 0;
int32_t offset; int32_t offset;
@ -160,7 +160,9 @@ int32_t tGetMapData(uint8_t *p, SMapData *pMapData) {
n += tGetI32v(p + n, &pMapData->nItem); n += tGetI32v(p + n, &pMapData->nItem);
if (pMapData->nItem) { if (pMapData->nItem) {
if (tRealloc((uint8_t **)&pMapData->aOffset, sizeof(int32_t) * pMapData->nItem)) return -1; if (tRealloc((uint8_t **)&pMapData->aOffset, sizeof(int32_t) * pMapData->nItem)) {
return TSDB_CODE_OUT_OF_MEMORY;
}
int32_t lOffset = 0; int32_t lOffset = 0;
for (int32_t iItem = 0; iItem < pMapData->nItem; iItem++) { for (int32_t iItem = 0; iItem < pMapData->nItem; iItem++) {
@ -170,12 +172,18 @@ int32_t tGetMapData(uint8_t *p, SMapData *pMapData) {
} }
n += tGetI32v(p + n, &pMapData->nData); n += tGetI32v(p + n, &pMapData->nData);
if (tRealloc(&pMapData->pData, pMapData->nData)) return -1; if (tRealloc(&pMapData->pData, pMapData->nData)) {
return TSDB_CODE_OUT_OF_MEMORY;
}
memcpy(pMapData->pData, p + n, pMapData->nData); memcpy(pMapData->pData, p + n, pMapData->nData);
n += pMapData->nData; n += pMapData->nData;
} }
return n; if (decodedSize) {
*decodedSize = n;
}
return 0;
} }
#ifdef BUILD_NO_CALL #ifdef BUILD_NO_CALL
@ -680,20 +688,17 @@ int32_t tsdbRowCompareWithoutVersion(const void *p1, const void *p2) {
// STSDBRowIter ====================================================== // STSDBRowIter ======================================================
int32_t tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema) { int32_t tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema) {
int32_t code = 0;
pIter->pRow = pRow; pIter->pRow = pRow;
if (pRow->type == TSDBROW_ROW_FMT) { if (pRow->type == TSDBROW_ROW_FMT) {
code = tRowIterOpen(pRow->pTSRow, pTSchema, &pIter->pIter); int32_t code = tRowIterOpen(pRow->pTSRow, pTSchema, &pIter->pIter);
if (code) goto _exit; if (code) return code;
} else if (pRow->type == TSDBROW_COL_FMT) { } else if (pRow->type == TSDBROW_COL_FMT) {
pIter->iColData = 0; pIter->iColData = 0;
} else { } else {
ASSERT(0); ASSERT(0);
} }
_exit: return 0;
return code;
} }
void tsdbRowClose(STSDBRowIter *pIter) { void tsdbRowClose(STSDBRowIter *pIter) {
@ -760,7 +765,9 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
--iCol; --iCol;
continue; continue;
} else if (pTSchema->columns[jCol].colId > pTColumn->colId) { } else if (pTSchema->columns[jCol].colId > pTColumn->colId) {
taosArrayPush(pMerger->pArray, &COL_VAL_NONE(pTColumn->colId, pTColumn->type)); if (taosArrayPush(pMerger->pArray, &COL_VAL_NONE(pTColumn->colId, pTColumn->type)) == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
continue; continue;
} }
@ -780,14 +787,15 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
} }
if (taosArrayPush(pMerger->pArray, pColVal) == NULL) { if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
return code;
} }
} }
for (; iCol < pMerger->pTSchema->numOfCols; ++iCol) { for (; iCol < pMerger->pTSchema->numOfCols; ++iCol) {
pTColumn = &pMerger->pTSchema->columns[iCol]; pTColumn = &pMerger->pTSchema->columns[iCol];
taosArrayPush(pMerger->pArray, &COL_VAL_NONE(pTColumn->colId, pTColumn->type)); if (taosArrayPush(pMerger->pArray, &COL_VAL_NONE(pTColumn->colId, pTColumn->type)) == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
} }
pMerger->version = key.version; pMerger->version = key.version;
@ -962,8 +970,7 @@ _exit:
*/ */
// delete skyline ====================================================== // delete skyline ======================================================
static int32_t tsdbMergeSkyline(SArray *pSkyline1, SArray *pSkyline2, SArray *pSkyline) { static void tsdbMergeSkyline(SArray *pSkyline1, SArray *pSkyline2, SArray *pSkyline) {
int32_t code = 0;
int32_t i1 = 0; int32_t i1 = 0;
int32_t n1 = taosArrayGetSize(pSkyline1); int32_t n1 = taosArrayGetSize(pSkyline1);
int32_t i2 = 0; int32_t i2 = 0;
@ -1017,7 +1024,6 @@ static int32_t tsdbMergeSkyline(SArray *pSkyline1, SArray *pSkyline2, SArray *pS
} }
pSkyline->size = TARRAY_ELEM_IDX(pSkyline, pItem); pSkyline->size = TARRAY_ELEM_IDX(pSkyline, pItem);
return code;
} }
int32_t tsdbBuildDeleteSkylineImpl(SArray *aSkyline, int32_t sidx, int32_t eidx, SArray *pSkyline) { int32_t tsdbBuildDeleteSkylineImpl(SArray *aSkyline, int32_t sidx, int32_t eidx, SArray *pSkyline) {
@ -1029,8 +1035,13 @@ int32_t tsdbBuildDeleteSkylineImpl(SArray *aSkyline, int32_t sidx, int32_t eidx,
if (sidx == eidx) { if (sidx == eidx) {
TSDBKEY *pItem1 = taosArrayGet(aSkyline, sidx * 2); TSDBKEY *pItem1 = taosArrayGet(aSkyline, sidx * 2);
TSDBKEY *pItem2 = taosArrayGet(aSkyline, sidx * 2 + 1); TSDBKEY *pItem2 = taosArrayGet(aSkyline, sidx * 2 + 1);
taosArrayPush(pSkyline, &pItem1); if (taosArrayPush(pSkyline, &pItem1) == NULL) {
taosArrayPush(pSkyline, &pItem2); return TSDB_CODE_OUT_OF_MEMORY;
}
if (taosArrayPush(pSkyline, &pItem2) == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
} else { } else {
SArray *pSkyline1 = NULL; SArray *pSkyline1 = NULL;
SArray *pSkyline2 = NULL; SArray *pSkyline2 = NULL;
@ -1049,7 +1060,7 @@ int32_t tsdbBuildDeleteSkylineImpl(SArray *aSkyline, int32_t sidx, int32_t eidx,
code = tsdbBuildDeleteSkylineImpl(aSkyline, midx + 1, eidx, pSkyline2); code = tsdbBuildDeleteSkylineImpl(aSkyline, midx + 1, eidx, pSkyline2);
if (code) goto _clear; if (code) goto _clear;
code = tsdbMergeSkyline(pSkyline1, pSkyline2, pSkyline); tsdbMergeSkyline(pSkyline1, pSkyline2, pSkyline);
_clear: _clear:
taosArrayDestroy(pSkyline1); taosArrayDestroy(pSkyline1);
@ -1064,13 +1075,28 @@ int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SAr
int32_t code = 0; int32_t code = 0;
int32_t dataNum = eidx - sidx + 1; int32_t dataNum = eidx - sidx + 1;
SArray *aTmpSkyline = taosArrayInit(dataNum * 2, sizeof(TSDBKEY)); SArray *aTmpSkyline = taosArrayInit(dataNum * 2, sizeof(TSDBKEY));
if (aTmpSkyline == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
SArray *pSkyline = taosArrayInit(dataNum * 2, POINTER_BYTES); SArray *pSkyline = taosArrayInit(dataNum * 2, POINTER_BYTES);
if (pSkyline == NULL) {
taosArrayDestroy(aTmpSkyline);
return TSDB_CODE_OUT_OF_MEMORY;
}
taosArrayClear(aSkyline); taosArrayClear(aSkyline);
for (int32_t i = sidx; i <= eidx; ++i) { for (int32_t i = sidx; i <= eidx; ++i) {
pDelData = (SDelData *)taosArrayGet(aDelData, i); pDelData = (SDelData *)taosArrayGet(aDelData, i);
taosArrayPush(aTmpSkyline, &(TSDBKEY){.ts = pDelData->sKey, .version = pDelData->version}); if (taosArrayPush(aTmpSkyline, &(TSDBKEY){.ts = pDelData->sKey, .version = pDelData->version}) == NULL) {
taosArrayPush(aTmpSkyline, &(TSDBKEY){.ts = pDelData->eKey, .version = 0}); code = TSDB_CODE_OUT_OF_MEMORY;
goto _clear;
}
if (taosArrayPush(aTmpSkyline, &(TSDBKEY){.ts = pDelData->eKey, .version = 0}) == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _clear;
}
} }
code = tsdbBuildDeleteSkylineImpl(aTmpSkyline, sidx, eidx, pSkyline); code = tsdbBuildDeleteSkylineImpl(aTmpSkyline, sidx, eidx, pSkyline);
@ -1079,7 +1105,10 @@ int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SAr
int32_t skylineNum = taosArrayGetSize(pSkyline); int32_t skylineNum = taosArrayGetSize(pSkyline);
for (int32_t i = 0; i < skylineNum; ++i) { for (int32_t i = 0; i < skylineNum; ++i) {
TSDBKEY *p = taosArrayGetP(pSkyline, i); TSDBKEY *p = taosArrayGetP(pSkyline, i);
taosArrayPush(aSkyline, p); if (taosArrayPush(aSkyline, p) == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _clear;
}
} }
_clear: _clear:
@ -1519,8 +1548,8 @@ int32_t tBlockDataDecompress(SBufferReader *br, SBlockData *blockData, SBuffer *
SBlockCol blockCol; SBlockCol blockCol;
code = tGetBlockCol(&br2, &blockCol, hdr.fmtVer, hdr.cmprAlg); code = tGetBlockCol(&br2, &blockCol, hdr.fmtVer, hdr.cmprAlg);
if (blockCol.alg == 0) blockCol.alg = hdr.cmprAlg;
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
if (blockCol.alg == 0) blockCol.alg = hdr.cmprAlg;
code = tBlockDataDecompressColData(&hdr, &blockCol, br, blockData, assist); code = tBlockDataDecompressColData(&hdr, &blockCol, br, blockData, assist);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
@ -1812,7 +1841,9 @@ int32_t tsdbGetColCmprAlgFromSet(SHashObj *set, int16_t colId, uint32_t *alg) {
if (set == NULL) return -1; if (set == NULL) return -1;
uint32_t *ret = taosHashGet(set, &colId, sizeof(colId)); uint32_t *ret = taosHashGet(set, &colId, sizeof(colId));
if (ret == NULL) return -1; if (ret == NULL) {
return TSDB_CODE_NOT_FOUND;
}
*alg = *ret; *alg = *ret;
return 0; return 0;

View File

@ -43,17 +43,16 @@ void syncUtilNodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet) {
bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* raftId) { bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* raftId) {
uint32_t ipv4 = 0xFFFFFFFF; uint32_t ipv4 = 0xFFFFFFFF;
sDebug("vgId:%d, start to resolve sync addr fqdn in %d seconds, " sDebug(
"vgId:%d, start to resolve sync addr fqdn in %d seconds, "
"dnode:%d cluster:%" PRId64 " fqdn:%s port:%u ", "dnode:%d cluster:%" PRId64 " fqdn:%s port:%u ",
vgId, tsResolveFQDNRetryTime, vgId, tsResolveFQDNRetryTime, pInfo->nodeId, pInfo->clusterId, pInfo->nodeFqdn, pInfo->nodePort);
pInfo->nodeId, pInfo->clusterId, pInfo->nodeFqdn, pInfo->nodePort);
for (int i = 0; i < tsResolveFQDNRetryTime; i++) { for (int i = 0; i < tsResolveFQDNRetryTime; i++) {
ipv4 = taosGetIpv4FromFqdn(pInfo->nodeFqdn); ipv4 = taosGetIpv4FromFqdn(pInfo->nodeFqdn);
if (ipv4 == 0xFFFFFFFF || ipv4 == 1) { if (ipv4 == 0xFFFFFFFF || ipv4 == 1) {
sError("failed to resolve ipv4 addr, fqdn:%s, wait one second", pInfo->nodeFqdn); sError("failed to resolve ipv4 addr, fqdn:%s, wait one second", pInfo->nodeFqdn);
taosSsleep(1); taosSsleep(1);
} } else {
else{
break; break;
} }
} }
@ -501,8 +500,7 @@ void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteRepl
int32_t syncSnapInfoDataRealloc(SSnapshot* pSnap, int32_t size) { int32_t syncSnapInfoDataRealloc(SSnapshot* pSnap, int32_t size) {
void* data = taosMemoryRealloc(pSnap->data, size); void* data = taosMemoryRealloc(pSnap->data, size);
if (data == NULL) { if (data == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; return terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
} }
pSnap->data = data; pSnap->data = data;
return 0; return 0;

View File

@ -70,7 +70,7 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb, i
ret = taosMulModeMkDir(dbname, 0755, false); ret = taosMulModeMkDir(dbname, 0755, false);
if (ret < 0) { if (ret < 0) {
return TAOS_SYSTEM_ERROR(ret); return terrno;
} }
#ifdef USE_MAINDB #ifdef USE_MAINDB

View File

@ -103,7 +103,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
tstrncpy(pWal->path, path, sizeof(pWal->path)); tstrncpy(pWal->path, path, sizeof(pWal->path));
if (taosMkDir(pWal->path) != 0) { if (taosMkDir(pWal->path) != 0) {
wError("vgId:%d, path:%s, failed to create directory since %s", pWal->cfg.vgId, pWal->path, strerror(errno)); wError("vgId:%d, path:%s, failed to create directory since %s", pWal->cfg.vgId, pWal->path, tstrerror(terrno));
goto _err; goto _err;
} }

View File

@ -44,7 +44,7 @@ int wordexp(char *words, wordexp_t *pwordexp, int flags) {
pwordexp->we_wordc = 1; pwordexp->we_wordc = 1;
pwordexp->we_wordv[0] = pwordexp->wordPos; pwordexp->we_wordv[0] = pwordexp->wordPos;
memset(pwordexp->wordPos, 0, 1025); (void)memset(pwordexp->wordPos, 0, 1025);
if (_fullpath(pwordexp->wordPos, words, 1024) == NULL) { if (_fullpath(pwordexp->wordPos, words, 1024) == NULL) {
pwordexp->we_wordv[0] = words; pwordexp->we_wordv[0] = words;
printf("failed to parse relative path:%s to abs path\n", words); printf("failed to parse relative path:%s to abs path\n", words);
@ -100,7 +100,7 @@ void taosRemoveDir(const char *dirname) {
if (strcmp(taosGetDirEntryName(de), ".") == 0 || strcmp(taosGetDirEntryName(de), "..") == 0) continue; if (strcmp(taosGetDirEntryName(de), ".") == 0 || strcmp(taosGetDirEntryName(de), "..") == 0) continue;
char filename[1024] = {0}; char filename[1024] = {0};
snprintf(filename, sizeof(filename), "%s%s%s", dirname, TD_DIRSEP, taosGetDirEntryName(de)); (void)snprintf(filename, sizeof(filename), "%s%s%s", dirname, TD_DIRSEP, taosGetDirEntryName(de));
if (taosDirEntryIsDir(de)) { if (taosDirEntryIsDir(de)) {
taosRemoveDir(filename); taosRemoveDir(filename);
} else { } else {
@ -109,8 +109,8 @@ void taosRemoveDir(const char *dirname) {
} }
} }
taosCloseDir(&pDir); (void)taosCloseDir(&pDir);
rmdir(dirname); (void)rmdir(dirname);
// printf("dir:%s is removed\n", dirname); // printf("dir:%s is removed\n", dirname);
return; return;
@ -127,8 +127,13 @@ int32_t taosMkDir(const char *dirname) {
#else #else
int32_t code = mkdir(dirname, 0755); int32_t code = mkdir(dirname, 0755);
#endif #endif
if (code < 0 && errno == EEXIST) { if (-1 == code) {
if (errno == EEXIST) {
return 0; return 0;
} else {
terrno = TAOS_SYSTEM_ERROR(errno);
code = terrno;
}
} }
return code; return code;
@ -143,7 +148,7 @@ int32_t taosMulMkDir(const char *dirname) {
taosRealPath(dirname, temp, sizeof(temp)); taosRealPath(dirname, temp, sizeof(temp));
if (temp[1] == ':') pos += 3; if (temp[1] == ':') pos += 3;
#else #else
strcpy(temp, dirname); (void)strcpy(temp, dirname);
#endif #endif
if (taosDirExist(temp)) return code; if (taosDirExist(temp)) return code;
@ -165,7 +170,7 @@ int32_t taosMulMkDir(const char *dirname) {
code = mkdir(temp, 0755); code = mkdir(temp, 0755);
#endif #endif
if (code < 0 && errno != EEXIST) { if (code < 0 && errno != EEXIST) {
// terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return code; return code;
} }
*pos = TD_DIRSEP[0]; *pos = TD_DIRSEP[0];
@ -181,7 +186,7 @@ int32_t taosMulMkDir(const char *dirname) {
code = mkdir(temp, 0755); code = mkdir(temp, 0755);
#endif #endif
if (code < 0 && errno != EEXIST) { if (code < 0 && errno != EEXIST) {
// terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return code; return code;
} }
} }
@ -194,7 +199,10 @@ int32_t taosMulMkDir(const char *dirname) {
} }
int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) { int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return -1; if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) {
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
char temp[TDDIRMAXLEN]; char temp[TDDIRMAXLEN];
char *pos = temp; char *pos = temp;
int32_t code = 0; int32_t code = 0;
@ -202,14 +210,18 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
taosRealPath(dirname, temp, sizeof(temp)); taosRealPath(dirname, temp, sizeof(temp));
if (temp[1] == ':') pos += 3; if (temp[1] == ':') pos += 3;
#else #else
strcpy(temp, dirname); (void)strcpy(temp, dirname);
#endif #endif
if (taosDirExist(temp)) { if (taosDirExist(temp)) {
if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) {
return 0; return 0;
} }
return chmod(temp, mode); code = chmod(temp, mode);
if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
}
} }
if (strncmp(temp, TD_DIRSEP, 1) == 0) { if (strncmp(temp, TD_DIRSEP, 1) == 0) {
@ -229,8 +241,8 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
code = mkdir(temp, mode); code = mkdir(temp, mode);
#endif #endif
if (code < 0 && errno != EEXIST) { if (code < 0 && errno != EEXIST) {
// terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return code; return terrno;
} }
*pos = TD_DIRSEP[0]; *pos = TD_DIRSEP[0];
} }
@ -245,8 +257,8 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
code = mkdir(temp, mode); code = mkdir(temp, mode);
#endif #endif
if (code < 0 && errno != EEXIST) { if (code < 0 && errno != EEXIST) {
// terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return code; return terrno;
} }
} }
@ -254,10 +266,14 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) {
return 0; return 0;
} }
return chmod(temp, mode);
} }
return chmod(temp, mode); code = chmod(temp, mode);
if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
}
return code;
} }
void taosRemoveOldFiles(const char *dirname, int32_t keepDays) { void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
@ -271,7 +287,7 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
if (strcmp(taosGetDirEntryName(de), ".") == 0 || strcmp(taosGetDirEntryName(de), "..") == 0) continue; if (strcmp(taosGetDirEntryName(de), ".") == 0 || strcmp(taosGetDirEntryName(de), "..") == 0) continue;
char filename[1024]; char filename[1024];
snprintf(filename, sizeof(filename), "%s/%s", dirname, taosGetDirEntryName(de)); (void)snprintf(filename, sizeof(filename), "%s/%s", dirname, taosGetDirEntryName(de));
if (taosDirEntryIsDir(de)) { if (taosDirEntryIsDir(de)) {
continue; continue;
} else { } else {
@ -299,34 +315,25 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
} }
} }
taosCloseDir(&pDir); (void)taosCloseDir(&pDir);
rmdir(dirname); (void)rmdir(dirname);
} }
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
wordexp_t full_path; wordexp_t full_path;
switch (wordexp(dirname, &full_path, 0)) { int32_t code = wordexp(dirname, &full_path, 0);
switch (code) {
case 0: case 0:
break; break;
case WRDE_NOSPACE: case WRDE_NOSPACE:
wordfree(&full_path); wordfree(&full_path);
// printf("failed to expand path:%s since Out of memory\n", dirname); // FALL THROUGH
return -1;
case WRDE_BADCHAR:
// printf("failed to expand path:%s since illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }\n",
// dirname);
return -1;
case WRDE_SYNTAX:
// printf("failed to expand path:%s since Shell syntax error, such as unbalanced parentheses or unmatched
// quotes\n", dirname);
return -1;
default: default:
// printf("failed to expand path:%s since %s\n", dirname, strerror(errno)); return code;
return -1;
} }
if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
strncpy(outname, full_path.we_wordv[0], maxlen); (void)strncpy(outname, full_path.we_wordv[0], maxlen);
} }
wordfree(&full_path); wordfree(&full_path);
@ -343,21 +350,23 @@ int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) {
#endif #endif
if (strlen(tmp) < maxlen) { if (strlen(tmp) < maxlen) {
if (realPath == NULL) { if (realPath == NULL) {
strncpy(dirname, tmp, maxlen); (void)strncpy(dirname, tmp, maxlen);
} else { } else {
strncpy(realPath, tmp, maxlen); (void)strncpy(realPath, tmp, maxlen);
} }
return 0; return 0;
} }
} }
return -1; terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
} }
bool taosIsDir(const char *dirname) { bool taosIsDir(const char *dirname) {
TdDirPtr pDir = taosOpenDir(dirname); TdDirPtr pDir = taosOpenDir(dirname);
if (pDir != NULL) { if (pDir != NULL) {
taosCloseDir(&pDir); (void)taosCloseDir(&pDir);
return true; return true;
} }
return false; return false;
@ -410,6 +419,7 @@ char *taosDirEntryBaseName(char *name) {
TdDirPtr taosOpenDir(const char *dirname) { TdDirPtr taosOpenDir(const char *dirname) {
if (dirname == NULL) { if (dirname == NULL) {
terrno = TSDB_CODE_INVALID_PARA;
return NULL; return NULL;
} }
@ -436,12 +446,17 @@ TdDirPtr taosOpenDir(const char *dirname) {
dirPtr->pDir = pDir; dirPtr->pDir = pDir;
return dirPtr; return dirPtr;
#else #else
return (TdDirPtr)opendir(dirname); TdDirPtr ptr = (TdDirPtr)opendir(dirname);
if (NULL == ptr) {
terrno = TAOS_SYSTEM_ERROR(errno);
}
return ptr;
#endif #endif
} }
TdDirEntryPtr taosReadDir(TdDirPtr pDir) { TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
if (pDir == NULL) { if (pDir == NULL) {
terrno = TSDB_CODE_INVALID_PARA;
return NULL; return NULL;
} }
#ifdef WINDOWS #ifdef WINDOWS
@ -456,7 +471,13 @@ TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
return NULL; return NULL;
} }
#else #else
return (TdDirEntryPtr)readdir((DIR *)pDir); errno = 0;
terrno = 0;
TdDirEntryPtr p = (TdDirEntryPtr)readdir((DIR *)pDir);
if (NULL == p && errno) {
terrno = TAOS_SYSTEM_ERROR(errno);
}
return p;
#endif #endif
} }
@ -484,7 +505,8 @@ char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) {
int32_t taosCloseDir(TdDirPtr *ppDir) { int32_t taosCloseDir(TdDirPtr *ppDir) {
if (ppDir == NULL || *ppDir == NULL) { if (ppDir == NULL || *ppDir == NULL) {
return -1; terrno = TSDB_CODE_INVALID_PARA;
return terrno;
} }
#ifdef WINDOWS #ifdef WINDOWS
FindClose((*ppDir)->hFind); FindClose((*ppDir)->hFind);
@ -497,8 +519,12 @@ int32_t taosCloseDir(TdDirPtr *ppDir) {
*ppDir = NULL; *ppDir = NULL;
return 0; return 0;
#else #else
closedir((DIR *)*ppDir); int32_t code = closedir((DIR *)*ppDir);
*ppDir = NULL; *ppDir = NULL;
if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
}
return 0; return 0;
#endif #endif
} }

View File

@ -45,11 +45,16 @@ char tsAVX2Supported = 0;
char tsFMASupported = 0; char tsFMASupported = 0;
char tsAVX512Supported = 0; char tsAVX512Supported = 0;
void osDefaultInit() { int32_t osDefaultInit() {
int32_t code = TSDB_CODE_SUCCESS;
taosSeedRand(taosSafeRand()); taosSeedRand(taosSafeRand());
taosGetSystemLocale(tsLocale, tsCharset); taosGetSystemLocale(tsLocale, tsCharset);
taosGetSystemTimezone(tsTimezoneStr, &tsTimezone); taosGetSystemTimezone(tsTimezoneStr, &tsTimezone);
taosSetSystemTimezone(tsTimezoneStr, tsTimezoneStr, &tsDaylight, &tsTimezone); code = taosSetSystemTimezone(tsTimezoneStr, tsTimezoneStr, &tsDaylight, &tsTimezone);
if (code) {
return code;
}
taosGetSystemInfo(); taosGetSystemInfo();
// deadlock in query // deadlock in query
@ -65,33 +70,35 @@ void osDefaultInit() {
tmpDir = getenv("temp"); tmpDir = getenv("temp");
} }
if (tmpDir != NULL) { if (tmpDir != NULL) {
strcpy(tsTempDir, tmpDir); (void)strcpy(tsTempDir, tmpDir);
} }
strcpy(tsOsName, "Windows"); (void)strcpy(tsOsName, "Windows");
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
strcpy(tsOsName, "Darwin"); (void)strcpy(tsOsName, "Darwin");
#else #else
strcpy(tsOsName, "Linux"); (void)strcpy(tsOsName, "Linux");
#endif #endif
if (configDir[0] == 0) { if (configDir[0] == 0) {
strcpy(configDir, TD_CFG_DIR_PATH); (void)strcpy(configDir, TD_CFG_DIR_PATH);
} }
strcpy(tsDataDir, TD_DATA_DIR_PATH); (void)strcpy(tsDataDir, TD_DATA_DIR_PATH);
strcpy(tsLogDir, TD_LOG_DIR_PATH); (void)strcpy(tsLogDir, TD_LOG_DIR_PATH);
if(strlen(tsTempDir) == 0){ if(strlen(tsTempDir) == 0){
strcpy(tsTempDir, TD_TMP_DIR_PATH); (void)strcpy(tsTempDir, TD_TMP_DIR_PATH);
} }
return code;
} }
void osUpdate() { void osUpdate() {
if (tsLogDir[0] != 0) { if (tsLogDir[0] != 0) {
taosGetDiskSize(tsLogDir, &tsLogSpace.size); (void)taosGetDiskSize(tsLogDir, &tsLogSpace.size);
} }
if (tsDataDir[0] != 0) { if (tsDataDir[0] != 0) {
taosGetDiskSize(tsDataDir, &tsDataSpace.size); (void)taosGetDiskSize(tsDataDir, &tsDataSpace.size);
} }
if (tsTempDir[0] != 0) { if (tsTempDir[0] != 0) {
taosGetDiskSize(tsTempDir, &tsTempSpace.size); (void)taosGetDiskSize(tsTempDir, &tsTempSpace.size);
} }
} }
@ -109,11 +116,11 @@ bool osDataSpaceSufficient() { return tsDataSpace.size.avail > tsDataSpace.reser
bool osTempSpaceSufficient() { return tsTempSpace.size.avail > tsTempSpace.reserved; } bool osTempSpaceSufficient() { return tsTempSpace.size.avail > tsTempSpace.reserved; }
void osSetTimezone(const char *tz) { taosSetSystemTimezone(tz, tsTimezoneStr, &tsDaylight, &tsTimezone); } int32_t osSetTimezone(const char *tz) { return taosSetSystemTimezone(tz, tsTimezoneStr, &tsDaylight, &tsTimezone); }
void osSetSystemLocale(const char *inLocale, const char *inCharSet) { void osSetSystemLocale(const char *inLocale, const char *inCharSet) {
memcpy(tsLocale, inLocale, strlen(inLocale) + 1); (void)memcpy(tsLocale, inLocale, strlen(inLocale) + 1);
memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1); (void)memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1);
} }
void osSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; } void osSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; }

View File

@ -90,24 +90,24 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, cha
char tmpPath[PATH_MAX]; char tmpPath[PATH_MAX];
int32_t len = strlen(inputTmpDir); int32_t len = strlen(inputTmpDir);
memcpy(tmpPath, inputTmpDir, len); (void)memcpy(tmpPath, inputTmpDir, len);
static uint64_t seqId = 0; static uint64_t seqId = 0;
if (tmpPath[len - 1] != '/') { if (tmpPath[len - 1] != '/') {
tmpPath[len++] = '/'; tmpPath[len++] = '/';
} }
strcpy(tmpPath + len, TD_TMP_FILE_PREFIX); (void)strcpy(tmpPath + len, TD_TMP_FILE_PREFIX);
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) { if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
strcat(tmpPath, fileNamePrefix); (void)strcat(tmpPath, fileNamePrefix);
strcat(tmpPath, "-%d-%s"); (void)strcat(tmpPath, "-%d-%s");
} }
char rand[32] = {0}; char rand[32] = {0};
sprintf(rand, "%" PRIu64, atomic_add_fetch_64(&seqId, 1)); (void)sprintf(rand, "%" PRIu64, atomic_add_fetch_64(&seqId, 1));
snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand); (void)snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand);
#endif #endif
} }
@ -123,41 +123,60 @@ int64_t taosCopyFile(const char *from, const char *to) {
char buffer[4096]; char buffer[4096];
int64_t size = 0; int64_t size = 0;
int64_t bytes; int64_t bytes;
int32_t code = TSDB_CODE_SUCCESS;
// fidfrom = open(from, O_RDONLY); // fidfrom = open(from, O_RDONLY);
TdFilePtr pFileFrom = taosOpenFile(from, TD_FILE_READ); TdFilePtr pFileFrom = taosOpenFile(from, TD_FILE_READ);
if (pFileFrom == NULL) goto _err; if (pFileFrom == NULL) {
code = terrno;
goto _err;
}
// fidto = open(to, O_WRONLY | O_CREAT | O_EXCL, 0755); // fidto = open(to, O_WRONLY | O_CREAT | O_EXCL, 0755);
TdFilePtr pFileTo = taosOpenFile(to, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_EXCL); TdFilePtr pFileTo = taosOpenFile(to, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_EXCL);
if (pFileTo == NULL) goto _err; if (pFileTo == NULL) {
code = terrno;
goto _err;
}
while (true) { while (true) {
bytes = taosReadFile(pFileFrom, buffer, sizeof(buffer)); bytes = taosReadFile(pFileFrom, buffer, sizeof(buffer));
if (bytes < 0) goto _err; if (bytes < 0) {
code = terrno;
goto _err;
}
if (bytes == 0) break; if (bytes == 0) break;
size += bytes; size += bytes;
if (taosWriteFile(pFileTo, (void *)buffer, bytes) < bytes) goto _err; if (taosWriteFile(pFileTo, (void *)buffer, bytes) < bytes) {
code = terrno;
goto _err;
}
if (bytes < sizeof(buffer)) break; if (bytes < sizeof(buffer)) break;
} }
int code = taosFsyncFile(pFileTo); code = taosFsyncFile(pFileTo);
taosCloseFile(&pFileFrom); (void)taosCloseFile(&pFileFrom);
taosCloseFile(&pFileTo); (void)taosCloseFile(&pFileTo);
if (code != 0) { if (code != 0) {
terrno = code;
return -1; return -1;
} }
return size; return size;
_err: _err:
if (pFileFrom != NULL) taosCloseFile(&pFileFrom);
if (pFileTo != NULL) taosCloseFile(&pFileTo); if (pFileFrom != NULL) (void)taosCloseFile(&pFileFrom);
if (pFileTo != NULL) (void)taosCloseFile(&pFileTo);
/* coverity[+retval] */ /* coverity[+retval] */
taosRemoveFile(to); (void)taosRemoveFile(to);
terrno = code;
return -1; return -1;
#endif #endif
} }
@ -165,24 +184,31 @@ _err:
TdFilePtr taosCreateFile(const char *path, int32_t tdFileOptions) { TdFilePtr taosCreateFile(const char *path, int32_t tdFileOptions) {
TdFilePtr fp = taosOpenFile(path, tdFileOptions); TdFilePtr fp = taosOpenFile(path, tdFileOptions);
if (!fp) { if (!fp) {
if (errno == ENOENT) { if (terrno == TAOS_SYSTEM_ERROR(ENOENT)) {
// Try to create directory recursively // Try to create directory recursively
char *s = taosStrdup(path); char s[PATH_MAX];
tstrncpy(s, path, sizeof(s));
if (taosMulMkDir(taosDirName(s)) != 0) { if (taosMulMkDir(taosDirName(s)) != 0) {
taosMemoryFree(s);
return NULL; return NULL;
} }
taosMemoryFree(s);
fp = taosOpenFile(path, tdFileOptions); fp = taosOpenFile(path, tdFileOptions);
if (!fp) { if (!fp) {
return NULL; return NULL;
} }
} }
} }
return fp; return fp;
} }
int32_t taosRemoveFile(const char *path) { return remove(path); } int32_t taosRemoveFile(const char *path) {
int32_t code = remove(path);
if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
}
return code;
}
int32_t taosRenameFile(const char *oldName, const char *newName) { int32_t taosRenameFile(const char *oldName, const char *newName) {
#ifdef WINDOWS #ifdef WINDOWS
@ -214,8 +240,9 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
return finished ? 0 : -1; return finished ? 0 : -1;
#else #else
int32_t code = rename(oldName, newName); int32_t code = rename(oldName, newName);
if (code < 0) { if (-1 == code) {
printf("failed to rename file %s to %s, reason:%s\n", oldName, newName, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
} }
return code; return code;
@ -230,8 +257,9 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime, int32_t *a
struct stat fileStat; struct stat fileStat;
int32_t code = stat(path, &fileStat); int32_t code = stat(path, &fileStat);
#endif #endif
if (code < 0) { if (-1 == code) {
return code; terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
} }
if (size != NULL) { if (size != NULL) {
@ -269,13 +297,15 @@ int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) {
#else #else
if (pFile == NULL || pFile->fd < 0) { if (pFile == NULL || pFile->fd < 0) {
return TSDB_CODE_INVALID_PARA; terrno = TSDB_CODE_INVALID_PARA;
return terrno;
} }
struct stat fileStat; struct stat fileStat;
int32_t code = fstat(pFile->fd, &fileStat); int32_t code = fstat(pFile->fd, &fileStat);
if (code < 0) { if (-1 == code) {
printf("taosFStatFile run fstat fail."); terrno = TAOS_SYSTEM_ERROR(errno);
return TAOS_SYSTEM_ERROR(errno); return terrno;
} }
if (stDev != NULL) { if (stDev != NULL) {
@ -301,11 +331,15 @@ FILE *taosOpenFileForStream(const char *path, int32_t tdFileOptions) {
} else { } else {
mode = (tdFileOptions & TD_FILE_TEXT) ? "rt+" : "rb+"; mode = (tdFileOptions & TD_FILE_TEXT) ? "rt+" : "rb+";
} }
ASSERT(!(tdFileOptions & TD_FILE_EXCL));
if (tdFileOptions & TD_FILE_EXCL) { if (tdFileOptions & TD_FILE_EXCL) {
terrno = TSDB_CODE_INVALID_PARA;
return NULL; return NULL;
} }
return fopen(path, mode); FILE* f = fopen(path, mode);
if (NULL == f) {
terrno = TAOS_SYSTEM_ERROR(errno);
}
return f;
} }
#ifdef WINDOWS #ifdef WINDOWS
@ -653,6 +687,9 @@ int taosOpenFileNotStream(const char *path, int32_t tdFileOptions) {
access |= (tdFileOptions & TD_FILE_CLOEXEC) ? O_CLOEXEC : 0; access |= (tdFileOptions & TD_FILE_CLOEXEC) ? O_CLOEXEC : 0;
int fd = open(path, access, S_IRWXU | S_IRWXG | S_IRWXO); int fd = open(path, access, S_IRWXU | S_IRWXG | S_IRWXO);
if (-1 == fd) {
terrno = TAOS_SYSTEM_ERROR(errno);
}
return fd; return fd;
} }
@ -1060,14 +1097,14 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
#ifdef WINDOWS #ifdef WINDOWS
if (hFile != NULL) CloseHandle(hFile); if (hFile != NULL) CloseHandle(hFile);
#else #else
if (fd >= 0) close(fd); if (fd >= 0) (void)close(fd);
#endif #endif
if (fp != NULL) fclose(fp); if (fp != NULL) (void)fclose(fp);
return NULL; return NULL;
} }
#if FILE_WITH_LOCK #if FILE_WITH_LOCK
taosThreadRwlockInit(&(pFile->rwlock), NULL); (void)taosThreadRwlockInit(&(pFile->rwlock), NULL);
#endif #endif
pFile->fp = fp; pFile->fp = fp;
pFile->refId = 0; pFile->refId = 0;
@ -1082,9 +1119,15 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
// Remove it instantly, so when the program exits normally/abnormally, the file // Remove it instantly, so when the program exits normally/abnormally, the file
// will be automatically remove by OS. // will be automatically remove by OS.
if (tdFileOptions & TD_FILE_AUTO_DEL) { if (tdFileOptions & TD_FILE_AUTO_DEL) {
unlink(path); if (-1 == unlink(path)) {
terrno = TAOS_SYSTEM_ERROR(errno);
(void)close(fd);
taosMemoryFree(pFile);
return NULL;
}
} }
#endif #endif
return pFile; return pFile;
} }
@ -1094,11 +1137,11 @@ int32_t taosCloseFile(TdFilePtr *ppFile) {
return 0; return 0;
} }
#if FILE_WITH_LOCK #if FILE_WITH_LOCK
taosThreadRwlockWrlock(&((*ppFile)->rwlock)); (void)taosThreadRwlockWrlock(&((*ppFile)->rwlock));
#endif #endif
if ((*ppFile)->fp != NULL) { if ((*ppFile)->fp != NULL) {
fflush((*ppFile)->fp); (void)fflush((*ppFile)->fp);
fclose((*ppFile)->fp); (void)fclose((*ppFile)->fp);
(*ppFile)->fp = NULL; (*ppFile)->fp = NULL;
} }
#ifdef WINDOWS #ifdef WINDOWS
@ -1113,16 +1156,20 @@ int32_t taosCloseFile(TdFilePtr *ppFile) {
// warning: never fsync silently in base lib // warning: never fsync silently in base lib
/*fsync((*ppFile)->fd);*/ /*fsync((*ppFile)->fd);*/
code = close((*ppFile)->fd); code = close((*ppFile)->fd);
if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);
}
(*ppFile)->fd = -1; (*ppFile)->fd = -1;
#endif #endif
} }
(*ppFile)->refId = 0; (*ppFile)->refId = 0;
#if FILE_WITH_LOCK #if FILE_WITH_LOCK
taosThreadRwlockUnlock(&((*ppFile)->rwlock)); (void)taosThreadRwlockUnlock(&((*ppFile)->rwlock));
taosThreadRwlockDestroy(&((*ppFile)->rwlock)); (void)taosThreadRwlockDestroy(&((*ppFile)->rwlock));
#endif #endif
taosMemoryFree(*ppFile); taosMemoryFree(*ppFile);
*ppFile = NULL; *ppFile = NULL;
return code; return code;
} }
@ -1131,6 +1178,8 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
return 0; return 0;
} }
int32_t code = 0;
#ifdef WINDOWS #ifdef WINDOWS
#if FILE_WITH_LOCK #if FILE_WITH_LOCK
taosThreadRwlockRdlock(&(pFile->rwlock)); taosThreadRwlockRdlock(&(pFile->rwlock));
@ -1155,20 +1204,27 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
} }
#else #else
#if FILE_WITH_LOCK #if FILE_WITH_LOCK
taosThreadRwlockRdlock(&(pFile->rwlock)); (void)taosThreadRwlockRdlock(&(pFile->rwlock));
#endif #endif
ASSERT(pFile->fd >= 0); // Please check if you have closed the file. ASSERT(pFile->fd >= 0); // Please check if you have closed the file.
if (pFile->fd < 0) { if (pFile->fd < 0) {
#if FILE_WITH_LOCK #if FILE_WITH_LOCK
taosThreadRwlockUnlock(&(pFile->rwlock)); (void)taosThreadRwlockUnlock(&(pFile->rwlock));
#endif #endif
terrno = TSDB_CODE_INVALID_PARA;
return -1; return -1;
} }
int64_t ret = pread(pFile->fd, buf, count, offset); int64_t ret = pread(pFile->fd, buf, count, offset);
if (-1 == ret) {
code = TAOS_SYSTEM_ERROR(errno);
}
#endif #endif
#if FILE_WITH_LOCK #if FILE_WITH_LOCK
taosThreadRwlockUnlock(&(pFile->rwlock)); (void)taosThreadRwlockUnlock(&(pFile->rwlock));
#endif #endif
terrno = code;
return ret; return ret;
} }
@ -1177,20 +1233,36 @@ int32_t taosFsyncFile(TdFilePtr pFile) {
return 0; return 0;
} }
int32_t code = 0;
// this implementation is WRONG // this implementation is WRONG
// fflush is not a replacement of fsync // fflush is not a replacement of fsync
if (pFile->fp != NULL) return fflush(pFile->fp); if (pFile->fp != NULL) {
code = fflush(pFile->fp);
if (0 != code) {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
}
return code;
}
#ifdef WINDOWS #ifdef WINDOWS
if (pFile->hFile != NULL) { if (pFile->hFile != NULL) {
if (pFile->tdFileOptions & TD_FILE_WRITE_THROUGH) { if (pFile->tdFileOptions & TD_FILE_WRITE_THROUGH) {
return 0; return 0;
} }
return !FlushFileBuffers(pFile->hFile); return !FlushFileBuffers(pFile->hFile);
}
#else #else
if (pFile->fd >= 0) { if (pFile->fd >= 0) {
return fsync(pFile->fd); code = fsync(pFile->fd);
#endif if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
} }
}
#endif
return 0; return 0;
} }

View File

@ -186,7 +186,7 @@ static void print_line(Dwarf_Debug dbg, Dwarf_Line line, Dwarf_Addr pc) {
dwarf_linesrc(line, &linesrc, NULL); dwarf_linesrc(line, &linesrc, NULL);
dwarf_lineno(line, &lineno, NULL); dwarf_lineno(line, &lineno, NULL);
} }
printf("BackTrace %08" PRId64 " %s:%" DW_PR_DUu "\n", taosGetSelfPthreadId(), linesrc, lineno); (void)printf("BackTrace %08" PRId64 " %s:%" DW_PR_DUu "\n", taosGetSelfPthreadId(), linesrc, lineno);
if (line) dwarf_dealloc(dbg, linesrc, DW_DLA_STRING); if (line) dwarf_dealloc(dbg, linesrc, DW_DLA_STRING);
} }
void taosPrintBackTrace() { void taosPrintBackTrace() {
@ -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 (NULL == 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 (NULL == 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 (size > 0 && NULL == p) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
}
return p;
#endif #endif
} }
@ -330,7 +342,12 @@ char *taosStrdup(const char *ptr) {
return (char *)tmp + sizeof(TdMemoryInfo); return (char *)tmp + sizeof(TdMemoryInfo);
#else #else
return tstrdup(ptr); char* p = tstrdup(ptr);
if (ptr != NULL && NULL == p) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
}
return p;
#endif #endif
} }
@ -357,8 +374,7 @@ int64_t taosMemorySize(void *ptr) {
TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char *)ptr - sizeof(TdMemoryInfo)); TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char *)ptr - sizeof(TdMemoryInfo));
ASSERT(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL); ASSERT(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL);
if (pTdMemoryInfo->symbol != TD_MEMORY_SYMBOL) { if (pTdMemoryInfo->symbol != TD_MEMORY_SYMBOL) {
+return NULL; return NULL;
+
} }
return pTdMemoryInfo->memorySize; return pTdMemoryInfo->memorySize;
@ -378,7 +394,7 @@ void taosMemoryTrim(int32_t size) {
// do nothing // do nothing
return; return;
#else #else
malloc_trim(size); (void)malloc_trim(size);
#endif #endif
} }
@ -388,6 +404,13 @@ void *taosMemoryMallocAlign(uint32_t alignment, int64_t size) {
#else #else
#if defined(LINUX) #if defined(LINUX)
void *p = memalign(alignment, size); void *p = memalign(alignment, size);
if (NULL == p) {
if (ENOMEM == errno) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
} else {
terrno = TAOS_SYSTEM_ERROR(errno);
}
}
return p; return p;
#else #else
return taosMemoryMalloc(size); return taosMemoryMalloc(size);

View File

@ -69,7 +69,7 @@ uint32_t taosSafeRand(void) {
if (len < 0) { if (len < 0) {
seed = (int)taosGetTimestampSec(); seed = (int)taosGetTimestampSec();
} }
taosCloseFile(&pFile); (void)taosCloseFile(&pFile);
} }
return (uint32_t)seed; return (uint32_t)seed;

View File

@ -26,7 +26,9 @@ void taosSsleep(int32_t s) {
#ifdef WINDOWS #ifdef WINDOWS
Sleep(1000 * s); Sleep(1000 * s);
#else #else
sleep(s); while (s > 0) {
s = sleep(s);
}
#endif #endif
} }
@ -35,7 +37,7 @@ void taosMsleep(int32_t ms) {
#ifdef WINDOWS #ifdef WINDOWS
Sleep(ms); Sleep(ms);
#else #else
usleep(ms * 1000); (void)usleep(ms * 1000);
#endif #endif
} }
@ -51,6 +53,6 @@ void taosUsleep(int32_t us) {
WaitForSingleObject(timer, INFINITE); WaitForSingleObject(timer, INFINITE);
CloseHandle(timer); CloseHandle(timer);
#else #else
usleep(us); (void)usleep(us);
#endif #endif
} }

View File

@ -345,6 +345,7 @@ char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) {
} }
int32_t taosGetTimeOfDay(struct timeval *tv) { int32_t taosGetTimeOfDay(struct timeval *tv) {
int32_t code = 0;
#ifdef WINDOWS #ifdef WINDOWS
LARGE_INTEGER t; LARGE_INTEGER t;
FILETIME f; FILETIME f;
@ -359,11 +360,18 @@ int32_t taosGetTimeOfDay(struct timeval *tv) {
tv->tv_usec = (t.QuadPart % 10000000) / 10; tv->tv_usec = (t.QuadPart % 10000000) / 10;
return 0; return 0;
#else #else
return gettimeofday(tv, NULL); code = gettimeofday(tv, NULL);
return (-1 == code) ? (terrno = TAOS_SYSTEM_ERROR(errno)) : 0;
#endif #endif
} }
time_t taosTime(time_t *t) { return time(t); } time_t taosTime(time_t *t) {
time_t r = time(t);
if (r == (time_t)-1) {
terrno = TAOS_SYSTEM_ERROR(errno);
}
return r;
}
/* /*
* mktime64 - Converts date to seconds. * mktime64 - Converts date to seconds.
@ -458,7 +466,11 @@ time_t taosMktime(struct tm *timep) {
timep->tm_sec, tz); timep->tm_sec, tz);
#endif #endif
#else #else
return mktime(timep); time_t r = mktime(timep);
if (r == (time_t)-1) {
terrno = TAOS_SYSTEM_ERROR(errno);
}
return r;
#endif #endif
} }
@ -470,7 +482,7 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf) {
if (result == NULL) { if (result == NULL) {
res = localtime(timep); res = localtime(timep);
if (res == NULL && buf != NULL) { if (res == NULL && buf != NULL) {
sprintf(buf, "NaN"); (void)sprintf(buf, "NaN");
} }
return res; return res;
} }
@ -528,7 +540,7 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf) {
#else #else
res = localtime_r(timep, result); res = localtime_r(timep, result);
if (res == NULL && buf != NULL) { if (res == NULL && buf != NULL) {
sprintf(buf, "NaN"); (void)sprintf(buf, "NaN");
} }
#endif #endif
return result; return result;
@ -642,6 +654,7 @@ struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst)
int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } int32_t taosGetTimestampSec() { return (int32_t)time(NULL); }
int32_t taosClockGetTime(int clock_id, struct timespec *pTS) { int32_t taosClockGetTime(int clock_id, struct timespec *pTS) {
int32_t code = 0;
#ifdef WINDOWS #ifdef WINDOWS
LARGE_INTEGER t; LARGE_INTEGER t;
FILETIME f; FILETIME f;
@ -656,6 +669,7 @@ int32_t taosClockGetTime(int clock_id, struct timespec *pTS) {
pTS->tv_nsec = (t.QuadPart % 10000000) * 100; pTS->tv_nsec = (t.QuadPart % 10000000) * 100;
return (0); return (0);
#else #else
return clock_gettime(clock_id, pTS); code = clock_gettime(clock_id, pTS);
return (-1 == code) ? (terrno = TAOS_SYSTEM_ERROR(errno)) : 0;
#endif #endif
} }

View File

@ -80,7 +80,7 @@ void taos_block_sigalrm(void) {
static void taosDeleteTimer(void *tharg) { static void taosDeleteTimer(void *tharg) {
timer_t *pTimer = tharg; timer_t *pTimer = tharg;
timer_delete(*pTimer); (void)timer_delete(*pTimer);
} }
static TdThread timerThread; static TdThread timerThread;
@ -90,9 +90,9 @@ static volatile bool stopTimer = false;
static void *taosProcessAlarmSignal(void *tharg) { static void *taosProcessAlarmSignal(void *tharg) {
// Block the signal // Block the signal
sigset_t sigset; sigset_t sigset;
sigemptyset(&sigset); (void)sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM); (void)sigaddset(&sigset, SIGALRM);
sigprocmask(SIG_BLOCK, &sigset, NULL); (void)sigprocmask(SIG_BLOCK, &sigset, NULL);
void (*callback)(int) = tharg; void (*callback)(int) = tharg;
struct sigevent sevent = {{0}}; struct sigevent sevent = {{0}};
@ -110,7 +110,8 @@ static void *taosProcessAlarmSignal(void *tharg) {
sevent.sigev_signo = SIGALRM; sevent.sigev_signo = SIGALRM;
if (timer_create(CLOCK_REALTIME, &sevent, &timerId) == -1) { if (timer_create(CLOCK_REALTIME, &sevent, &timerId) == -1) {
// printf("Failed to create timer"); terrno = TAOS_SYSTEM_ERROR(errno);
return NULL;
} }
taosThreadCleanupPush(taosDeleteTimer, &timerId); taosThreadCleanupPush(taosDeleteTimer, &timerId);
@ -122,15 +123,17 @@ static void *taosProcessAlarmSignal(void *tharg) {
ts.it_interval.tv_sec = 0; ts.it_interval.tv_sec = 0;
ts.it_interval.tv_nsec = 1000000 * MSECONDS_PER_TICK; ts.it_interval.tv_nsec = 1000000 * MSECONDS_PER_TICK;
if (timer_settime(timerId, 0, &ts, NULL)) { if (-1 == timer_settime(timerId, 0, &ts, NULL)) {
// printf("Failed to init timer"); terrno = TAOS_SYSTEM_ERROR(errno);
break; break;
} }
int signo; int signo;
int32_t code = 0;
while (!stopTimer) { while (!stopTimer) {
if (sigwait(&sigset, &signo)) { code = sigwait(&sigset, &signo);
// printf("Failed to wait signal: number %d", signo); if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
continue; continue;
} }
/* //printf("Signal handling: number %d ......\n", signo); */ /* //printf("Signal handling: number %d ......\n", signo); */
@ -178,14 +181,12 @@ int taosInitTimer(void (*callback)(int), int ms) {
#else #else
stopTimer = false; stopTimer = false;
TdThreadAttr tattr; TdThreadAttr tattr;
taosThreadAttrInit(&tattr); (void)taosThreadAttrInit(&tattr);
int code = taosThreadCreate(&timerThread, &tattr, taosProcessAlarmSignal, callback); int code = taosThreadCreate(&timerThread, &tattr, taosProcessAlarmSignal, callback);
taosThreadAttrDestroy(&tattr); (void)taosThreadAttrDestroy(&tattr);
if (code != 0) { if (code != 0) {
// printf("failed to create timer thread"); // printf("failed to create timer thread");
return -1; return TAOS_SYSTEM_ERROR(code);
} else {
// printf("timer thread:0x%08" PRIx64 " is created", taosGetPthreadId(timerThread));
} }
return 0; return 0;
@ -210,7 +211,7 @@ void taosUninitTimer() {
stopTimer = true; stopTimer = true;
// printf("join timer thread:0x%08" PRIx64, taosGetPthreadId(timerThread)); // printf("join timer thread:0x%08" PRIx64, taosGetPthreadId(timerThread));
taosThreadJoin(timerThread, NULL); (void)taosThreadJoin(timerThread, NULL);
#endif #endif
} }

View File

@ -742,12 +742,20 @@ char *tz_win[554][2] = {{"Asia/Shanghai", "China Standard Time"},
static int isdst_now = 0; static int isdst_now = 0;
void taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8_t *outDaylight, int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8_t *outDaylight,
enum TdTimezone *tsTimezone) { enum TdTimezone *tsTimezone) {
if (inTimezoneStr == NULL || inTimezoneStr[0] == 0) return; if (inTimezoneStr == NULL || inTimezoneStr[0] == 0) {
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
int32_t code = TSDB_CODE_SUCCESS;
size_t len = strlen(inTimezoneStr); size_t len = strlen(inTimezoneStr);
char *buf = taosMemoryCalloc(len + 1, 1); if (len >= TD_TIMEZONE_LEN) {
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
char buf[TD_TIMEZONE_LEN] = {0};
for (int32_t i = 0; i < len; i++) { for (int32_t i = 0; i < len; i++) {
if (inTimezoneStr[i] == ' ' || inTimezoneStr[i] == '(') { if (inTimezoneStr[i] == ' ' || inTimezoneStr[i] == '(') {
buf[i] = 0; buf[i] = 0;
@ -813,17 +821,22 @@ void taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8
*outDaylight = isdst_now; *outDaylight = isdst_now;
#else #else
setenv("TZ", buf, 1); code = setenv("TZ", buf, 1);
if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
}
tzset(); tzset();
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR); int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
*tsTimezone = tz; *tsTimezone = tz;
tz += isdst_now; tz += isdst_now;
sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[isdst_now], tz >= 0 ? "+" : "-", abs(tz)); (void)sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[isdst_now], tz >= 0 ? "+" : "-", abs(tz));
*outDaylight = isdst_now; *outDaylight = isdst_now;
#endif #endif
taosMemoryFree(buf); return code;
} }
void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) { void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
@ -914,7 +927,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
{ {
int n = readlink("/etc/localtime", buf, sizeof(buf)-1); int n = readlink("/etc/localtime", buf, sizeof(buf)-1);
if (n < 0) { if (n < 0) {
printf("read /etc/localtime error, reason:%s", strerror(errno)); (void)printf("read /etc/localtime error, reason:%s", strerror(errno));
if (taosCheckExistFile("/etc/timezone")) { if (taosCheckExistFile("/etc/timezone")) {
/* /*
@ -924,7 +937,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
*/ */
time_t tx1 = taosGetTimestampSec(); time_t tx1 = taosGetTimestampSec();
struct tm tm1; struct tm tm1;
taosLocalTime(&tx1, &tm1, NULL); (void)taosLocalTime(&tx1, &tm1, NULL);
/* load time zone string from /etc/timezone */ /* load time zone string from /etc/timezone */
// FILE *f = fopen("/etc/timezone", "r"); // FILE *f = fopen("/etc/timezone", "r");
errno = 0; errno = 0;
@ -933,12 +946,12 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
if (pFile != NULL) { if (pFile != NULL) {
int len = taosReadFile(pFile, buf, 64); int len = taosReadFile(pFile, buf, 64);
if (len < 64 && taosGetErrorFile(pFile)) { if (len < 64 && taosGetErrorFile(pFile)) {
taosCloseFile(&pFile); (void)taosCloseFile(&pFile);
printf("read /etc/timezone error, reason:%s", strerror(errno)); (void)printf("read /etc/timezone error, reason:%s", strerror(errno));
return; return;
} }
taosCloseFile(&pFile); (void)taosCloseFile(&pFile);
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = 0;
char *lineEnd = strstr(buf, "\n"); char *lineEnd = strstr(buf, "\n");
@ -948,7 +961,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
// for CentOS system, /etc/timezone does not exist. Ignore the TZ environment variables // for CentOS system, /etc/timezone does not exist. Ignore the TZ environment variables
if (strlen(buf) > 0) { if (strlen(buf) > 0) {
setenv("TZ", buf, 1); (void)setenv("TZ", buf, 1);
} }
} }
// get and set default timezone // get and set default timezone
@ -970,10 +983,10 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
* Asia/Shanghai (CST, +0800) * Asia/Shanghai (CST, +0800)
* Europe/London (BST, +0100) * Europe/London (BST, +0100)
*/ */
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", (void)snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-",
abs(tz)); abs(tz));
} else { } else {
printf("There is not /etc/timezone.\n"); (void)printf("There is not /etc/timezone.\n");
} }
return; return;
} }
@ -981,7 +994,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
char *zi = strstr(buf, "zoneinfo"); char *zi = strstr(buf, "zoneinfo");
if (!zi) { if (!zi) {
printf("parsing /etc/localtime failed"); (void)printf("parsing /etc/localtime failed");
return; return;
} }
tz = zi + strlen("zoneinfo") + 1; tz = zi + strlen("zoneinfo") + 1;
@ -1000,7 +1013,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
// return; // return;
// } // }
setenv("TZ", tz, 1); (void)setenv("TZ", tz, 1);
tzset(); tzset();
} }
@ -1011,7 +1024,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
*/ */
time_t tx1 = taosGetTimestampSec(); time_t tx1 = taosGetTimestampSec();
struct tm tm1; struct tm tm1;
taosLocalTime(&tx1, &tm1, NULL); (void)taosLocalTime(&tx1, &tm1, NULL);
isdst_now = tm1.tm_isdst; isdst_now = tm1.tm_isdst;
/* /*
@ -1020,7 +1033,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
* Asia/Shanghai (CST, +0800) * Asia/Shanghai (CST, +0800)
* Europe/London (BST, +0100) * Europe/London (BST, +0100)
*/ */
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %+03ld00)", tz, tm1.tm_isdst ? tzname[daylight] : tzname[0], (void)snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %+03ld00)", tz, tm1.tm_isdst ? tzname[daylight] : tzname[0],
-timezone / 3600); -timezone / 3600);
#endif #endif
} }

View File

@ -136,8 +136,7 @@ static int32_t cfgCheckAndSetConf(SConfigItem *pItem, const char *conf) {
static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) { static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) {
char fullDir[PATH_MAX] = {0}; char fullDir[PATH_MAX] = {0};
if (taosExpandDir(inputDir, fullDir, PATH_MAX) != 0) { if (taosExpandDir(inputDir, fullDir, PATH_MAX) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); uError("failed to expand dir:%s", inputDir);
uError("failed to expand dir:%s since %s", inputDir, terrstr());
return -1; return -1;
} }