Merge remote-tracking branch 'origin/3.0' into fix/addErrorToMgmt
This commit is contained in:
commit
4977dfc7ea
|
@ -401,7 +401,7 @@ pipeline {
|
|||
}
|
||||
}
|
||||
stage('linux test') {
|
||||
agent{label " slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || slave1_59 || slave1_63 || worker03 || slave215 || slave217 || slave219 "}
|
||||
agent{label "slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || worker03 || slave215 || slave217 || slave219 "}
|
||||
options { skipDefaultCheckout() }
|
||||
when {
|
||||
changeRequest()
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "taoserror.h"
|
||||
#include "tcoding.h"
|
||||
#include "tutil.h"
|
||||
|
||||
struct SBuffer {
|
||||
uint32_t size;
|
||||
|
@ -67,8 +68,7 @@ static FORCE_INLINE int32_t tBufferEnsureCapacity(SBuffer *buffer, uint32_t capa
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t tBufferPut(SBuffer *buffer, const void *data, uint32_t size) {
|
||||
int32_t code = tBufferEnsureCapacity(buffer, buffer->size + size);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferEnsureCapacity(buffer, buffer->size + size));
|
||||
memcpy((char *)buffer->data + buffer->size, data, size);
|
||||
buffer->size += size;
|
||||
return 0;
|
||||
|
@ -119,10 +119,8 @@ static FORCE_INLINE int32_t tBufferPutU16v(SBuffer *buffer, uint16_t value) { re
|
|||
static FORCE_INLINE int32_t tBufferPutU32v(SBuffer *buffer, uint32_t value) { return tBufferPutU64v(buffer, value); }
|
||||
|
||||
static FORCE_INLINE int32_t tBufferPutU64v(SBuffer *buffer, uint64_t value) {
|
||||
int32_t code;
|
||||
while (value >= 0x80) {
|
||||
code = tBufferPutU8(buffer, (value & 0x7F) | 0x80);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutU8(buffer, (value & 0x7F) | 0x80));
|
||||
value >>= 7;
|
||||
}
|
||||
return tBufferPutU8(buffer, value);
|
||||
|
@ -141,8 +139,7 @@ static FORCE_INLINE int32_t tBufferPutI64v(SBuffer *buffer, int64_t value) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t tBufferPutBinary(SBuffer *buffer, const void *data, uint32_t size) {
|
||||
int32_t code = tBufferPutU32v(buffer, size);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutU32v(buffer, size));
|
||||
return tBufferPut(buffer, data, size);
|
||||
}
|
||||
|
||||
|
@ -324,8 +321,7 @@ static int32_t tBufferGetF32(SBufferReader *reader, float *value) {
|
|||
float f;
|
||||
uint32_t u;
|
||||
} u;
|
||||
int32_t code = tBufferGetU32(reader, &u.u);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetU32(reader, &u.u));
|
||||
if (value) {
|
||||
*value = u.f;
|
||||
}
|
||||
|
@ -337,8 +333,7 @@ static int32_t tBufferGetF64(SBufferReader *reader, double *value) {
|
|||
double f;
|
||||
uint64_t u;
|
||||
} u;
|
||||
int32_t code = tBufferGetU64(reader, &u.u);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetU64(reader, &u.u));
|
||||
if (value) {
|
||||
*value = u.f;
|
||||
}
|
||||
|
|
|
@ -172,6 +172,8 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_UNUSED(expr) (void)(expr)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -54,6 +54,7 @@ int32_t mndInitAcct(SMnode *pMnode) {
|
|||
void mndCleanupAcct(SMnode *pMnode) {}
|
||||
|
||||
static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
||||
int32_t code = 0;
|
||||
SAcctObj acctObj = {0};
|
||||
tstrncpy(acctObj.acct, TSDB_DEFAULT_USER, TSDB_USER_LEN);
|
||||
acctObj.createdTime = taosGetTimestampMs();
|
||||
|
@ -76,7 +77,10 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
|||
};
|
||||
|
||||
SSdbRaw *pRaw = mndAcctActionEncode(&acctObj);
|
||||
if (pRaw == NULL) return -1;
|
||||
if (pRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mInfo("acct:%s, will be created when deploying, raw:%p", acctObj.acct, pRaw);
|
||||
|
@ -84,21 +88,24 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
|||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-acct");
|
||||
if (pTrans == NULL) {
|
||||
sdbFreeRaw(pRaw);
|
||||
mError("acct:%s, failed to create since %s", acctObj.acct, terrstr());
|
||||
return -1;
|
||||
code = terrno;
|
||||
mError("acct:%s, failed to create since %s", acctObj.acct, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, used to create acct:%s", pTrans->id, acctObj.acct);
|
||||
|
||||
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) {
|
||||
mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
|
||||
code = mndTransAppendCommitlog(pTrans, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to commit redo log since %s", pTrans->id, tstrerror(code));
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
code = mndTransPrepare(pMnode, pTrans);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -216,31 +223,36 @@ static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) {
|
|||
}
|
||||
|
||||
static int32_t mndProcessCreateAcctReq(SRpcMsg *pReq) {
|
||||
if (mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_CREATE_ACCT) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_CREATE_ACCT);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterAcctReq(SRpcMsg *pReq) {
|
||||
if (mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_ALTER_ACCT) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_ALTER_ACCT);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropAcctReq(SRpcMsg *pReq) {
|
||||
if (mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_DROP_ACCT) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
if ((code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_DROP_ACCT)) != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
|
@ -57,6 +57,7 @@ static int32_t mndArbCheckToken(const char *token1, const char *token2) {
|
|||
}
|
||||
|
||||
int32_t mndInitArbGroup(SMnode *pMnode) {
|
||||
int32_t code = 0;
|
||||
SSdbTable table = {
|
||||
.sdbType = SDB_ARBGROUP,
|
||||
.keyType = SDB_KEY_INT32,
|
||||
|
@ -78,6 +79,10 @@ int32_t mndInitArbGroup(SMnode *pMnode) {
|
|||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_ARBGROUP, mndCancelGetNextArbGroup);
|
||||
|
||||
arbUpdateHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
|
||||
if (arbUpdateHash == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return sdbSetTable(pMnode->pSdb, table);
|
||||
}
|
||||
|
@ -248,50 +253,74 @@ _OVER:
|
|||
}
|
||||
|
||||
int32_t mndSetCreateArbGroupRedoLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendRedolog(pTrans, pRedoRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetCreateArbGroupUndoLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pUndoRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pUndoRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
if (pUndoRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendUndolog(pTrans, pUndoRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetCreateArbGroupCommitLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw) != 0)) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetDropArbGroupPrepareLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendPrepareLog(pTrans, pRedoRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetDropArbGroupRedoLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendRedolog(pTrans, pRedoRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetDropArbGroupCommitLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -343,6 +372,7 @@ static int32_t mndSendArbHeartBeatReq(SDnodeObj *pDnode, char *arbToken, int64_t
|
|||
}
|
||||
|
||||
static int32_t mndProcessArbHbTimer(SRpcMsg *pReq) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SArbGroup *pArbGroup = NULL;
|
||||
|
@ -377,7 +407,7 @@ static int32_t mndProcessArbHbTimer(SRpcMsg *pReq) {
|
|||
}
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-hb timer");
|
||||
pIter = taosHashIterate(pDnodeHash, NULL);
|
||||
while (pIter) {
|
||||
|
@ -386,7 +416,7 @@ static int32_t mndProcessArbHbTimer(SRpcMsg *pReq) {
|
|||
pIter = taosHashIterate(pDnodeHash, pIter);
|
||||
}
|
||||
taosHashCleanup(pDnodeHash);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int64_t nowMs = taosGetTimestampMs();
|
||||
|
@ -447,6 +477,7 @@ static void *mndBuildArbCheckSyncReq(int32_t *pContLen, int32_t vgId, char *arbT
|
|||
|
||||
static int32_t mndSendArbCheckSyncReq(SMnode *pMnode, int32_t vgId, char *arbToken, int64_t term, char *member0Token,
|
||||
char *member1Token) {
|
||||
int32_t code = 0;
|
||||
int32_t contLen = 0;
|
||||
void *pHead = mndBuildArbCheckSyncReq(&contLen, vgId, arbToken, term, member0Token, member1Token);
|
||||
if (!pHead) {
|
||||
|
@ -459,10 +490,12 @@ static int32_t mndSendArbCheckSyncReq(SMnode *pMnode, int32_t vgId, char *arbTok
|
|||
if (epSet.numOfEps == 0) {
|
||||
mError("vgId:%d, failed to send check-sync request since no epSet found", vgId);
|
||||
rpcFreeCont(pHead);
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t code = tmsgSendReq(&epSet, &rpcMsg);
|
||||
code = tmsgSendReq(&epSet, &rpcMsg);
|
||||
if (code != 0) {
|
||||
mError("vgId:%d, failed to send check-sync request since 0x%x", vgId, code);
|
||||
} else {
|
||||
|
@ -502,11 +535,14 @@ static void *mndBuildArbSetAssignedLeaderReq(int32_t *pContLen, int32_t vgId, ch
|
|||
|
||||
static int32_t mndSendArbSetAssignedLeaderReq(SMnode *pMnode, int32_t dnodeId, int32_t vgId, char *arbToken,
|
||||
int64_t term, char *memberToken) {
|
||||
int32_t code = 0;
|
||||
int32_t contLen = 0;
|
||||
void *pHead = mndBuildArbSetAssignedLeaderReq(&contLen, vgId, arbToken, term, memberToken);
|
||||
if (!pHead) {
|
||||
mError("vgId:%d, failed to build set-assigned request", vgId);
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_SYNC_SET_ASSIGNED_LEADER, .pCont = pHead, .contLen = contLen};
|
||||
|
||||
|
@ -514,9 +550,11 @@ static int32_t mndSendArbSetAssignedLeaderReq(SMnode *pMnode, int32_t dnodeId, i
|
|||
if (epSet.numOfEps == 0) {
|
||||
mError("dnodeId:%d vgId:%d, failed to send arb-set-assigned request to dnode since no epSet found", dnodeId, vgId);
|
||||
rpcFreeCont(pHead);
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
int32_t code = tmsgSendReq(&epSet, &rpcMsg);
|
||||
code = tmsgSendReq(&epSet, &rpcMsg);
|
||||
if (code != 0) {
|
||||
mError("dnodeId:%d vgId:%d, failed to send arb-set-assigned request to dnode since 0x%x", dnodeId, vgId, code);
|
||||
} else {
|
||||
|
@ -526,6 +564,7 @@ static int32_t mndSendArbSetAssignedLeaderReq(SMnode *pMnode, int32_t dnodeId, i
|
|||
}
|
||||
|
||||
static int32_t mndProcessArbCheckSyncTimer(SRpcMsg *pReq) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SArbGroup *pArbGroup = NULL;
|
||||
|
@ -533,14 +572,16 @@ static int32_t mndProcessArbCheckSyncTimer(SRpcMsg *pReq) {
|
|||
void *pIter = NULL;
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-check-sync timer");
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
int64_t term = mndGetTerm(pMnode);
|
||||
if (term < 0) {
|
||||
mError("arb failed to get term since %s", terrstr());
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int64_t roleTimeMs = mndGetRoleTimeMs(pMnode);
|
||||
|
@ -747,13 +788,13 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndProcessArbUpdateGroupBatchReq(SRpcMsg *pReq) {
|
||||
int ret = -1;
|
||||
int code = -1;
|
||||
size_t sz = 0;
|
||||
|
||||
SMArbUpdateGroupBatchReq req = {0};
|
||||
if (tDeserializeSMArbUpdateGroupBatchReq(pReq->pCont, pReq->contLen, &req) != 0) {
|
||||
if ((code = tDeserializeSMArbUpdateGroupBatchReq(pReq->pCont, pReq->contLen, &req)) != 0) {
|
||||
mError("arb failed to decode arb-update-group request");
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
|
@ -789,7 +830,7 @@ static int32_t mndProcessArbUpdateGroupBatchReq(SRpcMsg *pReq) {
|
|||
|
||||
mndTransAddArbGroupId(pTrans, newGroup.vgId);
|
||||
|
||||
if (mndSetCreateArbGroupCommitLogs(pTrans, &newGroup) != 0) {
|
||||
if ((code = mndSetCreateArbGroupCommitLogs(pTrans, &newGroup)) != 0) {
|
||||
mError("failed to update arbgroup in set commit log, vgId:%d, trans:%d, since %s", newGroup.vgId, pTrans->id,
|
||||
terrstr());
|
||||
goto _OVER;
|
||||
|
@ -803,13 +844,13 @@ static int32_t mndProcessArbUpdateGroupBatchReq(SRpcMsg *pReq) {
|
|||
sdbRelease(pMnode->pSdb, pOldGroup);
|
||||
}
|
||||
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
if ((code = mndTransCheckConflict(pMnode, pTrans)) != 0) goto _OVER;
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
|
||||
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
if (ret != 0) {
|
||||
if (code != 0) {
|
||||
// failed to update arbgroup
|
||||
for (size_t i = 0; i < sz; i++) {
|
||||
SMArbUpdateGroup *pUpdateGroup = taosArrayGet(req.updateArray, i);
|
||||
|
@ -819,7 +860,7 @@ _OVER:
|
|||
|
||||
mndTransDrop(pTrans);
|
||||
tFreeSMArbUpdateGroupBatchReq(&req);
|
||||
return ret;
|
||||
return code;
|
||||
}
|
||||
|
||||
static void mndArbGroupDupObj(SArbGroup *pGroup, SArbGroup *pNew) {
|
||||
|
@ -841,10 +882,11 @@ static void mndArbGroupResetAssignedLeader(SArbGroup *pGroup) {
|
|||
}
|
||||
|
||||
static int32_t mndArbGroupUpdateTrans(SMnode *pMnode, SArbGroup *pNew) {
|
||||
int32_t ret = -1;
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_ARBGROUP, NULL, "update-arbgroup");
|
||||
if (pTrans == NULL) {
|
||||
mError("failed to update arbgroup in create trans, vgId:%d, since %s", pNew->vgId, terrstr());
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -854,23 +896,22 @@ static int32_t mndArbGroupUpdateTrans(SMnode *pMnode, SArbGroup *pNew) {
|
|||
pNew->assignedLeader.token, pNew->assignedLeader.acked);
|
||||
|
||||
mndTransAddArbGroupId(pTrans, pNew->vgId);
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
ret = -1;
|
||||
if ((code = mndTransCheckConflict(pMnode, pTrans)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndSetCreateArbGroupCommitLogs(pTrans, pNew) != 0) {
|
||||
mError("failed to update arbgroup in set commit log, vgId:%d, since %s", pNew->vgId, terrstr());
|
||||
if ((code = mndSetCreateArbGroupCommitLogs(pTrans, pNew)) != 0) {
|
||||
mError("failed to update arbgroup in set commit log, vgId:%d, since %s", pNew->vgId, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
|
||||
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return ret;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool mndUpdateArbGroupByHeartBeat(SArbGroup *pGroup, SVArbHbRspMember *pRspMember, int64_t nowMs, int32_t dnodeId,
|
||||
|
@ -993,11 +1034,13 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndUpdateArbSync(SMnode *pMnode, int32_t vgId, char *member0Token, char *member1Token, bool newIsSync) {
|
||||
int32_t code = 0;
|
||||
SArbGroup *pGroup = sdbAcquire(pMnode->pSdb, SDB_ARBGROUP, &vgId);
|
||||
if (pGroup == NULL) {
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
mInfo("failed to update arb sync, vgId:%d not found", vgId);
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SArbGroup newGroup = {0};
|
||||
|
@ -1018,38 +1061,36 @@ static int32_t mndProcessArbHbRsp(SRpcMsg *pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t ret = -1;
|
||||
int32_t code = -1;
|
||||
|
||||
SMnode *pMnode = pRsp->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-hb response");
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SVArbHeartBeatRsp arbHbRsp = {0};
|
||||
if (tDeserializeSVArbHeartBeatRsp(pRsp->pCont, pRsp->contLen, &arbHbRsp) != 0) {
|
||||
if ((code = tDeserializeSVArbHeartBeatRsp(pRsp->pCont, pRsp->contLen, &arbHbRsp)) != 0) {
|
||||
mInfo("arb hb-rsp des failed, since:%s", tstrerror(pRsp->code));
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (mndArbCheckToken(arbToken, arbHbRsp.arbToken) != 0) {
|
||||
mInfo("arb hearbeat skip update for dnodeId:%d, arb token mismatch, local:[%s] msg:[%s]", arbHbRsp.dnodeId,
|
||||
arbToken, arbHbRsp.arbToken);
|
||||
terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
code = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
(void)mndUpdateArbHeartBeat(pMnode, arbHbRsp.dnodeId, arbHbRsp.hbMembers);
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
tFreeSVArbHeartBeatRsp(&arbHbRsp);
|
||||
return ret;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessArbCheckSyncRsp(SRpcMsg *pRsp) {
|
||||
|
@ -1058,27 +1099,25 @@ static int32_t mndProcessArbCheckSyncRsp(SRpcMsg *pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t ret = -1;
|
||||
int32_t code = -1;
|
||||
|
||||
SMnode *pMnode = pRsp->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-check-sync response");
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SVArbCheckSyncRsp syncRsp = {0};
|
||||
if (tDeserializeSVArbCheckSyncRsp(pRsp->pCont, pRsp->contLen, &syncRsp) != 0) {
|
||||
if ((code = tDeserializeSVArbCheckSyncRsp(pRsp->pCont, pRsp->contLen, &syncRsp)) != 0) {
|
||||
mInfo("arb check-sync-rsp des failed, since:%s", tstrerror(pRsp->code));
|
||||
if (pRsp->code == TSDB_CODE_MND_ARB_TOKEN_MISMATCH) {
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (mndArbCheckToken(arbToken, syncRsp.arbToken) != 0) {
|
||||
|
@ -1089,16 +1128,16 @@ static int32_t mndProcessArbCheckSyncRsp(SRpcMsg *pRsp) {
|
|||
}
|
||||
|
||||
bool newIsSync = (syncRsp.errCode == TSDB_CODE_SUCCESS);
|
||||
if (mndUpdateArbSync(pMnode, syncRsp.vgId, syncRsp.member0Token, syncRsp.member1Token, newIsSync) != 0) {
|
||||
if ((code = mndUpdateArbSync(pMnode, syncRsp.vgId, syncRsp.member0Token, syncRsp.member1Token, newIsSync)) != 0) {
|
||||
mInfo("failed to update arb sync for vgId:%d, since:%s", syncRsp.vgId, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
tFreeSVArbCheckSyncRsp(&syncRsp);
|
||||
return ret;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
bool mndUpdateArbGroupBySetAssignedLeader(SArbGroup *pGroup, int32_t vgId, char *memberToken, int32_t errcode,
|
||||
|
@ -1138,35 +1177,35 @@ static int32_t mndProcessArbSetAssignedLeaderRsp(SRpcMsg *pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t ret = -1;
|
||||
int32_t code = -1;
|
||||
|
||||
SMnode *pMnode = pRsp->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-set-assigned response");
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SVArbSetAssignedLeaderRsp setAssignedRsp = {0};
|
||||
if (tDeserializeSVArbSetAssignedLeaderRsp(pRsp->pCont, pRsp->contLen, &setAssignedRsp) != 0) {
|
||||
if ((code = tDeserializeSVArbSetAssignedLeaderRsp(pRsp->pCont, pRsp->contLen, &setAssignedRsp)) != 0) {
|
||||
mInfo("arb set-assigned-rsp des failed, since:%s", tstrerror(pRsp->code));
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (mndArbCheckToken(arbToken, setAssignedRsp.arbToken) != 0) {
|
||||
mInfo("skip update arb assigned for vgId:%d, arb token mismatch, local:[%s] msg:[%s]", setAssignedRsp.vgId,
|
||||
arbToken, setAssignedRsp.arbToken);
|
||||
terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
code = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SArbGroup *pGroup = mndAcquireArbGroup(pMnode, setAssignedRsp.vgId);
|
||||
if (!pGroup) {
|
||||
mError("failed to set arb assigned for vgId:%d, since:%s", setAssignedRsp.vgId, terrstr());
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -1174,17 +1213,17 @@ static int32_t mndProcessArbSetAssignedLeaderRsp(SRpcMsg *pRsp) {
|
|||
bool updateAssigned = mndUpdateArbGroupBySetAssignedLeader(pGroup, setAssignedRsp.vgId, setAssignedRsp.memberToken,
|
||||
pRsp->code, &newGroup);
|
||||
if (updateAssigned) {
|
||||
if (mndPullupArbUpdateGroup(pMnode, &newGroup) != 0) {
|
||||
mInfo("failed to pullup update arb assigned for vgId:%d, since:%s", setAssignedRsp.vgId, terrstr());
|
||||
if ((code = mndPullupArbUpdateGroup(pMnode, &newGroup)) != 0) {
|
||||
mInfo("failed to pullup update arb assigned for vgId:%d, since:%s", setAssignedRsp.vgId, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
tFreeSVArbSetAssignedLeaderRsp(&setAssignedRsp);
|
||||
return ret;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveArbGroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "audit.h"
|
||||
#include "mndCluster.h"
|
||||
#include "audit.h"
|
||||
#include "mndGrant.h"
|
||||
#include "mndPrivilege.h"
|
||||
#include "mndShow.h"
|
||||
|
@ -61,11 +61,13 @@ int32_t mndInitCluster(SMnode *pMnode) {
|
|||
void mndCleanupCluster(SMnode *pMnode) {}
|
||||
|
||||
int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t code = 0;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
SClusterObj *pCluster = sdbAcquire(pSdb, SDB_CLUSTER, &pMnode->clusterId);
|
||||
if (pCluster == NULL) {
|
||||
return -1;
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
tstrncpy(clusterName, pCluster->name, len);
|
||||
|
@ -247,7 +249,10 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
|
|||
mInfo("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name);
|
||||
|
||||
SSdbRaw *pRaw = mndClusterActionEncode(&clusterObj);
|
||||
if (pRaw == NULL) return -1;
|
||||
if (pRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mInfo("cluster:%" PRId64 ", will be created when deploying, raw:%p", clusterObj.id, pRaw);
|
||||
|
@ -256,21 +261,22 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
|
|||
if (pTrans == NULL) {
|
||||
sdbFreeRaw(pRaw);
|
||||
mError("cluster:%" PRId64 ", failed to create since %s", clusterObj.id, terrstr());
|
||||
return -1;
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, used to create cluster:%" PRId64, pTrans->id, clusterObj.id);
|
||||
|
||||
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) {
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pRaw)) != 0) {
|
||||
mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -347,22 +353,33 @@ static int32_t mndProcessUptimeTimer(SRpcMsg *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
mInfo("update cluster uptime to %d", clusterObj.upTime);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "update-uptime");
|
||||
if (pTrans == NULL) return -1;
|
||||
if (pTrans == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SSdbRaw *pCommitRaw = mndClusterActionEncode(&clusterObj);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
if (pCommitRaw == NULL) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -374,13 +391,12 @@ int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) {
|
|||
SMnode *pMnode = pReq->info.node;
|
||||
SMCfgClusterReq cfgReq = {0};
|
||||
if (tDeserializeSMCfgClusterReq(pReq->pCont, pReq->contLen, &cfgReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mInfo("cluster: start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_CLUSTER) != 0) {
|
||||
code = terrno != 0 ? terrno : TSDB_CODE_MND_NO_RIGHTS;
|
||||
if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_CLUSTER)) != 0) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
@ -410,17 +426,17 @@ int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) {
|
|||
}
|
||||
|
||||
{ // audit
|
||||
auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql, TMIN(cfgReq.sqlLen, GRANT_ACTIVE_HEAD_LEN << 1));
|
||||
auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql,
|
||||
TMIN(cfgReq.sqlLen, GRANT_ACTIVE_HEAD_LEN << 1));
|
||||
}
|
||||
_exit:
|
||||
tFreeSMCfgClusterReq(&cfgReq);
|
||||
if (code != 0) {
|
||||
terrno = code;
|
||||
mError("cluster: failed to config:%s %s since %s", cfgReq.config, cfgReq.value, terrstr());
|
||||
} else {
|
||||
mInfo("cluster: success to config:%s %s", cfgReq.config, cfgReq.value);
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndProcessConfigClusterRsp(SRpcMsg *pRsp) {
|
||||
|
|
|
@ -387,11 +387,11 @@ TEST_F(MndTestSdb, 00_API) {
|
|||
void *pRow2 = sdbGetRowObj(NULL);
|
||||
ASSERT_EQ(pRow2 == NULL, 1);
|
||||
|
||||
//sdbRaw.c
|
||||
// sdbRaw.c
|
||||
SStrObj strObj;
|
||||
SSdbRaw *pRaw1 = NULL;
|
||||
strSetDefault(&strObj, 1);
|
||||
|
||||
|
||||
pRaw1 = strEncode(&strObj);
|
||||
int32_t id = sdbGetIdFromRaw(pSdb, pRaw1);
|
||||
ASSERT_EQ(id, -2);
|
||||
|
@ -399,32 +399,32 @@ TEST_F(MndTestSdb, 00_API) {
|
|||
SSdbRaw *pRaw2 = sdbAllocRaw(SDB_USER, 1, -128);
|
||||
ASSERT_EQ(pRaw2 == NULL, 1);
|
||||
|
||||
ASSERT_EQ(sdbSetRawInt8(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt8(pRaw1, -128, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt32(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt32(pRaw1, -128, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt16(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt16(pRaw1, -128, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt64(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt64(pRaw1, -128, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawBinary(NULL, 0, "12", 3), -1);
|
||||
ASSERT_EQ(sdbSetRawBinary(pRaw1, 9028, "12", 3), -1);
|
||||
ASSERT_EQ(sdbSetRawDataLen(NULL, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawDataLen(pRaw1, 9000), -1);
|
||||
ASSERT_EQ(sdbSetRawStatus(NULL, SDB_STATUS_READY), -1);
|
||||
ASSERT_EQ(sdbSetRawStatus(pRaw1, SDB_STATUS_INIT), -1);
|
||||
ASSERT_EQ(sdbSetRawInt8(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawInt8(pRaw1, -128, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawInt32(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawInt32(pRaw1, -128, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawInt16(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawInt16(pRaw1, -128, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawInt64(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawInt64(pRaw1, -128, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawBinary(NULL, 0, "12", 3), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawBinary(pRaw1, 9028, "12", 3), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawDataLen(NULL, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawDataLen(pRaw1, 9000), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawStatus(NULL, SDB_STATUS_READY), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawStatus(pRaw1, SDB_STATUS_INIT), TSDB_CODE_INVALID_PARA);
|
||||
|
||||
ASSERT_EQ(sdbGetRawInt8(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt8(pRaw1, 9000, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt32(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt32(pRaw1, 9000, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt16(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt16(pRaw1, 9000, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt64(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt64(pRaw1, 9000, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawBinary(NULL, 0, 0, 4096), -1);
|
||||
ASSERT_EQ(sdbGetRawBinary(pRaw1, 9000, 0, 112), -1);
|
||||
ASSERT_EQ(sdbGetRawSoftVer(NULL, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt8(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawInt8(pRaw1, 9000, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawInt32(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawInt32(pRaw1, 9000, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawInt16(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawInt16(pRaw1, 9000, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawInt64(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawInt64(pRaw1, 9000, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawBinary(NULL, 0, 0, 4096), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawBinary(pRaw1, 9000, 0, 112), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawSoftVer(NULL, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawTotalSize(NULL), -1);
|
||||
|
||||
// sdbHash.c
|
||||
|
|
|
@ -112,6 +112,8 @@ void sdbCleanup(SSdb *pSdb) {
|
|||
}
|
||||
|
||||
int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
||||
int32_t code = 0;
|
||||
|
||||
ESdbType sdbType = table.sdbType;
|
||||
EKeyType keyType = table.keyType;
|
||||
pSdb->keyTypes[sdbType] = table.keyType;
|
||||
|
@ -134,8 +136,8 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
|||
|
||||
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(hashType), true, HASH_ENTRY_LOCK);
|
||||
if (hash == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pSdb->maxId[sdbType] = 0;
|
||||
|
@ -146,16 +148,17 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
|||
}
|
||||
|
||||
static int32_t sdbCreateDir(SSdb *pSdb) {
|
||||
int32_t code = 0;
|
||||
if (taosMulMkDir(pSdb->currDir) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", pSdb->currDir, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", pSdb->currDir, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (taosMkDir(pSdb->tmpDir) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", pSdb->tmpDir, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", pSdb->tmpDir, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -14,18 +14,19 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "crypt.h"
|
||||
#include "sdb.h"
|
||||
#include "sync.h"
|
||||
#include "tchecksum.h"
|
||||
#include "wal.h"
|
||||
#include "tglobal.h"
|
||||
#include "crypt.h"
|
||||
#include "wal.h"
|
||||
|
||||
#define SDB_TABLE_SIZE 24
|
||||
#define SDB_RESERVE_SIZE 512
|
||||
#define SDB_FILE_VER 1
|
||||
|
||||
static int32_t sdbDeployData(SSdb *pSdb) {
|
||||
int32_t code = 0;
|
||||
mInfo("start to deploy sdb");
|
||||
|
||||
for (int32_t i = SDB_MAX - 1; i >= 0; --i) {
|
||||
|
@ -33,8 +34,9 @@ static int32_t sdbDeployData(SSdb *pSdb) {
|
|||
if (fp == NULL) continue;
|
||||
|
||||
mInfo("start to deploy sdb:%s", sdbTableName(i));
|
||||
if ((*fp)(pSdb->pMnode) != 0) {
|
||||
mError("failed to deploy sdb:%s since %s", sdbTableName(i), terrstr());
|
||||
code = (*fp)(pSdb->pMnode);
|
||||
if (code != 0) {
|
||||
mError("failed to deploy sdb:%s since %s", sdbTableName(i), tstrerror(code));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -80,61 +82,62 @@ static void sdbResetData(SSdb *pSdb) {
|
|||
}
|
||||
|
||||
static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||
int32_t code = 0;
|
||||
int64_t sver = 0;
|
||||
int32_t ret = taosReadFile(pFile, &sver, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (sver != SDB_FILE_VER) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
ret = taosReadFile(pFile, &pSdb->applyIndex, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
ret = taosReadFile(pFile, &pSdb->applyTerm, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
ret = taosReadFile(pFile, &pSdb->applyConfig, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
|
||||
int64_t maxId = 0;
|
||||
ret = taosReadFile(pFile, &maxId, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (i < SDB_MAX) {
|
||||
pSdb->maxId[i] = maxId;
|
||||
|
@ -145,12 +148,12 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
|||
int64_t ver = 0;
|
||||
ret = taosReadFile(pFile, &ver, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (i < SDB_MAX) {
|
||||
pSdb->tableVer[i] = ver;
|
||||
|
@ -160,37 +163,38 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
|||
char reserve[SDB_RESERVE_SIZE] = {0};
|
||||
ret = taosReadFile(pFile, reserve, sizeof(reserve));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(reserve)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||
int32_t code = 0;
|
||||
int64_t sver = SDB_FILE_VER;
|
||||
if (taosWriteFile(pFile, &sver, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (taosWriteFile(pFile, &pSdb->applyIndex, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (taosWriteFile(pFile, &pSdb->applyTerm, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (taosWriteFile(pFile, &pSdb->applyConfig, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
|
||||
|
@ -199,8 +203,8 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
|||
maxId = pSdb->maxId[i];
|
||||
}
|
||||
if (taosWriteFile(pFile, &maxId, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,15 +214,15 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
|||
ver = pSdb->tableVer[i];
|
||||
}
|
||||
if (taosWriteFile(pFile, &ver, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
char reserve[SDB_RESERVE_SIZE] = {0};
|
||||
if (taosWriteFile(pFile, reserve, sizeof(reserve)) != sizeof(reserve)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -237,21 +241,22 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
|||
|
||||
SSdbRaw *pRaw = taosMemoryMalloc(bufLen + 100);
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed read sdb file since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed read sdb file since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
taosMemoryFree(pRaw);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mInfo("read sdb file:%s finished since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mInfo("read sdb file:%s finished since %s", file, tstrerror(code));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sdbReadFileHead(pSdb, pFile) != 0) {
|
||||
mError("failed to read sdb file:%s head since %s", file, terrstr());
|
||||
code = sdbReadFileHead(pSdb, pFile);
|
||||
if (code != 0) {
|
||||
mError("failed to read sdb file:%s head since %s", file, tstrerror(code));
|
||||
taosMemoryFree(pRaw);
|
||||
taosCloseFile(&pFile);
|
||||
return -1;
|
||||
|
@ -278,14 +283,14 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
|||
}
|
||||
|
||||
readLen = pRaw->dataLen + sizeof(int32_t);
|
||||
if(tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_SDB) == DND_CS_SDB ){
|
||||
if (tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_SDB) == DND_CS_SDB) {
|
||||
readLen = ENCRYPTED_LEN(pRaw->dataLen) + sizeof(int32_t);
|
||||
}
|
||||
if (readLen >= bufLen) {
|
||||
bufLen = pRaw->dataLen * 2;
|
||||
SSdbRaw *pNewRaw = taosMemoryMalloc(bufLen + 100);
|
||||
if (pNewRaw == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed read sdb file since malloc new sdbRaw size:%d failed", bufLen);
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -308,10 +313,14 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if(tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_SDB) == DND_CS_SDB ){
|
||||
if (tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_SDB) == DND_CS_SDB) {
|
||||
int32_t count = 0;
|
||||
|
||||
char *plantContent = taosMemoryMalloc(ENCRYPTED_LEN(pRaw->dataLen));
|
||||
if (plantContent == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SCryptOpts opts;
|
||||
opts.len = ENCRYPTED_LEN(pRaw->dataLen);
|
||||
|
@ -321,8 +330,8 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
|||
strncpy(opts.key, tsEncryptKey, ENCRYPT_KEY_LEN);
|
||||
|
||||
count = CBC_Decrypt(&opts);
|
||||
|
||||
//mDebug("read sdb, CBC_Decrypt dataLen:%d, descrypted len:%d, %s", pRaw->dataLen, count, __FUNCTION__);
|
||||
|
||||
// mDebug("read sdb, CBC_Decrypt dataLen:%d, descrypted len:%d, %s", pRaw->dataLen, count, __FUNCTION__);
|
||||
|
||||
memcpy(pRaw->pData, plantContent, pRaw->dataLen);
|
||||
taosMemoryFree(plantContent);
|
||||
|
@ -355,8 +364,7 @@ _OVER:
|
|||
taosCloseFile(&pFile);
|
||||
sdbFreeRaw(pRaw);
|
||||
|
||||
terrno = code;
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t sdbReadFile(SSdb *pSdb) {
|
||||
|
@ -365,7 +373,7 @@ int32_t sdbReadFile(SSdb *pSdb) {
|
|||
sdbResetData(pSdb);
|
||||
int32_t code = sdbReadFileImp(pSdb);
|
||||
if (code != 0) {
|
||||
mError("failed to read sdb file since %s", terrstr());
|
||||
mError("failed to read sdb file since %s", tstrerror(code));
|
||||
sdbResetData(pSdb);
|
||||
}
|
||||
|
||||
|
@ -388,13 +396,14 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
|
|||
|
||||
TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open sdb file:%s for write since %s", tmpfile, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open sdb file:%s for write since %s", tmpfile, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (sdbWriteFileHead(pSdb, pFile) != 0) {
|
||||
mError("failed to write sdb file:%s head since %s", tmpfile, terrstr());
|
||||
code = sdbWriteFileHead(pSdb, pFile);
|
||||
if (code != 0) {
|
||||
mError("failed to write sdb file:%s head since %s", tmpfile, tstrerror(code));
|
||||
taosCloseFile(&pFile);
|
||||
return -1;
|
||||
}
|
||||
|
@ -436,8 +445,8 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
|
|||
}
|
||||
|
||||
int32_t newDataLen = pRaw->dataLen;
|
||||
char* newData = pRaw->pData;
|
||||
if(tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_SDB) == DND_CS_SDB ){
|
||||
char *newData = pRaw->pData;
|
||||
if (tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_SDB) == DND_CS_SDB) {
|
||||
newDataLen = ENCRYPTED_LEN(pRaw->dataLen);
|
||||
newData = taosMemoryMalloc(newDataLen);
|
||||
if (newData == NULL) {
|
||||
|
@ -456,8 +465,8 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
|
|||
|
||||
int32_t count = CBC_Encrypt(&opts);
|
||||
|
||||
//mDebug("write sdb, CBC_Encrypt encryptedDataLen:%d, dataLen:%d, %s",
|
||||
// newDataLen, pRaw->dataLen, __FUNCTION__);
|
||||
// mDebug("write sdb, CBC_Encrypt encryptedDataLen:%d, dataLen:%d, %s",
|
||||
// newDataLen, pRaw->dataLen, __FUNCTION__);
|
||||
}
|
||||
|
||||
if (taosWriteFile(pFile, newData, newDataLen) != newDataLen) {
|
||||
|
@ -467,7 +476,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
|
|||
break;
|
||||
}
|
||||
|
||||
if(tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_SDB) == DND_CS_SDB ){
|
||||
if (tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_SDB) == DND_CS_SDB) {
|
||||
taosMemoryFree(newData);
|
||||
}
|
||||
|
||||
|
@ -549,19 +558,22 @@ int32_t sdbWriteFile(SSdb *pSdb, int32_t delta) {
|
|||
}
|
||||
}
|
||||
if (code != 0) {
|
||||
mError("failed to write sdb file since %s", terrstr());
|
||||
mError("failed to write sdb file since %s", tstrerror(code));
|
||||
}
|
||||
taosThreadMutexUnlock(&pSdb->filelock);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t sdbDeploy(SSdb *pSdb) {
|
||||
if (sdbDeployData(pSdb) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
code = sdbDeployData(pSdb);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (sdbWriteFile(pSdb, 0) != 0) {
|
||||
return -1;
|
||||
code = sdbWriteFile(pSdb, 0);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -605,6 +617,7 @@ static void sdbCloseIter(SSdbIter *pIter) {
|
|||
}
|
||||
|
||||
int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *term, int64_t *config) {
|
||||
int32_t code = 0;
|
||||
SSdbIter *pIter = sdbCreateIter(pSdb);
|
||||
if (pIter == NULL) return -1;
|
||||
|
||||
|
@ -617,19 +630,19 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter
|
|||
int64_t commitConfig = pSdb->commitConfig;
|
||||
if (taosCopyFile(datafile, pIter->name) < 0) {
|
||||
taosThreadMutexUnlock(&pSdb->filelock);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, tstrerror(code));
|
||||
sdbCloseIter(pIter);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
taosThreadMutexUnlock(&pSdb->filelock);
|
||||
|
||||
pIter->file = taosOpenFile(pIter->name, TD_FILE_READ);
|
||||
if (pIter->file == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open sdb file:%s since %s", pIter->name, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open sdb file:%s since %s", pIter->name, tstrerror(code));
|
||||
sdbCloseIter(pIter);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*ppIter = pIter;
|
||||
|
@ -645,21 +658,22 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter
|
|||
void sdbStopRead(SSdb *pSdb, SSdbIter *pIter) { sdbCloseIter(pIter); }
|
||||
|
||||
int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) {
|
||||
int32_t code = 0;
|
||||
int32_t maxlen = 4096;
|
||||
void *pBuf = taosMemoryCalloc(1, maxlen);
|
||||
if (pBuf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t readlen = taosReadFile(pIter->file, pBuf, maxlen);
|
||||
if (readlen < 0 || readlen > maxlen) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, terrstr(), pIter->total);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, tstrerror(code), pIter->total);
|
||||
*ppBuf = NULL;
|
||||
*len = 0;
|
||||
taosMemoryFree(pBuf);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
} else if (readlen == 0) {
|
||||
mInfo("sdbiter:%p, read snapshot to the end, total:%" PRId64, pIter, pIter->total);
|
||||
*ppBuf = NULL;
|
||||
|
@ -676,15 +690,19 @@ int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) {
|
|||
}
|
||||
|
||||
int32_t sdbStartWrite(SSdb *pSdb, SSdbIter **ppIter) {
|
||||
int32_t code = 0;
|
||||
SSdbIter *pIter = sdbCreateIter(pSdb);
|
||||
if (pIter == NULL) return -1;
|
||||
if (pIter == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pIter->file = taosOpenFile(pIter->name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pIter->file == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open %s since %s", pIter->name, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open %s since %s", pIter->name, tstrerror(code));
|
||||
sdbCloseIter(pIter);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*ppIter = pIter;
|
||||
|
@ -702,8 +720,8 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
|
|||
}
|
||||
|
||||
if (taosFsyncFile(pIter->file) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to fasync file %s since %s", pIter, pIter->name, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to fasync file %s since %s", pIter, pIter->name, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -713,13 +731,14 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
|
|||
char datafile[PATH_MAX] = {0};
|
||||
snprintf(datafile, sizeof(datafile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
|
||||
if (taosRenameFile(pIter->name, datafile) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (sdbReadFile(pSdb) != 0) {
|
||||
mError("sdbiter:%p, failed to read from %s since %s", pIter, datafile, terrstr());
|
||||
code = sdbReadFile(pSdb);
|
||||
if (code != 0) {
|
||||
mError("sdbiter:%p, failed to read from %s since %s", pIter, datafile, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -742,11 +761,12 @@ _OVER:
|
|||
}
|
||||
|
||||
int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) {
|
||||
int32_t code = 0;
|
||||
int32_t writelen = taosWriteFile(pIter->file, pBuf, len);
|
||||
if (writelen != len) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to write len:%d since %s, total:%" PRId64, len, terrstr(), pIter->total);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to write len:%d since %s, total:%" PRId64, len, tstrerror(code), pIter->total);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pIter->total += writelen;
|
||||
|
|
|
@ -53,14 +53,15 @@ void sdbFreeRaw(SSdbRaw *pRaw) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(int8_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -68,14 +69,15 @@ int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(uint8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(uint8_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -83,14 +85,15 @@ int32_t sdbSetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(int32_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -98,14 +101,15 @@ int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(int16_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -113,14 +117,15 @@ int32_t sdbSetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(int64_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -128,14 +133,15 @@ int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_t valLen) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + valLen > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (pVal != NULL) {
|
||||
|
@ -145,14 +151,15 @@ int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_
|
|||
}
|
||||
|
||||
int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataLen > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pRaw->dataLen = dataLen;
|
||||
|
@ -160,14 +167,15 @@ int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (status == SDB_STATUS_INIT) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pRaw->status = status;
|
||||
|
@ -175,14 +183,15 @@ int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(int8_t *)(pRaw->pData + dataPos);
|
||||
|
@ -190,14 +199,15 @@ int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(uint8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(uint8_t *)(pRaw->pData + dataPos);
|
||||
|
@ -205,14 +215,15 @@ int32_t sdbGetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(int32_t *)(pRaw->pData + dataPos);
|
||||
|
@ -220,14 +231,15 @@ int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(int16_t *)(pRaw->pData + dataPos);
|
||||
|
@ -235,14 +247,15 @@ int32_t sdbGetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(int64_t *)(pRaw->pData + dataPos);
|
||||
|
@ -250,14 +263,15 @@ int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valLen) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + valLen > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (pVal != NULL) {
|
||||
memcpy(pVal, pRaw->pData + dataPos, valLen);
|
||||
|
@ -266,9 +280,10 @@ int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valL
|
|||
}
|
||||
|
||||
int32_t sdbGetRawSoftVer(SSdbRaw *pRaw, int8_t *sver) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*sver = pRaw->sver;
|
||||
|
|
|
@ -147,7 +147,6 @@ int32_t tsdbRowKeyCmpr(const STsdbRowKey *key1, const STsdbRowKey *key2);
|
|||
void tsdbRowGetKey(TSDBROW *row, STsdbRowKey *key);
|
||||
void tColRowGetPrimaryKey(SBlockData *pBlock, int32_t irow, SRowKey *key);
|
||||
|
||||
|
||||
// STSDBRowIter
|
||||
int32_t tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema);
|
||||
void tsdbRowClose(STSDBRowIter *pIter);
|
||||
|
@ -245,10 +244,10 @@ void tsdbMemTableDestroy(SMemTable *pMemTable, bool proactive);
|
|||
STbData *tsdbGetTbDataFromMemTable(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid);
|
||||
int32_t tsdbRefMemTable(SMemTable *pMemTable, SQueryNode *pQNode);
|
||||
int32_t tsdbUnrefMemTable(SMemTable *pMemTable, SQueryNode *pNode, bool proactive);
|
||||
SArray * tsdbMemTableGetTbDataArray(SMemTable *pMemTable);
|
||||
SArray *tsdbMemTableGetTbDataArray(SMemTable *pMemTable);
|
||||
// STbDataIter
|
||||
int32_t tsdbTbDataIterCreate(STbData *pTbData, STsdbRowKey *pFrom, int8_t backward, STbDataIter **ppIter);
|
||||
void * tsdbTbDataIterDestroy(STbDataIter *pIter);
|
||||
void *tsdbTbDataIterDestroy(STbDataIter *pIter);
|
||||
void tsdbTbDataIterOpen(STbData *pTbData, STsdbRowKey *pFrom, int8_t backward, STbDataIter *pIter);
|
||||
bool tsdbTbDataIterNext(STbDataIter *pIter);
|
||||
void tsdbMemTableCountRows(SMemTable *pMemTable, SSHashObj *pTableMap, int64_t *rowsNum);
|
||||
|
@ -301,7 +300,7 @@ int32_t tsdbGetTableSchema(SMeta *pMeta, int64_t uid, STSchema **pSchema, int64_
|
|||
|
||||
// tsdbMerge.c ==============================================================================================
|
||||
typedef struct {
|
||||
STsdb * tsdb;
|
||||
STsdb *tsdb;
|
||||
int32_t fid;
|
||||
} SMergeArg;
|
||||
|
||||
|
@ -332,22 +331,22 @@ int32_t tsdbDataIterNext2(STsdbDataIter2 *pIter, STsdbFilterInfo *pFilterInfo);
|
|||
// structs =======================
|
||||
struct STsdbFS {
|
||||
SDelFile *pDelFile;
|
||||
SArray * aDFileSet; // SArray<SDFileSet>
|
||||
SArray *aDFileSet; // SArray<SDFileSet>
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
rocksdb_t * db;
|
||||
rocksdb_comparator_t * my_comparator;
|
||||
rocksdb_cache_t * blockcache;
|
||||
rocksdb_t *db;
|
||||
rocksdb_comparator_t *my_comparator;
|
||||
rocksdb_cache_t *blockcache;
|
||||
rocksdb_block_based_table_options_t *tableoptions;
|
||||
rocksdb_options_t * options;
|
||||
rocksdb_flushoptions_t * flushoptions;
|
||||
rocksdb_writeoptions_t * writeoptions;
|
||||
rocksdb_readoptions_t * readoptions;
|
||||
rocksdb_writebatch_t * writebatch;
|
||||
rocksdb_writebatch_t * rwritebatch;
|
||||
rocksdb_options_t *options;
|
||||
rocksdb_flushoptions_t *flushoptions;
|
||||
rocksdb_writeoptions_t *writeoptions;
|
||||
rocksdb_readoptions_t *readoptions;
|
||||
rocksdb_writebatch_t *writebatch;
|
||||
rocksdb_writebatch_t *rwritebatch;
|
||||
TdThreadMutex rMutex;
|
||||
STSchema * pTSchema;
|
||||
STSchema *pTSchema;
|
||||
} SRocksCache;
|
||||
|
||||
typedef struct {
|
||||
|
@ -358,26 +357,26 @@ typedef struct {
|
|||
typedef struct SCompMonitor SCompMonitor;
|
||||
|
||||
struct STsdb {
|
||||
char * path;
|
||||
SVnode * pVnode;
|
||||
char *path;
|
||||
SVnode *pVnode;
|
||||
STsdbKeepCfg keepCfg;
|
||||
TdThreadMutex mutex;
|
||||
bool bgTaskDisabled;
|
||||
SMemTable * mem;
|
||||
SMemTable * imem;
|
||||
SMemTable *mem;
|
||||
SMemTable *imem;
|
||||
STsdbFS fs; // old
|
||||
SLRUCache * lruCache;
|
||||
SLRUCache *lruCache;
|
||||
SCacheFlushState flushState;
|
||||
TdThreadMutex lruMutex;
|
||||
SLRUCache * biCache;
|
||||
SLRUCache *biCache;
|
||||
TdThreadMutex biMutex;
|
||||
SLRUCache * bCache;
|
||||
SLRUCache *bCache;
|
||||
TdThreadMutex bMutex;
|
||||
SLRUCache * pgCache;
|
||||
SLRUCache *pgCache;
|
||||
TdThreadMutex pgMutex;
|
||||
struct STFileSystem *pFS; // new
|
||||
SRocksCache rCache;
|
||||
SCompMonitor *pCompMonitor;
|
||||
SCompMonitor *pCompMonitor;
|
||||
struct {
|
||||
SVHashTable *ht;
|
||||
SArray *arr;
|
||||
|
@ -405,17 +404,17 @@ struct STbData {
|
|||
TSKEY minKey;
|
||||
TSKEY maxKey;
|
||||
SRWLatch lock;
|
||||
SDelData * pHead;
|
||||
SDelData * pTail;
|
||||
SDelData *pHead;
|
||||
SDelData *pTail;
|
||||
SMemSkipList sl;
|
||||
STbData * next;
|
||||
STbData *next;
|
||||
SRBTreeNode rbtn[1];
|
||||
};
|
||||
|
||||
struct SMemTable {
|
||||
SRWLatch latch;
|
||||
STsdb * pTsdb;
|
||||
SVBufPool * pPool;
|
||||
STsdb *pTsdb;
|
||||
SVBufPool *pPool;
|
||||
volatile int32_t nRef;
|
||||
int64_t minVer;
|
||||
int64_t maxVer;
|
||||
|
@ -425,7 +424,7 @@ struct SMemTable {
|
|||
int64_t nDel;
|
||||
int32_t nTbData;
|
||||
int32_t nBucket;
|
||||
STbData ** aBucket;
|
||||
STbData **aBucket;
|
||||
SRBTree tbDataTree[1];
|
||||
};
|
||||
|
||||
|
@ -434,7 +433,7 @@ struct TSDBROW {
|
|||
union {
|
||||
struct {
|
||||
int64_t version;
|
||||
SRow * pTSRow;
|
||||
SRow *pTSRow;
|
||||
};
|
||||
struct {
|
||||
SBlockData *pBlockData;
|
||||
|
@ -535,9 +534,9 @@ struct SBlockData {
|
|||
int64_t suid; // 0 means normal table block data, otherwise child table block data
|
||||
int64_t uid; // 0 means block data in .last file, otherwise in .data file
|
||||
int32_t nRow; // number of rows
|
||||
int64_t * aUid; // uids of each row, only exist in block data in .last file (uid == 0)
|
||||
int64_t * aVersion; // versions of each row
|
||||
TSKEY * aTSKEY; // timestamp of each row
|
||||
int64_t *aUid; // uids of each row, only exist in block data in .last file (uid == 0)
|
||||
int64_t *aVersion; // versions of each row
|
||||
TSKEY *aTSKEY; // timestamp of each row
|
||||
int32_t nColData;
|
||||
SColData *aColData;
|
||||
};
|
||||
|
@ -548,10 +547,10 @@ struct TABLEID {
|
|||
};
|
||||
|
||||
struct STbDataIter {
|
||||
STbData * pTbData;
|
||||
STbData *pTbData;
|
||||
int8_t backward;
|
||||
SMemSkipListNode *pNode;
|
||||
TSDBROW * pRow;
|
||||
TSDBROW *pRow;
|
||||
TSDBROW row;
|
||||
};
|
||||
|
||||
|
@ -629,9 +628,9 @@ struct SDFileSet {
|
|||
int32_t fid;
|
||||
SHeadFile *pHeadF;
|
||||
SDataFile *pDataF;
|
||||
SSmaFile * pSmaF;
|
||||
SSmaFile *pSmaF;
|
||||
uint8_t nSttF;
|
||||
SSttFile * aSttF[TSDB_STT_TRIGGER_ARRAY_SIZE];
|
||||
SSttFile *aSttF[TSDB_STT_TRIGGER_ARRAY_SIZE];
|
||||
};
|
||||
|
||||
struct STSDBRowIter {
|
||||
|
@ -647,18 +646,18 @@ struct STSDBRowIter {
|
|||
struct SRowMerger {
|
||||
STSchema *pTSchema;
|
||||
int64_t version;
|
||||
SArray * pArray; // SArray<SColVal>
|
||||
SArray *pArray; // SArray<SColVal>
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char * path;
|
||||
char *path;
|
||||
int32_t szPage;
|
||||
int32_t flag;
|
||||
TdFilePtr pFD;
|
||||
int64_t pgno;
|
||||
uint8_t * pBuf;
|
||||
uint8_t *pBuf;
|
||||
int64_t szFile;
|
||||
STsdb * pTsdb;
|
||||
STsdb *pTsdb;
|
||||
const char *objName;
|
||||
uint8_t s3File;
|
||||
int32_t lcn;
|
||||
|
@ -668,7 +667,7 @@ typedef struct {
|
|||
} STsdbFD;
|
||||
|
||||
struct SDelFWriter {
|
||||
STsdb * pTsdb;
|
||||
STsdb *pTsdb;
|
||||
SDelFile fDel;
|
||||
STsdbFD *pWriteH;
|
||||
uint8_t *aBuf[1];
|
||||
|
@ -728,15 +727,15 @@ int32_t tDeserializeTsdbRepOpts(void *buf, int32_t bufLen, STsdbRepOpts *pInfo);
|
|||
|
||||
// snap read
|
||||
struct STsdbReadSnap {
|
||||
SMemTable * pMem;
|
||||
SQueryNode * pNode;
|
||||
SMemTable * pIMem;
|
||||
SQueryNode * pINode;
|
||||
SMemTable *pMem;
|
||||
SQueryNode *pNode;
|
||||
SMemTable *pIMem;
|
||||
SQueryNode *pINode;
|
||||
TFileSetArray *pfSetArray;
|
||||
};
|
||||
|
||||
struct SDataFWriter {
|
||||
STsdb * pTsdb;
|
||||
STsdb *pTsdb;
|
||||
SDFileSet wSet;
|
||||
|
||||
STsdbFD *pHeadFD;
|
||||
|
@ -753,13 +752,13 @@ struct SDataFWriter {
|
|||
};
|
||||
|
||||
struct SDataFReader {
|
||||
STsdb * pTsdb;
|
||||
STsdb *pTsdb;
|
||||
SDFileSet *pSet;
|
||||
STsdbFD * pHeadFD;
|
||||
STsdbFD * pDataFD;
|
||||
STsdbFD * pSmaFD;
|
||||
STsdbFD * aSttFD[TSDB_STT_TRIGGER_ARRAY_SIZE];
|
||||
uint8_t * aBuf[3];
|
||||
STsdbFD *pHeadFD;
|
||||
STsdbFD *pDataFD;
|
||||
STsdbFD *pSmaFD;
|
||||
STsdbFD *aSttFD[TSDB_STT_TRIGGER_ARRAY_SIZE];
|
||||
uint8_t *aBuf[3];
|
||||
};
|
||||
|
||||
// NOTE: do NOT change the order of the fields
|
||||
|
@ -794,10 +793,10 @@ typedef struct {
|
|||
|
||||
typedef struct SSttBlockLoadInfo {
|
||||
SBlockDataInfo blockData[2]; // buffered block data
|
||||
SArray * aSttBlk;
|
||||
SArray *aSttBlk;
|
||||
int32_t currentLoadBlockIndex;
|
||||
STSchema * pSchema;
|
||||
int16_t * colIds;
|
||||
STSchema *pSchema;
|
||||
int16_t *colIds;
|
||||
int32_t numOfCols;
|
||||
bool checkRemainingRow; // todo: no assign value?
|
||||
bool isLast;
|
||||
|
@ -834,7 +833,7 @@ struct SDiskData {
|
|||
const uint8_t *pUid;
|
||||
const uint8_t *pVer;
|
||||
const uint8_t *pKey;
|
||||
SArray * aDiskCol; // SArray<SDiskCol>
|
||||
SArray *aDiskCol; // SArray<SDiskCol>
|
||||
};
|
||||
|
||||
struct SDiskDataBuilder {
|
||||
|
@ -847,15 +846,15 @@ struct SDiskDataBuilder {
|
|||
SCompressor *pVerC;
|
||||
SCompressor *pKeyC;
|
||||
int32_t nBuilder;
|
||||
SArray * aBuilder; // SArray<SDiskColBuilder>
|
||||
uint8_t * aBuf[2];
|
||||
SArray *aBuilder; // SArray<SDiskColBuilder>
|
||||
uint8_t *aBuf[2];
|
||||
SDiskData dd;
|
||||
SBlkInfo bi;
|
||||
};
|
||||
|
||||
struct SLDataIter {
|
||||
SRBTreeNode node;
|
||||
SSttBlk * pSttBlk;
|
||||
SSttBlk *pSttBlk;
|
||||
int64_t cid; // for debug purpose
|
||||
int8_t backward;
|
||||
int32_t iSttBlk;
|
||||
|
@ -864,8 +863,8 @@ struct SLDataIter {
|
|||
uint64_t uid;
|
||||
STimeWindow timeWindow;
|
||||
SVersionRange verRange;
|
||||
SSttBlockLoadInfo * pBlockLoadInfo;
|
||||
SRowKey * pStartRowKey; // current row key
|
||||
SSttBlockLoadInfo *pBlockLoadInfo;
|
||||
SRowKey *pStartRowKey; // current row key
|
||||
bool ignoreEarlierTs;
|
||||
struct SSttFileReader *pReader;
|
||||
};
|
||||
|
@ -878,21 +877,21 @@ typedef int32_t (*_load_tomb_fn)(STsdbReader *pReader, struct SSttFileReader *pS
|
|||
|
||||
typedef struct SMergeTreeConf {
|
||||
int8_t backward;
|
||||
STsdb * pTsdb;
|
||||
STsdb *pTsdb;
|
||||
uint64_t suid;
|
||||
uint64_t uid;
|
||||
STimeWindow timewindow;
|
||||
SVersionRange verRange;
|
||||
bool strictTimeRange;
|
||||
SArray * pSttFileBlockIterArray;
|
||||
void * pCurrentFileset;
|
||||
STSchema * pSchema;
|
||||
int16_t * pCols;
|
||||
SArray *pSttFileBlockIterArray;
|
||||
void *pCurrentFileset;
|
||||
STSchema *pSchema;
|
||||
int16_t *pCols;
|
||||
int32_t numOfCols;
|
||||
SRowKey * pCurRowKey;
|
||||
SRowKey *pCurRowKey;
|
||||
_load_tomb_fn loadTombFn;
|
||||
void * pReader;
|
||||
void * idstr;
|
||||
void *pReader;
|
||||
void *idstr;
|
||||
bool rspRows; // response the rows in stt-file, if possible
|
||||
} SMergeTreeConf;
|
||||
|
||||
|
@ -1023,7 +1022,7 @@ struct STsdbDataIter2 {
|
|||
// TSDB_DATA_FILE_DATA_ITER
|
||||
struct {
|
||||
SDataFReader *pReader;
|
||||
SArray * aBlockIdx; // SArray<SBlockIdx>
|
||||
SArray *aBlockIdx; // SArray<SBlockIdx>
|
||||
SMapData mDataBlk;
|
||||
SBlockData bData;
|
||||
int32_t iBlockIdx;
|
||||
|
@ -1035,7 +1034,7 @@ struct STsdbDataIter2 {
|
|||
struct {
|
||||
SDataFReader *pReader;
|
||||
int32_t iStt;
|
||||
SArray * aSttBlk;
|
||||
SArray *aSttBlk;
|
||||
SBlockData bData;
|
||||
int32_t iSttBlk;
|
||||
int32_t iRow;
|
||||
|
@ -1043,8 +1042,8 @@ struct STsdbDataIter2 {
|
|||
// TSDB_TOMB_FILE_DATA_ITER
|
||||
struct {
|
||||
SDelFReader *pReader;
|
||||
SArray * aDelIdx;
|
||||
SArray * aDelData;
|
||||
SArray *aDelIdx;
|
||||
SArray *aDelData;
|
||||
int32_t iDelIdx;
|
||||
int32_t iDelData;
|
||||
} tIter;
|
||||
|
|
|
@ -1307,186 +1307,6 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
|
||||
static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SCacheRowsReader *pr, int16_t *aCols,
|
||||
int nCols, int16_t *slotIds);
|
||||
#ifdef BUILD_NO_CALL
|
||||
static SLastCol *tsdbCacheLookup(STsdb *pTsdb, tb_uid_t uid, int16_t cid, int8_t ltype) {
|
||||
SLastCol *pLastCol = NULL;
|
||||
|
||||
char *err = NULL;
|
||||
size_t vlen = 0;
|
||||
SLastKey *key = &(SLastKey){.ltype = ltype, .uid = uid, .cid = cid};
|
||||
size_t klen = ROCKS_KEY_LEN;
|
||||
char *value = NULL;
|
||||
value = rocksdb_get(pTsdb->rCache.db, pTsdb->rCache.readoptions, (char *)key, klen, &vlen, &err);
|
||||
if (NULL != err) {
|
||||
tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, err);
|
||||
rocksdb_free(err);
|
||||
}
|
||||
|
||||
pLastCol = tsdbCacheDeserialize(value);
|
||||
|
||||
return pLastCol;
|
||||
}
|
||||
|
||||
int32_t tsdbCacheGetSlow(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCacheRowsReader *pr, int8_t ltype) {
|
||||
rocksdb_writebatch_t *wb = NULL;
|
||||
int32_t code = 0;
|
||||
|
||||
SArray *pCidList = pr->pCidList;
|
||||
int num_keys = TARRAY_SIZE(pCidList);
|
||||
|
||||
char **keys_list = taosMemoryMalloc(num_keys * sizeof(char *));
|
||||
size_t *keys_list_sizes = taosMemoryMalloc(num_keys * sizeof(size_t));
|
||||
char *key_list = taosMemoryMalloc(num_keys * ROCKS_KEY_LEN);
|
||||
for (int i = 0; i < num_keys; ++i) {
|
||||
int16_t cid = *(int16_t *)taosArrayGet(pCidList, i);
|
||||
|
||||
memcpy(key_list + i * ROCKS_KEY_LEN, &(SLastKey){.ltype = ltype, .uid = uid, .cid = cid}, ROCKS_KEY_LEN);
|
||||
keys_list[i] = key_list + i * ROCKS_KEY_LEN;
|
||||
keys_list_sizes[i] = ROCKS_KEY_LEN;
|
||||
}
|
||||
|
||||
char **values_list = taosMemoryCalloc(num_keys, sizeof(char *));
|
||||
size_t *values_list_sizes = taosMemoryCalloc(num_keys, sizeof(size_t));
|
||||
char **errs = taosMemoryMalloc(num_keys * sizeof(char *));
|
||||
rocksdb_multi_get(pTsdb->rCache.db, pTsdb->rCache.readoptions, num_keys, (const char *const *)keys_list,
|
||||
keys_list_sizes, values_list, values_list_sizes, errs);
|
||||
for (int i = 0; i < num_keys; ++i) {
|
||||
if (errs[i]) {
|
||||
rocksdb_free(errs[i]);
|
||||
}
|
||||
}
|
||||
taosMemoryFree(key_list);
|
||||
taosMemoryFree(keys_list);
|
||||
taosMemoryFree(keys_list_sizes);
|
||||
taosMemoryFree(errs);
|
||||
|
||||
for (int i = 0; i < num_keys; ++i) {
|
||||
bool freeCol = true;
|
||||
SArray *pTmpColArray = NULL;
|
||||
SLastCol *pLastCol = tsdbCacheDeserialize(values_list[i]);
|
||||
int16_t cid = *(int16_t *)taosArrayGet(pCidList, i);
|
||||
SLastCol noneCol = {.ts = TSKEY_MIN, .colVal = COL_VAL_NONE(cid, pr->pSchema->columns[pr->pSlotIds[i]].type)};
|
||||
if (pLastCol) {
|
||||
reallocVarData(&pLastCol->colVal);
|
||||
} else {
|
||||
taosThreadMutexLock(&pTsdb->rCache.rMutex);
|
||||
|
||||
pLastCol = tsdbCacheLookup(pTsdb, uid, cid, ltype);
|
||||
if (!pLastCol) {
|
||||
// recalc: load from tsdb
|
||||
int16_t aCols[1] = {cid};
|
||||
int16_t slotIds[1] = {pr->pSlotIds[i]};
|
||||
pTmpColArray = NULL;
|
||||
|
||||
if (ltype) {
|
||||
mergeLastCid(uid, pTsdb, &pTmpColArray, pr, aCols, 1, slotIds);
|
||||
} else {
|
||||
mergeLastRowCid(uid, pTsdb, &pTmpColArray, pr, aCols, 1, slotIds);
|
||||
}
|
||||
|
||||
if (pTmpColArray && TARRAY_SIZE(pTmpColArray) >= 1) {
|
||||
pLastCol = taosArrayGet(pTmpColArray, 0);
|
||||
freeCol = false;
|
||||
}
|
||||
|
||||
// still null, then make up a none col value
|
||||
if (!pLastCol) {
|
||||
pLastCol = &noneCol;
|
||||
freeCol = false;
|
||||
}
|
||||
|
||||
// store result back to rocks cache
|
||||
wb = pTsdb->rCache.rwritebatch;
|
||||
char *value = NULL;
|
||||
size_t vlen = 0;
|
||||
tsdbCacheSerialize(pLastCol, &value, &vlen);
|
||||
|
||||
SLastKey *key = &(SLastKey){.ltype = ltype, .uid = uid, .cid = pLastCol->colVal.cid};
|
||||
size_t klen = ROCKS_KEY_LEN;
|
||||
rocksdb_writebatch_put(wb, (char *)key, klen, value, vlen);
|
||||
|
||||
taosMemoryFree(value);
|
||||
} else {
|
||||
reallocVarData(&pLastCol->colVal);
|
||||
}
|
||||
|
||||
if (wb) {
|
||||
rocksMayWrite(pTsdb, false, true, false);
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&pTsdb->rCache.rMutex);
|
||||
}
|
||||
|
||||
taosArrayPush(pLastArray, pLastCol);
|
||||
taosArrayDestroy(pTmpColArray);
|
||||
if (freeCol) {
|
||||
taosMemoryFree(pLastCol);
|
||||
}
|
||||
}
|
||||
taosMemoryFree(values_list);
|
||||
taosMemoryFree(values_list_sizes);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static SLastCol *tsdbCacheLoadCol(STsdb *pTsdb, SCacheRowsReader *pr, int16_t slotid, tb_uid_t uid, int16_t cid,
|
||||
int8_t ltype) {
|
||||
SLastCol *pLastCol = tsdbCacheLookup(pTsdb, uid, cid, ltype);
|
||||
if (!pLastCol) {
|
||||
rocksdb_writebatch_t *wb = NULL;
|
||||
|
||||
taosThreadMutexLock(&pTsdb->rCache.rMutex);
|
||||
pLastCol = tsdbCacheLookup(pTsdb, uid, cid, ltype);
|
||||
if (!pLastCol) {
|
||||
// recalc: load from tsdb
|
||||
int16_t aCols[1] = {cid};
|
||||
int16_t slotIds[1] = {slotid};
|
||||
SArray *pTmpColArray = NULL;
|
||||
|
||||
if (ltype) {
|
||||
mergeLastCid(uid, pTsdb, &pTmpColArray, pr, aCols, 1, slotIds);
|
||||
} else {
|
||||
mergeLastRowCid(uid, pTsdb, &pTmpColArray, pr, aCols, 1, slotIds);
|
||||
}
|
||||
|
||||
if (pTmpColArray && TARRAY_SIZE(pTmpColArray) >= 1) {
|
||||
pLastCol = taosArrayGet(pTmpColArray, 0);
|
||||
}
|
||||
|
||||
// still null, then make up a none col value
|
||||
SLastCol noneCol = {.ts = TSKEY_MIN, .colVal = COL_VAL_NONE(cid, pr->pSchema->columns[slotid].type)};
|
||||
if (!pLastCol) {
|
||||
pLastCol = &noneCol;
|
||||
}
|
||||
|
||||
// store result back to rocks cache
|
||||
wb = pTsdb->rCache.rwritebatch;
|
||||
char *value = NULL;
|
||||
size_t vlen = 0;
|
||||
tsdbCacheSerialize(pLastCol, &value, &vlen);
|
||||
|
||||
SLastKey *key = &(SLastKey){.ltype = ltype, .uid = uid, .cid = pLastCol->colVal.cid};
|
||||
size_t klen = ROCKS_KEY_LEN;
|
||||
rocksdb_writebatch_put(wb, (char *)key, klen, value, vlen);
|
||||
taosMemoryFree(value);
|
||||
|
||||
SLastCol *pTmpLastCol = taosMemoryCalloc(1, sizeof(SLastCol));
|
||||
*pTmpLastCol = *pLastCol;
|
||||
pLastCol = pTmpLastCol;
|
||||
|
||||
taosArrayDestroy(pTmpColArray);
|
||||
}
|
||||
|
||||
if (wb) {
|
||||
rocksMayWrite(pTsdb, false, true, false);
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&pTsdb->rCache.rMutex);
|
||||
}
|
||||
|
||||
return pLastCol;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SArray *remainCols,
|
||||
SCacheRowsReader *pr, int8_t ltype) {
|
||||
|
@ -3453,8 +3273,9 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
taosArrayPush(aColArray, &aCols[i]);
|
||||
}
|
||||
|
||||
TSKEY lastRowTs = TSKEY_MAX;
|
||||
STsdbRowKey lastRowKey = {.key.ts = TSKEY_MAX};
|
||||
|
||||
// inverse iterator
|
||||
CacheNextRowIter iter = {0};
|
||||
nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->info.suid, pr->pLDataIterArray, pr->pReadSnap, pr->lastTs, pr);
|
||||
|
||||
|
@ -3478,10 +3299,11 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
}
|
||||
// int16_t nCol = pTSchema->numOfCols;
|
||||
|
||||
TSKEY rowTs = TSDBROW_TS(pRow);
|
||||
STsdbRowKey rowKey = {0};
|
||||
tsdbRowGetKey(pRow, &rowKey);
|
||||
|
||||
if (lastRowTs == TSKEY_MAX) {
|
||||
lastRowTs = rowTs;
|
||||
if (lastRowKey.key.ts == TSKEY_MAX) { // first time
|
||||
lastRowKey = rowKey;
|
||||
|
||||
for (int16_t iCol = noneCol; iCol < nCols; ++iCol) {
|
||||
if (iCol >= nLastCol) {
|
||||
|
@ -3501,13 +3323,13 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
if (slotIds[iCol] == 0) {
|
||||
STColumn *pTColumn = &pTSchema->columns[0];
|
||||
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowTs}));
|
||||
taosArraySet(pColArray, 0, &(SLastCol){.rowKey.ts = rowTs, .colVal = *pColVal});
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowKey.key.ts}));
|
||||
taosArraySet(pColArray, 0, &(SLastCol){.rowKey = rowKey.key, .colVal = *pColVal});
|
||||
continue;
|
||||
}
|
||||
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
||||
|
||||
*pCol = (SLastCol){.rowKey.ts = rowTs, .colVal = *pColVal};
|
||||
*pCol = (SLastCol){.rowKey = rowKey.key, .colVal = *pColVal};
|
||||
if (IS_VAR_DATA_TYPE(pColVal->value.type) /*&& pColVal->value.nData > 0*/) {
|
||||
if (pColVal->value.nData > 0) {
|
||||
pCol->colVal.value.pData = taosMemoryMalloc(pCol->colVal.value.nData);
|
||||
|
@ -3554,10 +3376,11 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
continue;
|
||||
}
|
||||
SColVal *tColVal = &lastColVal->colVal;
|
||||
if (COL_VAL_IS_VALUE(tColVal)) continue;
|
||||
|
||||
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
||||
if (!COL_VAL_IS_VALUE(tColVal) && COL_VAL_IS_VALUE(pColVal)) {
|
||||
SLastCol lastCol = {.rowKey.ts = rowTs, .colVal = *pColVal};
|
||||
if (COL_VAL_IS_VALUE(pColVal)) {
|
||||
SLastCol lastCol = {.rowKey = rowKey.key, .colVal = *pColVal};
|
||||
if (IS_VAR_DATA_TYPE(pColVal->value.type) /* && pColVal->value.nData > 0 */) {
|
||||
SLastCol *pLastCol = (SLastCol *)taosArrayGet(pColArray, iCol);
|
||||
taosMemoryFree(pLastCol->colVal.value.pData);
|
||||
|
@ -3580,7 +3403,7 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
if (aColIndex >= 0) {
|
||||
taosArrayRemove(aColArray, aColIndex);
|
||||
}
|
||||
} else if (!COL_VAL_IS_VALUE(tColVal) && !COL_VAL_IS_VALUE(pColVal) && !setNoneCol) {
|
||||
} else if (!COL_VAL_IS_VALUE(pColVal) && !setNoneCol) {
|
||||
noneCol = iCol;
|
||||
setNoneCol = true;
|
||||
}
|
||||
|
@ -3637,8 +3460,7 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray,
|
|||
taosArrayPush(aColArray, &aCols[i]);
|
||||
}
|
||||
|
||||
TSKEY lastRowTs = TSKEY_MAX;
|
||||
|
||||
// inverse iterator
|
||||
CacheNextRowIter iter = {0};
|
||||
nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->info.suid, pr->pLDataIterArray, pr->pReadSnap, pr->lastTs, pr);
|
||||
|
||||
|
@ -3662,9 +3484,8 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray,
|
|||
}
|
||||
// int16_t nCol = pTSchema->numOfCols;
|
||||
|
||||
TSKEY rowTs = TSDBROW_TS(pRow);
|
||||
|
||||
lastRowTs = rowTs;
|
||||
STsdbRowKey rowKey = {0};
|
||||
tsdbRowGetKey(pRow, &rowKey);
|
||||
|
||||
for (int16_t iCol = noneCol; iCol < nCols; ++iCol) {
|
||||
if (iCol >= nLastCol) {
|
||||
|
@ -3680,13 +3501,13 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray,
|
|||
if (slotIds[iCol] == 0) {
|
||||
STColumn *pTColumn = &pTSchema->columns[0];
|
||||
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowTs}));
|
||||
taosArraySet(pColArray, 0, &(SLastCol){.rowKey.ts = rowTs, .colVal = *pColVal});
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowKey.key.ts}));
|
||||
taosArraySet(pColArray, 0, &(SLastCol){.rowKey = rowKey.key, .colVal = *pColVal});
|
||||
continue;
|
||||
}
|
||||
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
||||
|
||||
*pCol = (SLastCol){.rowKey.ts = rowTs, .colVal = *pColVal};
|
||||
*pCol = (SLastCol){.rowKey = rowKey.key, .colVal = *pColVal};
|
||||
if (IS_VAR_DATA_TYPE(pColVal->value.type) /*&& pColVal->value.nData > 0*/) {
|
||||
if (pColVal->value.nData > 0) {
|
||||
pCol->colVal.value.pData = taosMemoryMalloc(pCol->colVal.value.nData);
|
||||
|
|
|
@ -37,8 +37,8 @@ static int32_t tsdbUpgradeHead(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader *
|
|||
int8_t cmprAlg;
|
||||
int32_t szPage;
|
||||
SBuffer buffers[10];
|
||||
int32_t encryptAlgorithm;
|
||||
char* encryptKey;
|
||||
int32_t encryptAlgorithm;
|
||||
char *encryptKey;
|
||||
// reader
|
||||
SArray *aBlockIdx;
|
||||
SMapData mDataBlk[1];
|
||||
|
@ -139,8 +139,9 @@ static int32_t tsdbUpgradeHead(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader *
|
|||
|
||||
if (ctx->brinBlock->numOfRecords >= ctx->maxRow) {
|
||||
SVersionRange range = {.minVer = VERSION_MAX, .maxVer = VERSION_MIN};
|
||||
code = tsdbFileWriteBrinBlock(ctx->fd, ctx->brinBlock, ctx->cmprAlg, &fset->farr[TSDB_FTYPE_HEAD]->f->size,
|
||||
ctx->brinBlkArray, ctx->buffers, &range, ctx->encryptAlgorithm, ctx->encryptKey);
|
||||
code =
|
||||
tsdbFileWriteBrinBlock(ctx->fd, ctx->brinBlock, ctx->cmprAlg, &fset->farr[TSDB_FTYPE_HEAD]->f->size,
|
||||
ctx->brinBlkArray, ctx->buffers, &range, ctx->encryptAlgorithm, ctx->encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
}
|
||||
|
@ -157,8 +158,8 @@ static int32_t tsdbUpgradeHead(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader *
|
|||
&fset->farr[TSDB_FTYPE_HEAD]->f->size, ctx->encryptAlgorithm, ctx->encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tsdbFileWriteHeadFooter(ctx->fd, &fset->farr[TSDB_FTYPE_HEAD]->f->size, ctx->footer, ctx->encryptAlgorithm,
|
||||
ctx->encryptKey);
|
||||
code = tsdbFileWriteHeadFooter(ctx->fd, &fset->farr[TSDB_FTYPE_HEAD]->f->size, ctx->footer, ctx->encryptAlgorithm,
|
||||
ctx->encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tsdbFsyncFile(ctx->fd, ctx->encryptAlgorithm, ctx->encryptKey);
|
||||
|
@ -258,7 +259,7 @@ static int32_t tsdbUpgradeSttFile(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReade
|
|||
struct {
|
||||
int32_t szPage;
|
||||
int32_t encryptAlgorithm;
|
||||
char* encryptKey;
|
||||
char *encryptKey;
|
||||
// writer
|
||||
STsdbFD *fd;
|
||||
TSttBlkArray sttBlkArray[1];
|
||||
|
@ -290,7 +291,7 @@ static int32_t tsdbUpgradeSttFile(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReade
|
|||
}
|
||||
|
||||
code = tsdbFileWriteSttBlk(ctx->fd, ctx->sttBlkArray, ctx->footer->sttBlkPtr, &fobj->f->size, ctx->encryptAlgorithm,
|
||||
ctx->encryptKey);
|
||||
ctx->encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit1);
|
||||
|
||||
code = tsdbFileWriteSttFooter(ctx->fd, ctx->footer, &fobj->f->size, ctx->encryptAlgorithm, ctx->encryptKey);
|
||||
|
@ -442,7 +443,7 @@ static int32_t tsdbUpgradeOpenTombFile(STsdb *tsdb, STFileSet *fset, STsdbFD **f
|
|||
|
||||
uint8_t hdr[TSDB_FHDR_SIZE] = {0};
|
||||
int32_t encryptAlgorithm = tsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
||||
char* encryptKey = tsdb->pVnode->config.tsdbCfg.encryptKey;
|
||||
char *encryptKey = tsdb->pVnode->config.tsdbCfg.encryptKey;
|
||||
|
||||
code = tsdbWriteFile(fd[0], 0, hdr, TSDB_FHDR_SIZE, encryptAlgorithm, encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
@ -467,8 +468,8 @@ static int32_t tsdbDumpTombDataToFSet(STsdb *tsdb, SDelFReader *reader, SArray *
|
|||
int64_t minKey;
|
||||
int64_t maxKey;
|
||||
SBuffer buffers[10];
|
||||
int32_t encryptAlgorithm;
|
||||
char* encryptKey;
|
||||
int32_t encryptAlgorithm;
|
||||
char *encryptKey;
|
||||
// reader
|
||||
SArray *aDelData;
|
||||
// writer
|
||||
|
@ -538,20 +539,20 @@ static int32_t tsdbDumpTombDataToFSet(STsdb *tsdb, SDelFReader *reader, SArray *
|
|||
|
||||
if (ctx->fd != NULL) {
|
||||
if (ctx->toStt) {
|
||||
code = tsdbFileWriteTombBlk(ctx->fd, ctx->tombBlkArray, ctx->sttFooter->tombBlkPtr, &ctx->fobj->f->size,
|
||||
code = tsdbFileWriteTombBlk(ctx->fd, ctx->tombBlkArray, ctx->sttFooter->tombBlkPtr, &ctx->fobj->f->size,
|
||||
ctx->encryptAlgorithm, ctx->encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tsdbFileWriteSttFooter(ctx->fd, ctx->sttFooter, &ctx->fobj->f->size, ctx->encryptAlgorithm,
|
||||
ctx->encryptKey);
|
||||
code =
|
||||
tsdbFileWriteSttFooter(ctx->fd, ctx->sttFooter, &ctx->fobj->f->size, ctx->encryptAlgorithm, ctx->encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
} else {
|
||||
code = tsdbFileWriteTombBlk(ctx->fd, ctx->tombBlkArray, ctx->tombFooter->tombBlkPtr, &ctx->fobj->f->size,
|
||||
code = tsdbFileWriteTombBlk(ctx->fd, ctx->tombBlkArray, ctx->tombFooter->tombBlkPtr, &ctx->fobj->f->size,
|
||||
ctx->encryptAlgorithm, ctx->encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tsdbFileWriteTombFooter(ctx->fd, ctx->tombFooter, &ctx->fobj->f->size, ctx->encryptAlgorithm,
|
||||
ctx->encryptKey);
|
||||
code = tsdbFileWriteTombFooter(ctx->fd, ctx->tombFooter, &ctx->fobj->f->size, ctx->encryptAlgorithm,
|
||||
ctx->encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,17 +17,24 @@
|
|||
|
||||
// SDelBlock ----------
|
||||
int32_t tTombBlockInit(STombBlock *tombBlock) {
|
||||
int32_t code;
|
||||
|
||||
tombBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
tBufferInit(&tombBlock->buffers[i]);
|
||||
TAOS_CHECK_GOTO(tBufferInit(&tombBlock->buffers[i]), NULL, _exit);
|
||||
}
|
||||
return 0;
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TAOS_UNUSED(tTombBlockDestroy(tombBlock));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tTombBlockDestroy(STombBlock *tombBlock) {
|
||||
tombBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
tBufferDestroy(&tombBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferDestroy(&tombBlock->buffers[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -35,15 +42,14 @@ int32_t tTombBlockDestroy(STombBlock *tombBlock) {
|
|||
int32_t tTombBlockClear(STombBlock *tombBlock) {
|
||||
tombBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
tBufferClear(&tombBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferClear(&tombBlock->buffers[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tTombBlockPut(STombBlock *tombBlock, const STombRecord *record) {
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
int32_t code = tBufferPutI64(&tombBlock->buffers[i], record->data[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&tombBlock->buffers[i], record->data[i]));
|
||||
}
|
||||
tombBlock->numOfRecords++;
|
||||
return 0;
|
||||
|
@ -56,8 +62,7 @@ int32_t tTombBlockGet(STombBlock *tombBlock, int32_t idx, STombRecord *record) {
|
|||
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
SBufferReader br = BUFFER_READER_INITIALIZER(sizeof(int64_t) * idx, &tombBlock->buffers[i]);
|
||||
int32_t code = tBufferGetI64(&br, &record->data[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&br, &record->data[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -74,27 +79,34 @@ int32_t tTombRecordCompare(const STombRecord *r1, const STombRecord *r2) {
|
|||
|
||||
// STbStatisBlock ----------
|
||||
int32_t tStatisBlockInit(STbStatisBlock *statisBlock) {
|
||||
int32_t code;
|
||||
|
||||
statisBlock->numOfPKs = 0;
|
||||
statisBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
|
||||
tBufferInit(&statisBlock->buffers[i]);
|
||||
TAOS_CHECK_GOTO(tBufferInit(&statisBlock->buffers[i]), NULL, _exit);
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnInit(&statisBlock->firstKeyPKs[i]);
|
||||
tValueColumnInit(&statisBlock->lastKeyPKs[i]);
|
||||
TAOS_CHECK_GOTO(tValueColumnInit(&statisBlock->firstKeyPKs[i]), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(tValueColumnInit(&statisBlock->lastKeyPKs[i]), NULL, _exit);
|
||||
}
|
||||
return 0;
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TAOS_UNUSED(tStatisBlockDestroy(statisBlock));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tStatisBlockDestroy(STbStatisBlock *statisBlock) {
|
||||
statisBlock->numOfPKs = 0;
|
||||
statisBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
|
||||
tBufferDestroy(&statisBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferDestroy(&statisBlock->buffers[i]));
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnDestroy(&statisBlock->firstKeyPKs[i]);
|
||||
tValueColumnDestroy(&statisBlock->lastKeyPKs[i]);
|
||||
TAOS_UNUSED(tValueColumnDestroy(&statisBlock->firstKeyPKs[i]));
|
||||
TAOS_UNUSED(tValueColumnDestroy(&statisBlock->lastKeyPKs[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -103,17 +115,16 @@ int32_t tStatisBlockClear(STbStatisBlock *statisBlock) {
|
|||
statisBlock->numOfPKs = 0;
|
||||
statisBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
|
||||
tBufferClear(&statisBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferClear(&statisBlock->buffers[i]));
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnClear(&statisBlock->firstKeyPKs[i]);
|
||||
tValueColumnClear(&statisBlock->lastKeyPKs[i]);
|
||||
TAOS_UNUSED(tValueColumnClear(&statisBlock->firstKeyPKs[i]));
|
||||
TAOS_UNUSED(tValueColumnClear(&statisBlock->lastKeyPKs[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tStatisBlockAppend(STbStatisBlock *block, SRowInfo *row) {
|
||||
int32_t code;
|
||||
STsdbRowKey key;
|
||||
|
||||
tsdbRowGetKey(&row->row, &key);
|
||||
|
@ -129,14 +140,14 @@ static int32_t tStatisBlockAppend(STbStatisBlock *block, SRowInfo *row) {
|
|||
}
|
||||
}
|
||||
|
||||
if ((code = tBufferPutI64(&block->suids, row->suid))) return code;
|
||||
if ((code = tBufferPutI64(&block->uids, row->uid))) return code;
|
||||
if ((code = tBufferPutI64(&block->firstKeyTimestamps, key.key.ts))) return code;
|
||||
if ((code = tBufferPutI64(&block->lastKeyTimestamps, key.key.ts))) return code;
|
||||
if ((code = tBufferPutI64(&block->counts, 1))) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->suids, row->suid));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->uids, row->uid));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->firstKeyTimestamps, key.key.ts));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->lastKeyTimestamps, key.key.ts));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->counts, 1));
|
||||
for (int32_t i = 0; i < block->numOfPKs; ++i) {
|
||||
if ((code = tValueColumnAppend(block->firstKeyPKs + i, key.key.pks + i))) return code;
|
||||
if ((code = tValueColumnAppend(block->lastKeyPKs + i, key.key.pks + i))) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnAppend(block->firstKeyPKs + i, key.key.pks + i));
|
||||
TAOS_CHECK_RETURN(tValueColumnAppend(block->lastKeyPKs + i, key.key.pks + i));
|
||||
}
|
||||
|
||||
block->numOfRecords++;
|
||||
|
@ -147,9 +158,8 @@ static int32_t tStatisBlockUpdate(STbStatisBlock *block, SRowInfo *row) {
|
|||
STbStatisRecord record;
|
||||
STsdbRowKey key;
|
||||
int32_t c;
|
||||
int32_t code;
|
||||
|
||||
tStatisBlockGet(block, block->numOfRecords - 1, &record);
|
||||
TAOS_CHECK_RETURN(tStatisBlockGet(block, block->numOfRecords - 1, &record));
|
||||
tsdbRowGetKey(&row->row, &key);
|
||||
|
||||
c = tRowKeyCompare(&record.lastKey, &key.key);
|
||||
|
@ -157,21 +167,18 @@ static int32_t tStatisBlockUpdate(STbStatisBlock *block, SRowInfo *row) {
|
|||
return 0;
|
||||
} else if (c < 0) {
|
||||
// last ts
|
||||
code = tBufferPutAt(&block->lastKeyTimestamps, (block->numOfRecords - 1) * sizeof(record.lastKey.ts), &key.key.ts,
|
||||
sizeof(key.key.ts));
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutAt(&block->lastKeyTimestamps, (block->numOfRecords - 1) * sizeof(record.lastKey.ts),
|
||||
&key.key.ts, sizeof(key.key.ts)));
|
||||
|
||||
// last primary keys
|
||||
for (int i = 0; i < block->numOfPKs; i++) {
|
||||
code = tValueColumnUpdate(&block->lastKeyPKs[i], block->numOfRecords - 1, &key.key.pks[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnUpdate(&block->lastKeyPKs[i], block->numOfRecords - 1, &key.key.pks[i]));
|
||||
}
|
||||
|
||||
// count
|
||||
record.count++;
|
||||
code = tBufferPutAt(&block->counts, (block->numOfRecords - 1) * sizeof(record.count), &record.count,
|
||||
sizeof(record.count));
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutAt(&block->counts, (block->numOfRecords - 1) * sizeof(record.count), &record.count,
|
||||
sizeof(record.count)));
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -183,8 +190,7 @@ int32_t tStatisBlockPut(STbStatisBlock *block, SRowInfo *row, int32_t maxRecords
|
|||
if (block->numOfRecords > 0) {
|
||||
int64_t lastUid;
|
||||
SBufferReader br = BUFFER_READER_INITIALIZER(sizeof(int64_t) * (block->numOfRecords - 1), &block->uids);
|
||||
int32_t code = tBufferGetI64(&br, &lastUid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&br, &lastUid));
|
||||
|
||||
if (lastUid == row->uid) {
|
||||
return tStatisBlockUpdate(block, row);
|
||||
|
@ -196,7 +202,6 @@ int32_t tStatisBlockPut(STbStatisBlock *block, SRowInfo *row, int32_t maxRecords
|
|||
}
|
||||
|
||||
int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecord *record) {
|
||||
int32_t code;
|
||||
SBufferReader reader;
|
||||
|
||||
if (idx < 0 || idx >= statisBlock->numOfRecords) {
|
||||
|
@ -204,36 +209,29 @@ int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecor
|
|||
}
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->suid), &statisBlock->suids);
|
||||
code = tBufferGetI64(&reader, &record->suid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->suid));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->uid), &statisBlock->uids);
|
||||
code = tBufferGetI64(&reader, &record->uid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->uid));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->firstKey.ts), &statisBlock->firstKeyTimestamps);
|
||||
code = tBufferGetI64(&reader, &record->firstKey.ts);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->firstKey.ts));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->lastKey.ts), &statisBlock->lastKeyTimestamps);
|
||||
code = tBufferGetI64(&reader, &record->lastKey.ts);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->lastKey.ts));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->count), &statisBlock->counts);
|
||||
code = tBufferGetI64(&reader, &record->count);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->count));
|
||||
|
||||
// primary keys
|
||||
for (record->firstKey.numOfPKs = 0; record->firstKey.numOfPKs < statisBlock->numOfPKs; record->firstKey.numOfPKs++) {
|
||||
code = tValueColumnGet(&statisBlock->firstKeyPKs[record->firstKey.numOfPKs], idx,
|
||||
&record->firstKey.pks[record->firstKey.numOfPKs]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnGet(&statisBlock->firstKeyPKs[record->firstKey.numOfPKs], idx,
|
||||
&record->firstKey.pks[record->firstKey.numOfPKs]));
|
||||
}
|
||||
|
||||
for (record->lastKey.numOfPKs = 0; record->lastKey.numOfPKs < statisBlock->numOfPKs; record->lastKey.numOfPKs++) {
|
||||
code = tValueColumnGet(&statisBlock->lastKeyPKs[record->lastKey.numOfPKs], idx,
|
||||
&record->lastKey.pks[record->lastKey.numOfPKs]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnGet(&statisBlock->lastKeyPKs[record->lastKey.numOfPKs], idx,
|
||||
&record->lastKey.pks[record->lastKey.numOfPKs]));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -241,27 +239,34 @@ int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecor
|
|||
|
||||
// SBrinRecord ----------
|
||||
int32_t tBrinBlockInit(SBrinBlock *brinBlock) {
|
||||
int32_t code;
|
||||
|
||||
brinBlock->numOfPKs = 0;
|
||||
brinBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
|
||||
tBufferInit(&brinBlock->buffers[i]);
|
||||
TAOS_CHECK_GOTO(tBufferInit(&brinBlock->buffers[i]), NULL, _exit);
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnInit(&brinBlock->firstKeyPKs[i]);
|
||||
tValueColumnInit(&brinBlock->lastKeyPKs[i]);
|
||||
TAOS_CHECK_GOTO(tValueColumnInit(&brinBlock->firstKeyPKs[i]), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(tValueColumnInit(&brinBlock->lastKeyPKs[i]), NULL, _exit);
|
||||
}
|
||||
return 0;
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TAOS_UNUSED(tBrinBlockDestroy(brinBlock));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tBrinBlockDestroy(SBrinBlock *brinBlock) {
|
||||
brinBlock->numOfPKs = 0;
|
||||
brinBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
|
||||
tBufferDestroy(&brinBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferDestroy(&brinBlock->buffers[i]));
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnDestroy(&brinBlock->firstKeyPKs[i]);
|
||||
tValueColumnDestroy(&brinBlock->lastKeyPKs[i]);
|
||||
TAOS_UNUSED(tValueColumnDestroy(&brinBlock->firstKeyPKs[i]));
|
||||
TAOS_UNUSED(tValueColumnDestroy(&brinBlock->lastKeyPKs[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -270,18 +275,16 @@ int32_t tBrinBlockClear(SBrinBlock *brinBlock) {
|
|||
brinBlock->numOfPKs = 0;
|
||||
brinBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
|
||||
tBufferClear(&brinBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferClear(&brinBlock->buffers[i]));
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnClear(&brinBlock->firstKeyPKs[i]);
|
||||
tValueColumnClear(&brinBlock->lastKeyPKs[i]);
|
||||
TAOS_UNUSED(tValueColumnClear(&brinBlock->firstKeyPKs[i]));
|
||||
TAOS_UNUSED(tValueColumnClear(&brinBlock->lastKeyPKs[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record) {
|
||||
int32_t code;
|
||||
|
||||
ASSERT(record->firstKey.key.numOfPKs == record->lastKey.key.numOfPKs);
|
||||
|
||||
if (brinBlock->numOfRecords == 0) { // the first row
|
||||
|
@ -298,60 +301,29 @@ int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record) {
|
|||
}
|
||||
}
|
||||
|
||||
code = tBufferPutI64(&brinBlock->suids, record->suid);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->uids, record->uid);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->firstKeyTimestamps, record->firstKey.key.ts);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->firstKeyVersions, record->firstKey.version);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->lastKeyTimestamps, record->lastKey.key.ts);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->lastKeyVersions, record->lastKey.version);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->minVers, record->minVer);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->maxVers, record->maxVer);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->blockOffsets, record->blockOffset);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->smaOffsets, record->smaOffset);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->blockSizes, record->blockSize);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->blockKeySizes, record->blockKeySize);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->smaSizes, record->smaSize);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->numRows, record->numRow);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->counts, record->count);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->suids, record->suid));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->uids, record->uid));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->firstKeyTimestamps, record->firstKey.key.ts));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->firstKeyVersions, record->firstKey.version));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->lastKeyTimestamps, record->lastKey.key.ts));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->lastKeyVersions, record->lastKey.version));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->minVers, record->minVer));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->maxVers, record->maxVer));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->blockOffsets, record->blockOffset));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->smaOffsets, record->smaOffset));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->blockSizes, record->blockSize));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->blockKeySizes, record->blockKeySize));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->smaSizes, record->smaSize));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->numRows, record->numRow));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->counts, record->count));
|
||||
|
||||
if (brinBlock->numOfPKs > 0) {
|
||||
for (int32_t i = 0; i < brinBlock->numOfPKs; ++i) {
|
||||
code = tValueColumnAppend(&brinBlock->firstKeyPKs[i], &record->firstKey.key.pks[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnAppend(&brinBlock->firstKeyPKs[i], &record->firstKey.key.pks[i]));
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < brinBlock->numOfPKs; ++i) {
|
||||
code = tValueColumnAppend(&brinBlock->lastKeyPKs[i], &record->lastKey.key.pks[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnAppend(&brinBlock->lastKeyPKs[i], &record->lastKey.key.pks[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -361,7 +333,6 @@ int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record) {
|
|||
}
|
||||
|
||||
int32_t tBrinBlockGet(SBrinBlock *brinBlock, int32_t idx, SBrinRecord *record) {
|
||||
int32_t code;
|
||||
SBufferReader reader;
|
||||
|
||||
if (idx < 0 || idx >= brinBlock->numOfRecords) {
|
||||
|
@ -369,78 +340,61 @@ int32_t tBrinBlockGet(SBrinBlock *brinBlock, int32_t idx, SBrinRecord *record) {
|
|||
}
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->suids);
|
||||
code = tBufferGetI64(&reader, &record->suid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->suid));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->uids);
|
||||
code = tBufferGetI64(&reader, &record->uid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->uid));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->firstKeyTimestamps);
|
||||
code = tBufferGetI64(&reader, &record->firstKey.key.ts);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->firstKey.key.ts));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->firstKeyVersions);
|
||||
code = tBufferGetI64(&reader, &record->firstKey.version);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->firstKey.version));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->lastKeyTimestamps);
|
||||
code = tBufferGetI64(&reader, &record->lastKey.key.ts);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->lastKey.key.ts));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->lastKeyVersions);
|
||||
code = tBufferGetI64(&reader, &record->lastKey.version);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->lastKey.version));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->minVers);
|
||||
code = tBufferGetI64(&reader, &record->minVer);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->minVer));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->maxVers);
|
||||
code = tBufferGetI64(&reader, &record->maxVer);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->maxVer));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->blockOffsets);
|
||||
code = tBufferGetI64(&reader, &record->blockOffset);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->blockOffset));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->smaOffsets);
|
||||
code = tBufferGetI64(&reader, &record->smaOffset);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->smaOffset));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->blockSizes);
|
||||
code = tBufferGetI32(&reader, &record->blockSize);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->blockSize));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->blockKeySizes);
|
||||
code = tBufferGetI32(&reader, &record->blockKeySize);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->blockKeySize));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->smaSizes);
|
||||
code = tBufferGetI32(&reader, &record->smaSize);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->smaSize));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->numRows);
|
||||
code = tBufferGetI32(&reader, &record->numRow);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->numRow));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->counts);
|
||||
code = tBufferGetI32(&reader, &record->count);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->count));
|
||||
|
||||
// primary keys
|
||||
for (record->firstKey.key.numOfPKs = 0; record->firstKey.key.numOfPKs < brinBlock->numOfPKs;
|
||||
record->firstKey.key.numOfPKs++) {
|
||||
code = tValueColumnGet(&brinBlock->firstKeyPKs[record->firstKey.key.numOfPKs], idx,
|
||||
&record->firstKey.key.pks[record->firstKey.key.numOfPKs]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnGet(&brinBlock->firstKeyPKs[record->firstKey.key.numOfPKs], idx,
|
||||
&record->firstKey.key.pks[record->firstKey.key.numOfPKs]));
|
||||
}
|
||||
|
||||
for (record->lastKey.key.numOfPKs = 0; record->lastKey.key.numOfPKs < brinBlock->numOfPKs;
|
||||
record->lastKey.key.numOfPKs++) {
|
||||
code = tValueColumnGet(&brinBlock->lastKeyPKs[record->lastKey.key.numOfPKs], idx,
|
||||
&record->lastKey.key.pks[record->lastKey.key.numOfPKs]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnGet(&brinBlock->lastKeyPKs[record->lastKey.key.numOfPKs], idx,
|
||||
&record->lastKey.key.pks[record->lastKey.key.numOfPKs]));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -11,61 +11,216 @@ class TDTestCase(TBase):
|
|||
def init(self, conn, logSql, replicaVar=1):
|
||||
tdLog.debug(f"start to excute {__file__}")
|
||||
tdSql.init(conn.cursor(), True)
|
||||
self.dbname = "cast_db"
|
||||
self._datetime_epoch = datetime.datetime.fromtimestamp(0)
|
||||
|
||||
def cast_without_from(self):
|
||||
def cast_from_int_to_other(self):
|
||||
# int
|
||||
int_num = 2147483648
|
||||
tdSql.query(f"select cast({int_num} as int) re;")
|
||||
tdSql.checkData(0, 0, -int_num)
|
||||
int_num1 = 2147483647
|
||||
int_num2 = 2147483648
|
||||
tdSql.query(f"select cast({int_num1} as int) re;")
|
||||
tdSql.checkData(0, 0, int_num1)
|
||||
|
||||
tdSql.query(f"select cast(2147483647 as int) re;")
|
||||
tdSql.checkData(0, 0, 2147483647)
|
||||
tdSql.query(f"select cast({int_num2} as int) re;")
|
||||
tdSql.checkData(0, 0, -int_num2)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num2} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num2)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as bigint) re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as bigint) re;")
|
||||
tdSql.checkData(0, 0, int_num1)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num1)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as smallint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.query(f"select cast({int_num1} as smallint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.query(f"select cast({int_num1} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 65535)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.query(f"select cast({int_num1} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.query(f"select cast({int_num1} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 255)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as float) re;")
|
||||
tdSql.checkData(0, 0, '2147483648.0')
|
||||
tdSql.query(f"select cast({int_num2} as float) re;")
|
||||
tdSql.checkData(0, 0, "2147483648.0")
|
||||
|
||||
tdSql.query(f"select cast({int_num} as double) re;")
|
||||
tdSql.checkData(0, 0, '2147483648.0')
|
||||
tdSql.query(f"select cast({int_num2} as double) re;")
|
||||
tdSql.checkData(0, 0, "2147483648.0")
|
||||
|
||||
tdSql.query(f"select cast({int_num} as bool) as re;")
|
||||
tdSql.query(f"select cast({int_num2} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(int_num) / 1000))
|
||||
tdSql.query(f"select cast({int_num2} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(int_num2) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({int_num} as varchar(10)) as re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as varchar(5)) as re;")
|
||||
tdSql.checkData(0, 0, "21474")
|
||||
|
||||
tdSql.query(f"select cast({int_num} as binary(10)) as re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as binary(5)) as re;")
|
||||
tdSql.checkData(0, 0, "21474")
|
||||
|
||||
sql = f"select cast({int_num} as nchar(10));"
|
||||
tdSql.query(sql)
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as nchar(5));")
|
||||
tdSql.checkData(0, 0, "21474")
|
||||
|
||||
def cast_from_bigint_to_other(self):
|
||||
# bigint
|
||||
bigint_num = 9223372036854775807
|
||||
bigint_num2 = 9223372036854775808
|
||||
tdSql.query(f"select cast({bigint_num} as int) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, 4294967295)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as bigint) re;")
|
||||
tdSql.checkData(0, 0, bigint_num)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num2} as bigint) re;")
|
||||
tdSql.checkData(0, 0, -bigint_num2)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num2} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, bigint_num2)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as smallint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 65535)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 255)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as float) re;")
|
||||
tdSql.checkData(0, 0, 9.2233720e18)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as double) re;")
|
||||
tdSql.checkData(0, 0, 9.2233720e18)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
# WARN: datetime overflow dont worry
|
||||
tdSql.query(f"select cast({bigint_num} as timestamp) as re;")
|
||||
# tdSql.checkData(0, 0, "292278994-08-17 15:12:55.807")
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as varchar(5)) as re;")
|
||||
tdSql.checkData(0, 0, "92233")
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as binary(5)) as re;")
|
||||
tdSql.checkData(0, 0, "92233")
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as nchar(5));")
|
||||
tdSql.checkData(0, 0, "92233")
|
||||
|
||||
def cast_from_smallint_to_other(self):
|
||||
smallint_num = 32767
|
||||
smallint_num2 = 32768
|
||||
tdSql.query(f"select cast({smallint_num} as int) re;")
|
||||
tdSql.checkData(0, 0, smallint_num)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, smallint_num)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as bigint) re;")
|
||||
tdSql.checkData(0, 0, smallint_num)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num2} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, smallint_num2)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as smallint) re;")
|
||||
tdSql.checkData(0, 0, smallint_num)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num2} as smallint) re;")
|
||||
tdSql.checkData(0, 0, -smallint_num2)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num2} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, smallint_num2)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 255)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as float) re;")
|
||||
tdSql.checkData(0, 0, "32767.0")
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as double) re;")
|
||||
tdSql.checkData(0, 0, "32767.0")
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(smallint_num) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as varchar(3)) as re;")
|
||||
tdSql.checkData(0, 0, "327")
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as binary(3)) as re;")
|
||||
tdSql.checkData(0, 0, "327")
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as nchar(3));")
|
||||
tdSql.checkData(0, 0, "327")
|
||||
|
||||
def cast_from_tinyint_to_other(self):
|
||||
tinyint_num = 127
|
||||
tinyint_num2 = 128
|
||||
tdSql.query(f"select cast({tinyint_num} as int) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as bigint) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num2} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num2)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as smallint) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num2} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, -tinyint_num2)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num2} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num2)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as float) re;")
|
||||
tdSql.checkData(0, 0, "127.0")
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as double) re;")
|
||||
tdSql.checkData(0, 0, "127.0")
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(tinyint_num) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as varchar(2)) as re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as binary(2)) as re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as nchar(2));")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
def cast_from_float_to_other(self):
|
||||
# float
|
||||
float_1001 = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019
|
||||
|
||||
|
@ -116,22 +271,31 @@ class TDTestCase(TBase):
|
|||
tdSql.query(f"select cast({float_1001} as nchar(5));")
|
||||
tdSql.checkData(0, 0, 3.141)
|
||||
|
||||
def cast_from_str_to_other(self):
|
||||
# str
|
||||
str_410 = "bcdefghigk" * 41
|
||||
big_str = "bcdefghigk" * 6552
|
||||
_str = "bcdefghigk"
|
||||
str_410 = _str * 41
|
||||
str_401 = _str * 40 + "b"
|
||||
big_str = _str * 6552
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as binary(3)) as re;")
|
||||
tdSql.checkData(0, 0, "bcd")
|
||||
tdSql.query(f"select cast('{str_410}' as binary(401)) as re;")
|
||||
tdSql.checkData(0, 0, str_401)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as varchar(2)) as re;")
|
||||
tdSql.checkData(0, 0, "bc")
|
||||
tdSql.query(f"select cast('{str_410}' as varchar(401)) as re;")
|
||||
tdSql.checkData(0, 0, str_401)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as nchar(10));")
|
||||
tdSql.checkData(0, 0, "bcdefghigk")
|
||||
tdSql.query(f"select cast('{big_str}' as varchar(420)) as re;")
|
||||
tdSql.checkData(0, 0, _str * 42)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as nchar(401));")
|
||||
tdSql.checkData(0, 0, str_401)
|
||||
|
||||
tdSql.query(f"select cast('北京' as nchar(10));")
|
||||
tdSql.checkData(0, 0, "北京")
|
||||
|
||||
# tdSql.query(f"select cast('北京涛思数据有限公司' as nchar(6));")
|
||||
# tdSql.checkData(0, 0, "北京涛思数据")
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as int) as re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
|
@ -165,15 +329,232 @@ class TDTestCase(TBase):
|
|||
tdSql.query(f"select cast('{str_410}' as bool) as re")
|
||||
tdSql.checkData(0, 0, False)
|
||||
|
||||
tdSql.query( f"select cast('{str_410}' as timestamp) as re")
|
||||
tdSql.query(f"select cast('{str_410}' as timestamp) as re")
|
||||
tdSql.checkData(0, 0, "1970-01-01 08:00:00.000")
|
||||
|
||||
def cast_from_bool_to_other(self):
|
||||
true_val = True
|
||||
false_val = False
|
||||
tdSql.query(f"select cast({false_val} as int) re, cast({true_val} as int) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as int unsigned) re, cast({true_val} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as bigint) re, cast({true_val} as bigint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(
|
||||
f"select cast({false_val} as bigint unsigned) re, cast({true_val} as bigint unsigned) re;"
|
||||
)
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as smallint) re, cast({true_val} as smallint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(
|
||||
f"select cast({false_val} as smallint unsigned) re, cast({true_val} as smallint unsigned) re;"
|
||||
)
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as tinyint) re, cast({true_val} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(
|
||||
f"select cast({false_val} as tinyint unsigned) re, cast({true_val} as tinyint unsigned) re;"
|
||||
)
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as smallint) re, cast({true_val} as smallint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as float) re, cast({true_val} as float) re;")
|
||||
tdSql.checkData(0, 0, 0.0000000)
|
||||
tdSql.checkData(0, 1, 1.0000000)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as double) re, cast({true_val} as double) re;")
|
||||
tdSql.checkData(0, 0, 0.000000000000000)
|
||||
tdSql.checkData(0, 1, 1.000000000000000)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as bool) re, cast({true_val} as bool) re;")
|
||||
tdSql.checkData(0, 0, false_val)
|
||||
tdSql.checkData(0, 1, true_val)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as timestamp) re, cast({true_val} as timestamp) re;")
|
||||
tdSql.checkData(0, 0, "1970-01-01 08:00:00.000")
|
||||
tdSql.checkData(0, 1, "1970-01-01 08:00:00.001")
|
||||
|
||||
tdSql.query(f"select cast({false_val} as varchar(3)) re, cast({true_val} as varchar(3)) re;")
|
||||
tdSql.checkData(0, 0, "fal")
|
||||
tdSql.checkData(0, 1, "tru")
|
||||
|
||||
tdSql.query(f"select cast({false_val} as binary(3)) re, cast({true_val} as binary(3)) re;")
|
||||
tdSql.checkData(0, 0, "fal")
|
||||
tdSql.checkData(0, 1, "tru")
|
||||
|
||||
tdSql.query(f"select cast({false_val} as nchar(3)) re, cast({true_val} as nchar(3)) re;")
|
||||
tdSql.checkData(0, 0, "fal")
|
||||
tdSql.checkData(0, 1, "tru")
|
||||
|
||||
def cast_from_timestamp_to_other(self):
|
||||
# ts = self._datetime_epoch
|
||||
# tdSql.query(f"select cast({ts} as int) re;")
|
||||
# tdSql.checkData(0, 0, None)
|
||||
# todo
|
||||
pass
|
||||
|
||||
def cast_from_null_to_other(self):
|
||||
tdSql.query(f"select cast(null as int) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as bigint) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as smallint) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as tinyint) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as float) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as double) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as bool) as re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as varchar(55)) as re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as binary(5)) as re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as nchar(5));")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
def cast_from_compute_to_other(self):
|
||||
add1 = 123
|
||||
add2 = 456
|
||||
re = 579
|
||||
tdSql.query(f"select cast({add1}+{add2} as int) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as bigint) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as smallint) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, 67)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 67)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as float) re;")
|
||||
tdSql.checkData(0, 0, "579.0")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as double) re;")
|
||||
tdSql.checkData(0, 0, "579.0")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(re) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as varchar(2)) as re;")
|
||||
tdSql.checkData(0, 0, "57")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as binary(2)) as re;")
|
||||
tdSql.checkData(0, 0, "57")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as nchar(2));")
|
||||
tdSql.checkData(0, 0, "57")
|
||||
|
||||
test_str = "'!@#'"
|
||||
tdSql.query(f"select cast({add1}+{test_str} as int) re;")
|
||||
tdSql.checkData(0, 0, add1)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as bigint) re;")
|
||||
tdSql.checkData(0, 0, add1)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as smallint) re;")
|
||||
tdSql.checkData(0, 0, add1)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, add1)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as float) re;")
|
||||
tdSql.checkData(0, 0, "123.0")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as double) re;")
|
||||
tdSql.checkData(0, 0, "123.0")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as bool) re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as timestamp) re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(add1) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as varchar(2)) re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as binary(2)) re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as nchar(2)) re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
def cast_without_from(self):
|
||||
self.cast_from_int_to_other()
|
||||
self.cast_from_bigint_to_other()
|
||||
self.cast_from_smallint_to_other()
|
||||
self.cast_from_tinyint_to_other()
|
||||
self.cast_from_float_to_other()
|
||||
self.cast_from_str_to_other()
|
||||
self.cast_from_bool_to_other()
|
||||
self.cast_from_timestamp_to_other()
|
||||
self.cast_from_compute_to_other()
|
||||
# self.cast_from_null_to_other()
|
||||
|
||||
def run(self):
|
||||
# self.prepare_data()
|
||||
# self.all_test()
|
||||
# tdSql.execute(f"flush database {self.dbname}")
|
||||
# self.all_test()
|
||||
# 'from table' case see system-test/2-query/cast.py
|
||||
self.cast_without_from()
|
||||
|
||||
tdLog.success(f"{__file__} successfully executed")
|
||||
|
|
|
@ -38,15 +38,16 @@ class TDSimClient:
|
|||
"asyncLog": "0",
|
||||
"rpcDebugFlag": "135",
|
||||
"tmrDebugFlag": "131",
|
||||
"cDebugFlag": "135",
|
||||
"uDebugFlag": "135",
|
||||
"jniDebugFlag": "135",
|
||||
"dDebugFlag":"131",
|
||||
"cDebugFlag": "131",
|
||||
"uDebugFlag": "131",
|
||||
"jniDebugFlag": "131",
|
||||
"qDebugFlag": "135",
|
||||
"supportVnodes": "1024",
|
||||
"enableQueryHb": "1",
|
||||
"telemetryReporting": "0",
|
||||
"tqDebugflag": "135",
|
||||
"wDebugflag":"135",
|
||||
"stDebugflag":"135",
|
||||
}
|
||||
|
||||
def getLogDir(self):
|
||||
|
@ -134,9 +135,9 @@ class TDDnode:
|
|||
"dDebugFlag": "131",
|
||||
"vDebugFlag": "131",
|
||||
"tqDebugFlag": "135",
|
||||
"cDebugFlag": "135",
|
||||
"cDebugFlag": "131",
|
||||
"stDebugFlag": "135",
|
||||
"smaDebugFlag": "135",
|
||||
"smaDebugFlag": "131",
|
||||
"jniDebugFlag": "131",
|
||||
"qDebugFlag": "131",
|
||||
"rpcDebugFlag": "135",
|
||||
|
|
|
@ -307,8 +307,8 @@ class TDSql:
|
|||
return col_name_list, col_type_list
|
||||
return col_name_list
|
||||
|
||||
def waitedQuery(self, sql, expectRows, timeout):
|
||||
tdLog.info("sql: %s, try to retrieve %d rows in %d seconds" % (sql, expectRows, timeout))
|
||||
def waitedQuery(self, sql, expectedRows, timeout):
|
||||
tdLog.info("sql: %s, try to retrieve %d rows in %d seconds" % (sql, expectedRows, timeout))
|
||||
self.sql = sql
|
||||
try:
|
||||
for i in range(timeout):
|
||||
|
@ -316,8 +316,8 @@ class TDSql:
|
|||
self.queryResult = self.cursor.fetchall()
|
||||
self.queryRows = len(self.queryResult)
|
||||
self.queryCols = len(self.cursor.description)
|
||||
tdLog.info("sql: %s, try to retrieve %d rows,get %d rows" % (sql, expectRows, self.queryRows))
|
||||
if self.queryRows >= expectRows:
|
||||
tdLog.info("sql: %s, try to retrieve %d rows,get %d rows" % (sql, expectedRows, self.queryRows))
|
||||
if self.queryRows >= expectedRows:
|
||||
return (self.queryRows, i)
|
||||
time.sleep(1)
|
||||
except Exception as e:
|
||||
|
@ -330,15 +330,26 @@ class TDSql:
|
|||
def getRows(self):
|
||||
return self.queryRows
|
||||
|
||||
def checkRows(self, expectRows):
|
||||
if self.queryRows == expectRows:
|
||||
tdLog.info("sql:%s, queryRows:%d == expect:%d" % (self.sql, self.queryRows, expectRows))
|
||||
def checkRows(self, expectedRows):
|
||||
if self.queryRows == expectedRows:
|
||||
tdLog.info("sql:%s, queryRows:%d == expect:%d" % (self.sql, self.queryRows, expectedRows))
|
||||
return True
|
||||
else:
|
||||
caller = inspect.getframeinfo(inspect.stack()[1][0])
|
||||
args = (caller.filename, caller.lineno, self.sql, self.queryRows, expectRows)
|
||||
args = (caller.filename, caller.lineno, self.sql, self.queryRows, expectedRows)
|
||||
tdLog.exit("%s(%d) failed: sql:%s, queryRows:%d != expect:%d" % args)
|
||||
|
||||
def checkRows_not_exited(self, expectedRows):
|
||||
"""
|
||||
Check if the query rows is equal to the expected rows
|
||||
:param expectedRows: The expected number of rows.
|
||||
:return: Returns True if the actual number of rows matches the expected number, otherwise returns False.
|
||||
"""
|
||||
if self.queryRows == expectedRows:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def checkRows_range(self, excepte_row_list):
|
||||
if self.queryRows in excepte_row_list:
|
||||
tdLog.info(f"sql:{self.sql}, queryRows:{self.queryRows} in expect:{excepte_row_list}")
|
||||
|
@ -508,7 +519,7 @@ class TDSql:
|
|||
|
||||
|
||||
# return true or false replace exit, no print out
|
||||
def checkDataNoExit(self, row, col, data):
|
||||
def checkDataNotExit(self, row, col, data):
|
||||
if self.checkRowColNoExit(row, col) == False:
|
||||
return False
|
||||
if self.queryResult[row][col] != data:
|
||||
|
@ -542,7 +553,7 @@ class TDSql:
|
|||
# loop check util checkData return true
|
||||
for i in range(loopCount):
|
||||
self.query(sql)
|
||||
if self.checkDataNoExit(row, col, data) :
|
||||
if self.checkDataNotExit(row, col, data) :
|
||||
self.checkData(row, col, data)
|
||||
return
|
||||
time.sleep(waitTime)
|
||||
|
@ -551,6 +562,19 @@ class TDSql:
|
|||
self.query(sql)
|
||||
self.checkData(row, col, data)
|
||||
|
||||
def check_rows_loop(self, expectedRows, sql, loopCount, waitTime):
|
||||
# loop check util checkData return true
|
||||
for i in range(loopCount):
|
||||
self.query(sql)
|
||||
if self.checkRows_not_exited(expectedRows):
|
||||
return
|
||||
else:
|
||||
time.sleep(waitTime)
|
||||
continue
|
||||
# last check
|
||||
self.query(sql)
|
||||
self.checkRows(expectedRows)
|
||||
|
||||
|
||||
def getData(self, row, col):
|
||||
self.checkRowCol(row, col)
|
||||
|
|
|
@ -297,7 +297,8 @@ class TDTestCase:
|
|||
'mysql':'MySQL',
|
||||
'postgres':'PostgreSQL',
|
||||
'oracle':'Oracle',
|
||||
'mssql':'SqlServer'
|
||||
'mssql':'SqlServer',
|
||||
'mongodb':'MongoDB',
|
||||
}
|
||||
|
||||
tdSql.execute('drop database if exists db2')
|
||||
|
|
|
@ -177,21 +177,15 @@ class TDTestCase:
|
|||
if stopRole == "mnode":
|
||||
for i in range(mnodeNums):
|
||||
tdDnodes[i].stoptaosd()
|
||||
# sleep(10)
|
||||
tdDnodes[i].starttaosd()
|
||||
# sleep(10)
|
||||
elif stopRole == "vnode":
|
||||
for i in range(vnodeNumbers):
|
||||
tdDnodes[i+mnodeNums].stoptaosd()
|
||||
# sleep(10)
|
||||
tdDnodes[i+mnodeNums].starttaosd()
|
||||
# sleep(10)
|
||||
elif stopRole == "dnode":
|
||||
for i in range(dnodeNumbers):
|
||||
tdDnodes[i].stoptaosd()
|
||||
# sleep(10)
|
||||
tdDnodes[i].starttaosd()
|
||||
# sleep(10)
|
||||
|
||||
# dnodeNumbers don't include database of schema
|
||||
if clusterComCheck.checkDnodes(dnodeNumbers):
|
||||
|
@ -219,7 +213,7 @@ class TDTestCase:
|
|||
tdSql.checkRows(rowsPerStb)
|
||||
def run(self):
|
||||
# print(self.master_dnode.cfgDict)
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=2,stopRole='dnode')
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=1,stopRole='dnode')
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
|
@ -227,7 +227,7 @@ class TDTestCase:
|
|||
|
||||
def run(self):
|
||||
# print(self.master_dnode.cfgDict)
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=2,stopRole='dnode')
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=1,stopRole='dnode')
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
|
@ -168,7 +168,7 @@ class TDTestCase:
|
|||
|
||||
def run(self):
|
||||
# print(self.master_dnode.cfgDict)
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=2,stopRole='dnode')
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=1,stopRole='dnode')
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
|
@ -170,7 +170,7 @@ class TDTestCase:
|
|||
|
||||
def run(self):
|
||||
# print(self.master_dnode.cfgDict)
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=4,stopRole='mnode')
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=2,stopRole='mnode')
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
|
@ -93,7 +93,7 @@ class TDTestCase:
|
|||
# seperate vnode and mnode in different dnodes.
|
||||
# create database and stable
|
||||
stopcount =0
|
||||
while stopcount <= 2:
|
||||
while stopcount <= 1:
|
||||
tdLog.info(" restart loop: %d"%stopcount )
|
||||
for i in range(dnodenumbers):
|
||||
tdDnodes[i].stoptaosd()
|
||||
|
|
|
@ -37,7 +37,7 @@ class ClusterComCheck:
|
|||
tdSql.init(conn.cursor())
|
||||
# tdSql.init(conn.cursor(), logSql) # output sql.txt file
|
||||
|
||||
def checkDnodes(self,dnodeNumbers, timeout=30):
|
||||
def checkDnodes(self,dnodeNumbers, timeout=100):
|
||||
count=0
|
||||
# print(tdSql)
|
||||
while count < timeout:
|
||||
|
|
|
@ -37,26 +37,26 @@ class TDTestCase:
|
|||
def case1(self):
|
||||
tdLog.debug("========case1 start========")
|
||||
|
||||
os.system("nohup taosBenchmark -y -B 1 -t 40 -S 1000 -n 10 -i 1000 -v 5 > /dev/null 2>&1 &")
|
||||
os.system(" taosBenchmark -y -B 1 -t 10 -S 1000 -n 10 -i 1000 -v 5 ")
|
||||
time.sleep(10)
|
||||
tdSql.execute("use test", queryTimes=100)
|
||||
tdSql.query("create stream if not exists s1 trigger at_once ignore expired 0 ignore update 0 fill_history 1 into st1 as select _wstart,sum(voltage),groupid from meters partition by groupid interval(2s)")
|
||||
tdLog.debug("========create stream and insert data ok========")
|
||||
time.sleep(20)
|
||||
tdLog.debug("========create stream and insert data ok========")
|
||||
|
||||
tdSql.query("select _wstart,sum(voltage),groupid from meters partition by groupid interval(2s) order by groupid,_wstart")
|
||||
rowCnt = tdSql.getRows()
|
||||
results = []
|
||||
for i in range(rowCnt):
|
||||
results.append(tdSql.getData(i,1))
|
||||
results_meters = tdSql.queryResult
|
||||
|
||||
tdSql.query("select * from st1 order by groupid,_wstart")
|
||||
tdSql.checkRows(rowCnt)
|
||||
sql = "select _wstart,`sum(voltage)`,groupid from st1 order by groupid,_wstart"
|
||||
tdSql.check_rows_loop(rowCnt, sql, loopCount=100, waitTime=0.5)
|
||||
|
||||
tdSql.query(sql)
|
||||
results_st1 = tdSql.queryResult
|
||||
for i in range(rowCnt):
|
||||
data1 = tdSql.getData(i,1)
|
||||
data2 = results[i]
|
||||
data1 = results_st1[i]
|
||||
data2 = results_meters[i]
|
||||
if data1 != data2:
|
||||
tdLog.info("num: %d, act data: %d, expect data: %d"%(i, data1, data2))
|
||||
tdLog.info(f"num: {i}, act data: {data1}, expect data: {data2}")
|
||||
tdLog.exit("check data error!")
|
||||
|
||||
tdLog.debug("case1 end")
|
||||
|
@ -64,7 +64,7 @@ class TDTestCase:
|
|||
def case2(self):
|
||||
tdLog.debug("========case2 start========")
|
||||
|
||||
os.system("taosBenchmark -d db -t 20 -v 6 -n 1000 -y > /dev/null 2>&1")
|
||||
os.system("taosBenchmark -d db -t 20 -v 6 -n 1000 -y")
|
||||
# create stream
|
||||
tdSql.execute("use db", queryTimes=100)
|
||||
tdSql.execute("create stream stream1 fill_history 1 into sta as select count(*) as cnt from meters interval(10a);",show=True)
|
||||
|
@ -73,7 +73,7 @@ class TDTestCase:
|
|||
sql = "select count(*) from sta"
|
||||
# loop wait max 60s to check count is ok
|
||||
tdLog.info("loop wait result ...")
|
||||
tdSql.checkDataLoop(0, 0, 100, sql, loopCount=10, waitTime=0.5)
|
||||
tdSql.checkDataLoop(0, 0, 100, sql, loopCount=100, waitTime=0.5)
|
||||
|
||||
# check all data is correct
|
||||
sql = "select * from sta where cnt != 200;"
|
||||
|
|
Loading…
Reference in New Issue