Merge remote-tracking branch 'origin/3.0' into fix/TD-31674

This commit is contained in:
dapan1121 2024-08-26 15:24:50 +08:00
commit 2eccbc3e28
58 changed files with 918 additions and 503 deletions

View File

@ -120,15 +120,29 @@ int32_t taosSetFileHandlesLimit();
int32_t taosLinkFile(char *src, char *dst); int32_t taosLinkFile(char *src, char *dst);
FILE* taosOpenCFile(const char* filename, const char* mode); FILE *taosOpenCFile(const char *filename, const char *mode);
int taosSeekCFile(FILE* file, int64_t offset, int whence); int taosSeekCFile(FILE *file, int64_t offset, int whence);
size_t taosReadFromCFile(void *buffer, size_t size, size_t count, FILE *stream ); size_t taosReadFromCFile(void *buffer, size_t size, size_t count, FILE *stream);
size_t taosWriteToCFile(const void* ptr, size_t size, size_t nitems, FILE* stream); size_t taosWriteToCFile(const void *ptr, size_t size, size_t nitems, FILE *stream);
int taosCloseCFile(FILE *); int taosCloseCFile(FILE *);
int taosSetAutoDelFile(char* path); int taosSetAutoDelFile(char *path);
bool lastErrorIsFileNotExist(); bool lastErrorIsFileNotExist();
#ifdef BUILD_WITH_RAND_ERR
#define STUB_RAND_NETWORK_ERR(status) \
do { \
if (tsEnableRandErr && (tsRandErrScope & RAND_ERR_NETWORK)) { \
uint32_t r = taosRand() % tsRandErrDivisor; \
if ((r + 1) <= tsRandErrChance) { \
status = TSDB_CODE_RPC_NETWORK_UNAVAIL; \
} \
} \
while (0)
#else
#define STUB_RAND_NETWORK_ERR(status)
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -468,6 +468,8 @@ int32_t taosGetErrSize();
#define TSDB_CODE_DNODE_INVALID_TTL_CHG_ON_WR TAOS_DEF_ERROR_CODE(0, 0x0427) #define TSDB_CODE_DNODE_INVALID_TTL_CHG_ON_WR TAOS_DEF_ERROR_CODE(0, 0x0427)
#define TSDB_CODE_DNODE_INVALID_EN_WHITELIST TAOS_DEF_ERROR_CODE(0, 0x0428) #define TSDB_CODE_DNODE_INVALID_EN_WHITELIST TAOS_DEF_ERROR_CODE(0, 0x0428)
#define TSDB_CODE_DNODE_INVALID_MONITOR_PARAS TAOS_DEF_ERROR_CODE(0, 0x0429) #define TSDB_CODE_DNODE_INVALID_MONITOR_PARAS TAOS_DEF_ERROR_CODE(0, 0x0429)
#define TSDB_CODE_MNODE_STOPPED TAOS_DEF_ERROR_CODE(0, 0x042A)
// mnode-sma // mnode-sma
#define TSDB_CODE_MND_SMA_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0480) #define TSDB_CODE_MND_SMA_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0480)

View File

@ -294,7 +294,7 @@ typedef enum ELogicConditionType {
#define TSDB_SHOW_SUBQUERY_LEN 1000 #define TSDB_SHOW_SUBQUERY_LEN 1000
#define TSDB_LOG_VAR_LEN 32 #define TSDB_LOG_VAR_LEN 32
#define TSDB_MAX_EP_NUM 10 #define TSDB_MAX_EP_NUM 10
#define TSDB_ARB_GROUP_MEMBER_NUM 2 #define TSDB_ARB_GROUP_MEMBER_NUM 2
#define TSDB_ARB_TOKEN_SIZE 32 #define TSDB_ARB_TOKEN_SIZE 32
@ -568,12 +568,7 @@ enum {
SND_WORKER_TYPE__UNIQUE, SND_WORKER_TYPE__UNIQUE,
}; };
enum { enum { RAND_ERR_MEMORY = 1, RAND_ERR_FILE = 2, RAND_ERR_NETWORK = 4 };
RAND_ERR_MEMORY = 1,
RAND_ERR_FILE = 2,
// RAND_ERR_SCOPE_XXX... = 4,
// ...
};
#define DEFAULT_HANDLE 0 #define DEFAULT_HANDLE 0
#define MNODE_HANDLE 1 #define MNODE_HANDLE 1

View File

@ -934,7 +934,8 @@ SColVal *tRowIterNext(SRowIter *pIter) {
pIter->cv = COL_VAL_NONE(pTColumn->colId, pTColumn->type); pIter->cv = COL_VAL_NONE(pTColumn->colId, pTColumn->type);
goto _exit; goto _exit;
} else { } else {
ASSERT(0); uError("unexpected column id %d, %d", cid, pTColumn->colId);
goto _exit;
} }
} else { } else {
pIter->cv = COL_VAL_NONE(pTColumn->colId, pTColumn->type); pIter->cv = COL_VAL_NONE(pTColumn->colId, pTColumn->type);
@ -1356,11 +1357,8 @@ int32_t tValueCompare(const SValue *tv1, const SValue *tv2) {
int32_t ret = memcmp(tv1->pData, tv2->pData, tv1->nData < tv2->nData ? tv1->nData : tv2->nData); int32_t ret = memcmp(tv1->pData, tv2->pData, tv1->nData < tv2->nData ? tv1->nData : tv2->nData);
return ret ? ret : (tv1->nData < tv2->nData ? -1 : (tv1->nData > tv2->nData ? 1 : 0)); return ret ? ret : (tv1->nData < tv2->nData ? -1 : (tv1->nData > tv2->nData ? 1 : 0));
} }
case TSDB_DATA_TYPE_DECIMAL:
ASSERT(0);
break;
default: default:
ASSERT(0); break;
} }
return 0; return 0;
@ -2600,7 +2598,7 @@ static FORCE_INLINE void tColDataGetValue3(SColData *pColData, int32_t iVal,
*pColVal = COL_VAL_NULL(pColData->cid, pColData->type); *pColVal = COL_VAL_NULL(pColData->cid, pColData->type);
break; break;
default: default:
ASSERT(0); break;
} }
} }
static FORCE_INLINE void tColDataGetValue4(SColData *pColData, int32_t iVal, SColVal *pColVal) { // HAS_VALUE static FORCE_INLINE void tColDataGetValue4(SColData *pColData, int32_t iVal, SColVal *pColVal) { // HAS_VALUE
@ -2628,7 +2626,7 @@ static FORCE_INLINE void tColDataGetValue5(SColData *pColData, int32_t iVal,
tColDataGetValue4(pColData, iVal, pColVal); tColDataGetValue4(pColData, iVal, pColVal);
break; break;
default: default:
ASSERT(0); break;
} }
} }
static FORCE_INLINE void tColDataGetValue6(SColData *pColData, int32_t iVal, static FORCE_INLINE void tColDataGetValue6(SColData *pColData, int32_t iVal,
@ -2641,7 +2639,7 @@ static FORCE_INLINE void tColDataGetValue6(SColData *pColData, int32_t iVal,
tColDataGetValue4(pColData, iVal, pColVal); tColDataGetValue4(pColData, iVal, pColVal);
break; break;
default: default:
ASSERT(0); break;
} }
} }
static FORCE_INLINE void tColDataGetValue7(SColData *pColData, int32_t iVal, static FORCE_INLINE void tColDataGetValue7(SColData *pColData, int32_t iVal,
@ -2657,7 +2655,7 @@ static FORCE_INLINE void tColDataGetValue7(SColData *pColData, int32_t iVal,
tColDataGetValue4(pColData, iVal, pColVal); tColDataGetValue4(pColData, iVal, pColVal);
break; break;
default: default:
ASSERT(0); break;
} }
} }
static void (*tColDataGetValueImpl[])(SColData *pColData, int32_t iVal, SColVal *pColVal) = { static void (*tColDataGetValueImpl[])(SColData *pColData, int32_t iVal, SColVal *pColVal) = {
@ -2671,7 +2669,6 @@ static void (*tColDataGetValueImpl[])(SColData *pColData, int32_t iVal, SColVal
tColDataGetValue7 // HAS_VALUE | HAS_NULL | HAS_NONE tColDataGetValue7 // HAS_VALUE | HAS_NULL | HAS_NONE
}; };
void tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal) { void tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal) {
ASSERT(iVal >= 0 && iVal < pColData->nVal && pColData->flag);
tColDataGetValueImpl[pColData->flag](pColData, iVal, pColVal); tColDataGetValueImpl[pColData->flag](pColData, iVal, pColVal);
} }
@ -3334,7 +3331,8 @@ static void tColDataMergeImpl(SColData *pColData, int32_t iStart, int32_t iEnd /
} else if (bv == BIT_FLG_NULL) { } else if (bv == BIT_FLG_NULL) {
flag |= HAS_NULL; flag |= HAS_NULL;
} else { } else {
ASSERT(0); uError("invalid bit value:%d", bv);
return;
} }
if (flag == pColData->flag) break; if (flag == pColData->flag) break;

View File

@ -397,11 +397,6 @@ char getPrecisionUnit(int32_t precision) {
} }
int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPrecision) { int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPrecision) {
ASSERT(fromPrecision == TSDB_TIME_PRECISION_MILLI || fromPrecision == TSDB_TIME_PRECISION_MICRO ||
fromPrecision == TSDB_TIME_PRECISION_NANO);
ASSERT(toPrecision == TSDB_TIME_PRECISION_MILLI || toPrecision == TSDB_TIME_PRECISION_MICRO ||
toPrecision == TSDB_TIME_PRECISION_NANO);
switch (fromPrecision) { switch (fromPrecision) {
case TSDB_TIME_PRECISION_MILLI: { case TSDB_TIME_PRECISION_MILLI: {
switch (toPrecision) { switch (toPrecision) {
@ -418,7 +413,6 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre
} }
return utime * 1000000; return utime * 1000000;
default: default:
ASSERT(0);
return utime; return utime;
} }
} // end from milli } // end from milli
@ -434,7 +428,6 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre
} }
return utime * 1000; return utime * 1000;
default: default:
ASSERT(0);
return utime; return utime;
} }
} // end from micro } // end from micro
@ -447,12 +440,10 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre
case TSDB_TIME_PRECISION_NANO: case TSDB_TIME_PRECISION_NANO:
return utime; return utime;
default: default:
ASSERT(0);
return utime; return utime;
} }
} // end from nano } // end from nano
default: { default: {
ASSERT(0);
return utime; // only to pass windows compilation return utime; // only to pass windows compilation
} }
} // end switch fromPrecision } // end switch fromPrecision
@ -463,10 +454,6 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre
// !!!!notice:there are precision problems, double lose precison if time is too large, for example: // !!!!notice:there are precision problems, double lose precison if time is too large, for example:
// 1626006833631000000*1.0 = double = 1626006833631000064 // 1626006833631000000*1.0 = double = 1626006833631000064
// int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision) { // int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision) {
// assert(fromPrecision == TSDB_TIME_PRECISION_MILLI || fromPrecision == TSDB_TIME_PRECISION_MICRO ||
// fromPrecision == TSDB_TIME_PRECISION_NANO);
// assert(toPrecision == TSDB_TIME_PRECISION_MILLI || toPrecision == TSDB_TIME_PRECISION_MICRO ||
// toPrecision == TSDB_TIME_PRECISION_NANO);
// static double factors[3][3] = {{1., 1000., 1000000.}, {1.0 / 1000, 1., 1000.}, {1.0 / 1000000, 1.0 / 1000, 1.}}; // static double factors[3][3] = {{1., 1000., 1000000.}, {1.0 / 1000, 1., 1000.}, {1.0 / 1000000, 1.0 / 1000, 1.}};
// ((double)time * factors[fromPrecision][toPrecision]); // ((double)time * factors[fromPrecision][toPrecision]);
//} //}
@ -783,7 +770,6 @@ int32_t taosTimeCountIntervalForFill(int64_t skey, int64_t ekey, int64_t interva
int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) { int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) {
if (pInterval->sliding == 0) { if (pInterval->sliding == 0) {
ASSERT(pInterval->interval == 0);
return ts; return ts;
} }
@ -814,7 +800,6 @@ int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) {
} else { } else {
if (IS_CALENDAR_TIME_DURATION(pInterval->intervalUnit)) { if (IS_CALENDAR_TIME_DURATION(pInterval->intervalUnit)) {
int64_t news = (ts / pInterval->sliding) * pInterval->sliding; int64_t news = (ts / pInterval->sliding) * pInterval->sliding;
ASSERT(news <= ts);
if (pInterval->slidingUnit == 'd' || pInterval->slidingUnit == 'w') { if (pInterval->slidingUnit == 'd' || pInterval->slidingUnit == 'w') {
#if defined(WINDOWS) && _MSC_VER >= 1900 #if defined(WINDOWS) && _MSC_VER >= 1900
int64_t timezone = _timezone; int64_t timezone = _timezone;
@ -887,8 +872,6 @@ int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) {
} }
} }
ASSERT(pInterval->offset >= 0);
if (pInterval->offset > 0) { if (pInterval->offset > 0) {
// try to move current window to the left-hande-side, due to the offset effect. // try to move current window to the left-hande-side, due to the offset effect.
int64_t newe = taosTimeAdd(start, pInterval->interval, pInterval->intervalUnit, precision) - 1; int64_t newe = taosTimeAdd(start, pInterval->interval, pInterval->intervalUnit, precision) - 1;
@ -1284,7 +1267,6 @@ static int32_t parseTsFormat(const char* formatStr, SArray* formats) {
} }
if (last) { if (last) {
// expand // expand
assert(last->type == TS_FORMAT_NODE_TYPE_CHAR);
last->len++; last->len++;
formatStr++; formatStr++;
} else { } else {
@ -1311,7 +1293,6 @@ static int32_t parseTsFormat(const char* formatStr, SArray* formats) {
} }
} }
if (lastOtherFormat) { if (lastOtherFormat) {
assert(lastOtherFormat->type == TS_FORMAT_NODE_TYPE_CHAR);
lastOtherFormat->len++; lastOtherFormat->len++;
formatStr++; formatStr++;
} else { } else {
@ -1664,7 +1645,6 @@ static int32_t char2ts(const char* s, SArray* formats, int64_t* ts, int32_t prec
} }
continue; continue;
} }
assert(node->type == TS_FORMAT_NODE_TYPE_KEYWORD);
switch (node->key->id) { switch (node->key->id) {
case TSFKW_A_M: case TSFKW_A_M:
case TSFKW_P_M: case TSFKW_P_M:
@ -1929,7 +1909,7 @@ static int32_t char2ts(const char* s, SArray* formats, int64_t* ts, int32_t prec
int32_t taosTs2Char(const char* format, SArray** formats, int64_t ts, int32_t precision, char* out, int32_t outLen) { int32_t taosTs2Char(const char* format, SArray** formats, int64_t ts, int32_t precision, char* out, int32_t outLen) {
if (!*formats) { if (!*formats) {
*formats = taosArrayInit(8, sizeof(TSFormatNode)); *formats = taosArrayInit(8, sizeof(TSFormatNode));
if (!*formats){ if (!*formats) {
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
} }
TAOS_CHECK_RETURN(parseTsFormat(format, *formats)); TAOS_CHECK_RETURN(parseTsFormat(format, *formats));
@ -2002,7 +1982,7 @@ static int8_t UNIT_INDEX[26] = {/*a*/ 2, 0, -1, 6, -1, -1, -1,
/*o*/ -1, -1, -1, -1, 3, -1, /*o*/ -1, -1, -1, -1, 3, -1,
/*u*/ 1, -1, 7, -1, 9, -1}; /*u*/ 1, -1, 7, -1, 9, -1};
#define GET_UNIT_INDEX(idx) UNIT_INDEX[(idx) - 97] #define GET_UNIT_INDEX(idx) UNIT_INDEX[(idx)-97]
// clang-format off // clang-format off
static int64_t UNIT_MATRIX[10][11] = { /* ns, us, ms, s, min, h, d, w, month, y*/ static int64_t UNIT_MATRIX[10][11] = { /* ns, us, ms, s, min, h, d, w, month, y*/

View File

@ -22,7 +22,7 @@ static inline int32_t mmAcquire(SMnodeMgmt *pMgmt) {
int32_t code = 0; int32_t code = 0;
(void)taosThreadRwlockRdlock(&pMgmt->lock); (void)taosThreadRwlockRdlock(&pMgmt->lock);
if (pMgmt->stopped) { if (pMgmt->stopped) {
code = -1; code = TSDB_CODE_MNODE_STOPPED;
} else { } else {
(void)atomic_add_fetch_32(&pMgmt->refCount, 1); (void)atomic_add_fetch_32(&pMgmt->refCount, 1);
} }
@ -134,16 +134,19 @@ int32_t mmPutMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
} }
int32_t mmPutMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { int32_t mmPutMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
int32_t code = 0;
if (NULL == pMgmt->pMnode) { if (NULL == pMgmt->pMnode) {
const STraceId *trace = &pMsg->info.traceId; const STraceId *trace = &pMsg->info.traceId;
dGError("msg:%p, stop to pre-process in mnode since mnode is NULL, type:%s", pMsg, TMSG_INFO(pMsg->msgType)); code = TSDB_CODE_MNODE_NOT_FOUND;
return -1; dGError("msg:%p, stop to pre-process in mnode since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
return code;
} }
pMsg->info.node = pMgmt->pMnode; pMsg->info.node = pMgmt->pMnode;
if (mndPreProcessQueryMsg(pMsg) != 0) { if ((code = mndPreProcessQueryMsg(pMsg)) != 0) {
const STraceId *trace = &pMsg->info.traceId; const STraceId *trace = &pMsg->info.traceId;
dGError("msg:%p, failed to pre-process in mnode since %s, type:%s", pMsg, terrstr(), TMSG_INFO(pMsg->msgType)); dGError("msg:%p, failed to pre-process in mnode since %s, type:%s", pMsg, tstrerror(code),
return -1; TMSG_INFO(pMsg->msgType));
return code;
} }
return mmPutMsgToWorker(pMgmt, &pMgmt->queryWorker, pMsg); return mmPutMsgToWorker(pMgmt, &pMgmt->queryWorker, pMsg);
} }

View File

@ -29,7 +29,7 @@ void mndReleaseArbGroup(SMnode *pMnode, SArbGroup *pObj);
SSdbRaw *mndArbGroupActionEncode(SArbGroup *pGroup); SSdbRaw *mndArbGroupActionEncode(SArbGroup *pGroup);
SSdbRow *mndArbGroupActionDecode(SSdbRaw *pRaw); SSdbRow *mndArbGroupActionDecode(SSdbRaw *pRaw);
void mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup); int32_t mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup);
int32_t mndSetCreateArbGroupRedoLogs(STrans *pTrans, SArbGroup *pGroup); int32_t mndSetCreateArbGroupRedoLogs(STrans *pTrans, SArbGroup *pGroup);
int32_t mndSetCreateArbGroupUndoLogs(STrans *pTrans, SArbGroup *pGroup); int32_t mndSetCreateArbGroupUndoLogs(STrans *pTrans, SArbGroup *pGroup);

View File

@ -102,8 +102,10 @@ void mndReleaseArbGroup(SMnode *pMnode, SArbGroup *pGroup) {
sdbRelease(pSdb, pGroup); sdbRelease(pSdb, pGroup);
} }
void mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup) { int32_t mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup) {
ASSERT(pVgObj->replica == 2); if (pVgObj->replica != 2) {
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
}
(void)memset(outGroup, 0, sizeof(SArbGroup)); (void)memset(outGroup, 0, sizeof(SArbGroup));
outGroup->dbUid = pVgObj->dbUid; outGroup->dbUid = pVgObj->dbUid;
outGroup->vgId = pVgObj->vgId; outGroup->vgId = pVgObj->vgId;
@ -111,6 +113,8 @@ void mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup) {
SArbGroupMember *pMember = &outGroup->members[i]; SArbGroupMember *pMember = &outGroup->members[i];
pMember->info.dnodeId = pVgObj->vnodeGid[i].dnodeId; pMember->info.dnodeId = pVgObj->vnodeGid[i].dnodeId;
} }
TAOS_RETURN(TSDB_CODE_SUCCESS);
} }
SSdbRaw *mndArbGroupActionEncode(SArbGroup *pGroup) { SSdbRaw *mndArbGroupActionEncode(SArbGroup *pGroup) {

View File

@ -629,7 +629,7 @@ static int32_t mndSetCreateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD
for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) { for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) {
SVgObj *pVgObj = pVgroups + v; SVgObj *pVgObj = pVgroups + v;
SArbGroup arbGroup = {0}; SArbGroup arbGroup = {0};
mndArbGroupInitFromVgObj(pVgObj, &arbGroup); TAOS_CHECK_RETURN(mndArbGroupInitFromVgObj(pVgObj, &arbGroup));
TAOS_CHECK_RETURN(mndSetCreateArbGroupRedoLogs(pTrans, &arbGroup)); TAOS_CHECK_RETURN(mndSetCreateArbGroupRedoLogs(pTrans, &arbGroup));
} }
} }
@ -663,7 +663,7 @@ static int32_t mndSetCreateDbUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD
for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) { for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) {
SVgObj *pVgObj = pVgroups + v; SVgObj *pVgObj = pVgroups + v;
SArbGroup arbGroup = {0}; SArbGroup arbGroup = {0};
mndArbGroupInitFromVgObj(pVgObj, &arbGroup); TAOS_CHECK_RETURN(mndArbGroupInitFromVgObj(pVgObj, &arbGroup));
TAOS_CHECK_RETURN(mndSetCreateArbGroupUndoLogs(pTrans, &arbGroup)); TAOS_CHECK_RETURN(mndSetCreateArbGroupUndoLogs(pTrans, &arbGroup));
} }
} }
@ -698,7 +698,7 @@ static int32_t mndSetCreateDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *
for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) { for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) {
SVgObj *pVgObj = pVgroups + v; SVgObj *pVgObj = pVgroups + v;
SArbGroup arbGroup = {0}; SArbGroup arbGroup = {0};
mndArbGroupInitFromVgObj(pVgObj, &arbGroup); TAOS_CHECK_RETURN(mndArbGroupInitFromVgObj(pVgObj, &arbGroup));
TAOS_CHECK_RETURN(mndSetCreateArbGroupCommitLogs(pTrans, &arbGroup)); TAOS_CHECK_RETURN(mndSetCreateArbGroupCommitLogs(pTrans, &arbGroup));
} }
} }
@ -1156,44 +1156,30 @@ static int32_t mndSetAlterDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *p
} }
static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) {
int32_t code = 0; int32_t code = 0, lino = 0;
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
void *pIter = NULL; void *pIter = NULL;
SVgObj *pVgroup = NULL;
SArray *pArray = mndBuildDnodesArray(pMnode, 0); SArray *pArray = mndBuildDnodesArray(pMnode, 0);
while (1) { while (1) {
SVgObj *pVgroup = NULL;
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break; if (pIter == NULL) break;
if (mndVgroupInDb(pVgroup, pNewDb->uid)) { if (mndVgroupInDb(pVgroup, pNewDb->uid)) {
SVgObj newVgroup = {0}; SVgObj newVgroup = {0};
if ((code = mndBuildAlterVgroupAction(pMnode, pTrans, pOldDb, pNewDb, pVgroup, pArray, &newVgroup)) != 0) { TAOS_CHECK_GOTO(mndBuildAlterVgroupAction(pMnode, pTrans, pOldDb, pNewDb, pVgroup, pArray, &newVgroup), &lino,
sdbCancelFetch(pSdb, pIter); _err);
sdbRelease(pSdb, pVgroup);
taosArrayDestroy(pArray);
TAOS_RETURN(code);
}
if (pNewDb->cfg.withArbitrator != pOldDb->cfg.withArbitrator) { if (pNewDb->cfg.withArbitrator != pOldDb->cfg.withArbitrator) {
if (pNewDb->cfg.withArbitrator) { if (pNewDb->cfg.withArbitrator) {
SArbGroup arbGroup = {0}; SArbGroup arbGroup = {0};
mndArbGroupInitFromVgObj(&newVgroup, &arbGroup); TAOS_CHECK_GOTO(mndArbGroupInitFromVgObj(&newVgroup, &arbGroup), &lino, _err);
if ((code = mndSetCreateArbGroupCommitLogs(pTrans, &arbGroup)) != 0) { TAOS_CHECK_GOTO(mndSetCreateArbGroupCommitLogs(pTrans, &arbGroup), &lino, _err);
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
taosArrayDestroy(pArray);
TAOS_RETURN(code);
}
} else { } else {
SArbGroup arbGroup = {0}; SArbGroup arbGroup = {0};
mndArbGroupInitFromVgObj(pVgroup, &arbGroup); TAOS_CHECK_GOTO(mndArbGroupInitFromVgObj(pVgroup, &arbGroup), &lino, _err);
if ((code = mndSetDropArbGroupCommitLogs(pTrans, &arbGroup)) != 0) { TAOS_CHECK_GOTO(mndSetDropArbGroupCommitLogs(pTrans, &arbGroup), &lino, _err);
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
taosArrayDestroy(pArray);
TAOS_RETURN(code);
}
} }
} }
} }
@ -1203,6 +1189,14 @@ static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *
taosArrayDestroy(pArray); taosArrayDestroy(pArray);
TAOS_RETURN(code); TAOS_RETURN(code);
_err:
mError("db:%s, %s failed at %d since %s", pNewDb->name, __func__, lino, tstrerror(code));
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
taosArrayDestroy(pArray);
TAOS_RETURN(code);
} }
static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *pNew) { static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *pNew) {

View File

@ -180,7 +180,11 @@ static void mndFreeShowObj(SShowObj *pShow) {
ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type]; ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
if (freeFp != NULL) { if (freeFp != NULL) {
if (pShow->pIter != NULL) { if (pShow->pIter != NULL) {
mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
(*freeFp)(pMnode, pShow->pIter); (*freeFp)(pMnode, pShow->pIter);
pShow->pIter = NULL;
} }
} }

View File

@ -3147,7 +3147,7 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_
if (TSDB_CODE_MND_USER_NOT_EXIST == code) { if (TSDB_CODE_MND_USER_NOT_EXIST == code) {
SGetUserAuthRsp rsp = {.dropped = 1}; SGetUserAuthRsp rsp = {.dropped = 1};
(void)memcpy(rsp.user, pUsers[i].user, TSDB_USER_LEN); (void)memcpy(rsp.user, pUsers[i].user, TSDB_USER_LEN);
(void)taosArrayPush(batchRsp.pArray, &rsp); TSDB_CHECK_NULL(taosArrayPush(batchRsp.pArray, &rsp), code, lino, _OVER, TSDB_CODE_OUT_OF_MEMORY);
} }
mError("user:%s, failed to auth user since %s", pUsers[i].user, tstrerror(code)); mError("user:%s, failed to auth user since %s", pUsers[i].user, tstrerror(code));
code = 0; code = 0;
@ -3168,7 +3168,12 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_
TAOS_CHECK_GOTO(code, &lino, _OVER); TAOS_CHECK_GOTO(code, &lino, _OVER);
} }
(void)taosArrayPush(batchRsp.pArray, &rsp); if (!(taosArrayPush(batchRsp.pArray, &rsp))) {
code = TSDB_CODE_OUT_OF_MEMORY;
mndReleaseUser(pMnode, pUser);
tFreeSGetUserAuthRsp(&rsp);
TAOS_CHECK_GOTO(code, &lino, _OVER);
}
mndReleaseUser(pMnode, pUser); mndReleaseUser(pMnode, pUser);
} }

