Merge branch '3.0' of https://github.com/taosdata/TDengine into enh--refactor-return-code
This commit is contained in:
commit
930974abc2
|
@ -548,8 +548,7 @@ static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOld, STrans *pNew) {
|
|||
pOld->id, pOld, mndTransStr(pOld->stage), pOld->createdTime, pNew, mndTransStr(pNew->stage),
|
||||
pNew->createdTime);
|
||||
// only occured while sync timeout
|
||||
terrno = TSDB_CODE_MND_TRANS_SYNC_TIMEOUT;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_MND_TRANS_SYNC_TIMEOUT);
|
||||
}
|
||||
|
||||
mndTransUpdateActions(pOld->prepareActions, pNew->prepareActions);
|
||||
|
@ -667,8 +666,7 @@ static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction) {
|
|||
|
||||
void *ptr = taosArrayPush(pArray, pAction);
|
||||
if (ptr == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -779,26 +777,29 @@ void mndTransSetChangeless(STrans *pTrans) { pTrans->changeless = true; }
|
|||
void mndTransSetOper(STrans *pTrans, EOperType oper) { pTrans->oper = oper; }
|
||||
|
||||
static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRaw = mndTransEncode(pTrans);
|
||||
if (pRaw == NULL) {
|
||||
mError("trans:%d, failed to encode while sync trans since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
mError("trans:%d, failed to encode while sync trans since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mInfo("trans:%d, sync to other mnodes, stage:%s createTime:%" PRId64, pTrans->id, mndTransStr(pTrans->stage),
|
||||
pTrans->createdTime);
|
||||
int32_t code = mndSyncPropose(pMnode, pRaw, pTrans->id);
|
||||
code = mndSyncPropose(pMnode, pRaw, pTrans->id);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to sync, errno:%s code:0x%x createTime:%" PRId64 " saved trans:%d", pTrans->id, terrstr(),
|
||||
code, pTrans->createdTime, pMnode->syncMgmt.transId);
|
||||
mError("trans:%d, failed to sync, errno:%s code:0x%x createTime:%" PRId64 " saved trans:%d", pTrans->id,
|
||||
tstrerror(code), code, pTrans->createdTime, pMnode->syncMgmt.transId);
|
||||
sdbFreeRaw(pRaw);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
sdbFreeRaw(pRaw);
|
||||
mInfo("trans:%d, sync finished, createTime:%" PRId64, pTrans->id, pTrans->createdTime);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static bool mndCheckDbConflict(const char *conflict, STrans *pTrans) {
|
||||
|
@ -890,24 +891,26 @@ static bool mndCheckTransConflict(SMnode *pMnode, STrans *pNew) {
|
|||
}
|
||||
|
||||
int32_t mndTransCheckConflict(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (pTrans->conflict == TRN_CONFLICT_DB || pTrans->conflict == TRN_CONFLICT_DB_INSIDE) {
|
||||
if (strlen(pTrans->dbname) == 0 && strlen(pTrans->stbname) == 0) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CONFLICT;
|
||||
code = TSDB_CODE_MND_TRANS_CONFLICT;
|
||||
mError("trans:%d, failed to prepare conflict db not set", pTrans->id);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
if (mndCheckTransConflict(pMnode, pTrans)) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CONFLICT;
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
return terrno;
|
||||
code = TSDB_CODE_MND_TRANS_CONFLICT;
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndTransCheckConflictWithCompact(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
void *pIter = NULL;
|
||||
bool conflict = false;
|
||||
SCompactObj *pCompact = NULL;
|
||||
|
@ -934,12 +937,12 @@ int32_t mndTransCheckConflictWithCompact(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
|
||||
if (conflict) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CONFLICT_COMPACT;
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
return terrno;
|
||||
code = TSDB_CODE_MND_TRANS_CONFLICT_COMPACT;
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static bool mndTransActionsOfSameType(SArray *pActions) {
|
||||
|
@ -960,66 +963,65 @@ static bool mndTransActionsOfSameType(SArray *pActions) {
|
|||
}
|
||||
|
||||
static int32_t mndTransCheckParallelActions(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (pTrans->exec == TRN_EXEC_PARALLEL) {
|
||||
if (mndTransActionsOfSameType(pTrans->redoActions) == false) {
|
||||
terrno = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
code = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
mError("trans:%d, types of parallel redo actions are not the same", pTrans->id);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (pTrans->policy == TRN_POLICY_ROLLBACK) {
|
||||
if (mndTransActionsOfSameType(pTrans->undoActions) == false) {
|
||||
terrno = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
code = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
mError("trans:%d, types of parallel undo actions are not the same", pTrans->id);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndTransCheckCommitActions(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (!pTrans->changeless && taosArrayGetSize(pTrans->commitActions) <= 0) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CLOG_IS_NULL;
|
||||
code = TSDB_CODE_MND_TRANS_CLOG_IS_NULL;
|
||||
mError("trans:%d, commit actions of non-changeless trans are empty", pTrans->id);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (mndTransActionsOfSameType(pTrans->commitActions) == false) {
|
||||
terrno = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
code = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
mError("trans:%d, types of commit actions are not the same", pTrans->id);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (pTrans == NULL) return -1;
|
||||
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransCheckConflict(pMnode, pTrans));
|
||||
|
||||
if (mndTransCheckParallelActions(pMnode, pTrans) != 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransCheckParallelActions(pMnode, pTrans));
|
||||
|
||||
if (mndTransCheckCommitActions(pMnode, pTrans) != 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransCheckCommitActions(pMnode, pTrans));
|
||||
|
||||
mInfo("trans:%d, prepare transaction", pTrans->id);
|
||||
if (mndTransSync(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
if ((code = mndTransSync(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, prepare finished", pTrans->id);
|
||||
|
||||
STrans *pNew = mndAcquireTrans(pMnode, pTrans->id);
|
||||
if (pNew == NULL) {
|
||||
mError("trans:%d, failed to read from sdb since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
mError("trans:%d, failed to read from sdb since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pNew->pRpcArray = pTrans->pRpcArray;
|
||||
|
@ -1032,37 +1034,41 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
|
|||
|
||||
mndTransExecute(pMnode, pNew);
|
||||
mndReleaseTrans(pMnode, pNew);
|
||||
// TDOD change to TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransCommit(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
mInfo("trans:%d, commit transaction", pTrans->id);
|
||||
if (mndTransSync(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to commit since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
if ((code = mndTransSync(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to commit since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, commit finished", pTrans->id);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
mInfo("trans:%d, rollback transaction", pTrans->id);
|
||||
if (mndTransSync(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to rollback since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
if ((code = mndTransSync(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to rollback since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, rollback finished", pTrans->id);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndTransPreFinish(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
mInfo("trans:%d, pre-finish transaction", pTrans->id);
|
||||
if (mndTransSync(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to pre-finish since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
if ((code = mndTransSync(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to pre-finish since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, pre-finish finished", pTrans->id);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
||||
|
@ -1168,6 +1174,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
|
||||
int32_t mndTransProcessRsp(SRpcMsg *pRsp) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pRsp->info.node;
|
||||
int64_t signature = (int64_t)(pRsp->info.ahandle);
|
||||
int32_t transId = (int32_t)(signature >> 32);
|
||||
|
@ -1175,7 +1182,9 @@ int32_t mndTransProcessRsp(SRpcMsg *pRsp) {
|
|||
|
||||
STrans *pTrans = mndAcquireTrans(pMnode, transId);
|
||||
if (pTrans == NULL) {
|
||||
mError("trans:%d, failed to get transId from vnode rsp since %s", transId, terrstr());
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
mError("trans:%d, failed to get transId from vnode rsp since %s", transId, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -1216,7 +1225,7 @@ int32_t mndTransProcessRsp(SRpcMsg *pRsp) {
|
|||
|
||||
_OVER:
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static void mndTransResetAction(SMnode *pMnode, STrans *pTrans, STransAction *pAction) {
|
||||
|
@ -1252,8 +1261,7 @@ static void mndTransResetActions(SMnode *pMnode, STrans *pTrans, SArray *pArray)
|
|||
static int32_t mndTransWriteSingleLog(SMnode *pMnode, STrans *pTrans, STransAction *pAction, bool topHalf) {
|
||||
if (pAction->rawWritten) return 0;
|
||||
if (topHalf) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CTX_SWITCH;
|
||||
return TSDB_CODE_MND_TRANS_CTX_SWITCH;
|
||||
TAOS_RETURN(TSDB_CODE_MND_TRANS_CTX_SWITCH);
|
||||
}
|
||||
|
||||
int32_t code = sdbWriteWithoutFree(pMnode->pSdb, pAction->pRaw);
|
||||
|
@ -1272,15 +1280,14 @@ static int32_t mndTransWriteSingleLog(SMnode *pMnode, STrans *pTrans, STransActi
|
|||
mndSetTransLastAction(pTrans, pAction);
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
// execute at top half
|
||||
static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransAction *pAction, bool topHalf) {
|
||||
if (pAction->msgSent) return 0;
|
||||
if (mndCannotExecuteTransAction(pMnode, topHalf)) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CTX_SWITCH;
|
||||
return TSDB_CODE_MND_TRANS_CTX_SWITCH;
|
||||
TAOS_RETURN(TSDB_CODE_MND_TRANS_CTX_SWITCH);
|
||||
}
|
||||
|
||||
int64_t signature = pTrans->id;
|
||||
|
@ -1324,7 +1331,7 @@ static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransActio
|
|||
mndSetTransLastAction(pTrans, pAction);
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndTransExecNullMsg(SMnode *pMnode, STrans *pTrans, STransAction *pAction, bool topHalf) {
|
||||
|
@ -1822,8 +1829,7 @@ int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) {
|
|||
} else if (pTrans->stage == TRN_STAGE_UNDO_ACTION) {
|
||||
pArray = pTrans->undoActions;
|
||||
} else {
|
||||
terrno = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_MND_TRANS_INVALID_STAGE);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
|
@ -1846,17 +1852,19 @@ static int32_t mndProcessKillTransReq(SRpcMsg *pReq) {
|
|||
STrans *pTrans = NULL;
|
||||
|
||||
if (tDeserializeSKillTransReq(pReq->pCont, pReq->contLen, &killReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
mInfo("trans:%d, start to kill", killReq.transId);
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_TRANS) != 0) {
|
||||
if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_TRANS)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pTrans = mndAcquireTrans(pMnode, killReq.transId);
|
||||
if (pTrans == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -1868,7 +1876,7 @@ _OVER:
|
|||
}
|
||||
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndCompareTransId(int32_t *pTransId1, int32_t *pTransId2) { return *pTransId1 >= *pTransId2 ? 1 : 0; }
|
||||
|
|
|
@ -48,27 +48,23 @@ void metaReaderClear(SMetaReader *pReader) {
|
|||
}
|
||||
|
||||
int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t uid) {
|
||||
int32_t code = 0;
|
||||
SMeta *pMeta = pReader->pMeta;
|
||||
STbDbKey tbDbKey = {.version = version, .uid = uid};
|
||||
|
||||
// query table.db
|
||||
if (tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pReader->pBuf, &pReader->szBuf) < 0) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
goto _err;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
// decode the entry
|
||||
tDecoderInit(&pReader->coder, pReader->pBuf, pReader->szBuf);
|
||||
|
||||
if (metaDecodeEntry(&pReader->coder, &pReader->me) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
code = metaDecodeEntry(&pReader->coder, &pReader->me);
|
||||
if (code) return code;
|
||||
// taosMemoryFreeClear(pReader->me.colCmpr.pColCmpr);
|
||||
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool metaIsTableExist(void *pVnode, tb_uid_t uid) {
|
||||
|
@ -90,8 +86,7 @@ int metaReaderGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) {
|
|||
|
||||
// query uid.idx
|
||||
if (tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pReader->pBuf, &pReader->szBuf) < 0) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
version1 = ((SUidIdxVal *)pReader->pBuf)[0].version;
|
||||
|
@ -103,8 +98,7 @@ int metaReaderGetTableEntryByUidCache(SMetaReader *pReader, tb_uid_t uid) {
|
|||
|
||||
SMetaInfo info;
|
||||
if (metaGetInfo(pMeta, uid, &info, pReader) == TSDB_CODE_NOT_FOUND) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
return metaGetTableEntryByVersion(pReader, info.version, uid);
|
||||
|
@ -116,8 +110,7 @@ int metaGetTableEntryByName(SMetaReader *pReader, const char *name) {
|
|||
|
||||
// query name.idx
|
||||
if (tdbTbGet(pMeta->pNameIdx, name, strlen(name) + 1, &pReader->pBuf, &pReader->szBuf) < 0) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
uid = *(tb_uid_t *)pReader->pBuf;
|
||||
|
@ -148,7 +141,7 @@ int metaGetTableNameByUid(void *pVnode, uint64_t uid, char *tbName) {
|
|||
code = metaReaderGetTableEntryByUid(&mr, uid);
|
||||
if (code < 0) {
|
||||
metaReaderClear(&mr);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
STR_TO_VARSTR(tbName, mr.me.name);
|
||||
|
@ -164,7 +157,7 @@ int metaGetTableSzNameByUid(void *meta, uint64_t uid, char *tbName) {
|
|||
code = metaReaderGetTableEntryByUid(&mr, uid);
|
||||
if (code < 0) {
|
||||
metaReaderClear(&mr);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
strncpy(tbName, mr.me.name, TSDB_TABLE_NAME_LEN);
|
||||
metaReaderClear(&mr);
|
||||
|
@ -181,9 +174,8 @@ int metaGetTableUidByName(void *pVnode, char *tbName, uint64_t *uid) {
|
|||
|
||||
// query name.idx
|
||||
if (tdbTbGet(((SMeta *)pReader->pMeta)->pNameIdx, tbName, strlen(tbName) + 1, &pReader->pBuf, &pReader->szBuf) < 0) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
metaReaderClear(&mr);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
*uid = *(tb_uid_t *)pReader->pBuf;
|
||||
|
|
|
@ -13,9 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "vnodeInt.h"
|
||||
#include "meta.h"
|
||||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
static int metaHandleSmaEntry(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaSaveSmaToDB(SMeta *pMeta, const SMetaEntry *pME);
|
||||
|
@ -34,15 +33,15 @@ int32_t metaCreateTSma(SMeta *pMeta, int64_t version, SSmaCfg *pCfg) {
|
|||
int32_t szBuf = 0;
|
||||
void *p = NULL;
|
||||
SMetaReader mr = {0};
|
||||
int32_t code = 0;
|
||||
|
||||
// validate req
|
||||
// save smaIndex
|
||||
metaReaderDoInit(&mr, pMeta, META_READER_LOCK);
|
||||
if (metaReaderGetTableEntryByUidCache(&mr, pCfg->indexUid) == 0) {
|
||||
#if 1
|
||||
terrno = TSDB_CODE_TSMA_ALREADY_EXIST;
|
||||
metaReaderClear(&mr);
|
||||
return -1; // don't goto _err;
|
||||
return terrno = TSDB_CODE_TSMA_ALREADY_EXIST;
|
||||
#else
|
||||
metaReaderClear(&mr);
|
||||
return 0;
|
||||
|
@ -57,7 +56,8 @@ int32_t metaCreateTSma(SMeta *pMeta, int64_t version, SSmaCfg *pCfg) {
|
|||
me.name = pCfg->indexName;
|
||||
me.smaEntry.tsma = pCfg;
|
||||
|
||||
if (metaHandleSmaEntry(pMeta, &me) < 0) goto _err;
|
||||
code = metaHandleSmaEntry(pMeta, &me);
|
||||
if (code) goto _err;
|
||||
|
||||
metaDebug("vgId:%d, tsma is created, name:%s uid:%" PRId64, TD_VID(pMeta->pVnode), pCfg->indexName, pCfg->indexUid);
|
||||
|
||||
|
@ -66,7 +66,7 @@ int32_t metaCreateTSma(SMeta *pMeta, int64_t version, SSmaCfg *pCfg) {
|
|||
_err:
|
||||
metaError("vgId:%d, failed to create tsma:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pCfg->indexName,
|
||||
pCfg->indexUid, tstrerror(terrno));
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid) {
|
||||
|
@ -147,24 +147,25 @@ static int metaUpdateSmaIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
}
|
||||
|
||||
static int metaHandleSmaEntry(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
int32_t code = 0;
|
||||
metaWLock(pMeta);
|
||||
|
||||
// save to table.db
|
||||
if (metaSaveSmaToDB(pMeta, pME) < 0) goto _err;
|
||||
if ((code = metaSaveSmaToDB(pMeta, pME)) < 0) goto _err;
|
||||
|
||||
// update uid.idx
|
||||
if (metaUpdateUidIdx(pMeta, pME) < 0) goto _err;
|
||||
if ((code = metaUpdateUidIdx(pMeta, pME)) < 0) goto _err;
|
||||
|
||||
// update name.idx
|
||||
if (metaUpdateNameIdx(pMeta, pME) < 0) goto _err;
|
||||
if ((code = metaUpdateNameIdx(pMeta, pME)) < 0) goto _err;
|
||||
|
||||
// update sma.idx
|
||||
if (metaUpdateSmaIdx(pMeta, pME) < 0) goto _err;
|
||||
if ((code = metaUpdateSmaIdx(pMeta, pME)) < 0) goto _err;
|
||||
|
||||
metaULock(pMeta);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
metaULock(pMeta);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ int32_t metaSnapReaderOpen(SMeta* pMeta, int64_t sver, int64_t ever, SMetaSnapRe
|
|||
// alloc
|
||||
pReader = (SMetaSnapReader*)taosMemoryCalloc(1, sizeof(*pReader));
|
||||
if (pReader == NULL) {
|
||||
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||
}
|
||||
pReader->pMeta = pMeta;
|
||||
pReader->sver = sver;
|
||||
|
@ -261,7 +261,9 @@ static void saveSuperTableInfoForChildTable(SMetaEntry* me, SHashObj* suidInfo)
|
|||
int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8_t subType, int8_t withMeta,
|
||||
SSnapContext** ctxRet) {
|
||||
SSnapContext* ctx = taosMemoryCalloc(1, sizeof(SSnapContext));
|
||||
if (ctx == NULL) return -1;
|
||||
if (ctx == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
*ctxRet = ctx;
|
||||
ctx->pMeta = pVnode->pMeta;
|
||||
ctx->snapVersion = snapVersion;
|
||||
|
@ -271,12 +273,12 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8
|
|||
ctx->withMeta = withMeta;
|
||||
ctx->idVersion = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
|
||||
if (ctx->idVersion == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
ctx->suidInfo = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
|
||||
if (ctx->suidInfo == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
taosHashSetFreeFp(ctx->suidInfo, destroySTableInfoForChildTable);
|
||||
|
||||
|
@ -426,21 +428,21 @@ static int32_t buildSuperTableInfo(SVCreateStbReq* req, void** pBuf, int32_t* co
|
|||
int32_t ret = 0;
|
||||
tEncodeSize(tEncodeSVCreateStbReq, req, *contLen, ret);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
*contLen += sizeof(SMsgHead);
|
||||
*pBuf = taosMemoryMalloc(*contLen);
|
||||
if (NULL == *pBuf) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, POINTER_SHIFT(*pBuf, sizeof(SMsgHead)), *contLen);
|
||||
if (tEncodeSVCreateStbReq(&encoder, req) < 0) {
|
||||
if ((ret = tEncodeSVCreateStbReq(&encoder, req)) < 0) {
|
||||
taosMemoryFreeClear(*pBuf);
|
||||
tEncoderClear(&encoder);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
return 0;
|
||||
|
|
|
@ -36,11 +36,15 @@ static int metaDeleteBtimeIdx(SMeta *pMeta, const SMetaEntry *pME);
|
|||
static int metaUpdateNcolIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
|
||||
int8_t updataTableColCmpr(SColCmprWrapper *pWp, SSchema *pSchema, int8_t add, uint32_t compress) {
|
||||
static int32_t updataTableColCmpr(SColCmprWrapper *pWp, SSchema *pSchema, int8_t add, uint32_t compress) {
|
||||
int32_t nCols = pWp->nCols;
|
||||
int32_t ver = pWp->version;
|
||||
if (add) {
|
||||
SColCmpr *p = taosMemoryCalloc(1, sizeof(SColCmpr) * (nCols + 1));
|
||||
if (p == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
memcpy(p, pWp->pColCmpr, sizeof(SColCmpr) * nCols);
|
||||
|
||||
SColCmpr *pCol = p + nCols;
|
||||
|
@ -64,7 +68,7 @@ int8_t updataTableColCmpr(SColCmprWrapper *pWp, SSchema *pSchema, int8_t add, ui
|
|||
pWp->nCols = nCols;
|
||||
pWp->version = ver;
|
||||
}
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
static void metaGetEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) {
|
||||
pInfo->uid = pEntry->uid;
|
||||
|
@ -87,8 +91,7 @@ static int metaUpdateMetaRsp(tb_uid_t uid, char *tbName, SSchemaWrapper *pSchema
|
|||
pMetaRsp->pSchemas = taosMemoryMalloc(pSchema->nCols * sizeof(SSchema));
|
||||
|
||||
if (NULL == pMetaRsp->pSchemas) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pMetaRsp->pSchemaExt = taosMemoryMalloc(pSchema->nCols * sizeof(SSchemaExt));
|
||||
|
@ -105,9 +108,11 @@ static int metaUpdateMetaRsp(tb_uid_t uid, char *tbName, SSchemaWrapper *pSchema
|
|||
}
|
||||
|
||||
static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema) {
|
||||
int32_t code = 0;
|
||||
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
if (pMeta->pTagIvtIdx == NULL || pCtbEntry == NULL) {
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
void *data = pCtbEntry->ctbEntry.pTags;
|
||||
const char *tagName = pSchema->name;
|
||||
|
@ -118,8 +123,9 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const
|
|||
int32_t nTagData = 0;
|
||||
|
||||
SArray *pTagVals = NULL;
|
||||
if (tTagToValArray((const STag *)data, &pTagVals) != 0) {
|
||||
return -1;
|
||||
code = tTagToValArray((const STag *)data, &pTagVals);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SIndexMultiTerm *terms = indexMultiTermCreate();
|
||||
|
@ -168,7 +174,7 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const
|
|||
int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema) {
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
if (pMeta->pTagIvtIdx == NULL || pCtbEntry == NULL) {
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
void *data = pCtbEntry->ctbEntry.pTags;
|
||||
const char *tagName = pSchema->name;
|
||||
|
@ -179,8 +185,9 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche
|
|||
int32_t nTagData = 0;
|
||||
|
||||
SArray *pTagVals = NULL;
|
||||
if (tTagToValArray((const STag *)data, &pTagVals) != 0) {
|
||||
return -1;
|
||||
int32_t code = tTagToValArray((const STag *)data, &pTagVals);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SIndexMultiTerm *terms = indexMultiTermCreate();
|
||||
|
@ -247,6 +254,7 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
void *pBuf = NULL;
|
||||
int32_t szBuf = 0;
|
||||
void *p = NULL;
|
||||
int32_t code = 0;
|
||||
|
||||
// validate req
|
||||
void *pData = NULL;
|
||||
|
@ -256,14 +264,12 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
tdbFree(pData);
|
||||
SMetaInfo info;
|
||||
if (metaGetInfo(pMeta, uid, &info, NULL) == TSDB_CODE_NOT_FOUND) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
if (info.uid == info.suid) {
|
||||
return 0;
|
||||
} else {
|
||||
terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,7 +289,8 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
me.colCmpr = pReq->colCmpr;
|
||||
}
|
||||
|
||||
if (metaHandleEntry(pMeta, &me) < 0) goto _err;
|
||||
code = metaHandleEntry(pMeta, &me);
|
||||
if (code) goto _err;
|
||||
|
||||
++pMeta->pVnode->config.vndStats.numOfSTables;
|
||||
|
||||
|
@ -295,7 +302,7 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
_err:
|
||||
metaError("vgId:%d, failed to create stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, pReq->suid,
|
||||
tstrerror(terrno));
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq, SArray *tbUidList) {
|
||||
|
@ -310,8 +317,7 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq, SArray *tb
|
|||
rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData);
|
||||
if (rc < 0 || *(tb_uid_t *)pData != pReq->suid) {
|
||||
tdbFree(pData);
|
||||
terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
}
|
||||
|
||||
// drop all child tables
|
||||
|
@ -424,16 +430,14 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
if (ret < 0 || c) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
|
||||
terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
}
|
||||
|
||||
ret = tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||
if (ret < 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
|
||||
terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
}
|
||||
|
||||
oversion = ((SUidIdxVal *)pData)[0].version;
|
||||
|
@ -444,9 +448,8 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
|
||||
terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
metaError("meta/table: invalide ret: %" PRId32 " or c: %" PRId32 "alter stb failed.", ret, c);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
}
|
||||
|
||||
ret = tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
|
@ -454,8 +457,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
|
||||
terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
}
|
||||
|
||||
oStbEntry.pBuf = taosMemoryMalloc(nData);
|
||||
|
@ -870,8 +872,7 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs
|
|||
if (pReq->type == TSDB_CHILD_TABLE) {
|
||||
tb_uid_t suid = metaGetTableEntryUidByName(pMeta, pReq->ctb.stbName);
|
||||
if (suid != pReq->ctb.suid) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -879,17 +880,15 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs
|
|||
metaReaderDoInit(&mr, pMeta, META_READER_LOCK);
|
||||
if (metaGetTableEntryByName(&mr, pReq->name) == 0) {
|
||||
if (pReq->type == TSDB_CHILD_TABLE && pReq->ctb.suid != mr.me.ctbEntry.suid) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_IN_OTHER_STABLE;
|
||||
metaReaderClear(&mr);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_IN_OTHER_STABLE;
|
||||
}
|
||||
pReq->uid = mr.me.uid;
|
||||
if (pReq->type == TSDB_CHILD_TABLE) {
|
||||
pReq->ctb.suid = mr.me.ctbEntry.suid;
|
||||
}
|
||||
terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
|
||||
metaReaderClear(&mr);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
|
||||
} else if (terrno == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1001,7 +1000,7 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs
|
|||
_err:
|
||||
metaError("vgId:%d, failed to create table:%s type:%s since %s", TD_VID(pMeta->pVnode), pReq->name,
|
||||
pReq->type == TSDB_CHILD_TABLE ? "child table" : "normal table", tstrerror(terrno));
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUids, tb_uid_t *tbUid) {
|
||||
|
@ -1015,8 +1014,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi
|
|||
|
||||
rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData);
|
||||
if (rc < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
uid = *(tb_uid_t *)pData;
|
||||
|
||||
|
@ -1154,7 +1152,7 @@ int32_t metaTrimTables(SMeta *pMeta) {
|
|||
|
||||
SArray *tbUids = taosArrayInit(8, sizeof(int64_t));
|
||||
if (tbUids == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
code = metaFilterTableByHash(pMeta, tbUids);
|
||||
|
@ -1195,7 +1193,7 @@ static int metaBuildBtimeIdxKey(SBtimeIdxKey *btimeKey, const SMetaEntry *pME) {
|
|||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||
btime = pME->ntbEntry.btime;
|
||||
} else {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
btimeKey->btime = btime;
|
||||
|
@ -1208,7 +1206,7 @@ static int metaBuildNColIdxKey(SNcolIdxKey *ncolKey, const SMetaEntry *pME) {
|
|||
ncolKey->ncol = pME->ntbEntry.schemaRow.nCols;
|
||||
ncolKey->uid = pME->uid;
|
||||
} else {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1235,7 +1233,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p
|
|||
|
||||
rc = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData);
|
||||
if (rc < 0) {
|
||||
return -1;
|
||||
return rc;
|
||||
}
|
||||
int64_t version = ((SUidIdxVal *)pData)[0].version;
|
||||
|
||||
|
@ -1245,7 +1243,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p
|
|||
rc = metaDecodeEntry(&dc, &e);
|
||||
if (rc < 0) {
|
||||
tDecoderClear(&dc);
|
||||
return -1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (type) *type = e.type;
|
||||
|
@ -1408,16 +1406,14 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
int c;
|
||||
bool freeColCmpr = false;
|
||||
if (pAlterTbReq->colName == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
metaError("meta/table: null pAlterTbReq->colName");
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
// search name index
|
||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
uid = *(tb_uid_t *)pVal;
|
||||
|
@ -1432,7 +1428,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
if (c != 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
metaError("meta/table: invalide c: %" PRId32 " alt tb column failed.", c);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||
|
@ -1447,7 +1443,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
metaError("meta/table: invalide c: %" PRId32 " alt tb column failed.", c);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
|
@ -1463,7 +1459,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
tdbTbcClose(pTbDbc);
|
||||
tDecoderClear(&dc);
|
||||
metaError("meta/table: invalide ret: %" PRId32 " alt tb column failed.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (entry.type != TSDB_NORMAL_TABLE) {
|
||||
|
@ -1660,7 +1656,7 @@ _err:
|
|||
tdbTbcClose(pUidIdxc);
|
||||
tDecoderClear(&dc);
|
||||
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) {
|
||||
|
@ -1676,15 +1672,13 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
int nData = 0;
|
||||
|
||||
if (pAlterTbReq->tagName == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
// search name index
|
||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
uid = *(tb_uid_t *)pVal;
|
||||
|
@ -1698,9 +1692,8 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
|
||||
if (c != 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb tag val failed.", c);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||
|
@ -1717,9 +1710,8 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
if (c != 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb tag val failed.", c);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
|
@ -1866,8 +1858,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
// search name index
|
||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
uid = *(tb_uid_t *)pVal;
|
||||
|
@ -1882,7 +1873,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
if (c != 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb options failed.", c);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||
|
@ -1897,7 +1888,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb options failed.", c);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
|
@ -1913,7 +1904,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
metaError("meta/table: invalide ret: %" PRId32 " alt tb options failed.", ret);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
entry.version = version;
|
||||
|
@ -1968,15 +1959,13 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb
|
|||
SDecoder dc = {0};
|
||||
|
||||
if (pAlterTbReq->tagName == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
// search name index
|
||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
} else {
|
||||
uid = *(tb_uid_t *)pVal;
|
||||
tdbFree(pVal);
|
||||
|
@ -2085,7 +2074,7 @@ _err:
|
|||
// if (stbEntry.pBuf) tdbFree(stbEntry.pBuf);
|
||||
// tdbTbcClose(pTbDbc);
|
||||
// tdbTbcClose(pUidIdxc);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
typedef struct SMetaPair {
|
||||
|
@ -2106,15 +2095,13 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT
|
|||
SDecoder dc = {0};
|
||||
|
||||
if (pAlterTbReq->tagName == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
// search name index
|
||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
suid = *(tb_uid_t *)pVal;
|
||||
tdbFree(pVal);
|
||||
|
@ -2200,7 +2187,7 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT
|
|||
// set pCol->flags; INDEX_ON
|
||||
return 0;
|
||||
_err:
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) {
|
||||
// impl later
|
||||
|
@ -2216,8 +2203,7 @@ int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq *
|
|||
SDecoder dc = {0};
|
||||
ret = tdbTbGet(pMeta->pNameIdx, pReq->tbName, strlen(pReq->tbName) + 1, &pVal, &nVal);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
suid = *(tb_uid_t *)pVal;
|
||||
tdbFree(pVal);
|
||||
|
@ -2290,7 +2276,7 @@ int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq *
|
|||
|
||||
return 0;
|
||||
_err:
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pMetaRsp) {
|
||||
|
@ -2313,8 +2299,7 @@ int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMeta
|
|||
case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS:
|
||||
return metaUpdateTableColCompress(pMeta, version, pReq);
|
||||
default:
|
||||
terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2370,7 +2355,7 @@ _err:
|
|||
pME->uid, tstrerror(terrno));
|
||||
|
||||
taosMemoryFree(pVal);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
|
@ -2446,8 +2431,7 @@ int metaCreateTagIdxKey(tb_uid_t suid, int32_t cid, const void *pTagData, int32_
|
|||
|
||||
*ppTagIdxKey = (STagIdxKey *)taosMemoryMalloc(*nTagIdxKey);
|
||||
if (*ppTagIdxKey == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
(*ppTagIdxKey)->suid = suid;
|
||||
|
@ -2667,7 +2651,7 @@ _err:
|
|||
metaULock(pMeta);
|
||||
metaError("vgId:%d, failed to handle meta entry since %s at line:%d, ver:%" PRId64 ", uid:%" PRId64 ", name:%s",
|
||||
TD_VID(pMeta->pVnode), terrstr(), line, pME->version, pME->uid, pME->name);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
int32_t colCompressDebug(SHashObj *pColCmprObj) {
|
||||
|
@ -2703,7 +2687,7 @@ int32_t metaGetColCmpr(SMeta *pMeta, tb_uid_t uid, SHashObj **ppColCmprObj) {
|
|||
if (rc < 0) {
|
||||
taosHashClear(pColCmprObj);
|
||||
metaULock(pMeta);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
int64_t version = ((SUidIdxVal *)pData)[0].version;
|
||||
rc = tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData);
|
||||
|
@ -2721,7 +2705,7 @@ int32_t metaGetColCmpr(SMeta *pMeta, tb_uid_t uid, SHashObj **ppColCmprObj) {
|
|||
tdbFree(pData);
|
||||
metaULock(pMeta);
|
||||
taosHashClear(pColCmprObj);
|
||||
return -1;
|
||||
return rc;
|
||||
}
|
||||
if (useCompress(e.type)) {
|
||||
SColCmprWrapper *p = &e.colCmpr;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -281,12 +281,13 @@ int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t s
|
|||
int32_t diskPrimary, STfs *pTfs) {
|
||||
SVnodeInfo info = {0};
|
||||
char dir[TSDB_FILENAME_LEN] = {0};
|
||||
int32_t code = 0;
|
||||
|
||||
vnodeGetPrimaryDir(dstPath, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN);
|
||||
if (vnodeLoadInfo(dir, &info) == 0) {
|
||||
if (info.config.vgId != dstVgId) {
|
||||
vError("vgId:%d, unexpected vnode config.vgId:%d", dstVgId, info.config.vgId);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return dstVgId;
|
||||
}
|
||||
|
@ -302,13 +303,13 @@ int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t s
|
|||
return srcVgId;
|
||||
} else if (info.config.vgId != dstVgId) {
|
||||
vError("vgId:%d, unexpected vnode config.vgId:%d", dstVgId, info.config.vgId);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
vInfo("vgId:%d, rename %s to %s", dstVgId, srcPath, dstPath);
|
||||
if (vnodeRenameVgroupId(srcPath, dstPath, srcVgId, dstVgId, diskPrimary, pTfs) < 0) {
|
||||
vError("vgId:%d, failed to rename vnode from %s to %s since %s", dstVgId, srcPath, dstPath, tstrerror(terrno));
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
return dstVgId;
|
||||
|
@ -333,8 +334,7 @@ static int32_t vnodeCheckDisk(int32_t diskPrimary, STfs *pTfs) {
|
|||
}
|
||||
if (diskPrimary < 0 || diskPrimary >= ndisk) {
|
||||
vError("disk:%d is unavailable from the %d disks mounted at level 0", diskPrimary, ndisk);
|
||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -513,6 +513,7 @@ int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg *pRsp) {
|
||||
int32_t code = 0;
|
||||
void *ptr = NULL;
|
||||
void *pReq;
|
||||
int32_t len;
|
||||
|
@ -520,8 +521,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg
|
|||
if (ver <= pVnode->state.applied) {
|
||||
vError("vgId:%d, duplicate write request. ver: %" PRId64 ", applied: %" PRId64 "", TD_VID(pVnode), ver,
|
||||
pVnode->state.applied);
|
||||
terrno = TSDB_CODE_VND_DUP_REQUEST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_VND_DUP_REQUEST;
|
||||
}
|
||||
|
||||
vDebug("vgId:%d, start to process write request %s, index:%" PRId64 ", applied:%" PRId64 ", state.applyTerm:%" PRId64
|
||||
|
@ -693,7 +693,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg
|
|||
break;
|
||||
default:
|
||||
vError("vgId:%d, unprocessed msg, %d", TD_VID(pVnode), pMsg->msgType);
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
vTrace("vgId:%d, process %s request, code:0x%x index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), pRsp->code,
|
||||
|
@ -701,21 +701,24 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg
|
|||
|
||||
walApplyVer(pVnode->pWal, ver);
|
||||
|
||||
if (tqPushMsg(pVnode->pTq, pMsg->msgType) < 0) {
|
||||
code = tqPushMsg(pVnode->pTq, pMsg->msgType);
|
||||
if (code) {
|
||||
vError("vgId:%d, failed to push msg to TQ since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
// commit if need
|
||||
if (needCommit) {
|
||||
vInfo("vgId:%d, commit at version %" PRId64, TD_VID(pVnode), ver);
|
||||
if (vnodeAsyncCommit(pVnode) < 0) {
|
||||
code = vnodeAsyncCommit(pVnode);
|
||||
if (code) {
|
||||
vError("vgId:%d, failed to vnode async commit since %s.", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// start a new one
|
||||
if (vnodeBegin(pVnode) < 0) {
|
||||
code = vnodeBegin(pVnode);
|
||||
if (code) {
|
||||
vError("vgId:%d, failed to begin vnode since %s.", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
@ -727,7 +730,7 @@ _exit:
|
|||
_err:
|
||||
vError("vgId:%d, process %s request failed since %s, ver:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType),
|
||||
tstrerror(terrno), ver);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||
|
@ -987,11 +990,18 @@ static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode *pVnode, int64_t ver, void
|
|||
if (terrno < 0) goto _end;
|
||||
strncpy(buf, mr.me.name, TSDB_TABLE_NAME_LEN);
|
||||
void *p = taosArrayPush(pNames, buf);
|
||||
if (p == NULL) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
expiredTb.name = p;
|
||||
if (mr.me.type == TSDB_CHILD_TABLE) {
|
||||
expiredTb.suid = mr.me.ctbEntry.suid;
|
||||
}
|
||||
taosArrayPush(rsp.pExpiredTbs, &expiredTb);
|
||||
|
||||
if (taosArrayPush(rsp.pExpiredTbs, &expiredTb) == NULL) {
|
||||
goto _end;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
|
@ -1017,6 +1027,7 @@ _end:
|
|||
}
|
||||
|
||||
static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
int32_t code = 0;
|
||||
SVCreateStbReq req = {0};
|
||||
SDecoder coder;
|
||||
|
||||
|
@ -1028,18 +1039,20 @@ static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
// decode and process req
|
||||
tDecoderInit(&coder, pReq, len);
|
||||
|
||||
if (tDecodeSVCreateStbReq(&coder, &req) < 0) {
|
||||
pRsp->code = terrno;
|
||||
code = tDecodeSVCreateStbReq(&coder, &req);
|
||||
if (code) {
|
||||
pRsp->code = code;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (metaCreateSTable(pVnode->pMeta, ver, &req) < 0) {
|
||||
pRsp->code = terrno;
|
||||
code = metaCreateSTable(pVnode->pMeta, ver, &req);
|
||||
if (code) {
|
||||
pRsp->code = code;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (tdProcessRSmaCreate(pVnode->pSma, &req) < 0) {
|
||||
pRsp->code = terrno;
|
||||
if ((code = tdProcessRSmaCreate(pVnode->pSma, &req)) < 0) {
|
||||
pRsp->code = code;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
|
@ -1048,7 +1061,7 @@ static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
|
||||
_err:
|
||||
tDecoderClear(&coder);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
|
||||
|
@ -1100,7 +1113,11 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
goto _exit;
|
||||
}
|
||||
strcpy(str, pCreateReq->name);
|
||||
taosArrayPush(tbNames, &str);
|
||||
if (taosArrayPush(tbNames, &str) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
rcode = -1;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
|
||||
// validate hash
|
||||
|
@ -1185,6 +1202,7 @@ _exit:
|
|||
}
|
||||
|
||||
static int32_t vnodeProcessAlterStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
int32_t code = 0;
|
||||
SVCreateStbReq req = {0};
|
||||
SDecoder dc = {0};
|
||||
|
||||
|
@ -1196,16 +1214,17 @@ static int32_t vnodeProcessAlterStbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
tDecoderInit(&dc, pReq, len);
|
||||
|
||||
// decode req
|
||||
if (tDecodeSVCreateStbReq(&dc, &req) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
code = tDecodeSVCreateStbReq(&dc, &req);
|
||||
if (code) {
|
||||
tDecoderClear(&dc);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (metaAlterSTable(pVnode->pMeta, ver, &req) < 0) {
|
||||
pRsp->code = terrno;
|
||||
code = metaAlterSTable(pVnode->pMeta, ver, &req);
|
||||
if (code) {
|
||||
pRsp->code = code;
|
||||
tDecoderClear(&dc);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tDecoderClear(&dc);
|
||||
|
@ -2224,6 +2243,7 @@ _err:
|
|||
static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
SVCreateStbReq req = {0};
|
||||
SDecoder dc = {0};
|
||||
int32_t code = 0;
|
||||
|
||||
pRsp->msgType = TDMT_VND_CREATE_INDEX_RSP;
|
||||
pRsp->code = TSDB_CODE_SUCCESS;
|
||||
|
@ -2233,35 +2253,38 @@ static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pRe
|
|||
tDecoderInit(&dc, pReq, len);
|
||||
// decode req
|
||||
if (tDecodeSVCreateStbReq(&dc, &req) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
tDecoderClear(&dc);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
if (metaAddIndexToSTable(pVnode->pMeta, ver, &req) < 0) {
|
||||
pRsp->code = terrno;
|
||||
|
||||
code = metaAddIndexToSTable(pVnode->pMeta, ver, &req);
|
||||
if (code) {
|
||||
pRsp->code = code;
|
||||
goto _err;
|
||||
}
|
||||
tDecoderClear(&dc);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
tDecoderClear(&dc);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
static int32_t vnodeProcessDropIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
SDropIndexReq req = {0};
|
||||
int32_t code = 0;
|
||||
pRsp->msgType = TDMT_VND_DROP_INDEX_RSP;
|
||||
pRsp->code = TSDB_CODE_SUCCESS;
|
||||
pRsp->pCont = NULL;
|
||||
pRsp->contLen = 0;
|
||||
|
||||
if (tDeserializeSDropIdxReq(pReq, len, &req)) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
if ((code = tDeserializeSDropIdxReq(pReq, len, &req))) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (metaDropIndexFromSTable(pVnode->pMeta, ver, &req) < 0) {
|
||||
pRsp->code = terrno;
|
||||
return -1;
|
||||
code = metaDropIndexFromSTable(pVnode->pMeta, ver, &req);
|
||||
if (code) {
|
||||
pRsp->code = code;
|
||||
return code;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -2290,20 +2313,17 @@ static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pR
|
|||
static int32_t vnodePreCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
|
||||
SSyncState syncState = syncGetState(pVnode->sync);
|
||||
if (syncState.state != TAOS_SYNC_STATE_LEADER) {
|
||||
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||
}
|
||||
|
||||
char token[TSDB_ARB_TOKEN_SIZE] = {0};
|
||||
if (vnodeGetArbToken(pVnode, token) != 0) {
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (strncmp(token, member0Token, TSDB_ARB_TOKEN_SIZE) != 0 &&
|
||||
strncmp(token, member1Token, TSDB_ARB_TOKEN_SIZE) != 0) {
|
||||
terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
@ -2324,9 +2344,9 @@ static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t l
|
|||
|
||||
SVArbCheckSyncReq syncReq = {0};
|
||||
|
||||
if (tDeserializeSVArbCheckSyncReq(pReq, len, &syncReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = tDeserializeSVArbCheckSyncReq(pReq, len, &syncReq);
|
||||
if (code) {
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
pRsp->msgType = TDMT_VND_ARB_CHECK_SYNC_RSP;
|
||||
|
|
|
@ -128,9 +128,9 @@ SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfFillExpr, SExprIn
|
|||
int32_t numOfNotFillCols, const struct SNodeListNode* val);
|
||||
bool taosFillHasMoreResults(struct SFillInfo* pFillInfo);
|
||||
|
||||
SFillInfo* taosCreateFillInfo(TSKEY skey, int32_t numOfFillCols, int32_t numOfNotFillCols, int32_t capacity,
|
||||
SInterval* pInterval, int32_t fillType, struct SFillColInfo* pCol, int32_t slotId,
|
||||
int32_t order, const char* id, SExecTaskInfo* pTaskInfo);
|
||||
void taosCreateFillInfo(TSKEY skey, int32_t numOfFillCols, int32_t numOfNotFillCols, int32_t capacity,
|
||||
SInterval* pInterval, int32_t fillType, struct SFillColInfo* pCol, int32_t slotId,
|
||||
int32_t order, const char* id, SExecTaskInfo* pTaskInfo, SFillInfo** ppFillInfo);
|
||||
|
||||
void* taosDestroyFillInfo(struct SFillInfo* pFillInfo);
|
||||
int32_t taosFillResultDataBlock(struct SFillInfo* pFillInfo, SSDataBlock* p, int32_t capacity);
|
||||
|
|
|
@ -252,14 +252,15 @@ _end:
|
|||
return pBlock != NULL;
|
||||
}
|
||||
|
||||
SSDataBlock* getAggregateResult(SOperatorInfo* pOperator) {
|
||||
int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SAggOperatorInfo* pAggInfo = pOperator->info;
|
||||
SOptrBasicInfo* pInfo = &pAggInfo->binfo;
|
||||
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
@ -291,10 +292,18 @@ SSDataBlock* getAggregateResult(SOperatorInfo* pOperator) {
|
|||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
|
||||
return (rows == 0) ? NULL : pInfo->pRes;
|
||||
(*ppRes) = (rows == 0) ? NULL : pInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* getAggregateResult(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = getAggregateResultNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx) {
|
||||
|
|
|
@ -144,7 +144,7 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe
|
|||
|
||||
for (int i = 0; i < TARRAY_SIZE(pInfo->matchInfo.pList); ++i) {
|
||||
SColMatchItem* pColInfo = taosArrayGet(pInfo->matchInfo.pList, i);
|
||||
void* tmp = taosArrayPush(pCidList, &pColInfo->colId);
|
||||
void* tmp = taosArrayPush(pCidList, &pColInfo->colId);
|
||||
QUERY_CHECK_NULL(tmp, code, lino, _error, TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (pInfo->pFuncTypeList != NULL && taosArrayGetSize(pInfo->pFuncTypeList) > i) {
|
||||
pColInfo->funcType = *(int32_t*)taosArrayGet(pInfo->pFuncTypeList, i);
|
||||
|
@ -219,9 +219,12 @@ _error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
||||
int32_t doScanCacheNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
SCacheRowsScanInfo* pInfo = pOperator->info;
|
||||
|
@ -234,7 +237,8 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
int32_t size = tableListGetSize(pTableList);
|
||||
if (size == 0) {
|
||||
setOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
blockDataCleanup(pInfo->pRes);
|
||||
|
@ -249,11 +253,9 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
blockDataCleanup(pBufRes);
|
||||
taosArrayClear(pInfo->pUidList);
|
||||
|
||||
int32_t code =
|
||||
code =
|
||||
pReaderFn->retrieveRows(pInfo->pLastrowReader, pBufRes, pInfo->pSlotIds, pInfo->pDstSlotIds, pInfo->pUidList);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
// check for tag values
|
||||
int32_t resultRows = pBufRes->info.rows;
|
||||
|
@ -277,12 +279,9 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
colDataSetNULL(pDst, 0);
|
||||
} else {
|
||||
if (pSrc->pData) {
|
||||
char* p = colDataGetData(pSrc, pInfo->indexOfBufferedRes);
|
||||
int32_t code = colDataSetVal(pDst, 0, p, false);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
char* p = colDataGetData(pSrc, pInfo->indexOfBufferedRes);
|
||||
code = colDataSetVal(pDst, 0, p, false);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -292,19 +291,22 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
pRes->info.scanFlag = MAIN_SCAN;
|
||||
|
||||
SExprSupp* pSup = &pInfo->pseudoExprSup;
|
||||
int32_t code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pRes,
|
||||
pRes->info.rows, pTaskInfo, NULL);
|
||||
code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pRes, pRes->info.rows,
|
||||
pTaskInfo, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pTaskInfo->code = code;
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
pRes->info.id.groupId = tableListGetTableGroupId(pTableList, pRes->info.id.uid);
|
||||
pInfo->indexOfBufferedRes += 1;
|
||||
return pRes;
|
||||
(*ppRes) = pRes;
|
||||
return code;
|
||||
} else {
|
||||
setOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
size_t totalGroups = tableListGetOutputGroups(pTableList);
|
||||
|
@ -317,37 +319,30 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
STableKeyInfo* pList = NULL;
|
||||
int32_t num = 0;
|
||||
|
||||
int32_t code = tableListGetGroupList(pTableList, pInfo->currentGroupIndex, &pList, &num);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
code = tableListGetGroupList(pTableList, pInfo->currentGroupIndex, &pList, &num);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
if (NULL == pInfo->pLastrowReader) {
|
||||
code = pReaderFn->openReader(pInfo->readHandle.vnode, pInfo->retrieveType, pList, num,
|
||||
taosArrayGetSize(pInfo->matchInfo.pList), pInfo->pCidList, pInfo->pSlotIds, suid,
|
||||
&pInfo->pLastrowReader, pTaskInfo->id.str, pInfo->pFuncTypeList, &pInfo->pkCol,
|
||||
pInfo->numOfPks);
|
||||
int32_t tmpRes = pReaderFn->openReader(pInfo->readHandle.vnode, pInfo->retrieveType, pList, num,
|
||||
taosArrayGetSize(pInfo->matchInfo.pList), pInfo->pCidList,
|
||||
pInfo->pSlotIds, suid, &pInfo->pLastrowReader, pTaskInfo->id.str,
|
||||
pInfo->pFuncTypeList, &pInfo->pkCol, pInfo->numOfPks);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
if (tmpRes != TSDB_CODE_SUCCESS) {
|
||||
pInfo->currentGroupIndex += 1;
|
||||
taosArrayClear(pInfo->pUidList);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
code = pReaderFn->reuseReader(pInfo->pLastrowReader, pList, num);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
}
|
||||
|
||||
taosArrayClear(pInfo->pUidList);
|
||||
|
||||
code = pReaderFn->retrieveRows(pInfo->pLastrowReader, pInfo->pRes, pInfo->pSlotIds, pInfo->pDstSlotIds,
|
||||
pInfo->pUidList);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
pInfo->currentGroupIndex += 1;
|
||||
|
||||
|
@ -365,13 +360,15 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
pInfo->pRes->info.rows, pTaskInfo, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pTaskInfo->code = code;
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pInfo->pLastrowReader = tsdbCacherowsReaderClose(pInfo->pLastrowReader);
|
||||
return pInfo->pRes;
|
||||
(*ppRes) = pInfo->pRes;
|
||||
return code;
|
||||
} else {
|
||||
// pInfo->pLastrowReader = tsdbCacherowsReaderClose(pInfo->pLastrowReader);
|
||||
}
|
||||
|
@ -380,8 +377,23 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
pReaderFn->closeReader(pInfo->pLastrowReader);
|
||||
pInfo->pLastrowReader = NULL;
|
||||
setOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doScanCacheNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
void destroyCacheScanOperator(void* param) {
|
||||
|
|
|
@ -145,8 +145,8 @@ void doCountWindowAggImpl(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
|||
static void buildCountResult(SExprSupp* pExprSup, SCountWindowSupp* pCountSup, SExecTaskInfo* pTaskInfo,
|
||||
SFilterInfo* pFilterInfo, SSDataBlock* pBlock) {
|
||||
SResultRow* pResultRow = NULL;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pCountSup->pWinStates); i++) {
|
||||
SCountWindowResult* pBuff = NULL;
|
||||
code = setCountWindowOutputBuff(pExprSup, pCountSup, &pResultRow, &pBuff);
|
||||
|
@ -171,7 +171,7 @@ _end:
|
|||
}
|
||||
}
|
||||
|
||||
static SSDataBlock* countWindowAggregate(SOperatorInfo* pOperator) {
|
||||
static int32_t countWindowAggregateNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SCountWindowOperatorInfo* pInfo = pOperator->info;
|
||||
|
@ -198,11 +198,9 @@ static SSDataBlock* countWindowAggregate(SOperatorInfo* pOperator) {
|
|||
|
||||
// there is an scalar expression that needs to be calculated right before apply the group aggregation.
|
||||
if (pInfo->scalarSup.pExprInfo != NULL) {
|
||||
pTaskInfo->code = projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
|
||||
pInfo->scalarSup.numOfExprs, NULL);
|
||||
if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
|
||||
}
|
||||
code = projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
|
||||
pInfo->scalarSup.numOfExprs, NULL);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
}
|
||||
|
||||
if (pInfo->groupId == 0) {
|
||||
|
@ -214,7 +212,8 @@ static SSDataBlock* countWindowAggregate(SOperatorInfo* pOperator) {
|
|||
|
||||
doCountWindowAggImpl(pOperator, pBlock);
|
||||
if (pRes->info.rows >= pOperator->resultInfo.threshold) {
|
||||
return pRes;
|
||||
(*ppRes) = pRes;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,9 +222,17 @@ static SSDataBlock* countWindowAggregate(SOperatorInfo* pOperator) {
|
|||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
return pRes->info.rows == 0 ? NULL : pRes;
|
||||
(*ppRes) = pRes->info.rows == 0 ? NULL : pRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* countWindowAggregate(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = countWindowAggregateNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
SOperatorInfo* createCountwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* physiNode,
|
||||
|
|
|
@ -168,7 +168,7 @@ void destroyEWindowOperatorInfo(void* param) {
|
|||
taosMemoryFreeClear(param);
|
||||
}
|
||||
|
||||
static SSDataBlock* eventWindowAggregate(SOperatorInfo* pOperator) {
|
||||
static int32_t eventWindowAggregateNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SEventWindowOperatorInfo* pInfo = pOperator->info;
|
||||
|
@ -197,11 +197,9 @@ static SSDataBlock* eventWindowAggregate(SOperatorInfo* pOperator) {
|
|||
|
||||
// there is an scalar expression that needs to be calculated right before apply the group aggregation.
|
||||
if (pInfo->scalarSup.pExprInfo != NULL) {
|
||||
pTaskInfo->code = projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
|
||||
pInfo->scalarSup.numOfExprs, NULL);
|
||||
if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
|
||||
}
|
||||
code = projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
|
||||
pInfo->scalarSup.numOfExprs, NULL);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
}
|
||||
|
||||
code = eventWindowAggImpl(pOperator, pInfo, pBlock);
|
||||
|
@ -211,16 +209,25 @@ static SSDataBlock* eventWindowAggregate(SOperatorInfo* pOperator) {
|
|||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
if (pRes->info.rows >= pOperator->resultInfo.threshold) {
|
||||
return pRes;
|
||||
(*ppRes) = pRes;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
return pRes->info.rows == 0 ? NULL : pRes;
|
||||
(*ppRes) = pRes->info.rows == 0 ? NULL : pRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* eventWindowAggregate(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = eventWindowAggregateNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static int32_t setSingleOutputTupleBufv1(SResultRowInfo* pResultRowInfo, STimeWindow* win, SResultRow** pResult,
|
||||
|
|
|
@ -230,30 +230,30 @@ static SSDataBlock* doLoadRemoteDataImpl(SOperatorInfo* pOperator) {
|
|||
}
|
||||
}
|
||||
|
||||
static SSDataBlock* loadRemoteData(SOperatorInfo* pOperator) {
|
||||
static int32_t loadRemoteDataNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SExchangeInfo* pExchangeInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
pTaskInfo->code = pOperator->fpSet._openFn(pOperator);
|
||||
if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
|
||||
}
|
||||
code = pOperator->fpSet._openFn(pOperator);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
SSDataBlock* pBlock = doLoadRemoteDataImpl(pOperator);
|
||||
if (pBlock == NULL) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
pTaskInfo->code = doFilter(pBlock, pOperator->exprSupp.pFilterInfo, NULL);
|
||||
if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(pTaskInfo->code));
|
||||
T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
|
||||
}
|
||||
code = doFilter(pBlock, pOperator->exprSupp.pFilterInfo, NULL);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
if (blockDataGetNumOfRows(pBlock) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
@ -266,15 +266,33 @@ static SSDataBlock* loadRemoteData(SOperatorInfo* pOperator) {
|
|||
} else if (status == PROJECT_RETRIEVE_DONE) {
|
||||
if (pBlock->info.rows == 0) {
|
||||
setOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
} else {
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* loadRemoteData(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = loadRemoteDataNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static int32_t initDataSource(int32_t numOfSources, SExchangeInfo* pInfo, const char* id) {
|
||||
|
|
|
@ -316,12 +316,14 @@ _end:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static SSDataBlock* doFill(SOperatorInfo* pOperator) {
|
||||
static int32_t doFillNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SFillOperatorInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
SSDataBlock* fillResult = NULL;
|
||||
|
@ -332,9 +334,10 @@ static SSDataBlock* doFill(SOperatorInfo* pOperator) {
|
|||
break;
|
||||
}
|
||||
|
||||
int32_t code = doFilter(fillResult, pOperator->exprSupp.pFilterInfo, &pInfo->matchInfo);
|
||||
code = doFilter(fillResult, pOperator->exprSupp.pFilterInfo, &pInfo->matchInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
if (fillResult->info.rows > 0) {
|
||||
|
@ -346,7 +349,14 @@ static SSDataBlock* doFill(SOperatorInfo* pOperator) {
|
|||
pOperator->resultInfo.totalRows += fillResult->info.rows;
|
||||
}
|
||||
|
||||
return fillResult;
|
||||
(*ppRes) = fillResult;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doFill(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doFillNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
void destroyFillOperatorInfo(void* param) {
|
||||
|
@ -374,8 +384,9 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t
|
|||
|
||||
// STimeWindow w = {0};
|
||||
// getInitialStartTimeWindow(pInterval, startKey, &w, order == TSDB_ORDER_ASC);
|
||||
pInfo->pFillInfo = taosCreateFillInfo(startKey, numOfCols, numOfNotFillCols, capacity, pInterval, fillType, pColInfo,
|
||||
pInfo->primaryTsCol, order, id, pTaskInfo);
|
||||
pInfo->pFillInfo = NULL;
|
||||
taosCreateFillInfo(startKey, numOfCols, numOfNotFillCols, capacity, pInterval, fillType, pColInfo,
|
||||
pInfo->primaryTsCol, order, id, pTaskInfo, &pInfo->pFillInfo);
|
||||
|
||||
if (order == TSDB_ORDER_ASC) {
|
||||
pInfo->win.skey = win.skey;
|
||||
|
|
|
@ -460,9 +460,10 @@ _end:
|
|||
return (pRes->info.rows == 0) ? NULL : pRes;
|
||||
}
|
||||
|
||||
static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
|
||||
static int32_t hashGroupbyAggregateNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
@ -471,7 +472,8 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
|
|||
|
||||
SGroupbyOperatorInfo* pInfo = pOperator->info;
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
return buildGroupResultDataBlockByHash(pOperator);
|
||||
(*ppRes) = buildGroupResultDataBlockByHash(pOperator);
|
||||
return code;
|
||||
}
|
||||
SGroupResInfo* pGroupResInfo = &pInfo->groupResInfo;
|
||||
|
||||
|
@ -523,7 +525,14 @@ _end:
|
|||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
return buildGroupResultDataBlockByHash(pOperator);
|
||||
(*ppRes) = buildGroupResultDataBlockByHash(pOperator);
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = hashGroupbyAggregateNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode, SExecTaskInfo* pTaskInfo) {
|
||||
|
@ -978,9 +987,10 @@ _end:
|
|||
return pInfo->binfo.pRes;
|
||||
}
|
||||
|
||||
static SSDataBlock* hashPartition(SOperatorInfo* pOperator) {
|
||||
static int32_t hashPartitionNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
@ -990,7 +1000,8 @@ static SSDataBlock* hashPartition(SOperatorInfo* pOperator) {
|
|||
SSDataBlock* pRes = pInfo->binfo.pRes;
|
||||
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
return buildPartitionResult(pOperator);
|
||||
(*ppRes) = buildPartitionResult(pOperator);
|
||||
return code;
|
||||
}
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
@ -1005,21 +1016,21 @@ static SSDataBlock* hashPartition(SOperatorInfo* pOperator) {
|
|||
pInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
|
||||
// there is an scalar expression that needs to be calculated right before apply the group aggregation.
|
||||
if (pInfo->scalarSup.pExprInfo != NULL) {
|
||||
pTaskInfo->code = projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
|
||||
pInfo->scalarSup.numOfExprs, NULL);
|
||||
if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
|
||||
}
|
||||
code = projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
|
||||
pInfo->scalarSup.numOfExprs, NULL);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
doHashPartition(pOperator, pBlock);
|
||||
if (terrno != TSDB_CODE_SUCCESS) { // group by json error
|
||||
T_LONG_JMP(pTaskInfo->env, terrno);
|
||||
code = terrno;
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
}
|
||||
}
|
||||
|
||||
SArray* groupArray = taosArrayInit(taosHashGetSize(pInfo->pGroupSet), sizeof(SDataGroupInfo));
|
||||
QUERY_CHECK_NULL(groupArray, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||
|
||||
void* pGroupIter = taosHashIterate(pInfo->pGroupSet, NULL);
|
||||
while (pGroupIter != NULL) {
|
||||
|
@ -1043,10 +1054,18 @@ static SSDataBlock* hashPartition(SOperatorInfo* pOperator) {
|
|||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
|
||||
return buildPartitionResult(pOperator);
|
||||
(*ppRes) = buildPartitionResult(pOperator);
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* hashPartition(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = hashPartitionNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static void destroyPartitionOperatorInfo(void* param) {
|
||||
|
@ -1413,26 +1432,29 @@ _end:
|
|||
}
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamHashPartition(SOperatorInfo* pOperator) {
|
||||
static int32_t doStreamHashPartitionNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SStreamPartitionOperatorInfo* pInfo = pOperator->info;
|
||||
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (hasRemainTbName(pInfo)) {
|
||||
code = buildStreamCreateTableResult(pOperator);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
if (pInfo->pCreateTbRes && pInfo->pCreateTbRes->info.rows > 0) {
|
||||
return pInfo->pCreateTbRes;
|
||||
(*ppRes) = pInfo->pCreateTbRes;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasRemainPartion(pInfo)) {
|
||||
return buildStreamPartitionResult(pOperator);
|
||||
(*ppRes) = buildStreamPartitionResult(pOperator);
|
||||
return code;
|
||||
}
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
@ -1442,7 +1464,8 @@ static SSDataBlock* doStreamHashPartition(SOperatorInfo* pOperator) {
|
|||
SSDataBlock* pBlock = getNextBlockFromDownstream(pOperator, 0);
|
||||
if (pBlock == NULL) {
|
||||
setOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
printSpecDataBlock(pBlock, getStreamOpName(pOperator->operatorType), "recv", GET_TASKID(pTaskInfo));
|
||||
switch (pBlock->info.type) {
|
||||
|
@ -1457,13 +1480,15 @@ static SSDataBlock* doStreamHashPartition(SOperatorInfo* pOperator) {
|
|||
|
||||
pInfo->pDelRes->info.type = STREAM_DELETE_RESULT;
|
||||
printDataBlock(pInfo->pDelRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pInfo->pDelRes;
|
||||
(*ppRes) = pInfo->pDelRes;
|
||||
return code;
|
||||
} break;
|
||||
case STREAM_CREATE_CHILD_TABLE:
|
||||
case STREAM_RETRIEVE:
|
||||
case STREAM_CHECKPOINT:
|
||||
case STREAM_GET_ALL: {
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
}
|
||||
default:
|
||||
ASSERTS(0, "invalid SSDataBlock type");
|
||||
|
@ -1485,15 +1510,25 @@ static SSDataBlock* doStreamHashPartition(SOperatorInfo* pOperator) {
|
|||
code = buildStreamCreateTableResult(pOperator);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
if (pInfo->pCreateTbRes && pInfo->pCreateTbRes->info.rows > 0) {
|
||||
return pInfo->pCreateTbRes;
|
||||
(*ppRes) = pInfo->pCreateTbRes;
|
||||
return code;
|
||||
}
|
||||
return buildStreamPartitionResult(pOperator);
|
||||
(*ppRes) = buildStreamPartitionResult(pOperator);
|
||||
return code;
|
||||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pTaskInfo->code = code;
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
}
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamHashPartition(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doStreamHashPartitionNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static void destroyStreamPartitionOperatorInfo(void* param) {
|
||||
|
|
|
@ -842,23 +842,24 @@ static SSDataBlock* getBlockForEmptyTable(SOperatorInfo* pOperator, const STable
|
|||
return pBlock;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
|
||||
static int32_t doTableScanImplNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
STableScanInfo* pTableScanInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SStorageAPI* pAPI = &pTaskInfo->storageAPI;
|
||||
|
||||
SSDataBlock* pBlock = pTableScanInfo->pResBlock;
|
||||
bool hasNext = false;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
pBlock->info.dataLoad = false;
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
||||
while (true) {
|
||||
code = pAPI->tsdReader.tsdNextDataBlock(pTableScanInfo->base.dataReader, &hasNext);
|
||||
if (code) {
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pAPI->tsdReader.tsdReaderReleaseDataBlock(pTableScanInfo->base.dataReader);
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
}
|
||||
|
||||
if (!hasNext) {
|
||||
|
@ -887,9 +888,7 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
|
|||
|
||||
uint32_t status = 0;
|
||||
code = loadDataBlock(pOperator, &pTableScanInfo->base, pBlock, &status);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
if (status == FUNC_DATA_REQUIRED_ALL_FILTEROUT) {
|
||||
break;
|
||||
|
@ -905,9 +904,24 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
|
|||
|
||||
pOperator->cost.totalCost = pTableScanInfo->base.readRecorder.elapsedTime;
|
||||
pBlock->info.scanFlag = pTableScanInfo->base.scanFlag;
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doTableScanImplNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static SSDataBlock* doGroupedTableScan(SOperatorInfo* pOperator) {
|
||||
|
@ -1177,7 +1191,7 @@ _end:
|
|||
return result;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
|
||||
static int32_t doTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
STableScanInfo* pInfo = pOperator->info;
|
||||
|
@ -1189,10 +1203,8 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
|
|||
code = createTableListInfoFromParam(pOperator);
|
||||
freeOperatorParam(pOperator->pOperatorGetParam, OP_GET_PARAM);
|
||||
pOperator->pOperatorGetParam = NULL;
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
pInfo->currentGroupId = -1;
|
||||
pOperator->status = OP_OPENED;
|
||||
|
@ -1200,7 +1212,8 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
|
|||
while (true) {
|
||||
result = startNextGroupScan(pOperator);
|
||||
if (result || pOperator->status == OP_EXEC_DONE) {
|
||||
return result;
|
||||
(*ppRes) = result;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1215,7 +1228,8 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
|
|||
while (1) {
|
||||
SSDataBlock* result = doGroupedTableScan(pOperator);
|
||||
if (result || (pOperator->status == OP_EXEC_DONE) || isTaskKilled(pTaskInfo)) {
|
||||
return result;
|
||||
(*ppRes) = result;
|
||||
return code;
|
||||
}
|
||||
|
||||
// if no data, switch to next table and continue scan
|
||||
|
@ -1227,7 +1241,8 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
|
|||
if (pInfo->currentTable >= numOfTables) {
|
||||
qDebug("all table checked in table list, total:%d, return NULL, %s", numOfTables, GET_TASKID(pTaskInfo));
|
||||
taosRUnLockLatch(&pTaskInfo->lock);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
tInfo = *(STableKeyInfo*)tableListGetInfo(pInfo->base.pTableListInfo, pInfo->currentTable);
|
||||
|
@ -1243,7 +1258,8 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
|
|||
pInfo->scanTimes = 0;
|
||||
}
|
||||
} else { // scan table group by group sequentially
|
||||
return groupSeqTableScan(pOperator);
|
||||
(*ppRes) = groupSeqTableScan(pOperator);
|
||||
return code;
|
||||
}
|
||||
|
||||
_end:
|
||||
|
@ -1252,7 +1268,14 @@ _end:
|
|||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doTableScanNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static int32_t getTableScannerExecInfo(struct SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) {
|
||||
|
@ -2648,7 +2671,7 @@ static void processPrimaryKey(SSDataBlock* pBlock, bool hasPrimaryKey, STqOffset
|
|||
tqOffsetResetToData(offset, pBlock->info.id.uid, pBlock->info.window.ekey, val);
|
||||
}
|
||||
|
||||
static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
||||
static int32_t doQueueScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
@ -2660,7 +2683,8 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
|||
qDebug("start to exec queue scan, %s", id);
|
||||
|
||||
if (isTaskKilled(pTaskInfo)) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
|
@ -2672,7 +2696,8 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
|||
processPrimaryKey(pResult, hasPrimaryKey, &pTaskInfo->streamInfo.currentOffset);
|
||||
qDebug("tmqsnap doQueueScan get data uid:%" PRId64 "", pResult->info.id.uid);
|
||||
if (pResult->info.rows > 0) {
|
||||
return pResult;
|
||||
(*ppRes) = pResult;
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
|
@ -2686,7 +2711,8 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
|||
int64_t validVer = pTaskInfo->streamInfo.snapshotVer + 1;
|
||||
qDebug("queue scan tsdb over, switch to wal ver %" PRId64 "", validVer);
|
||||
if (pAPI->tqReaderFn.tqReaderSeek(pInfo->tqReader, validVer, pTaskInfo->id.str) < 0) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
tqOffsetResetToLog(&pTaskInfo->streamInfo.currentOffset, validVer);
|
||||
|
@ -2716,23 +2742,34 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
|||
qDebug("doQueueScan after filter get data from log %" PRId64 " rows, version:%" PRId64, pInfo->pRes->info.rows,
|
||||
pTaskInfo->streamInfo.currentOffset.version);
|
||||
if (pInfo->pRes->info.rows > 0) {
|
||||
return pInfo->pRes;
|
||||
(*ppRes) = pInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
qDebug("doQueueScan get none from log, return, version:%" PRId64, pTaskInfo->streamInfo.currentOffset.version);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qError("unexpected streamInfo prepare type: %d", pTaskInfo->streamInfo.currentOffset.type);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pTaskInfo->code = code;
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
}
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doQueueScanNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static int32_t filterDelBlockByUid(SSDataBlock* pDst, const SSDataBlock* pSrc, SStreamScanInfo* pInfo) {
|
||||
|
@ -2923,7 +2960,7 @@ static bool isStreamWindow(SStreamScanInfo* pInfo) {
|
|||
return isIntervalWindow(pInfo) || isSessionWindow(pInfo) || isStateWindow(pInfo) || isCountWindow(pInfo);
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
||||
static int32_t doStreamScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
// NOTE: this operator does never check if current status is done or not
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
|
@ -2973,7 +3010,8 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
if (pStreamInfo->recoverStep == STREAM_RECOVER_STEP__SCAN1) {
|
||||
if (isTaskKilled(pTaskInfo)) {
|
||||
qInfo("===stream===stream scan is killed. task id:%s, code %s", id, tstrerror(pTaskInfo->code));
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
switch (pInfo->scanMode) {
|
||||
|
@ -2981,7 +3019,8 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE;
|
||||
printSpecDataBlock(pInfo->pRecoverRes, getStreamOpName(pOperator->operatorType), "recover",
|
||||
GET_TASKID(pTaskInfo));
|
||||
return pInfo->pRecoverRes;
|
||||
(*ppRes) = pInfo->pRecoverRes;
|
||||
return code;
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
|
@ -3002,13 +3041,15 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
pInfo->scanMode = STREAM_SCAN_FROM_RES;
|
||||
printSpecDataBlock(pInfo->pCreateTbRes, getStreamOpName(pOperator->operatorType), "recover",
|
||||
GET_TASKID(pTaskInfo));
|
||||
return pInfo->pCreateTbRes;
|
||||
(*ppRes) = pInfo->pCreateTbRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
qDebug("stream recover scan get block, rows %" PRId64, pInfo->pRecoverRes->info.rows);
|
||||
printSpecDataBlock(pInfo->pRecoverRes, getStreamOpName(pOperator->operatorType), "recover",
|
||||
GET_TASKID(pTaskInfo));
|
||||
return pInfo->pRecoverRes;
|
||||
(*ppRes) = pInfo->pRecoverRes;
|
||||
return code;
|
||||
}
|
||||
pStreamInfo->recoverStep = STREAM_RECOVER_STEP__NONE;
|
||||
STableScanInfo* pTSInfo = pInfo->pTableScanOp->info;
|
||||
|
@ -3020,7 +3061,8 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
pTSInfo->base.cond.endVersion = -1;
|
||||
|
||||
pStreamInfo->recoverScanFinished = true;
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
size_t total = taosArrayGetSize(pInfo->pBlockLists);
|
||||
|
@ -3029,7 +3071,8 @@ FETCH_NEXT_BLOCK:
|
|||
if (pInfo->blockType == STREAM_INPUT__DATA_BLOCK) {
|
||||
if (pInfo->validBlockIndex >= total) {
|
||||
doClearBufferedBlocks(pInfo);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t current = pInfo->validBlockIndex++;
|
||||
|
@ -3060,7 +3103,8 @@ FETCH_NEXT_BLOCK:
|
|||
case STREAM_GET_ALL:
|
||||
printDataBlock(pBlock, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
setStreamOperatorState(&pInfo->basic, pBlock->info.type);
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
case STREAM_RETRIEVE: {
|
||||
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
||||
pInfo->scanMode = STREAM_SCAN_FROM_DATAREADER_RETRIEVE;
|
||||
|
@ -3107,7 +3151,8 @@ FETCH_NEXT_BLOCK:
|
|||
printSpecDataBlock(pInfo->pDeleteDataRes, getStreamOpName(pOperator->operatorType), "delete result",
|
||||
GET_TASKID(pTaskInfo));
|
||||
setStreamOperatorState(&pInfo->basic, pInfo->pDeleteDataRes->info.type);
|
||||
return pInfo->pDeleteDataRes;
|
||||
(*ppRes) = pInfo->pDeleteDataRes;
|
||||
return code;
|
||||
} else {
|
||||
goto FETCH_NEXT_BLOCK;
|
||||
}
|
||||
|
@ -3128,7 +3173,8 @@ FETCH_NEXT_BLOCK:
|
|||
printSpecDataBlock(pInfo->pDeleteDataRes, getStreamOpName(pOperator->operatorType), "delete result",
|
||||
GET_TASKID(pTaskInfo));
|
||||
setStreamOperatorState(&pInfo->basic, pInfo->pDeleteDataRes->info.type);
|
||||
return pInfo->pDeleteDataRes;
|
||||
(*ppRes) = pInfo->pDeleteDataRes;
|
||||
return code;
|
||||
} else {
|
||||
goto FETCH_NEXT_BLOCK;
|
||||
}
|
||||
|
@ -3142,7 +3188,8 @@ FETCH_NEXT_BLOCK:
|
|||
}
|
||||
printDataBlock(pBlock, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
setStreamOperatorState(&pInfo->basic, pBlock->info.type);
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
} else if (pInfo->blockType == STREAM_INPUT__DATA_SUBMIT) {
|
||||
qDebug("stream scan mode:%d, %s", pInfo->scanMode, id);
|
||||
switch (pInfo->scanMode) {
|
||||
|
@ -3158,7 +3205,8 @@ FETCH_NEXT_BLOCK:
|
|||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
if (pInfo->pRes->info.rows > 0) {
|
||||
printDataBlock(pInfo->pRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pInfo->pRes;
|
||||
(*ppRes) = pInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
} break;
|
||||
case STREAM_SCAN_FROM_DELETE_DATA: {
|
||||
|
@ -3169,14 +3217,16 @@ FETCH_NEXT_BLOCK:
|
|||
code = copyDataBlock(pInfo->pDeleteDataRes, pInfo->pUpdateRes);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
pInfo->pDeleteDataRes->info.type = STREAM_DELETE_DATA;
|
||||
return pInfo->pDeleteDataRes;
|
||||
(*ppRes) = pInfo->pDeleteDataRes;
|
||||
return code;
|
||||
} break;
|
||||
case STREAM_SCAN_FROM_UPDATERES: {
|
||||
code = generateScanRange(pInfo, pInfo->pUpdateDataRes, pInfo->pUpdateRes, STREAM_CLEAR);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
prepareRangeScan(pInfo, pInfo->pUpdateRes, &pInfo->updateResIndex, NULL);
|
||||
pInfo->scanMode = STREAM_SCAN_FROM_DATAREADER_RANGE;
|
||||
return pInfo->pUpdateRes;
|
||||
(*ppRes) = pInfo->pUpdateRes;
|
||||
return code;
|
||||
} break;
|
||||
case STREAM_SCAN_FROM_DATAREADER_RANGE:
|
||||
case STREAM_SCAN_FROM_DATAREADER_RETRIEVE: {
|
||||
|
@ -3193,7 +3243,8 @@ FETCH_NEXT_BLOCK:
|
|||
printSpecDataBlock(pSDB, getStreamOpName(pOperator->operatorType), "update", GET_TASKID(pTaskInfo));
|
||||
code = calBlockTbName(pInfo, pSDB, 0);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
return pSDB;
|
||||
(*ppRes) = pSDB;
|
||||
return code;
|
||||
}
|
||||
blockDataCleanup(pInfo->pUpdateDataRes);
|
||||
pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE;
|
||||
|
@ -3212,7 +3263,8 @@ FETCH_NEXT_BLOCK:
|
|||
prepareRangeScan(pInfo, pInfo->pUpdateRes, &pInfo->updateResIndex, NULL);
|
||||
pInfo->pUpdateRes->info.type = STREAM_DELETE_DATA;
|
||||
printSpecDataBlock(pInfo->pUpdateRes, getStreamOpName(pOperator->operatorType), "rebuild", GET_TASKID(pTaskInfo));
|
||||
return pInfo->pUpdateRes;
|
||||
(*ppRes) = pInfo->pUpdateRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
SDataBlockInfo* pBlockInfo = &pInfo->pRes->info;
|
||||
|
@ -3226,7 +3278,8 @@ FETCH_NEXT_BLOCK:
|
|||
doClearBufferedBlocks(pInfo);
|
||||
|
||||
qDebug("stream scan return empty, all %d submit blocks consumed, %s", totalBlocks, id);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t current = pInfo->validBlockIndex++;
|
||||
|
@ -3264,7 +3317,8 @@ FETCH_NEXT_BLOCK:
|
|||
pInfo->scanMode = STREAM_SCAN_FROM_RES;
|
||||
qDebug("create table res exists, rows:%" PRId64 " return from stream scan, %s",
|
||||
pInfo->pCreateTbRes->info.rows, id);
|
||||
return pInfo->pCreateTbRes;
|
||||
(*ppRes) = pInfo->pCreateTbRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
code = doCheckUpdate(pInfo, pBlockInfo->window.ekey, pInfo->pRes);
|
||||
|
@ -3297,7 +3351,8 @@ FETCH_NEXT_BLOCK:
|
|||
qDebug("stream scan completed, and return source rows:%" PRId64 ", %s", pBlockInfo->rows, id);
|
||||
if (pBlockInfo->rows > 0) {
|
||||
printDataBlock(pInfo->pRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pInfo->pRes;
|
||||
(*ppRes) = pInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pInfo->pUpdateDataRes->info.rows > 0) {
|
||||
|
@ -3308,7 +3363,8 @@ FETCH_NEXT_BLOCK:
|
|||
} else if (pInfo->blockType == STREAM_INPUT__CHECKPOINT) {
|
||||
if (pInfo->validBlockIndex >= total) {
|
||||
doClearBufferedBlocks(pInfo);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t current = pInfo->validBlockIndex++;
|
||||
|
@ -3321,16 +3377,24 @@ FETCH_NEXT_BLOCK:
|
|||
streamScanOperatorSaveCheckpoint(pInfo);
|
||||
}
|
||||
// printDataBlock(pInfo->pCheckpointRes, "stream scan ck", GET_TASKID(pTaskInfo));
|
||||
return pInfo->pCheckpointRes;
|
||||
(*ppRes) = pInfo->pCheckpointRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pTaskInfo->code = code;
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
}
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doStreamScanNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
static int32_t extractTableIdList(const STableListInfo* pTableListInfo, SArray** ppArrayRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
|
@ -3353,7 +3417,7 @@ _end:
|
|||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
||||
static int32_t doRawScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
@ -3368,9 +3432,9 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
|||
bool hasNext = false;
|
||||
if (pInfo->dataReader && pInfo->sContext->withMeta != ONLY_META) {
|
||||
code = pAPI->tsdReader.tsdNextDataBlock(pInfo->dataReader, &hasNext);
|
||||
if (code) {
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pAPI->tsdReader.tsdReaderReleaseDataBlock(pInfo->dataReader);
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3382,15 +3446,14 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
|||
|
||||
SSDataBlock* pBlock = NULL;
|
||||
code = pAPI->tsdReader.tsdReaderRetrieveDataBlock(pInfo->dataReader, &pBlock, NULL);
|
||||
if (pBlock == NULL || code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, terrno);
|
||||
}
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
if (pBlock && pBlock->info.rows > 0) {
|
||||
bool hasPrimaryKey = pAPI->snapshotFn.taosXGetTablePrimaryKey(pInfo->sContext);
|
||||
processPrimaryKey(pBlock, hasPrimaryKey, &pTaskInfo->streamInfo.currentOffset);
|
||||
qDebug("tmqsnap doRawScan get data uid:%" PRId64 "", pBlock->info.id.uid);
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3407,7 +3470,8 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
|||
code = qStreamPrepareScan(pTaskInfo, &offset, pInfo->sContext->subType);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
tDeleteSchemaWrapper(mtInfo.schema);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
} else if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__SNAPSHOT_META) {
|
||||
SSnapContext* sContext = pInfo->sContext;
|
||||
for (int32_t i = 0; i < tmqRowSize; i++) {
|
||||
|
@ -3441,22 +3505,24 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
|||
pTaskInfo->streamInfo.btMetaRsp.batchMetaLen = taosArrayInit(4, sizeof(int32_t));
|
||||
QUERY_CHECK_NULL(pTaskInfo->streamInfo.btMetaRsp.batchMetaLen, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t tempRes = TSDB_CODE_SUCCESS;
|
||||
uint32_t len = 0;
|
||||
tEncodeSize(tEncodeMqMetaRsp, &tmpMetaRsp, len, code);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tEncodeSize(tEncodeMqMetaRsp, &tmpMetaRsp, len, tempRes);
|
||||
if (TSDB_CODE_SUCCESS != tempRes) {
|
||||
qError("tmqsnap tEncodeMqMetaRsp error");
|
||||
taosMemoryFreeClear(data);
|
||||
break;
|
||||
}
|
||||
|
||||
int32_t tLen = sizeof(SMqRspHead) + len;
|
||||
void* tBuf = taosMemoryCalloc(1, tLen);
|
||||
int32_t tLen = sizeof(SMqRspHead) + len;
|
||||
void* tBuf = taosMemoryCalloc(1, tLen);
|
||||
QUERY_CHECK_NULL(tBuf, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||
|
||||
void* metaBuff = POINTER_SHIFT(tBuf, sizeof(SMqRspHead));
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, metaBuff, len);
|
||||
code = tEncodeMqMetaRsp(&encoder, &tmpMetaRsp);
|
||||
if (code < 0) {
|
||||
int32_t tempLen = tEncodeMqMetaRsp(&encoder, &tmpMetaRsp);
|
||||
if (tempLen < 0) {
|
||||
qError("tmqsnap tEncodeMqMetaRsp error");
|
||||
tEncoderClear(&encoder);
|
||||
taosMemoryFreeClear(tBuf);
|
||||
|
@ -3471,7 +3537,8 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
|||
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
_end:
|
||||
|
@ -3480,7 +3547,14 @@ _end:
|
|||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doRawScanNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static void destroyRawScanOperatorInfo(void* param) {
|
||||
|
@ -3570,6 +3644,7 @@ void streamScanReleaseState(SOperatorInfo* pOperator) {
|
|||
return;
|
||||
}
|
||||
if (!pInfo->pUpdateInfo) {
|
||||
qDebug("stask:%s streamScanReleaseState cancel", GET_TASKID(pOperator->pTaskInfo));
|
||||
return;
|
||||
}
|
||||
int32_t len = 0;
|
||||
|
@ -3602,6 +3677,10 @@ void streamScanReloadState(SOperatorInfo* pOperator) {
|
|||
if (!pInfo->pState) {
|
||||
return;
|
||||
}
|
||||
if (!pInfo->pUpdateInfo) {
|
||||
qDebug("stask:%s streamScanReloadState cancel", GET_TASKID(pOperator->pTaskInfo));
|
||||
return;
|
||||
}
|
||||
void* pBuff = NULL;
|
||||
int32_t len = 0;
|
||||
code = pInfo->stateStore.streamStateGetInfo(pInfo->pState, STREAM_SCAN_OP_STATE_NAME,
|
||||
|
@ -4179,9 +4258,10 @@ _end:
|
|||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTagScanFromCtbIdx(SOperatorInfo* pOperator) {
|
||||
static int32_t doTagScanFromCtbIdxNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
|
@ -4268,12 +4348,21 @@ _end:
|
|||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
pOperator->resultInfo.totalRows += pRes->info.rows;
|
||||
return (pRes->info.rows == 0) ? NULL : pInfo->pRes;
|
||||
(*ppRes) = (pRes->info.rows == 0) ? NULL : pInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTagScanFromMetaEntry(SOperatorInfo* pOperator) {
|
||||
static SSDataBlock* doTagScanFromCtbIdx(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doTagScanFromCtbIdxNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static int32_t doTagScanFromMetaEntryNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
@ -4287,7 +4376,8 @@ static SSDataBlock* doTagScanFromMetaEntry(SOperatorInfo* pOperator) {
|
|||
int32_t size = tableListGetSize(pInfo->pTableListInfo);
|
||||
if (size == 0) {
|
||||
setTaskStatus(pTaskInfo, TASK_COMPLETED);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
char str[512] = {0};
|
||||
|
@ -4316,7 +4406,14 @@ static SSDataBlock* doTagScanFromMetaEntry(SOperatorInfo* pOperator) {
|
|||
|
||||
pOperator->resultInfo.totalRows += pRes->info.rows;
|
||||
|
||||
return (pRes->info.rows == 0) ? NULL : pInfo->pRes;
|
||||
(*ppRes) = (pRes->info.rows == 0) ? NULL : pInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTagScanFromMetaEntry(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doTagScanFromMetaEntryNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static void destroyTagScanOperatorInfo(void* param) {
|
||||
|
@ -4849,9 +4946,10 @@ static void stopSubTablesTableMergeScan(STableMergeScanInfo* pInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
SSDataBlock* doTableMergeScanParaSubTables(SOperatorInfo* pOperator) {
|
||||
int32_t doTableMergeScanParaSubTablesNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
@ -4871,7 +4969,8 @@ SSDataBlock* doTableMergeScanParaSubTables(SOperatorInfo* pOperator) {
|
|||
|
||||
if (tableListSize == 0) {
|
||||
setOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
pInfo->tableStartIndex = 0;
|
||||
pInfo->groupId = ((STableKeyInfo*)tableListGetInfo(pInfo->base.pTableListInfo, pInfo->tableStartIndex))->groupId;
|
||||
|
@ -4919,7 +5018,14 @@ _end:
|
|||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTableMergeScanParaSubTables(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doTableMergeScanParaSubTablesNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static void tableMergeScanDoSkipTable(uint64_t uid, void* pTableMergeOpInfo) {
|
||||
|
@ -5312,18 +5418,19 @@ SSDataBlock* getSortedTableMergeScanBlockData(SSortHandle* pHandle, SSDataBlock*
|
|||
return (pResBlock->info.rows > 0) ? pResBlock : NULL;
|
||||
}
|
||||
|
||||
SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) {
|
||||
int32_t doTableMergeScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
STableMergeScanInfo* pInfo = pOperator->info;
|
||||
|
||||
int32_t code = pOperator->fpSet._openFn(pOperator);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
code = pOperator->fpSet._openFn(pOperator);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
||||
|
@ -5333,7 +5440,8 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) {
|
|||
|
||||
if (tableListSize == 0) {
|
||||
setOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
pInfo->tableStartIndex = 0;
|
||||
pInfo->groupId = ((STableKeyInfo*)tableListGetInfo(pInfo->base.pTableListInfo, pInfo->tableStartIndex))->groupId;
|
||||
|
@ -5361,9 +5469,7 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) {
|
|||
if (pInfo->bNewFilesetEvent) {
|
||||
stopDurationForGroupTableMergeScan(pOperator);
|
||||
code = startDurationForGroupTableMergeScan(pOperator);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, terrno);
|
||||
}
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
} else {
|
||||
// Data of this group are all dumped, let's try the next group
|
||||
stopGroupTableMergeScan(pOperator);
|
||||
|
@ -5382,7 +5488,20 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) {
|
|||
|
||||
pOperator->cost.totalCost += (taosGetTimestampUs() - st) / 1000.0;
|
||||
|
||||
return pBlock;
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doTableMergeScanNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
void destroyTableMergeScanOperatorInfo(void* param) {
|
||||
|
@ -5841,7 +5960,8 @@ _end:
|
|||
}
|
||||
}
|
||||
|
||||
static SSDataBlock* doTableCountScan(SOperatorInfo* pOperator) {
|
||||
static int32_t doTableCountScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
STableCountScanOperatorInfo* pInfo = pOperator->info;
|
||||
STableCountScanSupp* pSupp = &pInfo->supp;
|
||||
|
@ -5849,13 +5969,22 @@ static SSDataBlock* doTableCountScan(SOperatorInfo* pOperator) {
|
|||
blockDataCleanup(pRes);
|
||||
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
if (pInfo->readHandle.mnd != NULL) {
|
||||
return buildSysDbTableCount(pOperator, pInfo);
|
||||
(*ppRes) = buildSysDbTableCount(pOperator, pInfo);
|
||||
return code;
|
||||
}
|
||||
|
||||
return buildVnodeDbTableCount(pOperator, pInfo, pSupp, pRes);
|
||||
(*ppRes) = buildVnodeDbTableCount(pOperator, pInfo, pSupp, pRes);
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTableCountScan(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doTableCountScanNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static SSDataBlock* buildVnodeDbTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo,
|
||||
|
|
|
@ -357,12 +357,13 @@ static void doStreamCountAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBl
|
|||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
destroySBuffInfo(pAggSup, &buffInfo);
|
||||
}
|
||||
|
||||
static SSDataBlock* buildCountResult(SOperatorInfo* pOperator) {
|
||||
static int32_t buildCountResult(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SStreamCountAggOperatorInfo* pInfo = pOperator->info;
|
||||
SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
|
||||
SOptrBasicInfo* pBInfo = &pInfo->binfo;
|
||||
|
@ -370,15 +371,18 @@ static SSDataBlock* buildCountResult(SOperatorInfo* pOperator) {
|
|||
doBuildDeleteDataBlock(pOperator, pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
|
||||
if (pInfo->pDelRes->info.rows > 0) {
|
||||
printDataBlock(pInfo->pDelRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pInfo->pDelRes;
|
||||
(*ppRes) = pInfo->pDelRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
doBuildSessionResult(pOperator, pAggSup->pState, &pInfo->groupResInfo, pBInfo->pRes);
|
||||
if (pBInfo->pRes->info.rows > 0) {
|
||||
printDataBlock(pBInfo->pRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pBInfo->pRes;
|
||||
(*ppRes) = pBInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t doStreamCountEncodeOpState(void** buf, int32_t len, SOperatorInfo* pOperator, bool isParent) {
|
||||
|
@ -425,6 +429,7 @@ int32_t doStreamCountDecodeOpState(void* buf, int32_t len, SOperatorInfo* pOpera
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SStreamCountAggOperatorInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
if (!pInfo) {
|
||||
code = TSDB_CODE_FAILED;
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
@ -465,7 +470,7 @@ int32_t doStreamCountDecodeOpState(void* buf, int32_t len, SOperatorInfo* pOpera
|
|||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -475,6 +480,7 @@ void doStreamCountSaveCheckpoint(SOperatorInfo* pOperator) {
|
|||
int32_t lino = 0;
|
||||
void* pBuf = NULL;
|
||||
SStreamCountAggOperatorInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
if (needSaveStreamOperatorInfo(&pInfo->basic)) {
|
||||
int32_t len = doStreamCountEncodeOpState(NULL, 0, pOperator, true);
|
||||
pBuf = taosMemoryCalloc(1, len);
|
||||
|
@ -492,7 +498,7 @@ void doStreamCountSaveCheckpoint(SOperatorInfo* pOperator) {
|
|||
_end:
|
||||
taosMemoryFreeClear(pBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -604,7 +610,7 @@ _end:
|
|||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamCountAgg(SOperatorInfo* pOperator) {
|
||||
static int32_t doStreamCountAggNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SExprSupp* pSup = &pOperator->exprSupp;
|
||||
|
@ -614,11 +620,15 @@ static SSDataBlock* doStreamCountAgg(SOperatorInfo* pOperator) {
|
|||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
qDebug("stask:%s %s status: %d", GET_TASKID(pTaskInfo), getStreamOpName(pOperator->operatorType), pOperator->status);
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
} else if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
SSDataBlock* opRes = buildCountResult(pOperator);
|
||||
SSDataBlock* opRes = NULL;
|
||||
code = buildCountResult(pOperator, &opRes);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
if (opRes) {
|
||||
return opRes;
|
||||
(*ppRes) = opRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pInfo->recvGetAll) {
|
||||
|
@ -629,11 +639,13 @@ static SSDataBlock* doStreamCountAgg(SOperatorInfo* pOperator) {
|
|||
if (pInfo->reCkBlock) {
|
||||
pInfo->reCkBlock = false;
|
||||
printDataBlock(pInfo->pCheckpointRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pInfo->pCheckpointRes;
|
||||
(*ppRes) = pInfo->pCheckpointRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
setStreamOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
SOperatorInfo* downstream = pOperator->pDownstream[0];
|
||||
|
@ -667,7 +679,8 @@ static SSDataBlock* doStreamCountAgg(SOperatorInfo* pOperator) {
|
|||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
continue;
|
||||
} else if (pBlock->info.type == STREAM_CREATE_CHILD_TABLE) {
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
} else if (pBlock->info.type == STREAM_CHECKPOINT) {
|
||||
pAggSup->stateStore.streamStateCommit(pAggSup->pState);
|
||||
doStreamCountSaveCheckpoint(pOperator);
|
||||
|
@ -710,29 +723,39 @@ static SSDataBlock* doStreamCountAgg(SOperatorInfo* pOperator) {
|
|||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
}
|
||||
|
||||
SSDataBlock* opRes = buildCountResult(pOperator);
|
||||
SSDataBlock* opRes = NULL;
|
||||
code = buildCountResult(pOperator, &opRes);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
if (opRes) {
|
||||
return opRes;
|
||||
(*ppRes) = opRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
setStreamOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamCountAgg(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doStreamCountAggNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
void streamCountReleaseState(SOperatorInfo* pOperator) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SStreamEventAggOperatorInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
int32_t resSize = sizeof(TSKEY);
|
||||
char* pBuff = taosMemoryCalloc(1, resSize);
|
||||
if (pBuff) {
|
||||
code = terrno;
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
}
|
||||
QUERY_CHECK_NULL(pBuff, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||
|
||||
memcpy(pBuff, &pInfo->twAggSup.maxTs, sizeof(TSKEY));
|
||||
qDebug("===stream=== count window operator relase state. ");
|
||||
pInfo->streamAggSup.stateStore.streamStateSaveInfo(pInfo->streamAggSup.pState, STREAM_COUNT_OP_STATE_NAME,
|
||||
|
@ -745,7 +768,8 @@ void streamCountReleaseState(SOperatorInfo* pOperator) {
|
|||
}
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
terrno = code;
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -753,6 +777,7 @@ void streamCountReloadState(SOperatorInfo* pOperator) {
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SStreamCountAggOperatorInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
|
||||
int32_t size = 0;
|
||||
void* pBuf = NULL;
|
||||
|
@ -773,7 +798,8 @@ void streamCountReloadState(SOperatorInfo* pOperator) {
|
|||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
terrno = code;
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -882,6 +908,6 @@ _error:
|
|||
|
||||
taosMemoryFreeClear(pOperator);
|
||||
pTaskInfo->code = code;
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -285,7 +285,7 @@ static int32_t compactEventWindow(SOperatorInfo* pOperator, SEventWindowInfo* pC
|
|||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -382,8 +382,8 @@ static void doStreamEventAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBl
|
|||
&curWin.winInfo.sessionWin.win.ekey, &uid, &groupId, NULL);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
code = tSimpleHashRemove(pSeUpdated, &curWin.winInfo.sessionWin, sizeof(SSessionKey));
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
int32_t tmpRes = tSimpleHashRemove(pSeUpdated, &curWin.winInfo.sessionWin, sizeof(SSessionKey));
|
||||
qTrace("%s at line %d res:%d", __func__, __LINE__, tmpRes);
|
||||
|
||||
doDeleteEventWindow(pAggSup, pSeUpdated, &curWin.winInfo.sessionWin);
|
||||
if (pInfo->destHasPrimaryKey && curWin.winInfo.isOutput && IS_NORMAL_EVENT_OP(pOperator) &&
|
||||
|
@ -444,7 +444,7 @@ _end:
|
|||
colDataDestroy(pColEnd);
|
||||
taosMemoryFree(pColEnd);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -490,6 +490,7 @@ int32_t doStreamEventDecodeOpState(void* buf, int32_t len, SOperatorInfo* pOpera
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SStreamEventAggOperatorInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
if (!pInfo) {
|
||||
code = TSDB_CODE_FAILED;
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
@ -532,7 +533,7 @@ int32_t doStreamEventDecodeOpState(void* buf, int32_t len, SOperatorInfo* pOpera
|
|||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -555,7 +556,8 @@ void doStreamEventSaveCheckpoint(SOperatorInfo* pOperator) {
|
|||
}
|
||||
}
|
||||
|
||||
static SSDataBlock* buildEventResult(SOperatorInfo* pOperator) {
|
||||
static int32_t buildEventResult(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SStreamEventAggOperatorInfo* pInfo = pOperator->info;
|
||||
SOptrBasicInfo* pBInfo = &pInfo->binfo;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
@ -563,20 +565,24 @@ static SSDataBlock* buildEventResult(SOperatorInfo* pOperator) {
|
|||
doBuildDeleteDataBlock(pOperator, pInfo->pSeDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
|
||||
if (pInfo->pDelRes->info.rows > 0) {
|
||||
printDataBlock(pInfo->pDelRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pInfo->pDelRes;
|
||||
(*ppRes) = pInfo->pDelRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
doBuildSessionResult(pOperator, pInfo->streamAggSup.pState, &pInfo->groupResInfo, pBInfo->pRes);
|
||||
if (pBInfo->pRes->info.rows > 0) {
|
||||
printDataBlock(pBInfo->pRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pBInfo->pRes;
|
||||
(*ppRes) = pBInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamEventAgg(SOperatorInfo* pOperator) {
|
||||
static int32_t doStreamEventAggNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
@ -585,11 +591,14 @@ static SSDataBlock* doStreamEventAgg(SOperatorInfo* pOperator) {
|
|||
SStreamEventAggOperatorInfo* pInfo = pOperator->info;
|
||||
SOptrBasicInfo* pBInfo = &pInfo->binfo;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
qDebug("===stream=== stream event agg");
|
||||
qDebug("===stream=== stream event agg. history task:%d, taskId:%s", pInfo->isHistoryOp, GET_TASKID(pTaskInfo));
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
SSDataBlock* resBlock = buildEventResult(pOperator);
|
||||
SSDataBlock* resBlock = NULL;
|
||||
code = buildEventResult(pOperator, &resBlock);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
if (resBlock != NULL) {
|
||||
return resBlock;
|
||||
(*ppRes) = resBlock;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pInfo->recvGetAll) {
|
||||
|
@ -600,11 +609,13 @@ static SSDataBlock* doStreamEventAgg(SOperatorInfo* pOperator) {
|
|||
if (pInfo->reCkBlock) {
|
||||
pInfo->reCkBlock = false;
|
||||
printDataBlock(pInfo->pCheckpointRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pInfo->pCheckpointRes;
|
||||
(*ppRes) = pInfo->pCheckpointRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
setStreamOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
SOperatorInfo* downstream = pOperator->pDownstream[0];
|
||||
|
@ -636,7 +647,8 @@ static SSDataBlock* doStreamEventAgg(SOperatorInfo* pOperator) {
|
|||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
continue;
|
||||
} else if (pBlock->info.type == STREAM_CREATE_CHILD_TABLE) {
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
} else if (pBlock->info.type == STREAM_CHECKPOINT) {
|
||||
pInfo->streamAggSup.stateStore.streamStateCommit(pInfo->streamAggSup.pState);
|
||||
doStreamEventSaveCheckpoint(pOperator);
|
||||
|
@ -680,6 +692,10 @@ static SSDataBlock* doStreamEventAgg(SOperatorInfo* pOperator) {
|
|||
code = copyUpdateResult(&pInfo->pAllUpdated, pHisWins, sessionKeyCompareAsc);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
|
||||
pInfo->pAllUpdated = tSimpleHashInit(64, hashFn);
|
||||
QUERY_CHECK_NULL(pInfo->pAllUpdated, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||
|
||||
code = getMaxTsWins(pHisWins, pInfo->historyWins);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
|
@ -695,17 +711,28 @@ static SSDataBlock* doStreamEventAgg(SOperatorInfo* pOperator) {
|
|||
code = blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
SSDataBlock* resBlock = buildEventResult(pOperator);
|
||||
SSDataBlock* resBlock = NULL;
|
||||
code = buildEventResult(pOperator, &resBlock);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
if (resBlock != NULL) {
|
||||
return resBlock;
|
||||
(*ppRes) = resBlock;
|
||||
return code;
|
||||
}
|
||||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
setStreamOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamEventAgg(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doStreamEventAggNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
void streamEventReleaseState(SOperatorInfo* pOperator) {
|
||||
|
@ -733,6 +760,7 @@ void streamEventReloadState(SOperatorInfo* pOperator) {
|
|||
int32_t lino = 0;
|
||||
SStreamEventAggOperatorInfo* pInfo = pOperator->info;
|
||||
SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
resetWinRange(&pAggSup->winRange);
|
||||
|
||||
SSessionKey seKey = {.win.skey = INT64_MIN, .win.ekey = INT64_MIN, .groupId = 0};
|
||||
|
@ -816,7 +844,7 @@ void streamEventReloadState(SOperatorInfo* pOperator) {
|
|||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -937,6 +965,6 @@ _error:
|
|||
destroyStreamEventOperatorInfo(pInfo);
|
||||
taosMemoryFreeClear(pOperator);
|
||||
pTaskInfo->code = code;
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -563,8 +563,7 @@ static void doStreamFillLinear(SStreamFillSupporter* pFillSup, SStreamFillInfo*
|
|||
code = checkResult(pFillSup, pFillInfo->current, groupId, &ckRes);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
if ((pFillSup->hasDelete && !ckRes) ||
|
||||
!inWinRange(&pFillSup->winRange, &st)) {
|
||||
if ((pFillSup->hasDelete && !ckRes) || !inWinRange(&pFillSup->winRange, &st)) {
|
||||
pFillInfo->current = taosTimeAdd(pFillInfo->current, pFillSup->interval.sliding, pFillSup->interval.slidingUnit,
|
||||
pFillSup->interval.precision);
|
||||
pFillInfo->pLinearInfo->winIndex++;
|
||||
|
@ -743,7 +742,7 @@ static void doStreamFillImpl(SOperatorInfo* pOperator) {
|
|||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -752,6 +751,7 @@ static int32_t buildDeleteRange(SOperatorInfo* pOp, TSKEY start, TSKEY end, uint
|
|||
int32_t lino = 0;
|
||||
SStorageAPI* pAPI = &pOp->pTaskInfo->storageAPI;
|
||||
void* pState = pOp->pTaskInfo->streamInfo.pState;
|
||||
SExecTaskInfo* pTaskInfo = pOp->pTaskInfo;
|
||||
SSDataBlock* pBlock = delRes;
|
||||
SColumnInfoData* pStartCol = taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX);
|
||||
SColumnInfoData* pEndCol = taosArrayGet(pBlock->pDataBlock, END_TS_COLUMN_INDEX);
|
||||
|
@ -794,7 +794,7 @@ static int32_t buildDeleteRange(SOperatorInfo* pOp, TSKEY start, TSKEY end, uint
|
|||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -805,6 +805,7 @@ static int32_t buildDeleteResult(SOperatorInfo* pOperator, TSKEY startTs, TSKEY
|
|||
int32_t lino = 0;
|
||||
SStreamFillOperatorInfo* pInfo = pOperator->info;
|
||||
SStreamFillSupporter* pFillSup = pInfo->pFillSup;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
if (hasPrevWindow(pFillSup)) {
|
||||
TSKEY start = getNextWindowTs(pFillSup->prev.key, &pFillSup->interval);
|
||||
code = buildDeleteRange(pOperator, start, endTs, groupId, delRes);
|
||||
|
@ -820,7 +821,7 @@ static int32_t buildDeleteResult(SOperatorInfo* pOperator, TSKEY startTs, TSKEY
|
|||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -830,6 +831,7 @@ static int32_t doDeleteFillResultImpl(SOperatorInfo* pOperator, TSKEY startTs, T
|
|||
int32_t lino = 0;
|
||||
SStorageAPI* pAPI = &pOperator->pTaskInfo->storageAPI;
|
||||
SStreamFillOperatorInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
getWindowFromDiscBuf(pOperator, startTs, groupId, pInfo->pFillSup);
|
||||
setDeleteFillValueInfo(startTs, endTs, pInfo->pFillSup, pInfo->pFillInfo);
|
||||
SWinKey key = {.ts = startTs, .groupId = groupId};
|
||||
|
@ -852,7 +854,7 @@ static int32_t doDeleteFillResultImpl(SOperatorInfo* pOperator, TSKEY startTs, T
|
|||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -911,6 +913,7 @@ static int32_t doDeleteFillResult(SOperatorInfo* pOperator) {
|
|||
SStreamFillOperatorInfo* pInfo = pOperator->info;
|
||||
SStreamFillInfo* pFillInfo = pInfo->pFillInfo;
|
||||
SSDataBlock* pBlock = pInfo->pSrcDelBlock;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
SColumnInfoData* pStartCol = taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX);
|
||||
TSKEY* tsStarts = (TSKEY*)pStartCol->pData;
|
||||
|
@ -967,7 +970,7 @@ static int32_t doDeleteFillResult(SOperatorInfo* pOperator) {
|
|||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -985,6 +988,7 @@ static int32_t doApplyStreamScalarCalculation(SOperatorInfo* pOperator, SSDataBl
|
|||
int32_t lino = 0;
|
||||
SStreamFillOperatorInfo* pInfo = pOperator->info;
|
||||
SExprSupp* pSup = &pOperator->exprSupp;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
blockDataCleanup(pDstBlock);
|
||||
code = blockDataEnsureCapacity(pDstBlock, pSrcBlock->info.rows);
|
||||
|
@ -1008,19 +1012,20 @@ static int32_t doApplyStreamScalarCalculation(SOperatorInfo* pOperator, SSDataBl
|
|||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) {
|
||||
static int32_t doStreamFillNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SStreamFillOperatorInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
blockDataCleanup(pInfo->pRes);
|
||||
if (hasRemainCalc(pInfo->pFillInfo) ||
|
||||
|
@ -1028,18 +1033,21 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) {
|
|||
doStreamFillRange(pInfo->pFillInfo, pInfo->pFillSup, pInfo->pRes);
|
||||
if (pInfo->pRes->info.rows > 0) {
|
||||
printDataBlock(pInfo->pRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pInfo->pRes;
|
||||
(*ppRes) = pInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
doDeleteFillFinalize(pOperator);
|
||||
if (pInfo->pRes->info.rows > 0) {
|
||||
printDataBlock(pInfo->pRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pInfo->pRes;
|
||||
(*ppRes) = pInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
setOperatorCompleted(pOperator);
|
||||
resetStreamFillInfo(pInfo);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
SSDataBlock* fillResult = NULL;
|
||||
|
@ -1053,7 +1061,8 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) {
|
|||
pInfo->pFillInfo->preRowKey = INT64_MIN;
|
||||
if (pInfo->pRes->info.rows > 0) {
|
||||
printDataBlock(pInfo->pRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pInfo->pRes;
|
||||
(*ppRes) = pInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1071,7 +1080,8 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) {
|
|||
|
||||
switch (pBlock->info.type) {
|
||||
case STREAM_RETRIEVE:
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
case STREAM_DELETE_RESULT: {
|
||||
pInfo->pSrcDelBlock = pBlock;
|
||||
pInfo->srcDelRowIndex = 0;
|
||||
|
@ -1082,7 +1092,8 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) {
|
|||
|
||||
if (pInfo->pDelRes->info.rows > 0) {
|
||||
printDataBlock(pInfo->pDelRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pInfo->pDelRes;
|
||||
(*ppRes) = pInfo->pDelRes;
|
||||
return code;
|
||||
}
|
||||
continue;
|
||||
} break;
|
||||
|
@ -1097,7 +1108,8 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) {
|
|||
} break;
|
||||
case STREAM_CHECKPOINT:
|
||||
case STREAM_CREATE_CHILD_TABLE: {
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
} break;
|
||||
default:
|
||||
ASSERTS(false, "invalid SSDataBlock type");
|
||||
|
@ -1121,20 +1133,30 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) {
|
|||
if (pInfo->pRes->info.rows == 0) {
|
||||
setOperatorCompleted(pOperator);
|
||||
resetStreamFillInfo(pInfo);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
pOperator->resultInfo.totalRows += pInfo->pRes->info.rows;
|
||||
printDataBlock(pInfo->pRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||
return pInfo->pRes;
|
||||
(*ppRes) = pInfo->pRes;
|
||||
return code;
|
||||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
setOperatorCompleted(pOperator);
|
||||
resetStreamFillInfo(pInfo);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doStreamFillNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static int32_t initResultBuf(SStreamFillSupporter* pFillSup) {
|
||||
|
@ -1406,7 +1428,7 @@ SOperatorInfo* createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFi
|
|||
|
||||
_error:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
}
|
||||
destroyStreamFillOperatorInfo(pInfo);
|
||||
taosMemoryFreeClear(pOperator);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1872,8 +1872,9 @@ static void getDBNameFromCondition(SNode* pCondition, const char* dbName) {
|
|||
nodesWalkExpr(pCondition, getDBNameFromConditionWalker, (char*)dbName);
|
||||
}
|
||||
|
||||
static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
||||
static int32_t doSysTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
// build message and send to mnode to fetch the content of system tables.
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SSysTableScanInfo* pInfo = pOperator->info;
|
||||
char dbName[TSDB_DB_NAME_LEN] = {0};
|
||||
|
@ -1881,7 +1882,8 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
|||
while (1) {
|
||||
if (isTaskKilled(pOperator->pTaskInfo)) {
|
||||
setOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
blockDataCleanup(pInfo->pRes);
|
||||
|
@ -1923,13 +1925,21 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
|||
if (pBlock->info.rows == 0) {
|
||||
continue;
|
||||
}
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
} else {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doSysTableScanNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static void sysTableScanFillTbName(SOperatorInfo* pOperator, const SSysTableScanInfo* pInfo, const char* name,
|
||||
SSDataBlock* pBlock) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
@ -1974,7 +1984,11 @@ static SSDataBlock* sysTableScanFromMNode(SOperatorInfo* pOperator, SSysTableSca
|
|||
|
||||
int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &pInfo->req);
|
||||
char* buf1 = taosMemoryCalloc(1, contLen);
|
||||
(void)tSerializeSRetrieveTableReq(buf1, contLen, &pInfo->req);
|
||||
int32_t tempRes = tSerializeSRetrieveTableReq(buf1, contLen, &pInfo->req);
|
||||
if (tempRes < 0) {
|
||||
code = terrno;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// send the fetch remote task result reques
|
||||
SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
|
@ -2548,11 +2562,12 @@ static int32_t doGetTableRowSize(SReadHandle* pHandle, uint64_t uid, int32_t* ro
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) {
|
||||
static int32_t doBlockInfoScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
SBlockDistInfo* pBlockScanInfo = pOperator->info;
|
||||
|
@ -2578,7 +2593,11 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) {
|
|||
char* p = taosMemoryCalloc(1, len + VARSTR_HEADER_SIZE);
|
||||
QUERY_CHECK_NULL(p, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||
|
||||
(void)tSerializeBlockDistInfo(varDataVal(p), len, &blockDistInfo);
|
||||
int32_t tempRes = tSerializeBlockDistInfo(varDataVal(p), len, &blockDistInfo);
|
||||
if (tempRes < 0) {
|
||||
code = terrno;
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
}
|
||||
varDataSetLen(p, len);
|
||||
|
||||
code = colDataSetVal(pColInfo, 0, p, false);
|
||||
|
@ -2602,7 +2621,14 @@ _end:
|
|||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
return pBlock;
|
||||
(*ppRes) = pBlock;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doBlockInfoScanNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static void destroyBlockDistScanOperatorInfo(void* param) {
|
||||
|
|
|
@ -47,9 +47,9 @@ static void setNotFillColumn(SFillInfo* pFillInfo, SColumnInfoData* pDstColInfo,
|
|||
}
|
||||
|
||||
SGroupKeys* pKey = taosArrayGet(p->pRowVal, colIdx);
|
||||
int32_t code = doSetVal(pDstColInfo, rowIndex, pKey);
|
||||
int32_t code = doSetVal(pDstColInfo, rowIndex, pKey);
|
||||
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));
|
||||
T_LONG_JMP(pFillInfo->pTaskInfo->env, code);
|
||||
}
|
||||
}
|
||||
|
@ -511,20 +511,18 @@ static int32_t taosNumOfRemainRows(SFillInfo* pFillInfo) {
|
|||
return pFillInfo->numOfRows - pFillInfo->index;
|
||||
}
|
||||
|
||||
struct SFillInfo* taosCreateFillInfo(TSKEY skey, int32_t numOfFillCols, int32_t numOfNotFillCols, int32_t capacity,
|
||||
SInterval* pInterval, int32_t fillType, struct SFillColInfo* pCol,
|
||||
int32_t primaryTsSlotId, int32_t order, const char* id, SExecTaskInfo* pTaskInfo) {
|
||||
void taosCreateFillInfo(TSKEY skey, int32_t numOfFillCols, int32_t numOfNotFillCols, int32_t capacity,
|
||||
SInterval* pInterval, int32_t fillType, struct SFillColInfo* pCol, int32_t primaryTsSlotId,
|
||||
int32_t order, const char* id, SExecTaskInfo* pTaskInfo, SFillInfo** ppFillInfo) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
if (fillType == TSDB_FILL_NONE) {
|
||||
return NULL;
|
||||
(*ppFillInfo) = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
SFillInfo* pFillInfo = taosMemoryCalloc(1, sizeof(SFillInfo));
|
||||
if (pFillInfo == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
QUERY_CHECK_NULL(pFillInfo, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||
|
||||
pFillInfo->order = order;
|
||||
pFillInfo->srcTsSlotId = primaryTsSlotId;
|
||||
|
@ -562,10 +560,10 @@ _end:
|
|||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosArrayDestroy(pFillInfo->next.pRowVal);
|
||||
taosArrayDestroy(pFillInfo->prev.pRowVal);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
terrno = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
return pFillInfo;
|
||||
(*ppFillInfo) = pFillInfo;
|
||||
}
|
||||
|
||||
void taosResetFillInfo(SFillInfo* pFillInfo, TSKEY startTimestamp) {
|
||||
|
|
|
@ -321,7 +321,7 @@ static bool genInterpolationResult(STimeSliceOperatorInfo* pSliceInfo, SExprSupp
|
|||
char* v = colDataGetData(pSrc, index);
|
||||
code = colDataSetVal(pDst, pResBlock->info.rows, v, false);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
} else if(!isSelectGroupConstValueFunc(pExprInfo)){
|
||||
} else if (!isSelectGroupConstValueFunc(pExprInfo)) {
|
||||
// use stored group key
|
||||
SGroupKeys* pkey = pSliceInfo->pPrevGroupKey;
|
||||
if (pkey->isNull == false) {
|
||||
|
@ -331,7 +331,7 @@ static bool genInterpolationResult(STimeSliceOperatorInfo* pSliceInfo, SExprSupp
|
|||
colDataSetNULL(pDst, rows);
|
||||
}
|
||||
} else {
|
||||
int32_t srcSlot = pExprInfo->base.pParam[0].pCol->slotId;
|
||||
int32_t srcSlot = pExprInfo->base.pParam[0].pCol->slotId;
|
||||
SGroupKeys* pkey = taosArrayGet(pSliceInfo->pPrevRow, srcSlot);
|
||||
if (pkey->isNull == false) {
|
||||
colDataSetVal(pDst, rows, pkey->pData, false);
|
||||
|
@ -781,10 +781,10 @@ static void saveBlockStatus(STimeSliceOperatorInfo* pSliceInfo, SSDataBlock* pBl
|
|||
|
||||
static void doTimesliceImpl(SOperatorInfo* pOperator, STimeSliceOperatorInfo* pSliceInfo, SSDataBlock* pBlock,
|
||||
SExecTaskInfo* pTaskInfo, bool ignoreNull) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SSDataBlock* pResBlock = pSliceInfo->pRes;
|
||||
SInterval* pInterval = &pSliceInfo->interval;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SSDataBlock* pResBlock = pSliceInfo->pRes;
|
||||
SInterval* pInterval = &pSliceInfo->interval;
|
||||
|
||||
SColumnInfoData* pTsCol = taosArrayGet(pBlock->pDataBlock, pSliceInfo->tsCol.slotId);
|
||||
SColumnInfoData* pPkCol = NULL;
|
||||
|
@ -988,12 +988,13 @@ static void doHandleTimeslice(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
|||
copyPrevGroupKey(&pOperator->exprSupp, pSliceInfo->pPrevGroupKey, pBlock);
|
||||
}
|
||||
|
||||
static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) {
|
||||
static int32_t doTimesliceNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
STimeSliceOperatorInfo* pSliceInfo = pOperator->info;
|
||||
|
@ -1079,7 +1080,14 @@ _finished:
|
|||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
|
||||
return pResBlock->info.rows == 0 ? NULL : pResBlock;
|
||||
(*ppRes) = pResBlock->info.rows == 0 ? NULL : pResBlock;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doTimesliceNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static int32_t extractPkColumnFromFuncs(SNodeList* pFuncs, bool* pHasPk, SColumn* pPkColumn) {
|
||||
|
|
|
@ -811,9 +811,10 @@ void doCloseWindow(SResultRowInfo* pResultRowInfo, const SIntervalAggOperatorInf
|
|||
}
|
||||
}
|
||||
|
||||
SResultRowPosition addToOpenWindowList(SResultRowInfo* pResultRowInfo, const SResultRow* pResult, uint64_t groupId, SExecTaskInfo* pTaskInfo) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SResultRowPosition addToOpenWindowList(SResultRowInfo* pResultRowInfo, const SResultRow* pResult, uint64_t groupId,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SOpenWindowInfo openWin = {0};
|
||||
openWin.pos.pageId = pResult->pageId;
|
||||
openWin.pos.offset = pResult->offset;
|
||||
|
@ -1053,36 +1054,28 @@ _end:
|
|||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator) {
|
||||
static int32_t doStateWindowAggNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SStateWindowOperatorInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SOptrBasicInfo* pBInfo = &pInfo->binfo;
|
||||
|
||||
pTaskInfo->code = pOperator->fpSet._openFn(pOperator);
|
||||
if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
|
||||
setOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
}
|
||||
code = pOperator->fpSet._openFn(pOperator);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
int32_t code = blockDataEnsureCapacity(pBInfo->pRes, pOperator->resultInfo.capacity);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
code = blockDataEnsureCapacity(pBInfo->pRes, pOperator->resultInfo.capacity);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
while (1) {
|
||||
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
|
||||
code = doFilter(pBInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
bool hasRemain = hasRemainResults(&pInfo->groupResInfo);
|
||||
if (!hasRemain) {
|
||||
|
@ -1096,31 +1089,42 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
pOperator->resultInfo.totalRows += pBInfo->pRes->info.rows;
|
||||
return (pBInfo->pRes->info.rows == 0) ? NULL : pBInfo->pRes;
|
||||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
(*ppRes) = (pBInfo->pRes->info.rows == 0) ? NULL : pBInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator) {
|
||||
static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doStateWindowAggNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static int32_t doBuildIntervalResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SIntervalAggOperatorInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
SSDataBlock* pBlock = pInfo->binfo.pRes;
|
||||
pTaskInfo->code = pOperator->fpSet._openFn(pOperator);
|
||||
if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
code = pOperator->fpSet._openFn(pOperator);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
while (1) {
|
||||
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
|
||||
int32_t code = doFilter(pBlock, pOperator->exprSupp.pFilterInfo, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
code = doFilter(pBlock, pOperator->exprSupp.pFilterInfo, NULL);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
bool hasRemain = hasRemainResults(&pInfo->groupResInfo);
|
||||
if (!hasRemain) {
|
||||
|
@ -1136,7 +1140,20 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator) {
|
|||
size_t rows = pBlock->info.rows;
|
||||
pOperator->resultInfo.totalRows += rows;
|
||||
|
||||
return (rows == 0) ? NULL : pBlock;
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
(*ppRes) = (rows == 0) ? NULL : pBlock;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doBuildIntervalResultNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
static void destroyStateWindowOperatorInfo(void* param) {
|
||||
|
@ -1429,9 +1446,10 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperator
|
|||
pRowSup->numOfRows, pBlock->info.rows, numOfOutput);
|
||||
}
|
||||
|
||||
static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) {
|
||||
static int32_t doSessionWindowAggNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
@ -1458,7 +1476,8 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) {
|
|||
}
|
||||
}
|
||||
pOperator->resultInfo.totalRows += pBInfo->pRes->info.rows;
|
||||
return (pBInfo->pRes->info.rows == 0) ? NULL : pBInfo->pRes;
|
||||
(*ppRes) = (pBInfo->pRes->info.rows == 0) ? NULL : pBInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
@ -1519,7 +1538,14 @@ _end:
|
|||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
return (pBInfo->pRes->info.rows == 0) ? NULL : pBInfo->pRes;
|
||||
(*ppRes) = (pBInfo->pRes->info.rows == 0) ? NULL : pBInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doSessionWindowAggNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
// todo make this as an non-blocking operator
|
||||
|
@ -1883,13 +1909,14 @@ _end:
|
|||
}
|
||||
}
|
||||
|
||||
static SSDataBlock* mergeAlignedIntervalAgg(SOperatorInfo* pOperator) {
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
static int32_t mergeAlignedIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SMergeAlignedIntervalAggOperatorInfo* pMiaInfo = pOperator->info;
|
||||
SIntervalAggOperatorInfo* iaInfo = pMiaInfo->intervalAggOperatorInfo;
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
SSDataBlock* pRes = iaInfo->binfo.pRes;
|
||||
|
@ -1913,7 +1940,14 @@ static SSDataBlock* mergeAlignedIntervalAgg(SOperatorInfo* pOperator) {
|
|||
|
||||
size_t rows = pRes->info.rows;
|
||||
pOperator->resultInfo.totalRows += rows;
|
||||
return (rows == 0) ? NULL : pRes;
|
||||
(*ppRes) = (rows == 0) ? NULL : pRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* mergeAlignedIntervalAgg(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = mergeAlignedIntervalAggNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, SMergeAlignedIntervalPhysiNode* pNode,
|
||||
|
@ -2151,7 +2185,7 @@ static void doMergeIntervalAggImpl(SOperatorInfo* pOperatorInfo, SResultRowInfo*
|
|||
}
|
||||
}
|
||||
|
||||
static SSDataBlock* doMergeIntervalAgg(SOperatorInfo* pOperator) {
|
||||
static int32_t doMergeIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
@ -2161,7 +2195,8 @@ static SSDataBlock* doMergeIntervalAgg(SOperatorInfo* pOperator) {
|
|||
SExprSupp* pExpSupp = &pOperator->exprSupp;
|
||||
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
SSDataBlock* pRes = iaInfo->binfo.pRes;
|
||||
|
@ -2231,7 +2266,14 @@ _end:
|
|||
pTaskInfo->code = code;
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
return (rows == 0) ? NULL : pRes;
|
||||
(*ppRes) = (rows == 0) ? NULL : pRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doMergeIntervalAgg(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doMergeIntervalAggNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
SOperatorInfo* createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SMergeIntervalPhysiNode* pIntervalPhyNode,
|
||||
|
|
|
@ -51,7 +51,12 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
|
|||
taosLRUCacheSetStrictCapacity(pLogStore->pCache, false);
|
||||
|
||||
pLogStore->data = taosMemoryMalloc(sizeof(SSyncLogStoreData));
|
||||
ASSERT(pLogStore->data != NULL);
|
||||
if (!pLogStore->data) {
|
||||
taosMemoryFree(pLogStore);
|
||||
taosLRUCacheCleanup(pLogStore->pCache);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
pData->pSyncNode = pSyncNode;
|
||||
|
@ -60,7 +65,13 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
|
|||
|
||||
taosThreadMutexInit(&(pData->mutex), NULL);
|
||||
pData->pWalHandle = walOpenReader(pData->pWal, NULL, 0);
|
||||
ASSERT(pData->pWalHandle != NULL);
|
||||
if (!pData->pWalHandle) {
|
||||
taosMemoryFree(pLogStore);
|
||||
taosLRUCacheCleanup(pLogStore->pCache);
|
||||
taosThreadMutexDestroy(&(pData->mutex));
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pLogStore->syncLogUpdateCommitIndex = raftLogUpdateCommitIndex;
|
||||
pLogStore->syncLogCommitIndex = raftlogCommitIndex;
|
||||
|
@ -110,7 +121,7 @@ static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncI
|
|||
SWal* pWal = pData->pWal;
|
||||
int32_t code = walRestoreFromSnapshot(pWal, snapshotIndex);
|
||||
if (code != 0) {
|
||||
int32_t err = terrno;
|
||||
int32_t err = code;
|
||||
const char* errStr = tstrerror(err);
|
||||
int32_t sysErr = errno;
|
||||
const char* sysErrStr = strerror(errno);
|
||||
|
@ -118,10 +129,10 @@ static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncI
|
|||
sNError(pData->pSyncNode,
|
||||
"wal restore from snapshot error, index:%" PRId64 ", err:0x%x, msg:%s, syserr:%d, sysmsg:%s", snapshotIndex,
|
||||
err, errStr, sysErr, sysErrStr);
|
||||
return -1;
|
||||
TAOS_RETURN(err);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
SyncIndex raftLogBeginIndex(struct SSyncLogStore* pLogStore) {
|
||||
|
@ -224,7 +235,8 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
|
|||
|
||||
sNError(pData->pSyncNode, "wal write error, index:%" PRId64 ", err:0x%x, msg:%s, syserr:%d, sysmsg:%s",
|
||||
pEntry->index, err, errStr, sysErr, sysErrStr);
|
||||
return -1;
|
||||
|
||||
TAOS_RETURN(err);
|
||||
}
|
||||
|
||||
code = walFsync(pWal, forceSync);
|
||||
|
@ -235,7 +247,7 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
|
|||
|
||||
sNTrace(pData->pSyncNode, "write index:%" PRId64 ", type:%s, origin type:%s, elapsed:%" PRId64, pEntry->index,
|
||||
TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType), tsElapsed);
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
// entry found, return 0
|
||||
|
@ -253,10 +265,10 @@ int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncR
|
|||
|
||||
SWalReader* pWalHandle = pData->pWalHandle;
|
||||
if (pWalHandle == NULL) {
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
sError("vgId:%d, wal handle is NULL", pData->pSyncNode->vgId);
|
||||
taosThreadMutexUnlock(&(pData->mutex));
|
||||
return -1;
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_SYN_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
int64_t ts2 = taosGetTimestampNs();
|
||||
|
@ -266,7 +278,7 @@ int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncR
|
|||
|
||||
// code = walReadVerCached(pWalHandle, index);
|
||||
if (code != 0) {
|
||||
int32_t err = terrno;
|
||||
int32_t err = code;
|
||||
const char* errStr = tstrerror(err);
|
||||
int32_t sysErr = errno;
|
||||
const char* sysErrStr = strerror(errno);
|
||||
|
@ -286,7 +298,8 @@ int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncR
|
|||
*/
|
||||
|
||||
taosThreadMutexUnlock(&(pData->mutex));
|
||||
return code;
|
||||
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*ppEntry = syncEntryBuild(pWalHandle->pHead->head.bodyLen);
|
||||
|
@ -319,7 +332,7 @@ int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncR
|
|||
", elapsed-build:%" PRId64,
|
||||
index, tsElapsed, tsElapsedLock, tsElapsedRead, tsElapsedBuild);
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
// truncate semantic
|
||||
|
@ -329,7 +342,7 @@ static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIn
|
|||
|
||||
int32_t code = walRollback(pWal, fromIndex);
|
||||
if (code != 0) {
|
||||
int32_t err = terrno;
|
||||
int32_t err = code;
|
||||
const char* errStr = tstrerror(err);
|
||||
int32_t sysErr = errno;
|
||||
const char* sysErrStr = strerror(errno);
|
||||
|
@ -339,7 +352,8 @@ static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIn
|
|||
|
||||
// event log
|
||||
sNTrace(pData->pSyncNode, "log truncate, from-index:%" PRId64, fromIndex);
|
||||
return code;
|
||||
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
// entry found, return 0
|
||||
|
@ -352,16 +366,16 @@ static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** pp
|
|||
|
||||
*ppLastEntry = NULL;
|
||||
if (walIsEmpty(pWal)) {
|
||||
terrno = TSDB_CODE_WAL_LOG_NOT_EXIST;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_WAL_LOG_NOT_EXIST);
|
||||
} else {
|
||||
SyncIndex lastIndex = raftLogLastIndex(pLogStore);
|
||||
ASSERT(lastIndex >= SYNC_INDEX_BEGIN);
|
||||
int32_t code = raftLogGetEntry(pLogStore, lastIndex, ppLastEntry);
|
||||
return code;
|
||||
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
}
|
||||
|
||||
int32_t raftLogUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) {
|
||||
|
@ -375,20 +389,22 @@ int32_t raftLogUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) {
|
|||
|
||||
if (index < snapshotVer || index > wallastVer) {
|
||||
// ignore
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t code = walCommit(pWal, index);
|
||||
if (code != 0) {
|
||||
int32_t err = terrno;
|
||||
int32_t err = code;
|
||||
const char* errStr = tstrerror(err);
|
||||
int32_t sysErr = errno;
|
||||
const char* sysErrStr = strerror(errno);
|
||||
sError("vgId:%d, wal update commit index error, index:%" PRId64 ", err:0x%x, msg:%s, syserr:%d, sysmsg:%s",
|
||||
pData->pSyncNode->vgId, index, err, errStr, sysErr, sysErrStr);
|
||||
return -1;
|
||||
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
return 0;
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
SyncIndex raftlogCommitIndex(SSyncLogStore* pLogStore) {
|
||||
|
@ -405,5 +421,6 @@ SyncIndex logStoreFirstIndex(SSyncLogStore* pLogStore) {
|
|||
SyncIndex logStoreWalCommitVer(SSyncLogStore* pLogStore) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
SWal* pWal = pData->pWal;
|
||||
|
||||
return walGetCommittedVer(pWal);
|
||||
}
|
||||
|
|
|
@ -25,17 +25,17 @@ static int32_t raftStoreDecode(const SJson *pJson, SRaftStore *pStore) {
|
|||
int32_t code = 0;
|
||||
|
||||
tjsonGetNumberValue(pJson, "current_term", pStore->currentTerm, code);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
tjsonGetNumberValue(pJson, "vote_for_addr", pStore->voteFor.addr, code);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
tjsonGetInt32ValueFromDouble(pJson, "vote_for_vgid", pStore->voteFor.vgId, code);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t raftStoreReadFile(SSyncNode *pNode) {
|
||||
int32_t code = -1;
|
||||
int32_t code = -1, lino = 0;
|
||||
TdFilePtr pFile = NULL;
|
||||
char *pData = NULL;
|
||||
SJson *pJson = NULL;
|
||||
|
@ -52,41 +52,38 @@ int32_t raftStoreReadFile(SSyncNode *pNode) {
|
|||
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
sError("vgId:%d, failed to open raft store file:%s since %s", pNode->vgId, file, terrstr());
|
||||
goto _OVER;
|
||||
|
||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
||||
}
|
||||
|
||||
int64_t size = 0;
|
||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
sError("vgId:%d, failed to fstat raft store file:%s since %s", pNode->vgId, file, terrstr());
|
||||
goto _OVER;
|
||||
|
||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
||||
}
|
||||
|
||||
pData = taosMemoryMalloc(size + 1);
|
||||
if (pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER);
|
||||
}
|
||||
|
||||
if (taosReadFile(pFile, pData, size) != size) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
sError("vgId:%d, failed to read raft store file:%s since %s", pNode->vgId, file, terrstr());
|
||||
goto _OVER;
|
||||
|
||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
||||
}
|
||||
|
||||
pData[size] = '\0';
|
||||
|
||||
pJson = tjsonParse(pData);
|
||||
if (pJson == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_INVALID_JSON_FORMAT, &lino, _OVER);
|
||||
}
|
||||
|
||||
if (raftStoreDecode(pJson, pStore) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_INVALID_JSON_FORMAT, &lino, _OVER);
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
@ -100,18 +97,20 @@ _OVER:
|
|||
if (code != 0) {
|
||||
sError("vgId:%d, failed to read raft store file:%s since %s", pNode->vgId, file, terrstr());
|
||||
}
|
||||
return code;
|
||||
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t raftStoreEncode(SJson *pJson, SRaftStore *pStore) {
|
||||
if (tjsonAddIntegerToObject(pJson, "current_term", pStore->currentTerm) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "vote_for_addr", pStore->voteFor.addr) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(pJson, "vote_for_vgid", pStore->voteFor.vgId) < 0) return -1;
|
||||
return 0;
|
||||
if (tjsonAddIntegerToObject(pJson, "current_term", pStore->currentTerm) < 0) TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
if (tjsonAddIntegerToObject(pJson, "vote_for_addr", pStore->voteFor.addr) < 0) TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
if (tjsonAddDoubleToObject(pJson, "vote_for_vgid", pStore->voteFor.vgId) < 0) TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t raftStoreWriteFile(SSyncNode *pNode) {
|
||||
int32_t code = -1;
|
||||
int32_t code = -1, lino = 0;
|
||||
char *buffer = NULL;
|
||||
SJson *pJson = NULL;
|
||||
TdFilePtr pFile = NULL;
|
||||
|
@ -120,23 +119,23 @@ int32_t raftStoreWriteFile(SSyncNode *pNode) {
|
|||
char file[PATH_MAX] = {0};
|
||||
snprintf(file, sizeof(file), "%s.bak", realfile);
|
||||
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pJson = tjsonCreateObject();
|
||||
if (pJson == NULL) goto _OVER;
|
||||
if (raftStoreEncode(pJson, pStore) != 0) goto _OVER;
|
||||
if (pJson == NULL) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER);
|
||||
if (raftStoreEncode(pJson, pStore) != 0) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER);
|
||||
|
||||
buffer = tjsonToString(pJson);
|
||||
if (buffer == NULL) goto _OVER;
|
||||
terrno = 0;
|
||||
if (buffer == NULL) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER);
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||
if (pFile == NULL) goto _OVER;
|
||||
if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
||||
|
||||
int32_t len = strlen(buffer);
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
||||
|
||||
if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||
if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
||||
|
||||
code = 0;
|
||||
sInfo("vgId:%d, succeed to write raft store file:%s, term:%" PRId64, pNode->vgId, realfile, pStore->currentTerm);
|
||||
|
@ -147,7 +146,6 @@ _OVER:
|
|||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (code != 0) {
|
||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
sError("vgId:%d, failed to write raft store file:%s since %s", pNode->vgId, realfile, terrstr());
|
||||
}
|
||||
return code;
|
||||
|
|
|
@ -52,7 +52,8 @@ int32_t syncNodeReplicateReset(SSyncNode* pNode, SRaftId* pDestId) {
|
|||
SSyncLogReplMgr* pMgr = syncNodeGetLogReplMgr(pNode, pDestId);
|
||||
syncLogReplReset(pMgr);
|
||||
taosThreadMutexUnlock(&pBuf->mutex);
|
||||
return 0;
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t syncNodeReplicate(SSyncNode* pNode) {
|
||||
|
@ -60,13 +61,14 @@ int32_t syncNodeReplicate(SSyncNode* pNode) {
|
|||
taosThreadMutexLock(&pBuf->mutex);
|
||||
int32_t ret = syncNodeReplicateWithoutLock(pNode);
|
||||
taosThreadMutexUnlock(&pBuf->mutex);
|
||||
return ret;
|
||||
|
||||
TAOS_RETURN(ret);
|
||||
}
|
||||
|
||||
int32_t syncNodeReplicateWithoutLock(SSyncNode* pNode) {
|
||||
if ((pNode->state != TAOS_SYNC_STATE_LEADER && pNode->state != TAOS_SYNC_STATE_ASSIGNED_LEADER) ||
|
||||
pNode->raftCfg.cfg.totalReplicaNum == 1) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
}
|
||||
for (int32_t i = 0; i < pNode->totalReplicaNum; i++) {
|
||||
if (syncUtilSameId(&pNode->replicasId[i], &pNode->myRaftId)) {
|
||||
|
@ -75,14 +77,16 @@ int32_t syncNodeReplicateWithoutLock(SSyncNode* pNode) {
|
|||
SSyncLogReplMgr* pMgr = pNode->logReplMgrs[i];
|
||||
(void)syncLogReplStart(pMgr, pNode);
|
||||
}
|
||||
return 0;
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg) {
|
||||
SyncAppendEntries* pMsg = pRpcMsg->pCont;
|
||||
pMsg->destId = *destRaftId;
|
||||
syncNodeSendMsgById(destRaftId, pSyncNode, pRpcMsg);
|
||||
return 0;
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* destId, SRpcMsg* pMsg) {
|
||||
|
@ -112,5 +116,5 @@ int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode) {
|
|||
syncNodeSendHeartbeat(pSyncNode, &pSyncMsg->destId, &rpcMsg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "syncRaftStore.h"
|
||||
#include "syncUtil.h"
|
||||
#include "syncVoteMgr.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
// TLA+ Spec
|
||||
// HandleRequestVoteRequest(i, j, m) ==
|
||||
|
@ -95,7 +94,8 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
|||
// if already drop replica, do not process
|
||||
if (!syncNodeInRaftGroup(ths, &pMsg->srcId)) {
|
||||
syncLogRecvRequestVote(ths, pMsg, -1, "not in my config");
|
||||
return -1;
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
}
|
||||
|
||||
bool logOK = syncNodeOnRequestVoteLogOK(ths, pMsg);
|
||||
|
@ -122,8 +122,8 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
|||
|
||||
// send msg
|
||||
SRpcMsg rpcMsg = {0};
|
||||
ret = syncBuildRequestVoteReply(&rpcMsg, ths->vgId);
|
||||
ASSERT(ret == 0);
|
||||
|
||||
TAOS_CHECK_RETURN(syncBuildRequestVoteReply(&rpcMsg, ths->vgId));
|
||||
|
||||
SyncRequestVoteReply* pReply = rpcMsg.pCont;
|
||||
pReply->srcId = ths->myRaftId;
|
||||
|
@ -138,5 +138,6 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
|||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
||||
|
||||
if (resetElect) syncNodeResetElectTimer(ths);
|
||||
return 0;
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
|
|
@ -45,19 +45,22 @@ int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
|||
// if already drop replica, do not process
|
||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) {
|
||||
syncLogRecvRequestVoteReply(ths, pMsg, "not in my config");
|
||||
return -1;
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
}
|
||||
SyncTerm currentTerm = raftStoreGetTerm(ths);
|
||||
// drop stale response
|
||||
if (pMsg->term < currentTerm) {
|
||||
syncLogRecvRequestVoteReply(ths, pMsg, "drop stale response");
|
||||
return -1;
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
}
|
||||
|
||||
if (pMsg->term > currentTerm) {
|
||||
syncLogRecvRequestVoteReply(ths, pMsg, "error term");
|
||||
syncNodeStepDown(ths, pMsg->term);
|
||||
return -1;
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
}
|
||||
|
||||
syncLogRecvRequestVoteReply(ths, pMsg, "");
|
||||
|
@ -69,7 +72,8 @@ int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
|||
if (ths->pVotesRespond->term != pMsg->term) {
|
||||
sNError(ths, "vote respond error vote-respond-mgr term:%" PRIu64 ", msg term:%" PRIu64 "",
|
||||
ths->pVotesRespond->term, pMsg->term);
|
||||
return -1;
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
}
|
||||
|
||||
votesRespondAdd(ths->pVotesRespond, pMsg);
|
||||
|
@ -93,5 +97,5 @@ int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
|||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg
|
|||
ret = tdbBegin(pEnv, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
|
||||
if (ret < 0) {
|
||||
tdbOsFree(pBt);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
SBtreeInitPageArg zArg;
|
||||
|
@ -124,7 +124,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg
|
|||
if (ret < 0) {
|
||||
tdbAbort(pEnv, txn);
|
||||
tdbOsFree(pBt);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = tdbPagerWrite(pPager, pPage);
|
||||
|
@ -132,7 +132,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg
|
|||
tdbError("failed to write page since %s", terrstr());
|
||||
tdbAbort(pEnv, txn);
|
||||
tdbOsFree(pBt);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (strcmp(TDB_MAINDB_NAME, tbname)) {
|
||||
|
@ -145,20 +145,23 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg
|
|||
if (ret < 0) {
|
||||
tdbAbort(pEnv, txn);
|
||||
tdbOsFree(pBt);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
tdbPCacheRelease(pPager->pCache, pPage, txn);
|
||||
|
||||
tdbCommit(pPager->pEnv, txn);
|
||||
tdbPostCommit(pPager->pEnv, txn);
|
||||
ret = tdbCommit(pPager->pEnv, txn);
|
||||
if (ret) return ret;
|
||||
|
||||
ret = tdbPostCommit(pPager->pEnv, txn);
|
||||
if (ret) return ret;
|
||||
}
|
||||
|
||||
if (pgno == 0) {
|
||||
tdbError("tdb/btree-open: pgno cannot be zero.");
|
||||
tdbOsFree(pBt);
|
||||
return -1;
|
||||
ASSERT(0);
|
||||
}
|
||||
pBt->root = pgno;
|
||||
/*
|
||||
|
@ -200,7 +203,7 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in
|
|||
if (ret < 0) {
|
||||
tdbBtcClose(&btc);
|
||||
tdbError("tdb/btree-insert: btc move to failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (btc.idx == -1) {
|
||||
|
@ -212,7 +215,7 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in
|
|||
// dup key not allowed with insert
|
||||
tdbBtcClose(&btc);
|
||||
tdbError("tdb/btree-insert: dup key. pKey: %p, kLen: %d, btc: %p, pTxn: %p", pKey, kLen, &btc, pTxn);
|
||||
return -1;
|
||||
return TSDB_CODE_DUP_KEY;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,7 +223,7 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in
|
|||
if (ret < 0) {
|
||||
tdbBtcClose(&btc);
|
||||
tdbError("tdb/btree-insert: btc upsert failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
tdbBtcClose(&btc);
|
||||
|
@ -245,18 +248,19 @@ int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn) {
|
|||
if (ret < 0) {
|
||||
tdbBtcClose(&btc);
|
||||
tdbError("tdb/btree-delete: btc move to failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (btc.idx < 0 || c != 0) {
|
||||
tdbBtcClose(&btc);
|
||||
return -1;
|
||||
return TSDB_CODE_NOT_FOUND;
|
||||
}
|
||||
|
||||
// delete the key
|
||||
if (tdbBtcDelete(&btc) < 0) {
|
||||
ret = tdbBtcDelete(&btc);
|
||||
if (ret < 0) {
|
||||
tdbBtcClose(&btc);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
SArray *ofps = btc.coder.ofps;
|
||||
|
@ -341,13 +345,12 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL
|
|||
if (ret < 0) {
|
||||
tdbBtcClose(&btc);
|
||||
tdbError("tdb/btree-pget: btc move to failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (btc.idx < 0 || cret) {
|
||||
tdbBtcClose(&btc);
|
||||
|
||||
return -1;
|
||||
return TSDB_CODE_NOT_FOUND;
|
||||
}
|
||||
|
||||
pCell = tdbPageGetCell(btc.pPage, btc.idx);
|
||||
|
@ -355,7 +358,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL
|
|||
if (ret < 0) {
|
||||
tdbBtcClose(&btc);
|
||||
tdbError("tdb/btree-pget: decode cell failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ppKey) {
|
||||
|
@ -363,7 +366,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL
|
|||
if (pTKey == NULL) {
|
||||
tdbBtcClose(&btc);
|
||||
tdbError("tdb/btree-pget: realloc pTKey failed.");
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
*ppKey = pTKey;
|
||||
*pkLen = cd.kLen;
|
||||
|
@ -375,7 +378,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL
|
|||
if (pTVal == NULL) {
|
||||
tdbBtcClose(&btc);
|
||||
tdbError("tdb/btree-pget: realloc pTVal failed.");
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
*ppVal = pTVal;
|
||||
*vLen = cd.vLen;
|
||||
|
@ -495,7 +498,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild, TXN
|
|||
zArg.pBt = pBt;
|
||||
ret = tdbPagerFetchPage(pPager, &pgnoChild, &pChild, tdbBtreeInitPage, &zArg, pTxn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!leaf) {
|
||||
|
@ -505,7 +508,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild, TXN
|
|||
ret = tdbPagerWrite(pPager, pChild);
|
||||
if (ret < 0) {
|
||||
tdbError("failed to write page since %s", terrstr());
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Copy the root page content to the child page
|
||||
|
@ -516,7 +519,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild, TXN
|
|||
zArg.pBt = pBt;
|
||||
ret = tdbBtreeInitPage(pRoot, &zArg, 0);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
pIntHdr = (SIntHdr *)(pRoot->pData);
|
||||
|
@ -557,13 +560,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
|||
}
|
||||
for (int i = 0; i < nOlds; i++) {
|
||||
if (ASSERT(sIdx + i <= nCells)) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SPgno pgno;
|
||||
if (sIdx + i == nCells) {
|
||||
if (ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pParent))) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
pgno = ((SIntHdr *)(pParent->pData))->pgno;
|
||||
} else {
|
||||
|
@ -575,13 +578,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
|||
&((SBtreeInitPageArg){.pBt = pBt, .flags = 0}), pTxn);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btree-balance: fetch page failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
ret = tdbPagerWrite(pBt->pPager, pOlds[i]);
|
||||
if (ret < 0) {
|
||||
tdbError("failed to write page since %s", terrstr());
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
// copy the parent key out if child pages are not leaf page
|
||||
|
@ -608,7 +611,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
|||
ret = tdbPagerWrite(pBt->pPager, pParent);
|
||||
if (ret < 0) {
|
||||
tdbError("failed to write page since %s", terrstr());
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// drop the cells on parent page
|
||||
|
@ -718,7 +721,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
|||
}
|
||||
|
||||
if (ASSERT(infoNews[iNew - 1].cnt > 0)) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
if (infoNews[iNew].size + szRCell >= infoNews[iNew - 1].size - szRCell) {
|
||||
|
@ -763,13 +766,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
|||
ret = tdbPagerFetchPage(pBt->pPager, &pgno, pNews + iNew, tdbBtreeInitPage, &iarg, pTxn);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btree-balance: fetch page failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = tdbPagerWrite(pBt->pPager, pNews[iNew]);
|
||||
if (ret < 0) {
|
||||
tdbError("failed to write page since %s", terrstr());
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -808,10 +811,10 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
|||
szCell = tdbBtreeCellSize(pPage, pCell, 0, NULL, NULL);
|
||||
|
||||
if (ASSERT(nNewCells <= infoNews[iNew].cnt)) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (ASSERT(iNew < nNews)) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
if (nNewCells < infoNews[iNew].cnt) {
|
||||
|
@ -852,10 +855,10 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
|||
}
|
||||
} else {
|
||||
if (ASSERT(childNotLeaf)) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (ASSERT(iNew < nNews - 1)) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
// set current new page right-most child
|
||||
|
@ -863,7 +866,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
|||
|
||||
// insert to parent as divider cell
|
||||
if (ASSERT(iNew < nNews - 1)) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
((SPgno *)pCell)[0] = TDB_PAGE_PGNO(pNews[iNew]);
|
||||
tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0);
|
||||
|
@ -880,7 +883,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
|||
|
||||
if (childNotLeaf) {
|
||||
if (ASSERT(TDB_PAGE_TOTAL_CELLS(pNews[nNews - 1]) == infoNews[nNews - 1].cnt)) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
((SIntHdr *)(pNews[nNews - 1]->pData))->pgno = rPgno;
|
||||
|
||||
|
@ -961,7 +964,7 @@ static int tdbBtreeBalance(SBTC *pBtc) {
|
|||
|
||||
ret = tdbBtreeBalanceDeeper(pBtc->pBt, pPage, &(pBtc->pgStack[1]), pBtc->pTxn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
pBtc->idx = 0;
|
||||
|
@ -975,7 +978,7 @@ static int tdbBtreeBalance(SBTC *pBtc) {
|
|||
|
||||
ret = tdbBtreeBalanceNonRoot(pBtc->pBt, pParent, pBtc->idxStack[pBtc->iPage - 1], pBtc->pTxn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
tdbPagerReturnPage(pBtc->pBt->pPager, pBtc->pPage, pBtc->pTxn);
|
||||
|
@ -998,14 +1001,14 @@ static int tdbFetchOvflPage(SPgno *pPgno, SPage **ppOfp, TXN *pTxn, SBTree *pBt)
|
|||
iArg.flags = TDB_FLAG_ADD(0, TDB_BTREE_OVFL);
|
||||
ret = tdbPagerFetchPage(pBt->pPager, pPgno, ppOfp, tdbBtreeInitPage, &iArg, pTxn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// mark dirty
|
||||
ret = tdbPagerWrite(pBt->pPager, *ppOfp);
|
||||
if (ret < 0) {
|
||||
tdbError("failed to write page since %s", terrstr());
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
tdbPCacheRelease(pBt->pPager->pCache, *ppOfp, pTxn);
|
||||
|
@ -1021,7 +1024,7 @@ static int tdbLoadOvflPage(SPgno *pPgno, SPage **ppOfp, TXN *pTxn, SBTree *pBt)
|
|||
iArg.flags = TDB_FLAG_ADD(0, TDB_BTREE_OVFL);
|
||||
ret = tdbPagerFetchPage(pBt->pPager, pPgno, ppOfp, tdbBtreeInitPage, &iArg, pTxn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -1058,13 +1061,13 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
|||
|
||||
ret = tdbFetchOvflPage(&pgno, &ofp, pTxn, pBt);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// local buffer for cell
|
||||
SCell *pBuf = tdbRealloc(NULL, pBt->pageSize);
|
||||
if (pBuf == NULL) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int nLeft = nPayload;
|
||||
|
@ -1078,7 +1081,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
|||
if (nLocal > nHeader + kLen + sizeof(SPgno)) {
|
||||
if (ASSERT(pVal != NULL && vLen != 0)) {
|
||||
tdbFree(pBuf);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
memcpy(pCell + nHeader + kLen, pVal, nLocal - nHeader - kLen - sizeof(SPgno));
|
||||
nLeft -= nLocal - nHeader - kLen - sizeof(SPgno);
|
||||
|
@ -1103,7 +1106,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
|||
ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt);
|
||||
if (ret < 0) {
|
||||
tdbFree(pBuf);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
pgno = 0;
|
||||
|
@ -1115,7 +1118,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
|||
ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0);
|
||||
if (ret < 0) {
|
||||
tdbFree(pBuf);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ofp = nextOfp;
|
||||
|
@ -1163,7 +1166,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
|||
ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt);
|
||||
if (ret < 0) {
|
||||
tdbFree(pBuf);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1171,7 +1174,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
|||
ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt);
|
||||
if (ret < 0) {
|
||||
tdbFree(pBuf);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1179,7 +1182,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
|||
|
||||
ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ofp = nextOfp;
|
||||
|
@ -1203,7 +1206,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
|||
ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt);
|
||||
if (ret < 0) {
|
||||
tdbFree(pBuf);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
pgno = 0;
|
||||
|
@ -1214,13 +1217,13 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
|||
|
||||
if (ofp == NULL) {
|
||||
tdbFree(pBuf);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0);
|
||||
if (ret < 0) {
|
||||
tdbFree(pBuf);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ofp = nextOfp;
|
||||
|
@ -1245,13 +1248,13 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo
|
|||
int ret;
|
||||
|
||||
if (ASSERT(pPage->kLen == TDB_VARIANT_LEN || pPage->kLen == kLen)) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (ASSERT(pPage->vLen == TDB_VARIANT_LEN || pPage->vLen == vLen)) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (ASSERT(pKey != NULL && kLen > 0)) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
nPayload = 0;
|
||||
|
@ -1263,7 +1266,7 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo
|
|||
if (!leaf) {
|
||||
if (pPage->vLen != sizeof(SPgno)) {
|
||||
tdbError("tdb/btree-encode-cell: invalid cell.");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
((SPgno *)(pCell + nHeader))[0] = ((SPgno *)pVal)[0];
|
||||
|
@ -1290,7 +1293,7 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo
|
|||
if (ret < 0) {
|
||||
// TODO
|
||||
tdbError("tdb/btree-encode-cell: encode payload failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
*szCell = nHeader + nPayload;
|
||||
|
@ -1309,7 +1312,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
|||
if (pDecoder->pVal) {
|
||||
if (TDB_BTREE_PAGE_IS_LEAF(pPage)) {
|
||||
tdbError("tdb/btree-decode-payload: leaf page with non-null pVal.");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_DATA_FMT;
|
||||
}
|
||||
nPayload = pDecoder->kLen;
|
||||
} else {
|
||||
|
@ -1344,7 +1347,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
|||
// read partial val to local
|
||||
pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen);
|
||||
if (pDecoder->pVal == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
TDB_CELLDECODER_SET_FREE_VAL(pDecoder);
|
||||
|
||||
|
@ -1361,7 +1364,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
|||
while (pgno != 0) {
|
||||
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
if (pDecoder->ofps) {
|
||||
|
@ -1389,7 +1392,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
|||
// load partial key and nextPgno
|
||||
pDecoder->pKey = tdbRealloc(pDecoder->pKey, kLen);
|
||||
if (pDecoder->pKey == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
TDB_CELLDECODER_SET_FREE_KEY(pDecoder);
|
||||
|
||||
|
@ -1406,7 +1409,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
|||
// printf("tdb decode-ofp, pTxn: %p, pgno:%u by cell:%p\n", pTxn, pgno, pCell);
|
||||
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
if (pDecoder->ofps) {
|
||||
|
@ -1439,7 +1442,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
|||
// read partial val to local
|
||||
pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen);
|
||||
if (pDecoder->pVal == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
TDB_CELLDECODER_SET_FREE_VAL(pDecoder);
|
||||
|
||||
|
@ -1459,7 +1462,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
|||
while (nLeft > 0) {
|
||||
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ofpCell = tdbPageGetCell(ofp, 0);
|
||||
|
@ -1480,7 +1483,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
|||
if (!pDecoder->pVal) {
|
||||
pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen);
|
||||
if (pDecoder->pVal == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
TDB_CELLDECODER_SET_FREE_VAL(pDecoder);
|
||||
}
|
||||
|
@ -1529,7 +1532,7 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD
|
|||
if (!leaf) {
|
||||
if (pPage->vLen != sizeof(SPgno)) {
|
||||
tdbError("tdb/btree-decode-cell: invalid cell.");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_DATA_FMT;
|
||||
}
|
||||
|
||||
pDecoder->pgno = ((SPgno *)(pCell + nHeader))[0];
|
||||
|
@ -1546,7 +1549,7 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD
|
|||
if (pPage->vLen == TDB_VARIANT_LEN) {
|
||||
if (!leaf) {
|
||||
tdbError("tdb/btree-decode-cell: not a leaf page.");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_DATA_FMT;
|
||||
}
|
||||
nHeader += tdbGetVarInt(pCell + nHeader, &(pDecoder->vLen));
|
||||
} else {
|
||||
|
@ -1556,7 +1559,7 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD
|
|||
// 2. Decode payload part
|
||||
ret = tdbBtreeDecodePayload(pPage, pCell, nHeader, pDecoder, pTxn, pBt);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1610,7 +1613,7 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *
|
|||
while (pgno != 0) {
|
||||
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
SCell *ofpCell = tdbPageGetCell(ofp, 0);
|
||||
|
@ -1627,7 +1630,7 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *
|
|||
ret = tdbPagerWrite(pBt->pPager, ofp);
|
||||
if (ret < 0) {
|
||||
tdbError("failed to write page since %s", terrstr());
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
tdbPageDropCell(ofp, 0, pTxn, pBt);
|
||||
|
@ -1664,12 +1667,13 @@ int tdbBtcOpen(SBTC *pBtc, SBTree *pBt, TXN *pTxn) {
|
|||
if (pTxn == NULL) {
|
||||
TXN *pTxn = tdbOsCalloc(1, sizeof(*pTxn));
|
||||
if (!pTxn) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (tdbTxnOpen(pTxn, 0, tdbDefaultMalloc, tdbDefaultFree, NULL, 0) < 0) {
|
||||
int32_t ret = tdbTxnOpen(pTxn, 0, tdbDefaultMalloc, tdbDefaultFree, NULL, 0);
|
||||
if (ret < 0) {
|
||||
tdbOsFree(pTxn);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
pBtc->pTxn = pTxn;
|
||||
|
@ -1698,12 +1702,12 @@ int tdbBtcMoveToFirst(SBTC *pBtc) {
|
|||
&((SBtreeInitPageArg){.pBt = pBt, .flags = TDB_BTREE_ROOT | TDB_BTREE_LEAF}), pBtc->pTxn);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btc-move-tofirst: fetch page failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!TDB_BTREE_PAGE_IS_ROOT(pBtc->pPage)) {
|
||||
tdbError("tdb/btc-move-tofirst: not a root page");
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
pBtc->iPage = 0;
|
||||
|
@ -1713,7 +1717,7 @@ int tdbBtcMoveToFirst(SBTC *pBtc) {
|
|||
// no any data, point to an invalid position
|
||||
if (!TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) {
|
||||
tdbError("tdb/btc-move-to-first: not a leaf page.");
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pBtc->idx = -1;
|
||||
|
@ -1722,7 +1726,7 @@ int tdbBtcMoveToFirst(SBTC *pBtc) {
|
|||
} else {
|
||||
// TODO
|
||||
tdbError("tdb/btc-move-to-first: move from a dirty cursor.");
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
#if 0
|
||||
// move from a position
|
||||
int iPage = 0;
|
||||
|
@ -1755,7 +1759,7 @@ int tdbBtcMoveToFirst(SBTC *pBtc) {
|
|||
ret = tdbBtcMoveDownward(pBtc);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btc-move-tofirst: btc move downward failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
pBtc->idx = 0;
|
||||
|
@ -1780,7 +1784,7 @@ int tdbBtcMoveToLast(SBTC *pBtc) {
|
|||
&((SBtreeInitPageArg){.pBt = pBt, .flags = TDB_BTREE_ROOT | TDB_BTREE_LEAF}), pBtc->pTxn);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btc-move-tolast: fetch page failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage);
|
||||
|
@ -1791,7 +1795,7 @@ int tdbBtcMoveToLast(SBTC *pBtc) {
|
|||
// no data at all, point to an invalid position
|
||||
if (!TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) {
|
||||
tdbError("tdb/btc-move-to-last: not a leaf page.");
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pBtc->idx = -1;
|
||||
|
@ -1800,7 +1804,7 @@ int tdbBtcMoveToLast(SBTC *pBtc) {
|
|||
} else {
|
||||
// TODO
|
||||
tdbError("tdb/btc-move-to-last: move from a dirty cursor.");
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
#if 0
|
||||
int iPage = 0;
|
||||
|
||||
|
@ -1838,7 +1842,7 @@ int tdbBtcMoveToLast(SBTC *pBtc) {
|
|||
ret = tdbBtcMoveDownward(pBtc);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btc-move-tolast: btc move downward failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage);
|
||||
|
@ -1860,7 +1864,7 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
|||
|
||||
// current cursor points to an invalid position
|
||||
if (pBtc->idx < 0) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx);
|
||||
|
@ -1868,12 +1872,12 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
|||
ret = tdbBtreeDecodeCell(pBtc->pPage, pCell, &cd, pBtc->pTxn, pBtc->pBt);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btree-next: decode cell failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
pKey = tdbRealloc(*ppKey, cd.kLen);
|
||||
if (pKey == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
*ppKey = pKey;
|
||||
|
@ -1885,7 +1889,7 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
|||
pVal = tdbRealloc(*ppVal, cd.vLen);
|
||||
if (pVal == NULL) {
|
||||
tdbFree(pKey);
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
memcpy(pVal, cd.pVal, cd.vLen);
|
||||
|
@ -1909,7 +1913,7 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
|||
ret = tdbBtcMoveToNext(pBtc);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btree-next: btc move to next failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1923,7 +1927,7 @@ int tdbBtreePrev(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
|||
|
||||
// current cursor points to an invalid position
|
||||
if (pBtc->idx < 0) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx);
|
||||
|
@ -1931,12 +1935,12 @@ int tdbBtreePrev(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
|||
ret = tdbBtreeDecodeCell(pBtc->pPage, pCell, &cd, pBtc->pTxn, pBtc->pBt);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btree-prev: decode cell failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
pKey = tdbRealloc(*ppKey, cd.kLen);
|
||||
if (pKey == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
*ppKey = pKey;
|
||||
|
@ -1948,7 +1952,7 @@ int tdbBtreePrev(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
|||
pVal = tdbRealloc(*ppVal, cd.vLen);
|
||||
if (pVal == NULL) {
|
||||
tdbFree(pKey);
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
*ppVal = pVal;
|
||||
|
@ -1959,7 +1963,7 @@ int tdbBtreePrev(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
|||
ret = tdbBtcMoveToPrev(pBtc);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btree-prev: btc move to prev failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1972,10 +1976,10 @@ int tdbBtcMoveToNext(SBTC *pBtc) {
|
|||
|
||||
if (!TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) {
|
||||
tdbError("tdb/btc-move-to-next: not a leaf page.");
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
if (pBtc->idx < 0) return -1;
|
||||
if (pBtc->idx < 0) return TSDB_CODE_FAILED;
|
||||
|
||||
pBtc->idx++;
|
||||
if (pBtc->idx < TDB_PAGE_TOTAL_CELLS(pBtc->pPage)) {
|
||||
|
@ -1994,7 +1998,7 @@ int tdbBtcMoveToNext(SBTC *pBtc) {
|
|||
|
||||
if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) {
|
||||
tdbError("tdb/btree-decode-cell: should not be a leaf page here.");
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (pBtc->idx <= TDB_PAGE_TOTAL_CELLS(pBtc->pPage)) {
|
||||
break;
|
||||
|
@ -2008,7 +2012,7 @@ int tdbBtcMoveToNext(SBTC *pBtc) {
|
|||
ret = tdbBtcMoveDownward(pBtc);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btc-move-tonext: btc move downward failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
pBtc->idx = 0;
|
||||
|
@ -2018,7 +2022,7 @@ int tdbBtcMoveToNext(SBTC *pBtc) {
|
|||
}
|
||||
|
||||
int tdbBtcMoveToPrev(SBTC *pBtc) {
|
||||
if (pBtc->idx < 0) return -1;
|
||||
if (pBtc->idx < 0) return TSDB_CODE_FAILED;
|
||||
|
||||
pBtc->idx--;
|
||||
if (pBtc->idx >= 0) {
|
||||
|
@ -2061,17 +2065,17 @@ static int tdbBtcMoveDownward(SBTC *pBtc) {
|
|||
|
||||
if (pBtc->idx < 0) {
|
||||
tdbError("tdb/btc-move-downward: invalid idx: %d.", pBtc->idx);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) {
|
||||
tdbError("tdb/btc-move-downward: should not be a leaf page here.");
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
if (TDB_BTREE_PAGE_IS_OVFL(pBtc->pPage)) {
|
||||
tdbError("tdb/btc-move-downward: should not be a ovfl page here.");
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
if (pBtc->idx < TDB_PAGE_TOTAL_CELLS(pBtc->pPage)) {
|
||||
|
@ -2083,7 +2087,7 @@ static int tdbBtcMoveDownward(SBTC *pBtc) {
|
|||
|
||||
if (!pgno) {
|
||||
tdbError("tdb/btc-move-downward: invalid pgno.");
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pBtc->pgStack[pBtc->iPage] = pBtc->pPage;
|
||||
|
@ -2096,14 +2100,14 @@ static int tdbBtcMoveDownward(SBTC *pBtc) {
|
|||
&((SBtreeInitPageArg){.pBt = pBtc->pBt, .flags = 0}), pBtc->pTxn);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btc-move-downward: fetch page failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tdbBtcMoveUpward(SBTC *pBtc) {
|
||||
if (pBtc->iPage == 0) return -1;
|
||||
if (pBtc->iPage == 0) return TSDB_CODE_FAILED;
|
||||
|
||||
tdbPagerReturnPage(pBtc->pBt->pPager, pBtc->pPage, pBtc->pTxn);
|
||||
|
||||
|
@ -2118,7 +2122,7 @@ int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int
|
|||
SCell *pCell;
|
||||
|
||||
if (pBtc->idx < 0 || pBtc->idx >= TDB_PAGE_TOTAL_CELLS(pBtc->pPage)) {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx);
|
||||
|
@ -2152,14 +2156,14 @@ int tdbBtcDelete(SBTC *pBtc) {
|
|||
|
||||
if (idx < 0 || idx >= nCells) {
|
||||
tdbError("tdb/btc-delete: idx: %d out of range[%d, %d).", idx, 0, nCells);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
// drop the cell on the leaf
|
||||
ret = tdbPagerWrite(pPager, pBtc->pPage);
|
||||
if (ret < 0) {
|
||||
tdbError("failed to write page since %s", terrstr());
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool destroyOfps = false;
|
||||
|
@ -2200,7 +2204,7 @@ int tdbBtcDelete(SBTC *pBtc) {
|
|||
ret = tdbPagerWrite(pPager, pPage);
|
||||
if (ret < 0) {
|
||||
tdbError("failed to write page since %s", terrstr());
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// update the cell with new key
|
||||
|
@ -2211,7 +2215,7 @@ int tdbBtcDelete(SBTC *pBtc) {
|
|||
if (ret < 0) {
|
||||
tdbOsFree(pCell);
|
||||
tdbError("tdb/btc-delete: page update cell failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
tdbOsFree(pCell);
|
||||
|
||||
|
@ -2229,7 +2233,7 @@ int tdbBtcDelete(SBTC *pBtc) {
|
|||
ret = tdbBtreeBalance(pBtc);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btc-delete: btree balance failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2242,7 +2246,7 @@ int tdbBtcDelete(SBTC *pBtc) {
|
|||
// delete the leaf page and do balance
|
||||
if (TDB_PAGE_TOTAL_CELLS(pBtc->pPage) != 0) {
|
||||
tdbError("tdb/btc-delete: page to be deleted should be empty.");
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
// printf("tdb/btc-delete: btree balance delete pgno: %d.\n", TDB_PAGE_PGNO(pBtc->pPage));
|
||||
|
@ -2250,7 +2254,7 @@ int tdbBtcDelete(SBTC *pBtc) {
|
|||
ret = tdbBtreeBalance(pBtc);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btc-delete: btree balance failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2268,7 +2272,7 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int
|
|||
|
||||
if (pBtc->idx < 0) {
|
||||
tdbError("tdb/btc-upsert: invalid idx: %d.", pBtc->idx);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
// alloc space
|
||||
|
@ -2276,7 +2280,7 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int
|
|||
pBuf = tdbRealloc(pBtc->pBt->pBuf, pBtc->pBt->pageSize > szBuf ? szBuf : pBtc->pBt->pageSize);
|
||||
if (pBuf == NULL) {
|
||||
tdbError("tdb/btc-upsert: realloc pBuf failed.");
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
pBtc->pBt->pBuf = pBuf;
|
||||
pCell = (SCell *)pBtc->pBt->pBuf;
|
||||
|
@ -2285,35 +2289,35 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int
|
|||
ret = tdbBtreeEncodeCell(pBtc->pPage, pKey, kLen, pData, nData, pCell, &szCell, pBtc->pTxn, pBtc->pBt);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btc-upsert: btree encode cell failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// mark dirty
|
||||
ret = tdbPagerWrite(pBtc->pBt->pPager, pBtc->pPage);
|
||||
if (ret < 0) {
|
||||
tdbError("failed to write page since %s", terrstr());
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// insert or update
|
||||
if (insert) {
|
||||
if (pBtc->idx > nCells) {
|
||||
tdbError("tdb/btc-upsert: invalid idx: %d, nCells: %d.", pBtc->idx, nCells);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
ret = tdbPageInsertCell(pBtc->pPage, pBtc->idx, pCell, szCell, 0);
|
||||
} else {
|
||||
if (pBtc->idx >= nCells) {
|
||||
tdbError("tdb/btc-upsert: invalid idx: %d, nCells: %d.", pBtc->idx, nCells);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
ret = tdbPageUpdateCell(pBtc->pPage, pBtc->idx, pCell, szCell, pBtc->pTxn, pBtc->pBt);
|
||||
}
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btc-upsert: page insert/update cell failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
bool destroyOfps = false;
|
||||
|
@ -2327,7 +2331,7 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int
|
|||
ret = tdbBtreeBalance(pBtc);
|
||||
if (ret < 0) {
|
||||
tdbError("tdb/btc-upsert: btree balance failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
@ -2365,7 +2369,7 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
|
|||
if (ret < 0) {
|
||||
// TODO
|
||||
tdbError("tdb/btc-move-to: fetch page failed with ret: %d.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
pBtc->iPage = 0;
|
||||
|
@ -2375,7 +2379,7 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
|
|||
} else {
|
||||
// TODO
|
||||
tdbError("tdb/btc-move-to: move from a dirty cursor.");
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
#if 0
|
||||
SPage *pPage;
|
||||
int idx;
|
||||
|
@ -2499,7 +2503,7 @@ int tdbBtcClose(SBTC *pBtc) {
|
|||
for (;;) {
|
||||
if (NULL == pBtc->pPage) {
|
||||
tdbError("tdb/btc-close: null ptr pPage.");
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
tdbPagerReturnPage(pBtc->pBt->pPager, pBtc->pPage, pBtc->pTxn);
|
||||
|
|
|
@ -862,7 +862,7 @@ static int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno, TXN *pTxn) {
|
|||
// Try to allocate from the free list of the pager
|
||||
ret = tdbPagerAllocFreePage(pPager, ppgno, pTxn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (*ppgno != 0) return 0;
|
||||
|
@ -875,7 +875,7 @@ static int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno, TXN *pTxn) {
|
|||
|
||||
if (*ppgno == 0) {
|
||||
tdbError("tdb/pager:%p, alloc new page failed.", pPager);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -907,7 +907,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
|
|||
if (nRead < pPage->pageSize) {
|
||||
tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32, pPager, pgno, nRead, pPage->pageSize);
|
||||
TDB_UNLOCK_PAGE(pPage);
|
||||
return -1;
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
int32_t encryptAlgorithm = pPager->pEnv->encryptAlgorithm;
|
||||
|
@ -954,7 +954,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
|
|||
tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32 " init page failed.", pPager, pgno, nRead,
|
||||
pPage->pageSize);
|
||||
TDB_UNLOCK_PAGE(pPage);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
tmemory_barrier();
|
||||
|
@ -975,7 +975,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
|
|||
} else {
|
||||
tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32 " lock page failed.", pPager, pgno, nRead,
|
||||
pPage->pageSize);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1127,14 +1127,12 @@ static int tdbPagerRestore(SPager *pPager, const char *jFileName) {
|
|||
|
||||
if (tdbOsClose(jfd) < 0) {
|
||||
tdbError("failed to close jfd due to %s. jFileName:%s", strerror(errno), pPager->jFileName);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
return terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
if (tdbOsRemove(jFileName) < 0 && errno != ENOENT) {
|
||||
tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), pPager->jFileName);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
return terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tjson.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#define LOG_MAX_LINE_SIZE (10024)
|
||||
#define LOG_MAX_LINE_BUFFER_SIZE (LOG_MAX_LINE_SIZE + 3)
|
||||
|
@ -146,7 +147,7 @@ static int32_t taosStartLog() {
|
|||
TdThreadAttr threadAttr;
|
||||
taosThreadAttrInit(&threadAttr);
|
||||
if (taosThreadCreate(&(tsLogObj.logHandle->asyncThread), &threadAttr, taosAsyncOutputLog, tsLogObj.logHandle) != 0) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
taosThreadAttrDestroy(&threadAttr);
|
||||
return 0;
|
||||
|
@ -176,13 +177,13 @@ int32_t taosInitSlowLog() {
|
|||
}
|
||||
|
||||
tsLogObj.slowHandle = taosLogBuffNew(LOG_SLOW_BUF_SIZE);
|
||||
if (tsLogObj.slowHandle == NULL) return -1;
|
||||
if (tsLogObj.slowHandle == NULL) return terrno;
|
||||
|
||||
taosUmaskFile(0);
|
||||
tsLogObj.slowHandle->pFile = taosOpenFile(fullName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
if (tsLogObj.slowHandle->pFile == NULL) {
|
||||
printf("\nfailed to open slow log file:%s, reason:%s\n", fullName, strerror(errno));
|
||||
return -1;
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -209,11 +210,11 @@ int32_t taosInitLog(const char *logName, int32_t maxFiles) {
|
|||
taosUpdateDaylight();
|
||||
|
||||
tsLogObj.logHandle = taosLogBuffNew(LOG_DEFAULT_BUF_SIZE);
|
||||
if (tsLogObj.logHandle == NULL) return -1;
|
||||
if (taosOpenLogFile(fullName, maxFiles) < 0) return -1;
|
||||
if (tsLogObj.logHandle == NULL) return terrno;
|
||||
TAOS_CHECK_RETURN(taosOpenLogFile(fullName, maxFiles));
|
||||
|
||||
if (taosInitSlowLog() < 0) return -1;
|
||||
if (taosStartLog() < 0) return -1;
|
||||
TAOS_CHECK_RETURN(taosInitSlowLog());
|
||||
TAOS_CHECK_RETURN(taosStartLog());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -484,7 +485,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxFileNum) {
|
|||
|
||||
if (tsLogObj.logHandle->pFile == NULL) {
|
||||
printf("\nfailed to open log file:%s, reason:%s\n", fileName, strerror(errno));
|
||||
return -1;
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
taosLockLogFile(tsLogObj.logHandle->pFile);
|
||||
|
||||
|
@ -492,7 +493,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxFileNum) {
|
|||
int64_t filesize = 0;
|
||||
if (taosFStatFile(tsLogObj.logHandle->pFile, &filesize, NULL) < 0) {
|
||||
printf("\nfailed to fstat log file:%s, reason:%s\n", fileName, strerror(errno));
|
||||
return -1;
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
tsLogObj.lines = (int32_t)(filesize / 60);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "tarray.h"
|
||||
#include "tdef.h"
|
||||
#include "tlog.h"
|
||||
#include "tutil.h"
|
||||
|
||||
typedef struct SLRUEntry SLRUEntry;
|
||||
typedef struct SLRUEntryTable SLRUEntryTable;
|
||||
|
@ -114,13 +115,13 @@ static int taosLRUEntryTableInit(SLRUEntryTable *table, int maxUpperHashBits) {
|
|||
table->lengthBits = 4;
|
||||
table->list = taosMemoryCalloc(1 << table->lengthBits, sizeof(SLRUEntry *));
|
||||
if (!table->list) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
table->elems = 0;
|
||||
table->maxLengthBits = maxUpperHashBits;
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static void taosLRUEntryTableApply(SLRUEntryTable *table, _taos_lru_table_func_t func, uint32_t begin, uint32_t end) {
|
||||
|
@ -349,9 +350,7 @@ static void taosLRUCacheShardSetCapacity(SLRUCacheShard *shard, size_t capacity)
|
|||
|
||||
static int taosLRUCacheShardInit(SLRUCacheShard *shard, size_t capacity, bool strict, double highPriPoolRatio,
|
||||
int maxUpperHashBits) {
|
||||
if (taosLRUEntryTableInit(&shard->table, maxUpperHashBits) < 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(taosLRUEntryTableInit(&shard->table, maxUpperHashBits));
|
||||
|
||||
taosThreadMutexInit(&shard->mutex, NULL);
|
||||
|
||||
|
@ -372,7 +371,7 @@ static int taosLRUCacheShardInit(SLRUCacheShard *shard, size_t capacity, bool st
|
|||
|
||||
taosLRUCacheShardSetCapacity(shard, capacity);
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static void taosLRUCacheShardCleanup(SLRUCacheShard *shard) {
|
||||
|
@ -671,16 +670,13 @@ static int getDefaultCacheShardBits(size_t capacity) {
|
|||
|
||||
SLRUCache *taosLRUCacheInit(size_t capacity, int numShardBits, double highPriPoolRatio) {
|
||||
if (numShardBits >= 20) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
}
|
||||
if (highPriPoolRatio < 0.0 || highPriPoolRatio > 1.0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
}
|
||||
SLRUCache *cache = taosMemoryCalloc(1, sizeof(SLRUCache));
|
||||
if (!cache) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -692,14 +688,15 @@ SLRUCache *taosLRUCacheInit(size_t capacity, int numShardBits, double highPriPoo
|
|||
cache->shards = taosMemoryCalloc(numShards, sizeof(SLRUCacheShard));
|
||||
if (!cache->shards) {
|
||||
taosMemoryFree(cache);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool strictCapacity = 1;
|
||||
size_t perShard = (capacity + (numShards - 1)) / numShards;
|
||||
for (int i = 0; i < numShards; ++i) {
|
||||
taosLRUCacheShardInit(&cache->shards[i], perShard, strictCapacity, highPriPoolRatio, 32 - numShardBits);
|
||||
if (TSDB_CODE_SUCCESS !=
|
||||
taosLRUCacheShardInit(&cache->shards[i], perShard, strictCapacity, highPriPoolRatio, 32 - numShardBits))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cache->numShards = numShards;
|
||||
|
|
|
@ -27,8 +27,10 @@ static void *taosProcessSchedQueue(void *param);
|
|||
static void taosDumpSchedulerStatus(void *qhandle, void *tmrId);
|
||||
|
||||
void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *label, SSchedQueue *pSched) {
|
||||
bool schedMalloced = false;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
bool schedMalloced = false;
|
||||
|
||||
if (NULL == pSched) {
|
||||
pSched = (SSchedQueue *)taosMemoryCalloc(sizeof(SSchedQueue), 1);
|
||||
if (pSched == NULL) {
|
||||
|
@ -95,23 +97,32 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
|
|||
atomic_store_8(&pSched->stop, 0);
|
||||
for (int32_t i = 0; i < numOfThreads; ++i) {
|
||||
TdThreadAttr attr;
|
||||
taosThreadAttrInit(&attr);
|
||||
taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
int32_t code = taosThreadCreate(pSched->qthread + i, &attr, taosProcessSchedQueue, (void *)pSched);
|
||||
taosThreadAttrDestroy(&attr);
|
||||
if (code != 0) {
|
||||
uError("%s: failed to create rpc thread(%s)", label, strerror(errno));
|
||||
taosCleanUpScheduler(pSched);
|
||||
if (schedMalloced) {
|
||||
taosMemoryFree(pSched);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
code = taosThreadAttrInit(&attr);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
code = taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
code = taosThreadCreate(pSched->qthread + i, &attr, taosProcessSchedQueue, (void *)pSched);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
(void)taosThreadAttrDestroy(&attr);
|
||||
++pSched->numOfThreads;
|
||||
}
|
||||
|
||||
uDebug("%s scheduler is initialized, numOfThreads:%d", label, pSched->numOfThreads);
|
||||
|
||||
_end:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosCleanUpScheduler(pSched);
|
||||
if (schedMalloced) {
|
||||
taosMemoryFree(pSched);
|
||||
}
|
||||
terrno = code;
|
||||
uError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (void *)pSched;
|
||||
}
|
||||
|
||||
|
@ -220,22 +231,22 @@ void taosCleanUpScheduler(void *param) {
|
|||
|
||||
for (int32_t i = 0; i < pSched->numOfThreads; ++i) {
|
||||
if (taosCheckPthreadValid(pSched->qthread[i])) {
|
||||
tsem_post(&pSched->fullSem);
|
||||
(void)tsem_post(&pSched->fullSem);
|
||||
}
|
||||
}
|
||||
for (int32_t i = 0; i < pSched->numOfThreads; ++i) {
|
||||
if (taosCheckPthreadValid(pSched->qthread[i])) {
|
||||
taosThreadJoin(pSched->qthread[i], NULL);
|
||||
(void)taosThreadJoin(pSched->qthread[i], NULL);
|
||||
taosThreadClear(&pSched->qthread[i]);
|
||||
}
|
||||
}
|
||||
|
||||
tsem_destroy(&pSched->emptySem);
|
||||
tsem_destroy(&pSched->fullSem);
|
||||
taosThreadMutexDestroy(&pSched->queueMutex);
|
||||
(void)tsem_destroy(&pSched->emptySem);
|
||||
(void)tsem_destroy(&pSched->fullSem);
|
||||
(void)taosThreadMutexDestroy(&pSched->queueMutex);
|
||||
|
||||
if (pSched->pTimer) {
|
||||
taosTmrStop(pSched->pTimer);
|
||||
(void)taosTmrStop(pSched->pTimer);
|
||||
pSched->pTimer = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -516,7 +516,7 @@ static int32_t taosTmrModuleInit(void) {
|
|||
tmrCtrls = taosMemoryMalloc(sizeof(tmr_ctrl_t) * tsMaxTmrCtrl);
|
||||
if (tmrCtrls == NULL) {
|
||||
tmrError("failed to allocate memory for timer controllers.");
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
memset(&timerMap, 0, sizeof(timerMap));
|
||||
|
@ -535,14 +535,14 @@ static int32_t taosTmrModuleInit(void) {
|
|||
time_wheel_t* wheel = wheels + i;
|
||||
if (taosThreadMutexInit(&wheel->mutex, NULL) != 0) {
|
||||
tmrError("failed to create the mutex for wheel, reason:%s", strerror(errno));
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
wheel->nextScanAt = now + wheel->resolution;
|
||||
wheel->index = 0;
|
||||
wheel->slots = (tmr_obj_t**)taosMemoryCalloc(wheel->size, sizeof(tmr_obj_t*));
|
||||
if (wheel->slots == NULL) {
|
||||
tmrError("failed to allocate wheel slots");
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
timerMap.size += wheel->size;
|
||||
}
|
||||
|
@ -551,7 +551,7 @@ static int32_t taosTmrModuleInit(void) {
|
|||
timerMap.slots = (timer_list_t*)taosMemoryCalloc(timerMap.size, sizeof(timer_list_t));
|
||||
if (timerMap.slots == NULL) {
|
||||
tmrError("failed to allocate hash map");
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
tmrQhandle = taosInitScheduler(10000, taosTmrThreads, "tmr", NULL);
|
||||
|
@ -570,7 +570,7 @@ static int32_t taosTmrInitModule(void) {
|
|||
if (atomic_load_32(&tmrModuleInit) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
while (true) {
|
||||
if (0 == atomic_val_compare_exchange_32(&tmrModuleInit, 0, 1)) {
|
||||
atomic_store_32(&tmrModuleInit, taosTmrModuleInit());
|
||||
|
@ -609,7 +609,7 @@ void* taosTmrInit(int32_t maxNumOfTmrs, int32_t resolution, int32_t longest, con
|
|||
}
|
||||
|
||||
tstrncpy(ctrl->label, label, sizeof(ctrl->label));
|
||||
|
||||
|
||||
tmrDebug("%s timer controller is initialized, number of timer controllers: %d.", label, numOfTmrCtrl);
|
||||
return ctrl;
|
||||
}
|
||||
|
|
|
@ -107,6 +107,9 @@ char **strsplit(char *z, const char *delim, int32_t *num) {
|
|||
int32_t size = 4;
|
||||
|
||||
char **split = taosMemoryMalloc(POINTER_BYTES * size);
|
||||
if (split == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (char *p = strsep(&z, delim); p != NULL; p = strsep(&z, delim)) {
|
||||
size_t len = strlen(p);
|
||||
|
@ -118,7 +121,10 @@ char **strsplit(char *z, const char *delim, int32_t *num) {
|
|||
if ((*num) >= size) {
|
||||
size = (size << 1);
|
||||
split = taosMemoryRealloc(split, POINTER_BYTES * size);
|
||||
ASSERTS(NULL != split, "realloc memory failed. size=%d", (int32_t) POINTER_BYTES * size);
|
||||
if (split == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ASSERTS(NULL != split, "realloc memory failed. size=%d", (int32_t)POINTER_BYTES * size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,10 +151,10 @@ char *strnchr(const char *haystack, char needle, int32_t len, bool skipquote) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
TdUcs4* wcsnchr(const TdUcs4* haystack, TdUcs4 needle, size_t len) {
|
||||
for(int32_t i = 0; i < len; ++i) {
|
||||
TdUcs4 *wcsnchr(const TdUcs4 *haystack, TdUcs4 needle, size_t len) {
|
||||
for (int32_t i = 0; i < len; ++i) {
|
||||
if (haystack[i] == needle) {
|
||||
return (TdUcs4*) &haystack[i];
|
||||
return (TdUcs4 *)&haystack[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -314,6 +320,9 @@ char *strbetween(char *string, char *begin, char *end) {
|
|||
int32_t size = (int32_t)(_end - _begin);
|
||||
if (_end != NULL && size > 0) {
|
||||
result = (char *)taosMemoryCalloc(1, size);
|
||||
if (result) {
|
||||
return NULL;
|
||||
}
|
||||
memcpy(result, _begin + strlen(begin), size - +strlen(begin));
|
||||
}
|
||||
}
|
||||
|
@ -324,13 +333,13 @@ int32_t tintToHex(uint64_t val, char hex[]) {
|
|||
const char hexstr[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
|
||||
int32_t j = 0, k = 0;
|
||||
if (val == 0) {
|
||||
if (val == 0) {
|
||||
hex[j++] = hexstr[0];
|
||||
return j;
|
||||
}
|
||||
|
||||
// ignore the initial 0
|
||||
while((val & (((uint64_t)0xfL) << ((15 - k) * 4))) == 0) {
|
||||
while ((val & (((uint64_t)0xfL) << ((15 - k) * 4))) == 0) {
|
||||
k += 1;
|
||||
}
|
||||
|
||||
|
@ -346,10 +355,10 @@ int32_t titoa(uint64_t val, size_t radix, char str[]) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
const char* s = "0123456789abcdef";
|
||||
char buf[65] = {0};
|
||||
const char *s = "0123456789abcdef";
|
||||
char buf[65] = {0};
|
||||
|
||||
int32_t i = 0;
|
||||
int32_t i = 0;
|
||||
uint64_t v = val;
|
||||
do {
|
||||
buf[i++] = s[v % radix];
|
||||
|
@ -357,7 +366,7 @@ int32_t titoa(uint64_t val, size_t radix, char str[]) {
|
|||
} while (v > 0);
|
||||
|
||||
// reverse order
|
||||
for(int32_t j = 0; j < i; ++j) {
|
||||
for (int32_t j = 0; j < i; ++j) {
|
||||
str[j] = buf[i - j - 1];
|
||||
}
|
||||
|
||||
|
@ -429,8 +438,8 @@ void taosIpPort2String(uint32_t ip, uint16_t port, char *str) {
|
|||
|
||||
size_t tstrncspn(const char *str, size_t size, const char *reject, size_t rsize) {
|
||||
if (rsize == 0 || rsize == 1) {
|
||||
char* p = strnchr(str, reject[0], size, false);
|
||||
return (p == NULL)? size:(p-str);
|
||||
char *p = strnchr(str, reject[0], size, false);
|
||||
return (p == NULL) ? size : (p - str);
|
||||
}
|
||||
|
||||
/* Use multiple small memsets to enable inlining on most targets. */
|
||||
|
@ -441,15 +450,15 @@ size_t tstrncspn(const char *str, size_t size, const char *reject, size_t rsize)
|
|||
memset(p + 192, 0, 64);
|
||||
|
||||
unsigned char *s = (unsigned char *)reject;
|
||||
int32_t index = 0;
|
||||
int32_t index = 0;
|
||||
do {
|
||||
p[s[index++]] = 1;
|
||||
} while (index < rsize);
|
||||
|
||||
s = (unsigned char*) str;
|
||||
s = (unsigned char *)str;
|
||||
int32_t times = size >> 2;
|
||||
if (times == 0) {
|
||||
for(int32_t i = 0; i < size; ++i) {
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
if (p[s[i]]) {
|
||||
return i;
|
||||
}
|
||||
|
@ -460,7 +469,7 @@ size_t tstrncspn(const char *str, size_t size, const char *reject, size_t rsize)
|
|||
|
||||
index = 0;
|
||||
uint32_t c0, c1, c2, c3;
|
||||
for(int32_t i = 0; i < times; ++i, index += 4) {
|
||||
for (int32_t i = 0; i < times; ++i, index += 4) {
|
||||
int32_t j = index;
|
||||
c0 = p[s[j]];
|
||||
c1 = p[s[j + 1]];
|
||||
|
@ -474,7 +483,7 @@ size_t tstrncspn(const char *str, size_t size, const char *reject, size_t rsize)
|
|||
}
|
||||
|
||||
int32_t offset = times * 4;
|
||||
for(int32_t i = offset; i < size; ++i) {
|
||||
for (int32_t i = offset; i < size; ++i) {
|
||||
if (p[s[i]]) {
|
||||
return i;
|
||||
}
|
||||
|
@ -485,8 +494,8 @@ size_t tstrncspn(const char *str, size_t size, const char *reject, size_t rsize)
|
|||
|
||||
size_t twcsncspn(const TdUcs4 *wcs, size_t size, const TdUcs4 *reject, size_t rsize) {
|
||||
if (rsize == 0 || rsize == 1) {
|
||||
TdUcs4* p = wcsnchr(wcs, reject[0], size);
|
||||
return (p == NULL)? size:(p-wcs);
|
||||
TdUcs4 *p = wcsnchr(wcs, reject[0], size);
|
||||
return (p == NULL) ? size : (p - wcs);
|
||||
}
|
||||
|
||||
size_t index = 0;
|
||||
|
@ -497,19 +506,17 @@ size_t twcsncspn(const TdUcs4 *wcs, size_t size, const TdUcs4 *reject, size_t rs
|
|||
return index;
|
||||
}
|
||||
|
||||
int32_t parseCfgReal(const char* str, double* out) {
|
||||
int32_t parseCfgReal(const char *str, double *out) {
|
||||
double val;
|
||||
char *endPtr;
|
||||
errno = 0;
|
||||
val = taosStr2Double(str, &endPtr);
|
||||
if (str == endPtr || errno == ERANGE || isnan(val)) {
|
||||
terrno = TSDB_CODE_INVALID_CFG_VALUE;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_INVALID_CFG_VALUE;
|
||||
}
|
||||
while(isspace((unsigned char)*endPtr)) endPtr++;
|
||||
while (isspace((unsigned char)*endPtr)) endPtr++;
|
||||
if (*endPtr != '\0') {
|
||||
terrno = TSDB_CODE_INVALID_CFG_VALUE;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_INVALID_CFG_VALUE;
|
||||
}
|
||||
*out = val;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
|
Loading…
Reference in New Issue