Merge pull request #26748 from taosdata/feat/TD-30991-3.0
feat: (errcode) tconfig.c && more for ttime.c/geomFunc.c/geosWrapper.c
This commit is contained in:
commit
c5d1c890af
|
@ -117,7 +117,7 @@ int32_t taosTs2Char(const char* format, SArray** formats, int64_t ts, int32_t pr
|
|||
int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int64_t* ts, int32_t precision, char* errMsg,
|
||||
int32_t errMsgLen);
|
||||
|
||||
void TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* out, int32_t outLen);
|
||||
int32_t TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* out, int32_t outLen);
|
||||
int32_t TEST_char2ts(const char* format, int64_t* ts, int32_t precision, const char* tsStr);
|
||||
|
||||
/// @brief get offset seconds from zero timezone to input timezone
|
||||
|
|
|
@ -101,7 +101,7 @@ typedef struct {
|
|||
typedef struct SConfig SConfig;
|
||||
typedef struct SConfigIter SConfigIter;
|
||||
|
||||
SConfig *cfgInit();
|
||||
int32_t cfgInit(SConfig **ppCfg);
|
||||
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr);
|
||||
int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
|
||||
void cfgCleanup(SConfig *pCfg);
|
||||
|
@ -110,7 +110,7 @@ SConfigItem *cfgGetItem(SConfig *pCfg, const char *pName);
|
|||
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype, bool lock);
|
||||
int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *pVal, bool isServer);
|
||||
|
||||
SConfigIter *cfgCreateIter(SConfig *pConf);
|
||||
int32_t cfgCreateIter(SConfig *pConf, SConfigIter **ppIter);
|
||||
SConfigItem *cfgNextIter(SConfigIter *pIter);
|
||||
void cfgDestroyIter(SConfigIter *pIter);
|
||||
void cfgLock(SConfig *pCfg);
|
||||
|
@ -131,8 +131,8 @@ int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal,
|
|||
const char *cfgStypeStr(ECfgSrcType type);
|
||||
const char *cfgDtypeStr(ECfgDataType type);
|
||||
|
||||
void cfgDumpItemValue(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen);
|
||||
void cfgDumpItemScope(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen);
|
||||
int32_t cfgDumpItemValue(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen);
|
||||
int32_t cfgDumpItemScope(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen);
|
||||
|
||||
void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump);
|
||||
void cfgDumpCfgS3(SConfig *pCfg, bool tsc, bool dump);
|
||||
|
|
|
@ -152,9 +152,9 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
|
||||
#define TCONTAINER_OF(ptr, type, member) ((type *)((char *)(ptr)-offsetof(type, member)))
|
||||
|
||||
#define TAOS_RETURN(code) \
|
||||
#define TAOS_RETURN(CODE) \
|
||||
do { \
|
||||
return (terrno = (code)); \
|
||||
return (terrno = (CODE)); \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_CHECK_RETURN(CMD) \
|
||||
|
|
|
@ -1263,8 +1263,8 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
|||
const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||
if (tsCfg == NULL) osDefaultInit();
|
||||
|
||||
SConfig *pCfg = cfgInit();
|
||||
if (pCfg == NULL) return -1;
|
||||
SConfig *pCfg = NULL;
|
||||
TAOS_CHECK_RETURN(cfgInit(&pCfg));
|
||||
|
||||
if (tsc) {
|
||||
tsLogEmbedded = 0;
|
||||
|
@ -1325,8 +1325,8 @@ int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, const char *
|
|||
SArray *pArgs) {
|
||||
if (tsCfg == NULL) osDefaultInit();
|
||||
|
||||
SConfig *pCfg = cfgInit();
|
||||
if (pCfg == NULL) return -1;
|
||||
SConfig *pCfg = NULL;
|
||||
TAOS_CHECK_RETURN(cfgInit(&pCfg));
|
||||
|
||||
if (cfgAddDir(pCfg, "dataDir", tsDataDir, CFG_SCOPE_SERVER, CFG_DYN_NONE) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1;
|
||||
|
@ -1371,10 +1371,7 @@ static int32_t taosCheckGlobalCfg() {
|
|||
|
||||
static int32_t cfgInitWrapper(SConfig **pCfg) {
|
||||
if (*pCfg == NULL) {
|
||||
*pCfg = cfgInit();
|
||||
if (*pCfg == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
TAOS_CHECK_RETURN(cfgInit(pCfg));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -270,11 +270,7 @@ int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) {
|
|||
|
||||
TAOS_CHECK_GOTO(blockDataEnsureCapacity(pBlock, cfgGetSize(pConf)), NULL, _exit);
|
||||
|
||||
pIter = cfgCreateIter(pConf);
|
||||
if (pIter == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_CHECK_GOTO(code, NULL, _exit);
|
||||
}
|
||||
TAOS_CHECK_GOTO(cfgCreateIter(pConf, &pIter), NULL, _exit);
|
||||
|
||||
cfgLock(pConf);
|
||||
locked = 1;
|
||||
|
@ -296,7 +292,7 @@ int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) {
|
|||
|
||||
char value[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
int32_t valueLen = 0;
|
||||
cfgDumpItemValue(pItem, &value[VARSTR_HEADER_SIZE], TSDB_CONFIG_VALUE_LEN, &valueLen);
|
||||
TAOS_CHECK_GOTO(cfgDumpItemValue(pItem, &value[VARSTR_HEADER_SIZE], TSDB_CONFIG_VALUE_LEN, &valueLen), NULL, _exit);
|
||||
varDataSetLen(value, valueLen);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
|
||||
|
@ -308,7 +304,7 @@ int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) {
|
|||
TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, value, false), NULL, _exit);
|
||||
|
||||
char scope[TSDB_CONFIG_SCOPE_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
cfgDumpItemScope(pItem, &scope[VARSTR_HEADER_SIZE], TSDB_CONFIG_SCOPE_LEN, &valueLen);
|
||||
TAOS_CHECK_GOTO(cfgDumpItemScope(pItem, &scope[VARSTR_HEADER_SIZE], TSDB_CONFIG_SCOPE_LEN, &valueLen), NULL, _exit);
|
||||
varDataSetLen(scope, valueLen);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
|
||||
|
|
|
@ -96,8 +96,6 @@ char* forwardToTimeStringEnd(char* str) {
|
|||
}
|
||||
|
||||
int32_t parseFraction(char* str, char** end, int32_t timePrec, int64_t* pFraction) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
int32_t i = 0;
|
||||
int64_t fraction = 0;
|
||||
|
||||
|
@ -147,8 +145,6 @@ int32_t parseFraction(char* str, char** end, int32_t timePrec, int64_t* pFractio
|
|||
}
|
||||
|
||||
int32_t parseTimezone(char* str, int64_t* tzOffset) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
int64_t hour = 0;
|
||||
|
||||
int32_t i = 0;
|
||||
|
@ -224,8 +220,6 @@ int32_t offsetOfTimezone(char* tzStr, int64_t* offset) {
|
|||
* 2013-04-12T15:52:01.123+0800
|
||||
*/
|
||||
int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, char delim) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
int64_t factor = TSDB_TICK_PER_SECOND(timePrec);
|
||||
int64_t tzOffset = 0;
|
||||
|
||||
|
@ -315,8 +309,6 @@ static FORCE_INLINE bool validateTm(struct tm* pTm) {
|
|||
}
|
||||
|
||||
int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
*utime = 0;
|
||||
struct tm tm = {0};
|
||||
|
||||
|
@ -358,8 +350,6 @@ int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timeP
|
|||
}
|
||||
|
||||
int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
*utime = 0;
|
||||
struct tm tm = {0};
|
||||
tm.tm_isdst = -1;
|
||||
|
@ -484,8 +474,6 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre
|
|||
// !!!!notice: double lose precison if time is too large, for example: 1626006833631000000*1.0 = double =
|
||||
// 1626006833631000064
|
||||
int32_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char toUnit, int64_t* pRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
if (fromPrecision != TSDB_TIME_PRECISION_MILLI && fromPrecision != TSDB_TIME_PRECISION_MICRO &&
|
||||
fromPrecision != TSDB_TIME_PRECISION_NANO) {
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
|
@ -559,13 +547,14 @@ int32_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char
|
|||
}
|
||||
|
||||
int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec, int64_t* timeVal) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
int32_t charLen = varDataLen(inputData);
|
||||
char* newColData;
|
||||
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY) {
|
||||
newColData = taosMemoryCalloc(1, charLen + 1);
|
||||
memcpy(newColData, varDataVal(inputData), charLen);
|
||||
if (NULL == newColData) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
(void)memcpy(newColData, varDataVal(inputData), charLen);
|
||||
int32_t ret = taosParseTime(newColData, timeVal, charLen, (int32_t)timePrec, tsDaylight);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFree(newColData);
|
||||
|
@ -574,6 +563,9 @@ int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec
|
|||
taosMemoryFree(newColData);
|
||||
} else if (type == TSDB_DATA_TYPE_NCHAR) {
|
||||
newColData = taosMemoryCalloc(1, charLen + TSDB_NCHAR_SIZE);
|
||||
if (NULL == newColData) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
int len = taosUcs4ToMbs((TdUcs4*)varDataVal(inputData), charLen, newColData);
|
||||
if (len < 0) {
|
||||
taosMemoryFree(newColData);
|
||||
|
@ -593,8 +585,6 @@ int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec
|
|||
}
|
||||
|
||||
int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
switch (unit) {
|
||||
case 's':
|
||||
if (val > INT64_MAX / MILLISECOND_PER_SECOND) {
|
||||
|
@ -658,8 +648,6 @@ int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecisi
|
|||
*/
|
||||
int32_t parseAbsoluteDuration(const char* token, int32_t tokenlen, int64_t* duration, char* unit,
|
||||
int32_t timePrecision) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
errno = 0;
|
||||
char* endPtr = NULL;
|
||||
|
||||
|
@ -680,8 +668,6 @@ int32_t parseAbsoluteDuration(const char* token, int32_t tokenlen, int64_t* dura
|
|||
|
||||
int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit, int32_t timePrecision,
|
||||
bool negativeAllow) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
errno = 0;
|
||||
|
||||
/* get the basic numeric value */
|
||||
|
@ -718,7 +704,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) {
|
|||
|
||||
struct tm tm;
|
||||
time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision));
|
||||
taosLocalTime(&tt, &tm, NULL);
|
||||
(void)taosLocalTime(&tt, &tm, NULL);
|
||||
int32_t mon = tm.tm_year * 12 + tm.tm_mon + (int32_t)numOfMonth;
|
||||
tm.tm_year = mon / 12;
|
||||
tm.tm_mon = mon % 12;
|
||||
|
@ -779,11 +765,11 @@ int32_t taosTimeCountIntervalForFill(int64_t skey, int64_t ekey, int64_t interva
|
|||
|
||||
struct tm tm;
|
||||
time_t t = (time_t)skey;
|
||||
taosLocalTime(&t, &tm, NULL);
|
||||
(void)taosLocalTime(&t, &tm, NULL);
|
||||
int32_t smon = tm.tm_year * 12 + tm.tm_mon;
|
||||
|
||||
t = (time_t)ekey;
|
||||
taosLocalTime(&t, &tm, NULL);
|
||||
(void)taosLocalTime(&t, &tm, NULL);
|
||||
int32_t emon = tm.tm_year * 12 + tm.tm_mon;
|
||||
|
||||
if (unit == 'y') {
|
||||
|
@ -808,7 +794,7 @@ int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) {
|
|||
start /= (int64_t)(TSDB_TICK_PER_SECOND(precision));
|
||||
struct tm tm;
|
||||
time_t tt = (time_t)start;
|
||||
taosLocalTime(&tt, &tm, NULL);
|
||||
(void)taosLocalTime(&tt, &tm, NULL);
|
||||
tm.tm_sec = 0;
|
||||
tm.tm_min = 0;
|
||||
tm.tm_hour = 0;
|
||||
|
@ -978,8 +964,6 @@ const char* fmtts(int64_t ts) {
|
|||
}
|
||||
|
||||
int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
char ts[40] = {0};
|
||||
struct tm ptm;
|
||||
|
||||
|
@ -1018,7 +1002,7 @@ int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precisio
|
|||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
if (taosLocalTime(", &ptm, buf) == NULL) {
|
||||
if (NULL == taosLocalTime(", &ptm, buf)) {
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
int32_t length = (int32_t)strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", &ptm);
|
||||
|
@ -1032,7 +1016,9 @@ int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precisio
|
|||
int32_t taosTs2Tm(int64_t ts, int32_t precision, struct STm* tm) {
|
||||
tm->fsec = ts % TICK_PER_SECOND[precision] * (TICK_PER_SECOND[TSDB_TIME_PRECISION_NANO] / TICK_PER_SECOND[precision]);
|
||||
time_t t = ts / TICK_PER_SECOND[precision];
|
||||
taosLocalTime(&t, &tm->tm, NULL);
|
||||
if (NULL == taosLocalTime(&t, &tm->tm, NULL)) {
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1344,7 +1330,7 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
TSFormatNode* format = taosArrayGet(formats, i);
|
||||
if (format->type != TS_FORMAT_NODE_TYPE_KEYWORD) {
|
||||
if (s - start + format->len + 1 > outLen) break;
|
||||
strncpy(s, format->c, format->len);
|
||||
(void)strncpy(s, format->c, format->len);
|
||||
s += format->len;
|
||||
continue;
|
||||
}
|
||||
|
@ -1353,37 +1339,37 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
switch (format->key->id) {
|
||||
case TSFKW_AM:
|
||||
case TSFKW_PM:
|
||||
sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "PM" : "AM");
|
||||
(void)sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "PM" : "AM");
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_A_M:
|
||||
case TSFKW_P_M:
|
||||
sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "P.M." : "A.M.");
|
||||
(void)sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "P.M." : "A.M.");
|
||||
s += 4;
|
||||
break;
|
||||
case TSFKW_am:
|
||||
case TSFKW_pm:
|
||||
sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "pm" : "am");
|
||||
(void)sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "pm" : "am");
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_a_m:
|
||||
case TSFKW_p_m:
|
||||
sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "p.m." : "a.m.");
|
||||
(void)sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "p.m." : "a.m.");
|
||||
s += 4;
|
||||
break;
|
||||
case TSFKW_DDD:
|
||||
#ifdef WINDOWS
|
||||
return TSDB_CODE_FUNC_TO_CHAR_NOT_SUPPORTED;
|
||||
#endif
|
||||
sprintf(s, "%03d", tm->tm.tm_yday + 1);
|
||||
(void)sprintf(s, "%03d", tm->tm.tm_yday + 1);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_DD:
|
||||
sprintf(s, "%02d", tm->tm.tm_mday);
|
||||
(void)sprintf(s, "%02d", tm->tm.tm_mday);
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_D:
|
||||
sprintf(s, "%d", tm->tm.tm_wday + 1);
|
||||
(void)sprintf(s, "%d", tm->tm.tm_wday + 1);
|
||||
s += 1;
|
||||
break;
|
||||
case TSFKW_DAY: {
|
||||
|
@ -1391,20 +1377,20 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
const char* wd = weekDays[tm->tm.tm_wday];
|
||||
char buf[10] = {0};
|
||||
for (int32_t i = 0; i < strlen(wd); ++i) buf[i] = toupper(wd[i]);
|
||||
sprintf(s, "%-9s", buf);
|
||||
(void)sprintf(s, "%-9s", buf);
|
||||
s += strlen(s);
|
||||
break;
|
||||
}
|
||||
case TSFKW_Day:
|
||||
// Monday, TuesDay...
|
||||
sprintf(s, "%-9s", weekDays[tm->tm.tm_wday]);
|
||||
(void)sprintf(s, "%-9s", weekDays[tm->tm.tm_wday]);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_day: {
|
||||
const char* wd = weekDays[tm->tm.tm_wday];
|
||||
char buf[10] = {0};
|
||||
for (int32_t i = 0; i < strlen(wd); ++i) buf[i] = tolower(wd[i]);
|
||||
sprintf(s, "%-9s", buf);
|
||||
(void)sprintf(s, "%-9s", buf);
|
||||
s += strlen(s);
|
||||
break;
|
||||
}
|
||||
|
@ -1413,13 +1399,13 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
const char* wd = shortWeekDays[tm->tm.tm_wday];
|
||||
char buf[8] = {0};
|
||||
for (int32_t i = 0; i < strlen(wd); ++i) buf[i] = toupper(wd[i]);
|
||||
sprintf(s, "%3s", buf);
|
||||
(void)sprintf(s, "%3s", buf);
|
||||
s += 3;
|
||||
break;
|
||||
}
|
||||
case TSFKW_Dy:
|
||||
// Mon, Tue
|
||||
sprintf(s, "%3s", shortWeekDays[tm->tm.tm_wday]);
|
||||
(void)sprintf(s, "%3s", shortWeekDays[tm->tm.tm_wday]);
|
||||
s += 3;
|
||||
break;
|
||||
case TSFKW_dy: {
|
||||
|
@ -1427,33 +1413,33 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
const char* wd = shortWeekDays[tm->tm.tm_wday];
|
||||
char buf[8] = {0};
|
||||
for (int32_t i = 0; i < strlen(wd); ++i) buf[i] = tolower(wd[i]);
|
||||
sprintf(s, "%3s", buf);
|
||||
(void)sprintf(s, "%3s", buf);
|
||||
s += 3;
|
||||
break;
|
||||
}
|
||||
case TSFKW_HH24:
|
||||
sprintf(s, "%02d", tm->tm.tm_hour);
|
||||
(void)sprintf(s, "%02d", tm->tm.tm_hour);
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_HH:
|
||||
case TSFKW_HH12:
|
||||
// 0 or 12 o'clock in 24H coresponds to 12 o'clock (AM/PM) in 12H
|
||||
sprintf(s, "%02d", tm->tm.tm_hour % 12 == 0 ? 12 : tm->tm.tm_hour % 12);
|
||||
(void)sprintf(s, "%02d", tm->tm.tm_hour % 12 == 0 ? 12 : tm->tm.tm_hour % 12);
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_MI:
|
||||
sprintf(s, "%02d", tm->tm.tm_min);
|
||||
(void)sprintf(s, "%02d", tm->tm.tm_min);
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_MM:
|
||||
sprintf(s, "%02d", tm->tm.tm_mon + 1);
|
||||
(void)sprintf(s, "%02d", tm->tm.tm_mon + 1);
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_MONTH: {
|
||||
const char* mon = fullMonths[tm->tm.tm_mon];
|
||||
char buf[10] = {0};
|
||||
for (int32_t i = 0; i < strlen(mon); ++i) buf[i] = toupper(mon[i]);
|
||||
sprintf(s, "%-9s", buf);
|
||||
(void)sprintf(s, "%-9s", buf);
|
||||
s += strlen(s);
|
||||
break;
|
||||
}
|
||||
|
@ -1461,44 +1447,44 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
const char* mon = months[tm->tm.tm_mon];
|
||||
char buf[10] = {0};
|
||||
for (int32_t i = 0; i < strlen(mon); ++i) buf[i] = toupper(mon[i]);
|
||||
sprintf(s, "%s", buf);
|
||||
(void)sprintf(s, "%s", buf);
|
||||
s += strlen(s);
|
||||
break;
|
||||
}
|
||||
case TSFKW_Month:
|
||||
sprintf(s, "%-9s", fullMonths[tm->tm.tm_mon]);
|
||||
(void)sprintf(s, "%-9s", fullMonths[tm->tm.tm_mon]);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_month: {
|
||||
const char* mon = fullMonths[tm->tm.tm_mon];
|
||||
char buf[10] = {0};
|
||||
for (int32_t i = 0; i < strlen(mon); ++i) buf[i] = tolower(mon[i]);
|
||||
sprintf(s, "%-9s", buf);
|
||||
(void)sprintf(s, "%-9s", buf);
|
||||
s += strlen(s);
|
||||
break;
|
||||
}
|
||||
case TSFKW_Mon:
|
||||
sprintf(s, "%s", months[tm->tm.tm_mon]);
|
||||
(void)sprintf(s, "%s", months[tm->tm.tm_mon]);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_mon: {
|
||||
const char* mon = months[tm->tm.tm_mon];
|
||||
char buf[10] = {0};
|
||||
for (int32_t i = 0; i < strlen(mon); ++i) buf[i] = tolower(mon[i]);
|
||||
sprintf(s, "%s", buf);
|
||||
(void)sprintf(s, "%s", buf);
|
||||
s += strlen(s);
|
||||
break;
|
||||
}
|
||||
case TSFKW_SS:
|
||||
sprintf(s, "%02d", tm->tm.tm_sec);
|
||||
(void)sprintf(s, "%02d", tm->tm.tm_sec);
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_MS:
|
||||
sprintf(s, "%03" PRId64, tm->fsec / 1000000L);
|
||||
(void)sprintf(s, "%03" PRId64, tm->fsec / 1000000L);
|
||||
s += 3;
|
||||
break;
|
||||
case TSFKW_US:
|
||||
sprintf(s, "%06" PRId64, tm->fsec / 1000L);
|
||||
(void)sprintf(s, "%06" PRId64, tm->fsec / 1000L);
|
||||
s += 6;
|
||||
break;
|
||||
case TSFKW_NS:
|
||||
|
@ -1506,23 +1492,23 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
s += 9;
|
||||
break;
|
||||
case TSFKW_TZH:
|
||||
sprintf(s, "%s%02d", tsTimezone < 0 ? "-" : "+", tsTimezone);
|
||||
(void)sprintf(s, "%s%02d", tsTimezone < 0 ? "-" : "+", tsTimezone);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_YYYY:
|
||||
sprintf(s, "%04d", tm->tm.tm_year + 1900);
|
||||
(void)sprintf(s, "%04d", tm->tm.tm_year + 1900);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_YYY:
|
||||
sprintf(s, "%03d", (tm->tm.tm_year + 1900) % 1000);
|
||||
(void)sprintf(s, "%03d", (tm->tm.tm_year + 1900) % 1000);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_YY:
|
||||
sprintf(s, "%02d", (tm->tm.tm_year + 1900) % 100);
|
||||
(void)sprintf(s, "%02d", (tm->tm.tm_year + 1900) % 100);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_Y:
|
||||
sprintf(s, "%01d", (tm->tm.tm_year + 1900) % 10);
|
||||
(void)sprintf(s, "%01d", (tm->tm.tm_year + 1900) % 10);
|
||||
s += strlen(s);
|
||||
break;
|
||||
default:
|
||||
|
@ -1557,7 +1543,7 @@ static const char* tsFormatStr2Int32(int32_t* dest, const char* str, int32_t len
|
|||
s = last;
|
||||
} else {
|
||||
char buf[16] = {0};
|
||||
strncpy(buf, s, len);
|
||||
(void)strncpy(buf, s, len);
|
||||
int32_t copiedLen = strlen(buf);
|
||||
if (copiedLen < len) {
|
||||
if (!needMoreDigit) {
|
||||
|
@ -1936,10 +1922,13 @@ static int32_t char2ts(const char* s, SArray* formats, int64_t* ts, int32_t prec
|
|||
int32_t taosTs2Char(const char* format, SArray** formats, int64_t ts, int32_t precision, char* out, int32_t outLen) {
|
||||
if (!*formats) {
|
||||
*formats = taosArrayInit(8, sizeof(TSFormatNode));
|
||||
if (!*formats){
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
parseTsFormat(format, *formats);
|
||||
}
|
||||
struct STm tm;
|
||||
taosTs2Tm(ts, precision, &tm);
|
||||
TAOS_CHECK_RETURN(taosTs2Tm(ts, precision, &tm));
|
||||
return tm2char(*formats, &tm, out, outLen);
|
||||
}
|
||||
|
||||
|
@ -1949,6 +1938,9 @@ int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int
|
|||
int32_t fErrIdx;
|
||||
if (!*formats) {
|
||||
*formats = taosArrayInit(4, sizeof(TSFormatNode));
|
||||
if (!*formats) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
parseTsFormat(format, *formats);
|
||||
}
|
||||
int32_t code = char2ts(tsStr, *formats, ts, precision, &sErrPos, &fErrIdx);
|
||||
|
@ -1964,16 +1956,24 @@ int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int
|
|||
snprintf(errMsg, errMsgLen, "timestamp format not supported");
|
||||
code = TSDB_CODE_FUNC_TO_TIMESTAMP_FAILED_NOT_SUPPORTED;
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
void TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* out, int32_t outLen) {
|
||||
int32_t TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* out, int32_t outLen) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
SArray* formats = taosArrayInit(4, sizeof(TSFormatNode));
|
||||
if (!formats) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
parseTsFormat(format, formats);
|
||||
struct STm tm;
|
||||
taosTs2Tm(ts, precision, &tm);
|
||||
tm2char(formats, &tm, out, outLen);
|
||||
TAOS_CHECK_GOTO(taosTs2Tm(ts, precision, &tm), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(tm2char(formats, &tm, out, outLen), NULL, _exit);
|
||||
|
||||
_exit:
|
||||
taosArrayDestroy(formats);
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t TEST_char2ts(const char* format, int64_t* ts, int32_t precision, const char* tsStr) {
|
||||
|
@ -1997,6 +1997,7 @@ static int8_t UNIT_INDEX[26] = {/*a*/ 2, 0, -1, 6, -1, -1, -1,
|
|||
|
||||
#define GET_UNIT_INDEX(idx) UNIT_INDEX[(idx) - 97]
|
||||
|
||||
// clang-format off
|
||||
static int64_t UNIT_MATRIX[10][11] = { /* ns, us, ms, s, min, h, d, w, month, y*/
|
||||
/*ns*/ { 1, 1000, 0},
|
||||
/*us*/ {1000, 1, 1000, 0},
|
||||
|
@ -2008,6 +2009,7 @@ static int64_t UNIT_MATRIX[10][11] = {/* ns, us, ms, s, min, h, d,
|
|||
/*w*/ { 0, 0, 0, 0, 0, 0, 7, 1, -1, 0},
|
||||
/*mon*/ { 0, 0, 0, 0, 0, 0, 0, 0, 1, 12, 0},
|
||||
/*y*/ { 0, 0, 0, 0, 0, 0, 0, 0, 12, 1, 0}};
|
||||
// clang-format on
|
||||
|
||||
static bool recursiveTsmaCheckRecursive(int64_t baseInterval, int8_t baseIdx, int64_t interval, int8_t idx,
|
||||
bool checkEq) {
|
||||
|
|
|
@ -465,7 +465,8 @@ TEST(timeTest, timestamp2tm) {
|
|||
|
||||
void test_ts2char(int64_t ts, const char* format, int32_t precison, const char* expected) {
|
||||
char buf[256] = {0};
|
||||
TEST_ts2char(format, ts, precison, buf, 256);
|
||||
int32_t code = TEST_ts2char(format, ts, precison, buf, 256);
|
||||
ASSERT_EQ(code, 0);
|
||||
printf("ts: %ld format: %s res: [%s], expected: [%s]\n", ts, format, buf, expected);
|
||||
ASSERT_STREQ(expected, buf);
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#include "sclInt.h"
|
||||
#include "sclvector.h"
|
||||
|
||||
typedef int32_t (*_geomDoRelationFunc_t)(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res);
|
||||
typedef int32_t (*_geomDoRelationFunc_t)(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1,
|
||||
const GEOSGeometry *geom2, bool swapped, char *res);
|
||||
|
||||
typedef int32_t (*_geomInitCtxFunc_t)();
|
||||
typedef int32_t (*_geomExecuteOneParamFunc_t)(SColumnInfoData *pInputData, int32_t i, SColumnInfoData *pOutputData);
|
||||
|
@ -47,7 +47,7 @@ int32_t doMakePointFunc(double x, double y, unsigned char **output) {
|
|||
goto _exit;
|
||||
}
|
||||
|
||||
memcpy(varDataVal(*output), outputGeom, size);
|
||||
(void)memcpy(varDataVal(*output), outputGeom, size);
|
||||
varDataSetLen(*output, size);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -77,12 +77,9 @@ int32_t doGeomFromTextFunc(const char *input, unsigned char **output) {
|
|||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
memcpy(inputGeom, varDataVal(input), varDataLen(input));
|
||||
(void)memcpy(inputGeom, varDataVal(input), varDataLen(input));
|
||||
|
||||
code = doGeomFromText(inputGeom, &outputGeom, &size);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(doGeomFromText(inputGeom, &outputGeom, &size), NULL, _exit);
|
||||
|
||||
*output = taosMemoryCalloc(1, size + VARSTR_HEADER_SIZE);
|
||||
if (*output == NULL) {
|
||||
|
@ -90,7 +87,7 @@ int32_t doGeomFromTextFunc(const char *input, unsigned char **output) {
|
|||
goto _exit;
|
||||
}
|
||||
|
||||
memcpy(varDataVal(*output), outputGeom, size);
|
||||
(void)memcpy(varDataVal(*output), outputGeom, size);
|
||||
varDataSetLen(*output, size);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -112,10 +109,7 @@ int32_t doAsTextFunc(unsigned char *input, char **output) {
|
|||
}
|
||||
|
||||
char *outputWKT = NULL;
|
||||
code = doAsText(varDataVal(input), varDataLen(input), &outputWKT);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(doAsText(varDataVal(input), varDataLen(input), &outputWKT), NULL, _exit);
|
||||
|
||||
size_t size = strlen(outputWKT);
|
||||
*output = taosMemoryCalloc(1, size + VARSTR_HEADER_SIZE);
|
||||
|
@ -124,7 +118,7 @@ int32_t doAsTextFunc(unsigned char *input, char **output) {
|
|||
goto _exit;
|
||||
}
|
||||
|
||||
memcpy(varDataVal(*output), outputWKT, size);
|
||||
(void)memcpy(varDataVal(*output), outputWKT, size);
|
||||
varDataSetLen(*output, size);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -145,22 +139,11 @@ int32_t executeMakePointFunc(SColumnInfoData *pInputData[], int32_t iLeft, int32
|
|||
unsigned char *output = NULL;
|
||||
double leftRes = 0;
|
||||
double rightRes = 0;
|
||||
code = getDoubleValueFn[0](pInputData[0]->pData, iLeft, &leftRes);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _exit;
|
||||
}
|
||||
code = getDoubleValueFn[1](pInputData[1]->pData, iRight, &rightRes);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _exit;
|
||||
}
|
||||
code = doMakePointFunc(leftRes, rightRes, &output);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _exit;
|
||||
}
|
||||
code = colDataSetVal(pOutputData, TMAX(iLeft, iRight), output, (output == NULL));
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
TAOS_CHECK_GOTO(getDoubleValueFn[0](pInputData[0]->pData, iLeft, &leftRes), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(getDoubleValueFn[1](pInputData[1]->pData, iRight, &rightRes), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(doMakePointFunc(leftRes, rightRes, &output), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(colDataSetVal(pOutputData, TMAX(iLeft, iRight), output, (output == NULL)), NULL, _exit);
|
||||
|
||||
_exit:
|
||||
if (output) {
|
||||
|
@ -175,12 +158,9 @@ int32_t executeGeomFromTextFunc(SColumnInfoData *pInputData, int32_t i, SColumnI
|
|||
|
||||
char *input = colDataGetData(pInputData, i);
|
||||
unsigned char *output = NULL;
|
||||
code = doGeomFromTextFunc(input, &output);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
code = colDataSetVal(pOutputData, i, output, (output == NULL));
|
||||
TAOS_CHECK_GOTO(doGeomFromTextFunc(input, &output), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(colDataSetVal(pOutputData, i, output, (output == NULL)), NULL, _exit);
|
||||
|
||||
_exit:
|
||||
if (output) {
|
||||
|
@ -195,12 +175,9 @@ int32_t executeAsTextFunc(SColumnInfoData *pInputData, int32_t i, SColumnInfoDat
|
|||
|
||||
unsigned char *input = colDataGetData(pInputData, i);
|
||||
char *output = NULL;
|
||||
code = doAsTextFunc(input, &output);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
code = colDataSetVal(pOutputData, i, output, (output == NULL));
|
||||
TAOS_CHECK_GOTO(doAsTextFunc(input, &output), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(colDataSetVal(pOutputData, i, output, (output == NULL)), NULL, _exit);
|
||||
|
||||
_exit:
|
||||
if (output) {
|
||||
|
@ -211,36 +188,22 @@ _exit:
|
|||
}
|
||||
|
||||
int32_t executeRelationFunc(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1,
|
||||
const GEOSGeometry *geom2, int32_t i,
|
||||
bool swapped, SColumnInfoData *pOutputData,
|
||||
const GEOSGeometry *geom2, int32_t i, bool swapped, SColumnInfoData *pOutputData,
|
||||
_geomDoRelationFunc_t doRelationFn) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
char res = 0;
|
||||
|
||||
if (!geom1 || !geom2) { // if empty input value
|
||||
res = -1;
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
}
|
||||
else {
|
||||
code = doRelationFn(geom1, preparedGeom1, geom2, swapped, &res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
TAOS_CHECK_RETURN(doRelationFn(geom1, preparedGeom1, geom2, swapped, &res));
|
||||
}
|
||||
|
||||
code = colDataSetVal(pOutputData, i, &res, (res==-1));
|
||||
|
||||
return code;
|
||||
return colDataSetVal(pOutputData, i, &res, (res == -1));
|
||||
}
|
||||
|
||||
int32_t geomOneParamFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
||||
_geomInitCtxFunc_t initCtxFn, _geomExecuteOneParamFunc_t executeOneParamFn) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
|
||||
code = initCtxFn();
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
int32_t geomOneParamFunction(SScalarParam *pInput, SScalarParam *pOutput, _geomInitCtxFunc_t initCtxFn,
|
||||
_geomExecuteOneParamFunc_t executeOneParamFn) {
|
||||
TAOS_CHECK_RETURN(initCtxFn());
|
||||
|
||||
SColumnInfoData *pInputData = pInput->columnData;
|
||||
SColumnInfoData *pOutputData = pOutput->columnData;
|
||||
|
@ -248,42 +211,30 @@ int32_t geomOneParamFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
|||
|
||||
if (IS_NULL_TYPE(GET_PARAM_TYPE(pInput))) {
|
||||
colDataSetNNULL(pOutputData, 0, pInput->numOfRows);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
|
||||
if (colDataIsNull_s(pInputData, i)) {
|
||||
colDataSetNULL(pOutputData, i);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
continue;
|
||||
}
|
||||
|
||||
code = executeOneParamFn(pInputData, i, pOutputData);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
TAOS_CHECK_RETURN(executeOneParamFn(pInputData, i, pOutputData));
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t geomTwoParamsFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
||||
_geomInitCtxFunc_t initCtxFn, _geomExecuteTwoParamsFunc_t executeTwoParamsFn) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
|
||||
code = initCtxFn();
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
int32_t geomTwoParamsFunction(SScalarParam *pInput, SScalarParam *pOutput, _geomInitCtxFunc_t initCtxFn,
|
||||
_geomExecuteTwoParamsFunc_t executeTwoParamsFn) {
|
||||
TAOS_CHECK_RETURN(initCtxFn());
|
||||
|
||||
SColumnInfoData *pInputData[2];
|
||||
SColumnInfoData *pOutputData = pOutput->columnData;
|
||||
pInputData[0] = pInput[0].columnData;
|
||||
pInputData[1] = pInput[1].columnData;
|
||||
|
||||
bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) ||
|
||||
IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1])));
|
||||
bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1])));
|
||||
bool isConstantLeft = (pInput[0].numOfRows == 1);
|
||||
bool isConstantRight = (pInput[1].numOfRows == 1);
|
||||
int32_t numOfRows = TMAX(pInput[0].numOfRows, pInput[1].numOfRows);
|
||||
|
@ -293,9 +244,7 @@ int32_t geomTwoParamsFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
|||
(isConstantLeft && colDataIsNull_s(pInputData[0], 0)) || // left operand is constant NULL
|
||||
(isConstantRight && colDataIsNull_s(pInputData[1], 0))) { // right operand is constant NULL
|
||||
colDataSetNNULL(pOutputData, 0, numOfRows);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
int32_t iLeft = 0;
|
||||
int32_t iRight = 0;
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
|
@ -305,32 +254,24 @@ int32_t geomTwoParamsFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
|||
if ((!isConstantLeft && colDataIsNull_s(pInputData[0], iLeft)) ||
|
||||
(!isConstantRight && colDataIsNull_s(pInputData[1], iRight))) {
|
||||
colDataSetNULL(pOutputData, i);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
continue;
|
||||
}
|
||||
|
||||
code = executeTwoParamsFn(pInputData, iLeft, iRight, pOutputData);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
TAOS_CHECK_RETURN(executeTwoParamsFn(pInputData, iLeft, iRight, pOutputData));
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t geomRelationFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
||||
bool swapAllowed, _geomDoRelationFunc_t doRelationFn) {
|
||||
int32_t geomRelationFunction(SScalarParam *pInput, SScalarParam *pOutput, bool swapAllowed,
|
||||
_geomDoRelationFunc_t doRelationFn) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
|
||||
code = initCtxRelationFunc();
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
TAOS_CHECK_RETURN(initCtxRelationFunc());
|
||||
|
||||
// handle with all NULL output
|
||||
bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) ||
|
||||
IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1])));
|
||||
bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1])));
|
||||
bool isConstant1 = (pInput[0].numOfRows == 1);
|
||||
bool isConstant2 = (pInput[1].numOfRows == 1);
|
||||
int32_t numOfRows = TMAX(pInput[0].numOfRows, pInput[1].numOfRows);
|
||||
|
@ -341,24 +282,21 @@ int32_t geomRelationFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
|||
(isConstant1 && colDataIsNull_s(pInput[0].columnData, 0)) || // left operand is constant NULL
|
||||
(isConstant2 && colDataIsNull_s(pInput[1].columnData, 0))) { // right operand is constant NULL
|
||||
colDataSetNNULL(pOutputData, 0, numOfRows);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
bool swapped = false;
|
||||
SColumnInfoData *pInputData[2];
|
||||
|
||||
// swap two input data to make sure input data 0 is constant if swapAllowed and only isConstant2 is true
|
||||
if (swapAllowed &&
|
||||
!isConstant1 && isConstant2) {
|
||||
if (swapAllowed && !isConstant1 && isConstant2) {
|
||||
pInputData[0] = pInput[1].columnData;
|
||||
pInputData[1] = pInput[0].columnData;
|
||||
|
||||
isConstant1 = true;
|
||||
isConstant2 = false;
|
||||
swapped = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pInputData[0] = pInput[0].columnData;
|
||||
pInputData[1] = pInput[1].columnData;
|
||||
}
|
||||
|
@ -369,43 +307,27 @@ int32_t geomRelationFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
|||
|
||||
// if there is constant, make PreparedGeometry from pInputData 0
|
||||
if (isConstant1) {
|
||||
code = readGeometry(colDataGetData(pInputData[0], 0), &geom1, &preparedGeom1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(readGeometry(colDataGetData(pInputData[0], 0), &geom1, &preparedGeom1), NULL, _exit);
|
||||
}
|
||||
if (isConstant2) {
|
||||
code = readGeometry(colDataGetData(pInputData[1], 0), &geom2, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(readGeometry(colDataGetData(pInputData[1], 0), &geom2, NULL), NULL, _exit);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
if ((!isConstant1 && colDataIsNull_s(pInputData[0], i)) ||
|
||||
(!isConstant2 && colDataIsNull_s(pInputData[1], i))) {
|
||||
if ((!isConstant1 && colDataIsNull_s(pInputData[0], i)) || (!isConstant2 && colDataIsNull_s(pInputData[1], i))) {
|
||||
colDataSetNULL(pOutputData, i);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isConstant1) {
|
||||
code = readGeometry(colDataGetData(pInputData[0], i), &geom1, &preparedGeom1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(readGeometry(colDataGetData(pInputData[0], i), &geom1, &preparedGeom1), NULL, _exit);
|
||||
}
|
||||
if (!isConstant2) {
|
||||
code = readGeometry(colDataGetData(pInputData[1], i), &geom2, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(readGeometry(colDataGetData(pInputData[1], i), &geom2, NULL), NULL, _exit);
|
||||
}
|
||||
|
||||
code = executeRelationFunc(geom1, preparedGeom1, geom2, i, swapped, pOutputData, doRelationFn);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(executeRelationFunc(geom1, preparedGeom1, geom2, i, swapped, pOutputData, doRelationFn), NULL,
|
||||
_exit);
|
||||
|
||||
if (!isConstant1) {
|
||||
destroyGeometry(&geom1, &preparedGeom1);
|
||||
|
@ -415,11 +337,13 @@ int32_t geomRelationFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
|||
}
|
||||
}
|
||||
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
|
||||
_exit:
|
||||
destroyGeometry(&geom1, &preparedGeom1);
|
||||
destroyGeometry(&geom2, NULL);
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t makePointFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
#include "types.h"
|
||||
|
||||
typedef char (*_geosRelationFunc_t)(GEOSContextHandle_t handle, const GEOSGeometry *g1, const GEOSGeometry *g2);
|
||||
typedef char (*_geosPreparedRelationFunc_t)(GEOSContextHandle_t handle, const GEOSPreparedGeometry *pg1, const GEOSGeometry *g2);
|
||||
typedef char (*_geosPreparedRelationFunc_t)(GEOSContextHandle_t handle, const GEOSPreparedGeometry *pg1,
|
||||
const GEOSGeometry *g2);
|
||||
|
||||
void geosFreeBuffer(void *buffer) {
|
||||
if (buffer) {
|
||||
|
@ -41,7 +42,7 @@ int32_t initCtxMakePoint() {
|
|||
return code;
|
||||
}
|
||||
|
||||
GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
(void)GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
}
|
||||
|
||||
if (geosCtx->WKBWriter == NULL) {
|
||||
|
@ -89,6 +90,10 @@ _exit:
|
|||
static int32_t initWktRegex(pcre2_code **ppRegex, pcre2_match_data **ppMatchData) {
|
||||
int32_t code = 0;
|
||||
char *wktPatternWithSpace = taosMemoryCalloc(4, 1024);
|
||||
if (NULL == wktPatternWithSpace) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
sprintf(
|
||||
wktPatternWithSpace,
|
||||
"^( *)point( *)z?m?( *)((empty)|(\\(( *)(([-+]?[0-9]+\\.?[0-9]*)|([-+]?[0-9]*\\.?[0-9]+))(e[-+]?[0-9]+)?(( "
|
||||
|
@ -157,7 +162,7 @@ int32_t initCtxGeomFromText() {
|
|||
return code;
|
||||
}
|
||||
|
||||
GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
(void)GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
}
|
||||
|
||||
if (geosCtx->WKTReader == NULL) {
|
||||
|
@ -228,7 +233,7 @@ int32_t initCtxAsText() {
|
|||
return code;
|
||||
}
|
||||
|
||||
GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
(void)GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
}
|
||||
|
||||
if (geosCtx->WKBReader == NULL) {
|
||||
|
@ -295,7 +300,7 @@ int32_t initCtxRelationFunc() {
|
|||
return code;
|
||||
}
|
||||
|
||||
GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
(void)GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
}
|
||||
|
||||
if (geosCtx->WKBReader == NULL) {
|
||||
|
@ -309,78 +314,71 @@ int32_t initCtxRelationFunc() {
|
|||
}
|
||||
|
||||
int32_t doGeosRelation(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res,
|
||||
_geosRelationFunc_t relationFn,
|
||||
_geosRelationFunc_t swappedRelationFn,
|
||||
bool swapped, char *res, _geosRelationFunc_t relationFn, _geosRelationFunc_t swappedRelationFn,
|
||||
_geosPreparedRelationFunc_t preparedRelationFn,
|
||||
_geosPreparedRelationFunc_t swappedPreparedRelationFn) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext *geosCtx = getThreadLocalGeosCtx();
|
||||
|
||||
if (!preparedGeom1) {
|
||||
if (!swapped) {
|
||||
ASSERT(relationFn);
|
||||
*res = relationFn(geosCtx->handle, geom1, geom2);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ASSERT(swappedRelationFn);
|
||||
*res = swappedRelationFn(geosCtx->handle, geom1, geom2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!swapped) {
|
||||
ASSERT(preparedRelationFn);
|
||||
*res = preparedRelationFn(geosCtx->handle, preparedGeom1, geom2);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ASSERT(swappedPreparedRelationFn);
|
||||
*res = swappedPreparedRelationFn(geosCtx->handle, preparedGeom1, geom2);
|
||||
}
|
||||
}
|
||||
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t doIntersects(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res,
|
||||
GEOSIntersects_r, GEOSIntersects_r, GEOSPreparedIntersects_r, GEOSPreparedIntersects_r);
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, GEOSIntersects_r, GEOSIntersects_r,
|
||||
GEOSPreparedIntersects_r, GEOSPreparedIntersects_r);
|
||||
}
|
||||
|
||||
int32_t doEquals(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, NULL, geom2, swapped, res,
|
||||
GEOSEquals_r, GEOSEquals_r, NULL, NULL); // no prepared version for eguals()
|
||||
return doGeosRelation(geom1, NULL, geom2, swapped, res, GEOSEquals_r, GEOSEquals_r, NULL,
|
||||
NULL); // no prepared version for eguals()
|
||||
}
|
||||
|
||||
int32_t doTouches(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res,
|
||||
GEOSTouches_r, GEOSTouches_r, GEOSPreparedTouches_r, GEOSPreparedTouches_r);
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, GEOSTouches_r, GEOSTouches_r, GEOSPreparedTouches_r,
|
||||
GEOSPreparedTouches_r);
|
||||
}
|
||||
|
||||
int32_t doCovers(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res,
|
||||
GEOSCovers_r, GEOSCoveredBy_r, GEOSPreparedCovers_r, GEOSPreparedCoveredBy_r);
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, GEOSCovers_r, GEOSCoveredBy_r, GEOSPreparedCovers_r,
|
||||
GEOSPreparedCoveredBy_r);
|
||||
}
|
||||
|
||||
int32_t doContains(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res,
|
||||
GEOSContains_r, GEOSWithin_r, GEOSPreparedContains_r, GEOSPreparedWithin_r);
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, GEOSContains_r, GEOSWithin_r, GEOSPreparedContains_r,
|
||||
GEOSPreparedWithin_r);
|
||||
}
|
||||
|
||||
int32_t doContainsProperly(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res,
|
||||
NULL, NULL, GEOSPreparedContainsProperly_r, NULL);
|
||||
int32_t doContainsProperly(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1,
|
||||
const GEOSGeometry *geom2, bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, NULL, NULL, GEOSPreparedContainsProperly_r, NULL);
|
||||
}
|
||||
|
||||
// input is with VARSTR format
|
||||
// need to call destroyGeometry(outputGeom, outputPreparedGeom) later
|
||||
int32_t readGeometry(const unsigned char *input, GEOSGeometry **outputGeom, const GEOSPreparedGeometry **outputPreparedGeom) {
|
||||
int32_t readGeometry(const unsigned char *input, GEOSGeometry **outputGeom,
|
||||
const GEOSPreparedGeometry **outputPreparedGeom) {
|
||||
SGeosContext *geosCtx = getThreadLocalGeosCtx();
|
||||
|
||||
ASSERT(outputGeom); // it is not allowed if outputGeom is NULL
|
||||
|
|
|
@ -42,22 +42,21 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url);
|
|||
|
||||
extern char **environ;
|
||||
|
||||
SConfig *cfgInit() {
|
||||
int32_t cfgInit(SConfig ** ppCfg) {
|
||||
SConfig *pCfg = taosMemoryCalloc(1, sizeof(SConfig));
|
||||
if (pCfg == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pCfg->array = taosArrayInit(32, sizeof(SConfigItem));
|
||||
if (pCfg->array == NULL) {
|
||||
taosMemoryFree(pCfg);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
taosThreadMutexInit(&pCfg->lock, NULL);
|
||||
return pCfg;
|
||||
*ppCfg = pCfg;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr) {
|
||||
|
@ -73,7 +72,7 @@ int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr) {
|
|||
case CFG_STYPE_ENV_CMD:
|
||||
return cfgLoadFromEnvCmd(pCfg, (const char **)sourceStr);
|
||||
default:
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,11 +81,11 @@ int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs) {
|
|||
for (int32_t i = 0; i < size; ++i) {
|
||||
SConfigPair *pPair = taosArrayGet(pArgs, i);
|
||||
if (cfgSetItem(pCfg, pPair->name, pPair->value, CFG_STYPE_ARG_LIST, true) != 0) {
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void cfgItemFreeVal(SConfigItem *pItem) {
|
||||
|
@ -126,28 +125,27 @@ static int32_t cfgCheckAndSetConf(SConfigItem *pItem, const char *conf) {
|
|||
|
||||
pItem->str = taosStrdup(conf);
|
||||
if (pItem->str == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) {
|
||||
char fullDir[PATH_MAX] = {0};
|
||||
if (taosExpandDir(inputDir, fullDir, PATH_MAX) != 0) {
|
||||
uError("failed to expand dir:%s", inputDir);
|
||||
return -1;
|
||||
int32_t code = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to expand dir:%s since %s", inputDir, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pItem->str);
|
||||
pItem->str = taosStrdup(fullDir);
|
||||
if (pItem->str == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static int32_t cfgSetBool(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
|
@ -166,97 +164,88 @@ static int32_t cfgSetBool(SConfigItem *pItem, const char *value, ECfgSrcType sty
|
|||
|
||||
static int32_t cfgSetInt32(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
int32_t ival;
|
||||
int32_t code = taosStrHumanToInt32(value, &ival);
|
||||
if (code != TSDB_CODE_SUCCESS) return code;
|
||||
TAOS_CHECK_RETURN(taosStrHumanToInt32(value, &ival));
|
||||
if (ival < pItem->imin || ival > pItem->imax) {
|
||||
uError("cfg:%s, type:%s src:%s value:%d out of range[%" PRId64 ", %" PRId64 "]", pItem->name,
|
||||
cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), ival, pItem->imin, pItem->imax);
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
pItem->i32 = ival;
|
||||
pItem->stype = stype;
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static int32_t cfgSetInt64(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
int64_t ival;
|
||||
int32_t code = taosStrHumanToInt64(value, &ival);
|
||||
if (code != TSDB_CODE_SUCCESS) return code;
|
||||
TAOS_CHECK_RETURN(taosStrHumanToInt64(value, &ival));
|
||||
if (ival < pItem->imin || ival > pItem->imax) {
|
||||
uError("cfg:%s, type:%s src:%s value:%" PRId64 " out of range[%" PRId64 ", %" PRId64 "]", pItem->name,
|
||||
cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), ival, pItem->imin, pItem->imax);
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
pItem->i64 = ival;
|
||||
pItem->stype = stype;
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static int32_t cfgSetFloat(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
double dval;
|
||||
int32_t code = parseCfgReal(value, &dval);
|
||||
TAOS_CHECK_RETURN(parseCfgReal(value, &dval));
|
||||
if (dval < pItem->fmin || dval > pItem->fmax) {
|
||||
uError("cfg:%s, type:%s src:%s value:%f out of range[%f, %f]", pItem->name, cfgDtypeStr(pItem->dtype),
|
||||
cfgStypeStr(stype), dval, pItem->fmin, pItem->fmax);
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
pItem->fval = (float)dval;
|
||||
pItem->stype = stype;
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static int32_t cfgSetString(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
char *tmp = taosStrdup(value);
|
||||
if (tmp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
uError("cfg:%s, type:%s src:%s value:%s failed to dup since %s", pItem->name, cfgDtypeStr(pItem->dtype),
|
||||
cfgStypeStr(stype), value, terrstr());
|
||||
return -1;
|
||||
cfgStypeStr(stype), value, tstrerror(TSDB_CODE_OUT_OF_MEMORY));
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pItem->str);
|
||||
pItem->str = tmp;
|
||||
pItem->stype = stype;
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static int32_t cfgSetDir(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
if (cfgCheckAndSetDir(pItem, value) != 0) {
|
||||
int32_t code = cfgCheckAndSetDir(pItem, value);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
uError("cfg:%s, type:%s src:%s value:%s failed to dup since %s", pItem->name, cfgDtypeStr(pItem->dtype),
|
||||
cfgStypeStr(stype), value, terrstr());
|
||||
return -1;
|
||||
cfgStypeStr(stype), value, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pItem->stype = stype;
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static int32_t doSetConf(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
if (cfgCheckAndSetConf(pItem, value) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
int32_t code = cfgCheckAndSetConf(pItem, value);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
uError("cfg:%s, type:%s src:%s value:%s failed to dup since %s", pItem->name, cfgDtypeStr(pItem->dtype),
|
||||
cfgStypeStr(stype), value, terrstr());
|
||||
return -1;
|
||||
cfgStypeStr(stype), value, tstrerror(TSDB_CODE_OUT_OF_MEMORY));
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pItem->stype = stype;
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static int32_t cfgSetTimezone(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
int32_t code = doSetConf(pItem, value, stype);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
TAOS_CHECK_RETURN(doSetConf(pItem, value, stype));
|
||||
osSetTimezone(value);
|
||||
return code;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static int32_t cfgSetTfsItem(SConfig *pCfg, const char *name, const char *value, const char *level, const char *primary,
|
||||
|
@ -267,16 +256,15 @@ static int32_t cfgSetTfsItem(SConfig *pCfg, const char *name, const char *value,
|
|||
if (pItem == NULL) {
|
||||
taosThreadMutexUnlock(&pCfg->lock);
|
||||
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (pItem->array == NULL) {
|
||||
pItem->array = taosArrayInit(16, sizeof(SDiskCfg));
|
||||
if (pItem->array == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosThreadMutexUnlock(&pCfg->lock);
|
||||
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,34 +275,32 @@ static int32_t cfgSetTfsItem(SConfig *pCfg, const char *name, const char *value,
|
|||
cfg.disable = disable ? atoi(disable) : 0;
|
||||
void *ret = taosArrayPush(pItem->array, &cfg);
|
||||
if (ret == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosThreadMutexUnlock(&pCfg->lock);
|
||||
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pItem->stype = stype;
|
||||
taosThreadMutexUnlock(&pCfg->lock);
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static int32_t cfgUpdateDebugFlagItem(SConfig *pCfg, const char *name, bool resetArray) {
|
||||
SConfigItem *pDebugFlagItem = cfgGetItem(pCfg, "debugFlag");
|
||||
if (resetArray) {
|
||||
// reset
|
||||
if (pDebugFlagItem == NULL) return -1;
|
||||
if (pDebugFlagItem == NULL) TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND);
|
||||
|
||||
// logflag names that should 'not' be set by 'debugFlag'
|
||||
if (pDebugFlagItem->array == NULL) {
|
||||
pDebugFlagItem->array = taosArrayInit(16, sizeof(SLogVar));
|
||||
if (pDebugFlagItem->array == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
taosArrayClear(pDebugFlagItem->array);
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
// update
|
||||
|
@ -322,9 +308,11 @@ static int32_t cfgUpdateDebugFlagItem(SConfig *pCfg, const char *name, bool rese
|
|||
if (pDebugFlagItem->array != NULL) {
|
||||
SLogVar logVar = {0};
|
||||
strncpy(logVar.name, name, TSDB_LOG_VAR_LEN - 1);
|
||||
taosArrayPush(pDebugFlagItem->array, &logVar);
|
||||
if (NULL == taosArrayPush(pDebugFlagItem->array, &logVar)) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype, bool lock) {
|
||||
|
@ -337,9 +325,8 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy
|
|||
|
||||
SConfigItem *pItem = cfgGetItem(pCfg, name);
|
||||
if (pItem == NULL) {
|
||||
terrno = TSDB_CODE_CFG_NOT_FOUND;
|
||||
taosThreadMutexUnlock(&pCfg->lock);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND);
|
||||
}
|
||||
|
||||
switch (pItem->dtype) {
|
||||
|
@ -382,7 +369,7 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy
|
|||
}
|
||||
case CFG_DTYPE_NONE:
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
code = TSDB_CODE_INVALID_CFG;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -390,7 +377,7 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy
|
|||
taosThreadMutexUnlock(&pCfg->lock);
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SConfigItem *cfgGetItem(SConfig *pCfg, const char *pName) {
|
||||
|
@ -403,7 +390,6 @@ SConfigItem *cfgGetItem(SConfig *pCfg, const char *pName) {
|
|||
}
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_CFG_NOT_FOUND;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -427,9 +413,8 @@ int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *p
|
|||
SConfigItem *pItem = cfgGetItem(pCfg, name);
|
||||
if (!pItem || (pItem->dynScope & dynType) == 0) {
|
||||
uError("failed to config:%s, not support update this config", name);
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
cfgUnLock(pCfg);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_CFG);
|
||||
}
|
||||
|
||||
switch (pItem->dtype) {
|
||||
|
@ -437,10 +422,9 @@ int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *p
|
|||
if (strcasecmp(name, "slowLogScope") == 0) {
|
||||
char *tmp = taosStrdup(pVal);
|
||||
if (taosSetSlowLogScope(tmp) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
cfgUnLock(pCfg);
|
||||
taosMemoryFree(tmp);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_CFG);
|
||||
}
|
||||
taosMemoryFree(tmp);
|
||||
}
|
||||
|
@ -449,9 +433,8 @@ int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *p
|
|||
int32_t ival = (int32_t)atoi(pVal);
|
||||
if (ival != 0 && ival != 1) {
|
||||
uError("cfg:%s, type:%s value:%d out of range[0, 1]", pItem->name, cfgDtypeStr(pItem->dtype), ival);
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
cfgUnLock(pCfg);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
} break;
|
||||
case CFG_DTYPE_INT32: {
|
||||
|
@ -464,9 +447,8 @@ int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *p
|
|||
if (ival < pItem->imin || ival > pItem->imax) {
|
||||
uError("cfg:%s, type:%s value:%d out of range[%" PRId64 ", %" PRId64 "]", pItem->name,
|
||||
cfgDtypeStr(pItem->dtype), ival, pItem->imin, pItem->imax);
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
cfgUnLock(pCfg);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
} break;
|
||||
case CFG_DTYPE_INT64: {
|
||||
|
@ -474,14 +456,13 @@ int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *p
|
|||
int32_t code = taosStrHumanToInt64(pVal, &ival);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
cfgUnLock(pCfg);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ival < pItem->imin || ival > pItem->imax) {
|
||||
uError("cfg:%s, type:%s value:%" PRId64 " out of range[%" PRId64 ", %" PRId64 "]", pItem->name,
|
||||
cfgDtypeStr(pItem->dtype), ival, pItem->imin, pItem->imax);
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
cfgUnLock(pCfg);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
} break;
|
||||
case CFG_DTYPE_FLOAT:
|
||||
|
@ -490,14 +471,13 @@ int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *p
|
|||
int32_t code = parseCfgReal(pVal, &dval);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
cfgUnLock(pCfg);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (dval < pItem->fmin || dval > pItem->fmax) {
|
||||
uError("cfg:%s, type:%s value:%f out of range[%f, %f]", pItem->name, cfgDtypeStr(pItem->dtype), dval,
|
||||
pItem->fmin, pItem->fmax);
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
cfgUnLock(pCfg);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
|
@ -505,15 +485,14 @@ int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *p
|
|||
}
|
||||
|
||||
cfgUnLock(pCfg);
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static int32_t cfgAddItem(SConfig *pCfg, SConfigItem *pItem, const char *name) {
|
||||
pItem->stype = CFG_STYPE_DEFAULT;
|
||||
pItem->name = taosStrdup(name);
|
||||
if (pItem->name == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
int32_t size = taosArrayGetSize(pCfg->array);
|
||||
|
@ -521,7 +500,7 @@ static int32_t cfgAddItem(SConfig *pCfg, SConfigItem *pItem, const char *name) {
|
|||
SConfigItem *existItem = taosArrayGet(pCfg->array, i);
|
||||
if (existItem != NULL && strcmp(existItem->name, pItem->name) == 0) {
|
||||
taosMemoryFree(pItem->name);
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_CFG);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -535,11 +514,10 @@ static int32_t cfgAddItem(SConfig *pCfg, SConfigItem *pItem, const char *name) {
|
|||
}
|
||||
|
||||
taosMemoryFree(pItem->name);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t cfgAddBool(SConfig *pCfg, const char *name, bool defaultVal, int8_t scope, int8_t dynScope) {
|
||||
|
@ -550,8 +528,7 @@ int32_t cfgAddBool(SConfig *pCfg, const char *name, bool defaultVal, int8_t scop
|
|||
int32_t cfgAddInt32(SConfig *pCfg, const char *name, int32_t defaultVal, int64_t minval, int64_t maxval, int8_t scope,
|
||||
int8_t dynScope) {
|
||||
if (defaultVal < minval || defaultVal > maxval) {
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_INT32,
|
||||
|
@ -566,8 +543,7 @@ int32_t cfgAddInt32(SConfig *pCfg, const char *name, int32_t defaultVal, int64_t
|
|||
int32_t cfgAddInt64(SConfig *pCfg, const char *name, int64_t defaultVal, int64_t minval, int64_t maxval, int8_t scope,
|
||||
int8_t dynScope) {
|
||||
if (defaultVal < minval || defaultVal > maxval) {
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_INT64,
|
||||
|
@ -582,8 +558,7 @@ int32_t cfgAddInt64(SConfig *pCfg, const char *name, int64_t defaultVal, int64_t
|
|||
int32_t cfgAddFloat(SConfig *pCfg, const char *name, float defaultVal, float minval, float maxval, int8_t scope,
|
||||
int8_t dynScope) {
|
||||
if (defaultVal < minval || defaultVal > maxval) {
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_FLOAT,
|
||||
|
@ -599,45 +574,32 @@ int32_t cfgAddString(SConfig *pCfg, const char *name, const char *defaultVal, in
|
|||
SConfigItem item = {.dtype = CFG_DTYPE_STRING, .scope = scope, .dynScope = dynScope};
|
||||
item.str = taosStrdup(defaultVal);
|
||||
if (item.str == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddDir(SConfig *pCfg, const char *name, const char *defaultVal, int8_t scope, int8_t dynScope) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_DIR, .scope = scope, .dynScope = dynScope};
|
||||
if (cfgCheckAndSetDir(&item, defaultVal) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
TAOS_CHECK_RETURN(cfgCheckAndSetDir(&item, defaultVal));
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddLocale(SConfig *pCfg, const char *name, const char *defaultVal, int8_t scope, int8_t dynScope) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_LOCALE, .scope = scope, .dynScope = dynScope};
|
||||
if (cfgCheckAndSetConf(&item, defaultVal) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
TAOS_CHECK_RETURN(cfgCheckAndSetConf(&item, defaultVal));
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddCharset(SConfig *pCfg, const char *name, const char *defaultVal, int8_t scope, int8_t dynScope) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_CHARSET, .scope = scope, .dynScope = dynScope};
|
||||
if (cfgCheckAndSetConf(&item, defaultVal) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
TAOS_CHECK_RETURN(cfgCheckAndSetConf(&item, defaultVal));
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal, int8_t scope, int8_t dynScope) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_TIMEZONE, .scope = scope, .dynScope = dynScope};
|
||||
if (cfgCheckAndSetConf(&item, defaultVal) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
TAOS_CHECK_RETURN(cfgCheckAndSetConf(&item, defaultVal));
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
|
@ -693,7 +655,7 @@ const char *cfgDtypeStr(ECfgDataType type) {
|
|||
}
|
||||
}
|
||||
|
||||
void cfgDumpItemValue(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen) {
|
||||
int32_t cfgDumpItemValue(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen) {
|
||||
int32_t len = 0;
|
||||
switch (pItem->dtype) {
|
||||
case CFG_DTYPE_BOOL:
|
||||
|
@ -719,14 +681,19 @@ void cfgDumpItemValue(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *p
|
|||
break;
|
||||
}
|
||||
|
||||
if (len < 0) {
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
|
||||
if (len > bufSize) {
|
||||
len = bufSize;
|
||||
}
|
||||
|
||||
*pLen = len;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
void cfgDumpItemScope(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen) {
|
||||
int32_t cfgDumpItemScope(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen) {
|
||||
int32_t len = 0;
|
||||
switch (pItem->scope) {
|
||||
case CFG_SCOPE_SERVER:
|
||||
|
@ -740,11 +707,16 @@ void cfgDumpItemScope(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *p
|
|||
break;
|
||||
}
|
||||
|
||||
if (len < 0) {
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
|
||||
if (len > bufSize) {
|
||||
len = bufSize;
|
||||
}
|
||||
|
||||
*pLen = len;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
void cfgDumpCfgS3(SConfig *pCfg, bool tsc, bool dump) {
|
||||
|
@ -919,14 +891,14 @@ int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
|
|||
char **pEnv = environ;
|
||||
line[1023] = 0;
|
||||
|
||||
if (pEnv == NULL) return 0;
|
||||
if (pEnv == NULL) TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
while (*pEnv != NULL) {
|
||||
name = value = value2 = value3 = value4 = NULL;
|
||||
olen = vlen = vlen2 = vlen3 = vlen4 = 0;
|
||||
|
||||
strncpy(line, *pEnv, sizeof(line) - 1);
|
||||
pEnv++;
|
||||
taosEnvToCfg(line, line);
|
||||
(void)taosEnvToCfg(line, line);
|
||||
|
||||
paGetToken(line, &name, &olen);
|
||||
if (olen == 0) continue;
|
||||
|
@ -948,16 +920,16 @@ int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
|
|||
}
|
||||
|
||||
code = cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_VAR, true);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
|
||||
|
||||
if (strcasecmp(name, "dataDir") == 0) {
|
||||
code = cfgSetTfsItem(pConfig, name, value, value2, value3, value4, CFG_STYPE_ENV_VAR);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
|
||||
}
|
||||
}
|
||||
|
||||
uInfo("load from env variables cfg success");
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) {
|
||||
|
@ -965,11 +937,11 @@ int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) {
|
|||
int32_t olen, vlen, vlen2, vlen3, vlen4;
|
||||
int32_t code = 0;
|
||||
int32_t index = 0;
|
||||
if (envCmd == NULL) return 0;
|
||||
if (envCmd == NULL) TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
while (envCmd[index] != NULL) {
|
||||
strncpy(buf, envCmd[index], sizeof(buf) - 1);
|
||||
buf[sizeof(buf) - 1] = 0;
|
||||
taosEnvToCfg(buf, buf);
|
||||
(void)taosEnvToCfg(buf, buf);
|
||||
index++;
|
||||
|
||||
name = value = value2 = value3 = value4 = NULL;
|
||||
|
@ -995,16 +967,16 @@ int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) {
|
|||
}
|
||||
|
||||
code = cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_CMD, true);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
|
||||
|
||||
if (strcasecmp(name, "dataDir") == 0) {
|
||||
code = cfgSetTfsItem(pConfig, name, value, value2, value3, value4, CFG_STYPE_ENV_CMD);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
|
||||
}
|
||||
}
|
||||
|
||||
uInfo("load from env cmd cfg success");
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
|
||||
|
@ -1017,20 +989,19 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
|
|||
if (envFile != NULL && strlen(envFile) > 0) {
|
||||
if (!taosCheckExistFile(envFile)) {
|
||||
uError("failed to load env file:%s", envFile);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_NOT_FOUND);
|
||||
}
|
||||
filepath = envFile;
|
||||
} else {
|
||||
if (!taosCheckExistFile(filepath)) {
|
||||
uInfo("env file:%s not load", filepath);
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
|
||||
while (!taosEOFFile(pFile)) {
|
||||
|
@ -1042,7 +1013,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
|
|||
break;
|
||||
}
|
||||
if (line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
|
||||
taosEnvToCfg(line, line);
|
||||
(void)taosEnvToCfg(line, line);
|
||||
|
||||
paGetToken(line, &name, &olen);
|
||||
if (olen == 0) continue;
|
||||
|
@ -1064,18 +1035,18 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
|
|||
}
|
||||
|
||||
code = cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_FILE, true);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
|
||||
|
||||
if (strcasecmp(name, "dataDir") == 0) {
|
||||
code = cfgSetTfsItem(pConfig, name, value, value2, value3, value4, CFG_STYPE_ENV_FILE);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
|
||||
}
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
|
||||
uInfo("load from env cfg file %s success", filepath);
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
||||
|
@ -1087,13 +1058,13 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
|||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (pFile == NULL) {
|
||||
// success when the file does not exist
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
if (errno == ENOENT) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uInfo("failed to load from cfg file %s since %s, use default parameters", filepath, terrstr());
|
||||
return 0;
|
||||
uInfo("failed to load from cfg file %s since %s, use default parameters", filepath, tstrerror(code));
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
} else {
|
||||
uError("failed to load from cfg file %s since %s", filepath, terrstr());
|
||||
return -1;
|
||||
uError("failed to load from cfg file %s since %s", filepath, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1134,7 +1105,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
|||
}
|
||||
|
||||
code = cfgSetItem(pConfig, name, newValue, CFG_STYPE_CFG_FILE, true);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
|
||||
} else {
|
||||
paGetToken(value + vlen + 1, &value2, &vlen2);
|
||||
if (vlen2 != 0) {
|
||||
|
@ -1148,12 +1119,12 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
|||
}
|
||||
|
||||
code = cfgSetItem(pConfig, name, value, CFG_STYPE_CFG_FILE, true);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
|
||||
}
|
||||
|
||||
if (strcasecmp(name, "dataDir") == 0) {
|
||||
code = cfgSetTfsItem(pConfig, name, value, value2, value3, value4, CFG_STYPE_CFG_FILE);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
|
||||
}
|
||||
|
||||
size_t len = strlen(name);
|
||||
|
@ -1161,18 +1132,18 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
|||
const size_t debugFlagLen = strlen(debugFlagStr);
|
||||
if (len >= debugFlagLen && strcasecmp(name + len - debugFlagLen, debugFlagStr) == 0) {
|
||||
code = cfgUpdateDebugFlagItem(pConfig, name, len == debugFlagLen);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
|
||||
}
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
|
||||
if (code == 0 || (code != 0 && terrno == TSDB_CODE_CFG_NOT_FOUND)) {
|
||||
if (TSDB_CODE_SUCCESS == code || TSDB_CODE_CFG_NOT_FOUND == code) {
|
||||
uInfo("load from cfg file %s success", filepath);
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
} else {
|
||||
uError("failed to load from cfg file %s since %s", filepath, terrstr());
|
||||
return -1;
|
||||
uError("failed to load from cfg file %s since %s", filepath, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1247,46 +1218,52 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
int32_t code = 0;
|
||||
if (url == NULL || strlen(url) == 0) {
|
||||
uInfo("apoll url not load");
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
char *p = strchr(url, ':');
|
||||
if (p == NULL) {
|
||||
uError("fail to load apoll url: %s, unknown format", url);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
p++;
|
||||
|
||||
SJson *pJson = NULL;
|
||||
if (strncmp(url, "jsonFile", 8) == 0) {
|
||||
char *filepath = p;
|
||||
if (!taosCheckExistFile(filepath)) {
|
||||
uError("failed to load json file:%s", filepath);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_NOT_FOUND);
|
||||
}
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END);
|
||||
char *buf = taosMemoryMalloc(fileSize);
|
||||
if (!buf) {
|
||||
taosCloseFile(&pFile);
|
||||
uError("load json file error: %s, failed to alloc memory", filepath);
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
taosLSeekFile(pFile, 0, SEEK_SET);
|
||||
if (taosReadFile(pFile, buf, fileSize) <= 0) {
|
||||
taosCloseFile(&pFile);
|
||||
uError("load json file error: %s", filepath);
|
||||
taosMemoryFreeClear(buf);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_DATA_FMT);
|
||||
}
|
||||
taosCloseFile(&pFile);
|
||||
SJson *pJson = tjsonParse(buf);
|
||||
pJson = tjsonParse(buf);
|
||||
if (NULL == pJson) {
|
||||
const char *jsonParseError = tjsonGetError();
|
||||
if (jsonParseError != NULL) {
|
||||
uError("load json file parse error: %s", jsonParseError);
|
||||
}
|
||||
taosMemoryFreeClear(buf);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_DATA_FMT);
|
||||
}
|
||||
taosMemoryFreeClear(buf);
|
||||
|
||||
|
@ -1295,13 +1272,17 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
cJSON *item = tjsonGetArrayItem(pJson, i);
|
||||
if (item == NULL) break;
|
||||
char *itemName = NULL, *itemValueString = NULL;
|
||||
tjsonGetObjectName(item, &itemName);
|
||||
tjsonGetObjectName(item, &itemName);
|
||||
tjsonGetObjectValueString(item, &itemValueString);
|
||||
TAOS_CHECK_GOTO(tjsonGetObjectName(item, &itemName), NULL, _err_json);
|
||||
TAOS_CHECK_GOTO(tjsonGetObjectValueString(item, &itemValueString), NULL, _err_json);
|
||||
if (itemValueString != NULL && itemName != NULL) {
|
||||
size_t itemNameLen = strlen(itemName);
|
||||
size_t itemValueStringLen = strlen(itemValueString);
|
||||
cfgLineBuf = taosMemoryMalloc(itemNameLen + itemValueStringLen + 2);
|
||||
if (NULL == cfgLineBuf) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err_json;
|
||||
}
|
||||
|
||||
memcpy(cfgLineBuf, itemName, itemNameLen);
|
||||
cfgLineBuf[itemNameLen] = ' ';
|
||||
memcpy(&cfgLineBuf[itemNameLen + 1], itemValueString, itemValueStringLen);
|
||||
|
@ -1327,11 +1308,11 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
}
|
||||
|
||||
code = cfgSetItem(pConfig, name, value, CFG_STYPE_APOLLO_URL, true);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
|
||||
|
||||
if (strcasecmp(name, "dataDir") == 0) {
|
||||
code = cfgSetTfsItem(pConfig, name, value, value2, value3, value4, CFG_STYPE_APOLLO_URL);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1341,16 +1322,20 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
// } else if (strncmp(url, "etcdUrl", 7) == 0) {
|
||||
} else {
|
||||
uError("Unsupported url: %s", url);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
uInfo("load from apoll url not implemented yet");
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
|
||||
_err_json:
|
||||
tjsonDelete(pJson);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl) {
|
||||
int32_t index = 0;
|
||||
if (envCmd == NULL) return 0;
|
||||
if (envCmd == NULL) TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
while (envCmd[index] != NULL) {
|
||||
if (strncmp(envCmd[index], "TAOS_APOLLO_URL", 14) == 0) {
|
||||
char *p = strchr(envCmd[index], '=');
|
||||
|
@ -1362,7 +1347,7 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl
|
|||
}
|
||||
memcpy(apolloUrl, p, TMIN(strlen(p) + 1, PATH_MAX));
|
||||
uInfo("get apollo url from env cmd success");
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
}
|
||||
index++;
|
||||
|
@ -1384,7 +1369,7 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl
|
|||
}
|
||||
memcpy(apolloUrl, p, TMIN(strlen(p) + 1, PATH_MAX));
|
||||
uInfo("get apollo url from env variables success, apolloUrl=%s", apolloUrl);
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1393,13 +1378,13 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl
|
|||
if (envFile != NULL && strlen(envFile) > 0) {
|
||||
if (!taosCheckExistFile(envFile)) {
|
||||
uError("failed to load env file:%s", envFile);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_NOT_FOUND);
|
||||
}
|
||||
filepath = envFile;
|
||||
} else {
|
||||
if (!taosCheckExistFile(filepath)) {
|
||||
uInfo("env file:%s not load", filepath);
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
}
|
||||
int64_t _bytes;
|
||||
|
@ -1422,7 +1407,7 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl
|
|||
memcpy(apolloUrl, p, TMIN(strlen(p) + 1, PATH_MAX));
|
||||
taosCloseFile(&pFile);
|
||||
uInfo("get apollo url from env file success");
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1430,7 +1415,7 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl
|
|||
}
|
||||
|
||||
uInfo("fail get apollo url from cmd env file");
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
struct SConfigIter {
|
||||
|
@ -1438,15 +1423,16 @@ struct SConfigIter {
|
|||
SConfig *pConf;
|
||||
};
|
||||
|
||||
SConfigIter *cfgCreateIter(SConfig *pConf) {
|
||||
int32_t cfgCreateIter(SConfig *pConf, SConfigIter **ppIter) {
|
||||
SConfigIter *pIter = taosMemoryCalloc(1, sizeof(SConfigIter));
|
||||
if (pIter == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pIter->pConf = pConf;
|
||||
return pIter;
|
||||
|
||||
*ppIter = pIter;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
SConfigItem *cfgNextIter(SConfigIter* pIter) {
|
||||
|
|
|
@ -51,7 +51,10 @@ TEST_F(CfgTest, 01_Str) {
|
|||
}
|
||||
|
||||
TEST_F(CfgTest, 02_Basic) {
|
||||
SConfig *pConfig = cfgInit();
|
||||
SConfig *pConfig = NULL;
|
||||
int32_t code = cfgInit(&pConfig);
|
||||
|
||||
ASSERT_EQ(code, TSDB_CODE_SUCCESS);
|
||||
ASSERT_NE(pConfig, nullptr);
|
||||
|
||||
EXPECT_EQ(cfgAddBool(pConfig, "test_bool", 0, 0, 0), 0);
|
||||
|
@ -66,7 +69,11 @@ TEST_F(CfgTest, 02_Basic) {
|
|||
int32_t size = cfgGetSize(pConfig);
|
||||
|
||||
SConfigItem* pItem = NULL;
|
||||
SConfigIter* pIter = cfgCreateIter(pConfig);
|
||||
SConfigIter *pIter = NULL;
|
||||
code = cfgCreateIter(pConfig, &pIter);
|
||||
ASSERT_EQ(code, TSDB_CODE_SUCCESS);
|
||||
ASSERT_NE(pIter, nullptr);
|
||||
|
||||
while((pItem = cfgNextIter(pIter)) != NULL) {
|
||||
switch (pItem->dtype) {
|
||||
case CFG_DTYPE_BOOL:
|
||||
|
|
Loading…
Reference in New Issue