View File

@ -129,7 +129,11 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const
} }
SIndexMultiTerm *terms = indexMultiTermCreate(); SIndexMultiTerm *terms = indexMultiTermCreate();
int16_t nCols = taosArrayGetSize(pTagVals); if (terms == NULL) {
return terrno;
}
int16_t nCols = taosArrayGetSize(pTagVals);
for (int i = 0; i < nCols; i++) { for (int i = 0; i < nCols; i++) {
STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, i); STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, i);
char type = pTagVal->type; char type = pTagVal->type;
@ -142,8 +146,14 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const
term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_VARCHAR, key, nKey, NULL, 0); term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_VARCHAR, key, nKey, NULL, 0);
} else if (type == TSDB_DATA_TYPE_NCHAR) { } else if (type == TSDB_DATA_TYPE_NCHAR) {
if (pTagVal->nData > 0) { if (pTagVal->nData > 0) {
char *val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE); char *val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE);
if (val == NULL) {
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception);
}
int32_t len = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, val + VARSTR_HEADER_SIZE); int32_t len = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, val + VARSTR_HEADER_SIZE);
if (len < 0) {
TAOS_CHECK_GOTO(len, NULL, _exception);
}
memcpy(val, (uint16_t *)&len, VARSTR_HEADER_SIZE); memcpy(val, (uint16_t *)&len, VARSTR_HEADER_SIZE);
type = TSDB_DATA_TYPE_VARCHAR; type = TSDB_DATA_TYPE_VARCHAR;
term = indexTermCreate(suid, ADD_VALUE, type, key, nKey, val, len); term = indexTermCreate(suid, ADD_VALUE, type, key, nKey, val, len);
@ -160,16 +170,24 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const
int len = sizeof(val); int len = sizeof(val);
term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BOOL, key, nKey, (const char *)&val, len); term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BOOL, key, nKey, (const char *)&val, len);
} }
if (term != NULL) { if (term != NULL) {
(void)indexMultiTermAdd(terms, term); (void)indexMultiTermAdd(terms, term);
} else {
code = terrno;
goto _exception;
} }
} }
(void)indexJsonPut(pMeta->pTagIvtIdx, terms, tuid); code = indexJsonPut(pMeta->pTagIvtIdx, terms, tuid);
indexMultiTermDestroy(terms); indexMultiTermDestroy(terms);
taosArrayDestroy(pTagVals); taosArrayDestroy(pTagVals);
#endif #endif
return 0; return code;
_exception:
indexMultiTermDestroy(terms);
taosArrayDestroy(pTagVals);
return code;
} }
int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema) { int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema) {
#ifdef USE_INVERTED_INDEX #ifdef USE_INVERTED_INDEX
@ -191,7 +209,11 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche
} }
SIndexMultiTerm *terms = indexMultiTermCreate(); SIndexMultiTerm *terms = indexMultiTermCreate();
int16_t nCols = taosArrayGetSize(pTagVals); if (terms == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
int16_t nCols = taosArrayGetSize(pTagVals);
for (int i = 0; i < nCols; i++) { for (int i = 0; i < nCols; i++) {
STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, i); STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, i);
char type = pTagVal->type; char type = pTagVal->type;
@ -204,8 +226,14 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche
term = indexTermCreate(suid, DEL_VALUE, TSDB_DATA_TYPE_VARCHAR, key, nKey, NULL, 0); term = indexTermCreate(suid, DEL_VALUE, TSDB_DATA_TYPE_VARCHAR, key, nKey, NULL, 0);
} else if (type == TSDB_DATA_TYPE_NCHAR) { } else if (type == TSDB_DATA_TYPE_NCHAR) {
if (pTagVal->nData > 0) { if (pTagVal->nData > 0) {
char *val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE); char *val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE);
if (val == NULL) {
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception);
}
int32_t len = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, val + VARSTR_HEADER_SIZE); int32_t len = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, val + VARSTR_HEADER_SIZE);
if (len < 0) {
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception);
}
memcpy(val, (uint16_t *)&len, VARSTR_HEADER_SIZE); memcpy(val, (uint16_t *)&len, VARSTR_HEADER_SIZE);
type = TSDB_DATA_TYPE_VARCHAR; type = TSDB_DATA_TYPE_VARCHAR;
term = indexTermCreate(suid, DEL_VALUE, type, key, nKey, val, len); term = indexTermCreate(suid, DEL_VALUE, type, key, nKey, val, len);
@ -224,13 +252,20 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche
} }
if (term != NULL) { if (term != NULL) {
(void)indexMultiTermAdd(terms, term); (void)indexMultiTermAdd(terms, term);
} else {
code = terrno;
goto _exception;
} }
} }
(void)indexJsonPut(pMeta->pTagIvtIdx, terms, tuid); code = indexJsonPut(pMeta->pTagIvtIdx, terms, tuid);
indexMultiTermDestroy(terms); indexMultiTermDestroy(terms);
taosArrayDestroy(pTagVals); taosArrayDestroy(pTagVals);
#endif #endif
return 0; return code;
_exception:
indexMultiTermDestroy(terms);
taosArrayDestroy(pTagVals);
return code;
} }
static inline void metaTimeSeriesNotifyCheck(SMeta *pMeta) { static inline void metaTimeSeriesNotifyCheck(SMeta *pMeta) {
@ -867,7 +902,6 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq)
goto _err; goto _err;
} }
nStbEntry.stbEntry.schemaRow = *row; nStbEntry.stbEntry.schemaRow = *row;
nStbEntry.stbEntry.schemaTag = *tag; nStbEntry.stbEntry.schemaTag = *tag;
nStbEntry.stbEntry.rsmaParam = oStbEntry.stbEntry.rsmaParam; nStbEntry.stbEntry.rsmaParam = oStbEntry.stbEntry.rsmaParam;
@ -1580,7 +1614,12 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
: pAlterTbReq->compress; : pAlterTbReq->compress;
(void)updataTableColCmpr(&entry.colCmpr, pCol, 1, compress); (void)updataTableColCmpr(&entry.colCmpr, pCol, 1, compress);
freeColCmpr = true; freeColCmpr = true;
ASSERT(entry.colCmpr.nCols == pSchema->nCols); if (entry.colCmpr.nCols != pSchema->nCols) {
if (pNewSchema) taosMemoryFree(pNewSchema);
if (freeColCmpr) taosMemoryFree(entry.colCmpr.pColCmpr);
terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION;
goto _err;
}
break; break;
case TSDB_ALTER_TABLE_DROP_COLUMN: case TSDB_ALTER_TABLE_DROP_COLUMN:
if (pColumn == NULL) { if (pColumn == NULL) {
@ -1617,7 +1656,10 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
} }
(void)updataTableColCmpr(&entry.colCmpr, &tScheam, 0, 0); (void)updataTableColCmpr(&entry.colCmpr, &tScheam, 0, 0);
ASSERT(entry.colCmpr.nCols == pSchema->nCols); if (entry.colCmpr.nCols != pSchema->nCols) {
terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION;
goto _err;
}
break; break;
case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES: case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:
if (pColumn == NULL) { if (pColumn == NULL) {
@ -1698,7 +1740,7 @@ _err:
(void)tdbTbcClose(pUidIdxc); (void)tdbTbcClose(pUidIdxc);
tDecoderClear(&dc); tDecoderClear(&dc);
return TSDB_CODE_FAILED; return terrno != 0 ? terrno : TSDB_CODE_FAILED;
} }
static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) {
@ -2514,8 +2556,7 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
if (tdbTbGet(pMeta->pUidIdx, &pCtbEntry->ctbEntry.suid, sizeof(tb_uid_t), &pData, &nData) != 0) { if (tdbTbGet(pMeta->pUidIdx, &pCtbEntry->ctbEntry.suid, sizeof(tb_uid_t), &pData, &nData) != 0) {
metaError("vgId:%d, failed to get stable suid for update. version:%" PRId64, TD_VID(pMeta->pVnode), metaError("vgId:%d, failed to get stable suid for update. version:%" PRId64, TD_VID(pMeta->pVnode),
pCtbEntry->version); pCtbEntry->version);
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID; ret = TSDB_CODE_TDB_INVALID_TABLE_ID;
ret = -1;
goto end; goto end;
} }
tbDbKey.uid = pCtbEntry->ctbEntry.suid; tbDbKey.uid = pCtbEntry->ctbEntry.suid;
@ -2529,6 +2570,7 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
} }
if (stbEntry.stbEntry.schemaTag.pSchema == NULL) { if (stbEntry.stbEntry.schemaTag.pSchema == NULL) {
ret = TSDB_CODE_INVALID_PARA;
goto end; goto end;
} }
@ -2573,7 +2615,9 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
} }
} }
end: end:
// metaDestroyTagIdxKey(pTagIdxKey); if (terrno != 0) {
ret = terrno;
}
tDecoderClear(&dc); tDecoderClear(&dc);
tdbFree(pData); tdbFree(pData);
return ret; return ret;

View File

@ -213,7 +213,7 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
TAOS_CHECK_GOTO(code, &lino, _exit); TAOS_CHECK_GOTO(code, &lino, _exit);
} }
SSDataBlock datablock = {.info.type = STREAM_CHECKPOINT}; SSDataBlock datablock = {.info.type = STREAM_CHECKPOINT};
(void)taosArrayPush(pRSmaStat->blocks, &datablock); TSDB_CHECK_NULL(taosArrayPush(pRSmaStat->blocks, &datablock), code, lino, _exit, TSDB_CODE_OUT_OF_MEMORY);
// init smaMgmt // init smaMgmt
TAOS_CHECK_GOTO(smaInit(), &lino, _exit); TAOS_CHECK_GOTO(smaInit(), &lino, _exit);

View File

@ -1430,7 +1430,7 @@ static void tdFreeRSmaSubmitItems(SArray *pItems, int32_t type) {
blockDataDestroy(packData->pDataBlock); blockDataDestroy(packData->pDataBlock);
} }
} else { } else {
ASSERTS(0, "unknown type:%d", type); smaWarn("%s:%d unknown type:%d", __func__, __LINE__, type);
} }
taosArrayClear(pItems); taosArrayClear(pItems);
} }
@ -1540,14 +1540,13 @@ static int32_t tdRSmaBatchExec(SSma *pSma, SRSmaInfo *pInfo, STaosQall *qall, SA
++nDelete; ++nDelete;
} }
} else { } else {
ASSERTS(0, "unknown msg type:%d", inputType); smaWarn("%s:%d unknown msg type:%d", __func__, __LINE__, inputType);
break; break;
} }
} }
if (nSubmit > 0 || nDelete > 0) { if (nSubmit > 0 || nDelete > 0) {
int32_t size = TARRAY_SIZE(pSubmitArr); int32_t size = TARRAY_SIZE(pSubmitArr);
ASSERTS(size > 0, "size is %d", size);
int32_t inputType = nSubmit > 0 ? STREAM_INPUT__MERGED_SUBMIT : STREAM_INPUT__REF_DATA_BLOCK; int32_t inputType = nSubmit > 0 ? STREAM_INPUT__MERGED_SUBMIT : STREAM_INPUT__REF_DATA_BLOCK;
for (int32_t i = 1; i <= TSDB_RETENTION_L2; ++i) { for (int32_t i = 1; i <= TSDB_RETENTION_L2; ++i) {
TAOS_CHECK_EXIT(tdExecuteRSmaImpl(pSma, pSubmitArr->pData, size, version, inputType, pInfo, type, i)); TAOS_CHECK_EXIT(tdExecuteRSmaImpl(pSma, pSubmitArr->pData, size, version, inputType, pInfo, type, i));
@ -1677,7 +1676,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
} }
} }
} else { } else {
ASSERTS(0, "unknown rsma exec type:%d", (int32_t)type); smaWarn("%s:%d unknown rsma exec type:%d", __func__, __LINE__, (int32_t)type);
code = TSDB_CODE_APP_ERROR; code = TSDB_CODE_APP_ERROR;
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }

View File

@ -3162,6 +3162,7 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
SLastCol lastCol = {.rowKey = rowKey.key, .colVal = *pColVal, .cacheStatus = TSDB_LAST_CACHE_VALID}; SLastCol lastCol = {.rowKey = rowKey.key, .colVal = *pColVal, .cacheStatus = TSDB_LAST_CACHE_VALID};
TAOS_CHECK_GOTO(tsdbCacheReallocSLastCol(&lastCol, NULL), &lino, _err); TAOS_CHECK_GOTO(tsdbCacheReallocSLastCol(&lastCol, NULL), &lino, _err);
tsdbCacheFreeSLastColItem(lastColVal);
taosArraySet(pColArray, iCol, &lastCol); taosArraySet(pColArray, iCol, &lastCol);
int32_t aColIndex = taosArraySearchIdx(aColArray, &lastCol.colVal.cid, compareInt16Val, TD_EQ); int32_t aColIndex = taosArraySearchIdx(aColArray, &lastCol.colVal.cid, compareInt16Val, TD_EQ);
if (aColIndex >= 0) { if (aColIndex >= 0) {

View File

@ -1036,7 +1036,9 @@ static int32_t tsdbDataFileDoWriteBlockData(SDataFileWriter *writer, SBlockData
code = metaGetColCmpr(writer->config->tsdb->pVnode->pMeta, bData->suid != 0 ? bData->suid : bData->uid, code = metaGetColCmpr(writer->config->tsdb->pVnode->pMeta, bData->suid != 0 ? bData->suid : bData->uid,
&cmprInfo.pColCmpr); &cmprInfo.pColCmpr);
ASSERT(code == TSDB_CODE_SUCCESS); if (code) {
tsdbWarn("vgId:%d failed to get column compress algrithm", TD_VID(writer->config->tsdb->pVnode));
}
TAOS_CHECK_GOTO(tBlockDataCompress(bData, &cmprInfo, buffers, assist), &lino, _exit); TAOS_CHECK_GOTO(tBlockDataCompress(bData, &cmprInfo, buffers, assist), &lino, _exit);

View File

@ -319,7 +319,7 @@ static int32_t extractSttBlockInfo(SLDataIter *pIter, const TSttBlkArray *pArray
} else { // all blocks are qualified } else { // all blocks are qualified
taosArrayClear(pBlockLoadInfo->aSttBlk); taosArrayClear(pBlockLoadInfo->aSttBlk);
px = taosArrayAddBatch(pBlockLoadInfo->aSttBlk, pArray->data, pArray->size); px = taosArrayAddBatch(pBlockLoadInfo->aSttBlk, pArray->data, pArray->size);
if (px == NULL){ if (px == NULL) {
return terrno; return terrno;
} }
} }
@ -336,7 +336,7 @@ static int32_t extractSttBlockInfo(SLDataIter *pIter, const TSttBlkArray *pArray
} }
if (p->suid == suid) { if (p->suid == suid) {
void* px = taosArrayPush(pTmp, p); void *px = taosArrayPush(pTmp, p);
if (px == NULL) { if (px == NULL) {
code = terrno; code = terrno;
break; break;
@ -372,7 +372,7 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl
TStatisBlkArray *pStatisBlkArray, uint64_t suid, const char *id) { TStatisBlkArray *pStatisBlkArray, uint64_t suid, const char *id) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0; int32_t lino = 0;
void* px = NULL; void *px = NULL;
int32_t startIndex = 0; int32_t startIndex = 0;
int32_t numOfBlocks = TARRAY2_SIZE(pStatisBlkArray); int32_t numOfBlocks = TARRAY2_SIZE(pStatisBlkArray);
@ -415,7 +415,7 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl
// existed // existed
if (i < rows) { if (i < rows) {
SSttTableRowsInfo* pInfo = &pBlockLoadInfo->info; SSttTableRowsInfo *pInfo = &pBlockLoadInfo->info;
if (pInfo->pUid == NULL) { if (pInfo->pUid == NULL) {
pInfo->pUid = taosArrayInit(rows, sizeof(int64_t)); pInfo->pUid = taosArrayInit(rows, sizeof(int64_t));
@ -530,7 +530,7 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl
} }
} }
_end: _end:
(void)tStatisBlockDestroy(&block); (void)tStatisBlockDestroy(&block);
double el = (taosGetTimestampUs() - st) / 1000.0; double el = (taosGetTimestampUs() - st) / 1000.0;
@ -672,7 +672,7 @@ int32_t tLDataIterOpen2(SLDataIter *pIter, SSttFileReader *pSttFileReader, int32
} }
void tLDataIterClose2(SLDataIter *pIter) { void tLDataIterClose2(SLDataIter *pIter) {
(void) tsdbSttFileReaderClose(&pIter->pReader); // always return 0 (void)tsdbSttFileReaderClose(&pIter->pReader); // always return 0
pIter->pReader = NULL; pIter->pReader = NULL;
} }
@ -826,7 +826,7 @@ static int32_t findNextValidRow(SLDataIter *pIter, const char *idStr) {
return code; return code;
} }
int32_t tLDataIterNextRow(SLDataIter *pIter, const char *idStr, bool* hasNext) { int32_t tLDataIterNextRow(SLDataIter *pIter, const char *idStr, bool *hasNext) {
int32_t step = pIter->backward ? -1 : 1; int32_t step = pIter->backward ? -1 : 1;
int32_t code = 0; int32_t code = 0;
int32_t iBlockL = pIter->iSttBlk; int32_t iBlockL = pIter->iSttBlk;
@ -835,7 +835,7 @@ int32_t tLDataIterNextRow(SLDataIter *pIter, const char *idStr, bool* hasNext) {
*hasNext = false; *hasNext = false;
terrno = 0; terrno = 0;
// no qualified last file block in current file, no need to fetch row // no qualified last file block in current file, no need to fetch row
if (pIter->pSttBlk == NULL) { if (pIter->pSttBlk == NULL) {
return code; return code;
@ -1020,7 +1020,7 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoF
// let's record the time window for current table of uid in the stt files // let's record the time window for current table of uid in the stt files
if (pSttDataInfo != NULL && numOfRows > 0) { if (pSttDataInfo != NULL && numOfRows > 0) {
void* px = taosArrayPush(pSttDataInfo->pKeyRangeList, &range); void *px = taosArrayPush(pSttDataInfo->pKeyRangeList, &range);
if (px == NULL) { if (px == NULL) {
return terrno; return terrno;
} }
@ -1041,7 +1041,7 @@ _end:
return code; return code;
} }
void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter) { (void) tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pIter); } void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter) { (void)tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pIter); }
bool tMergeTreeIgnoreEarlierTs(SMergeTree *pMTree) { return pMTree->ignoreEarlierTs; } bool tMergeTreeIgnoreEarlierTs(SMergeTree *pMTree) { return pMTree->ignoreEarlierTs; }
@ -1050,14 +1050,12 @@ static void tLDataIterPinSttBlock(SLDataIter *pIter, const char *id) {
if (pInfo->blockData[0].sttBlockIndex == pIter->iSttBlk) { if (pInfo->blockData[0].sttBlockIndex == pIter->iSttBlk) {
pInfo->blockData[0].pin = true; pInfo->blockData[0].pin = true;
ASSERT(!pInfo->blockData[1].pin);
tsdbTrace("pin stt-block, blockIndex:%d, stt-fileVer:%" PRId64 " %s", pIter->iSttBlk, pIter->cid, id); tsdbTrace("pin stt-block, blockIndex:%d, stt-fileVer:%" PRId64 " %s", pIter->iSttBlk, pIter->cid, id);
return; return;
} }
if (pInfo->blockData[1].sttBlockIndex == pIter->iSttBlk) { if (pInfo->blockData[1].sttBlockIndex == pIter->iSttBlk) {
pInfo->blockData[1].pin = true; pInfo->blockData[1].pin = true;
ASSERT(!pInfo->blockData[0].pin);
tsdbTrace("pin stt-block, blockIndex:%d, stt-fileVer:%" PRId64 " %s", pIter->iSttBlk, pIter->cid, id); tsdbTrace("pin stt-block, blockIndex:%d, stt-fileVer:%" PRId64 " %s", pIter->iSttBlk, pIter->cid, id);
return; return;
} }
@ -1068,14 +1066,12 @@ static void tLDataIterPinSttBlock(SLDataIter *pIter, const char *id) {
static void tLDataIterUnpinSttBlock(SLDataIter *pIter, const char *id) { static void tLDataIterUnpinSttBlock(SLDataIter *pIter, const char *id) {
SSttBlockLoadInfo *pInfo = pIter->pBlockLoadInfo; SSttBlockLoadInfo *pInfo = pIter->pBlockLoadInfo;
if (pInfo->blockData[0].pin) { if (pInfo->blockData[0].pin) {
ASSERT(!pInfo->blockData[1].pin);
pInfo->blockData[0].pin = false; pInfo->blockData[0].pin = false;
tsdbTrace("unpin stt-block:%d, stt-fileVer:%" PRId64 " %s", pInfo->blockData[0].sttBlockIndex, pIter->cid, id); tsdbTrace("unpin stt-block:%d, stt-fileVer:%" PRId64 " %s", pInfo->blockData[0].sttBlockIndex, pIter->cid, id);
return; return;
} }
if (pInfo->blockData[1].pin) { if (pInfo->blockData[1].pin) {
ASSERT(!pInfo->blockData[0].pin);
pInfo->blockData[1].pin = false; pInfo->blockData[1].pin = false;
tsdbTrace("unpin stt-block:%d, stt-fileVer:%" PRId64 " %s", pInfo->blockData[1].sttBlockIndex, pIter->cid, id); tsdbTrace("unpin stt-block:%d, stt-fileVer:%" PRId64 " %s", pInfo->blockData[1].sttBlockIndex, pIter->cid, id);
return; return;
@ -1117,7 +1113,7 @@ int32_t tMergeTreeNext(SMergeTree *pMTree, bool *pHasNext) {
code = tLDataIterNextRow(pIter, pMTree->idStr, &hasVal); code = tLDataIterNextRow(pIter, pMTree->idStr, &hasVal);
if (!hasVal || (code != 0)) { if (!hasVal || (code != 0)) {
if (code == TSDB_CODE_FILE_CORRUPTED) { if (code == TSDB_CODE_FILE_CORRUPTED) {
code = 0; // suppress the file corrupt error to enable all queries within this cluster can run without failed. code = 0; // suppress the file corrupt error to enable all queries within this cluster can run without failed.
} }
pMTree->pIter = NULL; pMTree->pIter = NULL;

View File

@ -129,7 +129,6 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
SMetaReader *pReader = mer1.me.type == TSDB_CHILD_TABLE ? &mer2 : &mer1; SMetaReader *pReader = mer1.me.type == TSDB_CHILD_TABLE ? &mer2 : &mer1;
code = fillTableColCmpr(pReader, metaRsp.pSchemaExt, metaRsp.numOfColumns); code = fillTableColCmpr(pReader, metaRsp.pSchemaExt, metaRsp.numOfColumns);
if (code < 0) { if (code < 0) {
code = TSDB_CODE_INVALID_MSG;
goto _exit; goto _exit;
} }
} else { } else {
@ -545,7 +544,7 @@ int32_t vnodeGetTableList(void *pVnode, int8_t type, SArray *pList) {
} }
int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list) { int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, uid, 1); SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, uid, 1);
if (NULL == pCur) { if (NULL == pCur) {
qError("vnode get all table list failed"); qError("vnode get all table list failed");
@ -575,7 +574,7 @@ int32_t vnodeGetCtbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bo
} }
int32_t vnodeGetCtbIdList(void *pVnode, int64_t suid, SArray *list) { int32_t vnodeGetCtbIdList(void *pVnode, int64_t suid, SArray *list) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SVnode *pVnodeObj = pVnode; SVnode *pVnodeObj = pVnode;
SMCtbCursor *pCur = metaOpenCtbCursor(pVnodeObj, suid, 1); SMCtbCursor *pCur = metaOpenCtbCursor(pVnodeObj, suid, 1);
if (NULL == pCur) { if (NULL == pCur) {
@ -589,7 +588,7 @@ int32_t vnodeGetCtbIdList(void *pVnode, int64_t suid, SArray *list) {
break; break;
} }
if (NULL == taosArrayPush(list, &id)) { if (NULL == taosArrayPush(list, &id)) {
qError("taosArrayPush failed"); qError("taosArrayPush failed");
code = TSDB_CODE_OUT_OF_MEMORY; code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit; goto _exit;
@ -602,7 +601,7 @@ _exit:
} }
int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list) { int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid); SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
if (!pCur) { if (!pCur) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
@ -614,7 +613,7 @@ int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list) {
break; break;
} }
if (NULL == taosArrayPush(list, &id)) { if (NULL == taosArrayPush(list, &id)) {
qError("taosArrayPush failed"); qError("taosArrayPush failed");
code = TSDB_CODE_OUT_OF_MEMORY; code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit; goto _exit;
@ -628,7 +627,7 @@ _exit:
int32_t vnodeGetStbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg, void *arg1), int32_t vnodeGetStbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg, void *arg1),
void *arg) { void *arg) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid); SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
if (!pCur) { if (!pCur) {
return terrno; return terrno;
@ -644,7 +643,7 @@ int32_t vnodeGetStbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bo
continue; continue;
} }
if (NULL == taosArrayPush(list, &id)) { if (NULL == taosArrayPush(list, &id)) {
qError("taosArrayPush failed"); qError("taosArrayPush failed");
code = TSDB_CODE_OUT_OF_MEMORY; code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit; goto _exit;

View File

@ -24,13 +24,13 @@
#include "tgrant.h" #include "tgrant.h"
#define COL_DATA_SET_VAL_AND_CHECK(pCol, rows, buf, isNull) \ #define COL_DATA_SET_VAL_AND_CHECK(pCol, rows, buf, isNull) \
do { \ do { \
int _code = colDataSetVal(pCol, rows, buf, isNull);\ int _code = colDataSetVal(pCol, rows, buf, isNull); \
if (TSDB_CODE_SUCCESS != _code) { \ if (TSDB_CODE_SUCCESS != _code) { \
terrno = _code; \ terrno = _code; \
return _code; \ return _code; \
} \ } \
} while(0) } while (0)
extern SConfig* tsCfg; extern SConfig* tsCfg;
@ -81,7 +81,7 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) {
QRY_OPTR_CHECK(pOutput); QRY_OPTR_CHECK(pOutput);
SSDataBlock* pBlock = NULL; SSDataBlock* pBlock = NULL;
int32_t code = createDataBlock(&pBlock); int32_t code = createDataBlock(&pBlock);
if (code) { if (code) {
return code; return code;
} }
@ -239,7 +239,7 @@ static int32_t buildCreateDBResultDataBlock(SSDataBlock** pOutput) {
QRY_OPTR_CHECK(pOutput); QRY_OPTR_CHECK(pOutput);
SSDataBlock* pBlock = NULL; SSDataBlock* pBlock = NULL;
int32_t code = createDataBlock(&pBlock); int32_t code = createDataBlock(&pBlock);
if (code) { if (code) {
return code; return code;
} }
@ -284,15 +284,15 @@ int64_t getValOfDiffPrecision(int8_t unit, int64_t val) {
return v; return v;
} }
static int32_t buildRetension(SArray* pRetension, char **ppRetentions ) { static int32_t buildRetension(SArray* pRetension, char** ppRetentions) {
size_t size = taosArrayGetSize(pRetension); size_t size = taosArrayGetSize(pRetension);
if (size == 0) { if (size == 0) {
*ppRetentions = NULL; *ppRetentions = NULL;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
char* p1 = taosMemoryCalloc(1, 100); char* p1 = taosMemoryCalloc(1, 100);
if(NULL == p1) { if (NULL == p1) {
return terrno; return terrno;
} }
int32_t len = 0; int32_t len = 0;
@ -372,7 +372,7 @@ static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName,
break; break;
} }
char* pRetentions = NULL; char* pRetentions = NULL;
QRY_ERR_RET(buildRetension(pCfg->pRetensions, &pRetentions)); QRY_ERR_RET(buildRetension(pCfg->pRetensions, &pRetentions));
int32_t dbFNameLen = strlen(dbFName); int32_t dbFNameLen = strlen(dbFName);
int32_t hashPrefix = 0; int32_t hashPrefix = 0;
@ -431,7 +431,7 @@ static int32_t buildCreateTbResultDataBlock(SSDataBlock** pOutput) {
QRY_OPTR_CHECK(pOutput); QRY_OPTR_CHECK(pOutput);
SSDataBlock* pBlock = NULL; SSDataBlock* pBlock = NULL;
int32_t code = createDataBlock(&pBlock); int32_t code = createDataBlock(&pBlock);
if (code) { if (code) {
return code; return code;
} }
@ -455,7 +455,7 @@ static int32_t buildCreateViewResultDataBlock(SSDataBlock** pOutput) {
QRY_OPTR_CHECK(pOutput); QRY_OPTR_CHECK(pOutput);
SSDataBlock* pBlock = NULL; SSDataBlock* pBlock = NULL;
int32_t code = createDataBlock(&pBlock); int32_t code = createDataBlock(&pBlock);
if (code) { if (code) {
return code; return code;
} }
@ -582,36 +582,7 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
} else { } else {
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "NULL"); *len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "NULL");
} }
/*
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
if (pTagVal->nData > 0) {
if (num) {
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, ", ");
}
memcpy(buf + VARSTR_HEADER_SIZE + *len, pTagVal->pData, pTagVal->nData);
*len += pTagVal->nData;
}
} else if (type == TSDB_DATA_TYPE_NCHAR) {
if (pTagVal->nData > 0) {
if (num) {
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, ", ");
}
int32_t tlen = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, buf + VARSTR_HEADER_SIZE + *len);
}
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
double val = *(double *)(&pTagVal->i64);
int len = 0;
term = indexTermCreate(suid, ADD_VALUE, type, key, nKey, (const char *)&val, len);
} else if (type == TSDB_DATA_TYPE_BOOL) {
int val = *(int *)(&pTagVal->i64);
int len = 0;
term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_INT, key, nKey, (const char *)&val, len);
}
*/
} }
_exit: _exit:
taosArrayDestroy(pTagVals); taosArrayDestroy(pTagVals);
@ -871,26 +842,26 @@ static int32_t buildLocalVariablesResultDataBlock(SSDataBlock** pOutput) {
infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN; infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN;
if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) { if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
goto _exit; goto _exit;
} }
infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN; infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN;
if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) { if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
goto _exit; goto _exit;
} }
infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD3_LEN; infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD3_LEN;
if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) { if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
goto _exit; goto _exit;
} }
*pOutput = pBlock; *pOutput = pBlock;
_exit: _exit:
if(terrno != TSDB_CODE_SUCCESS) { if (terrno != TSDB_CODE_SUCCESS) {
taosMemoryFree(pBlock); taosMemoryFree(pBlock);
taosArrayDestroy(pBlock->pDataBlock); taosArrayDestroy(pBlock->pDataBlock);
} }
@ -914,7 +885,7 @@ static int32_t createSelectResultDataBlock(SNodeList* pProjects, SSDataBlock** p
QRY_OPTR_CHECK(pOutput); QRY_OPTR_CHECK(pOutput);
SSDataBlock* pBlock = NULL; SSDataBlock* pBlock = NULL;
int32_t code = createDataBlock(&pBlock); int32_t code = createDataBlock(&pBlock);
if (code) { if (code) {
return code; return code;
} }
@ -949,7 +920,8 @@ int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) {
if (((SValueNode*)pProj)->isNull) { if (((SValueNode*)pProj)->isNull) {
QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true)); QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true));
} else { } else {
QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, nodesGetValueFromNode((SValueNode*)pProj), false)); QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0,
nodesGetValueFromNode((SValueNode*)pProj), false));
} }
} }
} }

