Merge pull request #25068 from taosdata/mark/tmq-opti
opti:subscribe logic
This commit is contained in:
commit
adcad780e1
|
@ -3921,11 +3921,11 @@ int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
||||||
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
||||||
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
||||||
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
||||||
int32_t tDeatroySMqHbReq(SMqHbReq* pReq);
|
void tDestroySMqHbReq(SMqHbReq* pReq);
|
||||||
|
|
||||||
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
|
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
|
||||||
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
|
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
|
||||||
int32_t tDeatroySMqHbRsp(SMqHbRsp* pRsp);
|
void tDestroySMqHbRsp(SMqHbRsp* pRsp);
|
||||||
|
|
||||||
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
|
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
|
||||||
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
|
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
|
||||||
|
|
|
@ -779,7 +779,7 @@ int32_t tmqHbCb(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
taosWUnLockLatch(&tmq->lock);
|
taosWUnLockLatch(&tmq->lock);
|
||||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||||
}
|
}
|
||||||
tDeatroySMqHbRsp(&rsp);
|
tDestroySMqHbRsp(&rsp);
|
||||||
taosMemoryFree(pMsg->pData);
|
taosMemoryFree(pMsg->pData);
|
||||||
taosMemoryFree(pMsg->pEpSet);
|
taosMemoryFree(pMsg->pEpSet);
|
||||||
}
|
}
|
||||||
|
@ -861,7 +861,7 @@ void tmqSendHbReq(void* param, void* tmrId) {
|
||||||
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||||
|
|
||||||
OVER:
|
OVER:
|
||||||
tDeatroySMqHbReq(&req);
|
tDestroySMqHbReq(&req);
|
||||||
taosTmrReset(tmqSendHbReq, DEFAULT_HEARTBEAT_INTERVAL, param, tmqMgmt.timer, &tmq->hbLiveTimer);
|
taosTmrReset(tmqSendHbReq, DEFAULT_HEARTBEAT_INTERVAL, param, tmqMgmt.timer, &tmq->hbLiveTimer);
|
||||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6201,9 +6201,8 @@ int32_t tDeserializeSMqAskEpReq(void *buf, int32_t bufLen, SMqAskEpReq *pReq) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tDeatroySMqHbRsp(SMqHbRsp *pRsp) {
|
void tDestroySMqHbRsp(SMqHbRsp *pRsp) {
|
||||||
taosArrayDestroy(pRsp->topicPrivileges);
|
taosArrayDestroy(pRsp->topicPrivileges);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tSerializeSMqHbRsp(void *buf, int32_t bufLen, SMqHbRsp *pRsp) {
|
int32_t tSerializeSMqHbRsp(void *buf, int32_t bufLen, SMqHbRsp *pRsp) {
|
||||||
|
@ -6250,13 +6249,12 @@ int32_t tDeserializeSMqHbRsp(void *buf, int32_t bufLen, SMqHbRsp *pRsp) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tDeatroySMqHbReq(SMqHbReq *pReq) {
|
void tDestroySMqHbReq(SMqHbReq *pReq) {
|
||||||
for (int i = 0; i < taosArrayGetSize(pReq->topics); i++) {
|
for (int i = 0; i < taosArrayGetSize(pReq->topics); i++) {
|
||||||
TopicOffsetRows *vgs = taosArrayGet(pReq->topics, i);
|
TopicOffsetRows *vgs = taosArrayGet(pReq->topics, i);
|
||||||
if (vgs) taosArrayDestroy(vgs->offsetRows);
|
if (vgs) taosArrayDestroy(vgs->offsetRows);
|
||||||
}
|
}
|
||||||
taosArrayDestroy(pReq->topics);
|
taosArrayDestroy(pReq->topics);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tSerializeSMqHbReq(void *buf, int32_t bufLen, SMqHbReq *pReq) {
|
int32_t tSerializeSMqHbReq(void *buf, int32_t bufLen, SMqHbReq *pReq) {
|
||||||
|
|
|
@ -24,27 +24,22 @@ extern "C" {
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MQ_CONSUMER_STATUS_REBALANCE = 1,
|
MQ_CONSUMER_STATUS_REBALANCE = 1,
|
||||||
// MQ_CONSUMER_STATUS__MODIFY_IN_REB, // this value is not used anymore
|
|
||||||
MQ_CONSUMER_STATUS_READY,
|
MQ_CONSUMER_STATUS_READY,
|
||||||
MQ_CONSUMER_STATUS_LOST,
|
MQ_CONSUMER_STATUS_LOST,
|
||||||
// MQ_CONSUMER_STATUS__LOST_IN_REB, // this value is not used anymore
|
};
|
||||||
// MQ_CONSUMER_STATUS__LOST_REBD,
|
|
||||||
};\
|
|
||||||
|
|
||||||
int32_t mndInitConsumer(SMnode *pMnode);
|
int32_t mndInitConsumer(SMnode *pMnode);
|
||||||
void mndCleanupConsumer(SMnode *pMnode);
|
void mndCleanupConsumer(SMnode *pMnode);
|
||||||
void mndDropConsumerFromSdb(SMnode *pMnode, int64_t consumerId, SRpcHandleInfo* info);
|
void mndSendConsumerMsg(SMnode *pMnode, int64_t consumerId, uint16_t msgType, SRpcHandleInfo* info);
|
||||||
|
|
||||||
SMqConsumerObj *mndAcquireConsumer(SMnode *pMnode, int64_t consumerId);
|
SMqConsumerObj *mndAcquireConsumer(SMnode *pMnode, int64_t consumerId);
|
||||||
void mndReleaseConsumer(SMnode *pMnode, SMqConsumerObj *pConsumer);
|
void mndReleaseConsumer(SMnode *pMnode, SMqConsumerObj *pConsumer);
|
||||||
|
|
||||||
SMqConsumerObj *mndCreateConsumer(int64_t consumerId, const char *cgroup);
|
|
||||||
|
|
||||||
SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer);
|
SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer);
|
||||||
SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw);
|
SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw);
|
||||||
|
|
||||||
int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer);
|
int32_t mndSetConsumerCommitLogs(STrans *pTrans, SMqConsumerObj *pConsumer);
|
||||||
int32_t mndSetConsumerDropLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer);
|
int32_t mndSetConsumerDropLogs(STrans *pTrans, SMqConsumerObj *pConsumer);
|
||||||
|
|
||||||
const char *mndConsumerStatusName(int status);
|
const char *mndConsumerStatusName(int status);
|
||||||
|
|
||||||
|
|
|
@ -149,6 +149,7 @@ typedef enum {
|
||||||
CONSUMER_REMOVE_REB, // remove after rebalance
|
CONSUMER_REMOVE_REB, // remove after rebalance
|
||||||
CONSUMER_UPDATE_REC, // update after recover
|
CONSUMER_UPDATE_REC, // update after recover
|
||||||
CONSUMER_UPDATE_SUB, // update after subscribe req
|
CONSUMER_UPDATE_SUB, // update after subscribe req
|
||||||
|
CONSUMER_INSERT_SUB,
|
||||||
} ECsmUpdateType;
|
} ECsmUpdateType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -556,8 +557,9 @@ typedef struct {
|
||||||
int32_t resetOffsetCfg;
|
int32_t resetOffsetCfg;
|
||||||
} SMqConsumerObj;
|
} SMqConsumerObj;
|
||||||
|
|
||||||
SMqConsumerObj* tNewSMqConsumerObj(int64_t consumerId, char cgroup[TSDB_CGROUP_LEN]);
|
SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType, char *topic, SCMSubscribeReq *subscribe);
|
||||||
void tDeleteSMqConsumerObj(SMqConsumerObj* pConsumer, bool isDeleted);
|
void tClearSMqConsumerObj(SMqConsumerObj* pConsumer);
|
||||||
|
void tDeleteSMqConsumerObj(SMqConsumerObj* pConsumer);
|
||||||
int32_t tEncodeSMqConsumerObj(void** buf, const SMqConsumerObj* pConsumer);
|
int32_t tEncodeSMqConsumerObj(void** buf, const SMqConsumerObj* pConsumer);
|
||||||
void* tDecodeSMqConsumerObj(const void* buf, SMqConsumerObj* pConsumer, int8_t sver);
|
void* tDecodeSMqConsumerObj(const void* buf, SMqConsumerObj* pConsumer, int8_t sver);
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ SMqSubscribeObj *mndAcquireSubscribe(SMnode *pMnode, const char *CGroup, const c
|
||||||
SMqSubscribeObj *mndAcquireSubscribeByKey(SMnode *pMnode, const char *key);
|
SMqSubscribeObj *mndAcquireSubscribeByKey(SMnode *pMnode, const char *key);
|
||||||
void mndReleaseSubscribe(SMnode *pMnode, SMqSubscribeObj *pSub);
|
void mndReleaseSubscribe(SMnode *pMnode, SMqSubscribeObj *pSub);
|
||||||
|
|
||||||
int32_t mndMakeSubscribeKey(char *key, const char *cgroup, const char *topicName);
|
void mndMakeSubscribeKey(char *key, const char *cgroup, const char *topicName);
|
||||||
|
|
||||||
int32_t mndDropSubByTopic(SMnode *pMnode, STrans *pTrans, const char *topic);
|
int32_t mndDropSubByTopic(SMnode *pMnode, STrans *pTrans, const char *topic);
|
||||||
int32_t mndSetDropSubCommitLogs(SMnode *pMnode, STrans *pTrans, SMqSubscribeObj *pSub);
|
int32_t mndSetDropSubCommitLogs(SMnode *pMnode, STrans *pTrans, SMqSubscribeObj *pSub);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -249,7 +249,9 @@ void *tDecodeSMqVgEp(const void *buf, SMqVgEp *pVgEp, int8_t sver) {
|
||||||
return (void *)buf;
|
return (void *)buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char *cgroup) {
|
static void *topicNameDup(void *p) { return taosStrdup((char *)p); }
|
||||||
|
|
||||||
|
SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType, char *topic, SCMSubscribeReq *subscribe) {
|
||||||
SMqConsumerObj *pConsumer = taosMemoryCalloc(1, sizeof(SMqConsumerObj));
|
SMqConsumerObj *pConsumer = taosMemoryCalloc(1, sizeof(SMqConsumerObj));
|
||||||
if (pConsumer == NULL) {
|
if (pConsumer == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -264,36 +266,64 @@ SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char *cgroup) {
|
||||||
pConsumer->hbStatus = 0;
|
pConsumer->hbStatus = 0;
|
||||||
|
|
||||||
taosInitRWLatch(&pConsumer->lock);
|
taosInitRWLatch(&pConsumer->lock);
|
||||||
|
pConsumer->createTime = taosGetTimestampMs();
|
||||||
|
pConsumer->updateType = updateType;
|
||||||
|
|
||||||
pConsumer->currentTopics = taosArrayInit(0, sizeof(void *));
|
if (updateType == CONSUMER_ADD_REB){
|
||||||
pConsumer->rebNewTopics = taosArrayInit(0, sizeof(void *));
|
pConsumer->rebNewTopics = taosArrayInit(0, sizeof(void *));
|
||||||
pConsumer->rebRemovedTopics = taosArrayInit(0, sizeof(void *));
|
if(pConsumer->rebNewTopics == NULL){
|
||||||
pConsumer->assignedTopics = taosArrayInit(0, sizeof(void *));
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
|
||||||
if (pConsumer->currentTopics == NULL || pConsumer->rebNewTopics == NULL || pConsumer->rebRemovedTopics == NULL ||
|
char* topicTmp = taosStrdup(topic);
|
||||||
pConsumer->assignedTopics == NULL) {
|
taosArrayPush(pConsumer->rebNewTopics, &topicTmp);
|
||||||
taosArrayDestroy(pConsumer->currentTopics);
|
}else if (updateType == CONSUMER_REMOVE_REB) {
|
||||||
taosArrayDestroy(pConsumer->rebNewTopics);
|
pConsumer->rebRemovedTopics = taosArrayInit(0, sizeof(void *));
|
||||||
taosArrayDestroy(pConsumer->rebRemovedTopics);
|
if(pConsumer->rebRemovedTopics == NULL){
|
||||||
taosArrayDestroy(pConsumer->assignedTopics);
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
taosMemoryFree(pConsumer);
|
goto END;
|
||||||
return NULL;
|
}
|
||||||
|
char* topicTmp = taosStrdup(topic);
|
||||||
|
taosArrayPush(pConsumer->rebRemovedTopics, &topicTmp);
|
||||||
|
}else if (updateType == CONSUMER_INSERT_SUB){
|
||||||
|
tstrncpy(pConsumer->clientId, subscribe->clientId, tListLen(pConsumer->clientId));
|
||||||
|
pConsumer->withTbName = subscribe->withTbName;
|
||||||
|
pConsumer->autoCommit = subscribe->autoCommit;
|
||||||
|
pConsumer->autoCommitInterval = subscribe->autoCommitInterval;
|
||||||
|
pConsumer->resetOffsetCfg = subscribe->resetOffsetCfg;
|
||||||
|
|
||||||
|
|
||||||
|
pConsumer->rebNewTopics = taosArrayDup(subscribe->topicNames, topicNameDup);
|
||||||
|
if (pConsumer->rebNewTopics == NULL){
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
pConsumer->assignedTopics = subscribe->topicNames;
|
||||||
|
subscribe->topicNames = NULL;
|
||||||
|
}else if (updateType == CONSUMER_UPDATE_SUB){
|
||||||
|
pConsumer->assignedTopics = subscribe->topicNames;
|
||||||
|
subscribe->topicNames = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pConsumer->createTime = taosGetTimestampMs();
|
|
||||||
|
|
||||||
return pConsumer;
|
return pConsumer;
|
||||||
|
|
||||||
|
END:
|
||||||
|
tDeleteSMqConsumerObj(pConsumer);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tDeleteSMqConsumerObj(SMqConsumerObj *pConsumer, bool delete) {
|
void tClearSMqConsumerObj(SMqConsumerObj *pConsumer) {
|
||||||
if (pConsumer == NULL) return;
|
if (pConsumer == NULL) return;
|
||||||
taosArrayDestroyP(pConsumer->currentTopics, (FDelete)taosMemoryFree);
|
taosArrayDestroyP(pConsumer->currentTopics, (FDelete)taosMemoryFree);
|
||||||
taosArrayDestroyP(pConsumer->rebNewTopics, (FDelete)taosMemoryFree);
|
taosArrayDestroyP(pConsumer->rebNewTopics, (FDelete)taosMemoryFree);
|
||||||
taosArrayDestroyP(pConsumer->rebRemovedTopics, (FDelete)taosMemoryFree);
|
taosArrayDestroyP(pConsumer->rebRemovedTopics, (FDelete)taosMemoryFree);
|
||||||
taosArrayDestroyP(pConsumer->assignedTopics, (FDelete)taosMemoryFree);
|
taosArrayDestroyP(pConsumer->assignedTopics, (FDelete)taosMemoryFree);
|
||||||
if (delete) {
|
}
|
||||||
taosMemoryFree(pConsumer);
|
|
||||||
}
|
void tDeleteSMqConsumerObj(SMqConsumerObj *pConsumer) {
|
||||||
|
tClearSMqConsumerObj(pConsumer);
|
||||||
|
taosMemoryFree(pConsumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
|
int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
|
||||||
|
@ -548,6 +578,7 @@ SMqSubscribeObj *tCloneSubscribeObj(const SMqSubscribeObj *pSub) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tDeleteSubscribeObj(SMqSubscribeObj *pSub) {
|
void tDeleteSubscribeObj(SMqSubscribeObj *pSub) {
|
||||||
|
if (pSub == NULL) return;
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
while (1) {
|
while (1) {
|
||||||
pIter = taosHashIterate(pSub->consumerHash, pIter);
|
pIter = taosHashIterate(pSub->consumerHash, pIter);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -353,6 +353,66 @@ static int32_t extractTopicTbInfo(SNode *pAst, SMqTopicObj *pTopic) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t sendCheckInfoToVnode(STrans *pTrans, SMnode *pMnode, SMqTopicObj *topicObj){
|
||||||
|
STqCheckInfo info;
|
||||||
|
memcpy(info.topic, topicObj->name, TSDB_TOPIC_FNAME_LEN);
|
||||||
|
info.ntbUid = topicObj->ntbUid;
|
||||||
|
info.colIdList = topicObj->ntbColIds;
|
||||||
|
// broadcast forbid alter info
|
||||||
|
void *pIter = NULL;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
SVgObj *pVgroup = NULL;
|
||||||
|
int32_t code = 0;
|
||||||
|
void *buf = NULL;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
// iterate vg
|
||||||
|
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
if (!mndVgroupInDb(pVgroup, topicObj->dbUid)) {
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// encoder check alter info
|
||||||
|
int32_t len;
|
||||||
|
tEncodeSize(tEncodeSTqCheckInfo, &info, len, code);
|
||||||
|
if (code != 0) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
buf = taosMemoryCalloc(1, sizeof(SMsgHead) + len);
|
||||||
|
void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||||
|
SEncoder encoder;
|
||||||
|
tEncoderInit(&encoder, abuf, len);
|
||||||
|
code = tEncodeSTqCheckInfo(&encoder, &info);
|
||||||
|
if (code < 0) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
tEncoderClear(&encoder);
|
||||||
|
((SMsgHead *)buf)->vgId = htonl(pVgroup->vgId);
|
||||||
|
// add redo action
|
||||||
|
STransAction action = {0};
|
||||||
|
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
|
action.pCont = buf;
|
||||||
|
action.contLen = sizeof(SMsgHead) + len;
|
||||||
|
action.msgType = TDMT_VND_TMQ_ADD_CHECKINFO;
|
||||||
|
code = mndTransAppendRedoAction(pTrans, &action);
|
||||||
|
if (code != 0) {
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
buf = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
END:
|
||||||
|
taosMemoryFree(buf);
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
sdbCancelFetch(pSdb, pIter);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *pCreate, SDbObj *pDb,
|
static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *pCreate, SDbObj *pDb,
|
||||||
const char *userName) {
|
const char *userName) {
|
||||||
mInfo("start to create topic:%s", pCreate->name);
|
mInfo("start to create topic:%s", pCreate->name);
|
||||||
|
@ -396,13 +456,6 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
|
||||||
topicObj.withMeta = pCreate->withMeta;
|
topicObj.withMeta = pCreate->withMeta;
|
||||||
|
|
||||||
if (pCreate->subType == TOPIC_SUB_TYPE__COLUMN) {
|
if (pCreate->subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||||
if (pCreate->withMeta) {
|
|
||||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION;
|
|
||||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
|
||||||
code = terrno;
|
|
||||||
goto _OUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
topicObj.ast = taosStrdup(pCreate->ast);
|
topicObj.ast = taosStrdup(pCreate->ast);
|
||||||
topicObj.astLen = strlen(pCreate->ast) + 1;
|
topicObj.astLen = strlen(pCreate->ast) + 1;
|
||||||
|
|
||||||
|
@ -474,59 +527,9 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
|
||||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||||
|
|
||||||
if (topicObj.ntbUid != 0) {
|
if (topicObj.ntbUid != 0) {
|
||||||
STqCheckInfo info;
|
code = sendCheckInfoToVnode(pTrans, pMnode, &topicObj);
|
||||||
memcpy(info.topic, topicObj.name, TSDB_TOPIC_FNAME_LEN);
|
if (code != 0){
|
||||||
info.ntbUid = topicObj.ntbUid;
|
goto _OUT;
|
||||||
info.colIdList = topicObj.ntbColIds;
|
|
||||||
// broadcast forbid alter info
|
|
||||||
void *pIter = NULL;
|
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
|
||||||
SVgObj *pVgroup = NULL;
|
|
||||||
while (1) {
|
|
||||||
// iterate vg
|
|
||||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
|
||||||
if (pIter == NULL) break;
|
|
||||||
if (!mndVgroupInDb(pVgroup, topicObj.dbUid)) {
|
|
||||||
sdbRelease(pSdb, pVgroup);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// encoder check alter info
|
|
||||||
int32_t len;
|
|
||||||
tEncodeSize(tEncodeSTqCheckInfo, &info, len, code);
|
|
||||||
if (code < 0) {
|
|
||||||
sdbRelease(pSdb, pVgroup);
|
|
||||||
sdbCancelFetch(pSdb, pIter);
|
|
||||||
goto _OUT;
|
|
||||||
}
|
|
||||||
void *buf = taosMemoryCalloc(1, sizeof(SMsgHead) + len);
|
|
||||||
void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
|
||||||
SEncoder encoder;
|
|
||||||
tEncoderInit(&encoder, abuf, len);
|
|
||||||
if (tEncodeSTqCheckInfo(&encoder, &info) < 0) {
|
|
||||||
taosMemoryFree(buf);
|
|
||||||
sdbRelease(pSdb, pVgroup);
|
|
||||||
sdbCancelFetch(pSdb, pIter);
|
|
||||||
code = -1;
|
|
||||||
goto _OUT;
|
|
||||||
}
|
|
||||||
tEncoderClear(&encoder);
|
|
||||||
((SMsgHead *)buf)->vgId = htonl(pVgroup->vgId);
|
|
||||||
// add redo action
|
|
||||||
STransAction action = {0};
|
|
||||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
|
||||||
action.pCont = buf;
|
|
||||||
action.contLen = sizeof(SMsgHead) + len;
|
|
||||||
action.msgType = TDMT_VND_TMQ_ADD_CHECKINFO;
|
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
|
||||||
taosMemoryFree(buf);
|
|
||||||
sdbRelease(pSdb, pVgroup);
|
|
||||||
sdbCancelFetch(pSdb, pIter);
|
|
||||||
code = -1;
|
|
||||||
goto _OUT;
|
|
||||||
}
|
|
||||||
buf = NULL;
|
|
||||||
sdbRelease(pSdb, pVgroup);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,7 +621,7 @@ static int32_t mndProcessCreateTopicReq(SRpcMsg *pReq) {
|
||||||
tNameFromString(&topicName, createTopicReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
tNameFromString(&topicName, createTopicReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||||
//reuse this function for topic
|
//reuse this function for topic
|
||||||
|
|
||||||
auditRecord(pReq, pMnode->clusterId, "createTopic", dbname.dbname, topicName.dbname,
|
auditRecord(pReq, pMnode->clusterId, "createTopic", dbname.dbname, topicName.dbname,
|
||||||
createTopicReq.sql, strlen(createTopicReq.sql));
|
createTopicReq.sql, strlen(createTopicReq.sql));
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
|
@ -653,9 +656,104 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool checkTopic(SArray *topics, char *topicName){
|
||||||
|
int32_t sz = taosArrayGetSize(topics);
|
||||||
|
for (int32_t i = 0; i < sz; i++) {
|
||||||
|
char *name = taosArrayGetP(topics, i);
|
||||||
|
if (strcmp(name, topicName) == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndDropConsumerByTopic(SMnode *pMnode, STrans *pTrans, char *topicName){
|
||||||
|
int32_t code = 0;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
void *pIter = NULL;
|
||||||
|
SMqConsumerObj *pConsumer = NULL;
|
||||||
|
while (1) {
|
||||||
|
pIter = sdbFetch(pSdb, SDB_CONSUMER, pIter, (void **)&pConsumer);
|
||||||
|
if (pIter == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool found = checkTopic(pConsumer->assignedTopics, topicName);
|
||||||
|
if (found){
|
||||||
|
if (pConsumer->status == MQ_CONSUMER_STATUS_LOST) {
|
||||||
|
code = mndSetConsumerDropLogs(pTrans, pConsumer);
|
||||||
|
if (code != 0) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
sdbRelease(pSdb, pConsumer);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
mError("topic:%s, failed to drop since subscribed by consumer:0x%" PRIx64 ", in consumer group %s",
|
||||||
|
topicName, pConsumer->consumerId, pConsumer->cgroup);
|
||||||
|
code = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkTopic(pConsumer->rebNewTopics, topicName) || checkTopic(pConsumer->rebRemovedTopics, topicName)) {
|
||||||
|
code = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
||||||
|
mError("topic:%s, failed to drop since subscribed by consumer:%" PRId64 ", in consumer group %s (reb new)",
|
||||||
|
topicName, pConsumer->consumerId, pConsumer->cgroup);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
sdbRelease(pSdb, pConsumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
sdbRelease(pSdb, pConsumer);
|
||||||
|
sdbCancelFetch(pSdb, pIter);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndDropCheckInfoByTopic(SMnode *pMnode, STrans *pTrans, SMqTopicObj *pTopic){
|
||||||
|
// broadcast to all vnode
|
||||||
|
void *pIter = NULL;
|
||||||
|
SVgObj *pVgroup = NULL;
|
||||||
|
int32_t code = 0;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
void *buf = NULL;
|
||||||
|
while (1) {
|
||||||
|
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
if (!mndVgroupInDb(pVgroup, pTopic->dbUid)) {
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = taosMemoryCalloc(1, sizeof(SMsgHead) + TSDB_TOPIC_FNAME_LEN);
|
||||||
|
if (buf == NULL){
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||||
|
((SMsgHead *)buf)->vgId = htonl(pVgroup->vgId);
|
||||||
|
memcpy(abuf, pTopic->name, TSDB_TOPIC_FNAME_LEN);
|
||||||
|
|
||||||
|
STransAction action = {0};
|
||||||
|
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
|
action.pCont = buf;
|
||||||
|
action.contLen = sizeof(SMsgHead) + TSDB_TOPIC_FNAME_LEN;
|
||||||
|
action.msgType = TDMT_VND_TMQ_DEL_CHECKINFO;
|
||||||
|
code = mndTransAppendRedoAction(pTrans, &action);
|
||||||
|
if (code != 0) {
|
||||||
|
taosMemoryFree(buf);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
sdbCancelFetch(pSdb, pIter);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
|
||||||
SMDropTopicReq dropReq = {0};
|
SMDropTopicReq dropReq = {0};
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SMqTopicObj *pTopic = NULL;
|
SMqTopicObj *pTopic = NULL;
|
||||||
|
@ -705,68 +803,9 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *pIter = NULL;
|
code = mndDropConsumerByTopic(pMnode, pTrans, dropReq.name);
|
||||||
SMqConsumerObj *pConsumer;
|
if (code != 0) {
|
||||||
while (1) {
|
goto end;
|
||||||
pIter = sdbFetch(pSdb, SDB_CONSUMER, pIter, (void **)&pConsumer);
|
|
||||||
if (pIter == NULL) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool found = false;
|
|
||||||
int32_t sz = taosArrayGetSize(pConsumer->assignedTopics);
|
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
|
||||||
char *name = taosArrayGetP(pConsumer->assignedTopics, i);
|
|
||||||
if (strcmp(name, pTopic->name) == 0) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found){
|
|
||||||
if (pConsumer->status == MQ_CONSUMER_STATUS_LOST) {
|
|
||||||
mndDropConsumerFromSdb(pMnode, pConsumer->consumerId, &pReq->info);
|
|
||||||
mndReleaseConsumer(pMnode, pConsumer);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
mndReleaseConsumer(pMnode, pConsumer);
|
|
||||||
sdbCancelFetch(pSdb, pIter);
|
|
||||||
terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
|
||||||
mError("topic:%s, failed to drop since subscribed by consumer:0x%" PRIx64 ", in consumer group %s",
|
|
||||||
dropReq.name, pConsumer->consumerId, pConsumer->cgroup);
|
|
||||||
code = -1;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
sz = taosArrayGetSize(pConsumer->rebNewTopics);
|
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
|
||||||
char *name = taosArrayGetP(pConsumer->rebNewTopics, i);
|
|
||||||
if (strcmp(name, pTopic->name) == 0) {
|
|
||||||
mndReleaseConsumer(pMnode, pConsumer);
|
|
||||||
sdbCancelFetch(pSdb, pIter);
|
|
||||||
terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
|
||||||
mError("topic:%s, failed to drop since subscribed by consumer:%" PRId64 ", in consumer group %s (reb new)",
|
|
||||||
dropReq.name, pConsumer->consumerId, pConsumer->cgroup);
|
|
||||||
code = -1;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sz = taosArrayGetSize(pConsumer->rebRemovedTopics);
|
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
|
||||||
char *name = taosArrayGetP(pConsumer->rebRemovedTopics, i);
|
|
||||||
if (strcmp(name, pTopic->name) == 0) {
|
|
||||||
mndReleaseConsumer(pMnode, pConsumer);
|
|
||||||
sdbCancelFetch(pSdb, pIter);
|
|
||||||
terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
|
||||||
mError("topic:%s, failed to drop since subscribed by consumer:%" PRId64 ", in consumer group %s (reb remove)",
|
|
||||||
dropReq.name, pConsumer->consumerId, pConsumer->cgroup);
|
|
||||||
code = -1;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sdbRelease(pSdb, pConsumer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
code = mndDropSubByTopic(pMnode, pTrans, dropReq.name);
|
code = mndDropSubByTopic(pMnode, pTrans, dropReq.name);
|
||||||
|
@ -776,36 +815,9 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTopic->ntbUid != 0) {
|
if (pTopic->ntbUid != 0) {
|
||||||
// broadcast to all vnode
|
code = mndDropCheckInfoByTopic(pMnode, pTrans, pTopic);
|
||||||
pIter = NULL;
|
if (code != 0) {
|
||||||
SVgObj *pVgroup = NULL;
|
goto end;
|
||||||
|
|
||||||
while (1) {
|
|
||||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
|
||||||
if (pIter == NULL) break;
|
|
||||||
if (!mndVgroupInDb(pVgroup, pTopic->dbUid)) {
|
|
||||||
sdbRelease(pSdb, pVgroup);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *buf = taosMemoryCalloc(1, sizeof(SMsgHead) + TSDB_TOPIC_FNAME_LEN);
|
|
||||||
void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
|
||||||
((SMsgHead *)buf)->vgId = htonl(pVgroup->vgId);
|
|
||||||
memcpy(abuf, pTopic->name, TSDB_TOPIC_FNAME_LEN);
|
|
||||||
|
|
||||||
STransAction action = {0};
|
|
||||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
|
||||||
action.pCont = buf;
|
|
||||||
action.contLen = sizeof(SMsgHead) + TSDB_TOPIC_FNAME_LEN;
|
|
||||||
action.msgType = TDMT_VND_TMQ_DEL_CHECKINFO;
|
|
||||||
code = mndTransAppendRedoAction(pTrans, &action);
|
|
||||||
if (code != 0) {
|
|
||||||
taosMemoryFree(buf);
|
|
||||||
sdbRelease(pSdb, pVgroup);
|
|
||||||
sdbCancelFetch(pSdb, pIter);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
sdbRelease(pSdb, pVgroup);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -822,7 +834,6 @@ end:
|
||||||
|
|
||||||
SName name = {0};
|
SName name = {0};
|
||||||
tNameFromString(&name, dropReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
tNameFromString(&name, dropReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||||
//reuse this function for topic
|
|
||||||
|
|
||||||
auditRecord(pReq, pMnode->clusterId, "dropTopic", name.dbname, name.tname, dropReq.sql, dropReq.sqlLen);
|
auditRecord(pReq, pMnode->clusterId, "dropTopic", name.dbname, name.tname, dropReq.sql, dropReq.sqlLen);
|
||||||
|
|
||||||
|
|
|
@ -88,10 +88,6 @@ int32_t tqMetaOpen(STQ* pTq) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (tqMetaRestoreHandle(pTq) < 0) {
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (tqMetaRestoreCheckInfo(pTq) < 0) {
|
if (tqMetaRestoreCheckInfo(pTq) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -167,32 +163,30 @@ int32_t tqMetaRestoreCheckInfo(STQ* pTq) {
|
||||||
void* pVal = NULL;
|
void* pVal = NULL;
|
||||||
int vLen = 0;
|
int vLen = 0;
|
||||||
SDecoder decoder;
|
SDecoder decoder;
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
tdbTbcMoveToFirst(pCur);
|
tdbTbcMoveToFirst(pCur);
|
||||||
|
|
||||||
while (tdbTbcNext(pCur, &pKey, &kLen, &pVal, &vLen) == 0) {
|
while (tdbTbcNext(pCur, &pKey, &kLen, &pVal, &vLen) == 0) {
|
||||||
STqCheckInfo info;
|
STqCheckInfo info;
|
||||||
tDecoderInit(&decoder, (uint8_t*)pVal, vLen);
|
tDecoderInit(&decoder, (uint8_t*)pVal, vLen);
|
||||||
if (tDecodeSTqCheckInfo(&decoder, &info) < 0) {
|
code = tDecodeSTqCheckInfo(&decoder, &info);
|
||||||
|
if (code != 0) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
tdbFree(pKey);
|
goto END;
|
||||||
tdbFree(pVal);
|
|
||||||
tdbTbcClose(pCur);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
tDecoderClear(&decoder);
|
tDecoderClear(&decoder);
|
||||||
if (taosHashPut(pTq->pCheckInfo, info.topic, strlen(info.topic), &info, sizeof(STqCheckInfo)) < 0) {
|
code = taosHashPut(pTq->pCheckInfo, info.topic, strlen(info.topic), &info, sizeof(STqCheckInfo));
|
||||||
|
if (code != 0) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
tdbFree(pKey);
|
goto END;
|
||||||
tdbFree(pVal);
|
|
||||||
tdbTbcClose(pCur);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
END:
|
||||||
tdbFree(pKey);
|
tdbFree(pKey);
|
||||||
tdbFree(pVal);
|
tdbFree(pVal);
|
||||||
tdbTbcClose(pCur);
|
tdbTbcClose(pCur);
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle) {
|
int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle) {
|
||||||
|
|
Loading…
Reference in New Issue