TDengine/source/dnode/mnode/impl/src/mndCluster.c

442 lines
14 KiB
C
Raw Normal View History

2021-09-22 08:15:20 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2021-10-16 07:16:05 +00:00
#define _DEFAULT_SOURCE
2023-12-18 08:34:31 +00:00
#include "audit.h"
2021-12-02 03:22:03 +00:00
#include "mndCluster.h"
2024-01-19 06:59:02 +00:00
#include "mndGrant.h"
2023-12-18 08:34:31 +00:00
#include "mndPrivilege.h"
2021-12-02 11:56:43 +00:00
#include "mndShow.h"
#include "mndTrans.h"
2021-10-17 03:42:05 +00:00
2024-01-22 05:20:15 +00:00
#define CLUSTER_VER_NUMBE 1
2023-11-30 05:39:54 +00:00
#define CLUSTER_RESERVE_SIZE 60
2023-01-09 08:49:58 +00:00
int64_t tsExpireTime = 0;
2021-12-02 03:22:03 +00:00
2021-12-06 10:21:14 +00:00
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster);
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw);
static int32_t mndClusterActionInsert(SSdb *pSdb, SClusterObj *pCluster);
static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster);
2021-12-07 13:10:36 +00:00
static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOldCluster, SClusterObj *pNewCluster);
2021-12-06 10:21:14 +00:00
static int32_t mndCreateDefaultCluster(SMnode *pMnode);
2022-05-16 06:55:31 +00:00
static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
2021-12-06 10:21:14 +00:00
static void mndCancelGetNextCluster(SMnode *pMnode, void *pIter);
2022-08-23 09:29:31 +00:00
static int32_t mndProcessUptimeTimer(SRpcMsg *pReq);
2024-01-19 06:59:02 +00:00
static int32_t mndProcessConfigClusterReq(SRpcMsg *pReq);
static int32_t mndProcessConfigClusterRsp(SRpcMsg *pReq);
2021-12-06 10:21:14 +00:00
int32_t mndInitCluster(SMnode *pMnode) {
2022-05-07 01:23:06 +00:00
SSdbTable table = {
.sdbType = SDB_CLUSTER,
.keyType = SDB_KEY_INT64,
.deployFp = (SdbDeployFp)mndCreateDefaultCluster,
.encodeFp = (SdbEncodeFp)mndClusterActionEncode,
.decodeFp = (SdbDecodeFp)mndClusterActionDecode,
.insertFp = (SdbInsertFp)mndClusterActionInsert,
.updateFp = (SdbUpdateFp)mndClusterActionUpdate,
.deleteFp = (SdbDeleteFp)mndClusterActionDelete,
};
2021-12-06 10:21:14 +00:00
2022-08-23 09:29:31 +00:00
mndSetMsgHandle(pMnode, TDMT_MND_UPTIME_TIMER, mndProcessUptimeTimer);
2024-01-19 06:59:02 +00:00
mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_CLUSTER, mndProcessConfigClusterReq);
mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_CLUSTER_RSP, mndProcessConfigClusterRsp);
2021-12-06 10:21:14 +00:00
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndRetrieveClusters);
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndCancelGetNextCluster);
2022-08-23 09:29:31 +00:00
2021-12-06 10:21:14 +00:00
return sdbSetTable(pMnode->pSdb, table);
}
void mndCleanupCluster(SMnode *pMnode) {}
2021-12-06 11:57:13 +00:00
int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) {
SSdb *pSdb = pMnode->pSdb;
SClusterObj *pCluster = sdbAcquire(pSdb, SDB_CLUSTER, &pMnode->clusterId);
2022-02-18 13:24:45 +00:00
if (pCluster == NULL) {
2021-12-06 11:57:13 +00:00
return -1;
}
tstrncpy(clusterName, pCluster->name, len);
sdbRelease(pSdb, pCluster);
return 0;
}
2023-04-10 08:52:41 +00:00
static SClusterObj *mndAcquireCluster(SMnode *pMnode, void **ppIter) {
2022-08-23 09:29:31 +00:00
SSdb *pSdb = pMnode->pSdb;
void *pIter = NULL;
2022-04-01 08:36:36 +00:00
while (1) {
SClusterObj *pCluster = NULL;
pIter = sdbFetch(pSdb, SDB_CLUSTER, pIter, (void **)&pCluster);
if (pIter == NULL) break;
2023-04-10 08:52:41 +00:00
*ppIter = pIter;
2022-08-23 09:29:31 +00:00
return pCluster;
}
return NULL;
}
2023-04-10 08:52:41 +00:00
static void mndReleaseCluster(SMnode *pMnode, SClusterObj *pCluster, void *pIter) {
2022-08-23 09:29:31 +00:00
SSdb *pSdb = pMnode->pSdb;
2023-04-10 08:52:41 +00:00
sdbCancelFetch(pSdb, pIter);
2022-08-23 09:29:31 +00:00
sdbRelease(pSdb, pCluster);
}
int64_t mndGetClusterId(SMnode *pMnode) {
int64_t clusterId = 0;
2023-04-10 08:52:41 +00:00
void *pIter = NULL;
SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
2022-08-23 09:29:31 +00:00
if (pCluster != NULL) {
2022-04-01 08:36:36 +00:00
clusterId = pCluster->id;
2023-04-10 08:52:41 +00:00
mndReleaseCluster(pMnode, pCluster, pIter);
2022-04-01 08:36:36 +00:00
}
return clusterId;
}
2022-07-11 09:19:54 +00:00
int64_t mndGetClusterCreateTime(SMnode *pMnode) {
2022-08-23 09:29:31 +00:00
int64_t createTime = 0;
2023-04-10 11:12:13 +00:00
void *pIter = NULL;
SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
2022-08-23 09:29:31 +00:00
if (pCluster != NULL) {
2022-07-11 09:19:54 +00:00
createTime = pCluster->createdTime;
2023-04-10 11:12:13 +00:00
mndReleaseCluster(pMnode, pCluster, pIter);
2022-07-11 09:19:54 +00:00
}
return createTime;
}
2022-08-23 09:29:31 +00:00
static int32_t mndGetClusterUpTimeImp(SClusterObj *pCluster) {
#if 0
int32_t upTime = taosGetTimestampSec() - pCluster->updateTime / 1000;
upTime = upTime + pCluster->upTime;
return upTime;
#else
return pCluster->upTime;
#endif
}
2023-07-20 02:56:08 +00:00
int64_t mndGetClusterUpTime(SMnode *pMnode) {
2022-08-23 09:29:31 +00:00
int64_t upTime = 0;
2023-04-10 08:52:41 +00:00
void *pIter = NULL;
SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
2022-08-23 09:29:31 +00:00
if (pCluster != NULL) {
upTime = mndGetClusterUpTimeImp(pCluster);
2023-04-10 08:52:41 +00:00
mndReleaseCluster(pMnode, pCluster, pIter);
2022-08-23 09:29:31 +00:00
}
2023-07-20 02:56:08 +00:00
return upTime;
2022-08-23 09:29:31 +00:00
}
2021-12-02 03:22:03 +00:00
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) {
2021-12-31 06:22:50 +00:00
terrno = TSDB_CODE_OUT_OF_MEMORY;
2023-12-07 06:11:41 +00:00
SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, CLUSTER_VER_NUMBE, sizeof(SClusterObj) + CLUSTER_RESERVE_SIZE);
2022-05-07 01:23:06 +00:00
if (pRaw == NULL) goto _OVER;
2021-12-02 03:22:03 +00:00
int32_t dataPos = 0;
2022-05-07 01:23:06 +00:00
SDB_SET_INT64(pRaw, dataPos, pCluster->id, _OVER)
SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime, _OVER)
SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime, _OVER)
SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, _OVER)
2022-08-23 09:29:31 +00:00
SDB_SET_INT32(pRaw, dataPos, pCluster->upTime, _OVER)
2022-05-07 01:23:06 +00:00
SDB_SET_RESERVE(pRaw, dataPos, CLUSTER_RESERVE_SIZE, _OVER)
2023-12-01 10:15:47 +00:00
SDB_SET_DATALEN(pRaw, dataPos, _OVER);
2021-12-31 06:22:50 +00:00
terrno = 0;
2022-05-07 01:23:06 +00:00
_OVER:
2021-12-31 06:22:50 +00:00
if (terrno != 0) {
mError("cluster:%" PRId64 ", failed to encode to raw:%p since %s", pCluster->id, pRaw, terrstr());
sdbFreeRaw(pRaw);
return NULL;
}
2021-12-02 03:22:03 +00:00
2021-12-31 06:22:50 +00:00
mTrace("cluster:%" PRId64 ", encode to raw:%p, row:%p", pCluster->id, pRaw, pCluster);
2021-12-02 03:22:03 +00:00
return pRaw;
}
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
2021-12-31 06:22:50 +00:00
terrno = TSDB_CODE_OUT_OF_MEMORY;
2022-12-01 08:04:39 +00:00
SClusterObj *pCluster = NULL;
2023-12-01 10:15:47 +00:00
SSdbRow *pRow = NULL;
2021-12-31 06:22:50 +00:00
2021-12-02 03:22:03 +00:00
int8_t sver = 0;
2022-05-07 01:23:06 +00:00
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
2021-12-02 03:22:03 +00:00
2024-01-22 05:20:15 +00:00
if (sver != CLUSTER_VER_NUMBE) {
2021-12-02 03:22:03 +00:00
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
2022-05-07 01:23:06 +00:00
goto _OVER;
2021-12-02 03:22:03 +00:00
}
2022-12-01 08:04:39 +00:00
pRow = sdbAllocRow(sizeof(SClusterObj));
2022-05-07 01:23:06 +00:00
if (pRow == NULL) goto _OVER;
2021-12-31 06:22:50 +00:00
2022-12-01 08:04:39 +00:00
pCluster = sdbGetRowObj(pRow);
2022-05-07 01:23:06 +00:00
if (pCluster == NULL) goto _OVER;
2021-12-02 03:22:03 +00:00
int32_t dataPos = 0;
2022-05-07 01:23:06 +00:00
SDB_GET_INT64(pRaw, dataPos, &pCluster->id, _OVER)
SDB_GET_INT64(pRaw, dataPos, &pCluster->createdTime, _OVER)
SDB_GET_INT64(pRaw, dataPos, &pCluster->updateTime, _OVER)
SDB_GET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, _OVER)
2022-08-23 09:29:31 +00:00
SDB_GET_INT32(pRaw, dataPos, &pCluster->upTime, _OVER)
2022-05-07 01:23:06 +00:00
SDB_GET_RESERVE(pRaw, dataPos, CLUSTER_RESERVE_SIZE, _OVER)
2021-12-31 06:22:50 +00:00
terrno = 0;
2022-05-07 01:23:06 +00:00
_OVER:
2021-12-31 06:22:50 +00:00
if (terrno != 0) {
2022-12-01 08:04:39 +00:00
mError("cluster:%" PRId64 ", failed to decode from raw:%p since %s", pCluster == NULL ? 0 : pCluster->id, pRaw,
terrstr());
2022-03-25 16:29:53 +00:00
taosMemoryFreeClear(pRow);
2021-12-31 06:22:50 +00:00
return NULL;
}
2021-12-02 03:22:03 +00:00
2021-12-31 06:22:50 +00:00
mTrace("cluster:%" PRId64 ", decode from raw:%p, row:%p", pCluster->id, pRaw, pCluster);
2021-12-02 03:22:03 +00:00
return pRow;
}
static int32_t mndClusterActionInsert(SSdb *pSdb, SClusterObj *pCluster) {
2021-12-31 06:22:50 +00:00
mTrace("cluster:%" PRId64 ", perform insert action, row:%p", pCluster->id, pCluster);
2022-05-26 11:29:29 +00:00
pSdb->pMnode->clusterId = pCluster->id;
2022-08-23 09:29:31 +00:00
pCluster->updateTime = taosGetTimestampMs();
2021-12-02 03:22:03 +00:00
return 0;
}
static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster) {
2021-12-31 06:22:50 +00:00
mTrace("cluster:%" PRId64 ", perform delete action, row:%p", pCluster->id, pCluster);
2021-12-02 03:22:03 +00:00
return 0;
}
2021-12-31 06:22:50 +00:00
static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOld, SClusterObj *pNew) {
2022-08-23 09:29:31 +00:00
mTrace("cluster:%" PRId64 ", perform update action, old row:%p new row:%p, uptime from %d to %d", pOld->id, pOld,
pNew, pOld->upTime, pNew->upTime);
pOld->upTime = pNew->upTime;
pOld->updateTime = taosGetTimestampMs();
2021-12-02 03:22:03 +00:00
return 0;
}
static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
SClusterObj clusterObj = {0};
clusterObj.createdTime = taosGetTimestampMs();
clusterObj.updateTime = clusterObj.createdTime;
2022-01-04 08:21:32 +00:00
int32_t code = taosGetSystemUUID(clusterObj.name, TSDB_CLUSTER_ID_LEN);
2021-12-02 03:22:03 +00:00
if (code != 0) {
2022-05-07 01:23:06 +00:00
strcpy(clusterObj.name, "tdengine3.0");
2021-12-06 10:21:14 +00:00
mError("failed to get name from system, set to default val %s", clusterObj.name);
2021-12-02 03:22:03 +00:00
}
2021-12-30 11:33:05 +00:00
clusterObj.id = mndGenerateUid(clusterObj.name, TSDB_CLUSTER_ID_LEN);
2021-12-27 02:57:31 +00:00
clusterObj.id = (clusterObj.id >= 0 ? clusterObj.id : -clusterObj.id);
2021-12-31 02:52:10 +00:00
pMnode->clusterId = clusterObj.id;
mInfo("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name);
2021-12-02 03:22:03 +00:00
SSdbRaw *pRaw = mndClusterActionEncode(&clusterObj);
2023-12-07 06:11:41 +00:00
if (pRaw == NULL) return -1;
2022-10-08 09:06:29 +00:00
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
2021-12-02 03:22:03 +00:00
2022-09-23 07:42:36 +00:00
mInfo("cluster:%" PRId64 ", will be created when deploying, raw:%p", clusterObj.id, pRaw);
2022-09-22 08:18:51 +00:00
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-cluster");
if (pTrans == NULL) {
2022-09-30 03:26:26 +00:00
sdbFreeRaw(pRaw);
mError("cluster:%" PRId64 ", failed to create since %s", clusterObj.id, terrstr());
return -1;
}
2022-09-23 07:42:36 +00:00
mInfo("trans:%d, used to create cluster:%" PRId64, pTrans->id, clusterObj.id);
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) {
mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
2022-10-08 03:29:46 +00:00
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
if (mndTransPrepare(pMnode, pTrans) != 0) {
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
mndTransDrop(pTrans);
return 0;
2021-12-02 03:22:03 +00:00
}
2022-05-16 06:55:31 +00:00
static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
SMnode *pMnode = pMsg->info.node;
2021-12-06 10:21:14 +00:00
SSdb *pSdb = pMnode->pSdb;
2024-06-20 07:38:22 +00:00
int32_t code = 0;
2021-12-06 10:21:14 +00:00
int32_t numOfRows = 0;
int32_t cols = 0;
SClusterObj *pCluster = NULL;
2021-12-02 11:56:43 +00:00
2021-12-06 10:21:14 +00:00
while (numOfRows < rows) {
pShow->pIter = sdbFetch(pSdb, SDB_CLUSTER, pShow->pIter, (void **)&pCluster);
if (pShow->pIter == NULL) break;
2021-12-02 11:56:43 +00:00
2021-12-06 10:21:14 +00:00
cols = 0;
2022-05-07 01:23:06 +00:00
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-06-20 07:38:22 +00:00
COL_DATA_SET_VAL_RET((const char *)&pCluster->id, false, pCluster);
2021-12-02 11:56:43 +00:00
char buf[tListLen(pCluster->name) + VARSTR_HEADER_SIZE] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(buf, pCluster->name, pShow->pMeta->pSchemas[cols].bytes);
2021-12-02 11:56:43 +00:00
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-06-20 07:38:22 +00:00
COL_DATA_SET_VAL_RET(buf, false, pCluster);
2021-12-02 11:56:43 +00:00
2022-08-23 09:29:31 +00:00
int32_t upTime = mndGetClusterUpTimeImp(pCluster);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-06-20 07:38:22 +00:00
COL_DATA_SET_VAL_RET((const char *)&upTime, false, pCluster);
2022-08-23 09:29:31 +00:00
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-06-20 07:38:22 +00:00
COL_DATA_SET_VAL_RET((const char *)&pCluster->createdTime, false, pCluster);
2021-12-02 11:56:43 +00:00
2023-01-09 08:49:58 +00:00
char ver[12] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(ver, tsVersionName, pShow->pMeta->pSchemas[cols].bytes);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2024-06-20 07:38:22 +00:00
COL_DATA_SET_VAL_RET((const char *)ver, false, pCluster);
2023-01-09 08:49:58 +00:00
char expireTime[25] = {0};
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
if (GRANT_EXPIRE_UNLIMITED(tsExpireTime / 1000)) {
STR_WITH_MAXSIZE_TO_VARSTR(expireTime, "unlimited", pShow->pMeta->pSchemas[cols].bytes);
2024-06-20 07:38:22 +00:00
COL_DATA_SET_VAL_RET(expireTime, false, pCluster);
} else if (tsExpireTime <= 0) {
colDataSetNULL(pColInfo, numOfRows);
2023-01-09 08:49:58 +00:00
} else {
char ts[20] = {0};
time_t expireSec = tsExpireTime / 1000;
struct tm ptm;
if (taosLocalTime(&expireSec, &ptm, ts) != NULL) {
strftime(ts, 20, "%Y-%m-%d %H:%M:%S", &ptm);
} else {
ts[0] = 0;
}
STR_WITH_MAXSIZE_TO_VARSTR(expireTime, ts, pShow->pMeta->pSchemas[cols].bytes);
2024-06-20 07:38:22 +00:00
COL_DATA_SET_VAL_RET(expireTime, false, pCluster);
2023-01-09 08:49:58 +00:00
}
2021-12-06 10:21:14 +00:00
sdbRelease(pSdb, pCluster);
numOfRows++;
}
2021-12-02 03:22:03 +00:00
pShow->numOfRows += numOfRows;
2021-12-06 10:21:14 +00:00
return numOfRows;
2021-12-02 03:22:03 +00:00
}
2021-12-06 10:21:14 +00:00
static void mndCancelGetNextCluster(SMnode *pMnode, void *pIter) {
SSdb *pSdb = pMnode->pSdb;
sdbCancelFetch(pSdb, pIter);
2021-12-06 11:57:13 +00:00
}
2022-08-23 09:29:31 +00:00
static int32_t mndProcessUptimeTimer(SRpcMsg *pReq) {
SMnode *pMnode = pReq->info.node;
SClusterObj clusterObj = {0};
2023-04-10 08:52:41 +00:00
void *pIter = NULL;
SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
2022-08-23 09:29:31 +00:00
if (pCluster != NULL) {
2023-12-07 06:11:41 +00:00
memcpy(&clusterObj, pCluster, sizeof(SClusterObj));
2022-08-23 09:29:31 +00:00
clusterObj.upTime += tsUptimeInterval;
2023-04-10 08:52:41 +00:00
mndReleaseCluster(pMnode, pCluster, pIter);
2022-08-23 09:29:31 +00:00
}
if (clusterObj.id <= 0) {
mError("can't get cluster info while update uptime");
return 0;
}
2022-09-29 11:41:54 +00:00
mInfo("update cluster uptime to %d", clusterObj.upTime);
2022-09-22 08:18:51 +00:00
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "update-uptime");
2023-12-07 06:11:41 +00:00
if (pTrans == NULL) return -1;
2022-08-23 09:29:31 +00:00
SSdbRaw *pCommitRaw = mndClusterActionEncode(&clusterObj);
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
2022-10-08 09:06:29 +00:00
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
2022-08-23 09:29:31 +00:00
if (mndTransPrepare(pMnode, pTrans) != 0) {
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
mndTransDrop(pTrans);
return 0;
2024-01-19 06:59:02 +00:00
}
int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) {
int32_t code = 0;
SMnode *pMnode = pReq->info.node;
SMCfgClusterReq cfgReq = {0};
if (tDeserializeSMCfgClusterReq(pReq->pCont, pReq->contLen, &cfgReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
return -1;
}
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;
goto _exit;
}
SClusterObj clusterObj = {0};
void *pIter = NULL;
SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
if (!pCluster || pCluster->id <= 0) {
code = TSDB_CODE_APP_IS_STARTING;
if (pCluster) mndReleaseCluster(pMnode, pCluster, pIter);
goto _exit;
}
memcpy(&clusterObj, pCluster, sizeof(SClusterObj));
mndReleaseCluster(pMnode, pCluster, pIter);
if (strncmp(cfgReq.config, GRANT_ACTIVE_CODE, TSDB_DNODE_CONFIG_LEN) == 0) {
#ifdef TD_ENTERPRISE
2024-01-22 05:20:15 +00:00
if (0 != (code = mndProcessConfigGrantReq(pMnode, pReq, &cfgReq))) {
2024-01-19 06:59:02 +00:00
goto _exit;
}
#else
code = TSDB_CODE_OPS_NOT_SUPPORT;
goto _exit;
#endif
} else {
code = TSDB_CODE_OPS_NOT_SUPPORT;
goto _exit;
}
{ // audit
2024-02-05 01:21:11 +00:00
auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql, TMIN(cfgReq.sqlLen, GRANT_ACTIVE_HEAD_LEN << 1));
2024-01-19 06:59:02 +00:00
}
_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;
}
int32_t mndProcessConfigClusterRsp(SRpcMsg *pRsp) {
mInfo("config rsp from cluster");
return 0;
2024-01-18 09:49:11 +00:00
}