View File

@ -126,7 +126,7 @@ uint64_t tableListGetTableGroupId(const STableListInfo* pTableList, uint6
int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t gid); int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t gid);
int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalIndex, STableKeyInfo** pKeyInfo, int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalIndex, STableKeyInfo** pKeyInfo,
int32_t* num); int32_t* num);
uint64_t tableListGetSize(const STableListInfo* pTableList); int32_t tableListGetSize(const STableListInfo* pTableList, int32_t* pRes);
uint64_t tableListGetSuid(const STableListInfo* pTableList); uint64_t tableListGetSuid(const STableListInfo* pTableList);
STableKeyInfo* tableListGetInfo(const STableListInfo* pTableList, int32_t index); STableKeyInfo* tableListGetInfo(const STableListInfo* pTableList, int32_t index);
int32_t tableListFind(const STableListInfo* pTableList, uint64_t uid, int32_t startIndex); int32_t tableListFind(const STableListInfo* pTableList, uint64_t uid, int32_t startIndex);

View File

@ -176,7 +176,10 @@ int32_t createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SReadHandl
code = extractCacheScanSlotId(pInfo->matchInfo.pList, pTaskInfo, &pInfo->pSlotIds, &pInfo->pDstSlotIds); code = extractCacheScanSlotId(pInfo->matchInfo.pList, pTaskInfo, &pInfo->pSlotIds, &pInfo->pDstSlotIds);
QUERY_CHECK_CODE(code, lino, _error); QUERY_CHECK_CODE(code, lino, _error);
int32_t totalTables = tableListGetSize(pTableListInfo); int32_t totalTables = 0;
code = tableListGetSize(pTableListInfo, &totalTables);
QUERY_CHECK_CODE(code, lino, _error);
int32_t capacity = 0; int32_t capacity = 0;
pInfo->pUidList = taosArrayInit(4, sizeof(int64_t)); pInfo->pUidList = taosArrayInit(4, sizeof(int64_t));
@ -271,7 +274,10 @@ int32_t doScanCacheNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
SSDataBlock* pBufRes = pInfo->pBufferedRes; SSDataBlock* pBufRes = pInfo->pBufferedRes;
uint64_t suid = tableListGetSuid(pTableList); uint64_t suid = tableListGetSuid(pTableList);
int32_t size = tableListGetSize(pTableList); int32_t size = 0;
code = tableListGetSize(pTableList, &size);
QUERY_CHECK_CODE(code, lino, _end);
if (size == 0) { if (size == 0) {
setOperatorCompleted(pOperator); setOperatorCompleted(pOperator);
(*ppRes) = NULL; (*ppRes) = NULL;

View File

@ -894,12 +894,12 @@ int32_t doExtractResultBlocks(SExchangeInfo* pExchangeInfo, SSourceDataInfo* pDa
int32_t rawLen = *(int32_t*)pStart; int32_t rawLen = *(int32_t*)pStart;
pStart += sizeof(int32_t); pStart += sizeof(int32_t);
ASSERT(compLen <= rawLen && compLen != 0); QUERY_CHECK_CONDITION((compLen <= rawLen && compLen != 0), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
pNextStart = pStart + compLen; pNextStart = pStart + compLen;
if (pRetrieveRsp->compressed && (compLen < rawLen)) { if (pRetrieveRsp->compressed && (compLen < rawLen)) {
int32_t t = tsDecompressString(pStart, compLen, 1, pDataInfo->decompBuf, rawLen, ONE_STAGE_COMP, NULL, 0); int32_t t = tsDecompressString(pStart, compLen, 1, pDataInfo->decompBuf, rawLen, ONE_STAGE_COMP, NULL, 0);
ASSERT(t == rawLen); QUERY_CHECK_CONDITION((t == rawLen), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
pStart = pDataInfo->decompBuf; pStart = pDataInfo->decompBuf;
} }

View File

@ -197,7 +197,6 @@ void initMultiResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayL
pGroupResInfo->freeItem = true; pGroupResInfo->freeItem = true;
pGroupResInfo->pRows = pArrayList; pGroupResInfo->pRows = pArrayList;
pGroupResInfo->index = 0; pGroupResInfo->index = 0;
ASSERT(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo));
} }
bool hasRemainResults(SGroupResInfo* pGroupResInfo) { bool hasRemainResults(SGroupResInfo* pGroupResInfo) {
@ -1560,7 +1559,12 @@ int32_t getGroupIdFromTagsVal(void* pVnode, uint64_t uid, SNodeList* pGroupNode,
return code; return code;
} }
ASSERT(nodeType(pNew) == QUERY_NODE_VALUE); if (nodeType(pNew) != QUERY_NODE_VALUE) {
nodesDestroyList(groupNew);
pAPI->metaReaderFn.clearReader(&mr);
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR));
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
}
SValueNode* pValue = (SValueNode*)pNew; SValueNode* pValue = (SValueNode*)pNew;
if (pValue->node.resType.type == TSDB_DATA_TYPE_NULL || pValue->isNull) { if (pValue->node.resType.type == TSDB_DATA_TYPE_NULL || pValue->isNull) {
@ -1879,7 +1883,8 @@ int32_t createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId) {
pExp->base.resSchema = createResSchema(pType->type, pType->bytes, slotId, pType->scale, pType->precision, pCond->node.aliasName); pExp->base.resSchema = createResSchema(pType->type, pType->bytes, slotId, pType->scale, pType->precision, pCond->node.aliasName);
pExp->pExpr->_optrRoot.pRootNode = pNode; pExp->pExpr->_optrRoot.pRootNode = pNode;
} else { } else {
ASSERT(0); code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
QUERY_CHECK_CODE(code, lino, _end);
} }
_end: _end:
@ -2149,7 +2154,8 @@ int32_t relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SAr
} else if (p->info.colId < pmInfo->colId) { } else if (p->info.colId < pmInfo->colId) {
i++; i++;
} else { } else {
ASSERT(0); qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR));
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
} }
} }
return code; return code;
@ -2383,9 +2389,13 @@ void resetLimitInfoForNextGroup(SLimitInfo* pLimitInfo) {
pLimitInfo->remainOffset = pLimitInfo->limit.offset; pLimitInfo->remainOffset = pLimitInfo->limit.offset;
} }
uint64_t tableListGetSize(const STableListInfo* pTableList) { int32_t tableListGetSize(const STableListInfo* pTableList, int32_t* pRes) {
ASSERT(taosArrayGetSize(pTableList->pTableList) == taosHashGetSize(pTableList->map)); if (taosArrayGetSize(pTableList->pTableList) != taosHashGetSize(pTableList->map)) {
return taosArrayGetSize(pTableList->pTableList); qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR));
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
}
(*pRes) = taosArrayGetSize(pTableList->pTableList);
return TSDB_CODE_SUCCESS;
} }
uint64_t tableListGetSuid(const STableListInfo* pTableList) { return pTableList->idInfo.suid; } uint64_t tableListGetSuid(const STableListInfo* pTableList) { return pTableList->idInfo.suid; }
@ -2430,7 +2440,6 @@ uint64_t tableListGetTableGroupId(const STableListInfo* pTableList, uint64_t tab
} }
STableKeyInfo* pKeyInfo = taosArrayGet(pTableList->pTableList, *slot); STableKeyInfo* pKeyInfo = taosArrayGet(pTableList->pTableList, *slot);
ASSERT(pKeyInfo->uid == tableUid);
return pKeyInfo->groupId; return pKeyInfo->groupId;
} }
@ -2457,7 +2466,8 @@ int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t
int32_t slot = (int32_t)taosArrayGetSize(pTableList->pTableList) - 1; int32_t slot = (int32_t)taosArrayGetSize(pTableList->pTableList) - 1;
code = taosHashPut(pTableList->map, &uid, sizeof(uid), &slot, sizeof(slot)); code = taosHashPut(pTableList->map, &uid, sizeof(uid), &slot, sizeof(slot));
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
ASSERT(code != TSDB_CODE_DUP_KEY); // we have checked the existence of uid in hash map above // we have checked the existence of uid in hash map above
QUERY_CHECK_CONDITION((code != TSDB_CODE_DUP_KEY), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
taosArrayPopTailBatch(pTableList->pTableList, 1); // let's pop the last element in the array list taosArrayPopTailBatch(pTableList->pTableList, 1); // let's pop the last element in the array list
} }
@ -2474,7 +2484,12 @@ _end:
int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalGroupIndex, STableKeyInfo** pKeyInfo, int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalGroupIndex, STableKeyInfo** pKeyInfo,
int32_t* size) { int32_t* size) {
int32_t totalGroups = tableListGetOutputGroups(pTableList); int32_t totalGroups = tableListGetOutputGroups(pTableList);
int32_t numOfTables = tableListGetSize(pTableList); int32_t numOfTables = 0;
int32_t code = tableListGetSize(pTableList, &numOfTables);
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
return code;
}
if (ordinalGroupIndex < 0 || ordinalGroupIndex >= totalGroups) { if (ordinalGroupIndex < 0 || ordinalGroupIndex >= totalGroups) {
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;

View File

@ -1295,7 +1295,13 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
// this value may be changed if new tables are created // this value may be changed if new tables are created
taosRLockLatch(&pTaskInfo->lock); taosRLockLatch(&pTaskInfo->lock);
int32_t numOfTables = tableListGetSize(pTableListInfo); int32_t numOfTables = 0;
code = tableListGetSize(pTableListInfo, &numOfTables);
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
taosRUnLockLatch(&pTaskInfo->lock);
return code;
}
if (uid == 0) { if (uid == 0) {
if (numOfTables != 0) { if (numOfTables != 0) {
@ -1439,7 +1445,13 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
tDeleteSchemaWrapper(mtInfo.schema); tDeleteSchemaWrapper(mtInfo.schema);
return code; return code;
} }
int32_t size = tableListGetSize(pTableListInfo); int32_t size = 0;
code = tableListGetSize(pTableListInfo, &size);
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
tDeleteSchemaWrapper(mtInfo.schema);
return code;
}
code = pTaskInfo->storageAPI.tsdReader.tsdReaderOpen(pInfo->vnode, &pTaskInfo->streamInfo.tableCond, pList, size, code = pTaskInfo->storageAPI.tsdReader.tsdReaderOpen(pInfo->vnode, &pTaskInfo->streamInfo.tableCond, pList, size,
NULL, (void**)&pInfo->dataReader, NULL, NULL); NULL, (void**)&pInfo->dataReader, NULL, NULL);
@ -1520,7 +1532,10 @@ SArray* qGetQueriedTableListInfo(qTaskInfo_t tinfo) {
SArray* pUidList = taosArrayInit(10, sizeof(uint64_t)); SArray* pUidList = taosArrayInit(10, sizeof(uint64_t));
QUERY_CHECK_NULL(pUidList, code, lino, _end, terrno); QUERY_CHECK_NULL(pUidList, code, lino, _end, terrno);
int32_t numOfTables = tableListGetSize(pTableListInfo); int32_t numOfTables = 0;
code = tableListGetSize(pTableListInfo, &numOfTables);
QUERY_CHECK_CODE(code, lino, _end);
for (int32_t i = 0; i < numOfTables; ++i) { for (int32_t i = 0; i < numOfTables; ++i) {
STableKeyInfo* pKeyInfo = tableListGetInfo(pTableListInfo, i); STableKeyInfo* pKeyInfo = tableListGetInfo(pTableListInfo, i);
QUERY_CHECK_NULL(pKeyInfo, code, lino, _end, terrno); QUERY_CHECK_NULL(pKeyInfo, code, lino, _end, terrno);

View File

@ -1115,7 +1115,14 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo*
pDeleterParam->suid = tableListGetSuid(pTableListInfo); pDeleterParam->suid = tableListGetSuid(pTableListInfo);
// TODO extract uid list // TODO extract uid list
int32_t numOfTables = tableListGetSize(pTableListInfo); int32_t numOfTables = 0;
code = tableListGetSize(pTableListInfo, &numOfTables);
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
taosMemoryFree(pDeleterParam);
return code;
}
pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t)); pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t));
if (NULL == pDeleterParam->pUidList) { if (NULL == pDeleterParam->pUidList) {
taosMemoryFree(pDeleterParam); taosMemoryFree(pDeleterParam);

View File

@ -415,7 +415,8 @@ static int32_t createPrimaryTsExprIfNeeded(SFillOperatorInfo* pInfo, SFillPhysiN
int32_t code = createExprFromTargetNode(&pExpr[pExprSupp->numOfExprs], (STargetNode*)pPhyFillNode->pWStartTs); int32_t code = createExprFromTargetNode(&pExpr[pExprSupp->numOfExprs], (STargetNode*)pPhyFillNode->pWStartTs);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
taosMemoryFreeClear(pExpr); pExprSupp->numOfExprs += 1;
pExprSupp->pExprInfo = pExpr;
return code; return code;
} }
@ -447,6 +448,7 @@ int32_t createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pPhyFi
QUERY_CHECK_CODE(code, lino, _error); QUERY_CHECK_CODE(code, lino, _error);
pOperator->exprSupp.pExprInfo = pExprInfo; pOperator->exprSupp.pExprInfo = pExprInfo;
pOperator->exprSupp.numOfExprs = pInfo->numOfExpr;
SExprSupp* pNoFillSupp = &pInfo->noFillExprSupp; SExprSupp* pNoFillSupp = &pInfo->noFillExprSupp;
code = createExprInfo(pPhyFillNode->pNotFillExprs, NULL, &pNoFillSupp->pExprInfo, &pNoFillSupp->numOfExprs); code = createExprInfo(pPhyFillNode->pNotFillExprs, NULL, &pNoFillSupp->pExprInfo, &pNoFillSupp->numOfExprs);
@ -511,7 +513,6 @@ int32_t createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pPhyFi
} }
setOperatorInfo(pOperator, "FillOperator", QUERY_NODE_PHYSICAL_PLAN_FILL, false, OP_NOT_OPENED, pInfo, pTaskInfo); setOperatorInfo(pOperator, "FillOperator", QUERY_NODE_PHYSICAL_PLAN_FILL, false, OP_NOT_OPENED, pInfo, pTaskInfo);
pOperator->exprSupp.numOfExprs = pInfo->numOfExpr;
pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, doFill, NULL, destroyFillOperatorInfo, optrDefaultBufFn, NULL, pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, doFill, NULL, destroyFillOperatorInfo, optrDefaultBufFn, NULL,
optrDefaultGetNextExtFn, NULL); optrDefaultGetNextExtFn, NULL);

View File

