diff --git a/include/common/ttime.h b/include/common/ttime.h index f50b5ee9d7..2d40bd93a6 100644 --- a/include/common/ttime.h +++ b/include/common/ttime.h @@ -86,11 +86,11 @@ void deltaToUtcInitOnce(); char getPrecisionUnit(int32_t precision); int64_t convertTimePrecision(int64_t ts, int32_t fromPrecision, int32_t toPrecision); -int64_t convertTimeFromPrecisionToUnit(int64_t ts, int32_t fromPrecision, char toUnit); +int32_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char toUnit, int64_t* pRes); int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec, int64_t* timeVal); int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision); -void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t ts, int32_t precision); +int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t ts, int32_t precision); struct STm { struct tm tm; diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index f7885caac0..4fca564804 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -35,7 +35,7 @@ void deltaToUtcInitOnce() { // printf("====delta:%lld\n\n", seconds); } -static int64_t parseFraction(char* str, char** end, int32_t timePrec); +static int32_t parseFraction(char* str, char** end, int32_t timePrec, int64_t* pFraction); static int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, char delim); static int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim); static int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim); @@ -95,7 +95,9 @@ char* forwardToTimeStringEnd(char* str) { return &str[i]; } -int64_t parseFraction(char* str, char** end, int32_t timePrec) { +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; @@ -112,7 +114,7 @@ int64_t parseFraction(char* str, char** end, int32_t timePrec) { int32_t totalLen = i; if (totalLen <= 0) { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } /* parse the fraction */ @@ -134,21 +136,24 @@ int64_t parseFraction(char* str, char** end, int32_t timePrec) { } times = NANO_SEC_FRACTION_LEN - i; } else { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } fraction = strnatoi(str, i) * factor[times]; *end = str + totalLen; + *pFraction = fraction; - return fraction; + TAOS_RETURN(TSDB_CODE_SUCCESS); } int32_t parseTimezone(char* str, int64_t* tzOffset) { + int32_t code = TSDB_CODE_SUCCESS; + int64_t hour = 0; int32_t i = 0; if (str[i] != '+' && str[i] != '-') { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } i++; @@ -160,7 +165,7 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) { continue; } - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } char* sep = strchr(&str[i], ':'); @@ -175,18 +180,18 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) { } if (hour > 12 || hour < 0) { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } // return error if there're illegal charaters after min(2 Digits) char* minStr = &str[i]; if (minStr[1] != '\0' && minStr[2] != '\0') { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } int64_t minute = strnatoi(&str[i], 2); if (minute > 59 || (hour == 12 && minute > 0)) { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } if (str[0] == '+') { @@ -195,13 +200,13 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) { *tzOffset = hour * 3600 + minute * 60; } - return 0; + TAOS_RETURN(TSDB_CODE_SUCCESS); } int32_t offsetOfTimezone(char* tzStr, int64_t* offset) { if (tzStr && (tzStr[0] == 'z' || tzStr[0] == 'Z')) { *offset = 0; - return 0; + return TSDB_CODE_SUCCESS; } return parseTimezone(tzStr, offset); } @@ -219,6 +224,8 @@ 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; @@ -234,7 +241,7 @@ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, ch } if (str == NULL) { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } /* mktime will be affected by TZ, set by using taos_options */ @@ -253,22 +260,18 @@ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, ch *time = seconds * factor; } else if (str[0] == '.') { str += 1; - if ((fraction = parseFraction(str, &str, timePrec)) < 0) { - return -1; - } + TAOS_CHECK_RETURN(parseFraction(str, &str, timePrec, &fraction)); *time = seconds * factor + fraction; char seg = str[0]; if (seg != 'Z' && seg != 'z' && seg != '+' && seg != '-') { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } else if ((seg == 'Z' || seg == 'z') && str[1] != '\0') { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } else if (seg == '+' || seg == '-') { // parse the timezone - if (parseTimezone(str, &tzOffset) == -1) { - return -1; - } + TAOS_CHECK_RETURN(parseTimezone(str, &tzOffset)); *time += tzOffset * factor; } @@ -277,16 +280,14 @@ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, ch *time = seconds * factor + fraction; // parse the timezone - if (parseTimezone(str, &tzOffset) == -1) { - return -1; - } + TAOS_CHECK_RETURN(parseTimezone(str, &tzOffset)); *time += tzOffset * factor; } else { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } - return 0; + TAOS_RETURN(TSDB_CODE_SUCCESS); } static FORCE_INLINE bool validateTm(struct tm* pTm) { @@ -314,6 +315,8 @@ 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}; @@ -330,7 +333,7 @@ int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timeP // if parse failed, try "%Y-%m-%d" format str = taosStrpTime(timestr, "%Y-%m-%d", &tm); if (str == NULL || (((str - timestr) < len) && (*str != '.')) || !validateTm(&tm)) { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } } @@ -347,16 +350,16 @@ int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timeP if (*str == '.') { /* parse the second fraction part */ - if ((fraction = parseFraction(str + 1, &str, timePrec)) < 0) { - return -1; - } + TAOS_CHECK_RETURN(parseFraction(str + 1, &str, timePrec, &fraction)); } *utime = TSDB_TICK_PER_SECOND(timePrec) * seconds + fraction; - return 0; + TAOS_RETURN(TSDB_CODE_SUCCESS); } 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; @@ -374,7 +377,7 @@ int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t ti // if parse failed, try "%Y-%m-%d" format str = taosStrpTime(timestr, "%Y-%m-%d", &tm); if (str == NULL || (((str - timestr) < len) && (*str != '.')) || !validateTm(&tm)) { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } } @@ -384,13 +387,11 @@ int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t ti int64_t fraction = 0; if (*str == '.') { /* parse the second fraction part */ - if ((fraction = parseFraction(str + 1, &str, timePrec)) < 0) { - return -1; - } + TAOS_CHECK_RETURN(parseFraction(str + 1, &str, timePrec, &fraction)); } *utime = TSDB_TICK_PER_SECOND(timePrec) * seconds + fraction; - return 0; + TAOS_RETURN(TSDB_CODE_SUCCESS); } char getPrecisionUnit(int32_t precision) { @@ -482,10 +483,12 @@ 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 -int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char toUnit) { +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) { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } int64_t factors[3] = {NANOSECOND_PER_MSEC, NANOSECOND_PER_USEC, 1}; @@ -541,15 +544,23 @@ int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char time *= factors[fromPrecision]; break; default: { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } } - if (tmp >= (double)INT64_MAX) return INT64_MAX; - if (tmp <= (double)INT64_MIN) return INT64_MIN; - return time; + if (tmp >= (double)INT64_MAX) { + *pRes = INT64_MAX; + } else if (tmp <= (double)INT64_MIN) { + *pRes = INT64_MIN; + } else { + *pRes = time; + } + + TAOS_RETURN(TSDB_CODE_SUCCESS); } 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) { @@ -558,7 +569,7 @@ int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec int32_t ret = taosParseTime(newColData, timeVal, charLen, (int32_t)timePrec, tsDaylight); if (ret != TSDB_CODE_SUCCESS) { taosMemoryFree(newColData); - return TSDB_CODE_INVALID_TIMESTAMP; + TAOS_RETURN(TSDB_CODE_INVALID_TIMESTAMP); } taosMemoryFree(newColData); } else if (type == TSDB_DATA_TYPE_NCHAR) { @@ -566,50 +577,52 @@ int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec int len = taosUcs4ToMbs((TdUcs4*)varDataVal(inputData), charLen, newColData); if (len < 0) { taosMemoryFree(newColData); - return TSDB_CODE_FAILED; + TAOS_RETURN(TSDB_CODE_FAILED); } newColData[len] = 0; int32_t ret = taosParseTime(newColData, timeVal, len, (int32_t)timePrec, tsDaylight); if (ret != TSDB_CODE_SUCCESS) { taosMemoryFree(newColData); - return ret; + TAOS_RETURN(ret); } taosMemoryFree(newColData); } else { - return TSDB_CODE_FAILED; + TAOS_RETURN(TSDB_CODE_FAILED); } - return TSDB_CODE_SUCCESS; + TAOS_RETURN(TSDB_CODE_SUCCESS); } 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) { - return -1; + TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); } (*result) = convertTimePrecision(val * MILLISECOND_PER_SECOND, TSDB_TIME_PRECISION_MILLI, timePrecision); break; case 'm': if (val > INT64_MAX / MILLISECOND_PER_MINUTE) { - return -1; + TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); } (*result) = convertTimePrecision(val * MILLISECOND_PER_MINUTE, TSDB_TIME_PRECISION_MILLI, timePrecision); break; case 'h': if (val > INT64_MAX / MILLISECOND_PER_MINUTE) { - return -1; + TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); } (*result) = convertTimePrecision(val * MILLISECOND_PER_HOUR, TSDB_TIME_PRECISION_MILLI, timePrecision); break; case 'd': if (val > INT64_MAX / MILLISECOND_PER_DAY) { - return -1; + TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); } (*result) = convertTimePrecision(val * MILLISECOND_PER_DAY, TSDB_TIME_PRECISION_MILLI, timePrecision); break; case 'w': if (val > INT64_MAX / MILLISECOND_PER_WEEK) { - return -1; + TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); } (*result) = convertTimePrecision(val * MILLISECOND_PER_WEEK, TSDB_TIME_PRECISION_MILLI, timePrecision); break; @@ -623,10 +636,10 @@ int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecisi (*result) = convertTimePrecision(val, TSDB_TIME_PRECISION_NANO, timePrecision); break; default: { - return -1; + TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); } } - return 0; + TAOS_RETURN(TSDB_CODE_SUCCESS); } /* @@ -645,47 +658,50 @@ 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; /* get the basic numeric value */ int64_t timestamp = taosStr2Int64(token, &endPtr, 10); if ((timestamp == 0 && token[0] != '0') || errno != 0) { - return -1; + TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); } /* natual month/year are not allowed in absolute duration */ *unit = token[tokenlen - 1]; if (*unit == 'n' || *unit == 'y') { - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } return getDuration(timestamp, *unit, duration, timePrecision); } -int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit, int32_t timePrecision, bool negativeAllow) { +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 */ *duration = taosStr2Int64(token, NULL, 10); if ((*duration < 0 && !negativeAllow) || errno != 0) { - return -1; + TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); } *unit = token[tokenLen - 1]; if (*unit == 'n' || *unit == 'y') { - return 0; + TAOS_RETURN(TSDB_CODE_SUCCESS); } - if(isdigit(*unit)) { + if (isdigit(*unit)) { *unit = getPrecisionUnit(timePrecision); } return getDuration(*duration, *unit, duration, timePrecision); } -static bool taosIsLeapYear(int32_t year) { - return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); -} +static bool taosIsLeapYear(int32_t year) { return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); } int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) { if (duration == 0) { @@ -900,7 +916,8 @@ int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) { // used together with taosTimeTruncate. when offset is great than zero, slide-start/slide-end is the anchor point int64_t taosTimeGetIntervalEnd(int64_t intervalStart, const SInterval* pInterval) { if (pInterval->offset > 0) { - int64_t slideStart = taosTimeAdd(intervalStart, -1 * pInterval->offset, pInterval->offsetUnit, pInterval->precision); + int64_t slideStart = + taosTimeAdd(intervalStart, -1 * pInterval->offset, pInterval->offsetUnit, pInterval->precision); int64_t slideEnd = taosTimeAdd(slideStart, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1; int64_t result = taosTimeAdd(slideEnd, pInterval->offset, pInterval->offsetUnit, pInterval->precision); return result; @@ -960,7 +977,9 @@ const char* fmtts(int64_t ts) { return buf; } -void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision) { +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; @@ -996,17 +1015,18 @@ void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision) default: fractionLen = 0; - return; + TAOS_RETURN(TSDB_CODE_INVALID_PARA); } if (taosLocalTime(", &ptm, buf) == NULL) { - return; + TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); } int32_t length = (int32_t)strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", &ptm); length += snprintf(ts + length, fractionLen, format, mod); length += (int32_t)strftime(ts + length, 40 - length, "%z", &ptm); tstrncpy(buf, ts, bufLen); + TAOS_RETURN(TSDB_CODE_SUCCESS); } int32_t taosTs2Tm(int64_t ts, int32_t precision, struct STm* tm) { @@ -1055,7 +1075,7 @@ typedef enum { TSFKW_Mon, TSFKW_MS, TSFKW_NS, - //TSFKW_OF, + // TSFKW_OF, TSFKW_PM, TSFKW_P_M, TSFKW_SS, @@ -1076,7 +1096,7 @@ typedef enum { TSFKW_day, TSFKW_ddd, TSFKW_dd, - TSFKW_dy, // mon, tue + TSFKW_dy, // mon, tue TSFKW_d, TSFKW_hh24, TSFKW_hh12, @@ -1268,7 +1288,7 @@ static void parseTsFormat(const char* formatStr, SArray* formats) { } if (*formatStr == '\\' && *(formatStr + 1)) { formatStr++; - last = NULL; // stop expanding last format, create new format + last = NULL; // stop expanding last format, create new format } if (last) { // expand @@ -1289,7 +1309,7 @@ static void parseTsFormat(const char* formatStr, SArray* formats) { // for other strings if (*formatStr == '\\' && *(formatStr + 1)) { formatStr++; - lastOtherFormat = NULL; // stop expanding + lastOtherFormat = NULL; // stop expanding } else { if (lastOtherFormat && !isSeperatorChar(*formatStr)) { // expanding @@ -1304,8 +1324,8 @@ static void parseTsFormat(const char* formatStr, SArray* formats) { formatStr++; } else { TSFormatNode format = { - .type = isSeperatorChar(*formatStr) ? TS_FORMAT_NODE_TYPE_SEPARATOR : TS_FORMAT_NODE_TYPE_CHAR, - .key = NULL}; + .type = isSeperatorChar(*formatStr) ? TS_FORMAT_NODE_TYPE_SEPARATOR : TS_FORMAT_NODE_TYPE_CHAR, + .key = NULL}; format.c = formatStr; format.len = 1; taosArrayPush(formats, &format); @@ -1318,7 +1338,7 @@ static void parseTsFormat(const char* formatStr, SArray* formats) { } static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int32_t outLen) { - int32_t size = taosArrayGetSize(formats); + int32_t size = taosArrayGetSize(formats); const char* start = s; for (int32_t i = 0; i < size; ++i) { TSFormatNode* format = taosArrayGet(formats, i); @@ -1923,8 +1943,8 @@ int32_t taosTs2Char(const char* format, SArray** formats, int64_t ts, int32_t pr return tm2char(*formats, &tm, out, outLen); } -int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int64_t* ts, int32_t precision, char* errMsg, - int32_t errMsgLen) { +int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int64_t* ts, int32_t precision, + char* errMsg, int32_t errMsgLen) { const char* sErrPos; int32_t fErrIdx; if (!*formats) { @@ -1977,26 +1997,27 @@ static int8_t UNIT_INDEX[26] = {/*a*/ 2, 0, -1, 6, -1, -1, -1, #define GET_UNIT_INDEX(idx) UNIT_INDEX[(idx) - 97] -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}, - /*ms*/ { 0, 1000, 1, 1000, 0}, - /*s*/ { 0, 0, 1000, 1, 60, 0}, - /*min*/ { 0, 0, 0, 60, 1, 60, 0}, - /*h*/ { 0, 0, 0, 0, 60, 1, 1, 0}, - /*d*/ { 0, 0, 0, 0, 0, 24, 1, 7, 1, 0}, - /*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}}; +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}, + /*ms*/ {0, 1000, 1, 1000, 0}, + /*s*/ {0, 0, 1000, 1, 60, 0}, + /*min*/ {0, 0, 0, 60, 1, 60, 0}, + /*h*/ {0, 0, 0, 0, 60, 1, 1, 0}, + /*d*/ {0, 0, 0, 0, 0, 24, 1, 7, 1, 0}, + /*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}}; -static bool recursiveTsmaCheckRecursive(int64_t baseInterval, int8_t baseIdx, int64_t interval, int8_t idx, bool checkEq) { +static bool recursiveTsmaCheckRecursive(int64_t baseInterval, int8_t baseIdx, int64_t interval, int8_t idx, + bool checkEq) { if (UNIT_MATRIX[baseIdx][idx] == -1) return false; if (baseIdx == idx) { if (interval < baseInterval) return false; if (checkEq && interval == baseInterval) return false; return interval % baseInterval == 0; } - int8_t next = baseIdx + 1; + int8_t next = baseIdx + 1; int64_t val = UNIT_MATRIX[baseIdx][next]; while (val != 0 && next <= idx) { if (val == -1) { @@ -2006,7 +2027,7 @@ static bool recursiveTsmaCheckRecursive(int64_t baseInterval, int8_t baseIdx, in } if (val % baseInterval == 0 || baseInterval % val == 0) { int8_t extra = baseInterval >= val ? 0 : 1; - bool needCheckEq = baseInterval >= val && !(baseIdx < next && val == 1); + bool needCheckEq = baseInterval >= val && !(baseIdx < next && val == 1); if (!recursiveTsmaCheckRecursive(baseInterval / val + extra, next, interval, idx, needCheckEq && checkEq)) { next++; val = UNIT_MATRIX[baseIdx][next]; @@ -2021,7 +2042,8 @@ static bool recursiveTsmaCheckRecursive(int64_t baseInterval, int8_t baseIdx, in return false; } -static bool recursiveTsmaCheckRecursiveReverse(int64_t baseInterval, int8_t baseIdx, int64_t interval, int8_t idx, bool checkEq) { +static bool recursiveTsmaCheckRecursiveReverse(int64_t baseInterval, int8_t baseIdx, int64_t interval, int8_t idx, + bool checkEq) { if (UNIT_MATRIX[baseIdx][idx] == -1) return false; if (baseIdx == idx) { @@ -2030,7 +2052,7 @@ static bool recursiveTsmaCheckRecursiveReverse(int64_t baseInterval, int8_t base return interval % baseInterval == 0; } - int8_t next = baseIdx - 1; + int8_t next = baseIdx - 1; int64_t val = UNIT_MATRIX[baseIdx][next]; while (val != 0 && next >= 0) { return recursiveTsmaCheckRecursiveReverse(baseInterval * val, next, interval, idx, checkEq); @@ -2041,18 +2063,27 @@ static bool recursiveTsmaCheckRecursiveReverse(int64_t baseInterval, int8_t base /* * @breif check if tsma with param [interval], [unit] can create based on base tsma with baseInterval and baseUnit * @param baseInterval, baseUnit, interval/unit of base tsma - * @param interval the tsma interval going to create. Not that if unit is not calander unit, then interval has already been - * translated to TICKS of [precision] + * @param interval the tsma interval going to create. Not that if unit is not calander unit, then interval has already + * been translated to TICKS of [precision] * @param unit the tsma unit going to create * @param precision the precision of this db * @param checkEq pass true if same interval is not acceptable, false if acceptable. * @ret true the tsma can be created, else cannot * */ -bool checkRecursiveTsmaInterval(int64_t baseInterval, int8_t baseUnit, int64_t interval, int8_t unit, int8_t precision, bool checkEq) { +bool checkRecursiveTsmaInterval(int64_t baseInterval, int8_t baseUnit, int64_t interval, int8_t unit, int8_t precision, + bool checkEq) { bool baseIsCalendarDuration = IS_CALENDAR_TIME_DURATION(baseUnit); - if (!baseIsCalendarDuration) baseInterval = convertTimeFromPrecisionToUnit(baseInterval, precision, baseUnit); + if (!baseIsCalendarDuration) { + if (TSDB_CODE_SUCCESS != convertTimeFromPrecisionToUnit(baseInterval, precision, baseUnit, &baseInterval)) { + return false; + } + } bool isCalendarDuration = IS_CALENDAR_TIME_DURATION(unit); - if (!isCalendarDuration) interval = convertTimeFromPrecisionToUnit(interval, precision, unit); + if (!isCalendarDuration) { + if (TSDB_CODE_SUCCESS != convertTimeFromPrecisionToUnit(interval, precision, unit, &interval)) { + return false; + } + } bool needCheckEq = baseIsCalendarDuration == isCalendarDuration && checkEq; diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 444ed3d750..894d888e2d 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -31,17 +31,18 @@ static bool mndCheckRetrieveFinished(SShowObj *pShow); static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq); int32_t mndInitShow(SMnode *pMnode) { + int32_t code = 0; SShowMgmt *pMgmt = &pMnode->showMgmt; pMgmt->cache = taosCacheInit(TSDB_DATA_TYPE_INT, 5000, true, (__cache_free_fn_t)mndFreeShowObj, "show"); if (pMgmt->cache == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("failed to alloc show cache since %s", terrstr()); - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + mError("failed to alloc show cache since %s", tstrerror(code)); + TAOS_RETURN(code); } mndSetMsgHandle(pMnode, TDMT_MND_SYSTABLE_RETRIEVE, mndProcessRetrieveSysTableReq); - return 0; + TAOS_RETURN(code); } void mndCleanupShow(SMnode *pMnode) { @@ -212,6 +213,7 @@ static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) { } static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { + int32_t code = 0; SMnode *pMnode = pReq->info.node; SShowMgmt *pMgmt = &pMnode->showMgmt; SShowObj *pShow = NULL; @@ -220,10 +222,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { int32_t rowsRead = 0; mDebug("mndProcessRetrieveSysTableReq start"); SRetrieveTableReq retrieveReq = {0}; - if (tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } + TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq)); mDebug("process to retrieve systable req db:%s, tb:%s", retrieveReq.db, retrieveReq.tb); @@ -232,17 +231,17 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { if (pMeta == NULL) { pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb)); if (pMeta == NULL) { - terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST; - mError("failed to process show-retrieve req:%p since %s", pShow, terrstr()); - return -1; + code = TSDB_CODE_PAR_TABLE_NOT_EXIST; + mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code)); + TAOS_RETURN(code); } } pShow = mndCreateShowObj(pMnode, &retrieveReq); if (pShow == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("failed to process show-meta req since %s", terrstr()); - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + mError("failed to process show-meta req since %s", tstrerror(code)); + TAOS_RETURN(code); } pShow->pMeta = pMeta; @@ -250,9 +249,9 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { } else { pShow = mndAcquireShowObj(pMnode, retrieveReq.showId); if (pShow == NULL) { - terrno = TSDB_CODE_MND_INVALID_SHOWOBJ; - mError("failed to process show-retrieve req:%p since %s", pShow, terrstr()); - return -1; + code = TSDB_CODE_MND_INVALID_SHOWOBJ; + mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code)); + TAOS_RETURN(code); } } @@ -264,9 +263,9 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type]; if (retrieveFp == NULL) { mndReleaseShowObj(pShow, false); - terrno = TSDB_CODE_MSG_NOT_PROCESSED; - mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); - return -1; + code = TSDB_CODE_MSG_NOT_PROCESSED; + mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code)); + TAOS_RETURN(code); } mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type); @@ -275,14 +274,16 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { } else { memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1); } - if (retrieveReq.db[0] && mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db) != 0) { - return -1; + code = -1; + if (retrieveReq.db[0] && + (code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) { + TAOS_RETURN(code); } if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) { if(strcmp(pReq->info.conn.user, "root") != 0){ mError("The operation is not permitted, user:%s, pShow->type:%d", pReq->info.conn.user, pShow->type); - terrno = TSDB_CODE_MND_NO_RIGHTS; - return -1; + code = TSDB_CODE_MND_NO_RIGHTS; + TAOS_RETURN(code); } } @@ -308,11 +309,11 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { } else { rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead); if (rowsRead < 0) { - terrno = rowsRead; + code = rowsRead; mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); mndReleaseShowObj(pShow, true); blockDataDestroy(pBlock); - return -1; + TAOS_RETURN(code); } pBlock->info.rows = rowsRead; @@ -325,10 +326,10 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size); if (pRsp == NULL) { mndReleaseShowObj(pShow, false); - terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); + code = TSDB_CODE_OUT_OF_MEMORY; + mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code)); blockDataDestroy(pBlock); - return -1; + TAOS_RETURN(code); } pRsp->handle = htobe64(pShow->id); diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 946df84a0f..108bafeb09 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -98,7 +98,7 @@ int32_t mndInitSma(SMnode *pMnode) { mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndRetrieveIdx); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndCancelRetrieveIdx); - + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_TSMA, mndProcessCreateTSMAReq); mndSetMsgHandle(pMnode, TDMT_MND_DROP_TSMA, mndProcessDropTSMAReq); mndSetMsgHandle(pMnode, TDMT_MND_GET_TABLE_TSMA, mndProcessGetTbTSMAReq); @@ -405,48 +405,74 @@ static void *mndBuildVDropSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSma, } static int32_t mndSetCreateSmaRedoLogs(SMnode *pMnode, STrans *pTrans, SSmaObj *pSma) { + int32_t code = 0; SSdbRaw *pRedoRaw = mndSmaActionEncode(pSma); - if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; - if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1; + if (pRedoRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING)); - return 0; + TAOS_RETURN(code); } static int32_t mndSetCreateSmaUndoLogs(SMnode* pMnode, STrans* pTrans, SSmaObj* pSma) { + int32_t code = 0; SSdbRaw * pUndoRaw = mndSmaActionEncode(pSma); - if (!pUndoRaw) return -1; - if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; - if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1; - return 0; + if (!pUndoRaw) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(mndTransAppendUndolog(pTrans, pUndoRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED)); + TAOS_RETURN(code); } static int32_t mndSetCreateSmaCommitLogs(SMnode *pMnode, STrans *pTrans, SSmaObj *pSma) { + int32_t code = 0; SSdbRaw *pCommitRaw = mndSmaActionEncode(pSma); - if (pCommitRaw == NULL) return -1; - if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; - if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; + if (pCommitRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)); - return 0; + TAOS_RETURN(code); } static int32_t mndSetCreateSmaVgroupRedoLogs(SMnode *pMnode, STrans *pTrans, SVgObj *pVgroup) { + int32_t code = 0; SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroup); - if (pVgRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pVgRaw) != 0) return -1; - if (sdbSetRawStatus(pVgRaw, SDB_STATUS_UPDATE) != 0) return -1; - return 0; + if (pVgRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pVgRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pVgRaw, SDB_STATUS_UPDATE)); + TAOS_RETURN(code); } static int32_t mndSetCreateSmaVgroupCommitLogs(SMnode *pMnode, STrans *pTrans, SVgObj *pVgroup) { + int32_t code = 0; SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroup); - if (pVgRaw == NULL) return -1; - if (mndTransAppendCommitlog(pTrans, pVgRaw) != 0) return -1; - if (sdbSetRawStatus(pVgRaw, SDB_STATUS_READY) != 0) return -1; - return 0; + if (pVgRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pVgRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pVgRaw, SDB_STATUS_READY)); + TAOS_RETURN(code); } static int32_t mndSetUpdateSmaStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) { + int32_t code = 0; SStbObj stbObj = {0}; taosRLockLatch(&pStb->lock); memcpy(&stbObj, pStb, sizeof(SStbObj)); @@ -462,18 +488,27 @@ static int32_t mndSetUpdateSmaStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStb stbObj.smaVer++; SSdbRaw *pCommitRaw = mndStbActionEncode(&stbObj); - if (pCommitRaw == NULL) return -1; - if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; - if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; + if (pCommitRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)); - return 0; + TAOS_RETURN(code); } static int32_t mndSetCreateSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SSmaObj *pSma) { + int32_t code = 0; SVnodeGid *pVgid = pVgroup->vnodeGid + 0; SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); - if (pDnode == NULL) return -1; + if (pDnode == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); @@ -481,12 +516,10 @@ static int32_t mndSetCreateSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans, // todo add sma info here SNode *pAst = NULL; - if (nodesStringToNode(pSma->ast, &pAst) < 0) { - return -1; - } - if (qExtractResultSchema(pAst, &pSma->schemaRow.nCols, &pSma->schemaRow.pSchema) != 0) { + TAOS_CHECK_RETURN(nodesStringToNode(pSma->ast, &pAst)); + if ((code = qExtractResultSchema(pAst, &pSma->schemaRow.nCols, &pSma->schemaRow.pSchema)) != 0) { nodesDestroyNode(pAst); - return -1; + TAOS_RETURN(code); } nodesDestroyNode(pAst); pSma->schemaRow.version = 1; @@ -496,7 +529,7 @@ static int32_t mndSetCreateSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans, pSma->schemaTag.version = 1; pSma->schemaTag.pSchema = taosMemoryCalloc(1, sizeof(SSchema)); if (!pSma->schemaTag.pSchema) { - return -1; + TAOS_RETURN(-1); } pSma->schemaTag.pSchema[0].type = TSDB_DATA_TYPE_BIGINT; pSma->schemaTag.pSchema[0].bytes = TYPE_BYTES[TSDB_DATA_TYPE_BIGINT]; @@ -506,14 +539,20 @@ static int32_t mndSetCreateSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans, int32_t smaContLen = 0; void *pSmaReq = mndBuildVCreateSmaReq(pMnode, pVgroup, pSma, &smaContLen); - if (pSmaReq == NULL) return -1; + if (pSmaReq == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } pVgroup->pTsma = pSmaReq; int32_t contLen = 0; void *pReq = mndBuildCreateVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen); if (pReq == NULL) { taosMemoryFreeClear(pSmaReq); - return -1; + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); } action.mTraceId = pTrans->mTraceId; @@ -522,10 +561,10 @@ static int32_t mndSetCreateSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans, action.msgType = TDMT_DND_CREATE_VNODE; action.acceptableCode = TSDB_CODE_VND_ALREADY_EXIST; - if (mndTransAppendRedoAction(pTrans, &action) != 0) { + if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) { taosMemoryFreeClear(pSmaReq); taosMemoryFree(pReq); - return -1; + TAOS_RETURN(code); } action.pCont = pSmaReq; @@ -533,12 +572,12 @@ static int32_t mndSetCreateSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans, action.msgType = TDMT_VND_CREATE_SMA; action.acceptableCode = TSDB_CODE_TSMA_ALREADY_EXIST; - if (mndTransAppendRedoAction(pTrans, &action) != 0) { + if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) { taosMemoryFreeClear(pSmaReq); - return -1; + TAOS_RETURN(code); } - return 0; + TAOS_RETURN(code); } static void mndDestroySmaObj(SSmaObj *pSmaObj) { @@ -550,10 +589,11 @@ static void mndDestroySmaObj(SSmaObj *pSmaObj) { static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCreate, SDbObj *pDb, SStbObj *pStb, const char *streamName) { + int32_t code = 0; if (pDb->cfg.replications > 1) { - terrno = TSDB_CODE_MND_INVALID_SMA_OPTION; + code = TSDB_CODE_MND_INVALID_SMA_OPTION; mError("sma:%s, failed to create since not support multiple replicas", pCreate->name); - return -1; + TAOS_RETURN(code); } SSmaObj smaObj = {0}; memcpy(smaObj.name, pCreate->name, TSDB_TABLE_FNAME_LEN); @@ -616,32 +656,37 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea // check the maxDelay if (streamObj.conf.triggerParam < TSDB_MIN_ROLLUP_MAX_DELAY) { - int64_t msInterval = convertTimeFromPrecisionToUnit(pCreate->interval, pDb->cfg.precision, TIME_UNIT_MILLISECOND); + int64_t msInterval = -1; + int32_t code = convertTimeFromPrecisionToUnit(pCreate->interval, pDb->cfg.precision, TIME_UNIT_MILLISECOND, &msInterval); + if (TSDB_CODE_SUCCESS != code) { + mError("sma:%s, failed to create since convert time failed: %s", smaObj.name, tstrerror(code)); + return code; + } streamObj.conf.triggerParam = msInterval > TSDB_MIN_ROLLUP_MAX_DELAY ? msInterval : TSDB_MIN_ROLLUP_MAX_DELAY; } if (streamObj.conf.triggerParam > TSDB_MAX_ROLLUP_MAX_DELAY) { streamObj.conf.triggerParam = TSDB_MAX_ROLLUP_MAX_DELAY; } - if (mndAllocSmaVgroup(pMnode, pDb, &streamObj.fixedSinkVg) != 0) { - mError("sma:%s, failed to create since %s", smaObj.name, terrstr()); - return -1; + if ((code = mndAllocSmaVgroup(pMnode, pDb, &streamObj.fixedSinkVg)) != 0) { + mError("sma:%s, failed to create since %s", smaObj.name, tstrerror(code)); + TAOS_RETURN(code); } smaObj.dstVgId = streamObj.fixedSinkVg.vgId; streamObj.fixedSinkVgId = smaObj.dstVgId; SNode *pAst = NULL; if (nodesStringToNode(streamObj.ast, &pAst) < 0) { - terrno = TSDB_CODE_MND_INVALID_SMA_OPTION; + code = TSDB_CODE_MND_INVALID_SMA_OPTION; mError("sma:%s, failed to create since parse ast error", smaObj.name); - return -1; + TAOS_RETURN(code); } // extract output schema from ast if (qExtractResultSchema(pAst, (int32_t *)&streamObj.outputSchema.nCols, &streamObj.outputSchema.pSchema) != 0) { - terrno = TSDB_CODE_MND_INVALID_SMA_OPTION; + code = TSDB_CODE_MND_INVALID_SMA_OPTION; mError("sma:%s, failed to create since extract result schema error", smaObj.name); - return -1; + TAOS_RETURN(code); } SQueryPlan *pPlan = NULL; @@ -655,39 +700,43 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea }; if (qCreateQueryPlan(&cxt, &pPlan, NULL) < 0) { - terrno = TSDB_CODE_MND_INVALID_SMA_OPTION; + code = TSDB_CODE_MND_INVALID_SMA_OPTION; mError("sma:%s, failed to create since create query plan error", smaObj.name); - return -1; + TAOS_RETURN(code); } // save physcial plan if (nodesNodeToString((SNode *)pPlan, false, &streamObj.physicalPlan, NULL) != 0) { - terrno = TSDB_CODE_MND_INVALID_SMA_OPTION; + code = TSDB_CODE_MND_INVALID_SMA_OPTION; mError("sma:%s, failed to create since save physcial plan error", smaObj.name); - return -1; + TAOS_RETURN(code); } if (pAst != NULL) nodesDestroyNode(pAst); nodesDestroyNode((SNode *)pPlan); - int32_t code = -1; + code = -1; STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq, "create-sma"); - if (pTrans == NULL) goto _OVER; + if (pTrans == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + goto _OVER; + } mndTransSetDbName(pTrans, pDb->name, NULL); - if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER); mndTransSetSerial(pTrans); mInfo("trans:%d, used to create sma:%s stream:%s", pTrans->id, pCreate->name, streamObj.name); - if (mndAddNewVgPrepareAction(pMnode, pTrans, &streamObj.fixedSinkVg) != 0) goto _OVER; - if (mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; - if (mndSetCreateSmaVgroupRedoLogs(pMnode, pTrans, &streamObj.fixedSinkVg) != 0) goto _OVER; - if (mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; - if (mndSetCreateSmaVgroupCommitLogs(pMnode, pTrans, &streamObj.fixedSinkVg) != 0) goto _OVER; - if (mndSetUpdateSmaStbCommitLogs(pMnode, pTrans, pStb) != 0) goto _OVER; - if (mndSetCreateSmaVgroupRedoActions(pMnode, pTrans, pDb, &streamObj.fixedSinkVg, &smaObj) != 0) goto _OVER; - if (mndScheduleStream(pMnode, &streamObj, 1685959190000, NULL) != 0) goto _OVER; - if (mndPersistStream(pTrans, &streamObj) != 0) goto _OVER; - if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndAddNewVgPrepareAction(pMnode, pTrans, &streamObj.fixedSinkVg), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetCreateSmaVgroupRedoLogs(pMnode, pTrans, &streamObj.fixedSinkVg), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetCreateSmaVgroupCommitLogs(pMnode, pTrans, &streamObj.fixedSinkVg), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetUpdateSmaStbCommitLogs(pMnode, pTrans, pStb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetCreateSmaVgroupRedoActions(pMnode, pTrans, pDb, &streamObj.fixedSinkVg, &smaObj), NULL, _OVER); + TAOS_CHECK_GOTO(mndScheduleStream(pMnode, &streamObj, 1685959190000, NULL), NULL, _OVER); + TAOS_CHECK_GOTO(mndPersistStream(pTrans, &streamObj), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); mInfo("sma:%s, uid:%" PRIi64 " create on stb:%" PRIi64 ", dstSuid:%" PRIi64 " dstTb:%s dstVg:%d", pCreate->name, smaObj.uid, smaObj.stbUid, smaObj.dstTbUid, smaObj.dstTbName, smaObj.dstVgId); @@ -698,35 +747,35 @@ _OVER: tFreeStreamObj(&streamObj); mndDestroySmaObj(&smaObj); mndTransDrop(pTrans); - return code; + TAOS_RETURN(code); } static int32_t mndCheckCreateSmaReq(SMCreateSmaReq *pCreate) { - terrno = TSDB_CODE_MND_INVALID_SMA_OPTION; - if (pCreate->name[0] == 0) return -1; - if (pCreate->stb[0] == 0) return -1; - if (pCreate->igExists < 0 || pCreate->igExists > 1) return -1; - if (pCreate->intervalUnit < 0) return -1; - if (pCreate->slidingUnit < 0) return -1; - if (pCreate->timezone < 0) return -1; - if (pCreate->interval < 0) return -1; - if (pCreate->offset < 0) return -1; - if (pCreate->sliding < 0) return -1; - if (pCreate->exprLen < 0) return -1; - if (pCreate->tagsFilterLen < 0) return -1; - if (pCreate->sqlLen < 0) return -1; - if (pCreate->astLen < 0) return -1; - if (pCreate->exprLen != 0 && strlen(pCreate->expr) + 1 != pCreate->exprLen) return -1; - if (pCreate->tagsFilterLen != 0 && strlen(pCreate->tagsFilter) + 1 != pCreate->tagsFilterLen) return -1; - if (pCreate->sqlLen != 0 && strlen(pCreate->sql) + 1 != pCreate->sqlLen) return -1; - if (pCreate->astLen != 0 && strlen(pCreate->ast) + 1 != pCreate->astLen) return -1; + int32_t code = TSDB_CODE_MND_INVALID_SMA_OPTION; + if (pCreate->name[0] == 0) TAOS_RETURN(code); + if (pCreate->stb[0] == 0) TAOS_RETURN(code); + if (pCreate->igExists < 0 || pCreate->igExists > 1) TAOS_RETURN(code); + if (pCreate->intervalUnit < 0) TAOS_RETURN(code); + if (pCreate->slidingUnit < 0) TAOS_RETURN(code); + if (pCreate->timezone < 0) TAOS_RETURN(code); + if (pCreate->interval < 0) TAOS_RETURN(code); + if (pCreate->offset < 0) TAOS_RETURN(code); + if (pCreate->sliding < 0) TAOS_RETURN(code); + if (pCreate->exprLen < 0) TAOS_RETURN(code); + if (pCreate->tagsFilterLen < 0) TAOS_RETURN(code); + if (pCreate->sqlLen < 0) TAOS_RETURN(code); + if (pCreate->astLen < 0) TAOS_RETURN(code); + if (pCreate->exprLen != 0 && strlen(pCreate->expr) + 1 != pCreate->exprLen) TAOS_RETURN(code); + if (pCreate->tagsFilterLen != 0 && strlen(pCreate->tagsFilter) + 1 != pCreate->tagsFilterLen) TAOS_RETURN(code); + if (pCreate->sqlLen != 0 && strlen(pCreate->sql) + 1 != pCreate->sqlLen) TAOS_RETURN(code); + if (pCreate->astLen != 0 && strlen(pCreate->ast) + 1 != pCreate->astLen) TAOS_RETURN(code); SName smaName = {0}; if (tNameFromString(&smaName, pCreate->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE) < 0) return -1; if (*(char *)tNameGetTableName(&smaName) == 0) return -1; - terrno = 0; - return 0; + code = 0; + TAOS_RETURN(code); } static void mndGetStreamNameFromSmaName(char *streamName, char *smaName) { @@ -746,22 +795,20 @@ static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq) { int64_t mTraceId = TRACE_GET_ROOTID(&pReq->info.traceId); - if (tDeserializeSMCreateSmaReq(pReq->pCont, pReq->contLen, &createReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - goto _OVER; - } + TAOS_CHECK_GOTO(tDeserializeSMCreateSmaReq(pReq->pCont, pReq->contLen, &createReq), NULL, _OVER); + #ifdef WINDOWS terrno = TSDB_CODE_MND_INVALID_PLATFORM; goto _OVER; #endif mInfo("sma:%s, start to create", createReq.name); - if (mndCheckCreateSmaReq(&createReq) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(mndCheckCreateSmaReq(&createReq), NULL, _OVER); pStb = mndAcquireStb(pMnode, createReq.stb); if (pStb == NULL) { mError("sma:%s, failed to create since stb:%s not exist", createReq.name, createReq.stb); + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; goto _OVER; } @@ -771,11 +818,11 @@ static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq) { pStream = mndAcquireStream(pMnode, streamName); if (pStream != NULL) { mError("sma:%s, failed to create since stream:%s already exist", createReq.name, streamName); - terrno = TSDB_CODE_MND_STREAM_ALREADY_EXIST; + code = TSDB_CODE_MND_STREAM_ALREADY_EXIST; goto _OVER; } SSIdx idx = {0}; - if (mndAcquireGlobalIdx(pMnode, createReq.name, SDB_SMA, &idx) == 0) { + if ((code = mndAcquireGlobalIdx(pMnode, createReq.name, SDB_SMA, &idx)) == 0) { pSma = idx.pIdx; } else { goto _OVER; @@ -787,27 +834,25 @@ static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq) { code = 0; goto _OVER; } else { - terrno = TSDB_CODE_MND_SMA_ALREADY_EXIST; + code = TSDB_CODE_MND_SMA_ALREADY_EXIST; goto _OVER; } } pDb = mndAcquireDbBySma(pMnode, createReq.name); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + code = TSDB_CODE_MND_DB_NOT_SELECTED; goto _OVER; } - if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb), NULL, _OVER); code = mndCreateSma(pMnode, pReq, &createReq, pDb, pStb, streamName); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { - mError("sma:%s, failed to create since %s", createReq.name, terrstr()); + mError("sma:%s, failed to create since %s", createReq.name, tstrerror(code)); } mndReleaseStb(pMnode, pStb); @@ -816,49 +861,74 @@ _OVER: mndReleaseDb(pMnode, pDb); tFreeSMCreateSmaReq(&createReq); - return code; + TAOS_RETURN(code); } static int32_t mndSetDropSmaRedoLogs(SMnode *pMnode, STrans *pTrans, SSmaObj *pSma) { + int32_t code = 0; SSdbRaw *pRedoRaw = mndSmaActionEncode(pSma); - if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; - if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1; + if (pRedoRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + return -1; + } + TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING)); return 0; } static int32_t mndSetDropSmaCommitLogs(SMnode *pMnode, STrans *pTrans, SSmaObj *pSma) { + int32_t code = 0; SSdbRaw *pCommitRaw = mndSmaActionEncode(pSma); - if (pCommitRaw == NULL) return -1; - if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; - if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; + if (pCommitRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + return -1; + } + TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED)); return 0; } static int32_t mndSetDropSmaVgroupRedoLogs(SMnode *pMnode, STrans *pTrans, SVgObj *pVgroup) { + int32_t code = 0; SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroup); - if (pVgRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pVgRaw) != 0) return -1; - if (sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPING) != 0) return -1; + if (pVgRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + return -1; + } + TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pVgRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPING)); return 0; } static int32_t mndSetDropSmaVgroupCommitLogs(SMnode *pMnode, STrans *pTrans, SVgObj *pVgroup) { + int32_t code = 0; SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroup); - if (pVgRaw == NULL) return -1; - if (mndTransAppendCommitlog(pTrans, pVgRaw) != 0) return -1; - if (sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPED) != 0) return -1; + if (pVgRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + return -1; + } + TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pVgRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPED)); return 0; } static int32_t mndSetDropSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) { + int32_t code = 0; SVnodeGid *pVgid = pVgroup->vnodeGid + 0; SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); - if (pDnode == NULL) return -1; + if (pDnode == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); @@ -866,19 +936,23 @@ static int32_t mndSetDropSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans, SD int32_t contLen = 0; void *pReq = mndBuildDropVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen); - if (pReq == NULL) return -1; + if (pReq == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } action.pCont = pReq; action.contLen = contLen; action.msgType = TDMT_DND_DROP_VNODE; action.acceptableCode = TSDB_CODE_VND_NOT_EXIST; - if (mndTransAppendRedoAction(pTrans, &action) != 0) { + if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) { taosMemoryFree(pReq); - return -1; + TAOS_RETURN(code); } - return 0; + TAOS_RETURN(code); } static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *pSma) { @@ -888,17 +962,29 @@ static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *p STrans *pTrans = NULL; pVgroup = mndAcquireVgroup(pMnode, pSma->dstVgId); - if (pVgroup == NULL) goto _OVER; + if (pVgroup == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + goto _OVER; + } pStb = mndAcquireStb(pMnode, pSma->stb); - if (pStb == NULL) goto _OVER; + if (pStb == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + goto _OVER; + } pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq, "drop-sma"); - if (pTrans == NULL) goto _OVER; + if (pTrans == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + goto _OVER; + } mInfo("trans:%d, used to drop sma:%s", pTrans->id, pSma->name); mndTransSetDbName(pTrans, pDb->name, NULL); - if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER); mndTransSetSerial(pTrans); @@ -910,26 +996,26 @@ static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *p sdbRelease(pMnode->pSdb, pStream); goto _OVER; } else { - if (mndStreamSetDropAction(pMnode, pTrans, pStream) < 0) { - mError("stream:%s, failed to drop task since %s", pStream->name, terrstr()); + if ((code = mndStreamSetDropAction(pMnode, pTrans, pStream)) < 0) { + mError("stream:%s, failed to drop task since %s", pStream->name, tstrerror(code)); sdbRelease(pMnode->pSdb, pStream); goto _OVER; } // drop stream - if (mndPersistTransLog(pStream, pTrans, SDB_STATUS_DROPPED) < 0) { - mError("stream:%s, failed to drop log since %s", pStream->name, terrstr()); + if ((code = mndPersistTransLog(pStream, pTrans, SDB_STATUS_DROPPED)) < 0) { + mError("stream:%s, failed to drop log since %s", pStream->name, tstrerror(code)); sdbRelease(pMnode->pSdb, pStream); goto _OVER; } } - if (mndSetDropSmaRedoLogs(pMnode, pTrans, pSma) != 0) goto _OVER; - if (mndSetDropSmaVgroupRedoLogs(pMnode, pTrans, pVgroup) != 0) goto _OVER; - if (mndSetDropSmaCommitLogs(pMnode, pTrans, pSma) != 0) goto _OVER; - if (mndSetDropSmaVgroupCommitLogs(pMnode, pTrans, pVgroup) != 0) goto _OVER; - if (mndSetUpdateSmaStbCommitLogs(pMnode, pTrans, pStb) != 0) goto _OVER; - if (mndSetDropSmaVgroupRedoActions(pMnode, pTrans, pDb, pVgroup) != 0) goto _OVER; - if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetDropSmaRedoLogs(pMnode, pTrans, pSma), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetDropSmaVgroupRedoLogs(pMnode, pTrans, pVgroup), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetDropSmaCommitLogs(pMnode, pTrans, pSma), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetDropSmaVgroupCommitLogs(pMnode, pTrans, pVgroup), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetUpdateSmaStbCommitLogs(pMnode, pTrans, pStb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetDropSmaVgroupRedoActions(pMnode, pTrans, pDb, pVgroup), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); code = 0; @@ -938,7 +1024,7 @@ _OVER: mndReleaseStream(pMnode, pStream); mndReleaseVgroup(pMnode, pVgroup); mndReleaseStb(pMnode, pStb); - return code; + TAOS_RETURN(code); } int32_t mndDropSmasByStb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { @@ -955,20 +1041,24 @@ int32_t mndDropSmasByStb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *p if (pSma->stbUid == pStb->uid) { mndTransSetSerial(pTrans); pVgroup = mndAcquireVgroup(pMnode, pSma->dstVgId); - if (pVgroup == NULL) goto _OVER; + if (pVgroup == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + goto _OVER; + } char streamName[TSDB_TABLE_FNAME_LEN] = {0}; mndGetStreamNameFromSmaName(streamName, pSma->name); SStreamObj *pStream = mndAcquireStream(pMnode, streamName); if (pStream != NULL && pStream->smaId == pSma->uid) { - if (mndStreamSetDropAction(pMnode, pTrans, pStream) < 0) { - mError("stream:%s, failed to drop task since %s", pStream->name, terrstr()); + if ((code = mndStreamSetDropAction(pMnode, pTrans, pStream)) < 0) { + mError("stream:%s, failed to drop task since %s", pStream->name, tstrerror(code)); mndReleaseStream(pMnode, pStream); goto _OVER; } - if (mndPersistTransLog(pStream, pTrans, SDB_STATUS_DROPPED) < 0) { + if ((code = mndPersistTransLog(pStream, pTrans, SDB_STATUS_DROPPED)) < 0) { mndReleaseStream(pMnode, pStream); goto _OVER; } @@ -976,9 +1066,9 @@ int32_t mndDropSmasByStb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *p mndReleaseStream(pMnode, pStream); } - if (mndSetDropSmaVgroupCommitLogs(pMnode, pTrans, pVgroup) != 0) goto _OVER; - if (mndSetDropSmaVgroupRedoActions(pMnode, pTrans, pDb, pVgroup) != 0) goto _OVER; - if (mndSetDropSmaCommitLogs(pMnode, pTrans, pSma) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetDropSmaVgroupCommitLogs(pMnode, pTrans, pVgroup), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetDropSmaVgroupRedoActions(pMnode, pTrans, pDb, pVgroup), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetDropSmaCommitLogs(pMnode, pTrans, pSma), NULL, _OVER); mndReleaseVgroup(pMnode, pVgroup); pVgroup = NULL; } @@ -992,10 +1082,11 @@ _OVER: sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pSma); mndReleaseVgroup(pMnode, pVgroup); - return code; + TAOS_RETURN(code); } int32_t mndDropSmasByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { + int32_t code = 0; SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; @@ -1005,17 +1096,17 @@ int32_t mndDropSmasByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { if (pIter == NULL) break; if (pSma->dbUid == pDb->uid) { - if (mndSetDropSmaCommitLogs(pMnode, pTrans, pSma) != 0) { + if ((code = mndSetDropSmaCommitLogs(pMnode, pTrans, pSma)) != 0) { sdbRelease(pSdb, pSma); sdbCancelFetch(pSdb, pSma); - return -1; + TAOS_RETURN(code); } } sdbRelease(pSdb, pSma); } - return 0; + TAOS_RETURN(code); } static int32_t mndProcessDropSmaReq(SRpcMsg *pReq) { @@ -1025,15 +1116,12 @@ static int32_t mndProcessDropSmaReq(SRpcMsg *pReq) { SSmaObj *pSma = NULL; SMDropSmaReq dropReq = {0}; - if (tDeserializeSMDropSmaReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - goto _OVER; - } + TAOS_CHECK_GOTO(tDeserializeSMDropSmaReq(pReq->pCont, pReq->contLen, &dropReq), NULL, _OVER); mInfo("sma:%s, start to drop", dropReq.name); SSIdx idx = {0}; - if (mndAcquireGlobalIdx(pMnode, dropReq.name, SDB_SMA, &idx) == 0) { + if ((code = mndAcquireGlobalIdx(pMnode, dropReq.name, SDB_SMA, &idx)) == 0) { pSma = idx.pIdx; } else { goto _OVER; @@ -1044,32 +1132,30 @@ static int32_t mndProcessDropSmaReq(SRpcMsg *pReq) { code = 0; goto _OVER; } else { - terrno = TSDB_CODE_MND_SMA_NOT_EXIST; + code = TSDB_CODE_MND_SMA_NOT_EXIST; goto _OVER; } } pDb = mndAcquireDbBySma(pMnode, dropReq.name); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + code = TSDB_CODE_MND_DB_NOT_SELECTED; goto _OVER; } - if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb), NULL, _OVER); code = mndDropSma(pMnode, pReq, pDb, pSma); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { - mError("sma:%s, failed to drop since %s", dropReq.name, terrstr()); + mError("sma:%s, failed to drop since %s", dropReq.name, tstrerror(code)); } mndReleaseSma(pMnode, pSma); mndReleaseDb(pMnode, pDb); - return code; + TAOS_RETURN(code); } static int32_t mndGetSma(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp *rsp, bool *exist) { @@ -1149,7 +1235,8 @@ int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool SVgObj *pVg = mndAcquireVgroup(pMnode, pSma->dstVgId); if (pVg == NULL) { - code = -1; + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; sdbRelease(pSdb, pSma); sdbCancelFetch(pSdb, pIter); return code; @@ -1158,8 +1245,7 @@ int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool info.expr = taosMemoryMalloc(pSma->exprLen + 1); if (info.expr == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - code = -1; + code = TSDB_CODE_OUT_OF_MEMORY; sdbRelease(pSdb, pSma); sdbCancelFetch(pSdb, pIter); return code; @@ -1169,8 +1255,7 @@ int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool info.expr[pSma->exprLen] = 0; if (NULL == taosArrayPush(rsp->pIndex, &info)) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - code = -1; + code = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFree(info.expr); sdbRelease(pSdb, pSma); sdbCancelFetch(pSdb, pIter); @@ -1183,7 +1268,7 @@ int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool sdbRelease(pSdb, pSma); } - return code; + TAOS_RETURN(code); } static int32_t mndProcessGetSmaReq(SRpcMsg *pReq) { @@ -1193,10 +1278,7 @@ static int32_t mndProcessGetSmaReq(SRpcMsg *pReq) { SUserIndexRsp rsp = {0}; bool exist = false; - if (tDeserializeSUserIndexReq(pReq->pCont, pReq->contLen, &indexReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - goto _OVER; - } + TAOS_CHECK_GOTO(tDeserializeSUserIndexReq(pReq->pCont, pReq->contLen, &indexReq), NULL, _OVER); code = mndGetSma(pMnode, &indexReq, &rsp, &exist); if (code) { @@ -1205,14 +1287,12 @@ static int32_t mndProcessGetSmaReq(SRpcMsg *pReq) { if (!exist) { // TODO GET INDEX FROM FULLTEXT - code = -1; - terrno = TSDB_CODE_MND_DB_INDEX_NOT_EXIST; + code = TSDB_CODE_MND_DB_INDEX_NOT_EXIST; } else { int32_t contLen = tSerializeSUserIndexRsp(NULL, 0, &rsp); void *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - code = -1; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } @@ -1226,10 +1306,10 @@ static int32_t mndProcessGetSmaReq(SRpcMsg *pReq) { _OVER: if (code != 0) { - mError("failed to get index %s since %s", indexReq.indexFName, terrstr()); + mError("failed to get index %s since %s", indexReq.indexFName, tstrerror(code)); } - return code; + TAOS_RETURN(code); } static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq) { @@ -1239,15 +1319,11 @@ static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq) { STableIndexRsp rsp = {0}; bool exist = false; - if (tDeserializeSTableIndexReq(pReq->pCont, pReq->contLen, &indexReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - goto _OVER; - } + TAOS_CHECK_GOTO(tDeserializeSTableIndexReq(pReq->pCont, pReq->contLen, &indexReq), NULL, _OVER); rsp.pIndex = taosArrayInit(10, sizeof(STableIndexInfo)); if (NULL == rsp.pIndex) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - code = -1; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } @@ -1257,14 +1333,12 @@ static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq) { } if (!exist) { - code = -1; - terrno = TSDB_CODE_MND_DB_INDEX_NOT_EXIST; + code = TSDB_CODE_MND_DB_INDEX_NOT_EXIST; } else { int32_t contLen = tSerializeSTableIndexRsp(NULL, 0, &rsp); void *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - code = -1; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } @@ -1278,11 +1352,11 @@ static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq) { _OVER: if (code != 0) { - mError("failed to get table index %s since %s", indexReq.tbFName, terrstr()); + mError("failed to get table index %s since %s", indexReq.tbFName, tstrerror(code)); } tFreeSerializeSTableIndexRsp(&rsp); - return code; + TAOS_RETURN(code); } static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { @@ -1500,27 +1574,37 @@ static void mndCreateTSMABuildDropStreamReq(SCreateTSMACxt* pCxt) { } static int32_t mndSetUpdateDbTsmaVersionPrepareLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOld, SDbObj *pNew) { + int32_t code = 0; SSdbRaw *pRedoRaw = mndDbActionEncode(pOld); - if (pRedoRaw == NULL) return -1; - if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) { + if (pRedoRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } + if ((code = mndTransAppendPrepareLog(pTrans, pRedoRaw)) != 0) { sdbFreeRaw(pRedoRaw); - return -1; + TAOS_RETURN(code); } (void)sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY); - return 0; + TAOS_RETURN(code); } static int32_t mndSetUpdateDbTsmaVersionCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOld, SDbObj *pNew) { + int32_t code = 0; SSdbRaw *pCommitRaw = mndDbActionEncode(pNew); - if (pCommitRaw == NULL) return -1; - if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { + if (pCommitRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } + if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) { sdbFreeRaw(pCommitRaw); - return -1; + TAOS_RETURN(code); } (void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); - return 0; + TAOS_RETURN(code); } static int32_t mndCreateTSMATxnPrepare(SCreateTSMACxt* pCxt) { @@ -1532,11 +1616,11 @@ static int32_t mndCreateTSMATxnPrepare(SCreateTSMACxt* pCxt) { STrans *pTrans = mndTransCreate(pCxt->pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pCxt->pRpcReq, "create-tsma"); if (!pTrans) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } mndTransSetDbName(pTrans, pCxt->pDb->name, NULL); - if (mndTransCheckConflict(pCxt->pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndTransCheckConflict(pCxt->pMnode, pTrans), NULL, _OVER); mndTransSetSerial(pTrans); mInfo("trans:%d, used to create tsma:%s stream:%s", pTrans->id, pCxt->pCreateSmaReq->name, @@ -1548,12 +1632,12 @@ static int32_t mndCreateTSMATxnPrepare(SCreateTSMACxt* pCxt) { createStreamRedoAction.contLen = tSerializeSCMCreateStreamReq(0, 0, pCxt->pCreateStreamReq); createStreamRedoAction.pCont = taosMemoryCalloc(1, createStreamRedoAction.contLen); if (!createStreamRedoAction.pCont) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } if (createStreamRedoAction.contLen != tSerializeSCMCreateStreamReq(createStreamRedoAction.pCont, createStreamRedoAction.contLen, pCxt->pCreateStreamReq)) { mError("sma: %s, failed to create due to create stream req encode failure", pCxt->pCreateSmaReq->name); - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } @@ -1563,12 +1647,12 @@ static int32_t mndCreateTSMATxnPrepare(SCreateTSMACxt* pCxt) { createStreamUndoAction.contLen = tSerializeSMDropStreamReq(0, 0, pCxt->pDropStreamReq); createStreamUndoAction.pCont = taosMemoryCalloc(1, createStreamUndoAction.contLen); if (!createStreamUndoAction.pCont) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } if (createStreamUndoAction.contLen != tSerializeSMDropStreamReq(createStreamUndoAction.pCont, createStreamUndoAction.contLen, pCxt->pDropStreamReq)) { mError("sma: %s, failed to create due to drop stream req encode failure", pCxt->pCreateSmaReq->name); - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } @@ -1581,37 +1665,37 @@ static int32_t mndCreateTSMATxnPrepare(SCreateTSMACxt* pCxt) { dropStbUndoAction.contLen = tSerializeSMDropStbReq(0, 0, &dropStbReq); dropStbUndoAction.pCont = taosMemoryCalloc(1, dropStbUndoAction.contLen); if (!dropStbUndoAction.pCont) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } if (dropStbUndoAction.contLen != tSerializeSMDropStbReq(dropStbUndoAction.pCont, dropStbUndoAction.contLen, &dropStbReq)) { mError("sma: %s, failed to create due to drop stb req encode failure", pCxt->pCreateSmaReq->name); - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } SDbObj newDb = {0}; memcpy(&newDb, pCxt->pDb, sizeof(SDbObj)); newDb.tsmaVersion++; - if (mndSetUpdateDbTsmaVersionPrepareLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb) != 0) goto _OVER; - if (mndSetUpdateDbTsmaVersionCommitLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb) != 0) goto _OVER; - if (mndSetCreateSmaRedoLogs(pCxt->pMnode, pTrans, pCxt->pSma) != 0) goto _OVER; - if (mndSetCreateSmaUndoLogs(pCxt->pMnode, pTrans, pCxt->pSma) != 0) goto _OVER; - if (mndSetCreateSmaCommitLogs(pCxt->pMnode, pTrans, pCxt->pSma) != 0) goto _OVER; - if (mndTransAppendRedoAction(pTrans, &createStreamRedoAction) != 0) goto _OVER; - if (mndTransAppendUndoAction(pTrans, &createStreamUndoAction) != 0) goto _OVER; - if (mndTransAppendUndoAction(pTrans, &dropStbUndoAction) != 0) goto _OVER; - if (mndTransPrepare(pCxt->pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetUpdateDbTsmaVersionPrepareLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetUpdateDbTsmaVersionCommitLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetCreateSmaRedoLogs(pCxt->pMnode, pTrans, pCxt->pSma), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetCreateSmaUndoLogs(pCxt->pMnode, pTrans, pCxt->pSma), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetCreateSmaCommitLogs(pCxt->pMnode, pTrans, pCxt->pSma), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransAppendRedoAction(pTrans, &createStreamRedoAction), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransAppendUndoAction(pTrans, &createStreamUndoAction), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransAppendUndoAction(pTrans, &dropStbUndoAction), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransPrepare(pCxt->pMnode, pTrans), NULL, _OVER); code = TSDB_CODE_SUCCESS; _OVER: mndTransDrop(pTrans); - return code; + TAOS_RETURN(code); } static int32_t mndCreateTSMA(SCreateTSMACxt *pCxt) { - int32_t code; + int32_t code = 0; SSmaObj sma = {0}; SCMCreateStreamReq createStreamReq = {0}; SMDropStreamReq dropStreamReq = {0}; @@ -1620,9 +1704,8 @@ static int32_t mndCreateTSMA(SCreateTSMACxt *pCxt) { initSMAObj(pCxt); SNodeList* pProjects = NULL; - terrno = nodesStringToList(pCxt->pCreateSmaReq->expr, &pProjects); - if (TSDB_CODE_SUCCESS != terrno) { - code = -1; + code = nodesStringToList(pCxt->pCreateSmaReq->expr, &pProjects); + if (TSDB_CODE_SUCCESS != code) { goto _OVER; } pCxt->pProjects = pProjects; @@ -1631,16 +1714,14 @@ static int32_t mndCreateTSMA(SCreateTSMACxt *pCxt) { if (pCxt->pCreateSmaReq->pVgroupVerList) { pCxt->pCreateStreamReq->pVgroupVerList = taosArrayDup(pCxt->pCreateSmaReq->pVgroupVerList, NULL); if (!pCxt->pCreateStreamReq->pVgroupVerList) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - code = -1; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } } if (LIST_LENGTH(pProjects) > 0) { createStreamReq.pCols = taosArrayInit(LIST_LENGTH(pProjects), sizeof(SField)); if (!createStreamReq.pCols) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - code = -1; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } } @@ -1648,8 +1729,7 @@ static int32_t mndCreateTSMA(SCreateTSMACxt *pCxt) { mndCreateTSMABuildCreateStreamReq(pCxt); mndCreateTSMABuildDropStreamReq(pCxt); - if (TSDB_CODE_SUCCESS != mndCreateTSMATxnPrepare(pCxt)) { - code = -1; + if (TSDB_CODE_SUCCESS != (code = mndCreateTSMATxnPrepare(pCxt))) { goto _OVER; } else { mInfo("sma:%s, uid:%" PRIi64 " create on stb:%" PRIi64 " dstTb:%s dstVg:%d", pCxt->pCreateSmaReq->name, sma.uid, @@ -1663,7 +1743,7 @@ _OVER: pCxt->pCreateStreamReq = NULL; if (pProjects) nodesDestroyList(pProjects); pCxt->pProjects = NULL; - return code; + TAOS_RETURN(code); } static void mndTSMAGenerateOutputName(const char* tsmaName, char* streamName, char* targetStbName) { @@ -1689,24 +1769,23 @@ static int32_t mndProcessCreateTSMAReq(SRpcMsg* pReq) { SMCreateSmaReq createReq = {0}; if (sdbGetSize(pMnode->pSdb, SDB_SMA) >= tsMaxTsmaNum) { - terrno = TSDB_CODE_MND_MAX_TSMA_NUM_EXCEEDED; + code = TSDB_CODE_MND_MAX_TSMA_NUM_EXCEEDED; goto _OVER; } if (tDeserializeSMCreateSmaReq(pReq->pCont, pReq->contLen, &createReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } mInfo("start to create tsma: %s", createReq.name); - if (mndCheckCreateSmaReq(&createReq)) - goto _OVER; + if ((code = mndCheckCreateSmaReq(&createReq)) != 0) goto _OVER; if (createReq.normSourceTbUid == 0) { pStb = mndAcquireStb(pMnode, createReq.stb); if (!pStb && !createReq.recursiveTsma) { mError("tsma:%s, failed to create since stb:%s not exist", createReq.name, createReq.stb); - terrno = TSDB_CODE_MND_STB_NOT_EXIST; + code = TSDB_CODE_MND_STB_NOT_EXIST; goto _OVER; } } @@ -1722,13 +1801,13 @@ static int32_t mndProcessCreateTSMAReq(SRpcMsg* pReq) { goto _OVER; } if (pSma) { - terrno = TSDB_CODE_MND_SMA_ALREADY_EXIST; + code = TSDB_CODE_MND_SMA_ALREADY_EXIST; goto _OVER; } SStbObj *pTargetStb = mndAcquireStb(pMnode, streamTargetStbFullName); if (pTargetStb) { - terrno = TSDB_CODE_TDB_STB_ALREADY_EXIST; + code = TSDB_CODE_TDB_STB_ALREADY_EXIST; mError("tsma: %s, failed to create since output stable already exists: %s", createReq.name, streamTargetStbFullName); goto _OVER; @@ -1737,25 +1816,23 @@ static int32_t mndProcessCreateTSMAReq(SRpcMsg* pReq) { pStream = mndAcquireStream(pMnode, streamName); if (pStream != NULL) { mError("tsma:%s, failed to create since stream:%s already exist", createReq.name, streamName); - terrno = TSDB_CODE_MND_SMA_ALREADY_EXIST; + code = TSDB_CODE_MND_SMA_ALREADY_EXIST; goto _OVER; } pDb = mndAcquireDbBySma(pMnode, createReq.name); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + code = TSDB_CODE_MND_DB_NOT_SELECTED; goto _OVER; } - if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb), NULL, _OVER); if (createReq.recursiveTsma) { pBaseTsma = sdbAcquire(pMnode->pSdb, SDB_SMA, createReq.baseTsmaName); if (!pBaseTsma) { mError("base tsma: %s not found when creating recursive tsma", createReq.baseTsmaName); - terrno = TSDB_CODE_MND_SMA_NOT_EXIST; + code = TSDB_CODE_MND_SMA_NOT_EXIST; goto _OVER; } if (!pStb) { @@ -1781,7 +1858,7 @@ static int32_t mndProcessCreateTSMAReq(SRpcMsg* pReq) { _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { - mError("tsma:%s, failed to create since %s", createReq.name, terrstr()); + mError("tsma:%s, failed to create since %s", createReq.name, tstrerror(code)); } if (pStb) mndReleaseStb(pMnode, pStb); @@ -1791,7 +1868,7 @@ _OVER: mndReleaseDb(pMnode, pDb); tFreeSMCreateSmaReq(&createReq); - return code; + TAOS_RETURN(code); } static int32_t mndDropTSMA(SCreateTSMACxt* pCxt) { @@ -1799,7 +1876,7 @@ static int32_t mndDropTSMA(SCreateTSMACxt* pCxt) { STransAction dropStreamRedoAction = {0}; STrans *pTrans = mndTransCreate(pCxt->pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pCxt->pRpcReq, "drop-tsma"); if (!pTrans) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } SMDropStreamReq dropStreamReq = {0}; @@ -1814,13 +1891,13 @@ static int32_t mndDropTSMA(SCreateTSMACxt* pCxt) { dropStreamRedoAction.contLen = tSerializeSMDropStreamReq(0, 0, pCxt->pDropStreamReq); dropStreamRedoAction.pCont = taosMemoryCalloc(1, dropStreamRedoAction.contLen); if (!dropStreamRedoAction.pCont) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } if (dropStreamRedoAction.contLen != tSerializeSMDropStreamReq(dropStreamRedoAction.pCont, dropStreamRedoAction.contLen, pCxt->pDropStreamReq)) { mError("tsma: %s, failed to drop due to drop stream req encode failure", pCxt->pDropSmaReq->name); - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } @@ -1838,30 +1915,30 @@ static int32_t mndDropTSMA(SCreateTSMACxt* pCxt) { dropStbRedoAction.contLen = tSerializeSMDropStbReq(0, 0, &dropStbReq); dropStbRedoAction.pCont = taosMemoryCalloc(1, dropStbRedoAction.contLen); if (!dropStbRedoAction.pCont) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } if (dropStbRedoAction.contLen != tSerializeSMDropStbReq(dropStbRedoAction.pCont, dropStbRedoAction.contLen, &dropStbReq)) { mError("tsma: %s, failedto drop due to drop stb req encode failure", pCxt->pDropSmaReq->name); - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } SDbObj newDb = {0}; memcpy(&newDb, pCxt->pDb, sizeof(SDbObj)); newDb.tsmaVersion++; - if (mndSetUpdateDbTsmaVersionPrepareLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb) != 0) goto _OVER; - if (mndSetUpdateDbTsmaVersionCommitLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb) != 0) goto _OVER; - if (mndSetDropSmaRedoLogs(pCxt->pMnode, pTrans, pCxt->pSma) != 0) goto _OVER; - if (mndSetDropSmaCommitLogs(pCxt->pMnode, pTrans, pCxt->pSma) != 0) goto _OVER; - if (mndTransAppendRedoAction(pTrans, &dropStreamRedoAction) != 0) goto _OVER; - if (mndTransAppendRedoAction(pTrans, &dropStbRedoAction) != 0) goto _OVER; - if (mndTransPrepare(pCxt->pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetUpdateDbTsmaVersionPrepareLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetUpdateDbTsmaVersionCommitLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetDropSmaRedoLogs(pCxt->pMnode, pTrans, pCxt->pSma), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetDropSmaCommitLogs(pCxt->pMnode, pTrans, pCxt->pSma), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransAppendRedoAction(pTrans, &dropStreamRedoAction), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransAppendRedoAction(pTrans, &dropStbRedoAction), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransPrepare(pCxt->pMnode, pTrans), NULL, _OVER); code = TSDB_CODE_SUCCESS; _OVER: tFreeMDropStreamReq(pCxt->pDropStreamReq); mndTransDrop(pTrans); - return code; + TAOS_RETURN(code); } static bool hasRecursiveTsmasBasedOnMe(SMnode* pMnode, const SSmaObj* pSma) { @@ -1887,7 +1964,7 @@ static int32_t mndProcessDropTSMAReq(SRpcMsg* pReq) { SDbObj * pDb = NULL; SMnode * pMnode = pReq->info.node; if (tDeserializeSMDropSmaReq(pReq->pCont, pReq->contLen, &dropReq) != TSDB_CODE_SUCCESS) { - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } @@ -1903,21 +1980,21 @@ static int32_t mndProcessDropTSMAReq(SRpcMsg* pReq) { goto _OVER; } if (!pSma) { - terrno = TSDB_CODE_MND_SMA_NOT_EXIST; + code = TSDB_CODE_MND_SMA_NOT_EXIST; goto _OVER; } pDb = mndAcquireDbBySma(pMnode, dropReq.name); if (!pDb) { - terrno = TSDB_CODE_MND_DB_NOT_EXIST; + code = TSDB_CODE_MND_DB_NOT_EXIST; goto _OVER; } - if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) { + if ((code = mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb)) != 0) { goto _OVER; } if (hasRecursiveTsmasBasedOnMe(pMnode, pSma)) { - terrno = TSDB_CODE_MND_INVALID_DROP_TSMA; + code = TSDB_CODE_MND_INVALID_DROP_TSMA; goto _OVER; } @@ -1939,7 +2016,7 @@ _OVER: mndReleaseStb(pMnode, pStb); mndReleaseSma(pMnode, pSma); mndReleaseDb(pMnode, pDb); - return code; + TAOS_RETURN(code); } static int32_t mndRetrieveTSMA(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { @@ -2104,7 +2181,7 @@ int32_t dumpTSMAInfoFromSmaObj(const SSmaObj* pSma, const SStbObj* pDestStb, STa funcInfo.funcId = pFuncNode->funcId; funcInfo.colId = ((SColumnNode *)pFuncNode->pParameterList->pHead->pNode)->colId; if (!taosArrayPush(pInfo->pFuncs, &funcInfo)) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; taosArrayDestroy(pInfo->pFuncs); nodesDestroyNode(pNode); return code; @@ -2136,7 +2213,7 @@ int32_t dumpTSMAInfoFromSmaObj(const SSmaObj* pSma, const SStbObj* pDestStb, STa } } } - return code; + TAOS_RETURN(code); } // @note remember to mndReleaseSma(*ppOut) @@ -2181,30 +2258,30 @@ static int32_t mndGetTSMA(SMnode *pMnode, char *tsmaFName, STableTSMAInfoRsp *rs STableTSMAInfo *pTsma = taosMemoryCalloc(1, sizeof(STableTSMAInfo)); if (!pTsma) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; sdbRelease(pMnode->pSdb, pSma); mndReleaseStb(pMnode, pDstStb); - return code; + TAOS_RETURN(code); } - terrno = mndGetDeepestBaseForTsma(pMnode, pSma, &pBaseTsma); - if (terrno == 0) { - terrno = dumpTSMAInfoFromSmaObj(pSma, pDstStb, pTsma, pBaseTsma); + code = mndGetDeepestBaseForTsma(pMnode, pSma, &pBaseTsma); + if (code == 0) { + code = dumpTSMAInfoFromSmaObj(pSma, pDstStb, pTsma, pBaseTsma); } mndReleaseStb(pMnode, pDstStb); sdbRelease(pMnode->pSdb, pSma); if (pBaseTsma) mndReleaseSma(pMnode, pBaseTsma); if (terrno) { tFreeTableTSMAInfo(pTsma); - return code; + TAOS_RETURN(code); } if (NULL == taosArrayPush(rsp->pTsmas, &pTsma)) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; tFreeTableTSMAInfo(pTsma); } *exist = true; } - return 0; + TAOS_RETURN(code); } typedef bool (*tsmaFilter)(const SSmaObj* pSma, void* param); @@ -2248,17 +2325,17 @@ static int32_t mndGetSomeTsmas(SMnode* pMnode, STableTSMAInfoRsp* pRsp, tsmaFilt STableTSMAInfo *pTsma = taosMemoryCalloc(1, sizeof(STableTSMAInfo)); if (!pTsma) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; mndReleaseStb(pMnode, pStb); sdbRelease(pSdb, pSma); sdbCancelFetch(pSdb, pIter); - return code; + TAOS_RETURN(code); } pTsma->streamUid = streamId; - terrno = mndGetDeepestBaseForTsma(pMnode, pSma, &pBaseTsma); - if (terrno == 0) { - terrno = dumpTSMAInfoFromSmaObj(pSma, pStb, pTsma, pBaseTsma); + code = mndGetDeepestBaseForTsma(pMnode, pSma, &pBaseTsma); + if (code == 0) { + code = dumpTSMAInfoFromSmaObj(pSma, pStb, pTsma, pBaseTsma); } mndReleaseStb(pMnode, pStb); sdbRelease(pSdb, pSma); @@ -2266,13 +2343,13 @@ static int32_t mndGetSomeTsmas(SMnode* pMnode, STableTSMAInfoRsp* pRsp, tsmaFilt if (terrno) { tFreeTableTSMAInfo(pTsma); sdbCancelFetch(pSdb, pIter); - return code; + TAOS_RETURN(code); } if (NULL == taosArrayPush(pRsp->pTsmas, &pTsma)) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; tFreeTableTSMAInfo(pTsma); sdbCancelFetch(pSdb, pIter); - return code; + TAOS_RETURN(code); } *exist = true; } @@ -2304,15 +2381,11 @@ static int32_t mndProcessGetTbTSMAReq(SRpcMsg *pReq) { bool exist = false; SMnode * pMnode = pReq->info.node; - if (tDeserializeTableTSMAInfoReq(pReq->pCont, pReq->contLen, &tsmaReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - goto _OVER; - } + TAOS_CHECK_GOTO(tDeserializeTableTSMAInfoReq(pReq->pCont, pReq->contLen, &tsmaReq), NULL, _OVER); rsp.pTsmas = taosArrayInit(4, POINTER_BYTES); if (NULL == rsp.pTsmas) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - code = -1; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } @@ -2326,14 +2399,12 @@ static int32_t mndProcessGetTbTSMAReq(SRpcMsg *pReq) { } if (!exist) { - code = -1; - terrno = TSDB_CODE_MND_SMA_NOT_EXIST; + code = TSDB_CODE_MND_SMA_NOT_EXIST; } else { int32_t contLen = tSerializeTableTSMAInfoRsp(NULL, 0, &rsp); void *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - code = -1; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } @@ -2347,7 +2418,7 @@ static int32_t mndProcessGetTbTSMAReq(SRpcMsg *pReq) { _OVER: tFreeTableTSMAInfoRsp(&rsp); - return code; + TAOS_RETURN(code); } static int32_t mkNonExistTSMAInfo(const STSMAVersion *pTsmaVer, STableTSMAInfo **ppTsma) { @@ -2377,8 +2448,8 @@ int32_t mndValidateTSMAInfo(SMnode *pMnode, STSMAVersion *pTsmaVersions, int32_t hbRsp.pTsmas = taosArrayInit(numOfTsmas, POINTER_BYTES); if (!hbRsp.pTsmas) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } for (int32_t i = 0; i < numOfTsmas; ++i) { @@ -2390,17 +2461,17 @@ int32_t mndValidateTSMAInfo(SMnode *pMnode, STSMAVersion *pTsmaVersions, int32_t snprintf(tsmaFName, sizeof(tsmaFName), "%s.%s", pTsmaVer->dbFName, pTsmaVer->name); SSmaObj* pSma = mndAcquireSma(pMnode, tsmaFName); if (!pSma) { - terrno = mkNonExistTSMAInfo(pTsmaVer, &pTsmaInfo); - if (terrno) goto _OVER; + code = mkNonExistTSMAInfo(pTsmaVer, &pTsmaInfo); + if (code) goto _OVER; taosArrayPush(hbRsp.pTsmas, &pTsmaInfo); continue; } if (pSma->uid != pTsmaVer->tsmaId) { mDebug("tsma: %s.%" PRIx64 " tsmaId mismatch with current %" PRIx64, tsmaFName, pTsmaVer->tsmaId, pSma->uid); - terrno = mkNonExistTSMAInfo(pTsmaVer, &pTsmaInfo); + code = mkNonExistTSMAInfo(pTsmaVer, &pTsmaInfo); mndReleaseSma(pMnode, pSma); - if (terrno) goto _OVER; + if (code) goto _OVER; taosArrayPush(hbRsp.pTsmas, &pTsmaInfo); continue; } else if (pSma->version == pTsmaVer->version) { @@ -2411,9 +2482,9 @@ int32_t mndValidateTSMAInfo(SMnode *pMnode, STSMAVersion *pTsmaVersions, int32_t SStbObj* pDestStb = mndAcquireStb(pMnode, pSma->dstTbName); if (!pDestStb) { mInfo("tsma: %s.%" PRIx64 " dest stb: %s not found, maybe dropped", tsmaFName, pTsmaVer->tsmaId, pSma->dstTbName); - terrno = mkNonExistTSMAInfo(pTsmaVer, &pTsmaInfo); + code = mkNonExistTSMAInfo(pTsmaVer, &pTsmaInfo); mndReleaseSma(pMnode, pSma); - if (terrno) goto _OVER; + if (code) goto _OVER; taosArrayPush(hbRsp.pTsmas, &pTsmaInfo); continue; } @@ -2422,15 +2493,15 @@ int32_t mndValidateTSMAInfo(SMnode *pMnode, STSMAVersion *pTsmaVersions, int32_t STableTSMAInfo * pInfo = NULL; pInfo = taosMemoryCalloc(1, sizeof(STableTSMAInfo)); if (!pInfo) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; mndReleaseSma(pMnode, pSma); mndReleaseStb(pMnode, pDestStb); goto _OVER; } SSmaObj* pBaseSma = NULL; - terrno = mndGetDeepestBaseForTsma(pMnode, pSma, &pBaseSma); - if (terrno == 0) terrno = dumpTSMAInfoFromSmaObj(pSma, pDestStb, pInfo, pBaseSma); + code = mndGetDeepestBaseForTsma(pMnode, pSma, &pBaseSma); + if (code == 0) code = dumpTSMAInfoFromSmaObj(pSma, pDestStb, pInfo, pBaseSma); mndReleaseStb(pMnode, pDestStb); mndReleaseSma(pMnode, pSma); @@ -2445,13 +2516,13 @@ int32_t mndValidateTSMAInfo(SMnode *pMnode, STSMAVersion *pTsmaVersions, int32_t rspLen = tSerializeTSMAHbRsp(NULL, 0, &hbRsp); if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } pRsp = taosMemoryMalloc(rspLen); if (!pRsp) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; rspLen = 0; goto _OVER; } @@ -2462,5 +2533,5 @@ _OVER: tFreeTSMAHbRsp(&hbRsp); *ppRsp = pRsp; *pRspLen = rspLen; - return code; + TAOS_RETURN(code); } diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index 4243ccb77c..e10fb394fc 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -170,38 +170,54 @@ static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOld, SSnodeObj *pNew } static int32_t mndSetCreateSnodeRedoLogs(STrans *pTrans, SSnodeObj *pObj) { + int32_t code = 0; SSdbRaw *pRedoRaw = mndSnodeActionEncode(pObj); - if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; - if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1; - return 0; + if (pRedoRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING)); + TAOS_RETURN(code); } static int32_t mndSetCreateSnodeUndoLogs(STrans *pTrans, SSnodeObj *pObj) { + int32_t code = 0; SSdbRaw *pUndoRaw = mndSnodeActionEncode(pObj); - if (pUndoRaw == NULL) return -1; - if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; - if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1; - return 0; + if (pUndoRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(mndTransAppendUndolog(pTrans, pUndoRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED)); + TAOS_RETURN(code); } static int32_t mndSetCreateSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { + int32_t code = 0; SSdbRaw *pCommitRaw = mndSnodeActionEncode(pObj); - if (pCommitRaw == NULL) return -1; - if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; - if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; - return 0; + if (pCommitRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)); + TAOS_RETURN(code); } static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { + int32_t code = 0; SDCreateSnodeReq createReq = {0}; createReq.dnodeId = pDnode->id; int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq); void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq); @@ -212,23 +228,24 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S action.msgType = TDMT_DND_CREATE_SNODE; action.acceptableCode = TSDB_CODE_SNODE_ALREADY_DEPLOYED; - if (mndTransAppendRedoAction(pTrans, &action) != 0) { + if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) { taosMemoryFree(pReq); - return -1; + TAOS_RETURN(code); } - return 0; + TAOS_RETURN(code); } static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { + int32_t code = 0; SDDropSnodeReq dropReq = {0}; dropReq.dnodeId = pDnode->id; int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq); void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq); @@ -239,12 +256,12 @@ static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S action.msgType = TDMT_DND_DROP_SNODE; action.acceptableCode = TSDB_CODE_SNODE_NOT_DEPLOYED; - if (mndTransAppendUndoAction(pTrans, &action) != 0) { + if ((code = mndTransAppendUndoAction(pTrans, &action)) != 0) { taosMemoryFree(pReq); - return -1; + TAOS_RETURN(code); } - return 0; + TAOS_RETURN(code); } static int32_t mndCreateSnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMCreateSnodeReq *pCreate) { @@ -256,23 +273,27 @@ static int32_t mndCreateSnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, snodeObj.updateTime = snodeObj.createdTime; STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "create-snode"); - if (pTrans == NULL) goto _OVER; + if (pTrans == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + goto _OVER; + } mndTransSetSerial(pTrans); mInfo("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId); - if (mndSetCreateSnodeRedoLogs(pTrans, &snodeObj) != 0) goto _OVER; - if (mndSetCreateSnodeUndoLogs(pTrans, &snodeObj) != 0) goto _OVER; - if (mndSetCreateSnodeCommitLogs(pTrans, &snodeObj) != 0) goto _OVER; - if (mndSetCreateSnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) goto _OVER; - if (mndSetCreateSnodeUndoActions(pTrans, pDnode, &snodeObj) != 0) goto _OVER; - if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetCreateSnodeRedoLogs(pTrans, &snodeObj), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetCreateSnodeUndoLogs(pTrans, &snodeObj), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetCreateSnodeCommitLogs(pTrans, &snodeObj), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetCreateSnodeRedoActions(pTrans, pDnode, &snodeObj), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetCreateSnodeUndoActions(pTrans, pDnode, &snodeObj), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); code = 0; _OVER: mndTransDrop(pTrans); - return code; + TAOS_RETURN(code); } static int32_t mndProcessCreateSnodeReq(SRpcMsg *pReq) { @@ -282,32 +303,27 @@ static int32_t mndProcessCreateSnodeReq(SRpcMsg *pReq) { SDnodeObj *pDnode = NULL; SMCreateSnodeReq createReq = {0}; - if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - goto _OVER; - } + TAOS_CHECK_GOTO(tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq), NULL, _OVER); mInfo("snode:%d, start to create", createReq.dnodeId); - if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_SNODE) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_SNODE), NULL, _OVER); -// pObj = mndAcquireSnode(pMnode, createReq.dnodeId); -// if (pObj != NULL) { -// terrno = TSDB_CODE_MND_SNODE_ALREADY_EXIST; -// goto _OVER; -// } else if (terrno != TSDB_CODE_MND_SNODE_NOT_EXIST) { -// goto _OVER; -// } + // pObj = mndAcquireSnode(pMnode, createReq.dnodeId); + // if (pObj != NULL) { + // terrno = TSDB_CODE_MND_SNODE_ALREADY_EXIST; + // goto _OVER; + // } else if (terrno != TSDB_CODE_MND_SNODE_NOT_EXIST) { + // goto _OVER; + // } if (sdbGetSize(pMnode->pSdb, SDB_SNODE) >= 1){ - terrno = TSDB_CODE_MND_SNODE_ALREADY_EXIST; + code = TSDB_CODE_MND_SNODE_ALREADY_EXIST; goto _OVER; } pDnode = mndAcquireDnode(pMnode, createReq.dnodeId); if (pDnode == NULL) { - terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + code = TSDB_CODE_MND_DNODE_NOT_EXIST; goto _OVER; } @@ -316,41 +332,52 @@ static int32_t mndProcessCreateSnodeReq(SRpcMsg *pReq) { _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { - mError("snode:%d, failed to create since %s", createReq.dnodeId, terrstr()); - return -1; + mError("snode:%d, failed to create since %s", createReq.dnodeId, tstrerror(code)); + TAOS_RETURN(code); } // mndReleaseSnode(pMnode, pObj); mndReleaseDnode(pMnode, pDnode); tFreeSMCreateQnodeReq(&createReq); - return code; + TAOS_RETURN(code); } static int32_t mndSetDropSnodeRedoLogs(STrans *pTrans, SSnodeObj *pObj) { + int32_t code = 0; SSdbRaw *pRedoRaw = mndSnodeActionEncode(pObj); - if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; - if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1; - return 0; + if (pRedoRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING)); + TAOS_RETURN(code); } static int32_t mndSetDropSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { + int32_t code = 0; SSdbRaw *pCommitRaw = mndSnodeActionEncode(pObj); - if (pCommitRaw == NULL) return -1; - if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; - if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; - return 0; + if (pCommitRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw)); + TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED)); + TAOS_RETURN(code); } static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { + int32_t code = 0; SDDropSnodeReq dropReq = {0}; dropReq.dnodeId = pDnode->id; int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq); void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq); @@ -361,20 +388,20 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn action.msgType = TDMT_DND_DROP_SNODE; action.acceptableCode = TSDB_CODE_SNODE_NOT_DEPLOYED; - if (mndTransAppendRedoAction(pTrans, &action) != 0) { + if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) { taosMemoryFree(pReq); - return -1; + TAOS_RETURN(code); } - return 0; + TAOS_RETURN(code); } int32_t mndSetDropSnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SSnodeObj *pObj, bool force) { if (pObj == NULL) return 0; - if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) return -1; - if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) return -1; + TAOS_CHECK_RETURN(mndSetDropSnodeRedoLogs(pTrans, pObj)); + TAOS_CHECK_RETURN(mndSetDropSnodeCommitLogs(pTrans, pObj)); if (!force) { - if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1; + TAOS_CHECK_RETURN(mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj)); } return 0; } @@ -383,18 +410,22 @@ static int32_t mndDropSnode(SMnode *pMnode, SRpcMsg *pReq, SSnodeObj *pObj) { int32_t code = -1; STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq, "drop-snode"); - if (pTrans == NULL) goto _OVER; + if (pTrans == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + goto _OVER; + } mndTransSetSerial(pTrans); mInfo("trans:%d, used to drop snode:%d", pTrans->id, pObj->id); - if (mndSetDropSnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER; - if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetDropSnodeInfoToTrans(pMnode, pTrans, pObj, false), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); code = 0; _OVER: mndTransDrop(pTrans); - return code; + TAOS_RETURN(code); } static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) { @@ -403,23 +434,20 @@ static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) { SSnodeObj *pObj = NULL; SMDropSnodeReq dropReq = {0}; - if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - goto _OVER; - } + TAOS_CHECK_GOTO(tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq), NULL, _OVER); mInfo("snode:%d, start to drop", dropReq.dnodeId); - if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_SNODE) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_SNODE), NULL, _OVER); if (dropReq.dnodeId <= 0) { - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } pObj = mndAcquireSnode(pMnode, dropReq.dnodeId); if (pObj == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; goto _OVER; } @@ -429,12 +457,12 @@ static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) { _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { - mError("snode:%d, failed to drop since %s", dropReq.dnodeId, terrstr()); + mError("snode:%d, failed to drop since %s", dropReq.dnodeId, tstrerror(code)); } mndReleaseSnode(pMnode, pObj); tFreeSMCreateQnodeReq(&dropReq); - return code; + TAOS_RETURN(code); } static int32_t mndRetrieveSnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 73542bbb1e..d4b086f32f 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -625,87 +625,99 @@ static void *mndBuildVDropStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, } int32_t mndCheckCreateStbReq(SMCreateStbReq *pCreate) { + int32_t code = 0; if (pCreate->igExists < 0 || pCreate->igExists > 1) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_OPTION; + TAOS_RETURN(code); } if (pCreate->numOfColumns < TSDB_MIN_COLUMNS || pCreate->numOfTags + pCreate->numOfColumns > TSDB_MAX_COLUMNS) { - terrno = TSDB_CODE_PAR_INVALID_COLUMNS_NUM; - return -1; + code = TSDB_CODE_PAR_INVALID_COLUMNS_NUM; + TAOS_RETURN(code); } if (pCreate->numOfTags <= 0 || pCreate->numOfTags > TSDB_MAX_TAGS) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_OPTION; + TAOS_RETURN(code); } SField *pField = taosArrayGet(pCreate->pColumns, 0); if (pField->type != TSDB_DATA_TYPE_TIMESTAMP) { - terrno = TSDB_CODE_PAR_INVALID_FIRST_COLUMN; - return -1; + code = TSDB_CODE_PAR_INVALID_FIRST_COLUMN; + TAOS_RETURN(code); } for (int32_t i = 0; i < pCreate->numOfColumns; ++i) { SFieldWithOptions *pField1 = taosArrayGet(pCreate->pColumns, i); if (pField1->type >= TSDB_DATA_TYPE_MAX) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_OPTION; + TAOS_RETURN(code); } if (pField1->bytes <= 0) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_OPTION; + TAOS_RETURN(code); } if (pField1->name[0] == 0) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_OPTION; + TAOS_RETURN(code); } } for (int32_t i = 0; i < pCreate->numOfTags; ++i) { SField *pField1 = taosArrayGet(pCreate->pTags, i); if (pField1->type >= TSDB_DATA_TYPE_MAX) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_OPTION; + TAOS_RETURN(code); } if (pField1->bytes <= 0) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_OPTION; + TAOS_RETURN(code); } if (pField1->name[0] == 0) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_OPTION; + TAOS_RETURN(code); } } - return 0; + TAOS_RETURN(code); } static int32_t mndSetCreateStbPrepareLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { + int32_t code = 0; SSdbRaw *pRedoRaw = mndStbActionEncode(pStb); - if (pRedoRaw == NULL) return -1; - if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) { - sdbFreeRaw(pRedoRaw); - return -1; + if (pRedoRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); } - if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1; + if ((code = mndTransAppendPrepareLog(pTrans, pRedoRaw)) != 0) { + sdbFreeRaw(pRedoRaw); + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING)); - return 0; + TAOS_RETURN(code); } static int32_t mndSetCreateStbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { + int32_t code = 0; SSdbRaw *pCommitRaw = mndStbActionEncode(pStb); - if (pCommitRaw == NULL) return -1; - if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { - sdbFreeRaw(pCommitRaw); - return -1; + if (pCommitRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); } - if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; + if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) { + sdbFreeRaw(pCommitRaw); + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)); - return 0; + TAOS_RETURN(code); } static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { + int32_t code = 0; SSdb *pSdb = pMnode->pSdb; SVgObj *pVgroup = NULL; void *pIter = NULL; @@ -723,7 +735,9 @@ static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj if (pReq == NULL) { sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); - return -1; + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); } STransAction action = {0}; @@ -734,25 +748,28 @@ static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.msgType = TDMT_VND_CREATE_STB; action.acceptableCode = TSDB_CODE_TDB_STB_ALREADY_EXIST; action.retryCode = TSDB_CODE_TDB_STB_NOT_EXIST; - if (mndTransAppendRedoAction(pTrans, &action) != 0) { + if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) { taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); - return -1; + TAOS_RETURN(code); } sdbRelease(pSdb, pVgroup); } - return 0; + TAOS_RETURN(code); } int32_t mndSetForceDropCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SVgObj *pVgroup, SStbObj *pStb) { + int32_t code = 0; SSdb *pSdb = pMnode->pSdb; int32_t contLen; void *pReq = mndBuildVCreateStbReq(pMnode, pVgroup, pStb, &contLen, NULL, 0); if (pReq == NULL) { - return -1; + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); } STransAction action = {0}; @@ -763,15 +780,16 @@ int32_t mndSetForceDropCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SVgO action.msgType = TDMT_VND_CREATE_STB; action.acceptableCode = TSDB_CODE_TDB_STB_ALREADY_EXIST; action.retryCode = TSDB_CODE_TDB_STB_NOT_EXIST; - if (mndTransAppendRedoAction(pTrans, &action) != 0) { + if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) { taosMemoryFree(pReq); - return -1; + TAOS_RETURN(code); } - return 0; + TAOS_RETURN(code); } static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { + int32_t code = 0; SSdb *pSdb = pMnode->pSdb; SVgObj *pVgroup = NULL; void *pIter = NULL; @@ -789,8 +807,8 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj if (pReq == NULL) { sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } STransAction action = {0}; @@ -799,16 +817,16 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.contLen = contLen; action.msgType = TDMT_VND_DROP_STB; action.acceptableCode = TSDB_CODE_TDB_STB_NOT_EXIST; - if (mndTransAppendUndoAction(pTrans, &action) != 0) { + if ((code = mndTransAppendUndoAction(pTrans, &action)) != 0) { taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); - return -1; + TAOS_RETURN(code); } sdbRelease(pSdb, pVgroup); } - return 0; + TAOS_RETURN(code); } static SSchema *mndFindStbColumns(const SStbObj *pStb, const char *colName) { @@ -822,6 +840,7 @@ static SSchema *mndFindStbColumns(const SStbObj *pStb, const char *colName) { } int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreate, SDbObj *pDb) { + int32_t code = 0; memcpy(pDst->name, pCreate->name, TSDB_TABLE_FNAME_LEN); memcpy(pDst->db, pDb->name, TSDB_DB_FNAME_LEN); pDst->createdTime = taosGetTimestampMs(); @@ -850,8 +869,8 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat if (pDst->commentLen > 0) { pDst->comment = taosMemoryCalloc(pDst->commentLen + 1, 1); if (pDst->comment == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } memcpy(pDst->comment, pCreate->pComment, pDst->commentLen + 1); } @@ -860,8 +879,8 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat if (pDst->ast1Len > 0) { pDst->pAst1 = taosMemoryCalloc(pDst->ast1Len, 1); if (pDst->pAst1 == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } memcpy(pDst->pAst1, pCreate->pAst1, pDst->ast1Len); } @@ -870,8 +889,8 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat if (pDst->ast2Len > 0) { pDst->pAst2 = taosMemoryCalloc(pDst->ast2Len, 1); if (pDst->pAst2 == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } memcpy(pDst->pAst2, pCreate->pAst2, pDst->ast2Len); } @@ -879,13 +898,13 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat pDst->pColumns = taosMemoryCalloc(1, pDst->numOfColumns * sizeof(SSchema)); pDst->pTags = taosMemoryCalloc(1, pDst->numOfTags * sizeof(SSchema)); if (pDst->pColumns == NULL || pDst->pTags == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } if (pDst->nextColId < 0 || pDst->nextColId >= 0x7fff - pDst->numOfColumns - pDst->numOfTags) { - terrno = TSDB_CODE_OUT_OF_RANGE; - return -1; + code = TSDB_CODE_OUT_OF_RANGE; + TAOS_RETURN(code); } for (int32_t i = 0; i < pDst->numOfColumns; ++i) { @@ -921,7 +940,7 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat pColCmpr->id = pSchema->colId; pColCmpr->alg = pField->compress; } - return 0; + TAOS_RETURN(code); } static int32_t mndGenIdxNameForFirstTag(char *fullname, char *dbname, char *stbname, char *tagname) { SName name = {0}; @@ -936,16 +955,20 @@ static int32_t mndCreateStb(SMnode *pMnode, SRpcMsg *pReq, SMCreateStbReq *pCrea char fullIdxName[TSDB_INDEX_FNAME_LEN * 2] = {0}; STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq, "create-stb"); - if (pTrans == NULL) goto _OVER; + if (pTrans == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + goto _OVER; + } mInfo("trans:%d, used to create stb:%s", pTrans->id, pCreate->name); - if (mndBuildStbFromReq(pMnode, &stbObj, pCreate, pDb) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndBuildStbFromReq(pMnode, &stbObj, pCreate, pDb), NULL, _OVER); SSchema *pSchema = &(stbObj.pTags[0]); mndGenIdxNameForFirstTag(fullIdxName, pDb->name, stbObj.name, pSchema->name); SSIdx idx = {0}; if (mndAcquireGlobalIdx(pMnode, fullIdxName, SDB_IDX, &idx) == 0 && idx.pIdx != NULL) { - terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST; + code = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST; mndReleaseIdx(pMnode, idx.pIdx); goto _OVER; } @@ -960,24 +983,24 @@ static int32_t mndCreateStb(SMnode *pMnode, SRpcMsg *pReq, SMCreateStbReq *pCrea idxObj.stbUid = stbObj.uid; idxObj.dbUid = stbObj.dbUid; - if (mndSetCreateIdxCommitLogs(pMnode, pTrans, &idxObj) < 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetCreateIdxCommitLogs(pMnode, pTrans, &idxObj), NULL, _OVER); - if (mndAddStbToTrans(pMnode, pTrans, pDb, &stbObj) < 0) goto _OVER; - if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndAddStbToTrans(pMnode, pTrans, pDb, &stbObj), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); code = 0; _OVER: mndTransDrop(pTrans); mndStbActionDelete(pMnode->pSdb, &stbObj); - return code; + TAOS_RETURN(code); } int32_t mndAddStbToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { mndTransSetDbName(pTrans, pDb->name, pStb->name); - if (mndTransCheckConflict(pMnode, pTrans) != 0) return -1; - if (mndSetCreateStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) return -1; - if (mndSetCreateStbRedoActions(pMnode, pTrans, pDb, pStb) != 0) return -1; - if (mndSetCreateStbUndoActions(pMnode, pTrans, pDb, pStb) != 0) return -1; + TAOS_CHECK_RETURN (mndTransCheckConflict(pMnode, pTrans)); + TAOS_CHECK_RETURN (mndSetCreateStbCommitLogs(pMnode, pTrans, pDb, pStb)); + TAOS_CHECK_RETURN (mndSetCreateStbRedoActions(pMnode, pTrans, pDb, pStb)); + TAOS_CHECK_RETURN (mndSetCreateStbUndoActions(pMnode, pTrans, pDb, pStb)); return 0; } @@ -1130,6 +1153,7 @@ static bool mndValidateSchema(SSchema *pSchemas, int32_t nSchema, SArray *pField } static int32_t mndBuildStbFromAlter(SStbObj *pStb, SStbObj *pDst, SMCreateStbReq *createReq) { + int32_t code = 0; taosRLockLatch(&pStb->lock); memcpy(pDst, pStb, sizeof(SStbObj)); taosRUnLockLatch(&pStb->lock); @@ -1143,13 +1167,13 @@ static int32_t mndBuildStbFromAlter(SStbObj *pStb, SStbObj *pDst, SMCreateStbReq pDst->pCmpr = taosMemoryCalloc(1, pDst->numOfColumns * sizeof(SColCmpr)); if (pDst->pColumns == NULL || pDst->pTags == NULL || pDst->pCmpr == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } if (pDst->nextColId < 0 || pDst->nextColId >= 0x7fff - pDst->numOfColumns - pDst->numOfTags) { - terrno = TSDB_CODE_OUT_OF_RANGE; - return -1; + code = TSDB_CODE_OUT_OF_RANGE; + TAOS_RETURN(code); } for (int32_t i = 0; i < pDst->numOfColumns; ++i) { @@ -1205,13 +1229,13 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) { bool isAlter = false; if (tDeserializeSMCreateStbReq(pReq->pCont, pReq->contLen, &createReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } mInfo("stb:%s, start to create", createReq.name); if (mndCheckCreateStbReq(&createReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } @@ -1241,17 +1265,17 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) { mInfo("stb:%s, schema version is only increased by 1 number, do alter operation", createReq.name); } else { mError("stb:%s, schema version increase more than 1 number, error is returned", createReq.name); - terrno = TSDB_CODE_MND_INVALID_SCHEMA_VER; + code = TSDB_CODE_MND_INVALID_SCHEMA_VER; goto _OVER; } } else { mError("stb:%s, already exist while create, input tagVer:%d colVer:%d is invalid, origin tagVer:%d colVer:%d", createReq.name, createReq.tagVer, createReq.colVer, pStb->tagVer, pStb->colVer); - terrno = TSDB_CODE_MND_INVALID_SCHEMA_VER; + code = TSDB_CODE_MND_INVALID_SCHEMA_VER; goto _OVER; } } else { - terrno = TSDB_CODE_MND_STB_ALREADY_EXIST; + code = TSDB_CODE_MND_STB_ALREADY_EXIST; goto _OVER; } } else if (terrno != TSDB_CODE_MND_STB_NOT_EXIST) { @@ -1265,33 +1289,32 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) { pDb = mndAcquireDbByStb(pMnode, createReq.name); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + code = TSDB_CODE_MND_DB_NOT_SELECTED; goto _OVER; } - if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) { + if ((code = mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb)) != 0) { goto _OVER; } int32_t numOfStbs = -1; - if (mndGetNumOfStbs(pMnode, pDb->name, &numOfStbs) != 0) { + if ((code = mndGetNumOfStbs(pMnode, pDb->name, &numOfStbs)) != 0) { goto _OVER; } if (pDb->cfg.numOfStables == 1 && numOfStbs != 0) { - terrno = TSDB_CODE_MND_SINGLE_STB_MODE_DB; + code = TSDB_CODE_MND_SINGLE_STB_MODE_DB; goto _OVER; } - if ((terrno = grantCheck(TSDB_GRANT_STABLE)) < 0) { - code = -1; + if ((code = grantCheck(TSDB_GRANT_STABLE)) < 0) { goto _OVER; } if (isAlter) { bool needRsp = false; SStbObj pDst = {0}; - if (mndBuildStbFromAlter(pStb, &pDst, &createReq) != 0) { + if ((code = mndBuildStbFromAlter(pStb, &pDst, &createReq)) != 0) { taosMemoryFreeClear(pDst.pTags); taosMemoryFreeClear(pDst.pColumns); taosMemoryFreeClear(pDst.pCmpr); @@ -1321,34 +1344,35 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) { } _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { - mError("stb:%s, failed to create since %s", createReq.name, terrstr()); + mError("stb:%s, failed to create since %s", createReq.name, tstrerror(code)); } mndReleaseStb(pMnode, pStb); mndReleaseDb(pMnode, pDb); tFreeSMCreateStbReq(&createReq); - return code; + TAOS_RETURN(code); } static int32_t mndCheckAlterStbReq(SMAlterStbReq *pAlter) { + int32_t code = 0; if (pAlter->commentLen >= 0) return 0; if (pAlter->ttl != 0) return 0; if (pAlter->numOfFields < 1 || pAlter->numOfFields != (int32_t)taosArrayGetSize(pAlter->pFields)) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_OPTION; + TAOS_RETURN(code); } for (int32_t i = 0; i < pAlter->numOfFields; ++i) { SField *pField = taosArrayGet(pAlter->pFields, i); if (pField->name[0] == 0) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_OPTION; + TAOS_RETURN(code); } } - return 0; + TAOS_RETURN(code); } int32_t mndAllocStbSchemas(const SStbObj *pOld, SStbObj *pNew) { @@ -1356,19 +1380,19 @@ int32_t mndAllocStbSchemas(const SStbObj *pOld, SStbObj *pNew) { pNew->pColumns = taosMemoryCalloc(pNew->numOfColumns, sizeof(SSchema)); pNew->pCmpr = taosMemoryCalloc(pNew->numOfColumns, sizeof(SColCmpr)); if (pNew->pTags == NULL || pNew->pColumns == NULL || pNew->pCmpr == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); } memcpy(pNew->pColumns, pOld->pColumns, sizeof(SSchema) * pOld->numOfColumns); memcpy(pNew->pTags, pOld->pTags, sizeof(SSchema) * pOld->numOfTags); memcpy(pNew->pCmpr, pOld->pCmpr, sizeof(SColCmpr) * pOld->numOfColumns); - return 0; + TAOS_RETURN(0); } static int32_t mndUpdateStbCommentAndTTL(const SStbObj *pOld, SStbObj *pNew, char *pComment, int32_t commentLen, int32_t ttl) { + int32_t code = 0; if (commentLen > 0) { pNew->commentLen = commentLen; pNew->comment = taosMemoryCalloc(1, commentLen + 1); @@ -1386,48 +1410,49 @@ static int32_t mndUpdateStbCommentAndTTL(const SStbObj *pOld, SStbObj *pNew, cha pNew->ttl = ttl; } - if (mndAllocStbSchemas(pOld, pNew) != 0) { - return -1; + if ((code = mndAllocStbSchemas(pOld, pNew)) != 0) { + TAOS_RETURN(code); } - return 0; + TAOS_RETURN(code); } static int32_t mndAddSuperTableTag(const SStbObj *pOld, SStbObj *pNew, SArray *pFields, int32_t ntags) { + int32_t code = 0; if (pOld->numOfTags + ntags > TSDB_MAX_TAGS) { - terrno = TSDB_CODE_MND_TOO_MANY_TAGS; - return -1; + code = TSDB_CODE_MND_TOO_MANY_TAGS; + TAOS_RETURN(code); } if (pOld->numOfColumns + ntags + pOld->numOfTags > TSDB_MAX_COLUMNS) { - terrno = TSDB_CODE_MND_TOO_MANY_COLUMNS; - return -1; + code = TSDB_CODE_MND_TOO_MANY_COLUMNS; + TAOS_RETURN(code); } if (!mndValidateSchema(pOld->pTags, pOld->numOfTags, pFields, TSDB_MAX_TAGS_LEN)) { - terrno = TSDB_CODE_PAR_INVALID_TAGS_LENGTH; - return -1; + code = TSDB_CODE_PAR_INVALID_TAGS_LENGTH; + TAOS_RETURN(code); } pNew->numOfTags = pNew->numOfTags + ntags; - if (mndAllocStbSchemas(pOld, pNew) != 0) { - return -1; + if ((code = mndAllocStbSchemas(pOld, pNew)) != 0) { + TAOS_RETURN(code); } if (pNew->nextColId < 0 || pNew->nextColId >= 0x7fff - ntags) { - terrno = TSDB_CODE_OUT_OF_RANGE; - return -1; + code = TSDB_CODE_OUT_OF_RANGE; + TAOS_RETURN(code); } for (int32_t i = 0; i < ntags; i++) { SField *pField = taosArrayGet(pFields, i); if (mndFindSuperTableColumnIndex(pOld, pField->name) >= 0) { - terrno = TSDB_CODE_MND_COLUMN_ALREADY_EXIST; - return -1; + code = TSDB_CODE_MND_COLUMN_ALREADY_EXIST; + TAOS_RETURN(code); } if (mndFindSuperTableTagIndex(pOld, pField->name) >= 0) { - terrno = TSDB_CODE_MND_TAG_ALREADY_EXIST; - return -1; + code = TSDB_CODE_MND_TAG_ALREADY_EXIST; + TAOS_RETURN(code); } SSchema *pSchema = &pNew->pTags[pOld->numOfTags + i]; @@ -1441,10 +1466,11 @@ static int32_t mndAddSuperTableTag(const SStbObj *pOld, SStbObj *pNew, SArray *p } pNew->tagVer++; - return 0; + TAOS_RETURN(code); } static int32_t mndCheckAlterColForTopic(SMnode *pMnode, const char *stbFullName, int64_t suid, col_id_t colId) { + int32_t code = 0; SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; while (1) { @@ -1461,11 +1487,11 @@ static int32_t mndCheckAlterColForTopic(SMnode *pMnode, const char *stbFullName, SNode *pAst = NULL; if (nodesStringToNode(pTopic->ast, &pAst) != 0) { - terrno = TSDB_CODE_MND_FIELD_CONFLICT_WITH_TOPIC; + code = TSDB_CODE_MND_FIELD_CONFLICT_WITH_TOPIC; mError("topic:%s, create ast error", pTopic->name); sdbRelease(pSdb, pTopic); sdbCancelFetch(pSdb, pIter); - return -1; + TAOS_RETURN(code); } SNodeList *pNodeList = NULL; @@ -1481,13 +1507,13 @@ static int32_t mndCheckAlterColForTopic(SMnode *pMnode, const char *stbFullName, goto NEXT; } if (pCol->colId > 0 && pCol->colId == colId) { - terrno = TSDB_CODE_MND_FIELD_CONFLICT_WITH_TOPIC; + code = TSDB_CODE_MND_FIELD_CONFLICT_WITH_TOPIC; mError("topic:%s, check colId:%d conflicted", pTopic->name, pCol->colId); nodesDestroyNode(pAst); nodesDestroyList(pNodeList); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pTopic); - return -1; + TAOS_RETURN(code); } mInfo("topic:%s, check colId:%d passed", pTopic->name, pCol->colId); } @@ -1497,10 +1523,11 @@ static int32_t mndCheckAlterColForTopic(SMnode *pMnode, const char *stbFullName, nodesDestroyNode(pAst); nodesDestroyList(pNodeList); } - return 0; + TAOS_RETURN(code); } static int32_t mndCheckAlterColForStream(SMnode *pMnode, const char *stbFullName, int64_t suid, col_id_t colId) { + int32_t code = 0; SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; while (1) { @@ -1510,11 +1537,11 @@ static int32_t mndCheckAlterColForStream(SMnode *pMnode, const char *stbFullName SNode *pAst = NULL; if (nodesStringToNode(pStream->ast, &pAst) != 0) { - terrno = TSDB_CODE_MND_INVALID_STREAM_OPTION; + code = TSDB_CODE_MND_INVALID_STREAM_OPTION; mError("stream:%s, create ast error", pStream->name); sdbRelease(pSdb, pStream); sdbCancelFetch(pSdb, pIter); - return -1; + TAOS_RETURN(code); } SNodeList *pNodeList = NULL; @@ -1528,13 +1555,13 @@ static int32_t mndCheckAlterColForStream(SMnode *pMnode, const char *stbFullName goto NEXT; } if (pCol->colId > 0 && pCol->colId == colId) { - terrno = TSDB_CODE_MND_STREAM_MUST_BE_DELETED; + code = TSDB_CODE_MND_STREAM_MUST_BE_DELETED; mError("stream:%s, check colId:%d conflicted", pStream->name, pCol->colId); nodesDestroyNode(pAst); nodesDestroyList(pNodeList); sdbRelease(pSdb, pStream); sdbCancelFetch(pSdb, pIter); - return -1; + TAOS_RETURN(code); } mInfo("stream:%s, check colId:%d passed", pStream->name, pCol->colId); } @@ -1544,10 +1571,11 @@ static int32_t mndCheckAlterColForStream(SMnode *pMnode, const char *stbFullName nodesDestroyNode(pAst); nodesDestroyList(pNodeList); } - return 0; + TAOS_RETURN(code); } static int32_t mndCheckAlterColForTSma(SMnode *pMnode, const char *stbFullName, int64_t suid, col_id_t colId) { + int32_t code = 0; SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; while (1) { @@ -1560,11 +1588,11 @@ static int32_t mndCheckAlterColForTSma(SMnode *pMnode, const char *stbFullName, SNode *pAst = NULL; if (nodesStringToNode(pSma->ast, &pAst) != 0) { - terrno = TSDB_CODE_SDB_INVALID_DATA_CONTENT; + code = TSDB_CODE_SDB_INVALID_DATA_CONTENT; mError("tsma:%s, check tag and column modifiable, stb:%s suid:%" PRId64 " colId:%d failed since parse AST err", pSma->name, stbFullName, suid, colId); sdbCancelFetch(pSdb, pIter); - return -1; + TAOS_RETURN(code); } SNodeList *pNodeList = NULL; @@ -1579,13 +1607,13 @@ static int32_t mndCheckAlterColForTSma(SMnode *pMnode, const char *stbFullName, goto NEXT; } if ((pCol->colId) > 0 && (pCol->colId == colId)) { - terrno = TSDB_CODE_MND_FIELD_CONFLICT_WITH_TSMA; + code = TSDB_CODE_MND_FIELD_CONFLICT_WITH_TSMA; mError("tsma:%s, check colId:%d conflicted", pSma->name, pCol->colId); nodesDestroyNode(pAst); nodesDestroyList(pNodeList); sdbRelease(pSdb, pSma); sdbCancelFetch(pSdb, pIter); - return -1; + TAOS_RETURN(code); } mInfo("tsma:%s, check colId:%d passed", pSma->name, pCol->colId); } @@ -1595,38 +1623,28 @@ static int32_t mndCheckAlterColForTSma(SMnode *pMnode, const char *stbFullName, nodesDestroyNode(pAst); nodesDestroyList(pNodeList); } - return 0; + TAOS_RETURN(code); } int32_t mndCheckColAndTagModifiable(SMnode *pMnode, const char *stbFullName, int64_t suid, col_id_t colId) { - if (mndCheckAlterColForTopic(pMnode, stbFullName, suid, colId) < 0) { - return -1; - } - if (mndCheckAlterColForStream(pMnode, stbFullName, suid, colId) < 0) { - return -1; - } - - if (mndCheckAlterColForTSma(pMnode, stbFullName, suid, colId) < 0) { - return -1; - } - return 0; + TAOS_CHECK_RETURN(mndCheckAlterColForTopic(pMnode, stbFullName, suid, colId)); + TAOS_CHECK_RETURN(mndCheckAlterColForStream(pMnode, stbFullName, suid, colId)); + TAOS_CHECK_RETURN(mndCheckAlterColForTSma(pMnode, stbFullName, suid, colId)); + TAOS_RETURN(0); } static int32_t mndDropSuperTableTag(SMnode *pMnode, const SStbObj *pOld, SStbObj *pNew, const char *tagName) { + int32_t code = 0; int32_t tag = mndFindSuperTableTagIndex(pOld, tagName); if (tag < 0) { - terrno = TSDB_CODE_MND_TAG_NOT_EXIST; - return -1; + code = TSDB_CODE_MND_TAG_NOT_EXIST; + TAOS_RETURN(code); } col_id_t colId = pOld->pTags[tag].colId; - if (mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId) != 0) { - return -1; - } + TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId)); - if (mndAllocStbSchemas(pOld, pNew) != 0) { - return -1; - } + TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew)); memmove(pNew->pTags + tag, pNew->pTags + tag + 1, sizeof(SSchema) * (pNew->numOfTags - tag - 1)); pNew->numOfTags--; @@ -1637,13 +1655,14 @@ static int32_t mndDropSuperTableTag(SMnode *pMnode, const SStbObj *pOld, SStbObj // return -1; // } mInfo("stb:%s, start to drop tag %s", pNew->name, tagName); - return 0; + TAOS_RETURN(code); } static int32_t mndAlterStbTagName(SMnode *pMnode, const SStbObj *pOld, SStbObj *pNew, SArray *pFields) { + int32_t code = 0; if ((int32_t)taosArrayGetSize(pFields) != 2) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_OPTION; + TAOS_RETURN(code); } SField *pField0 = taosArrayGet(pFields, 0); @@ -1654,48 +1673,43 @@ static int32_t mndAlterStbTagName(SMnode *pMnode, const SStbObj *pOld, SStbObj * int32_t tag = mndFindSuperTableTagIndex(pOld, oldTagName); if (tag < 0) { - terrno = TSDB_CODE_MND_TAG_NOT_EXIST; - return -1; + code = TSDB_CODE_MND_TAG_NOT_EXIST; + TAOS_RETURN(code); } col_id_t colId = pOld->pTags[tag].colId; - if (mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId) != 0) { - return -1; - } + TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId)); if (mndFindSuperTableTagIndex(pOld, newTagName) >= 0) { - terrno = TSDB_CODE_MND_TAG_ALREADY_EXIST; - return -1; + code = TSDB_CODE_MND_TAG_ALREADY_EXIST; + TAOS_RETURN(code); } if (mndFindSuperTableColumnIndex(pOld, newTagName) >= 0) { - terrno = TSDB_CODE_MND_COLUMN_ALREADY_EXIST; - return -1; + code = TSDB_CODE_MND_COLUMN_ALREADY_EXIST; + TAOS_RETURN(code); } - if (mndAllocStbSchemas(pOld, pNew) != 0) { - return -1; - } + TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew)); SSchema *pSchema = (SSchema *)(pNew->pTags + tag); memcpy(pSchema->name, newTagName, TSDB_COL_NAME_LEN); pNew->tagVer++; mInfo("stb:%s, start to modify tag %s to %s", pNew->name, oldTagName, newTagName); - return 0; + TAOS_RETURN(code); } static int32_t mndAlterStbTagBytes(SMnode *pMnode, const SStbObj *pOld, SStbObj *pNew, const SField *pField) { + int32_t code = 0; int32_t tag = mndFindSuperTableTagIndex(pOld, pField->name); if (tag < 0) { - terrno = TSDB_CODE_MND_TAG_NOT_EXIST; - return -1; + code = TSDB_CODE_MND_TAG_NOT_EXIST; + TAOS_RETURN(code); } col_id_t colId = pOld->pTags[tag].colId; - if (mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId) != 0) { - return -1; - } + TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId)); uint32_t nLen = 0; for (int32_t i = 0; i < pOld->numOfTags; ++i) { @@ -1703,32 +1717,30 @@ static int32_t mndAlterStbTagBytes(SMnode *pMnode, const SStbObj *pOld, SStbObj } if (nLen > TSDB_MAX_TAGS_LEN) { - terrno = TSDB_CODE_PAR_INVALID_TAGS_LENGTH; - return -1; + code = TSDB_CODE_PAR_INVALID_TAGS_LENGTH; + TAOS_RETURN(code); } - if (mndAllocStbSchemas(pOld, pNew) != 0) { - return -1; - } + TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew)); SSchema *pTag = pNew->pTags + tag; if (!(pTag->type == TSDB_DATA_TYPE_BINARY || pTag->type == TSDB_DATA_TYPE_VARBINARY || pTag->type == TSDB_DATA_TYPE_NCHAR || pTag->type == TSDB_DATA_TYPE_GEOMETRY)) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_OPTION; + TAOS_RETURN(code); } if (pField->bytes <= pTag->bytes) { - terrno = TSDB_CODE_MND_INVALID_ROW_BYTES; - return -1; + code = TSDB_CODE_MND_INVALID_ROW_BYTES; + TAOS_RETURN(code); } pTag->bytes = pField->bytes; pNew->tagVer++; mInfo("stb:%s, start to modify tag len %s to %d", pNew->name, pField->name, pField->bytes); - return 0; + TAOS_RETURN(code); } static int32_t mndUpdateSuperTableColumnCompress(SMnode *pMnode, const SStbObj *pOld, SStbObj *pNew, SArray *pField, @@ -1741,22 +1753,17 @@ static int32_t mndUpdateSuperTableColumnCompress(SMnode *pMnode, const SStbObj * int32_t code = 0; int32_t idx = mndFindSuperTableColumnIndex(pOld, p->name); if (idx == -1) { - terrno = TSDB_CODE_MND_COLUMN_NOT_EXIST; - return -1; + code = TSDB_CODE_MND_COLUMN_NOT_EXIST; + TAOS_RETURN(code); } SSchema *pTarget = &pOld->pColumns[idx]; col_id_t colId = pTarget->colId; - if (mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId) != 0) { - return -1; - } + TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId)); - if (mndAllocStbSchemas(pOld, pNew) != 0) { - return -1; - } + TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew)); code = validColCmprByType(pTarget->type, p->bytes); if (code != TSDB_CODE_SUCCESS) { - terrno = code; - return code; + TAOS_RETURN(code); } int8_t updated = 0; @@ -1772,55 +1779,54 @@ static int32_t mndUpdateSuperTableColumnCompress(SMnode *pMnode, const SStbObj * } if (updated == 0) { - terrno = TSDB_CODE_MND_COLUMN_COMPRESS_ALREADY_EXIST; - return -1; + code = TSDB_CODE_MND_COLUMN_COMPRESS_ALREADY_EXIST; + TAOS_RETURN(code); } else if (updated == -1) { - terrno = TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR; - return -1; + code = TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR; + TAOS_RETURN(code); } pNew->colVer++; - return 0; + TAOS_RETURN(code); } static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, SArray *pFields, int32_t ncols, int8_t withCompress) { + int32_t code = 0; if (pOld->numOfColumns + ncols + pOld->numOfTags > TSDB_MAX_COLUMNS) { - terrno = TSDB_CODE_MND_TOO_MANY_COLUMNS; - return -1; + code = TSDB_CODE_MND_TOO_MANY_COLUMNS; + TAOS_RETURN(code); } - if ((terrno = grantCheck(TSDB_GRANT_TIMESERIES)) != 0) { - return -1; + if ((code = grantCheck(TSDB_GRANT_TIMESERIES)) != 0) { + TAOS_RETURN(code); } if (!mndValidateSchema(pOld->pColumns, pOld->numOfColumns, pFields, TSDB_MAX_BYTES_PER_ROW)) { - terrno = TSDB_CODE_PAR_INVALID_ROW_LENGTH; - return -1; + code = TSDB_CODE_PAR_INVALID_ROW_LENGTH; + TAOS_RETURN(code); } pNew->numOfColumns = pNew->numOfColumns + ncols; - if (mndAllocStbSchemas(pOld, pNew) != 0) { - return -1; - } + TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew)); if (pNew->nextColId < 0 || pNew->nextColId >= 0x7fff - ncols) { - terrno = TSDB_CODE_OUT_OF_RANGE; - return -1; + code = TSDB_CODE_OUT_OF_RANGE; + TAOS_RETURN(code); } for (int32_t i = 0; i < ncols; i++) { if (withCompress) { SFieldWithOptions *pField = taosArrayGet(pFields, i); if (mndFindSuperTableColumnIndex(pOld, pField->name) >= 0) { - terrno = TSDB_CODE_MND_COLUMN_ALREADY_EXIST; - return -1; + code = TSDB_CODE_MND_COLUMN_ALREADY_EXIST; + TAOS_RETURN(code); } if (mndFindSuperTableTagIndex(pOld, pField->name) >= 0) { - terrno = TSDB_CODE_MND_TAG_ALREADY_EXIST; - return -1; + code = TSDB_CODE_MND_TAG_ALREADY_EXIST; + TAOS_RETURN(code); } SSchema *pSchema = &pNew->pColumns[pOld->numOfColumns + i]; @@ -1837,13 +1843,13 @@ static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, SArray } else { SField *pField = taosArrayGet(pFields, i); if (mndFindSuperTableColumnIndex(pOld, pField->name) >= 0) { - terrno = TSDB_CODE_MND_COLUMN_ALREADY_EXIST; - return -1; + code = TSDB_CODE_MND_COLUMN_ALREADY_EXIST; + TAOS_RETURN(code); } if (mndFindSuperTableTagIndex(pOld, pField->name) >= 0) { - terrno = TSDB_CODE_MND_TAG_ALREADY_EXIST; - return -1; + code = TSDB_CODE_MND_TAG_ALREADY_EXIST; + TAOS_RETURN(code); } SSchema *pSchema = &pNew->pColumns[pOld->numOfColumns + i]; @@ -1861,34 +1867,31 @@ static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, SArray } pNew->colVer++; - return 0; + TAOS_RETURN(code); } static int32_t mndDropSuperTableColumn(SMnode *pMnode, const SStbObj *pOld, SStbObj *pNew, const char *colName) { + int32_t code = 0; int32_t col = mndFindSuperTableColumnIndex(pOld, colName); if (col < 0) { - terrno = TSDB_CODE_MND_COLUMN_NOT_EXIST; - return -1; + code = TSDB_CODE_MND_COLUMN_NOT_EXIST; + TAOS_RETURN(code); } if (col == 0) { - terrno = TSDB_CODE_MND_INVALID_STB_ALTER_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_ALTER_OPTION; + TAOS_RETURN(code); } if (pOld->numOfColumns == 2) { - terrno = TSDB_CODE_MND_INVALID_STB_ALTER_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_ALTER_OPTION; + TAOS_RETURN(code); } col_id_t colId = pOld->pColumns[col].colId; - if (mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId) != 0) { - return -1; - } + TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId)); - if (mndAllocStbSchemas(pOld, pNew) != 0) { - return -1; - } + TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew)); int32_t sz = pNew->numOfColumns - col - 1; memmove(pNew->pColumns + col, pNew->pColumns + col + 1, sizeof(SSchema) * sz); @@ -1897,14 +1900,15 @@ static int32_t mndDropSuperTableColumn(SMnode *pMnode, const SStbObj *pOld, SStb pNew->colVer++; mInfo("stb:%s, start to drop col %s", pNew->name, colName); - return 0; + TAOS_RETURN(code); } static int32_t mndAlterStbColumnBytes(SMnode *pMnode, const SStbObj *pOld, SStbObj *pNew, const SField *pField) { + int32_t code = 0; int32_t col = mndFindSuperTableColumnIndex(pOld, pField->name); if (col < 0) { - terrno = TSDB_CODE_MND_COLUMN_NOT_EXIST; - return -1; + code = TSDB_CODE_MND_COLUMN_NOT_EXIST; + TAOS_RETURN(code); } col_id_t colId = pOld->pColumns[col].colId; @@ -1915,63 +1919,70 @@ static int32_t mndAlterStbColumnBytes(SMnode *pMnode, const SStbObj *pOld, SStbO } if (nLen > TSDB_MAX_BYTES_PER_ROW) { - terrno = TSDB_CODE_MND_INVALID_ROW_BYTES; - return -1; + code = TSDB_CODE_MND_INVALID_ROW_BYTES; + TAOS_RETURN(code); } - if (mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId) != 0) { - return -1; - } + TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId)); - if (mndAllocStbSchemas(pOld, pNew) != 0) { - return -1; - } + TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew)); SSchema *pCol = pNew->pColumns + col; if (!(pCol->type == TSDB_DATA_TYPE_BINARY || pCol->type == TSDB_DATA_TYPE_VARBINARY || pCol->type == TSDB_DATA_TYPE_NCHAR || pCol->type == TSDB_DATA_TYPE_GEOMETRY)) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; + code = TSDB_CODE_MND_INVALID_STB_OPTION; + TAOS_RETURN(code); } if (pField->bytes <= pCol->bytes) { - terrno = TSDB_CODE_MND_INVALID_ROW_BYTES; - return -1; + code = TSDB_CODE_MND_INVALID_ROW_BYTES; + TAOS_RETURN(code); } pCol->bytes = pField->bytes; pNew->colVer++; mInfo("stb:%s, start to modify col len %s to %d", pNew->name, pField->name, pField->bytes); - return 0; + TAOS_RETURN(code); } static int32_t mndSetAlterStbPrepareLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { + int32_t code = 0; SSdbRaw *pRedoRaw = mndStbActionEncode(pStb); - if (pRedoRaw == NULL) return -1; - if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) { - sdbFreeRaw(pRedoRaw); - return -1; + if (pRedoRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); } - if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY) != 0) return -1; + if ((code = mndTransAppendPrepareLog(pTrans, pRedoRaw)) != 0) { + sdbFreeRaw(pRedoRaw); + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY)); - return 0; + TAOS_RETURN(code); } static int32_t mndSetAlterStbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { + int32_t code = 0; SSdbRaw *pCommitRaw = mndStbActionEncode(pStb); - if (pCommitRaw == NULL) return -1; - if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { - sdbFreeRaw(pCommitRaw); - return -1; + if (pCommitRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); } - if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; + if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) { + sdbFreeRaw(pCommitRaw); + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)); - return 0; + TAOS_RETURN(code); } static int32_t mndSetAlterStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb, void *alterOriData, int32_t alterOriDataLen) { + int32_t code = 0; SSdb *pSdb = pMnode->pSdb; SVgObj *pVgroup = NULL; void *pIter = NULL; @@ -1989,27 +2000,30 @@ static int32_t mndSetAlterStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj if (pReq == NULL) { sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); - return -1; + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); } STransAction action = {0}; action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = pReq; action.contLen = contLen; action.msgType = TDMT_VND_ALTER_STB; - if (mndTransAppendRedoAction(pTrans, &action) != 0) { + if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) { taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); - return -1; + TAOS_RETURN(code); } sdbRelease(pSdb, pVgroup); } - return 0; + TAOS_RETURN(code); } static int32_t mndSetAlterStbRedoActions2(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb, void *alterOriData, int32_t alterOriDataLen) { + int32_t code = 0; SSdb *pSdb = pMnode->pSdb; SVgObj *pVgroup = NULL; void *pIter = NULL; @@ -2027,39 +2041,42 @@ static int32_t mndSetAlterStbRedoActions2(SMnode *pMnode, STrans *pTrans, SDbObj if (pReq == NULL) { sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); - return -1; + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); } STransAction action = {0}; action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = pReq; action.contLen = contLen; action.msgType = TDMT_VND_CREATE_INDEX; - if (mndTransAppendRedoAction(pTrans, &action) != 0) { + if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) { taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); - return -1; + TAOS_RETURN(code); } sdbRelease(pSdb, pVgroup); } - return 0; + TAOS_RETURN(code); } static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbName, STableMetaRsp *pRsp) { + int32_t code = 0; taosRLockLatch(&pStb->lock); int32_t totalCols = pStb->numOfColumns + pStb->numOfTags; pRsp->pSchemas = taosMemoryCalloc(totalCols, sizeof(SSchema)); if (pRsp->pSchemas == NULL) { taosRUnLockLatch(&pStb->lock); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } pRsp->pSchemaExt = taosMemoryCalloc(pStb->numOfColumns, sizeof(SSchemaExt)); if (pRsp->pSchemaExt == NULL) { taosRUnLockLatch(&pStb->lock); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } tstrncpy(pRsp->dbFName, pStb->db, sizeof(pRsp->dbFName)); @@ -2102,18 +2119,19 @@ static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbNa } taosRUnLockLatch(&pStb->lock); - return 0; + TAOS_RETURN(code); } static int32_t mndBuildStbCfgImp(SDbObj *pDb, SStbObj *pStb, const char *tbName, STableCfgRsp *pRsp) { + int32_t code = 0; taosRLockLatch(&pStb->lock); int32_t totalCols = pStb->numOfColumns + pStb->numOfTags; pRsp->pSchemas = taosMemoryCalloc(totalCols, sizeof(SSchema)); if (pRsp->pSchemas == NULL) { taosRUnLockLatch(&pStb->lock); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } tstrncpy(pRsp->dbFName, pStb->db, sizeof(pRsp->dbFName)); @@ -2166,30 +2184,31 @@ static int32_t mndBuildStbCfgImp(SDbObj *pDb, SStbObj *pStb, const char *tbName, } taosRUnLockLatch(&pStb->lock); - return 0; + TAOS_RETURN(code); } static int32_t mndValidateStbVersion(SMnode *pMnode, SSTableVersion *pStbVer, bool *schema, bool *sma) { + int32_t code = 0; char tbFName[TSDB_TABLE_FNAME_LEN] = {0}; snprintf(tbFName, sizeof(tbFName), "%s.%s", pStbVer->dbFName, pStbVer->stbName); SDbObj *pDb = mndAcquireDb(pMnode, pStbVer->dbFName); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; - return -1; + code = TSDB_CODE_MND_DB_NOT_SELECTED; + TAOS_RETURN(code); } if (pDb->uid != pStbVer->dbId) { mndReleaseDb(pMnode, pDb); - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; - return -1; + code = TSDB_CODE_MND_DB_NOT_SELECTED; + TAOS_RETURN(code); } SStbObj *pStb = mndAcquireStb(pMnode, tbFName); if (pStb == NULL) { mndReleaseDb(pMnode, pDb); - terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST; - return -1; + code = TSDB_CODE_PAR_TABLE_NOT_EXIST; + TAOS_RETURN(code); } taosRLockLatch(&pStb->lock); @@ -2214,54 +2233,56 @@ static int32_t mndValidateStbVersion(SMnode *pMnode, SSTableVersion *pStbVer, bo } static int32_t mndBuildStbSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp) { + int32_t code = 0; char tbFName[TSDB_TABLE_FNAME_LEN] = {0}; snprintf(tbFName, sizeof(tbFName), "%s.%s", dbFName, tbName); SDbObj *pDb = mndAcquireDb(pMnode, dbFName); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; - return -1; + code = TSDB_CODE_MND_DB_NOT_SELECTED; + TAOS_RETURN(code); } SStbObj *pStb = mndAcquireStb(pMnode, tbFName); if (pStb == NULL) { mndReleaseDb(pMnode, pDb); - terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST; - return -1; + code = TSDB_CODE_PAR_TABLE_NOT_EXIST; + TAOS_RETURN(code); } - int32_t code = mndBuildStbSchemaImp(pDb, pStb, tbName, pRsp); + code = mndBuildStbSchemaImp(pDb, pStb, tbName, pRsp); mndReleaseDb(pMnode, pDb); mndReleaseStb(pMnode, pStb); - return code; + TAOS_RETURN(code); } static int32_t mndBuildStbCfg(SMnode *pMnode, const char *dbFName, const char *tbName, STableCfgRsp *pRsp) { + int32_t code = 0; char tbFName[TSDB_TABLE_FNAME_LEN] = {0}; snprintf(tbFName, sizeof(tbFName), "%s.%s", dbFName, tbName); SDbObj *pDb = mndAcquireDb(pMnode, dbFName); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; - return -1; + code = TSDB_CODE_MND_DB_NOT_SELECTED; + TAOS_RETURN(code); } SStbObj *pStb = mndAcquireStb(pMnode, tbFName); if (pStb == NULL) { mndReleaseDb(pMnode, pDb); - terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST; - return -1; + code = TSDB_CODE_PAR_TABLE_NOT_EXIST; + TAOS_RETURN(code); } - int32_t code = mndBuildStbCfgImp(pDb, pStb, tbName, pRsp); + code = mndBuildStbCfgImp(pDb, pStb, tbName, pRsp); mndReleaseDb(pMnode, pDb); mndReleaseStb(pMnode, pStb); - return code; + TAOS_RETURN(code); } static int32_t mndBuildSMAlterStbRsp(SDbObj *pDb, SStbObj *pObj, void **pCont, int32_t *pLen) { - int32_t ret; + int32_t code = 0; SEncoder ec = {0}; uint32_t contLen = 0; SMAlterStbRsp alterRsp = {0}; @@ -2270,20 +2291,20 @@ static int32_t mndBuildSMAlterStbRsp(SDbObj *pDb, SStbObj *pObj, void **pCont, i alterRsp.pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); if (NULL == alterRsp.pMeta) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } - ret = mndBuildStbSchemaImp(pDb, pObj, name.tname, alterRsp.pMeta); - if (ret) { + code = mndBuildStbSchemaImp(pDb, pObj, name.tname, alterRsp.pMeta); + if (code) { tFreeSMAlterStbRsp(&alterRsp); - return ret; + return code; } - tEncodeSize(tEncodeSMAlterStbRsp, &alterRsp, contLen, ret); - if (ret) { + tEncodeSize(tEncodeSMAlterStbRsp, &alterRsp, contLen, code); + if (code) { tFreeSMAlterStbRsp(&alterRsp); - return ret; + return code; } void *cont = taosMemoryMalloc(contLen); @@ -2296,18 +2317,22 @@ static int32_t mndBuildSMAlterStbRsp(SDbObj *pDb, SStbObj *pObj, void **pCont, i *pCont = cont; *pLen = contLen; - return 0; + TAOS_RETURN(code); } int32_t mndBuildSMCreateStbRsp(SMnode *pMnode, char *dbFName, char *stbFName, void **pCont, int32_t *pLen) { - int32_t ret = -1; + int32_t code = -1; SDbObj *pDb = mndAcquireDb(pMnode, dbFName); if (NULL == pDb) { - return -1; + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); } SStbObj *pObj = mndAcquireStb(pMnode, stbFName); if (NULL == pObj) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; goto _OVER; } @@ -2319,18 +2344,18 @@ int32_t mndBuildSMCreateStbRsp(SMnode *pMnode, char *dbFName, char *stbFName, vo stbRsp.pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); if (NULL == stbRsp.pMeta) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } - ret = mndBuildStbSchemaImp(pDb, pObj, name.tname, stbRsp.pMeta); - if (ret) { + code = mndBuildStbSchemaImp(pDb, pObj, name.tname, stbRsp.pMeta); + if (code) { tFreeSMCreateStbRsp(&stbRsp); goto _OVER; } - tEncodeSize(tEncodeSMCreateStbRsp, &stbRsp, contLen, ret); - if (ret) { + tEncodeSize(tEncodeSMCreateStbRsp, &stbRsp, contLen, code); + if (code) { tFreeSMCreateStbRsp(&stbRsp); goto _OVER; } @@ -2345,7 +2370,7 @@ int32_t mndBuildSMCreateStbRsp(SMnode *pMnode, char *dbFName, char *stbFName, vo *pCont = cont; *pLen = contLen; - ret = 0; + code = 0; _OVER: if (pObj) { @@ -2356,53 +2381,61 @@ _OVER: mndReleaseDb(pMnode, pDb); } - return ret; + TAOS_RETURN(code); } static int32_t mndAlterStbImp(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pStb, bool needRsp, void *alterOriData, int32_t alterOriDataLen) { int32_t code = -1; STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB_INSIDE, pReq, "alter-stb"); - if (pTrans == NULL) goto _OVER; + if (pTrans == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + goto _OVER; + } mInfo("trans:%d, used to alter stb:%s", pTrans->id, pStb->name); mndTransSetDbName(pTrans, pDb->name, pStb->name); - if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER); if (needRsp) { void *pCont = NULL; int32_t contLen = 0; - if (mndBuildSMAlterStbRsp(pDb, pStb, &pCont, &contLen) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndBuildSMAlterStbRsp(pDb, pStb, &pCont, &contLen), NULL, _OVER); mndTransSetRpcRsp(pTrans, pCont, contLen); } - if (mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; - if (mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; - if (mndSetAlterStbRedoActions(pMnode, pTrans, pDb, pStb, alterOriData, alterOriDataLen) != 0) goto _OVER; - if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetAlterStbRedoActions(pMnode, pTrans, pDb, pStb, alterOriData, alterOriDataLen), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); code = 0; _OVER: mndTransDrop(pTrans); - return code; + TAOS_RETURN(code); } static int32_t mndAlterStbAndUpdateTagIdxImp(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pStb, bool needRsp, void *alterOriData, int32_t alterOriDataLen, const SMAlterStbReq *pAlter) { int32_t code = -1; STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB_INSIDE, pReq, "alter-stb"); - if (pTrans == NULL) goto _OVER; + if (pTrans == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + goto _OVER; + } mInfo("trans:%d, used to alter stb:%s", pTrans->id, pStb->name); mndTransSetDbName(pTrans, pDb->name, pStb->name); - if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER); if (needRsp) { void *pCont = NULL; int32_t contLen = 0; - if (mndBuildSMAlterStbRsp(pDb, pStb, &pCont, &contLen) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndBuildSMAlterStbRsp(pDb, pStb, &pCont, &contLen), NULL, _OVER); mndTransSetRpcRsp(pTrans, pCont, contLen); } @@ -2413,16 +2446,16 @@ static int32_t mndAlterStbAndUpdateTagIdxImp(SMnode *pMnode, SRpcMsg *pReq, SDbO if (mndGetIdxsByTagName(pMnode, pStb, pField0->name, &idxObj) == 0) { exist = true; } - if (mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; - if (mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb), NULL, _OVER); if (exist == true) { - if (mndSetDropIdxPrepareLogs(pMnode, pTrans, &idxObj) != 0) goto _OVER; - if (mndSetDropIdxCommitLogs(pMnode, pTrans, &idxObj) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetDropIdxPrepareLogs(pMnode, pTrans, &idxObj), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetDropIdxCommitLogs(pMnode, pTrans, &idxObj), NULL, _OVER); } - if (mndSetAlterStbRedoActions(pMnode, pTrans, pDb, pStb, alterOriData, alterOriDataLen) != 0) goto _OVER; - if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetAlterStbRedoActions(pMnode, pTrans, pDb, pStb, alterOriData, alterOriDataLen), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); } else if (pAlter->alterType == TSDB_ALTER_TABLE_UPDATE_TAG_NAME) { SIdxObj idxObj = {0}; @@ -2436,24 +2469,24 @@ static int32_t mndAlterStbAndUpdateTagIdxImp(SMnode *pMnode, SRpcMsg *pReq, SDbO exist = true; } - if (mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; - if (mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetAlterStbPrepareLogs(pMnode, pTrans, pDb, pStb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb), NULL, _OVER); if (exist == true) { memcpy(idxObj.colName, nTagName, strlen(nTagName)); idxObj.colName[strlen(nTagName)] = 0; - if (mndSetAlterIdxPrepareLogs(pMnode, pTrans, &idxObj) != 0) goto _OVER; - if (mndSetAlterIdxCommitLogs(pMnode, pTrans, &idxObj) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetAlterIdxPrepareLogs(pMnode, pTrans, &idxObj), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetAlterIdxCommitLogs(pMnode, pTrans, &idxObj), NULL, _OVER); } - if (mndSetAlterStbRedoActions(pMnode, pTrans, pDb, pStb, alterOriData, alterOriDataLen) != 0) goto _OVER; - if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetAlterStbRedoActions(pMnode, pTrans, pDb, pStb, alterOriData, alterOriDataLen), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); } code = 0; _OVER: mndTransDrop(pTrans); - return code; + TAOS_RETURN(code); } static int32_t mndAlterStb(SMnode *pMnode, SRpcMsg *pReq, const SMAlterStbReq *pAlter, SDbObj *pDb, SStbObj *pOld) { @@ -2530,7 +2563,7 @@ _OVER: if (pAlter->commentLen > 0) { taosMemoryFreeClear(stbObj.comment); } - return code; + TAOS_RETURN(code); } static int32_t mndProcessAlterStbReq(SRpcMsg *pReq) { @@ -2541,7 +2574,7 @@ static int32_t mndProcessAlterStbReq(SRpcMsg *pReq) { SMAlterStbReq alterReq = {0}; if (tDeserializeSMAlterStbReq(pReq->pCont, pReq->contLen, &alterReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } @@ -2550,17 +2583,17 @@ static int32_t mndProcessAlterStbReq(SRpcMsg *pReq) { pDb = mndAcquireDbByStb(pMnode, alterReq.name); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_EXIST; + code = TSDB_CODE_MND_DB_NOT_EXIST; goto _OVER; } pStb = mndAcquireStb(pMnode, alterReq.name); if (pStb == NULL) { - terrno = TSDB_CODE_MND_STB_NOT_EXIST; + code = TSDB_CODE_MND_STB_NOT_EXIST; goto _OVER; } - if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) { + if ((code = mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb)) != 0) { goto _OVER; } @@ -2574,41 +2607,52 @@ static int32_t mndProcessAlterStbReq(SRpcMsg *pReq) { _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { - mError("stb:%s, failed to alter since %s", alterReq.name, terrstr()); + mError("stb:%s, failed to alter since %s", alterReq.name, tstrerror(code)); } mndReleaseStb(pMnode, pStb); mndReleaseDb(pMnode, pDb); tFreeSMAltertbReq(&alterReq); - return code; + TAOS_RETURN(code); } static int32_t mndSetDropStbPrepareLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) { + int32_t code = 0; SSdbRaw *pRedoRaw = mndStbActionEncode(pStb); - if (pRedoRaw == NULL) return -1; - if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) { - sdbFreeRaw(pRedoRaw); - return -1; + if (pRedoRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); } - if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1; + if ((code = mndTransAppendPrepareLog(pTrans, pRedoRaw)) != 0) { + sdbFreeRaw(pRedoRaw); + TAOS_RETURN(code); + } + TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING)); - return 0; + TAOS_RETURN(code); } static int32_t mndSetDropStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) { + int32_t code = 0; SSdbRaw *pCommitRaw = mndStbActionEncode(pStb); - if (pCommitRaw == NULL) return -1; + if (pCommitRaw == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + } if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { sdbFreeRaw(pCommitRaw); - return -1; + TAOS_RETURN(code); } - if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; + TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED)); - return 0; + TAOS_RETURN(code); } static int32_t mndSetDropStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { + int32_t code = 0; SSdb *pSdb = pMnode->pSdb; SVgObj *pVgroup = NULL; void *pIter = NULL; @@ -2626,8 +2670,8 @@ static int32_t mndSetDropStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj * if (pReq == NULL) { sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } STransAction action = {0}; @@ -2636,42 +2680,47 @@ static int32_t mndSetDropStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj * action.contLen = contLen; action.msgType = TDMT_VND_DROP_STB; action.acceptableCode = TSDB_CODE_TDB_STB_NOT_EXIST; - if (mndTransAppendRedoAction(pTrans, &action) != 0) { + if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) { taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); - return -1; + TAOS_RETURN(code); } sdbRelease(pSdb, pVgroup); } - return 0; + TAOS_RETURN(code); } static int32_t mndDropStb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pStb) { int32_t code = -1; STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB_INSIDE, pReq, "drop-stb"); - if (pTrans == NULL) goto _OVER; + if (pTrans == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + goto _OVER; + } mInfo("trans:%d, used to drop stb:%s", pTrans->id, pStb->name); mndTransSetDbName(pTrans, pDb->name, pStb->name); - if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER); - if (mndSetDropStbPrepareLogs(pMnode, pTrans, pStb) != 0) goto _OVER; - if (mndSetDropStbCommitLogs(pMnode, pTrans, pStb) != 0) goto _OVER; - if (mndSetDropStbRedoActions(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; - if (mndDropIdxsByStb(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; - if (mndDropSmasByStb(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; - if (mndUserRemoveStb(pMnode, pTrans, pStb->name) != 0) goto _OVER; - if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndSetDropStbPrepareLogs(pMnode, pTrans, pStb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetDropStbCommitLogs(pMnode, pTrans, pStb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetDropStbRedoActions(pMnode, pTrans, pDb, pStb), NULL, _OVER); + TAOS_CHECK_GOTO(mndDropIdxsByStb(pMnode, pTrans, pDb, pStb), NULL, _OVER); + TAOS_CHECK_GOTO(mndDropSmasByStb(pMnode, pTrans, pDb, pStb), NULL, _OVER); + TAOS_CHECK_GOTO(mndUserRemoveStb(pMnode, pTrans, pStb->name), NULL, _OVER); + TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); code = 0; _OVER: mndTransDrop(pTrans); - return code; + TAOS_RETURN(code); } static int32_t mndCheckDropStbForTopic(SMnode *pMnode, const char *stbFullName, int64_t suid) { + int32_t code = 0; SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; while (1) { @@ -2683,7 +2732,7 @@ static int32_t mndCheckDropStbForTopic(SMnode *pMnode, const char *stbFullName, if (pTopic->stbUid == suid) { sdbRelease(pSdb, pTopic); sdbCancelFetch(pSdb, pIter); - return -1; + TAOS_RETURN(-1); } } @@ -2694,11 +2743,11 @@ static int32_t mndCheckDropStbForTopic(SMnode *pMnode, const char *stbFullName, SNode *pAst = NULL; if (nodesStringToNode(pTopic->ast, &pAst) != 0) { - terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION; + code = TSDB_CODE_MND_INVALID_TOPIC_OPTION; mError("topic:%s, create ast error", pTopic->name); sdbRelease(pSdb, pTopic); sdbCancelFetch(pSdb, pIter); - return -1; + TAOS_RETURN(code); } SNodeList *pNodeList = NULL; @@ -2712,7 +2761,7 @@ static int32_t mndCheckDropStbForTopic(SMnode *pMnode, const char *stbFullName, nodesDestroyNode(pAst); nodesDestroyList(pNodeList); sdbCancelFetch(pSdb, pIter); - return -1; + TAOS_RETURN(-1); } else { goto NEXT; } @@ -2722,10 +2771,11 @@ static int32_t mndCheckDropStbForTopic(SMnode *pMnode, const char *stbFullName, nodesDestroyNode(pAst); nodesDestroyList(pNodeList); } - return 0; + TAOS_RETURN(code); } static int32_t mndCheckDropStbForStream(SMnode *pMnode, const char *stbFullName, int64_t suid) { + int32_t code = 0; SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; while (1) { @@ -2736,16 +2786,16 @@ static int32_t mndCheckDropStbForStream(SMnode *pMnode, const char *stbFullName, if (pStream->targetStbUid == suid) { sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pStream); - return -1; + TAOS_RETURN(-1); } SNode *pAst = NULL; if (nodesStringToNode(pStream->ast, &pAst) != 0) { - terrno = TSDB_CODE_MND_INVALID_STREAM_OPTION; + code = TSDB_CODE_MND_INVALID_STREAM_OPTION; mError("stream:%s, create ast error", pStream->name); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pStream); - return -1; + TAOS_RETURN(code); } SNodeList *pNodeList = NULL; @@ -2759,7 +2809,7 @@ static int32_t mndCheckDropStbForStream(SMnode *pMnode, const char *stbFullName, sdbRelease(pSdb, pStream); nodesDestroyNode(pAst); nodesDestroyList(pNodeList); - return -1; + TAOS_RETURN(-1); } else { goto NEXT; } @@ -2769,7 +2819,7 @@ static int32_t mndCheckDropStbForStream(SMnode *pMnode, const char *stbFullName, nodesDestroyNode(pAst); nodesDestroyList(pNodeList); } - return 0; + TAOS_RETURN(code); } static int32_t mndProcessDropTtltbRsp(SRpcMsg *pRsp) { return 0; } @@ -2783,10 +2833,7 @@ static int32_t mndProcessDropStbReq(SRpcMsg *pReq) { SStbObj *pStb = NULL; SMDropStbReq dropReq = {0}; - if (tDeserializeSMDropStbReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - goto _OVER; - } + TAOS_CHECK_GOTO(tDeserializeSMDropStbReq(pReq->pCont, pReq->contLen, &dropReq), NULL, _OVER); mInfo("stb:%s, start to drop", dropReq.name); @@ -2797,7 +2844,7 @@ static int32_t mndProcessDropStbReq(SRpcMsg *pReq) { code = 0; goto _OVER; } else { - terrno = TSDB_CODE_MND_STB_NOT_EXIST; + code = TSDB_CODE_MND_STB_NOT_EXIST; goto _OVER; } } @@ -2809,21 +2856,21 @@ static int32_t mndProcessDropStbReq(SRpcMsg *pReq) { pDb = mndAcquireDbByStb(pMnode, dropReq.name); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + code = TSDB_CODE_MND_DB_NOT_SELECTED; goto _OVER; } - if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) { + if ((code = mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb)) != 0) { goto _OVER; } if (mndCheckDropStbForTopic(pMnode, dropReq.name, pStb->uid) < 0) { - terrno = TSDB_CODE_MND_TOPIC_MUST_BE_DELETED; + code = TSDB_CODE_MND_TOPIC_MUST_BE_DELETED; goto _OVER; } if (mndCheckDropStbForStream(pMnode, dropReq.name, pStb->uid) < 0) { - terrno = TSDB_CODE_MND_STREAM_MUST_BE_DELETED; + code = TSDB_CODE_MND_STREAM_MUST_BE_DELETED; goto _OVER; } @@ -2837,13 +2884,13 @@ static int32_t mndProcessDropStbReq(SRpcMsg *pReq) { _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { - mError("stb:%s, failed to drop since %s", dropReq.name, terrstr()); + mError("stb:%s, failed to drop since %s", dropReq.name, tstrerror(code)); } mndReleaseDb(pMnode, pDb); mndReleaseStb(pMnode, pStb); tFreeSMDropStbReq(&dropReq); - return code; + TAOS_RETURN(code); } static int32_t mndProcessTableMetaReq(SRpcMsg *pReq) { @@ -2853,40 +2900,32 @@ static int32_t mndProcessTableMetaReq(SRpcMsg *pReq) { STableMetaRsp metaRsp = {0}; SUserObj *pUser = mndAcquireUser(pMnode, pReq->info.conn.user); + //TODO why return 0 here if (pUser == NULL) return 0; bool sysinfo = pUser->sysInfo; - if (tDeserializeSTableInfoReq(pReq->pCont, pReq->contLen, &infoReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - goto _OVER; - } + TAOS_CHECK_GOTO(tDeserializeSTableInfoReq(pReq->pCont, pReq->contLen, &infoReq), NULL, _OVER); if (0 == strcmp(infoReq.dbFName, TSDB_INFORMATION_SCHEMA_DB)) { mInfo("information_schema table:%s.%s, start to retrieve meta", infoReq.dbFName, infoReq.tbName); - if (mndBuildInsTableSchema(pMnode, infoReq.dbFName, infoReq.tbName, sysinfo, &metaRsp) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(mndBuildInsTableSchema(pMnode, infoReq.dbFName, infoReq.tbName, sysinfo, &metaRsp), NULL, _OVER); } else if (0 == strcmp(infoReq.dbFName, TSDB_PERFORMANCE_SCHEMA_DB)) { mInfo("performance_schema table:%s.%s, start to retrieve meta", infoReq.dbFName, infoReq.tbName); - if (mndBuildPerfsTableSchema(pMnode, infoReq.dbFName, infoReq.tbName, &metaRsp) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(mndBuildPerfsTableSchema(pMnode, infoReq.dbFName, infoReq.tbName, &metaRsp), NULL, _OVER); } else { mInfo("stb:%s.%s, start to retrieve meta", infoReq.dbFName, infoReq.tbName); - if (mndBuildStbSchema(pMnode, infoReq.dbFName, infoReq.tbName, &metaRsp) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(mndBuildStbSchema(pMnode, infoReq.dbFName, infoReq.tbName, &metaRsp), NULL, _OVER); } int32_t rspLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp); if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } void *pRsp = rpcMallocCont(rspLen); if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } @@ -2899,11 +2938,12 @@ static int32_t mndProcessTableMetaReq(SRpcMsg *pReq) { _OVER: if (code != 0) { - mError("stb:%s.%s, failed to retrieve meta since %s", infoReq.dbFName, infoReq.tbName, terrstr()); + mError("stb:%s.%s, failed to retrieve meta since %s", infoReq.dbFName, infoReq.tbName, tstrerror(code)); } mndReleaseUser(pMnode, pUser); tFreeSTableMetaRsp(&metaRsp); + //TODO change to TAOS_RETURN return code; } @@ -2913,39 +2953,30 @@ static int32_t mndProcessTableCfgReq(SRpcMsg *pReq) { STableCfgReq cfgReq = {0}; STableCfgRsp cfgRsp = {0}; - if (tDeserializeSTableCfgReq(pReq->pCont, pReq->contLen, &cfgReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - goto _OVER; - } + TAOS_CHECK_GOTO(tDeserializeSTableCfgReq(pReq->pCont, pReq->contLen, &cfgReq), NULL, _OVER); char dbName[TSDB_DB_NAME_LEN] = {0}; mndExtractShortDbNameFromDbFullName(cfgReq.dbFName, dbName); if (0 == strcmp(dbName, TSDB_INFORMATION_SCHEMA_DB)) { mInfo("information_schema table:%s.%s, start to retrieve cfg", cfgReq.dbFName, cfgReq.tbName); - if (mndBuildInsTableCfg(pMnode, cfgReq.dbFName, cfgReq.tbName, &cfgRsp) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(mndBuildInsTableCfg(pMnode, cfgReq.dbFName, cfgReq.tbName, &cfgRsp), NULL, _OVER); } else if (0 == strcmp(dbName, TSDB_PERFORMANCE_SCHEMA_DB)) { mInfo("performance_schema table:%s.%s, start to retrieve cfg", cfgReq.dbFName, cfgReq.tbName); - if (mndBuildPerfsTableCfg(pMnode, cfgReq.dbFName, cfgReq.tbName, &cfgRsp) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(mndBuildPerfsTableCfg(pMnode, cfgReq.dbFName, cfgReq.tbName, &cfgRsp), NULL, _OVER); } else { mInfo("stb:%s.%s, start to retrieve cfg", cfgReq.dbFName, cfgReq.tbName); - if (mndBuildStbCfg(pMnode, cfgReq.dbFName, cfgReq.tbName, &cfgRsp) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(mndBuildStbCfg(pMnode, cfgReq.dbFName, cfgReq.tbName, &cfgRsp), NULL, _OVER); } int32_t rspLen = tSerializeSTableCfgRsp(NULL, 0, &cfgRsp); if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } void *pRsp = rpcMallocCont(rspLen); if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } @@ -2958,27 +2989,28 @@ static int32_t mndProcessTableCfgReq(SRpcMsg *pReq) { _OVER: if (code != 0) { - mError("stb:%s.%s, failed to retrieve cfg since %s", cfgReq.dbFName, cfgReq.tbName, terrstr()); + mError("stb:%s.%s, failed to retrieve cfg since %s", cfgReq.dbFName, cfgReq.tbName, tstrerror(code)); } tFreeSTableCfgRsp(&cfgRsp); - return code; + TAOS_RETURN(code); } int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t numOfStbs, void **ppRsp, int32_t *pRspLen) { + int32_t code = 0; SSTbHbRsp hbRsp = {0}; hbRsp.pMetaRsp = taosArrayInit(numOfStbs, sizeof(STableMetaRsp)); if (hbRsp.pMetaRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } hbRsp.pIndexRsp = taosArrayInit(numOfStbs, sizeof(STableIndexRsp)); if (NULL == hbRsp.pIndexRsp) { taosArrayDestroy(hbRsp.pMetaRsp); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } for (int32_t i = 0; i < numOfStbs; ++i) { @@ -3024,8 +3056,8 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t STableIndexRsp indexRsp = {0}; indexRsp.pIndex = taosArrayInit(10, sizeof(STableIndexInfo)); if (NULL == indexRsp.pIndex) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } sprintf(tbFName, "%s.%s", pStbVersion->dbFName, pStbVersion->stbName); @@ -3046,30 +3078,31 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t int32_t rspLen = tSerializeSSTbHbRsp(NULL, 0, &hbRsp); if (rspLen < 0) { tFreeSSTbHbRsp(&hbRsp); - terrno = TSDB_CODE_INVALID_MSG; - return -1; + code = TSDB_CODE_INVALID_MSG; + TAOS_RETURN(code); } void *pRsp = taosMemoryMalloc(rspLen); if (pRsp == NULL) { tFreeSSTbHbRsp(&hbRsp); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_RETURN(code); } tSerializeSSTbHbRsp(pRsp, rspLen, &hbRsp); tFreeSSTbHbRsp(&hbRsp); *ppRsp = pRsp; *pRspLen = rspLen; - return 0; + TAOS_RETURN(code); } int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs) { + int32_t code = 0; SSdb *pSdb = pMnode->pSdb; SDbObj *pDb = mndAcquireDb(pMnode, dbName); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; - return -1; + code = TSDB_CODE_MND_DB_NOT_SELECTED; + TAOS_RETURN(code); } int32_t numOfStbs = 0; @@ -3088,7 +3121,7 @@ int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs) { *pNumOfStbs = numOfStbs; mndReleaseDb(pMnode, pDb); - return 0; + TAOS_RETURN(code); } void mndExtractDbNameFromStbFullName(const char *stbFullName, char *dst) { @@ -4046,29 +4079,40 @@ static int32_t mndSetDropTbsRedoActions(SMnode *pMnode, STrans *pTrans, const SV } static int32_t mndCreateDropTbsTxnPrepare(SRpcMsg *pRsp, SMndDropTbsWithTsmaCtx *pCtx) { + int32_t code = 0; SMnode *pMnode = pRsp->info.node; STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pRsp, "drop-tbs"); mndTransSetChangeless(pTrans); - if (pTrans == NULL) goto _OVER; + if (pTrans == NULL) { + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + goto _OVER; + } - if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER; + TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER); void *pIter = taosHashIterate(pCtx->pVgMap, NULL); while (pIter) { const SVDropTbVgReqs *pVgReqs = pIter; int32_t len = 0; void *p = mndBuildVDropTbsReq(pMnode, &pVgReqs->info, &pVgReqs->req, &len); - if (!p || mndSetDropTbsRedoActions(pMnode, pTrans, pVgReqs, p, len) != 0) { + if (!p) { + taosHashCancelIterate(pCtx->pVgMap, pIter); + code = TSDB_CODE_MND_RETURN_VALUE_NULL; + if (terrno != 0) code = terrno; + goto _OVER; + } + if ((code = mndSetDropTbsRedoActions(pMnode, pTrans, pVgReqs, p, len)) != 0) { taosHashCancelIterate(pCtx->pVgMap, pIter); goto _OVER; } pIter = taosHashIterate(pCtx->pVgMap, pIter); } - if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER; _OVER: mndTransDrop(pTrans); - return terrno; + TAOS_RETURN(code); } static int32_t mndProcessDropTbWithTsma(SRpcMsg *pReq) { @@ -4079,23 +4123,23 @@ static int32_t mndProcessDropTbWithTsma(SRpcMsg *pReq) { SMDropTbsReq dropReq = {0}; bool locked = false; if (tDeserializeSMDropTbsReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; + code = TSDB_CODE_INVALID_MSG; goto _OVER; } SMndDropTbsWithTsmaCtx *pCtx = NULL; - terrno = mndInitDropTbsWithTsmaCtx(&pCtx); - if (terrno) goto _OVER; + code = mndInitDropTbsWithTsmaCtx(&pCtx); + if (code) goto _OVER; for (int32_t i = 0; i < dropReq.pVgReqs->size; ++i) { SMDropTbReqsOnSingleVg *pReq = taosArrayGet(dropReq.pVgReqs, i); - terrno = mndDropTbAddTsmaResTbsForSingleVg(pMnode, pCtx, pReq->pTbs, pReq->vgInfo.vgId); - if (terrno) goto _OVER; + code = mndDropTbAddTsmaResTbsForSingleVg(pMnode, pCtx, pReq->pTbs, pReq->vgInfo.vgId); + if (code) goto _OVER; } if (mndCreateDropTbsTxnPrepare(pReq, pCtx) == 0) code = 0; _OVER: tFreeSMDropTbsReq(&dropReq); if (pCtx) mndDestroyDropTbsWithTsmaCtx(pCtx); - return code; + TAOS_RETURN(code); } static int32_t mndDropTbAdd(SMnode *pMnode, SHashObj *pVgHashMap, const SVgroupInfo *pVgInfo, char *name, tb_uid_t suid, @@ -4140,7 +4184,7 @@ _end: taosArrayDestroy(pInfo->dbInfo.dbVgInfos); pInfo->dbInfo.dbVgInfos = NULL; } - return code; + TAOS_RETURN(code); } int32_t vgHashValCmp(const void *lp, const void *rp) { @@ -4249,7 +4293,7 @@ static int32_t mndProcessFetchTtlExpiredTbs(SRpcMsg *pRsp) { SVFetchTtlExpiredTbsRsp rsp = {0}; SMndDropTbsWithTsmaCtx *pCtx = NULL; if (pRsp->code != TSDB_CODE_SUCCESS) { - terrno = pRsp->code; + code = pRsp->code; goto _end; } if (pRsp->contLen == 0) { @@ -4258,18 +4302,18 @@ static int32_t mndProcessFetchTtlExpiredTbs(SRpcMsg *pRsp) { } tDecoderInit(&decoder, pRsp->pCont, pRsp->contLen); - terrno = tDecodeVFetchTtlExpiredTbsRsp(&decoder, &rsp); - if (terrno) goto _end; + code = tDecodeVFetchTtlExpiredTbsRsp(&decoder, &rsp); + if (code) goto _end; - terrno = mndInitDropTbsWithTsmaCtx(&pCtx); - if (terrno) goto _end; + code = mndInitDropTbsWithTsmaCtx(&pCtx); + if (code) goto _end; - terrno = mndDropTbAddTsmaResTbsForSingleVg(pMnode, pCtx, rsp.pExpiredTbs, rsp.vgId); - if (terrno) goto _end; + code = mndDropTbAddTsmaResTbsForSingleVg(pMnode, pCtx, rsp.pExpiredTbs, rsp.vgId); + if (code) goto _end; if (mndCreateDropTbsTxnPrepare(pRsp, pCtx) == 0) code = 0; _end: if (pCtx) mndDestroyDropTbsWithTsmaCtx(pCtx); tDecoderClear(&decoder); tFreeFetchTtlExpiredTbsRsp(&rsp); - return code; + TAOS_RETURN(code); } diff --git a/source/dnode/vnode/src/sma/smaOpen.c b/source/dnode/vnode/src/sma/smaOpen.c index 633e096314..29854b4441 100644 --- a/source/dnode/vnode/src/sma/smaOpen.c +++ b/source/dnode/vnode/src/sma/smaOpen.c @@ -23,7 +23,9 @@ static int32_t rsmaRestore(SSma *pSma); #define SMA_SET_KEEP_CFG(v, l) \ do { \ SRetention *r = &pCfg->retentions[l]; \ - pKeepCfg->keep2 = convertTimeFromPrecisionToUnit(r->keep, pCfg->precision, TIME_UNIT_MINUTE); \ + int64_t keep = -1; \ + convertTimeFromPrecisionToUnit(r->keep, pCfg->precision, TIME_UNIT_MINUTE, &keep); \ + pKeepCfg->keep2 = (int32_t)keep; \ pKeepCfg->keep0 = pKeepCfg->keep2; \ pKeepCfg->keep1 = pKeepCfg->keep2; \ pKeepCfg->days = smaEvalDays(v, pCfg->retentions, l, pCfg->precision, pCfg->days); \ @@ -60,8 +62,12 @@ static int32_t rsmaRestore(SSma *pSma); * @return int32_t */ static int32_t smaEvalDays(SVnode *pVnode, SRetention *r, int8_t level, int8_t precision, int32_t duration) { - int32_t freqDuration = convertTimeFromPrecisionToUnit((r + TSDB_RETENTION_L0)->freq, precision, TIME_UNIT_MINUTE); - int32_t keepDuration = convertTimeFromPrecisionToUnit((r + TSDB_RETENTION_L0)->keep, precision, TIME_UNIT_MINUTE); + int32_t code = TSDB_CODE_SUCCESS; + + int64_t freqDuration = -1; + int64_t keepDuration = -1; + code = convertTimeFromPrecisionToUnit((r + TSDB_RETENTION_L0)->freq, precision, TIME_UNIT_MINUTE, &freqDuration); + code = convertTimeFromPrecisionToUnit((r + TSDB_RETENTION_L0)->keep, precision, TIME_UNIT_MINUTE, &keepDuration); int32_t days = duration; // min if (days < freqDuration) { @@ -76,8 +82,8 @@ static int32_t smaEvalDays(SVnode *pVnode, SRetention *r, int8_t level, int8_t p goto _exit; } - freqDuration = convertTimeFromPrecisionToUnit((r + level)->freq, precision, TIME_UNIT_MINUTE); - keepDuration = convertTimeFromPrecisionToUnit((r + level)->keep, precision, TIME_UNIT_MINUTE); + code = convertTimeFromPrecisionToUnit((r + level)->freq, precision, TIME_UNIT_MINUTE, &freqDuration); + code = convertTimeFromPrecisionToUnit((r + level)->keep, precision, TIME_UNIT_MINUTE, &keepDuration); int32_t nFreqTimes = (r + level)->freq / (60 * 1000); // use 60s for freq of 1st level days *= (nFreqTimes > 1 ? nFreqTimes : 1); diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index 5ab2a57954..823f65a9fd 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -335,8 +335,9 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat } if (param->maxdelay[idx] < TSDB_MIN_ROLLUP_MAX_DELAY) { - int64_t msInterval = - convertTimeFromPrecisionToUnit(pRetention[idx + 1].freq, pTsdbCfg->precision, TIME_UNIT_MILLISECOND); + int64_t msInterval = -1; + TAOS_CHECK_RETURN(convertTimeFromPrecisionToUnit(pRetention[idx + 1].freq, pTsdbCfg->precision, + TIME_UNIT_MILLISECOND, &msInterval)); pItem->maxDelay = (int32_t)msInterval; } else { pItem->maxDelay = (int32_t)param->maxdelay[idx]; diff --git a/source/dnode/vnode/src/sma/smaTimeRange.c b/source/dnode/vnode/src/sma/smaTimeRange.c index d0913081ac..fe3117de49 100644 --- a/source/dnode/vnode/src/sma/smaTimeRange.c +++ b/source/dnode/vnode/src/sma/smaTimeRange.c @@ -69,8 +69,9 @@ static int32_t tdProcessTSmaGetDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t c } STsdbCfg *pTsdbCfg = &pCfg->tsdbCfg; - int64_t sInterval = convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_SECOND); - if (sInterval <= 0) { + int64_t sInterval = -1; + code = convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_SECOND, &sInterval); + if (TSDB_CODE_SUCCESS != code || 0 == sInterval) { *days = pTsdbCfg->days; goto _exit; } @@ -78,7 +79,11 @@ static int32_t tdProcessTSmaGetDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t c if (records >= SMA_STORAGE_SPLIT_FACTOR) { *days = pTsdbCfg->days; } else { - int64_t mInterval = convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_MINUTE); + int64_t mInterval = -1; + code = convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_MINUTE, &mInterval); + if (TSDB_CODE_SUCCESS != code) { + goto _exit; + } int64_t daysPerFile = mInterval * SMA_STORAGE_MINUTES_DAY * 2; if (daysPerFile > SMA_STORAGE_MINUTES_MAX) { diff --git a/source/libs/command/inc/commandInt.h b/source/libs/command/inc/commandInt.h index a583f21117..e433d61860 100644 --- a/source/libs/command/inc/commandInt.h +++ b/source/libs/command/inc/commandInt.h @@ -176,7 +176,14 @@ typedef struct SExplainCtx { #define EXPLAIN_JOIN_STRING(_type) ((JOIN_TYPE_INNER == _type) ? "Inner join" : "Join") #define EXPLAIN_MERGE_MODE_STRING(_mode) ((_mode) == MERGE_TYPE_SORT ? "sort" : ((_mode) == MERGE_TYPE_NON_SORT ? "merge" : "column")) -#define INVERAL_TIME_FROM_PRECISION_TO_UNIT(_t, _u, _p) (((_u) == 'n' || (_u) == 'y') ? (_t) : (convertTimeFromPrecisionToUnit(_t, _p, _u))) +#define INVERAL_TIME_FROM_PRECISION_TO_UNIT(_t, _u, _p, _r) \ +do { \ + if ((_u) == 'n' || (_u) == 'y') { \ + _r = (_t); \ + } else { \ + code = convertTimeFromPrecisionToUnit(_t, _p, _u, &_r); \ + } \ +} while(0) #define EXPLAIN_ROW_NEW(level, ...) \ do { \ diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 843e3ee734..e0040ac0e1 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -55,7 +55,7 @@ char* qExplainGetAsofOpStr(int32_t opType) { case OP_TYPE_LOWER_EQUAL: return "<="; case OP_TYPE_EQUAL: - return "="; + return "="; default: return "UNKNOWN"; } @@ -192,13 +192,13 @@ int32_t qExplainGenerateResNodeExecInfo(SPhysiNode *pNode, SArray **pExecInfo, S if (0 == group->physiPlanExecIdx) { group->nodeIdx = 0; } - + rsp = taosArrayGet(group->nodeExecInfo, group->nodeIdx++); if (group->physiPlanExecIdx >= rsp->numOfPlans) { qError("physiPlanIdx %d exceed plan num %d", group->physiPlanExecIdx, rsp->numOfPlans); return TSDB_CODE_APP_ERROR; } - + if(taosArrayPush(*pExecInfo, rsp->subplanInfo + group->physiPlanExecIdx) == NULL) return terrno; } else { for (int32_t i = 0; i < group->nodeNum; ++i) { @@ -338,7 +338,7 @@ static char* qExplainGetScanMode(STableScanPhysiNode* pScan) { isGroupByTag = (NULL != pScan->pGroupTags) && !isGroupByTbname; if ((((!isGroupByTag) || isGroupByTbname) && pScan->groupSort) || (isGroupByTag && (pScan->groupSort || pScan->scan.groupOrderScan))) { return "seq_grp_order"; - } + } if ((isGroupByTbname && (pScan->groupSort || pScan->scan.groupOrderScan)) || (isGroupByTag && (pScan->groupSort || pScan->scan.groupOrderScan))) { return "grp_order"; @@ -416,7 +416,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -581,7 +581,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -621,7 +621,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i EXPLAIN_ROW_NEW(level + 1, EXPLAIN_MERGEBLOCKS_FORMAT, pPrjNode->mergeDataBlock? "True":"False"); EXPLAIN_ROW_END(); - QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); if (pPrjNode->node.pConditions) { EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT); @@ -629,7 +629,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -689,7 +689,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i EXPLAIN_ROW_APPEND(EXPLAIN_GRP_JOIN_FORMAT, pJoinNode->grpJoin); EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); EXPLAIN_ROW_END(); - + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); } @@ -705,7 +705,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i EXPLAIN_ROW_NEW(level + 1, EXPLAIN_PRIM_CONDITIONS_FORMAT); QRY_ERR_RET(nodesNodeToSQL(pJoinNode->pPrimKeyCond, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); - QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); } if (NULL != pJoinNode->pEqLeft && pJoinNode->pEqLeft->length > 0) { @@ -733,7 +733,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i QRY_ERR_RET( nodesNodeToSQL(pJoinNode->pFullOnCond, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); - QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); } if (NULL != pJoinNode->pColOnCond) { @@ -741,7 +741,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i QRY_ERR_RET( nodesNodeToSQL(pJoinNode->pColOnCond, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); - QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); } } break; @@ -831,7 +831,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -844,7 +844,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i qError("exchange src group %d not in groupHash", pExchNode->srcStartGroupId); QRY_ERR_RET(TSDB_CODE_APP_ERROR); } - + nodeNum += group->nodeNum; } @@ -876,7 +876,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } for (int32_t i = pExchNode->srcStartGroupId; i <= pExchNode->srcEndGroupId; ++i) { @@ -956,7 +956,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -991,10 +991,17 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); uint8_t precision = qExplainGetIntervalPrecision(pIntNode); + int64_t time1 = -1; + int64_t time2 = -1; + int32_t code = TSDB_CODE_SUCCESS; + INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->interval, pIntNode->intervalUnit, precision, time1); + QRY_ERR_RET(code); + INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->sliding, pIntNode->slidingUnit, precision, time2); + QRY_ERR_RET(code); EXPLAIN_ROW_NEW(level + 1, EXPLAIN_TIME_WINDOWS_FORMAT, - INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->interval, pIntNode->intervalUnit, precision), + time1, pIntNode->intervalUnit, pIntNode->offset, getPrecisionUnit(precision), - INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->sliding, pIntNode->slidingUnit, precision), + time2, pIntNode->slidingUnit); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); @@ -1043,10 +1050,17 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); uint8_t precision = qExplainGetIntervalPrecision(pIntNode); + int64_t time1 = -1; + int64_t time2 = -1; + int32_t code = TSDB_CODE_SUCCESS; + INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->interval, pIntNode->intervalUnit, precision, time1); + QRY_ERR_RET(code); + INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->sliding, pIntNode->slidingUnit, precision, time2); + QRY_ERR_RET(code); EXPLAIN_ROW_NEW(level + 1, EXPLAIN_TIME_WINDOWS_FORMAT, - INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->interval, pIntNode->intervalUnit, precision), + time1, pIntNode->intervalUnit, pIntNode->offset, getPrecisionUnit(precision), - INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->sliding, pIntNode->slidingUnit, precision), + time2, pIntNode->slidingUnit); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); @@ -1123,7 +1137,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -1163,7 +1177,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -1205,7 +1219,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -1247,7 +1261,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -1340,7 +1354,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -1381,7 +1395,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -1422,7 +1436,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -1464,7 +1478,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -1535,7 +1549,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -1563,10 +1577,17 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); uint8_t precision = qExplainGetIntervalPrecision(pIntNode); + int64_t time1 = -1; + int64_t time2 = -1; + int32_t code = TSDB_CODE_SUCCESS; + INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->interval, pIntNode->intervalUnit, precision, time1); + QRY_ERR_RET(code); + INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->sliding, pIntNode->slidingUnit, precision, time2); + QRY_ERR_RET(code); EXPLAIN_ROW_NEW(level + 1, EXPLAIN_TIME_WINDOWS_FORMAT, - INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->interval, pIntNode->intervalUnit, precision), + time1, pIntNode->intervalUnit, pIntNode->offset, getPrecisionUnit(precision), - INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->sliding, pIntNode->slidingUnit, precision), + time2, pIntNode->slidingUnit); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); @@ -1577,7 +1598,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -1644,7 +1665,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - } + } } break; } @@ -1669,7 +1690,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); - + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_EVENT_END_FORMAT); QRY_ERR_RET(nodesNodeToSQL(pEventNode->pEndCond, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); @@ -1722,7 +1743,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i if (pJoinNode->pPrimKeyCond) { QRY_ERR_RET( nodesNodeToSQL(pJoinNode->pPrimKeyCond, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); - conditionsGot = true; + conditionsGot = true; } if (pJoinNode->pColEqCond) { if (conditionsGot) { @@ -1730,7 +1751,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i } QRY_ERR_RET( nodesNodeToSQL(pJoinNode->pColEqCond, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); - conditionsGot = true; + conditionsGot = true; } if (pJoinNode->pTagEqCond) { if (conditionsGot) { @@ -1738,7 +1759,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i } QRY_ERR_RET( nodesNodeToSQL(pJoinNode->pTagEqCond, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); - conditionsGot = true; + conditionsGot = true; } if (pJoinNode->pFullOnCond) { if (conditionsGot) { @@ -1746,14 +1767,14 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i } QRY_ERR_RET(nodesNodeToSQL(pJoinNode->pFullOnCond, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); - } + } EXPLAIN_ROW_END(); - QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); if (pJoinNode->timeRangeTarget) { EXPLAIN_ROW_NEW(level + 1, EXPLAIN_TABLE_TIMERANGE_FORMAT, qExplainGetTimerangeTargetStr(pJoinNode->timeRangeTarget), pJoinNode->timeRange.skey, pJoinNode->timeRange.ekey); EXPLAIN_ROW_END(); - QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); } } break; @@ -2124,7 +2145,7 @@ int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t code = TSDB_CODE_OUT_OF_MEMORY; TAOS_CHECK_ERRNO(code); } - + groupDone = (taosArrayGetSize(group->nodeExecInfo) >= group->nodeNum); taosWUnLockLatch(&group->lock); diff --git a/source/libs/executor/src/streamcountwindowoperator.c b/source/libs/executor/src/streamcountwindowoperator.c index dd05581ff0..d8ad026c6c 100644 --- a/source/libs/executor/src/streamcountwindowoperator.c +++ b/source/libs/executor/src/streamcountwindowoperator.c @@ -482,7 +482,8 @@ void doStreamCountSaveCheckpoint(SOperatorInfo* pOperator) { code = TSDB_CODE_OUT_OF_MEMORY; QUERY_CHECK_CODE(code, lino, _end); } - len = doStreamCountEncodeOpState(&pBuf, len, pOperator, true); + void* pTmpBuf = pBuf; + len = doStreamCountEncodeOpState(&pTmpBuf, len, pOperator, true); pInfo->streamAggSup.stateStore.streamStateSaveInfo(pInfo->streamAggSup.pState, STREAM_COUNT_OP_CHECKPOINT_NAME, strlen(STREAM_COUNT_OP_CHECKPOINT_NAME), pBuf, len); saveStreamOperatorStateComplete(&pInfo->basic); diff --git a/source/libs/executor/src/streameventwindowoperator.c b/source/libs/executor/src/streameventwindowoperator.c index 2cd36a7fb7..3f1887b1ae 100644 --- a/source/libs/executor/src/streameventwindowoperator.c +++ b/source/libs/executor/src/streameventwindowoperator.c @@ -542,7 +542,11 @@ void doStreamEventSaveCheckpoint(SOperatorInfo* pOperator) { if (needSaveStreamOperatorInfo(&pInfo->basic)) { int32_t len = doStreamEventEncodeOpState(NULL, 0, pOperator); void* buf = taosMemoryCalloc(1, len); - void* pBuf = buf; + if (!buf) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + return; + } + void* pBuf = buf; len = doStreamEventEncodeOpState(&pBuf, len, pOperator); pInfo->streamAggSup.stateStore.streamStateSaveInfo(pInfo->streamAggSup.pState, STREAM_EVENT_OP_CHECKPOINT_NAME, strlen(STREAM_EVENT_OP_CHECKPOINT_NAME), buf, len); diff --git a/source/libs/executor/src/streamtimewindowoperator.c b/source/libs/executor/src/streamtimewindowoperator.c index d340efbb1b..c47f99cca3 100644 --- a/source/libs/executor/src/streamtimewindowoperator.c +++ b/source/libs/executor/src/streamtimewindowoperator.c @@ -1410,7 +1410,11 @@ void doStreamIntervalSaveCheckpoint(SOperatorInfo* pOperator) { if (needSaveStreamOperatorInfo(&pInfo->basic)) { int32_t len = doStreamIntervalEncodeOpState(NULL, 0, pOperator); void* buf = taosMemoryCalloc(1, len); - void* pBuf = buf; + if (!buf) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + return; + } + void* pBuf = buf; len = doStreamIntervalEncodeOpState(&pBuf, len, pOperator); pInfo->stateStore.streamStateSaveInfo(pInfo->pState, STREAM_INTERVAL_OP_CHECKPOINT_NAME, strlen(STREAM_INTERVAL_OP_CHECKPOINT_NAME), buf, len); @@ -3193,7 +3197,11 @@ void doStreamSessionSaveCheckpoint(SOperatorInfo* pOperator) { if (needSaveStreamOperatorInfo(&pInfo->basic)) { int32_t len = doStreamSessionEncodeOpState(NULL, 0, pOperator, true); void* buf = taosMemoryCalloc(1, len); - void* pBuf = buf; + if (!buf) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + return; + } + void* pBuf = buf; len = doStreamSessionEncodeOpState(&pBuf, len, pOperator, true); pInfo->streamAggSup.stateStore.streamStateSaveInfo(pInfo->streamAggSup.pState, STREAM_SESSION_OP_CHECKPOINT_NAME, strlen(STREAM_SESSION_OP_CHECKPOINT_NAME), buf, len); @@ -4401,7 +4409,11 @@ void doStreamStateSaveCheckpoint(SOperatorInfo* pOperator) { if (needSaveStreamOperatorInfo(&pInfo->basic)) { int32_t len = doStreamStateEncodeOpState(NULL, 0, pOperator, true); void* buf = taosMemoryCalloc(1, len); - void* pBuf = buf; + if (!buf) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + return; + } + void* pBuf = buf; len = doStreamStateEncodeOpState(&pBuf, len, pOperator, true); pInfo->streamAggSup.stateStore.streamStateSaveInfo(pInfo->streamAggSup.pState, STREAM_STATE_OP_CHECKPOINT_NAME, strlen(STREAM_STATE_OP_CHECKPOINT_NAME), buf, len); diff --git a/source/libs/geometry/src/geomFunc.c b/source/libs/geometry/src/geomFunc.c index 6e32aaf1a6..601588571e 100644 --- a/source/libs/geometry/src/geomFunc.c +++ b/source/libs/geometry/src/geomFunc.c @@ -180,7 +180,7 @@ int32_t executeGeomFromTextFunc(SColumnInfoData *pInputData, int32_t i, SColumnI goto _exit; } - colDataSetVal(pOutputData, i, output, (output == NULL)); + code = colDataSetVal(pOutputData, i, output, (output == NULL)); _exit: if (output) { @@ -200,7 +200,7 @@ int32_t executeAsTextFunc(SColumnInfoData *pInputData, int32_t i, SColumnInfoDat goto _exit; } - colDataSetVal(pOutputData, i, output, (output == NULL)); + code = colDataSetVal(pOutputData, i, output, (output == NULL)); _exit: if (output) { @@ -228,7 +228,7 @@ int32_t executeRelationFunc(const GEOSGeometry *geom1, const GEOSPreparedGeometr } } - colDataSetVal(pOutputData, i, &res, (res==-1)); + code = colDataSetVal(pOutputData, i, &res, (res==-1)); return code; } diff --git a/source/libs/geometry/src/geosWrapper.c b/source/libs/geometry/src/geosWrapper.c index c7c83f4796..c5250c8481 100644 --- a/source/libs/geometry/src/geosWrapper.c +++ b/source/libs/geometry/src/geosWrapper.c @@ -86,9 +86,9 @@ _exit: return code; } -static int initWktRegex(pcre2_code **ppRegex, pcre2_match_data **ppMatchData) { - int ret = 0; - char *wktPatternWithSpace = taosMemoryCalloc(4, 1024); +static int32_t initWktRegex(pcre2_code **ppRegex, pcre2_match_data **ppMatchData) { + int32_t code = 0; + char *wktPatternWithSpace = taosMemoryCalloc(4, 1024); sprintf( wktPatternWithSpace, "^( *)point( *)z?m?( *)((empty)|(\\(( *)(([-+]?[0-9]+\\.?[0-9]*)|([-+]?[0-9]*\\.?[0-9]+))(e[-+]?[0-9]+)?(( " @@ -142,9 +142,9 @@ static int initWktRegex(pcre2_code **ppRegex, pcre2_match_data **ppMatchData) { "*)(([-+]?[0-9]+\\.?[0-9]*)|([-+]?[0-9]*\\.?[0-9]+))(e[-+]?[0-9]+)?){1,3}( *))*( *)\\)))( *))*( *)\\)))( *))*( " "*)\\)))|(GEOCOLLECTION\\((?R)(( *)(,)( *)(?R))*( *)\\))( *)$"); - ret = doRegComp(ppRegex, ppMatchData, wktPatternWithSpace); + code = doRegComp(ppRegex, ppMatchData, wktPatternWithSpace); taosMemoryFree(wktPatternWithSpace); - return ret; + return code; } int32_t initCtxGeomFromText() { diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index c1995ab784..844a608456 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -1523,7 +1523,7 @@ static int32_t biMakeTbnameProjectAstNode(char* funcName, char* tableAlias, SNod if (!multiResFunc) { code = TSDB_CODE_OUT_OF_MEMORY; } - + if (TSDB_CODE_SUCCESS == code) { tstrncpy(multiResFunc->functionName, funcName, TSDB_FUNC_NAME_LEN); code = nodesListMakeStrictAppend(&multiResFunc->pParameterList, (SNode*)tbNameFunc); @@ -5233,7 +5233,8 @@ static int32_t translateFill(STranslateContext* pCxt, SSelectStmt* pSelect, SInt } static int64_t getMonthsFromTimeVal(int64_t val, int32_t fromPrecision, char unit) { - int64_t days = convertTimeFromPrecisionToUnit(val, fromPrecision, 'd'); + int64_t days = -1; + convertTimeFromPrecisionToUnit(val, fromPrecision, 'd', &days); switch (unit) { case 'b': case 'u': @@ -8232,7 +8233,8 @@ static SNode* makeIntervalVal(SRetention* pRetension, int8_t precision) { if (NULL == pVal) { return NULL; } - int64_t timeVal = convertTimeFromPrecisionToUnit(pRetension->freq, precision, pRetension->freqUnit); + int64_t timeVal = -1; + convertTimeFromPrecisionToUnit(pRetension->freq, precision, pRetension->freqUnit, &timeVal); char buf[20] = {0}; int32_t len = snprintf(buf, sizeof(buf), "%" PRId64 "%c", timeVal, pRetension->freqUnit); pVal->literal = strndup(buf, len); @@ -8781,7 +8783,7 @@ static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* p if (TSDB_CODE_SUCCESS == code) { code = tNameExtractFullName(&name, usedbReq.db); } - if (TSDB_CODE_SUCCESS == code) + if (TSDB_CODE_SUCCESS == code) code = getDBVgVersion(pCxt, usedbReq.db, &usedbReq.vgVersion, &usedbReq.dbId, &usedbReq.numOfTable, &usedbReq.stateTs); if (TSDB_CODE_SUCCESS == code) { code = buildCmdMsg(pCxt, TDMT_MND_USE_DB, (FSerializeFunc)tSerializeSUseDbReq, &usedbReq); diff --git a/source/util/src/tpcr2.c b/source/util/src/tpcre2.c similarity index 100% rename from source/util/src/tpcr2.c rename to source/util/src/tpcre2.c diff --git a/tests/system-test/2-query/select_null.py b/tests/system-test/2-query/select_null.py index 682a98ad19..d6e48e4f99 100755 --- a/tests/system-test/2-query/select_null.py +++ b/tests/system-test/2-query/select_null.py @@ -33,7 +33,7 @@ class TDTestCase: self.testcasePath = os.path.split(__file__)[0] self.testcaseFilename = os.path.split(__file__)[-1] os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) - + self.db = "sel_null" def insert_data(self,database,vgroups): @@ -46,10 +46,10 @@ class TDTestCase: for i in range(5): tdSql.execute('''create table %s.stb0_%d using %s.stb0 tags(%d,'varchar%d',%d,%d, %d, %d,%d,'binary%d','nchar%d',%d,%d,%d ) ;'''%(database,i,database,i,i,i,i,i,i,i,i,i,i,i,i)) - + # insert data - for i in range(num_random): - for j in range(50): + for i in range(num_random): + for j in range(50): tdSql.execute('''insert into %s.stb0_0 (ts , c1 , c0) values(now, %d, %d) ;''' % (database,j,j)) tdSql.execute('''insert into %s.stb0_1 (ts , c1 , c0) values(now, %d, %d) ;''' % (database,j,j)) tdSql.execute('''insert into %s.stb0_2 (ts , c1 , c0) values(now, %d, %d) ;''' % (database,j,j)) @@ -60,378 +60,378 @@ class TDTestCase: tdSql.checkData(0,0,5*num_random*50) tdSql.query("select count(*) from %s.stb0_0;"%database) tdSql.checkData(0,0,num_random*50) - - def ts_3085(self,database): + + def ts_3085(self,database): sql = "select count(c0null) from(select * from %s.stb0 limit 20,4) "%(database) - tdSql.query(sql) + tdSql.query(sql) tdSql.checkData(0,0,0) - + offset = random.randint(10,100) for i in range(offset): sql = "select count(c0null) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i) - tdSql.query(sql) + tdSql.query(sql) tdSql.checkData(0,0,0) sql = "select count(c1null) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i) - tdSql.query(sql) + tdSql.query(sql) tdSql.checkData(0,0,0) sql = "select count(c0) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i) - tdSql.query(sql) + tdSql.query(sql) tdSql.checkData(0,0,i) sql = "select count(c1) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i) - tdSql.query(sql) + tdSql.query(sql) tdSql.checkData(0,0,i) sql = "select count(t0) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i) - tdSql.query(sql) + tdSql.query(sql) tdSql.checkData(0,0,i) sql = "select count(t1) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i) - tdSql.query(sql) + tdSql.query(sql) tdSql.checkData(0,0,i) - def ts_2974_max(self,database): + def ts_2974_max(self,database): sql = "select max(c0) from %s.stb0 where ts