From cad3b55a43504c8174af538342256e36dbf003de Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 26 May 2021 19:10:29 +0800 Subject: [PATCH] [TD-3178] fix some bug --- src/client/src/tscSQLParser.c | 1 - src/client/src/tscServer.c | 4 ++-- src/dnode/src/dnodeShell.c | 1 + src/mnode/src/mnodeDb.c | 32 +++++++++++++++++++++----------- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 3bc7377267..37dccba175 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2798,7 +2798,6 @@ int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killType) { } static int32_t setCompactVnodeInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { SSqlCmd* pCmd = &pSql->cmd; - //STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); pCmd->command = pInfo->type; return TSDB_CODE_SUCCESS; diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 180dae0afb..1c9b29ccf7 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1575,7 +1575,7 @@ int tscBuildCompactMsg(SSqlObj *pSql, SSqlInfo *pInfo) { for (int32_t i = 0; i < size; i++) { tSqlExprItem* pSub = taosArrayGet(pList, i); tVariant* pVar = &pSub->pNode->value; - if (pVar->nType >= TSDB_DATA_TYPE_TINYINT && pVar->nType <= TSDB_DATA_TYPE_INT) { + if (pVar->nType >= TSDB_DATA_TYPE_TINYINT && pVar->nType <= TSDB_DATA_TYPE_BIGINT) { result[i] = (int32_t)(pVar->i64); } else { free(result); @@ -1603,7 +1603,7 @@ int tscBuildCompactMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } else { tNameGetFullDbName(&pTableMetaInfo->name, pCompactMsg->db); } - + pCompactMsg->numOfVgroup = htons(count); for (int32_t i = 0; i < count; i++) { pCompactMsg->vgid[i] = htons(result[i]); diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index 50343cfd32..c80e1059b4 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -61,6 +61,7 @@ int32_t dnodeInitShell() { dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_KILL_STREAM] = dnodeDispatchToMWriteQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_KILL_CONN] = dnodeDispatchToMWriteQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_CONFIG_DNODE]= dnodeDispatchToMWriteQueue; + dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_COMPACT_VNODE]= dnodeDispatchToMWriteQueue; // the following message shall be treated as mnode query dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_HEARTBEAT] = dnodeDispatchToMReadQueue; diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 9e064a2f9e..3c78a0e33d 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -1226,25 +1226,34 @@ static int32_t mnodeSyncDb(SDbObj *pDb, SMnodeMsg *pMsg) { static int32_t mnodeCompact(SDbObj *pDb, SCompactMsg *pCompactMsg) { - int32_t count = htonl(pCompactMsg->numOfVgroup); - int32_t *buf = malloc(sizeof(int32_t) * count); + int32_t count = ntohs(pCompactMsg->numOfVgroup); + int32_t *buf = malloc(sizeof(int32_t) * count); if (buf == NULL) { return TSDB_CODE_MND_OUT_OF_MEMORY; } for (int32_t i = 0; i < count; i++) { - buf[i] = htonl(pCompactMsg->vgid[i]); + buf[i] = ntohs(pCompactMsg->vgid[i]); } // copy from mnodeSyncDb, so ugly - void *pIter = NULL; - SVgObj *pVgroup = NULL; - while (1) { - pIter = mnodeGetNextVgroup(pIter, &pVgroup); - if (pVgroup == NULL) break; - if (pVgroup->pDb == pDb) { - mnodeSendCompactVgroupMsg(pVgroup); + for (int32_t i = 0; i < count; i++) { + SVgObj *pVgroup = NULL; + void *pIter = NULL; + bool valid = false; + while (1) { + pIter = mnodeGetNextVgroup(pIter, &pVgroup); + if (pVgroup == NULL) break; + if (pVgroup->pDb == pDb && pVgroup->vgId == buf[i]) { + mnodeSendCompactVgroupMsg(pVgroup); + mnodeDecVgroupRef(pVgroup); + valid = true; + break; + } + mnodeDecVgroupRef(pVgroup); + } + if (valid == false) { + mLError("db:%s, cannot find valid vgId: %d", pDb->name, buf[i]); } - mnodeDecVgroupRef(pVgroup); } free(buf); @@ -1279,6 +1288,7 @@ static int32_t mnodeProcessCompactMsg(SMnodeMsg *pMsg) { mDebug("db:%s, compact is received from thandle:%p", pCompact->db, pMsg->rpcMsg.handle); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pCompact->db); + if (pMsg->pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED; if (pMsg->pDb->status != TSDB_DB_STATUS_READY) { mError("db:%s, status:%d, in dropping, ignore compact request", pCompact->db, pMsg->pDb->status); -- GitLab