@ -213,7 +213,6 @@ static void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSData
memcpy(pkey->pData, val, dataLen); memcpy(pkey->pData, val, dataLen);
} else if (IS_VAR_DATA_TYPE(pkey->type)) { } else if (IS_VAR_DATA_TYPE(pkey->type)) {
memcpy(pkey->pData, val, varDataTLen(val)); memcpy(pkey->pData, val, varDataTLen(val));
ASSERT(varDataTLen(val) <= pkey->bytes);
} else { } else {
memcpy(pkey->pData, val, pkey->bytes); memcpy(pkey->pData, val, pkey->bytes);
} }
@ -241,7 +240,6 @@ static int32_t buildGroupKeys(void* pKey, const SArray* pGroupColVals) {
} else if (IS_VAR_DATA_TYPE(pkey->type)) { } else if (IS_VAR_DATA_TYPE(pkey->type)) {
varDataCopy(pStart, pkey->pData); varDataCopy(pStart, pkey->pData);
pStart += varDataTLen(pkey->pData); pStart += varDataTLen(pkey->pData);
ASSERT(varDataTLen(pkey->pData) <= pkey->bytes);
} else { } else {
memcpy(pStart, pkey->pData, pkey->bytes); memcpy(pStart, pkey->pData, pkey->bytes);
pStart += pkey->bytes; pStart += pkey->bytes;
@ -740,7 +738,7 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
memcpy(data + (*columnLen), src, dataLen); memcpy(data + (*columnLen), src, dataLen);
int32_t v = (data + (*columnLen) + dataLen - (char*)pPage); int32_t v = (data + (*columnLen) + dataLen - (char*)pPage);
ASSERT(v > 0); QUERY_CHECK_CONDITION((v > 0), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
contentLen = dataLen; contentLen = dataLen;
} else { } else {
@ -748,7 +746,7 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
char* src = colDataGetData(pColInfoData, j); char* src = colDataGetData(pColInfoData, j);
memcpy(data + (*columnLen), src, varDataTLen(src)); memcpy(data + (*columnLen), src, varDataTLen(src));
int32_t v = (data + (*columnLen) + varDataTLen(src) - (char*)pPage); int32_t v = (data + (*columnLen) + varDataTLen(src) - (char*)pPage);
ASSERT(v > 0); QUERY_CHECK_CONDITION((v > 0), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
contentLen = varDataTLen(src); contentLen = varDataTLen(src);
} }
@ -762,7 +760,8 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
colDataSetNull_f(bitmap, (*rows)); colDataSetNull_f(bitmap, (*rows));
} else { } else {
memcpy(data + (*columnLen), colDataGetData(pColInfoData, j), bytes); memcpy(data + (*columnLen), colDataGetData(pColInfoData, j), bytes);
ASSERT((data + (*columnLen) + bytes - (char*)pPage) <= getBufPageSize(pInfo->pBuf)); QUERY_CHECK_CONDITION(((data + (*columnLen) + bytes - (char*)pPage) <= getBufPageSize(pInfo->pBuf)), code,
lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
} }
contentLen = bytes; contentLen = bytes;
} }
@ -1299,7 +1298,7 @@ static SSDataBlock* buildStreamPartitionResult(SOperatorInfo* pOperator) {
SStreamPartitionOperatorInfo* pInfo = pOperator->info; SStreamPartitionOperatorInfo* pInfo = pOperator->info;
SSDataBlock* pDest = pInfo->binfo.pRes; SSDataBlock* pDest = pInfo->binfo.pRes;
ASSERT(hasRemainPartion(pInfo)); QUERY_CHECK_CONDITION((hasRemainPartion(pInfo)), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
SPartitionDataInfo* pParInfo = (SPartitionDataInfo*)pInfo->parIte; SPartitionDataInfo* pParInfo = (SPartitionDataInfo*)pInfo->parIte;
blockDataCleanup(pDest); blockDataCleanup(pDest);
int32_t rows = taosArrayGetSize(pParInfo->rowIds); int32_t rows = taosArrayGetSize(pParInfo->rowIds);
@ -1343,7 +1342,7 @@ static SSDataBlock* buildStreamPartitionResult(SOperatorInfo* pOperator) {
pDest->info.id.groupId = pParInfo->groupId; pDest->info.id.groupId = pParInfo->groupId;
pOperator->resultInfo.totalRows += pDest->info.rows; pOperator->resultInfo.totalRows += pDest->info.rows;
pInfo->parIte = taosHashIterate(pInfo->pPartitions, pInfo->parIte); pInfo->parIte = taosHashIterate(pInfo->pPartitions, pInfo->parIte);
ASSERT(pDest->info.rows > 0); QUERY_CHECK_CONDITION((pDest->info.rows > 0), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
_end: _end:
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
@ -1549,7 +1548,8 @@ static int32_t doStreamHashPartitionNext(SOperatorInfo* pOperator, SSDataBlock**
return code; return code;
} }
default: default:
ASSERTS(0, "invalid SSDataBlock type"); code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
QUERY_CHECK_CODE(code, lino, _end);
} }
// there is an scalar expression that needs to be calculated right before apply the group aggregation. // there is an scalar expression that needs to be calculated right before apply the group aggregation.

View File

@ -1083,7 +1083,10 @@ static SSDataBlock* doGroupedTableScan(SOperatorInfo* pOperator) {
return getBlockForEmptyTable(pOperator, pStart); return getBlockForEmptyTable(pOperator, pStart);
} }
} else { // group by tag + no sort } else { // group by tag + no sort
int32_t numOfTables = tableListGetSize(pTableListInfo); int32_t numOfTables = 0;
code = tableListGetSize(pTableListInfo, &numOfTables);
QUERY_CHECK_CODE(code, lino, _end);
if (pTableScanInfo->tableEndIndex + 1 >= numOfTables) { if (pTableScanInfo->tableEndIndex + 1 >= numOfTables) {
// get empty group, mark processed & rm from hash // get empty group, mark processed & rm from hash
void* pIte = taosHashIterate(pTableListInfo->remainGroups, NULL); void* pIte = taosHashIterate(pTableListInfo->remainGroups, NULL);
@ -1172,7 +1175,10 @@ static SSDataBlock* startNextGroupScan(SOperatorInfo* pOperator) {
STableScanInfo* pInfo = pOperator->info; STableScanInfo* pInfo = pOperator->info;
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
SStorageAPI* pAPI = &pTaskInfo->storageAPI; SStorageAPI* pAPI = &pTaskInfo->storageAPI;
int32_t numOfTables = tableListGetSize(pInfo->base.pTableListInfo); int32_t numOfTables = 0;
code = tableListGetSize(pInfo->base.pTableListInfo, &numOfTables);
QUERY_CHECK_CODE(code, lino, _end);
if ((++pInfo->currentGroupId) >= tableListGetOutputGroups(pInfo->base.pTableListInfo)) { if ((++pInfo->currentGroupId) >= tableListGetOutputGroups(pInfo->base.pTableListInfo)) {
setOperatorCompleted(pOperator); setOperatorCompleted(pOperator);
if (pOperator->dynamicTask) { if (pOperator->dynamicTask) {
@ -1305,7 +1311,7 @@ static int32_t doTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
// scan table one by one sequentially // scan table one by one sequentially
if (pInfo->scanMode == TABLE_SCAN__TABLE_ORDER) { if (pInfo->scanMode == TABLE_SCAN__TABLE_ORDER) {
int32_t numOfTables = 0; // tableListGetSize(pTaskInfo->pTableListInfo); int32_t numOfTables = 0;
STableKeyInfo tInfo = {0}; STableKeyInfo tInfo = {0};
pInfo->countState = TABLE_COUNT_STATE_END; pInfo->countState = TABLE_COUNT_STATE_END;
@ -1320,7 +1326,13 @@ static int32_t doTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
pInfo->currentTable++; pInfo->currentTable++;
taosRLockLatch(&pTaskInfo->lock); taosRLockLatch(&pTaskInfo->lock);
numOfTables = tableListGetSize(pInfo->base.pTableListInfo); numOfTables = 0;
code = tableListGetSize(pInfo->base.pTableListInfo, &numOfTables);
if (code != TSDB_CODE_SUCCESS) {
taosRUnLockLatch(&pTaskInfo->lock);
lino = __LINE__;
goto _end;
}
if (pInfo->currentTable >= numOfTables) { if (pInfo->currentTable >= numOfTables) {
qDebug("all table checked in table list, total:%d, return NULL, %s", numOfTables, GET_TASKID(pTaskInfo)); qDebug("all table checked in table list, total:%d, return NULL, %s", numOfTables, GET_TASKID(pTaskInfo));
@ -3613,7 +3625,9 @@ static int32_t extractTableIdList(const STableListInfo* pTableListInfo, SArray**
QUERY_CHECK_NULL(tableIdList, code, lino, _end, terrno); QUERY_CHECK_NULL(tableIdList, code, lino, _end, terrno);
// Transfer the Array of STableKeyInfo into uid list. // Transfer the Array of STableKeyInfo into uid list.
size_t size = tableListGetSize(pTableListInfo); int32_t size = 0;
code = tableListGetSize(pTableListInfo, &size);
QUERY_CHECK_CODE(code, lino, _end);
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
STableKeyInfo* pkeyInfo = tableListGetInfo(pTableListInfo, i); STableKeyInfo* pkeyInfo = tableListGetInfo(pTableListInfo, i);
QUERY_CHECK_NULL(pkeyInfo, code, lino, _end, terrno); QUERY_CHECK_NULL(pkeyInfo, code, lino, _end, terrno);
@ -4629,7 +4643,13 @@ static int32_t doTagScanFromMetaEntryNext(SOperatorInfo* pOperator, SSDataBlock*
SSDataBlock* pRes = pInfo->pRes; SSDataBlock* pRes = pInfo->pRes;
blockDataCleanup(pRes); blockDataCleanup(pRes);
int32_t size = tableListGetSize(pInfo->pTableListInfo); int32_t size = 0;
code = tableListGetSize(pInfo->pTableListInfo, &size);
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
return code;
}
if (size == 0) { if (size == 0) {
setTaskStatus(pTaskInfo, TASK_COMPLETED); setTaskStatus(pTaskInfo, TASK_COMPLETED);
(*ppRes) = NULL; (*ppRes) = NULL;
@ -4927,7 +4947,13 @@ static int32_t fetchNextSubTableBlockFromReader(SOperatorInfo* pOperator, STmsSu
static int32_t setGroupStartEndIndex(STableMergeScanInfo* pInfo) { static int32_t setGroupStartEndIndex(STableMergeScanInfo* pInfo) {
pInfo->bGroupProcessed = false; pInfo->bGroupProcessed = false;
size_t numOfTables = tableListGetSize(pInfo->base.pTableListInfo); int32_t numOfTables = 0;
int32_t code = tableListGetSize(pInfo->base.pTableListInfo, &numOfTables);
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
return code;
}
int32_t i = pInfo->tableStartIndex + 1; int32_t i = pInfo->tableStartIndex + 1;
for (; i < numOfTables; ++i) { for (; i < numOfTables; ++i) {
STableKeyInfo* tableKeyInfo = tableListGetInfo(pInfo->base.pTableListInfo, i); STableKeyInfo* tableKeyInfo = tableListGetInfo(pInfo->base.pTableListInfo, i);
@ -5266,7 +5292,10 @@ int32_t doTableMergeScanParaSubTablesNext(SOperatorInfo* pOperator, SSDataBlock*
int64_t st = taosGetTimestampUs(); int64_t st = taosGetTimestampUs();
size_t tableListSize = tableListGetSize(pInfo->base.pTableListInfo); int32_t tableListSize = 0;
code = tableListGetSize(pInfo->base.pTableListInfo, &tableListSize);
QUERY_CHECK_CODE(code, lino, _end);
if (!pInfo->hasGroupId) { if (!pInfo->hasGroupId) {
pInfo->hasGroupId = true; pInfo->hasGroupId = true;
@ -5643,7 +5672,10 @@ void startGroupTableMergeScan(SOperatorInfo* pOperator) {
qDebug("%s table merge scan start group %" PRIu64, GET_TASKID(pTaskInfo), pInfo->groupId); qDebug("%s table merge scan start group %" PRIu64, GET_TASKID(pTaskInfo), pInfo->groupId);
{ {
size_t numOfTables = tableListGetSize(pInfo->base.pTableListInfo); int32_t numOfTables = 0;
code = tableListGetSize(pInfo->base.pTableListInfo, &numOfTables);
QUERY_CHECK_CODE(code, lino, _end);
int32_t i = pInfo->tableStartIndex + 1; int32_t i = pInfo->tableStartIndex + 1;
for (; i < numOfTables; ++i) { for (; i < numOfTables; ++i) {
STableKeyInfo* tableKeyInfo = tableListGetInfo(pInfo->base.pTableListInfo, i); STableKeyInfo* tableKeyInfo = tableListGetInfo(pInfo->base.pTableListInfo, i);
@ -5763,7 +5795,10 @@ int32_t doTableMergeScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
int64_t st = taosGetTimestampUs(); int64_t st = taosGetTimestampUs();
size_t tableListSize = tableListGetSize(pInfo->base.pTableListInfo); int32_t tableListSize = 0;
code = tableListGetSize(pInfo->base.pTableListInfo, &tableListSize);
QUERY_CHECK_CODE(code, lino, _end);
if (!pInfo->hasGroupId) { if (!pInfo->hasGroupId) {
pInfo->hasGroupId = true; pInfo->hasGroupId = true;

View File

@ -2843,7 +2843,10 @@ int32_t createDataBlockInfoScanOperator(SReadHandle* readHandle, SBlockDistScanP
QUERY_CHECK_CODE(code, lino, _error); QUERY_CHECK_CODE(code, lino, _error);
pInfo->pTableListInfo = pTableListInfo; pInfo->pTableListInfo = pTableListInfo;
size_t num = tableListGetSize(pTableListInfo); int32_t num = 0;
code = tableListGetSize(pTableListInfo, &num);
QUERY_CHECK_CODE(code, lino, _error);
void* pList = tableListGetInfo(pTableListInfo, 0); void* pList = tableListGetInfo(pTableListInfo, 0);
code = readHandle->api.tsdReader.tsdReaderOpen(readHandle->vnode, &cond, pList, num, pInfo->pResBlock, code = readHandle->api.tsdReader.tsdReaderOpen(readHandle->vnode, &cond, pList, num, pInfo->pResBlock,

View File

@ -324,8 +324,11 @@ _end:
static void saveColData(SArray* rowBuf, int32_t columnIndex, const char* src, bool isNull); static void saveColData(SArray* rowBuf, int32_t columnIndex, const char* src, bool isNull);
static void copyCurrentRowIntoBuf(SFillInfo* pFillInfo, int32_t rowIndex, SRowVal* pRowVal, bool reset) { static int32_t copyCurrentRowIntoBuf(SFillInfo* pFillInfo, int32_t rowIndex, SRowVal* pRowVal, bool reset) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0;
SColumnInfoData* pTsCol = taosArrayGet(pFillInfo->pSrcBlock->pDataBlock, pFillInfo->srcTsSlotId); SColumnInfoData* pTsCol = taosArrayGet(pFillInfo->pSrcBlock->pDataBlock, pFillInfo->srcTsSlotId);
QUERY_CHECK_NULL(pTsCol, code, lino, _end, terrno);
pRowVal->key = ((int64_t*)pTsCol->pData)[rowIndex]; pRowVal->key = ((int64_t*)pTsCol->pData)[rowIndex];
for (int32_t i = 0; i < pFillInfo->numOfCols; ++i) { for (int32_t i = 0; i < pFillInfo->numOfCols; ++i) {
@ -342,15 +345,24 @@ static void copyCurrentRowIntoBuf(SFillInfo* pFillInfo, int32_t rowIndex, SRowVa
} }
SColumnInfoData* pSrcCol = taosArrayGet(pFillInfo->pSrcBlock->pDataBlock, srcSlotId); SColumnInfoData* pSrcCol = taosArrayGet(pFillInfo->pSrcBlock->pDataBlock, srcSlotId);
QUERY_CHECK_NULL(pSrcCol, code, lino, _end, terrno);
bool isNull = colDataIsNull_s(pSrcCol, rowIndex); bool isNull = colDataIsNull_s(pSrcCol, rowIndex);
char* p = colDataGetData(pSrcCol, rowIndex); char* p = colDataGetData(pSrcCol, rowIndex);
saveColData(pRowVal->pRowVal, i, p, reset ? true : isNull); saveColData(pRowVal->pRowVal, i, p, reset ? true : isNull);
} else { } else {
ASSERT(0); code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
QUERY_CHECK_CODE(code, lino, _end);
} }
} }
_end:
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
}
return code;
} }
static int32_t fillResultImpl(SFillInfo* pFillInfo, SSDataBlock* pBlock, int32_t outputRows) { static int32_t fillResultImpl(SFillInfo* pFillInfo, SSDataBlock* pBlock, int32_t outputRows) {
@ -362,20 +374,18 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, SSDataBlock* pBlock, int32_t
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pFillInfo->order); int32_t step = GET_FORWARD_DIRECTION_FACTOR(pFillInfo->order);
bool ascFill = FILL_IS_ASC_FILL(pFillInfo); bool ascFill = FILL_IS_ASC_FILL(pFillInfo);
#if 0
ASSERT(ascFill && (pFillInfo->currentKey >= pFillInfo->start) || (!ascFill && (pFillInfo->currentKey <= pFillInfo->start)));
#endif
while (pFillInfo->numOfCurrent < outputRows) { while (pFillInfo->numOfCurrent < outputRows) {
int64_t ts = ((int64_t*)pTsCol->pData)[pFillInfo->index]; int64_t ts = ((int64_t*)pTsCol->pData)[pFillInfo->index];
// set the next value for interpolation // set the next value for interpolation
if (pFillInfo->currentKey < ts && ascFill) { if (pFillInfo->currentKey < ts && ascFill) {
SRowVal* pRVal = pFillInfo->type == TSDB_FILL_NEXT ? &pFillInfo->next : &pFillInfo->prev; SRowVal* pRVal = pFillInfo->type == TSDB_FILL_NEXT ? &pFillInfo->next : &pFillInfo->prev;
copyCurrentRowIntoBuf(pFillInfo, pFillInfo->index, pRVal, false); code = copyCurrentRowIntoBuf(pFillInfo, pFillInfo->index, pRVal, false);
QUERY_CHECK_CODE(code, lino, _end);
} else if (pFillInfo->currentKey > ts && !ascFill) { } else if (pFillInfo->currentKey > ts && !ascFill) {
SRowVal* pRVal = pFillInfo->type == TSDB_FILL_NEXT ? &pFillInfo->prev : &pFillInfo->next; SRowVal* pRVal = pFillInfo->type == TSDB_FILL_NEXT ? &pFillInfo->prev : &pFillInfo->next;
copyCurrentRowIntoBuf(pFillInfo, pFillInfo->index, pRVal, false); code = copyCurrentRowIntoBuf(pFillInfo, pFillInfo->index, pRVal, false);
QUERY_CHECK_CODE(code, lino, _end);
} }
if (((pFillInfo->currentKey < ts && ascFill) || (pFillInfo->currentKey > ts && !ascFill)) && if (((pFillInfo->currentKey < ts && ascFill) || (pFillInfo->currentKey > ts && !ascFill)) &&
@ -392,21 +402,24 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, SSDataBlock* pBlock, int32_t
goto _end; goto _end;
} }
} else { } else {
ASSERT(pFillInfo->currentKey == ts); QUERY_CHECK_CONDITION((pFillInfo->currentKey == ts), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
int32_t index = pBlock->info.rows; int32_t index = pBlock->info.rows;
int32_t nextRowIndex = pFillInfo->index + 1; int32_t nextRowIndex = pFillInfo->index + 1;
if (pFillInfo->type == TSDB_FILL_NEXT) { if (pFillInfo->type == TSDB_FILL_NEXT) {
if ((pFillInfo->index + 1) < pFillInfo->numOfRows) { if ((pFillInfo->index + 1) < pFillInfo->numOfRows) {
copyCurrentRowIntoBuf(pFillInfo, nextRowIndex, &pFillInfo->next, false); code = copyCurrentRowIntoBuf(pFillInfo, nextRowIndex, &pFillInfo->next, false);
QUERY_CHECK_CODE(code, lino, _end);
} else { } else {
// reset to null after last row // reset to null after last row
copyCurrentRowIntoBuf(pFillInfo, nextRowIndex, &pFillInfo->next, true); code = copyCurrentRowIntoBuf(pFillInfo, nextRowIndex, &pFillInfo->next, true);
QUERY_CHECK_CODE(code, lino, _end);
} }
} }
if (pFillInfo->type == TSDB_FILL_PREV) { if (pFillInfo->type == TSDB_FILL_PREV) {
if (nextRowIndex + 1 >= pFillInfo->numOfRows && !FILL_IS_ASC_FILL(pFillInfo)) { if (nextRowIndex + 1 >= pFillInfo->numOfRows && !FILL_IS_ASC_FILL(pFillInfo)) {
copyCurrentRowIntoBuf(pFillInfo, nextRowIndex, &pFillInfo->next, true); code = copyCurrentRowIntoBuf(pFillInfo, nextRowIndex, &pFillInfo->next, true);
QUERY_CHECK_CODE(code, lino, _end);
} }
} }
@ -500,7 +513,9 @@ static void saveColData(SArray* rowBuf, int32_t columnIndex, const char* src, bo
} }
} }
static void appendFilledResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, int64_t resultCapacity) { static int32_t appendFilledResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, int64_t resultCapacity) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0;
/* /*
* These data are generated according to fill strategy, since the current timestamp is out of the time window of * These data are generated according to fill strategy, since the current timestamp is out of the time window of
* real result set. Note that we need to keep the direct previous result rows, to generated the filled data. * real result set. Note that we need to keep the direct previous result rows, to generated the filled data.
@ -512,7 +527,14 @@ static void appendFilledResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, int64_
pFillInfo->numOfTotal += pFillInfo->numOfCurrent; pFillInfo->numOfTotal += pFillInfo->numOfCurrent;
ASSERT(pFillInfo->numOfCurrent == resultCapacity); QUERY_CHECK_CONDITION((pFillInfo->numOfCurrent == resultCapacity), code, lino, _end,
TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
_end:
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
}
return code;
} }
static int32_t taosNumOfRemainRows(SFillInfo* pFillInfo) { static int32_t taosNumOfRemainRows(SFillInfo* pFillInfo) {
@ -635,15 +657,6 @@ void taosFillSetStartInfo(SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey)
// the endKey is now the aligned time window value. truncate time window isn't correct. // the endKey is now the aligned time window value. truncate time window isn't correct.
pFillInfo->end = endKey; pFillInfo->end = endKey;
#if 0
if (pFillInfo->order == TSDB_ORDER_ASC) {
ASSERT(pFillInfo->start <= pFillInfo->end);
} else {
ASSERT(pFillInfo->start >= pFillInfo->end);
}
#endif
pFillInfo->index = 0; pFillInfo->index = 0;
pFillInfo->numOfRows = numOfRows; pFillInfo->numOfRows = numOfRows;
} }
@ -687,7 +700,6 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, TSKEY ekey, int32_t ma
numOfRes = numOfRes =
taosTimeCountIntervalForFill(lastKey, pFillInfo->currentKey, pFillInfo->interval.sliding, taosTimeCountIntervalForFill(lastKey, pFillInfo->currentKey, pFillInfo->interval.sliding,
pFillInfo->interval.slidingUnit, pFillInfo->interval.precision, pFillInfo->order); pFillInfo->interval.slidingUnit, pFillInfo->interval.precision, pFillInfo->order);
ASSERT(numOfRes >= numOfRows);
} else { // reach the end of data } else { // reach the end of data
if ((ekey1 < pFillInfo->currentKey && FILL_IS_ASC_FILL(pFillInfo)) || if ((ekey1 < pFillInfo->currentKey && FILL_IS_ASC_FILL(pFillInfo)) ||
(ekey1 > pFillInfo->currentKey && !FILL_IS_ASC_FILL(pFillInfo))) { (ekey1 > pFillInfo->currentKey && !FILL_IS_ASC_FILL(pFillInfo))) {
@ -719,23 +731,30 @@ void taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* po
int32_t taosFillResultDataBlock(SFillInfo* pFillInfo, SSDataBlock* p, int32_t capacity) { int32_t taosFillResultDataBlock(SFillInfo* pFillInfo, SSDataBlock* p, int32_t capacity) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0;
int32_t remain = taosNumOfRemainRows(pFillInfo); int32_t remain = taosNumOfRemainRows(pFillInfo);
int64_t numOfRes = getNumOfResultsAfterFillGap(pFillInfo, pFillInfo->end, capacity); int64_t numOfRes = getNumOfResultsAfterFillGap(pFillInfo, pFillInfo->end, capacity);
ASSERT(numOfRes <= capacity); QUERY_CHECK_CONDITION((numOfRes <= capacity), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
// no data existed for fill operation now, append result according to the fill strategy // no data existed for fill operation now, append result according to the fill strategy
if (remain == 0) { if (remain == 0) {
appendFilledResult(pFillInfo, p, numOfRes); code = appendFilledResult(pFillInfo, p, numOfRes);
QUERY_CHECK_CODE(code, lino, _end);
} else { } else {
code = fillResultImpl(pFillInfo, p, (int32_t)numOfRes); code = fillResultImpl(pFillInfo, p, (int32_t)numOfRes);
ASSERT(numOfRes == pFillInfo->numOfCurrent); QUERY_CHECK_CODE(code, lino, _end);
QUERY_CHECK_CONDITION((numOfRes == pFillInfo->numOfCurrent), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
} }
qDebug("fill:%p, generated fill result, src block:%d, index:%d, brange:%" PRId64 "-%" PRId64 ", currentKey:%" PRId64 qDebug("fill:%p, generated fill result, src block:%d, index:%d, brange:%" PRId64 "-%" PRId64 ", currentKey:%" PRId64
", current : % d, total : % d, %s", ", current : % d, total : % d, %s",
pFillInfo, pFillInfo->numOfRows, pFillInfo->index, pFillInfo->start, pFillInfo->end, pFillInfo->currentKey, pFillInfo, pFillInfo->numOfRows, pFillInfo->index, pFillInfo->start, pFillInfo->end, pFillInfo->currentKey,
pFillInfo->numOfCurrent, pFillInfo->numOfTotal, pFillInfo->id); pFillInfo->numOfCurrent, pFillInfo->numOfTotal, pFillInfo->id);
_end:
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
}
return code; return code;
} }

View File

@ -331,18 +331,26 @@ int32_t doGeosRelation(const GEOSGeometry *geom1, const GEOSPreparedGeometry *pr
if (!preparedGeom1) { if (!preparedGeom1) {
if (!swapped) { if (!swapped) {
ASSERT(relationFn); if (!relationFn) {
return TSDB_CODE_FUNC_FUNTION_PARA_VALUE;
}
*res = relationFn(geosCtx->handle, geom1, geom2); *res = relationFn(geosCtx->handle, geom1, geom2);
} else { } else {
ASSERT(swappedRelationFn); if (!swappedRelationFn) {
return TSDB_CODE_FUNC_FUNTION_PARA_VALUE;
}
*res = swappedRelationFn(geosCtx->handle, geom1, geom2); *res = swappedRelationFn(geosCtx->handle, geom1, geom2);
} }
} else { } else {
if (!swapped) { if (!swapped) {
ASSERT(preparedRelationFn); if (!preparedRelationFn) {
return TSDB_CODE_FUNC_FUNTION_PARA_VALUE;
}
*res = preparedRelationFn(geosCtx->handle, preparedGeom1, geom2); *res = preparedRelationFn(geosCtx->handle, preparedGeom1, geom2);
} else { } else {
ASSERT(swappedPreparedRelationFn); if (!swappedPreparedRelationFn) {
return TSDB_CODE_FUNC_FUNTION_PARA_VALUE;
}
*res = swappedPreparedRelationFn(geosCtx->handle, preparedGeom1, geom2); *res = swappedPreparedRelationFn(geosCtx->handle, preparedGeom1, geom2);
} }
} }
@ -391,7 +399,9 @@ int32_t readGeometry(const unsigned char *input, GEOSGeometry **outputGeom,
const GEOSPreparedGeometry **outputPreparedGeom) { const GEOSPreparedGeometry **outputPreparedGeom) {
SGeosContext *geosCtx = getThreadLocalGeosCtx(); SGeosContext *geosCtx = getThreadLocalGeosCtx();
ASSERT(outputGeom); // it is not allowed if outputGeom is NULL if (!outputGeom) {
return TSDB_CODE_FUNC_FUNTION_PARA_VALUE;
}
*outputGeom = NULL; *outputGeom = NULL;
if (outputPreparedGeom) { // it means not to generate PreparedGeometry if outputPreparedGeom is NULL if (outputPreparedGeom) { // it means not to generate PreparedGeometry if outputPreparedGeom is NULL

View File

@ -66,7 +66,7 @@ void setScalarParam(SScalarParam *sclParam, int32_t type, void *valueArray, TDRo
break; break;
} }
default: { default: {
ASSERT(0); ASSERT_TRUE(false);
break; break;
} }
} }

View File

@ -237,8 +237,7 @@ int32_t indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
indexDebug("w suid:%" PRIu64 ", colName:%s, colType:%d", key.suid, key.colName, key.colType); indexDebug("w suid:%" PRIu64 ", colName:%s, colType:%d", key.suid, key.colName, key.colType);
IndexCache** cache = taosHashGet(index->colObj, buf, sz); IndexCache** cache = taosHashGet(index->colObj, buf, sz);
ASSERTS(*cache != NULL, "index-cache already release"); if (*cache == NULL) return TSDB_CODE_INVALID_PTR;
if (*cache == NULL) return -1;
int ret = idxCachePut(*cache, p, uid); int ret = idxCachePut(*cache, p, uid);
if (ret != 0) { if (ret != 0) {
@ -295,7 +294,9 @@ void indexMultiTermQueryDestroy(SIndexMultiTermQuery* pQuery) {
}; };
int32_t indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EIndexQueryType qType) { int32_t indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EIndexQueryType qType) {
SIndexTermQuery q = {.qType = qType, .term = term}; SIndexTermQuery q = {.qType = qType, .term = term};
(void)taosArrayPush(pQuery->query, &q); if (taosArrayPush(pQuery->query, &q) == NULL) {
return terrno;
}
return 0; return 0;
} }
@ -303,6 +304,7 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy
int32_t nColName, const char* colVal, int32_t nColVal) { int32_t nColName, const char* colVal, int32_t nColVal) {
SIndexTerm* tm = (SIndexTerm*)taosMemoryCalloc(1, (sizeof(SIndexTerm))); SIndexTerm* tm = (SIndexTerm*)taosMemoryCalloc(1, (sizeof(SIndexTerm)));
if (tm == NULL) { if (tm == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL; return NULL;
} }
@ -311,6 +313,10 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy
tm->colType = colType; tm->colType = colType;
tm->colName = (char*)taosMemoryCalloc(1, nColName + 1); tm->colName = (char*)taosMemoryCalloc(1, nColName + 1);
if (tm->colName == NULL) {
taosMemoryFree(tm);
return NULL;
}
memcpy(tm->colName, colName, nColName); memcpy(tm->colName, colName, nColName);
tm->nColName = nColName; tm->nColName = nColName;
@ -326,8 +332,23 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy
buf = strndup(emptyStr, (int32_t)strlen(emptyStr)); buf = strndup(emptyStr, (int32_t)strlen(emptyStr));
len = (int32_t)strlen(emptyStr); len = (int32_t)strlen(emptyStr);
} }
tm->colVal = buf; tm->colVal = buf;
if (tm->colVal == NULL) {
taosMemoryFree(tm->colName);
taosMemoryFree(tm);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
tm->nColVal = len; tm->nColVal = len;
if (tm->nColVal < 0) {
taosMemoryFree(tm->colName);
taosMemoryFree(tm->colVal);
taosMemoryFree(tm);
terrno = len;
return NULL;
}
return tm; return tm;
} }

View File

@ -308,90 +308,6 @@ int idxUidCompare(const void* a, const void* b) {
uint64_t r = *(uint64_t*)b; uint64_t r = *(uint64_t*)b;
return l - r; return l - r;
} }
#ifdef BUILD_NO_CALL
int32_t idxConvertData(void* src, int8_t type, void** dst) {
int tlen = -1;
switch (type) {
case TSDB_DATA_TYPE_TIMESTAMP:
tlen = taosEncodeFixedI64(NULL, *(int64_t*)src);
*dst = taosMemoryCalloc(1, tlen + 1);
tlen = taosEncodeFixedI64(dst, *(int64_t*)src);
break;
case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_UTINYINT:
tlen = taosEncodeFixedU8(NULL, *(uint8_t*)src);
*dst = taosMemoryCalloc(1, tlen + 1);
tlen = taosEncodeFixedU8(dst, *(uint8_t*)src);
break;
case TSDB_DATA_TYPE_TINYINT:
tlen = taosEncodeFixedI8(NULL, *(uint8_t*)src);
*dst = taosMemoryCalloc(1, tlen + 1);
tlen = taosEncodeFixedI8(dst, *(uint8_t*)src);
break;
case TSDB_DATA_TYPE_SMALLINT:
tlen = taosEncodeFixedI16(NULL, *(int16_t*)src);
*dst = taosMemoryCalloc(1, tlen + 1);
tlen = taosEncodeFixedI16(dst, *(int16_t*)src);
break;
case TSDB_DATA_TYPE_USMALLINT:
tlen = taosEncodeFixedU16(NULL, *(uint16_t*)src);
*dst = taosMemoryCalloc(1, tlen + 1);
tlen = taosEncodeFixedU16(dst, *(uint16_t*)src);
break;
case TSDB_DATA_TYPE_INT:
tlen = taosEncodeFixedI32(NULL, *(int32_t*)src);
*dst = taosMemoryCalloc(1, tlen + 1);
tlen = taosEncodeFixedI32(dst, *(int32_t*)src);
break;
case TSDB_DATA_TYPE_FLOAT:
tlen = taosEncodeBinary(NULL, src, sizeof(float));
*dst = taosMemoryCalloc(1, tlen + 1);
tlen = taosEncodeBinary(dst, src, sizeof(float));
break;
case TSDB_DATA_TYPE_UINT:
tlen = taosEncodeFixedU32(NULL, *(uint32_t*)src);
*dst = taosMemoryCalloc(1, tlen + 1);
tlen = taosEncodeFixedU32(dst, *(uint32_t*)src);
break;
case TSDB_DATA_TYPE_BIGINT:
tlen = taosEncodeFixedI64(NULL, *(int64_t*)src);
*dst = taosMemoryCalloc(1, tlen + 1);
tlen = taosEncodeFixedI64(dst, *(int64_t*)src);
break;
case TSDB_DATA_TYPE_DOUBLE:
tlen = taosEncodeBinary(NULL, src, sizeof(double));
*dst = taosMemoryCalloc(1, tlen + 1);
tlen = taosEncodeBinary(dst, src, sizeof(double));
break;
case TSDB_DATA_TYPE_UBIGINT:
tlen = taosEncodeFixedU64(NULL, *(uint64_t*)src);
*dst = taosMemoryCalloc(1, tlen + 1);
tlen = taosEncodeFixedU64(dst, *(uint64_t*)src);
break;
case TSDB_DATA_TYPE_NCHAR: {
tlen = taosEncodeBinary(NULL, varDataVal(src), varDataLen(src));
*dst = taosMemoryCalloc(1, tlen + 1);
tlen = taosEncodeBinary(dst, varDataVal(src), varDataLen(src));
break;
}
case TSDB_DATA_TYPE_VARCHAR: // TSDB_DATA_TYPE_BINARY
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_GEOMETRY: {
tlen = taosEncodeBinary(NULL, src, strlen(src));
*dst = taosMemoryCalloc(1, tlen + 1);
tlen = taosEncodeBinary(dst, src, strlen(src));
break;
}
default:
ASSERTS(0, "index invalid input type");
break;
}
*dst = (char*)*dst - tlen;
// indexMayFillNumbericData(*dst, tlen);
return tlen;
}
#endif
int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) {
if (src == NULL) { if (src == NULL) {
@ -513,7 +429,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) {
break; break;
} }
default: default:
ASSERTS(0, "index invalid input type"); tlen = TSDB_CODE_INVALID_DATA_FMT;
break; break;
} }
return tlen; return tlen;

View File

@ -661,7 +661,16 @@ static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFP
} }
SIndexMultiTermQuery *mtm = indexMultiTermQueryCreate(MUST); SIndexMultiTermQuery *mtm = indexMultiTermQueryCreate(MUST);
(void)indexMultiTermQueryAdd(mtm, tm, qtype); if (mtm == NULL) {
indexTermDestroy(tm);
return TSDB_CODE_OUT_OF_MEMORY;
}
if ((ret = indexMultiTermQueryAdd(mtm, tm, qtype)) != 0) {
indexMultiTermQueryDestroy(mtm);
return ret;
}
ret = indexJsonSearch(arg->ivtIdx, mtm, output->result); ret = indexJsonSearch(arg->ivtIdx, mtm, output->result);
indexMultiTermQueryDestroy(mtm); indexMultiTermQueryDestroy(mtm);
} else { } else {
@ -1119,7 +1128,6 @@ int32_t doFilterTag(SNode *pFilterNode, SIndexMetaArg *metaArg, SArray *result,
*status = st; *status = st;
} }
if (taosArrayAddAll(result, param.result) == NULL) { if (taosArrayAddAll(result, param.result) == NULL) {
sifFreeParam(&param); sifFreeParam(&param);
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;

View File

@ -98,7 +98,7 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes* nodes, FstSlice bs, Output
} }
int32_t sz = taosArrayGetSize(nodes->stack) - 1; int32_t sz = taosArrayGetSize(nodes->stack) - 1;
FstBuilderNodeUnfinished* un = taosArrayGet(nodes->stack, sz); FstBuilderNodeUnfinished* un = taosArrayGet(nodes->stack, sz);
ASSERTS(un->last == NULL, "index-fst meet unexpected node");
if (un->last != NULL) return; if (un->last != NULL) return;
// FstLastTransition *trn = taosMemoryMalloc(sizeof(FstLastTransition)); // FstLastTransition *trn = taosMemoryMalloc(sizeof(FstLastTransition));
@ -318,8 +318,6 @@ void fstStateCompileForAnyTrans(IdxFstFile* w, CompiledAddr addr, FstBuilderNode
// set_comm_input // set_comm_input
void fstStateSetCommInput(FstState* s, uint8_t inp) { void fstStateSetCommInput(FstState* s, uint8_t inp) {
ASSERT(s->state == OneTransNext || s->state == OneTrans);
uint8_t val; uint8_t val;
COMMON_INDEX(inp, 0b111111, val); COMMON_INDEX(inp, 0b111111, val);
s->val = (s->val & fstStateDict[s->state].val) | val; s->val = (s->val & fstStateDict[s->state].val) | val;
@ -327,7 +325,6 @@ void fstStateSetCommInput(FstState* s, uint8_t inp) {
// comm_input // comm_input
uint8_t fstStateCommInput(FstState* s, bool* null) { uint8_t fstStateCommInput(FstState* s, bool* null) {
ASSERT(s->state == OneTransNext || s->state == OneTrans);
uint8_t v = s->val & 0b00111111; uint8_t v = s->val & 0b00111111;
if (v == 0) { if (v == 0) {
*null = true; *null = true;
@ -340,7 +337,6 @@ uint8_t fstStateCommInput(FstState* s, bool* null) {
// input_len // input_len
uint64_t fstStateInputLen(FstState* s) { uint64_t fstStateInputLen(FstState* s) {
ASSERT(s->state == OneTransNext || s->state == OneTrans);
bool null = false; bool null = false;
(void)fstStateCommInput(s, &null); (void)fstStateCommInput(s, &null);
return null ? 1 : 0; return null ? 1 : 0;
@ -348,11 +344,9 @@ uint64_t fstStateInputLen(FstState* s) {
// end_addr // end_addr
uint64_t fstStateEndAddrForOneTransNext(FstState* s, FstSlice* data) { uint64_t fstStateEndAddrForOneTransNext(FstState* s, FstSlice* data) {
ASSERT(s->state == OneTransNext);
return FST_SLICE_LEN(data) - 1 - fstStateInputLen(s); return FST_SLICE_LEN(data) - 1 - fstStateInputLen(s);
} }
uint64_t fstStateEndAddrForOneTrans(FstState* s, FstSlice* data, PackSizes sizes) { uint64_t fstStateEndAddrForOneTrans(FstState* s, FstSlice* data, PackSizes sizes) {
ASSERT(s->state == OneTrans);
return FST_SLICE_LEN(data) - 1 - fstStateInputLen(s) - 1 // pack size return FST_SLICE_LEN(data) - 1 - fstStateInputLen(s) - 1 // pack size
- FST_GET_TRANSITION_PACK_SIZE(sizes) - FST_GET_OUTPUT_PACK_SIZE(sizes); - FST_GET_TRANSITION_PACK_SIZE(sizes) - FST_GET_OUTPUT_PACK_SIZE(sizes);
} }
@ -366,7 +360,6 @@ uint64_t fstStateEndAddrForAnyTrans(FstState* state, uint64_t version, FstSlice*
} }
// input // input
uint8_t fstStateInput(FstState* s, FstNode* node) { uint8_t fstStateInput(FstState* s, FstNode* node) {
ASSERT(s->state == OneTransNext || s->state == OneTrans);
FstSlice* slice = &node->data; FstSlice* slice = &node->data;
bool null = false; bool null = false;
uint8_t inp = fstStateCommInput(s, &null); uint8_t inp = fstStateCommInput(s, &null);
@ -374,7 +367,6 @@ uint8_t fstStateInput(FstState* s, FstNode* node) {
return null == false ? inp : data[node->start - 1]; return null == false ? inp : data[node->start - 1];
} }
uint8_t fstStateInputForAnyTrans(FstState* s, FstNode* node, uint64_t i) { uint8_t fstStateInputForAnyTrans(FstState* s, FstNode* node, uint64_t i) {
ASSERT(s->state == AnyTrans);
FstSlice* slice = &node->data; FstSlice* slice = &node->data;
uint64_t at = node->start - fstStateNtransLen(s) - 1 // pack size uint64_t at = node->start - fstStateNtransLen(s) - 1 // pack size
@ -386,7 +378,6 @@ uint8_t fstStateInputForAnyTrans(FstState* s, FstNode* node, uint64_t i) {
// trans_addr // trans_addr
CompiledAddr fstStateTransAddr(FstState* s, FstNode* node) { CompiledAddr fstStateTransAddr(FstState* s, FstNode* node) {
ASSERT(s->state == OneTransNext || s->state == OneTrans);
FstSlice* slice = &node->data; FstSlice* slice = &node->data;
if (s->state == OneTransNext) { if (s->state == OneTransNext) {
return (CompiledAddr)(node->end) - 1; return (CompiledAddr)(node->end) - 1;
@ -402,8 +393,6 @@ CompiledAddr fstStateTransAddr(FstState* s, FstNode* node) {
} }
} }
CompiledAddr fstStateTransAddrForAnyTrans(FstState* s, FstNode* node, uint64_t i) { CompiledAddr fstStateTransAddrForAnyTrans(FstState* s, FstNode* node, uint64_t i) {
ASSERT(s->state == AnyTrans);
FstSlice* slice = &node->data; FstSlice* slice = &node->data;
uint8_t tSizes = FST_GET_TRANSITION_PACK_SIZE(node->sizes); uint8_t tSizes = FST_GET_TRANSITION_PACK_SIZE(node->sizes);
uint64_t at = node->start - fstStateNtransLen(s) - 1 - fstStateTransIndexSize(s, node->version, node->nTrans) - uint64_t at = node->start - fstStateNtransLen(s) - 1 - fstStateTransIndexSize(s, node->version, node->nTrans) -
@ -414,7 +403,6 @@ CompiledAddr fstStateTransAddrForAnyTrans(FstState* s, FstNode* node, uint64_t i
// sizes // sizes
PackSizes fstStateSizes(FstState* s, FstSlice* slice) { PackSizes fstStateSizes(FstState* s, FstSlice* slice) {
ASSERT(s->state == OneTrans || s->state == AnyTrans);
uint64_t i; uint64_t i;
if (s->state == OneTrans) { if (s->state == OneTrans) {
i = FST_SLICE_LEN(slice) - 1 - fstStateInputLen(s) - 1; i = FST_SLICE_LEN(slice) - 1 - fstStateInputLen(s) - 1;
@ -427,8 +415,6 @@ PackSizes fstStateSizes(FstState* s, FstSlice* slice) {
} }
// Output // Output
Output fstStateOutput(FstState* s, FstNode* node) { Output fstStateOutput(FstState* s, FstNode* node) {
ASSERT(s->state == OneTrans);
uint8_t oSizes = FST_GET_OUTPUT_PACK_SIZE(node->sizes); uint8_t oSizes = FST_GET_OUTPUT_PACK_SIZE(node->sizes);
if (oSizes == 0) { if (oSizes == 0) {
return 0; return 0;
@ -441,8 +427,6 @@ Output fstStateOutput(FstState* s, FstNode* node) {
return unpackUint64(data + i, oSizes); return unpackUint64(data + i, oSizes);
} }
Output fstStateOutputForAnyTrans(FstState* s, FstNode* node, uint64_t i) { Output fstStateOutputForAnyTrans(FstState* s, FstNode* node, uint64_t i) {
ASSERT(s->state == AnyTrans);
uint8_t oSizes = FST_GET_OUTPUT_PACK_SIZE(node->sizes); uint8_t oSizes = FST_GET_OUTPUT_PACK_SIZE(node->sizes);
if (oSizes == 0) { if (oSizes == 0) {
return 0; return 0;
@ -458,19 +442,14 @@ Output fstStateOutputForAnyTrans(FstState* s, FstNode* node, uint64_t i) {
// anyTrans specify function // anyTrans specify function
void fstStateSetFinalState(FstState* s, bool yes) { void fstStateSetFinalState(FstState* s, bool yes) {
ASSERT(s->state == AnyTrans);
if (yes) { if (yes) {
s->val |= 0b01000000; s->val |= 0b01000000;
} }
return; return;
} }
bool fstStateIsFinalState(FstState* s) { bool fstStateIsFinalState(FstState* s) { return (s->val & 0b01000000) == 0b01000000; }
ASSERT(s->state == AnyTrans);
return (s->val & 0b01000000) == 0b01000000;
}
void fstStateSetStateNtrans(FstState* s, uint8_t n) { void fstStateSetStateNtrans(FstState* s, uint8_t n) {
ASSERT(s->state == AnyTrans);
if (n <= 0b00111111) { if (n <= 0b00111111) {
s->val = (s->val & 0b11000000) | n; s->val = (s->val & 0b11000000) | n;
} }
@ -478,7 +457,6 @@ void fstStateSetStateNtrans(FstState* s, uint8_t n) {
} }
// state_ntrans // state_ntrans
uint8_t fstStateStateNtrans(FstState* s, bool* null) { uint8_t fstStateStateNtrans(FstState* s, bool* null) {
ASSERT(s->state == AnyTrans);
*null = false; *null = false;
uint8_t n = s->val & 0b00111111; uint8_t n = s->val & 0b00111111;
@ -488,16 +466,13 @@ uint8_t fstStateStateNtrans(FstState* s, bool* null) {
return n; return n;
} }
uint64_t fstStateTotalTransSize(FstState* s, uint64_t version, PackSizes sizes, uint64_t nTrans) { uint64_t fstStateTotalTransSize(FstState* s, uint64_t version, PackSizes sizes, uint64_t nTrans) {
ASSERT(s->state == AnyTrans);
uint64_t idxSize = fstStateTransIndexSize(s, version, nTrans); uint64_t idxSize = fstStateTransIndexSize(s, version, nTrans);
return nTrans + (nTrans * FST_GET_TRANSITION_PACK_SIZE(sizes)) + idxSize; return nTrans + (nTrans * FST_GET_TRANSITION_PACK_SIZE(sizes)) + idxSize;
} }
uint64_t fstStateTransIndexSize(FstState* s, uint64_t version, uint64_t nTrans) { uint64_t fstStateTransIndexSize(FstState* s, uint64_t version, uint64_t nTrans) {
ASSERT(s->state == AnyTrans);
return (version >= 2 && nTrans > TRANS_INDEX_THRESHOLD) ? 256 : 0; return (version >= 2 && nTrans > TRANS_INDEX_THRESHOLD) ? 256 : 0;
} }
uint64_t fstStateNtransLen(FstState* s) { uint64_t fstStateNtransLen(FstState* s) {
ASSERT(s->state == AnyTrans);
bool null = false; bool null = false;
(void)fstStateStateNtrans(s, &null); (void)fstStateStateNtrans(s, &null);
return null == true ? 1 : 0; return null == true ? 1 : 0;
@ -526,7 +501,6 @@ Output fstStateFinalOutput(FstState* s, uint64_t version, FstSlice* slice, PackS
return unpackUint64(data + at, (uint8_t)oSizes); return unpackUint64(data + at, (uint8_t)oSizes);
} }
uint64_t fstStateFindInput(FstState* s, FstNode* node, uint8_t b, bool* null) { uint64_t fstStateFindInput(FstState* s, FstNode* node, uint8_t b, bool* null) {
ASSERT(s->state == AnyTrans);
FstSlice* slice = &node->data; FstSlice* slice = &node->data;
if (node->version >= 2 && node->nTrans > TRANS_INDEX_THRESHOLD) { if (node->version >= 2 && node->nTrans > TRANS_INDEX_THRESHOLD) {
uint64_t at = node->start - fstStateNtransLen(s) - 1 // pack size uint64_t at = node->start - fstStateNtransLen(s) - 1 // pack size
@ -672,17 +646,14 @@ bool fstNodeGetTransitionAddrAt(FstNode* node, uint64_t i, CompiledAddr* res) {
bool s = true; bool s = true;
FstState* st = &node->state; FstState* st = &node->state;
if (st->state == OneTransNext) { if (st->state == OneTransNext) {
ASSERT(i == 0);
(void)fstStateTransAddr(st, node); (void)fstStateTransAddr(st, node);
} else if (st->state == OneTrans) { } else if (st->state == OneTrans) {
ASSERT(i == 0);
(void)fstStateTransAddr(st, node); (void)fstStateTransAddr(st, node);
} else if (st->state == AnyTrans) { } else if (st->state == AnyTrans) {
(void)fstStateTransAddrForAnyTrans(st, node, i); (void)fstStateTransAddrForAnyTrans(st, node, i);
} else if (FST_STATE_EMPTY_FINAL(node)) { } else if (FST_STATE_EMPTY_FINAL(node)) {
s = false; s = false;
} else { } else {
ASSERT(0);
} }
return s; return s;
} }
@ -718,7 +689,6 @@ bool fstNodeFindInput(FstNode* node, uint8_t b, uint64_t* res) {
bool fstNodeCompile(FstNode* node, void* w, CompiledAddr lastAddr, CompiledAddr addr, FstBuilderNode* builderNode) { bool fstNodeCompile(FstNode* node, void* w, CompiledAddr lastAddr, CompiledAddr addr, FstBuilderNode* builderNode) {
int32_t sz = taosArrayGetSize(builderNode->trans); int32_t sz = taosArrayGetSize(builderNode->trans);
ASSERT(sz < 256);
if (sz == 0 && builderNode->isFinal && builderNode->finalOutput == 0) { if (sz == 0 && builderNode->isFinal && builderNode->finalOutput == 0) {
return true; return true;
} else if (sz != 1 || builderNode->isFinal) { } else if (sz != 1 || builderNode->isFinal) {
@ -800,7 +770,6 @@ void fstBuilderInsertOutput(FstBuilder* b, FstSlice bs, Output in) {
uint64_t prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out); uint64_t prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out);
if (prefixLen == FST_SLICE_LEN(s)) { if (prefixLen == FST_SLICE_LEN(s)) {
ASSERT(out == 0);
return; return;
} }
@ -844,7 +813,6 @@ void fstBuilderCompileFrom(FstBuilder* b, uint64_t istate) {
addr = fstBuilderCompile(b, bn); addr = fstBuilderCompile(b, bn);
fstBuilderNodeDestroy(bn); fstBuilderNodeDestroy(bn);
ASSERT(addr != NONE_ADDRESS);
} }
fstUnFinishedNodesTopLastFreeze(b->unfinished, addr); fstUnFinishedNodesTopLastFreeze(b->unfinished, addr);
return; return;

View File

@ -104,7 +104,10 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of
do { do {
char key[1024] = {0}; char key[1024] = {0};
ASSERT(strlen(ctx->file.buf) + 1 + 64 < sizeof(key)); if (strlen(ctx->file.buf) + 1 + 64 >= sizeof(key)) {
return TSDB_CODE_INDEX_INVALID_FILE;
}
idxGenLRUKey(key, ctx->file.buf, blkId); idxGenLRUKey(key, ctx->file.buf, blkId);
LRUHandle* h = taosLRUCacheLookup(ctx->lru, key, strlen(key)); LRUHandle* h = taosLRUCacheLookup(ctx->lru, key, strlen(key));
@ -118,8 +121,10 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of
if (left < kBlockSize) { if (left < kBlockSize) {
nread = TMIN(left, len); nread = TMIN(left, len);
int32_t bytes = taosPReadFile(ctx->file.pFile, buf + total, nread, offset); int32_t bytes = taosPReadFile(ctx->file.pFile, buf + total, nread, offset);
ASSERTS(bytes == nread, "index read incomplete data"); if (bytes != nread) {
if (bytes != nread) break; total = TSDB_CODE_INDEX_INVALID_FILE;
break;
}
total += bytes; total += bytes;
return total; return total;
@ -129,7 +134,6 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of
SDataBlock* blk = taosMemoryCalloc(1, cacheMemSize); SDataBlock* blk = taosMemoryCalloc(1, cacheMemSize);
blk->blockId = blkId; blk->blockId = blkId;
blk->nread = taosPReadFile(ctx->file.pFile, blk->buf, kBlockSize, blkId * kBlockSize); blk->nread = taosPReadFile(ctx->file.pFile, blk->buf, kBlockSize, blkId * kBlockSize);
ASSERTS(blk->nread <= kBlockSize, "index read incomplete data");
if (blk->nread < kBlockSize && blk->nread < len) { if (blk->nread < kBlockSize && blk->nread < len) {
taosMemoryFree(blk); taosMemoryFree(blk);
break; break;
@ -288,7 +292,6 @@ int32_t idxFileWrite(IdxFstFile* write, uint8_t* buf, uint32_t len) {
// update checksum // update checksum
IFileCtx* ctx = write->wrt; IFileCtx* ctx = write->wrt;
int nWrite = ctx->write(ctx, buf, len); int nWrite = ctx->write(ctx, buf, len);
ASSERTS(nWrite == len, "index write incomplete data");
if (nWrite != len) { if (nWrite != len) {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
return code; return code;

View File

@ -97,9 +97,7 @@ void fstBuilderNodeCloneFrom(FstBuilderNode* dst, FstBuilderNode* src) {
// bool fstBuilderNodeCompileTo(FstBuilderNode *b, IdxFile *wrt, CompiledAddr lastAddr, CompiledAddr // bool fstBuilderNodeCompileTo(FstBuilderNode *b, IdxFile *wrt, CompiledAddr lastAddr, CompiledAddr
// startAddr) { // startAddr) {
// size_t sz = taosArrayGetSize(b->trans); // size_t sz = taosArrayGetSize(b->trans);
// assert(sz < 256);
// if (FST_BUILDER_NODE_IS_FINAL(b) // if (FST_BUILDER_NODE_IS_FINAL(b)
// && FST_BUILDER_NODE_TRANS_ISEMPTY(b) // && FST_BUILDER_NODE_TRANS_ISEMPTY(b)
// && FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) { // && FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) {

View File

@ -57,8 +57,9 @@ static void fstRegistryCellPromote(SArray* arr, uint32_t start, uint32_t end) {
if (start >= sz && end >= sz) { if (start >= sz && end >= sz) {
return; return;
} }
ASSERTS(start >= end, "index-fst start lower than end"); if (start < end) {
if (start < end) return; return;
}
int32_t s = (int32_t)start; int32_t s = (int32_t)start;
int32_t e = (int32_t)end; int32_t e = (int32_t)end;

View File

@ -933,17 +933,20 @@ static int tfileWriteFooter(TFileWriter* write) {
char buf[sizeof(FILE_MAGIC_NUMBER) + 1] = {0}; char buf[sizeof(FILE_MAGIC_NUMBER) + 1] = {0};
void* pBuf = (void*)buf; void* pBuf = (void*)buf;
(void)taosEncodeFixedU64((void**)(void*)&pBuf, FILE_MAGIC_NUMBER); (void)taosEncodeFixedU64((void**)(void*)&pBuf, FILE_MAGIC_NUMBER);
int nwrite = write->ctx->write(write->ctx, buf, (int32_t)strlen(buf)); int nwrite = write->ctx->write(write->ctx, (uint8_t*)buf, (int32_t)strlen(buf));
indexInfo("tfile write footer size: %d", write->ctx->size(write->ctx)); indexInfo("tfile write footer size: %d", write->ctx->size(write->ctx));
ASSERTS(nwrite == sizeof(FILE_MAGIC_NUMBER), "index write incomplete data"); if (nwrite != sizeof(FILE_MAGIC_NUMBER)) {
return nwrite; return TAOS_SYSTEM_ERROR(errno);
} else {
return nwrite;
}
} }
static int tfileReaderLoadHeader(TFileReader* reader) { static int tfileReaderLoadHeader(TFileReader* reader) {
// TODO simple tfile header later // TODO simple tfile header later
char buf[TFILE_HEADER_SIZE] = {0}; char buf[TFILE_HEADER_SIZE] = {0};
int64_t nread = reader->ctx->readFrom(reader->ctx, buf, sizeof(buf), 0); int64_t nread = reader->ctx->readFrom(reader->ctx, (uint8_t*)buf, sizeof(buf), 0);
if (nread == -1) { if (nread == -1) {
indexError("actual Read: %d, to read: %d, code:0x%x, filename: %s", (int)(nread), (int)sizeof(buf), errno, indexError("actual Read: %d, to read: %d, code:0x%x, filename: %s", (int)(nread), (int)sizeof(buf), errno,
@ -967,14 +970,13 @@ static int tfileReaderLoadFst(TFileReader* reader) {
} }
int64_t ts = taosGetTimestampUs(); int64_t ts = taosGetTimestampUs();
int32_t nread = ctx->readFrom(ctx, buf, fstSize, reader->header.fstOffset); int32_t nread = ctx->readFrom(ctx, (uint8_t*)buf, fstSize, reader->header.fstOffset);
int64_t cost = taosGetTimestampUs() - ts; int64_t cost = taosGetTimestampUs() - ts;
indexInfo("nread = %d, and fst offset=%d, fst size: %d, filename: %s, file size: %d, time cost: %" PRId64 "us", nread, indexInfo("nread = %d, and fst offset=%d, fst size: %d, filename: %s, file size: %d, time cost: %" PRId64 "us", nread,
reader->header.fstOffset, fstSize, ctx->file.buf, size, cost); reader->header.fstOffset, fstSize, ctx->file.buf, size, cost);
// we assuse fst size less than FST_MAX_SIZE // we assuse fst size less than FST_MAX_SIZE
ASSERTS(nread > 0 && nread <= fstSize, "index read incomplete fst");
if (nread <= 0 || nread > fstSize) { if (nread <= 0 || nread > fstSize) {
return -1; return TSDB_CODE_INDEX_INVALID_FILE;
} }
FstSlice st = fstSliceCreate((uint8_t*)buf, nread); FstSlice st = fstSliceCreate((uint8_t*)buf, nread);
@ -989,8 +991,10 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray*
IFileCtx* ctx = reader->ctx; IFileCtx* ctx = reader->ctx;
// add block cache // add block cache
char block[4096] = {0}; char block[4096] = {0};
int32_t nread = ctx->readFrom(ctx, block, sizeof(block), offset); int32_t nread = ctx->readFrom(ctx, (uint8_t*)block, sizeof(block), offset);
ASSERT(nread >= sizeof(uint32_t)); if (nread < sizeof(uint32_t)) {
return TSDB_CODE_INDEX_INVALID_FILE;
}
char* p = block; char* p = block;
int32_t nid = *(int32_t*)p; int32_t nid = *(int32_t*)p;
@ -1007,7 +1011,7 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray*
memset(block, 0, sizeof(block)); memset(block, 0, sizeof(block));
offset += sizeof(block); offset += sizeof(block);
nread = ctx->readFrom(ctx, block, sizeof(block), offset); nread = ctx->readFrom(ctx, (uint8_t*)block, sizeof(block), offset);
memcpy(buf + left, block, sizeof(uint64_t) - left); memcpy(buf + left, block, sizeof(uint64_t) - left);
(void)taosArrayPush(result, (uint64_t*)buf); (void)taosArrayPush(result, (uint64_t*)buf);
@ -1026,13 +1030,14 @@ static int tfileReaderVerify(TFileReader* reader) {
int size = ctx->size(ctx); int size = ctx->size(ctx);
if (size < sizeof(tMagicNumber) || size <= sizeof(reader->header)) { if (size < sizeof(tMagicNumber) || size <= sizeof(reader->header)) {
return -1; return TSDB_CODE_INDEX_INVALID_FILE;
} else if (ctx->readFrom(ctx, buf, sizeof(tMagicNumber), size - sizeof(tMagicNumber)) != sizeof(tMagicNumber)) { } else if (ctx->readFrom(ctx, (uint8_t*)buf, sizeof(tMagicNumber), size - sizeof(tMagicNumber)) !=
return -1; sizeof(tMagicNumber)) {
return TSDB_CODE_INDEX_INVALID_FILE;
} }
(void)taosDecodeFixedU64(buf, &tMagicNumber); (void)taosDecodeFixedU64(buf, &tMagicNumber);
return tMagicNumber == FILE_MAGIC_NUMBER ? 0 : -1; return tMagicNumber == FILE_MAGIC_NUMBER ? 0 : TSDB_CODE_INDEX_INVALID_FILE;
} }
void tfileReaderRef(TFileReader* rd) { void tfileReaderRef(TFileReader* rd) {

View File

@ -11072,7 +11072,10 @@ static int32_t createStreamReqVersionInfo(SSDataBlock* pBlock, SArray** pArray,
for (int32_t i = 0; i < pBlock->info.rows; ++i) { for (int32_t i = 0; i < pBlock->info.rows; ++i) {
SVgroupVer v = {.vgId = *(int32_t*)colDataGetData(pCol1, i), .ver = *(int64_t*)colDataGetData(pCol2, i)}; SVgroupVer v = {.vgId = *(int32_t*)colDataGetData(pCol1, i), .ver = *(int64_t*)colDataGetData(pCol2, i)};
(void)taosArrayPush(*pArray, &v); if((taosArrayPush(*pArray, &v)) == NULL) {
taosArrayDestroy(*pArray);
return terrno;
}
} }
} else { } else {
int32_t precision = (pInterval->interval > 0) ? pInterval->precision : TSDB_TIME_PRECISION_MILLI; int32_t precision = (pInterval->interval > 0) ? pInterval->precision : TSDB_TIME_PRECISION_MILLI;

View File

@ -420,7 +420,10 @@ int32_t remoteChkpGetDelFile(char* path, SArray* toDel) {
} }
void cleanDir(const char* pPath, const char* id) { void cleanDir(const char* pPath, const char* id) {
ASSERT(pPath != NULL); if (pPath == NULL) {
stError("%s try to clean dir, but path is NULL", id);
return;
}
if (taosIsDir(pPath)) { if (taosIsDir(pPath)) {
taosRemoveDir(pPath); taosRemoveDir(pPath);
@ -2603,7 +2606,7 @@ void taskDbDestroy(void* pDb, bool flush) {
stDebug("succ to destroy stream backend:%p", wrapper); stDebug("succ to destroy stream backend:%p", wrapper);
int8_t nCf = tListLen(ginitDict); int8_t nCf = tListLen(ginitDict);
if (flush && wrapper->removeAllFiles == 0) { if (flush && wrapper->removeAllFiles == 0) {
if (wrapper->db && wrapper->pCf) { if (wrapper->db && wrapper->pCf) {
rocksdb_flushoptions_t* flushOpt = rocksdb_flushoptions_create(); rocksdb_flushoptions_t* flushOpt = rocksdb_flushoptions_create();
rocksdb_flushoptions_set_wait(flushOpt, 1); rocksdb_flushoptions_set_wait(flushOpt, 1);

View File

@ -45,9 +45,6 @@
// //
static inline int64_t syncNodeAbs64(int64_t a, int64_t b) { static inline int64_t syncNodeAbs64(int64_t a, int64_t b) {
ASSERT(a >= 0);
ASSERT(b >= 0);
int64_t c = a > b ? a - b : b - a; int64_t c = a > b ? a - b : b - a;
return c; return c;
} }

View File

@ -3523,6 +3523,9 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
return 0; return 0;
} }
SyncTerm matchTerm = syncLogBufferGetLastMatchTerm(ths->pLogBuf); SyncTerm matchTerm = syncLogBufferGetLastMatchTerm(ths->pLogBuf);
if (matchTerm < 0) {
return TSDB_CODE_SYN_INTERNAL_ERROR;
}
if (pMsg->currentTerm == matchTerm) { if (pMsg->currentTerm == matchTerm) {
(void)syncNodeUpdateCommitIndex(ths, pMsg->commitIndex); (void)syncNodeUpdateCommitIndex(ths, pMsg->commitIndex);
} }

View File

@ -46,8 +46,8 @@ int64_t syncLogBufferGetEndIndex(SSyncLogBuffer* pBuf) {
int32_t syncLogBufferAppend(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry) { int32_t syncLogBufferAppend(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry) {
int32_t code = 0; int32_t code = 0;
TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
(void)taosThreadMutexLock(&pBuf->mutex); (void)taosThreadMutexLock(&pBuf->mutex);
(void)syncLogBufferValidate(pBuf);
SyncIndex index = pEntry->index; SyncIndex index = pEntry->index;
if (index - pBuf->startIndex >= pBuf->size) { if (index - pBuf->startIndex >= pBuf->size) {
@ -102,13 +102,13 @@ int32_t syncLogBufferAppend(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt
pBuf->entries[index % pBuf->size] = tmp; pBuf->entries[index % pBuf->size] = tmp;
pBuf->endIndex = index + 1; pBuf->endIndex = index + 1;
(void)syncLogBufferValidate(pBuf);
(void)taosThreadMutexUnlock(&pBuf->mutex); (void)taosThreadMutexUnlock(&pBuf->mutex);
TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
return 0; return 0;
_err: _err:
(void)syncLogBufferValidate(pBuf);
(void)taosThreadMutexUnlock(&pBuf->mutex); (void)taosThreadMutexUnlock(&pBuf->mutex);
TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
taosMsleep(1); taosMsleep(1);
TAOS_RETURN(code); TAOS_RETURN(code);
} }
@ -134,7 +134,11 @@ int32_t syncLogReplGetPrevLogTerm(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncI
if (prevIndex >= pBuf->startIndex) { if (prevIndex >= pBuf->startIndex) {
pEntry = pBuf->entries[(prevIndex + pBuf->size) % pBuf->size].pItem; pEntry = pBuf->entries[(prevIndex + pBuf->size) % pBuf->size].pItem;
ASSERTS(pEntry != NULL, "no log entry found"); if (pEntry == NULL) {
sError("vgId:%d, failed to get pre log term since no log entry found", pNode->vgId);
*pSyncTerm = -1;
TAOS_RETURN(TSDB_CODE_SYN_INTERNAL_ERROR);
}
prevLogTerm = pEntry->term; prevLogTerm = pEntry->term;
*pSyncTerm = prevLogTerm; *pSyncTerm = prevLogTerm;
return 0; return 0;
@ -142,9 +146,18 @@ int32_t syncLogReplGetPrevLogTerm(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncI
if (pMgr && pMgr->startIndex <= prevIndex && prevIndex < pMgr->endIndex) { if (pMgr && pMgr->startIndex <= prevIndex && prevIndex < pMgr->endIndex) {
int64_t timeMs = pMgr->states[(prevIndex + pMgr->size) % pMgr->size].timeMs; int64_t timeMs = pMgr->states[(prevIndex + pMgr->size) % pMgr->size].timeMs;
ASSERTS(timeMs != 0, "no log entry found"); if (timeMs == 0) {
sError("vgId:%d, failed to get pre log term since timeMs is 0", pNode->vgId);
*pSyncTerm = -1;
TAOS_RETURN(TSDB_CODE_SYN_INTERNAL_ERROR);
}
prevLogTerm = pMgr->states[(prevIndex + pMgr->size) % pMgr->size].term; prevLogTerm = pMgr->states[(prevIndex + pMgr->size) % pMgr->size].term;
ASSERT(prevIndex == 0 || prevLogTerm != 0); if (!(prevIndex == 0 || prevLogTerm != 0)) {
sError("vgId:%d, failed to get pre log term prevIndex:%" PRId64 ", prevLogTerm:%" PRId64, pNode->vgId, prevIndex,
prevLogTerm);
*pSyncTerm = -1;
TAOS_RETURN(TSDB_CODE_SYN_INTERNAL_ERROR);
}
*pSyncTerm = prevLogTerm; *pSyncTerm = prevLogTerm;
return 0; return 0;
} }
@ -289,7 +302,7 @@ int32_t syncLogBufferInitWithoutLock(SSyncLogBuffer* pBuf, SSyncNode* pNode) {
pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex); pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
// validate // validate
(void)syncLogBufferValidate(pBuf); TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
return 0; return 0;
_exit: _exit:
@ -307,8 +320,8 @@ int32_t syncLogBufferInit(SSyncLogBuffer* pBuf, SSyncNode* pNode) {
} }
int32_t syncLogBufferReInit(SSyncLogBuffer* pBuf, SSyncNode* pNode) { int32_t syncLogBufferReInit(SSyncLogBuffer* pBuf, SSyncNode* pNode) {
TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
(void)taosThreadMutexLock(&pBuf->mutex); (void)taosThreadMutexLock(&pBuf->mutex);
(void)syncLogBufferValidate(pBuf);
for (SyncIndex index = pBuf->startIndex; index < pBuf->endIndex; index++) { for (SyncIndex index = pBuf->startIndex; index < pBuf->endIndex; index++) {
SSyncRaftEntry* pEntry = pBuf->entries[(index + pBuf->size) % pBuf->size].pItem; SSyncRaftEntry* pEntry = pBuf->entries[(index + pBuf->size) % pBuf->size].pItem;
if (pEntry == NULL) continue; if (pEntry == NULL) continue;
@ -321,15 +334,19 @@ int32_t syncLogBufferReInit(SSyncLogBuffer* pBuf, SSyncNode* pNode) {
if (code < 0) { if (code < 0) {
sError("vgId:%d, failed to re-initialize sync log buffer since %s.", pNode->vgId, tstrerror(code)); sError("vgId:%d, failed to re-initialize sync log buffer since %s.", pNode->vgId, tstrerror(code));
} }
(void)syncLogBufferValidate(pBuf);
(void)taosThreadMutexUnlock(&pBuf->mutex); (void)taosThreadMutexUnlock(&pBuf->mutex);
TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
return code; return code;
} }
FORCE_INLINE SyncTerm syncLogBufferGetLastMatchTermWithoutLock(SSyncLogBuffer* pBuf) { FORCE_INLINE SyncTerm syncLogBufferGetLastMatchTermWithoutLock(SSyncLogBuffer* pBuf) {
SyncIndex index = pBuf->matchIndex; SyncIndex index = pBuf->matchIndex;
SSyncRaftEntry* pEntry = pBuf->entries[(index + pBuf->size) % pBuf->size].pItem; SSyncRaftEntry* pEntry = pBuf->entries[(index + pBuf->size) % pBuf->size].pItem;
ASSERT(pEntry != NULL); if (pEntry == NULL) {
sError("failed to get last match term since entry is null");
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
return -1;
}
return pEntry->term; return pEntry->term;
} }
@ -348,8 +365,8 @@ bool syncLogBufferIsEmpty(SSyncLogBuffer* pBuf) {
} }
int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevTerm) { int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevTerm) {
TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
(void)taosThreadMutexLock(&pBuf->mutex); (void)taosThreadMutexLock(&pBuf->mutex);
(void)syncLogBufferValidate(pBuf);
int32_t code = 0; int32_t code = 0;
SyncIndex index = pEntry->index; SyncIndex index = pEntry->index;
SyncIndex prevIndex = pEntry->index - 1; SyncIndex prevIndex = pEntry->index - 1;
@ -357,6 +374,12 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt
SSyncRaftEntry* pExist = NULL; SSyncRaftEntry* pExist = NULL;
bool inBuf = true; bool inBuf = true;
if (lastMatchTerm < 0) {
sError("vgId:%d, failed to accept, lastMatchTerm:%" PRId64, pNode->vgId, lastMatchTerm);
code = TSDB_CODE_SYN_INTERNAL_ERROR;
goto _out;
}
if (index <= pBuf->commitIndex) { if (index <= pBuf->commitIndex) {
sTrace("vgId:%d, already committed. index:%" PRId64 ", term:%" PRId64 ". log buffer: [%" PRId64 " %" PRId64 sTrace("vgId:%d, already committed. index:%" PRId64 ", term:%" PRId64 ". log buffer: [%" PRId64 " %" PRId64
" %" PRId64 ", %" PRId64 ")", " %" PRId64 ", %" PRId64 ")",
@ -364,7 +387,11 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt
pBuf->endIndex); pBuf->endIndex);
SyncTerm term = -1; SyncTerm term = -1;
code = syncLogReplGetPrevLogTerm(NULL, pNode, index + 1, &term); code = syncLogReplGetPrevLogTerm(NULL, pNode, index + 1, &term);
ASSERT(pEntry->term >= 0); if (pEntry->term < 0) {
sError("vgId:%d, failed to accept, pEntry->term:%" PRId64, pNode->vgId, pEntry->term);
code = TSDB_CODE_SYN_INTERNAL_ERROR;
goto _out;
}
if (term == pEntry->term) { if (term == pEntry->term) {
code = 0; code = 0;
} }
@ -401,7 +428,12 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt
// check current in buffer // check current in buffer
code = syncLogBufferGetOneEntry(pBuf, pNode, index, &inBuf, &pExist); code = syncLogBufferGetOneEntry(pBuf, pNode, index, &inBuf, &pExist);
if (pExist != NULL) { if (pExist != NULL) {
ASSERT(pEntry->index == pExist->index); if (pEntry->index != pExist->index) {
sError("vgId:%d, failed to accept, pEntry->index:%" PRId64 ", pExist->index:%" PRId64, pNode->vgId, pEntry->index,
pExist->index);
code = TSDB_CODE_SYN_INTERNAL_ERROR;
goto _out;
}
if (pEntry->term != pExist->term) { if (pEntry->term != pExist->term) {
(void)syncLogBufferRollback(pBuf, pNode, index); (void)syncLogBufferRollback(pBuf, pNode, index);
} else { } else {
@ -411,7 +443,14 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt
pBuf->endIndex); pBuf->endIndex);
SyncTerm existPrevTerm = -1; SyncTerm existPrevTerm = -1;
(void)syncLogReplGetPrevLogTerm(NULL, pNode, index, &existPrevTerm); (void)syncLogReplGetPrevLogTerm(NULL, pNode, index, &existPrevTerm);
ASSERT(pEntry->term == pExist->term && (pEntry->index > pBuf->matchIndex || prevTerm == existPrevTerm)); if (!(pEntry->term == pExist->term && (pEntry->index > pBuf->matchIndex || prevTerm == existPrevTerm))) {
sError("vgId:%d, failed to accept, pEntry->term:%" PRId64 ", pExist->indexpExist->term:%" PRId64
", pEntry->index:%" PRId64 ", pBuf->matchIndex:%" PRId64 ", prevTerm:%" PRId64
", existPrevTerm:%" PRId64,
pNode->vgId, pEntry->term, pExist->term, pEntry->index, pBuf->matchIndex, prevTerm, existPrevTerm);
code = TSDB_CODE_SYN_INTERNAL_ERROR;
goto _out;
}
code = 0; code = 0;
goto _out; goto _out;
} }
@ -446,8 +485,8 @@ _out:
syncEntryDestroy(pExist); syncEntryDestroy(pExist);
pExist = NULL; pExist = NULL;
} }
(void)syncLogBufferValidate(pBuf);
(void)taosThreadMutexUnlock(&pBuf->mutex); (void)taosThreadMutexUnlock(&pBuf->mutex);
TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
@ -479,8 +518,8 @@ int32_t syncLogStorePersist(SSyncLogStore* pLogStore, SSyncNode* pNode, SSyncRaf
} }
int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* pMatchTerm, char* str) { int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* pMatchTerm, char* str) {
TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
(void)taosThreadMutexLock(&pBuf->mutex); (void)taosThreadMutexLock(&pBuf->mutex);
(void)syncLogBufferValidate(pBuf);
SSyncLogStore* pLogStore = pNode->pLogStore; SSyncLogStore* pLogStore = pNode->pLogStore;
int64_t matchIndex = pBuf->matchIndex; int64_t matchIndex = pBuf->matchIndex;
@ -488,7 +527,11 @@ int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* p
while (pBuf->matchIndex + 1 < pBuf->endIndex) { while (pBuf->matchIndex + 1 < pBuf->endIndex) {
int64_t index = pBuf->matchIndex + 1; int64_t index = pBuf->matchIndex + 1;
ASSERT(index >= 0); if (index < 0) {
sError("vgId:%d, failed to proceed index:%" PRId64, pNode->vgId, index);
code = TSDB_CODE_SYN_INTERNAL_ERROR;
goto _out;
}
// try to proceed // try to proceed
SSyncLogBufEntry* pBufEntry = &pBuf->entries[index % pBuf->size]; SSyncLogBufEntry* pBufEntry = &pBuf->entries[index % pBuf->size];
@ -501,14 +544,37 @@ int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* p
goto _out; goto _out;
} }
ASSERT(index == pEntry->index); if (index != pEntry->index) {
sError("vgId:%d, failed to proceed index:%" PRId64 ", pEntry->index:%" PRId64, pNode->vgId, index, pEntry->index);
code = TSDB_CODE_SYN_INTERNAL_ERROR;
goto _out;
}
// match // match
SSyncRaftEntry* pMatch = pBuf->entries[(pBuf->matchIndex + pBuf->size) % pBuf->size].pItem; SSyncRaftEntry* pMatch = pBuf->entries[(pBuf->matchIndex + pBuf->size) % pBuf->size].pItem;
ASSERT(pMatch != NULL); if (pMatch == NULL) {
ASSERT(pMatch->index == pBuf->matchIndex); sError("vgId:%d, failed to proceed since pMatch is null", pNode->vgId);
ASSERT(pMatch->index + 1 == pEntry->index); code = TSDB_CODE_SYN_INTERNAL_ERROR;
ASSERT(prevLogIndex == pMatch->index); goto _out;
}
if (pMatch->index != pBuf->matchIndex) {
sError("vgId:%d, failed to proceed, pMatch->index:%" PRId64 ", pBuf->matchIndex:%" PRId64, pNode->vgId,
pMatch->index, pBuf->matchIndex);
code = TSDB_CODE_SYN_INTERNAL_ERROR;
goto _out;
}
if (pMatch->index + 1 != pEntry->index) {
sError("vgId:%d, failed to proceed, pMatch->index:%" PRId64 ", pEntry->index:%" PRId64, pNode->vgId,
pMatch->index, pEntry->index);
code = TSDB_CODE_SYN_INTERNAL_ERROR;
goto _out;
}
if (prevLogIndex != pMatch->index) {
sError("vgId:%d, failed to proceed, prevLogIndex:%" PRId64 ", pMatch->index:%" PRId64, pNode->vgId, prevLogIndex,
pMatch->index);
code = TSDB_CODE_SYN_INTERNAL_ERROR;
goto _out;
}
if (pMatch->term != prevLogTerm) { if (pMatch->term != prevLogTerm) {
sInfo( sInfo(
@ -567,7 +633,12 @@ int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* p
// replicate on demand // replicate on demand
(void)syncNodeReplicateWithoutLock(pNode); (void)syncNodeReplicateWithoutLock(pNode);
ASSERT(pEntry->index == pBuf->matchIndex); if (pEntry->index != pBuf->matchIndex) {
sError("vgId:%d, failed to proceed, pEntry->index:%" PRId64 ", pBuf->matchIndex:%" PRId64, pNode->vgId,
pEntry->index, pBuf->matchIndex);
code = TSDB_CODE_SYN_INTERNAL_ERROR;
goto _out;
}
// update my match index // update my match index
matchIndex = pBuf->matchIndex; matchIndex = pBuf->matchIndex;
@ -579,8 +650,8 @@ _out:
if (pMatchTerm) { if (pMatchTerm) {
*pMatchTerm = pBuf->entries[(matchIndex + pBuf->size) % pBuf->size].pItem->term; *pMatchTerm = pBuf->entries[(matchIndex + pBuf->size) % pBuf->size].pItem->term;
} }
(void)syncLogBufferValidate(pBuf);
(void)taosThreadMutexUnlock(&pBuf->mutex); (void)taosThreadMutexUnlock(&pBuf->mutex);
TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
return matchIndex; return matchIndex;
} }
@ -643,17 +714,36 @@ _exit:
} }
int32_t syncLogBufferValidate(SSyncLogBuffer* pBuf) { int32_t syncLogBufferValidate(SSyncLogBuffer* pBuf) {
ASSERT(pBuf->startIndex <= pBuf->matchIndex); if (pBuf->startIndex > pBuf->matchIndex) {
ASSERT(pBuf->commitIndex <= pBuf->matchIndex); sError("failed to validate, pBuf->startIndex:%" PRId64 ", pBuf->matchIndex:%" PRId64, pBuf->startIndex,
ASSERT(pBuf->matchIndex < pBuf->endIndex); pBuf->matchIndex);
ASSERT(pBuf->endIndex - pBuf->startIndex <= pBuf->size); return TSDB_CODE_SYN_INTERNAL_ERROR;
ASSERT(pBuf->entries[(pBuf->matchIndex + pBuf->size) % pBuf->size].pItem); }
if (pBuf->commitIndex > pBuf->matchIndex) {
sError("failed to validate, pBuf->commitIndex:%" PRId64 ", pBuf->matchIndex:%" PRId64, pBuf->commitIndex,
pBuf->matchIndex);
return TSDB_CODE_SYN_INTERNAL_ERROR;
}
if (pBuf->matchIndex >= pBuf->endIndex) {
sError("failed to validate, pBuf->matchIndex:%" PRId64 ", pBuf->endIndex:%" PRId64, pBuf->matchIndex,
pBuf->endIndex);
return TSDB_CODE_SYN_INTERNAL_ERROR;
}
if (pBuf->endIndex - pBuf->startIndex > pBuf->size) {
sError("failed to validate, pBuf->endIndex:%" PRId64 ", pBuf->startIndex:%" PRId64 ", pBuf->size:%" PRId64,
pBuf->endIndex, pBuf->startIndex, pBuf->size);
return TSDB_CODE_SYN_INTERNAL_ERROR;
}
if (pBuf->entries[(pBuf->matchIndex + pBuf->size) % pBuf->size].pItem == NULL) {
sError("failed to validate since pItem is null");
return TSDB_CODE_SYN_INTERNAL_ERROR;
}
return 0; return 0;
} }
int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t commitIndex) { int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t commitIndex) {
TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
(void)taosThreadMutexLock(&pBuf->mutex); (void)taosThreadMutexLock(&pBuf->mutex);
(void)syncLogBufferValidate(pBuf);
SSyncLogStore* pLogStore = pNode->pLogStore; SSyncLogStore* pLogStore = pNode->pLogStore;
SSyncFSM* pFsm = pNode->pFsm; SSyncFSM* pFsm = pNode->pFsm;
@ -778,15 +868,18 @@ _out:
syncEntryDestroy(pNextEntry); syncEntryDestroy(pNextEntry);
pNextEntry = NULL; pNextEntry = NULL;
} }
(void)syncLogBufferValidate(pBuf);
(void)taosThreadMutexUnlock(&pBuf->mutex); (void)taosThreadMutexUnlock(&pBuf->mutex);
TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
void syncLogReplReset(SSyncLogReplMgr* pMgr) { void syncLogReplReset(SSyncLogReplMgr* pMgr) {
if (pMgr == NULL) return; if (pMgr == NULL) return;
ASSERT(pMgr->startIndex >= 0); if (pMgr->startIndex < 0) {
sError("failed to reset, pMgr->startIndex:%" PRId64, pMgr->startIndex);
return;
}
for (SyncIndex index = pMgr->startIndex; index < pMgr->endIndex; index++) { for (SyncIndex index = pMgr->startIndex; index < pMgr->endIndex; index++) {
(void)memset(&pMgr->states[index % pMgr->size], 0, sizeof(pMgr->states[0])); (void)memset(&pMgr->states[index % pMgr->size], 0, sizeof(pMgr->states[0]));
} }
@ -1285,13 +1378,13 @@ int32_t syncLogBufferRollback(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncIndex
} }
if (pBuf->endIndex != toIndex) return TSDB_CODE_SYN_INTERNAL_ERROR; if (pBuf->endIndex != toIndex) return TSDB_CODE_SYN_INTERNAL_ERROR;
(void)syncLogBufferValidate(pBuf); TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
return 0; return 0;
} }
int32_t syncLogBufferReset(SSyncLogBuffer* pBuf, SSyncNode* pNode) { int32_t syncLogBufferReset(SSyncLogBuffer* pBuf, SSyncNode* pNode) {
TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
(void)taosThreadMutexLock(&pBuf->mutex); (void)taosThreadMutexLock(&pBuf->mutex);
(void)syncLogBufferValidate(pBuf);
SyncIndex lastVer = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore); SyncIndex lastVer = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
if (lastVer != pBuf->matchIndex) return TSDB_CODE_SYN_INTERNAL_ERROR; if (lastVer != pBuf->matchIndex) return TSDB_CODE_SYN_INTERNAL_ERROR;
SyncIndex index = pBuf->endIndex - 1; SyncIndex index = pBuf->endIndex - 1;
@ -1308,8 +1401,8 @@ int32_t syncLogBufferReset(SSyncLogBuffer* pBuf, SSyncNode* pNode) {
SSyncLogReplMgr* pMgr = pNode->logReplMgrs[i]; SSyncLogReplMgr* pMgr = pNode->logReplMgrs[i];
syncLogReplReset(pMgr); syncLogReplReset(pMgr);
} }
(void)syncLogBufferValidate(pBuf);
(void)taosThreadMutexUnlock(&pBuf->mutex); (void)taosThreadMutexUnlock(&pBuf->mutex);
TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf));
return 0; return 0;
} }

View File

@ -240,6 +240,7 @@ typedef struct {
void* pThrd; void* pThrd;
queue qmsg; queue qmsg;
TdThreadMutex mtx; // protect qmsg; TdThreadMutex mtx; // protect qmsg;
int64_t num;
} SAsyncItem; } SAsyncItem;
typedef struct { typedef struct {

View File

@ -30,6 +30,8 @@ static int32_t FAST_FAILURE_LIMIT = 1;
static int64_t httpDefaultChanId = -1; static int64_t httpDefaultChanId = -1;
static int64_t httpSeqNum = 0;
typedef struct SHttpModule { typedef struct SHttpModule {
uv_loop_t* loop; uv_loop_t* loop;
SAsyncPool* asyncPool; SAsyncPool* asyncPool;
@ -50,6 +52,7 @@ typedef struct SHttpMsg {
EHttpCompFlag flag; EHttpCompFlag flag;
int8_t quit; int8_t quit;
int64_t chanId; int64_t chanId;
int64_t seq;
} SHttpMsg; } SHttpMsg;
typedef struct SHttpClient { typedef struct SHttpClient {
@ -62,6 +65,7 @@ typedef struct SHttpClient {
uint16_t port; uint16_t port;
struct sockaddr_in dest; struct sockaddr_in dest;
int64_t chanId; int64_t chanId;
int64_t seq;
} SHttpClient; } SHttpClient;
typedef struct SHttpConnList { typedef struct SHttpConnList {
@ -193,14 +197,14 @@ static FORCE_INLINE int32_t taosBuildDstAddr(const char* server, uint16_t port,
uint32_t ip = 0; uint32_t ip = 0;
int32_t code = taosGetIpv4FromFqdn(server, &ip); int32_t code = taosGetIpv4FromFqdn(server, &ip);
if (code) { if (code) {
tError("http-report failed to resolving domain names: %s", server); tError("http-report failed to resolving domain names %s, reason: %s", server, tstrerror(code));
return TSDB_CODE_RPC_FQDN_ERROR; return TSDB_CODE_RPC_FQDN_ERROR;
} }
char buf[256] = {0}; char buf[256] = {0};
tinet_ntoa(buf, ip); tinet_ntoa(buf, ip);
int ret = uv_ip4_addr(buf, port, dest); int ret = uv_ip4_addr(buf, port, dest);
if (ret != 0) { if (ret != 0) {
tError("http-report failed to get addr %s", uv_err_name(ret)); tError("http-report failed to get addr, reason:%s", uv_err_name(ret));
return TSDB_CODE_THIRDPARTY_ERROR; return TSDB_CODE_THIRDPARTY_ERROR;
} }
return 0; return 0;
@ -215,14 +219,15 @@ static void* httpThread(void* arg) {
static int32_t httpCreateMsg(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, static int32_t httpCreateMsg(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen,
EHttpCompFlag flag, int64_t chanId, SHttpMsg** httpMsg) { EHttpCompFlag flag, int64_t chanId, SHttpMsg** httpMsg) {
int64_t seqNum = atomic_fetch_add_64(&httpSeqNum, 1);
if (server == NULL || uri == NULL) { if (server == NULL || uri == NULL) {
tError("http-report failed to report to invalid addr, chanId:%" PRId64 "", chanId); tError("http-report failed to report to invalid addr, chanId:%" PRId64 ", seq:%" PRId64 "", chanId, seqNum);
*httpMsg = NULL; *httpMsg = NULL;
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;
} }
if (pCont == NULL || contLen == 0) { if (pCont == NULL || contLen == 0) {
tError("http-report failed to report empty packet, chanId:%" PRId64 "", chanId); tError("http-report failed to report empty packet, chanId:%" PRId64 ", seq:%" PRId64 "", chanId, seqNum);
*httpMsg = NULL; *httpMsg = NULL;
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;
} }
@ -233,6 +238,7 @@ static int32_t httpCreateMsg(const char* server, const char* uri, uint16_t port,
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
msg->seq = seqNum;
msg->port = port; msg->port = port;
msg->server = taosStrdup(server); msg->server = taosStrdup(server);
msg->uri = taosStrdup(uri); msg->uri = taosStrdup(uri);
@ -259,7 +265,11 @@ static void httpDestroyMsg(SHttpMsg* msg) {
taosMemoryFree(msg->cont); taosMemoryFree(msg->cont);
taosMemoryFree(msg); taosMemoryFree(msg);
} }
static void httpDestroyMsgWrapper(void* cont, void* param) { httpDestroyMsg((SHttpMsg*)cont); } static void httpDestroyMsgWrapper(void* cont, void* param) {
SHttpMsg* pMsg = cont;
tWarn("http-report destroy msg, chanId:%" PRId64 ", seq:%" PRId64 "", pMsg->chanId, pMsg->seq);
httpDestroyMsg(pMsg);
}
static void httpMayDiscardMsg(SHttpModule* http, SAsyncItem* item) { static void httpMayDiscardMsg(SHttpModule* http, SAsyncItem* item) {
SHttpMsg *msg = NULL, *quitMsg = NULL; SHttpMsg *msg = NULL, *quitMsg = NULL;
@ -272,6 +282,8 @@ static void httpMayDiscardMsg(SHttpModule* http, SAsyncItem* item) {
QUEUE_REMOVE(h); QUEUE_REMOVE(h);
msg = QUEUE_DATA(h, SHttpMsg, q); msg = QUEUE_DATA(h, SHttpMsg, q);
if (!msg->quit) { if (!msg->quit) {
tError("http-report failed to report chanId:%" PRId64 ",seq:%" PRId64 ", reason: %s", msg->chanId, msg->seq,
tstrerror(TSDB_CODE_HTTP_MODULE_QUIT));
httpDestroyMsg(msg); httpDestroyMsg(msg);
} else { } else {
quitMsg = msg; quitMsg = msg;
@ -281,6 +293,25 @@ static void httpMayDiscardMsg(SHttpModule* http, SAsyncItem* item) {
QUEUE_PUSH(&item->qmsg, &quitMsg->q); QUEUE_PUSH(&item->qmsg, &quitMsg->q);
} }
} }
static void httpTrace(queue* q) {
if (!(rpcDebugFlag & DEBUG_DEBUG) || (QUEUE_IS_EMPTY(q))) {
return;
}
int64_t startSeq = 0, endSeq = 0;
SHttpMsg* msg = NULL;
queue* h = QUEUE_HEAD(q);
msg = QUEUE_DATA(h, SHttpMsg, q);
startSeq = msg->seq;
h = QUEUE_TAIL(q);
msg = QUEUE_DATA(h, SHttpMsg, q);
endSeq = msg->seq;
tDebug("http-report process msg, start_seq:%" PRId64 ", end_seq:%" PRId64 ", max_seq:%" PRId64 "", startSeq, endSeq,
atomic_load_64(&httpSeqNum) - 1);
}
static void httpAsyncCb(uv_async_t* handle) { static void httpAsyncCb(uv_async_t* handle) {
SAsyncItem* item = handle->data; SAsyncItem* item = handle->data;
@ -290,7 +321,7 @@ static void httpAsyncCb(uv_async_t* handle) {
queue wq; queue wq;
QUEUE_INIT(&wq); QUEUE_INIT(&wq);
static int32_t BATCH_SIZE = 5; static int32_t BATCH_SIZE = 20;
int32_t count = 0; int32_t count = 0;
(void)taosThreadMutexLock(&item->mtx); (void)taosThreadMutexLock(&item->mtx);
@ -303,6 +334,8 @@ static void httpAsyncCb(uv_async_t* handle) {
} }
(void)taosThreadMutexUnlock(&item->mtx); (void)taosThreadMutexUnlock(&item->mtx);
httpTrace(&wq);
while (!QUEUE_IS_EMPTY(&wq)) { while (!QUEUE_IS_EMPTY(&wq)) {
queue* h = QUEUE_HEAD(&wq); queue* h = QUEUE_HEAD(&wq);
QUEUE_REMOVE(h); QUEUE_REMOVE(h);
@ -345,47 +378,50 @@ static FORCE_INLINE void clientAllocBuffCb(uv_handle_t* handle, size_t suggested
} }
static FORCE_INLINE void clientRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { static FORCE_INLINE void clientRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
STUB_RAND_NETWORK_ERR(nread);
SHttpClient* cli = handle->data; SHttpClient* cli = handle->data;
if (nread < 0) { if (nread < 0) {
tError("http-report recv error:%s", uv_strerror(nread)); tError("http-report recv error:%s, seq:%" PRId64 "", uv_strerror(nread), cli->seq);
} else { } else {
tTrace("http-report succ to recv %d bytes", (int32_t)nread); tTrace("http-report succ to recv %d bytes, seq:%" PRId64 "", (int32_t)nread, cli->seq);
} }
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
} }
} }
static void clientSentCb(uv_write_t* req, int32_t status) { static void clientSentCb(uv_write_t* req, int32_t status) {
STUB_RAND_NETWORK_ERR(status);
SHttpClient* cli = req->data; SHttpClient* cli = req->data;
if (status != 0) { if (status != 0) {
tError("http-report failed to send data, reason: %s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status), cli->addr, tError("http-report failed to send data, reason: %s, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 "",
cli->port, cli->chanId); uv_strerror(status), cli->addr, cli->port, cli->chanId, cli->seq);
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
} }
return; return;
} else { } else {
tTrace("http-report succ to send data, chanId:%" PRId64 "", cli->chanId); tTrace("http-report succ to send data, chanId:%" PRId64 ", seq:%" PRId64 "", cli->chanId, cli->seq);
} }
status = uv_read_start((uv_stream_t*)&cli->tcp, clientAllocBuffCb, clientRecvCb); status = uv_read_start((uv_stream_t*)&cli->tcp, clientAllocBuffCb, clientRecvCb);
if (status != 0) { if (status != 0) {
tError("http-report failed to recv data,reason:%s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status), cli->addr, tError("http-report failed to recv data,reason:%s, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 "",
cli->port, cli->chanId); uv_strerror(status), cli->addr, cli->port, cli->chanId, cli->seq);
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
} }
} }
} }
static void clientConnCb(uv_connect_t* req, int32_t status) { static void clientConnCb(uv_connect_t* req, int32_t status) {
STUB_RAND_NETWORK_ERR(status);
SHttpClient* cli = req->data; SHttpClient* cli = req->data;
int64_t chanId = cli->chanId; int64_t chanId = cli->chanId;
SHttpModule* http = taosAcquireRef(httpRefMgt, chanId); SHttpModule* http = taosAcquireRef(httpRefMgt, chanId);
if (status != 0) { if (status != 0) {
httpFailFastMayUpdate(http->connStatusTable, cli->addr, cli->port, 0); httpFailFastMayUpdate(http->connStatusTable, cli->addr, cli->port, 0);
tError("http-report failed to conn to server, reason:%s, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 "",
tError("http-report failed to conn to server, reason:%s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status), uv_strerror(status), cli->addr, cli->port, chanId, cli->seq);
cli->addr, cli->port, chanId);
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
} }
@ -398,8 +434,8 @@ static void clientConnCb(uv_connect_t* req, int32_t status) {
status = uv_write(&cli->req, (uv_stream_t*)&cli->tcp, cli->wbuf, 2, clientSentCb); status = uv_write(&cli->req, (uv_stream_t*)&cli->tcp, cli->wbuf, 2, clientSentCb);
if (0 != status) { if (0 != status) {
tError("http-report failed to send data,reason:%s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status), cli->addr, tError("http-report failed to send data,reason:%s, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 "",
cli->port, chanId); uv_strerror(status), cli->addr, cli->port, chanId, cli->seq);
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
} }
@ -412,7 +448,7 @@ int32_t httpSendQuit(SHttpModule* http, int64_t chanId) {
if (msg == NULL) { if (msg == NULL) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
msg->seq = atomic_fetch_add_64(&httpSeqNum, 1);
msg->quit = 1; msg->quit = 1;
msg->chanId = chanId; msg->chanId = chanId;
@ -442,10 +478,11 @@ static void httpWalkCb(uv_handle_t* handle, void* arg) {
return; return;
} }
static void httpHandleQuit(SHttpMsg* msg) { static void httpHandleQuit(SHttpMsg* msg) {
int64_t seq = msg->seq;
int64_t chanId = msg->chanId; int64_t chanId = msg->chanId;
taosMemoryFree(msg); taosMemoryFree(msg);
tDebug("http-report receive quit, chanId:%" PRId64 "", chanId); tDebug("http-report receive quit, chanId:%" PRId64 ", seq:%" PRId64 "", chanId, seq);
SHttpModule* http = taosAcquireRef(httpRefMgt, chanId); SHttpModule* http = taosAcquireRef(httpRefMgt, chanId);
if (http == NULL) return; if (http == NULL) return;
uv_walk(http->loop, httpWalkCb, NULL); uv_walk(http->loop, httpWalkCb, NULL);
@ -542,7 +579,7 @@ static void httpHandleReq(SHttpMsg* msg) {
code = TSDB_CODE_OUT_OF_MEMORY; code = TSDB_CODE_OUT_OF_MEMORY;
goto END; goto END;
} }
cli->seq = msg->seq;
cli->conn.data = cli; cli->conn.data = cli;
cli->tcp.data = cli; cli->tcp.data = cli;
cli->req.data = cli; cli->req.data = cli;
@ -556,8 +593,8 @@ static void httpHandleReq(SHttpMsg* msg) {
cli->wbuf = wb; cli->wbuf = wb;
cli->rbuf = taosMemoryCalloc(1, HTTP_RECV_BUF_SIZE); cli->rbuf = taosMemoryCalloc(1, HTTP_RECV_BUF_SIZE);
if (cli->rbuf == NULL) { if (cli->rbuf == NULL) {
tError("http-report failed to alloc read buf, dst:%s:%d,chanId:%" PRId64 ", reason:%s", cli->addr, cli->port, tError("http-report failed to alloc read buf, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 ",reason:%s", cli->addr,
chanId, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); cli->port, chanId, cli->seq, tstrerror(TSDB_CODE_OUT_OF_MEMORY));
destroyHttpClient(cli); destroyHttpClient(cli);
(void)taosReleaseRef(httpRefMgt, chanId); (void)taosReleaseRef(httpRefMgt, chanId);
return; return;
@ -565,8 +602,8 @@ static void httpHandleReq(SHttpMsg* msg) {
int err = uv_tcp_init(http->loop, &cli->tcp); int err = uv_tcp_init(http->loop, &cli->tcp);
if (err != 0) { if (err != 0) {
tError("http-report failed to init socket handle, dst:%s:%d,chanId:%" PRId64 ", reason:%s", cli->addr, cli->port, tError("http-report failed to init socket handle, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 ", reason:%s",
chanId, uv_strerror(err)); cli->addr, cli->port, chanId, cli->seq, uv_strerror(err));
destroyHttpClient(cli); destroyHttpClient(cli);
(void)taosReleaseRef(httpRefMgt, chanId); (void)taosReleaseRef(httpRefMgt, chanId);
return; return;
@ -575,8 +612,8 @@ static void httpHandleReq(SHttpMsg* msg) {
// set up timeout to avoid stuck; // set up timeout to avoid stuck;
int32_t fd = taosCreateSocketWithTimeout(5000); int32_t fd = taosCreateSocketWithTimeout(5000);
if (fd < 0) { if (fd < 0) {
tError("http-report failed to open socket, dst:%s:%d, chanId:%" PRId64 ", reason:%s", cli->addr, cli->port, chanId, tError("http-report failed to open socket, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 ", reason:%s", cli->addr,
tstrerror(TAOS_SYSTEM_ERROR(errno))); cli->port, chanId, cli->seq, tstrerror(TAOS_SYSTEM_ERROR(errno)));
destroyHttpClient(cli); destroyHttpClient(cli);
(void)taosReleaseRef(httpRefMgt, chanId); (void)taosReleaseRef(httpRefMgt, chanId);
return; return;
@ -584,8 +621,9 @@ static void httpHandleReq(SHttpMsg* msg) {
int ret = uv_tcp_open((uv_tcp_t*)&cli->tcp, fd); int ret = uv_tcp_open((uv_tcp_t*)&cli->tcp, fd);
if (ret != 0) { if (ret != 0) {
tError("http-report failed to open socket, reason:%s, dst:%s:%d, chanId:%" PRId64 ",reason:%s", uv_strerror(ret), tError("http-report failed to open socket, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 ", reason:%s", cli->addr,
cli->addr, cli->port, chanId, uv_strerror(ret)); cli->port, chanId, cli->seq, uv_strerror(ret));
destroyHttpClient(cli); destroyHttpClient(cli);
(void)taosReleaseRef(httpRefMgt, chanId); (void)taosReleaseRef(httpRefMgt, chanId);
return; return;
@ -593,8 +631,8 @@ static void httpHandleReq(SHttpMsg* msg) {
ret = uv_tcp_connect(&cli->conn, &cli->tcp, (const struct sockaddr*)&cli->dest, clientConnCb); ret = uv_tcp_connect(&cli->conn, &cli->tcp, (const struct sockaddr*)&cli->dest, clientConnCb);
if (ret != 0) { if (ret != 0) {
tError("http-report failed to connect to http-server,dst:%s:%d, chanId:%" PRId64 ",reson:%s", cli->addr, cli->port, tError("http-report failed to connect to http-server,dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 ", reson:%s",
chanId, uv_strerror(ret)); cli->addr, cli->port, chanId, cli->seq, uv_strerror(ret));
httpFailFastMayUpdate(http->connStatusTable, cli->addr, cli->port, 0); httpFailFastMayUpdate(http->connStatusTable, cli->addr, cli->port, 0);
destroyHttpClient(cli); destroyHttpClient(cli);
} }
@ -603,8 +641,8 @@ static void httpHandleReq(SHttpMsg* msg) {
END: END:
if (ignore == false) { if (ignore == false) {
tError("http-report failed to report to addr: %s:%d, chanId:%" PRId64 ", reason:%s", msg->server, msg->port, chanId, tError("http-report failed to report to addr: %s:%d, chanId:%" PRId64 ",seq:%" PRId64 " reason:%s", msg->server,
tstrerror(code)); msg->port, chanId, msg->seq, tstrerror(code));
} }
httpDestroyMsg(msg); httpDestroyMsg(msg);
taosMemoryFree(header); taosMemoryFree(header);
@ -652,6 +690,7 @@ static int32_t taosSendHttpReportImplByChan(const char* server, const char* uri,
code = TSDB_CODE_HTTP_MODULE_QUIT; code = TSDB_CODE_HTTP_MODULE_QUIT;
goto _ERROR; goto _ERROR;
} }
tDebug("http-report start to report, chanId:%" PRId64 ", seq:%" PRId64 "", chanId, msg->seq);
code = transAsyncSend(load->asyncPool, &(msg->q)); code = transAsyncSend(load->asyncPool, &(msg->q));
if (code != 0) { if (code != 0) {
@ -661,6 +700,11 @@ static int32_t taosSendHttpReportImplByChan(const char* server, const char* uri,
msg = NULL; msg = NULL;
_ERROR: _ERROR:
if (code != 0) {
tError("http-report failed to report reason:%s, chanId:%" PRId64 ", seq:%" PRId64 "", tstrerror(code), chanId,
msg->seq);
}
httpDestroyMsg(msg); httpDestroyMsg(msg);
if (load != NULL) taosReleaseRef(httpRefMgt, chanId); if (load != NULL) taosReleaseRef(httpRefMgt, chanId);
return code; return code;
@ -684,6 +728,7 @@ int64_t transInitHttpChanImpl();
static void transHttpEnvInit() { static void transHttpEnvInit() {
httpRefMgt = taosOpenRef(64, transHttpDestroyHandle); httpRefMgt = taosOpenRef(64, transHttpDestroyHandle);
httpDefaultChanId = transInitHttpChanImpl(); httpDefaultChanId = transInitHttpChanImpl();
httpSeqNum = 0;
} }
void transHttpEnvDestroy() { void transHttpEnvDestroy() {
@ -748,7 +793,7 @@ int64_t taosInitHttpChan() {
} }
void taosDestroyHttpChan(int64_t chanId) { void taosDestroyHttpChan(int64_t chanId) {
tDebug("http-report send quit, chanId:%" PRId64 "", chanId); tDebug("http-report send quit, chanId: %" PRId64 "", chanId);
int ret = 0; int ret = 0;
SHttpModule* load = taosAcquireRef(httpRefMgt, chanId); SHttpModule* load = taosAcquireRef(httpRefMgt, chanId);
@ -772,4 +817,4 @@ void taosDestroyHttpChan(int64_t chanId) {
(void)taosReleaseRef(httpRefMgt, chanId); (void)taosReleaseRef(httpRefMgt, chanId);
(void)taosRemoveRef(httpRefMgt, chanId); (void)taosRemoveRef(httpRefMgt, chanId);
} }

View File

@ -923,10 +923,12 @@ static void cliAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_
} }
} }
static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
// impl later STUB_RAND_NETWORK_ERR(nread);
if (handle->data == NULL) { if (handle->data == NULL) {
return; return;
} }
SCliConn* conn = handle->data; SCliConn* conn = handle->data;
SConnBuffer* pBuf = &conn->readBuf; SConnBuffer* pBuf = &conn->readBuf;
if (nread > 0) { if (nread > 0) {
@ -1117,6 +1119,8 @@ static bool cliHandleNoResp(SCliConn* conn) {
return res; return res;
} }
static void cliSendCb(uv_write_t* req, int status) { static void cliSendCb(uv_write_t* req, int status) {
STUB_RAND_NETWORK_ERR(status);
SCliConn* pConn = transReqQueueRemove(req); SCliConn* pConn = transReqQueueRemove(req);
if (pConn == NULL) return; if (pConn == NULL) return;
@ -1434,6 +1438,7 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) {
cliSendBatch(conn); cliSendBatch(conn);
} }
static void cliSendBatchCb(uv_write_t* req, int status) { static void cliSendBatchCb(uv_write_t* req, int status) {
STUB_RAND_NETWORK_ERR(status);
SCliConn* conn = req->data; SCliConn* conn = req->data;
SCliThrd* thrd = conn->hostThrd; SCliThrd* thrd = conn->hostThrd;
SCliBatch* p = conn->pBatch; SCliBatch* p = conn->pBatch;
@ -1523,6 +1528,8 @@ void cliConnCb(uv_connect_t* req, int status) {
pConn->timer = NULL; pConn->timer = NULL;
} }
STUB_RAND_NETWORK_ERR(status);
if (status != 0) { if (status != 0) {
cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, pConn->dstAddr); cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, pConn->dstAddr);
if (timeout == false) { if (timeout == false) {
@ -2193,7 +2200,6 @@ bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) {
for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->cliMsgs); i++) { for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->cliMsgs); i++) {
SCliMsg* cliMsg = transQueueGet(&conn->cliMsgs, i); SCliMsg* cliMsg = transQueueGet(&conn->cliMsgs, i);
if (cliMsg->type == Release) { if (cliMsg->type == Release) {
ASSERTS(pMsg == NULL, "trans-cli recv invaid release-req");
tDebug("%s conn %p receive release request, refId:%" PRId64 ", ignore msg", CONN_GET_INST_LABEL(conn), conn, tDebug("%s conn %p receive release request, refId:%" PRId64 ", ignore msg", CONN_GET_INST_LABEL(conn), conn,
conn->refId); conn->refId);
cliDestroyConn(conn, true); cliDestroyConn(conn, true);
@ -3015,7 +3021,6 @@ _exception:
} }
int32_t transSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) { int32_t transSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) {
if (transpointId == NULL) { if (transpointId == NULL) {
ASSERT(0);
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;
} }
int32_t code = 0; int32_t code = 0;

View File

@ -183,7 +183,7 @@ int32_t transResetBuffer(SConnBuffer* connBuf, int8_t resetBuf) {
} }
} }
} else { } else {
ASSERTS(0, "invalid read from sock buf"); tError("failed to reset buffer, total:%d, len:%d, reason:%s", p->total, p->len, tstrerror(TSDB_CODE_INVALID_MSG));
return TSDB_CODE_INVALID_MSG; return TSDB_CODE_INVALID_MSG;
} }
return 0; return 0;
@ -869,3 +869,8 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pList, char** ppBuf) {
*ppBuf = pBuf; *ppBuf = pBuf;
return len; return len;
} }
// int32_t transGenRandomError(int32_t status) {
// STUB_RAND_NETWORK_ERR(status)
// return status;
// }

View File

@ -468,8 +468,8 @@ static bool uvHandleReq(SSvrConn* pConn) {
tGTrace("%s handle %p conn:%p translated to app, refId:%" PRIu64, transLabel(pTransInst), transMsg.info.handle, pConn, tGTrace("%s handle %p conn:%p translated to app, refId:%" PRIu64, transLabel(pTransInst), transMsg.info.handle, pConn,
pConn->refId); pConn->refId);
ASSERTS(transMsg.info.handle != NULL, "trans-svr failed to alloc handle to msg");
if (transMsg.info.handle == NULL) { if (transMsg.info.handle == NULL) {
tError("%s handle %p conn:%p handle failed to init" PRIu64, transLabel(pTransInst), transMsg.info.handle, pConn);
return false; return false;
} }
@ -493,6 +493,8 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) {
SSvrConn* conn = cli->data; SSvrConn* conn = cli->data;
SWorkThrd* pThrd = conn->hostThrd; SWorkThrd* pThrd = conn->hostThrd;
STUB_RAND_NETWORK_ERR(nread);
if (true == pThrd->quit) { if (true == pThrd->quit) {
tInfo("work thread received quit msg, destroy conn"); tInfo("work thread received quit msg, destroy conn");
destroyConn(conn, true); destroyConn(conn, true);
@ -553,6 +555,7 @@ void uvOnTimeoutCb(uv_timer_t* handle) {
} }
void uvOnSendCb(uv_write_t* req, int status) { void uvOnSendCb(uv_write_t* req, int status) {
STUB_RAND_NETWORK_ERR(status);
SSvrConn* conn = transReqQueueRemove(req); SSvrConn* conn = transReqQueueRemove(req);
if (conn == NULL) return; if (conn == NULL) return;
@ -602,6 +605,7 @@ void uvOnSendCb(uv_write_t* req, int status) {
} }
} }
static void uvOnPipeWriteCb(uv_write_t* req, int status) { static void uvOnPipeWriteCb(uv_write_t* req, int status) {
STUB_RAND_NETWORK_ERR(status);
if (status == 0) { if (status == 0) {
tTrace("success to dispatch conn to work thread"); tTrace("success to dispatch conn to work thread");
} else { } else {
@ -949,6 +953,7 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) {
} }
} }
void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) {
STUB_RAND_NETWORK_ERR(nread);
if (nread < 0) { if (nread < 0) {
if (nread != UV_EOF) { if (nread != UV_EOF) {
tError("read error %s", uv_err_name(nread)); tError("read error %s", uv_err_name(nread));
@ -960,15 +965,19 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) {
return; return;
} }
// free memory allocated by // free memory allocated by
ASSERTS(nread == strlen(notify), "trans-svr mem corrupted"); if (nread != strlen(notify) || strncmp(buf->base, notify, strlen(notify)) != 0) {
ASSERTS(buf->base[0] == notify[0], "trans-svr mem corrupted"); tError("failed to read pip ");
taosMemoryFree(buf->base);
uv_close((uv_handle_t*)q, NULL);
}
taosMemoryFree(buf->base); taosMemoryFree(buf->base);
SWorkThrd* pThrd = q->data; SWorkThrd* pThrd = q->data;
uv_pipe_t* pipe = (uv_pipe_t*)q; uv_pipe_t* pipe = (uv_pipe_t*)q;
if (!uv_pipe_pending_count(pipe)) { if (!uv_pipe_pending_count(pipe)) {
tError("No pending count"); tError("no pending count, unexpected error");
uv_close((uv_handle_t*)q, NULL); uv_close((uv_handle_t*)q, NULL);
return; return;
} }
@ -1041,9 +1050,11 @@ void* transAcceptThread(void* arg) {
return NULL; return NULL;
} }
void uvOnPipeConnectionCb(uv_connect_t* connect, int status) { void uvOnPipeConnectionCb(uv_connect_t* connect, int status) {
STUB_RAND_NETWORK_ERR(status);
if (status != 0) { if (status != 0) {
return; return;
} };
SWorkThrd* pThrd = container_of(connect, SWorkThrd, connect_req); SWorkThrd* pThrd = container_of(connect, SWorkThrd, connect_req);
(void)uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb); (void)uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb);
} }
@ -1344,25 +1355,32 @@ static void uvPipeListenCb(uv_stream_t* handle, int status) {
uv_pipe_t* pipe = &(srv->pipe[srv->numOfWorkerReady][0]); uv_pipe_t* pipe = &(srv->pipe[srv->numOfWorkerReady][0]);
int ret = uv_pipe_init(srv->loop, pipe, 1); int ret = uv_pipe_init(srv->loop, pipe, 1);
ASSERTS(ret == 0, "trans-svr failed to init pipe"); if (ret != 0) {
if (ret != 0) return; tError("trans-svr failed to init pipe, errmsg: %s", uv_err_name(ret));
}
ret = uv_accept((uv_stream_t*)&srv->pipeListen, (uv_stream_t*)pipe); ret = uv_accept((uv_stream_t*)&srv->pipeListen, (uv_stream_t*)pipe);
ASSERTS(ret == 0, "trans-svr failed to accept pipe msg"); if (ret != 0) {
if (ret != 0) return; tError("trans-svr failed to accept pipe, errmsg: %s", uv_err_name(ret));
return;
}
ret = uv_is_readable((uv_stream_t*)pipe); ret = uv_is_readable((uv_stream_t*)pipe);
ASSERTS(ret == 1, "trans-svr pipe status corrupted"); if (ret != 1) {
if (ret != 1) return; tError("trans-svr failed to check pipe, pip not readable");
return;
}
ret = uv_is_writable((uv_stream_t*)pipe); ret = uv_is_writable((uv_stream_t*)pipe);
ASSERTS(ret == 1, "trans-svr pipe status corrupted"); if (ret != 1) {
if (ret != 1) return; tError("trans-svr failed to check pipe, pip not writable");
return;
}
ret = uv_is_closing((uv_handle_t*)pipe); ret = uv_is_closing((uv_handle_t*)pipe);
ASSERTS(ret == 0, "trans-svr pipe status corrupted"); if (ret != 0) {
if (ret != 0) return; tError("trans-svr failed to check pipe, pip is closing");
return;
}
srv->numOfWorkerReady++; srv->numOfWorkerReady++;
} }

View File

@ -904,7 +904,7 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
int32_t code = _fstat64(pFile->fd, &fileStat); int32_t code = _fstat64(pFile->fd, &fileStat);
#else #else
struct stat fileStat; struct stat fileStat;
int32_t code = fstat(pFile->fd, &fileStat); int32_t code = fstat(pFile->fd, &fileStat);
#endif #endif
if (-1 == code) { if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
@ -1611,7 +1611,7 @@ int taosSeekCFile(FILE *file, int64_t offset, int whence) {
#ifdef WINDOWS #ifdef WINDOWS
return _fseeki64(file, offset, whence); return _fseeki64(file, offset, whence);
#else #else
int code = fseeko(file, offset, whence); int code = fseeko(file, offset, whence);
if (-1 == code) { if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
} }

View File

@ -24,7 +24,7 @@
int32_t tsRandErrChance = 1; int32_t tsRandErrChance = 1;
int64_t tsRandErrDivisor = 10001; int64_t tsRandErrDivisor = 10001;
int64_t tsRandErrScope = (RAND_ERR_MEMORY | RAND_ERR_FILE); int64_t tsRandErrScope = (RAND_ERR_MEMORY | RAND_ERR_FILE | RAND_ERR_NETWORK);
threadlocal bool tsEnableRandErr = 0; threadlocal bool tsEnableRandErr = 0;
#if defined(USE_TD_MEMORY) || defined(USE_ADDR2LINE) #if defined(USE_TD_MEMORY) || defined(USE_ADDR2LINE)
@ -385,7 +385,7 @@ char *taosStrdup(const char *ptr) {
} }
#endif #endif
return tstrdup(ptr); return tstrdup(ptr);
#endif #endif
} }

View File

@ -79,6 +79,7 @@ _error:
int32_t tBloomFilterPutHash(SBloomFilter* pBF, uint64_t hash1, uint64_t hash2) { int32_t tBloomFilterPutHash(SBloomFilter* pBF, uint64_t hash1, uint64_t hash2) {
if (tBloomFilterIsFull(pBF)) { if (tBloomFilterIsFull(pBF)) {
uError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_INVALID_PARA));
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
bool hasChange = false; bool hasChange = false;

View File

@ -389,6 +389,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_CHARSET, "charset not match")
TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_LOCALE, "locale not match") TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_LOCALE, "locale not match")
TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_TTL_CHG_ON_WR, "ttlChangeOnWrite not match") TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_TTL_CHG_ON_WR, "ttlChangeOnWrite not match")
TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_EN_WHITELIST, "enableWhiteList not match") TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_EN_WHITELIST, "enableWhiteList not match")
TAOS_DEFINE_ERROR(TSDB_CODE_MNODE_STOPPED, "Mnode stopped")
// vnode // vnode
TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_VGROUP_ID, "Vnode is closed or removed") TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_VGROUP_ID, "Vnode is closed or removed")

View File

@ -118,6 +118,8 @@ int32_t tScalableBfPut(SScalableBf* pSBf, const void* keyBuf, uint32_t len, int3
} }
SBloomFilter* pNormalBf = taosArrayGetP(pSBf->bfArray, size - 1); SBloomFilter* pNormalBf = taosArrayGetP(pSBf->bfArray, size - 1);
QUERY_CHECK_NULL(pNormalBf, code, lino, _end, TSDB_CODE_INTERNAL_ERROR);
if (tBloomFilterIsFull(pNormalBf)) { if (tBloomFilterIsFull(pNormalBf)) {
code = tScalableBfAddFilter(pSBf, pNormalBf->expectedEntries * pSBf->growth, code = tScalableBfAddFilter(pSBf, pNormalBf->expectedEntries * pSBf->growth,
pNormalBf->errorRate * DEFAULT_TIGHTENING_RATIO, &pNormalBf); pNormalBf->errorRate * DEFAULT_TIGHTENING_RATIO, &pNormalBf);

View File

@ -0,0 +1,192 @@
from frame.log import *
from frame.cases import *
from frame.sql import *
from frame.caseBase import *
from frame import *
from frame.eos import *
class TDTestCase(TBase):
"""Add test case to verify TD-30816 (last/last_row accuracy)
"""
def init(self, conn, logSql, replicaVar=1):
self.replicaVar = int(replicaVar)
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
def prepare_data(self):
tdSql.execute("create database db_td30816 cachemodel 'both';")
tdSql.execute("use db_td30816;")
# create regular table
tdSql.execute("create table rt_int (ts timestamp, c1 int primary key, c2 int);")
tdSql.execute("create table rt_str (ts timestamp, c1 varchar(16) primary key, c2 varchar(16));")
# create stable
tdSql.execute("create table st_pk_int (ts timestamp, c1 int primary key, c2 int) tags (t1 int);")
tdSql.execute("create table st_pk_str (ts timestamp, c1 varchar(16) primary key, c2 varchar(16)) tags (t1 int);")
# create child table
tdSql.execute("create table ct1 using st_pk_int tags(1);")
tdSql.execute("create table ct2 using st_pk_int tags(2);")
tdSql.execute("create table ct3 using st_pk_str tags(3);")
tdSql.execute("create table ct4 using st_pk_str tags(4);")
# insert data to regular table
tdSql.execute("insert into rt_int values ('2021-01-01 00:00:00', 1, NULL);")
tdSql.execute("insert into rt_int values ('2021-01-01 00:00:01', 2, 1);")
tdSql.execute("insert into rt_str values ('2021-01-01 00:00:00', 'a', NULL);")
tdSql.execute("insert into rt_str values ('2021-01-01 00:00:01', 'b', '1');")
# insert data to child table
tdSql.execute("insert into ct1 values ('2021-01-01 00:00:00', 1, 1);")
tdSql.execute("insert into ct1 values ('2021-01-01 00:00:01', 2, NULL);")
tdSql.execute("insert into ct2 values ('2021-01-01 00:00:00', 3, 3);")
tdSql.execute("insert into ct2 values ('2021-01-01 00:00:01', 4, NULL);")
tdSql.execute("insert into ct3 values ('2021-01-01 00:00:00', 'a', '1');")
tdSql.execute("insert into ct3 values ('2021-01-01 00:00:01', 'b', NULL);")
tdSql.execute("insert into ct4 values ('2021-01-01 00:00:00', 'c', '3');")
tdSql.execute("insert into ct4 values ('2021-01-01 00:00:01', 'd', NULL);")
def test_last_with_primarykey_int_ct(self):
tdSql.execute("use db_td30816;")
tdSql.query("select last(*) from st_pk_int;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:01')
tdSql.checkData(0, 1, 4)
tdSql.checkData(0, 2, 3)
tdSql.query("select last_row(*) from st_pk_int;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:01')
tdSql.checkData(0, 1, 4)
tdSql.checkData(0, 2, None)
# delete and insert data
tdSql.execute("delete from ct1 where ts='2021-01-01 00:00:01';")
tdSql.execute("delete from ct2 where ts='2021-01-01 00:00:01';")
tdSql.execute("insert into ct1 values ('2021-01-01 00:00:00', 0, 5);")
tdSql.execute("insert into ct2 values ('2021-01-01 00:00:00', -1, 6);")
tdSql.query("select last(*) from st_pk_int;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:00')
tdSql.checkData(0, 1, 3)
tdSql.checkData(0, 2, 3)
tdSql.query("select last_row(*) from st_pk_int;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:00')
tdSql.checkData(0, 1, 3)
tdSql.checkData(0, 2, 3)
tdLog.info("Finish test_last_with_primarykey_int_ct")
def test_last_with_primarykey_str_ct(self):
tdSql.execute("use db_td30816;")
tdSql.query("select last(*) from st_pk_str;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:01')
tdSql.checkData(0, 1, 'd')
tdSql.checkData(0, 2, '3')
tdSql.query("select last_row(*) from st_pk_str;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:01')
tdSql.checkData(0, 1, 'd')
tdSql.checkData(0, 2, None)
# delete and insert data
tdSql.execute("delete from ct3 where ts='2021-01-01 00:00:01';")
tdSql.execute("delete from ct4 where ts='2021-01-01 00:00:01';")
tdSql.execute("insert into ct3 values ('2021-01-01 00:00:00', '6', '5');")
tdSql.execute("insert into ct4 values ('2021-01-01 00:00:00', '7', '6');")
tdSql.query("select last(*) from st_pk_str;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:00')
tdSql.checkData(0, 1, 'c')
tdSql.checkData(0, 2, '3')
tdSql.query("select last_row(*) from st_pk_str;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:00')
tdSql.checkData(0, 1, 'c')
tdSql.checkData(0, 2, 3)
tdLog.info("Finish test_last_with_primarykey_str_ct")
def test_last_with_primarykey_int_rt(self):
tdSql.execute("use db_td30816;")
tdSql.query("select last(*) from rt_int;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:01')
tdSql.checkData(0, 1, 2)
tdSql.checkData(0, 2, 1)
tdSql.query("select last_row(*) from rt_int;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:01')
tdSql.checkData(0, 1, 2)
tdSql.checkData(0, 2, 1)
tdSql.execute("delete from rt_int where ts='2021-01-01 00:00:01';")
tdSql.execute("insert into rt_int values ('2021-01-01 00:00:00', 0, 5);")
tdSql.query("select last(*) from rt_int;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:00')
tdSql.checkData(0, 1, 1)
tdSql.checkData(0, 2, 5)
tdSql.query("select last_row(*) from rt_int;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:00')
tdSql.checkData(0, 1, 1)
tdSql.checkData(0, 2, None)
tdLog.info("Finish test_last_with_primarykey_int_rt")
def test_last_with_primarykey_str_rt(self):
tdSql.execute("use db_td30816;")
tdSql.query("select last(*) from rt_str;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:01')
tdSql.checkData(0, 1, 'b')
tdSql.checkData(0, 2, '1')
tdSql.query("select last_row(*) from rt_str;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:01')
tdSql.checkData(0, 1, 'b')
tdSql.checkData(0, 2, '1')
tdSql.execute("delete from rt_str where ts='2021-01-01 00:00:01';")
tdSql.execute("insert into rt_str values ('2021-01-01 00:00:00', '2', '5');")
tdSql.query("select last(*) from rt_str;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:00')
tdSql.checkData(0, 1, 'a')
tdSql.checkData(0, 2, '5')
tdSql.query("select last_row(*) from rt_str;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, '2021-01-01 00:00:00')
tdSql.checkData(0, 1, 'a')
tdSql.checkData(0, 2, None)
tdLog.info("Finish test_last_with_primarykey_str_rt")
def run(self):
self.prepare_data()
# regular table
self.test_last_with_primarykey_int_rt()
self.test_last_with_primarykey_str_rt()
# child tables
self.test_last_with_primarykey_int_ct()
self.test_last_with_primarykey_str_ct()
def stop(self):
tdSql.execute("drop database db_td30816;")
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())

View File

@ -38,6 +38,7 @@
,,y,army,./pytest.sh python3 ./test.py -f query/queryBugs.py -N 3 ,,y,army,./pytest.sh python3 ./test.py -f query/queryBugs.py -N 3
,,y,army,./pytest.sh python3 ./test.py -f tmq/tmqBugs.py -N 3 ,,y,army,./pytest.sh python3 ./test.py -f tmq/tmqBugs.py -N 3
,,y,army,./pytest.sh python3 ./test.py -f query/fill/fill_compare_asc_desc.py ,,y,army,./pytest.sh python3 ./test.py -f query/fill/fill_compare_asc_desc.py
,,y,army,./pytest.sh python3 ./test.py -f query/last/test_last.py
# #
# system test # system test
@ -310,7 +311,7 @@
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/balance_vgroups_r1.py -N 6 ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/balance_vgroups_r1.py -N 6
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/taosShell.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/taosShell.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/taosShellError.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/taosShellError.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/taosShellNetChk.py ,,n,system-test,python3 ./test.py -f 0-others/taosShellNetChk.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/telemetry.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/telemetry.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/backquote_check.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/backquote_check.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/taosdMonitor.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/taosdMonitor.py

View File

@ -49,6 +49,7 @@ fi
indirect_leak=$(cat ${LOG_DIR}/*.asan | grep "Indirect leak" | wc -l) indirect_leak=$(cat ${LOG_DIR}/*.asan | grep "Indirect leak" | wc -l)
python_error=$(cat ${LOG_DIR}/*.info | grep -w "stack" | wc -l) python_error=$(cat ${LOG_DIR}/*.info | grep -w "stack" | wc -l)
python_taos_error=$(cat ${LOG_DIR}/*.info |grep "#" | grep -w "TDinternal" | wc -l)
# ignore # ignore
@ -84,17 +85,18 @@ echo -e "\033[44;32;1m"asan memory_leak: $memory_leak"\033[0m"
echo -e "\033[44;32;1m"asan indirect_leak: $indirect_leak"\033[0m" echo -e "\033[44;32;1m"asan indirect_leak: $indirect_leak"\033[0m"
echo -e "\033[44;32;1m"asan runtime error: $runtime_error"\033[0m" echo -e "\033[44;32;1m"asan runtime error: $runtime_error"\033[0m"
echo -e "\033[44;32;1m"asan python error: $python_error"\033[0m" echo -e "\033[44;32;1m"asan python error: $python_error"\033[0m"
echo -e "\033[44;32;1m"asan python taos error: $python_taos_error"\033[0m"
let "errors=$error_num+$memory_leak+$indirect_leak+$runtime_error+$python_error" let "errors=$error_num+$memory_leak+$indirect_leak+$runtime_error+$python_error+$python_taos_error"
if [ $errors -eq 0 ]; then if [ $errors -eq 0 ]; then
echo -e "\033[44;32;1m"no asan errors"\033[0m" echo -e "\033[44;32;1m"no asan errors"\033[0m"
exit 0 exit 0
else else
echo -e "\033[44;31;1m"asan total errors: $errors"\033[0m" echo -e "\033[44;31;1m"asan total errors: $errors"\033[0m"
if [ $python_error -ne 0 ]; then if [ $python_error -ne 0 ] || [ $python_taos_error -ne 0 ] ; then
cat ${LOG_DIR}/*.info cat ${LOG_DIR}/*.info |grep "#" | grep -w "TDinternal"
fi fi
cat ${LOG_DIR}/*.asan cat ${LOG_DIR}/*.asan
exit 1 exit 1
fi fi