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