提交 fe12d0fe 编写于 作者: S slguan

add cluster codes

上级 9b6c8a30
......@@ -229,3 +229,7 @@ static int32_t dnodeInitStorage() {
}
static void dnodeCleanupStorage() {}
bool dnodeIsFirstDeploy() {
return strcmp(tsMasterIp, tsPrivateIp) == 0;
}
\ No newline at end of file
......@@ -44,6 +44,8 @@ void *dnodeAllocateRqueue(void *pVnode);
void dnodeFreeRqueue(void *rqueue);
void dnodeSendRpcWriteRsp(void *pVnode, void *param, int32_t code);
bool dnodeIsFirstDeploy();
#ifdef __cplusplus
}
#endif
......
......@@ -60,14 +60,16 @@ typedef struct _dnode_obj {
int32_t dnodeId;
uint32_t privateIp;
uint32_t publicIp;
uint16_t mnodeShellPort;
uint16_t mnodeDnodePort;
uint16_t dnodeShellPort;
uint16_t dnodeMnodePort;
uint16_t syncPort;
uint32_t moduleStatus;
int64_t createdTime;
uint32_t lastAccess;
int32_t openVnodes;
int32_t numOfTotalVnodes; // from dnode status msg, config information
uint32_t rack;
uint16_t idc;
uint16_t slot;
int32_t totalVnodes; // from dnode status msg, config information
uint16_t numOfCores; // from dnode status msg
int8_t alternativeRole; // from dnode status msg, 0-any, 1-mgmt, 2-dnode
int8_t status; // set in balance function
......@@ -88,7 +90,6 @@ typedef struct _dnode_obj {
typedef struct {
int32_t dnodeId;
uint16_t port;
uint32_t privateIp;
uint32_t publicIp;
} SVnodeGid;
......@@ -209,7 +210,7 @@ typedef struct _acct_obj {
SAcctCfg cfg;
int32_t acctId;
int64_t createdTime;
int8_t dirty;
int8_t status;
int8_t reserved[14];
int8_t updateEnd[1];
int32_t refCount;
......
......@@ -20,27 +20,15 @@
extern "C" {
#endif
struct _acct_obj;
struct _user_obj;
struct _db_obj;
typedef enum {
TSDB_ACCT_USER,
TSDB_ACCT_DB,
TSDB_ACCT_TABLE
ACCT_GRANT_USER,
ACCT_GRANT_DB,
ACCT_GRANT_TABLE
} EAcctGrantType;
int32_t acctInit();
void acctCleanUp();
void *acctGetAcct(char *acctName);
void acctIncRef(struct _acct_obj *pAcct);
void acctReleaseAcct(struct _acct_obj *pAcct);
int32_t acctCheck(struct _acct_obj *pAcct, EAcctGrantType type);
void acctAddDb(struct _acct_obj *pAcct, struct _db_obj *pDb);
void acctRemoveDb(struct _acct_obj *pAcct, struct _db_obj *pDb);
void acctAddUser(struct _acct_obj *pAcct, struct _user_obj *pUser);
void acctRemoveUser(struct _acct_obj *pAcct, struct _user_obj *pUser);
int32_t acctCheck(void *pAcct, EAcctGrantType type);
#ifdef __cplusplus
}
......
/*
* 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/>.
*/
#ifndef TDENGINE_MGMT_ACCT_H
#define TDENGINE_MGMT_ACCT_H
#ifdef __cplusplus
extern "C" {
#endif
#include "tacct.h"
struct _acct_obj;
struct _user_obj;
struct _db_obj;
int32_t mgmtInitAccts();
void mgmtCleanUpAccts();
void *mgmtGetAcct(char *acctName);
void mgmtIncAcctRef(struct _acct_obj *pAcct);
void mgmtDecAcctRef(struct _acct_obj *pAcct);
void mgmtAddDbToAcct(struct _acct_obj *pAcct, struct _db_obj *pDb);
void mgmtDropDbFromAcct(struct _acct_obj *pAcct, struct _db_obj *pDb);
void mgmtAddUserToAcct(struct _acct_obj *pAcct, struct _user_obj *pUser);
void mgmtDropUserFromAcct(struct _acct_obj *pAcct, struct _user_obj *pUser);
#ifdef __cplusplus
}
#endif
#endif
......@@ -33,7 +33,7 @@ void mgmtCleanUpDbs();
SDbObj *mgmtGetDb(char *db);
SDbObj *mgmtGetDbByTableId(char *db);
void mgmtIncDbRef(SDbObj *pDb);
void mgmtReleaseDb(SDbObj *pDb);
void mgmtDecDbRef(SDbObj *pDb);
bool mgmtCheckIsMonitorDB(char *db, char *monitordb);
void mgmtDropAllDbs(SAcctObj *pAcct);
......
......@@ -33,21 +33,20 @@ enum _TAOS_DN_STATUS {
TAOS_DN_STATUS_READY
};
int32_t clusterInit();
void clusterCleanUp();
char* clusterGetDnodeStatusStr(int32_t dnodeStatus);
bool clusterCheckModuleInDnode(struct _dnode_obj *pDnode, int moduleType);
void clusterMonitorDnodeModule();
int32_t clusterInitDnodes();
void clusterCleanupDnodes();
int32_t clusterGetDnodesNum();
void * clusterGetNextDnode(void *pNode, struct _dnode_obj **pDnode);
void clusterReleaseDnode(struct _dnode_obj *pDnode);
void * clusterGetDnode(int32_t dnodeId);
void * clusterGetDnodeByIp(uint32_t ip);
void clusterUpdateDnode(struct _dnode_obj *pDnode);
int32_t clusterDropDnode(struct _dnode_obj *pDnode);
int32_t mgmtInitDnodes();
void mgmtCleanupDnodes();
char* mgmtGetDnodeStatusStr(int32_t dnodeStatus);
bool mgmtCheckModuleInDnode(struct _dnode_obj *pDnode, int moduleType);
void mgmtMonitorDnodeModule();
int32_t mgmtGetDnodesNum();
void * mgmtGetNextDnode(void *pNode, struct _dnode_obj **pDnode);
void mgmtReleaseDnode(struct _dnode_obj *pDnode);
void * mgmtGetDnode(int32_t dnodeId);
void * mgmtGetDnodeByIp(uint32_t ip);
void mgmtUpdateDnode(struct _dnode_obj *pDnode);
int32_t mgmtDropDnode(struct _dnode_obj *pDnode);
#ifdef __cplusplus
}
......
......@@ -16,49 +16,178 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "taoserror.h"
#include "dnode.h"
#include "mnode.h"
#include "taccount.h"
#include "mgmtAcct.h"
#include "mgmtDb.h"
#include "mgmtSdb.h"
#include "mgmtUser.h"
#ifndef _ACCOUNT
static void * tsAcctSdb = NULL;
static int32_t tsAcctUpdateSize;
static void mgmtCreateRootAcct();
static SAcctObj tsAcctObj = {0};
static int32_t mgmtActionAcctDestroy(SSdbOperDesc *pOper) {
SAcctObj *pAcct = pOper->pObj;
pthread_mutex_destroy(&pAcct->mutex);
tfree(pOper->pObj);
return TSDB_CODE_SUCCESS;
}
int32_t acctInit() {
tsAcctObj.acctId = 0;
strcpy(tsAcctObj.user, "root");
static int32_t mgmtAcctActionInsert(SSdbOperDesc *pOper) {
SAcctObj *pAcct = pOper->pObj;
memset(&pAcct->acctInfo, 0, sizeof(SAcctInfo));
pthread_mutex_init(&pAcct->mutex, NULL);
return TSDB_CODE_SUCCESS;
}
void acctCleanUp() {}
void *acctGetAcct(char *acctName) { return &tsAcctObj; }
void acctIncRef(struct _acct_obj *pAcct) {}
void acctReleaseAcct(SAcctObj *pAcct) {}
int32_t acctCheck(SAcctObj *pAcct, EAcctGrantType type) { return TSDB_CODE_SUCCESS; }
static int32_t mgmtActionAcctDelete(SSdbOperDesc *pOper) {
SAcctObj *pAcct = pOper->pObj;
mgmtDropAllUsers(pAcct);
mgmtDropAllDbs(pAcct);
return TSDB_CODE_SUCCESS;
}
#endif
static int32_t mgmtActionAcctUpdate(SSdbOperDesc *pOper) {
SAcctObj *pAcct = pOper->pObj;
SAcctObj *pSaved = mgmtGetAcct(pAcct->user);
if (pAcct != pSaved) {
memcpy(pSaved, pAcct, tsAcctUpdateSize);
free(pAcct);
}
return TSDB_CODE_SUCCESS;
}
static int32_t mgmtActionActionEncode(SSdbOperDesc *pOper) {
SAcctObj *pAcct = pOper->pObj;
memcpy(pOper->rowData, pAcct, tsAcctUpdateSize);
pOper->rowSize = tsAcctUpdateSize;
return TSDB_CODE_SUCCESS;
}
static int32_t mgmtActionAcctDecode(SSdbOperDesc *pOper) {
SAcctObj *pAcct = (SAcctObj *) calloc(1, sizeof(SAcctObj));
if (pAcct == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY;
memcpy(pAcct, pOper->rowData, tsAcctUpdateSize);
pOper->pObj = pAcct;
return TSDB_CODE_SUCCESS;
}
static int32_t mgmtActionAcctRestored() {
if (dnodeIsFirstDeploy()) {
mgmtCreateRootAcct();
}
return TSDB_CODE_SUCCESS;
}
int32_t mgmtInitAccts() {
SAcctObj tObj;
tsAcctUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj;
SSdbTableDesc tableDesc = {
.tableId = SDB_TABLE_ACCOUNT,
.tableName = "accounts",
.hashSessions = TSDB_MAX_ACCOUNTS,
.maxRowSize = tsAcctUpdateSize,
.refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj,
.keyType = SDB_KEY_STRING,
.insertFp = mgmtAcctActionInsert,
.deleteFp = mgmtActionAcctDelete,
.updateFp = mgmtActionAcctUpdate,
.encodeFp = mgmtActionActionEncode,
.decodeFp = mgmtActionAcctDecode,
.destroyFp = mgmtActionAcctDestroy,
.restoredFp = mgmtActionAcctRestored
};
void acctAddDb(SAcctObj *pAcct, SDbObj *pDb) {
tsAcctSdb = sdbOpenTable(&tableDesc);
if (tsAcctSdb == NULL) {
mError("failed to init acct data");
return -1;
}
mTrace("account table is created");
return acctInit();
}
void mgmtCleanUpAccts() {
sdbCloseTable(tsAcctSdb);
acctCleanUp();
}
void *mgmtGetAcct(char *name) {
return sdbGetRow(tsAcctSdb, name);
}
void mgmtIncAcctRef(SAcctObj *pAcct) {
sdbIncRef(tsAcctSdb, pAcct);
}
void mgmtDecAcctRef(SAcctObj *pAcct) {
sdbDecRef(tsAcctSdb, pAcct);
}
void mgmtAddDbToAcct(SAcctObj *pAcct, SDbObj *pDb) {
atomic_add_fetch_32(&pAcct->acctInfo.numOfDbs, 1);
pDb->pAcct = pAcct;
acctIncRef(pAcct);
mgmtIncAcctRef(pAcct);
}
void acctRemoveDb(SAcctObj *pAcct, SDbObj *pDb) {
void mgmtDropDbFromAcct(SAcctObj *pAcct, SDbObj *pDb) {
atomic_sub_fetch_32(&pAcct->acctInfo.numOfDbs, 1);
pDb->pAcct = NULL;
acctReleaseAcct(pAcct);
mgmtDecAcctRef(pAcct);
}
void acctAddUser(SAcctObj *pAcct, SUserObj *pUser) {
void mgmtAddUserToAcct(SAcctObj *pAcct, SUserObj *pUser) {
atomic_add_fetch_32(&pAcct->acctInfo.numOfUsers, 1);
pUser->pAcct = pAcct;
acctIncRef(pAcct);
mgmtIncAcctRef(pAcct);
}
void acctRemoveUser(SAcctObj *pAcct, SUserObj *pUser) {
void mgmtDropUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) {
atomic_sub_fetch_32(&pAcct->acctInfo.numOfUsers, 1);
pUser->pAcct = NULL;
acctReleaseAcct(pAcct);
mgmtDecAcctRef(pAcct);
}
static void mgmtCreateRootAcct() {
int32_t numOfAccts = sdbGetNumOfRows(tsAcctSdb);
if (numOfAccts != 0) return;
SAcctObj *pAcct = malloc(sizeof(SAcctObj));
memset(pAcct, 0, sizeof(SAcctObj));
strcpy(pAcct->user, "root");
taosEncryptPass((uint8_t*)"taosdata", strlen("taosdata"), pAcct->pass);
pAcct->cfg = (SAcctCfg){
.maxUsers = 10,
.maxDbs = 64,
.maxTimeSeries = INT32_MAX,
.maxConnections = 1024,
.maxStreams = 1000,
.maxPointsPerSecond = 10000000,
.maxStorage = INT64_MAX,
.maxQueryTime = INT64_MAX,
.maxInbound = 0,
.maxOutbound = 0,
.accessState = TSDB_VN_ALL_ACCCESS
};
pAcct->acctId = sdbGetId(tsAcctSdb);
pAcct->createdTime = taosGetTimestampMs();
SSdbOperDesc oper = {
.type = SDB_OPER_GLOBAL,
.table = tsAcctSdb,
.pObj = pAcct,
};
sdbInsertRow(&oper);
}
#ifndef _ACCT
int32_t acctInit() { return TSDB_CODE_SUCCESS; }
void acctCleanUp() {}
int32_t acctCheck(void *pAcct, EAcctGrantType type) { return TSDB_CODE_SUCCESS; }
#endif
\ No newline at end of file
......@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE
#include "tbalance.h"
#include "mnode.h"
#include "tcluster.h"
#include "mgmtDnode.h"
#include "mgmtVgroup.h"
#ifndef _VPEER
......@@ -31,17 +31,17 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
float vnodeUsage = 1.0;
while (1) {
pNode = clusterGetNextDnode(pNode, &pDnode);
pNode = mgmtGetNextDnode(pNode, &pDnode);
if (pDnode == NULL) break;
if (pDnode->numOfTotalVnodes > 0 && pDnode->openVnodes < pDnode->numOfTotalVnodes) {
float usage = (float)pDnode->openVnodes / pDnode->numOfTotalVnodes;
if (pDnode->totalVnodes > 0 && pDnode->openVnodes < pDnode->totalVnodes) {
float usage = (float)pDnode->openVnodes / pDnode->totalVnodes;
if (usage <= vnodeUsage) {
pSelDnode = pDnode;
vnodeUsage = usage;
}
}
clusterReleaseDnode(pDnode);
mgmtReleaseDnode(pDnode);
}
if (pSelDnode == NULL) {
......
......@@ -23,7 +23,7 @@
#include "mnode.h"
#include "tbalance.h"
#include "mgmtDb.h"
#include "tcluster.h"
#include "mgmtDnode.h"
#include "tgrant.h"
#include "mgmtProfile.h"
#include "mgmtShell.h"
......
......@@ -19,10 +19,10 @@
#include "tutil.h"
#include "name.h"
#include "mnode.h"
#include "taccount.h"
#include "tbalance.h"
#include "mgmtAcct.h"
#include "mgmtDb.h"
#include "tcluster.h"
#include "mgmtDnode.h"
#include "tgrant.h"
#include "mpeer.h"
#include "mgmtShell.h"
......@@ -51,7 +51,7 @@ static int32_t mgmtDbActionDestroy(SSdbOperDesc *pOper) {
static int32_t mgmtDbActionInsert(SSdbOperDesc *pOper) {
SDbObj *pDb = pOper->pObj;
SAcctObj *pAcct = acctGetAcct(pDb->cfg.acct);
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
pDb->pHead = NULL;
pDb->pTail = NULL;
......@@ -60,7 +60,7 @@ static int32_t mgmtDbActionInsert(SSdbOperDesc *pOper) {
pDb->numOfSuperTables = 0;
if (pAcct != NULL) {
acctAddDb(pAcct, pDb);
mgmtAddDbToAcct(pAcct, pDb);
}
else {
mError("db:%s, acct:%s info not exist in sdb", pDb->name, pDb->cfg.acct);
......@@ -72,9 +72,9 @@ static int32_t mgmtDbActionInsert(SSdbOperDesc *pOper) {
static int32_t mgmtDbActionDelete(SSdbOperDesc *pOper) {
SDbObj *pDb = pOper->pObj;
SAcctObj *pAcct = acctGetAcct(pDb->cfg.acct);
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
acctRemoveDb(pAcct, pDb);
mgmtDropDbFromAcct(pAcct, pDb);
mgmtDropAllChildTables(pDb);
mgmtDropAllSuperTables(pDb);
mgmtDropAllVgroups(pDb);
......@@ -156,7 +156,7 @@ void mgmtIncDbRef(SDbObj *pDb) {
return sdbIncRef(tsDbSdb, pDb);
}
void mgmtReleaseDb(SDbObj *pDb) {
void mgmtDecDbRef(SDbObj *pDb) {
return sdbDecRef(tsDbSdb, pDb);
}
......@@ -288,14 +288,14 @@ static int32_t mgmtCheckDbParams(SCMCreateDbMsg *pCreate) {
}
static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) {
int32_t code = acctCheck(pAcct, TSDB_ACCT_DB);
int32_t code = acctCheck(pAcct, ACCT_GRANT_DB);
if (code != 0) {
return code;
}
SDbObj *pDb = mgmtGetDb(pCreate->db);
if (pDb != NULL) {
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
return TSDB_CODE_DB_ALREADY_EXIST;
}
......@@ -641,7 +641,7 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *
cols++;
numOfRows++;
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
}
pShow->numOfReads += numOfRows;
......@@ -888,7 +888,7 @@ void mgmtDropAllDbs(SAcctObj *pAcct) {
mgmtSetDbDropping(pDb);
numOfDbs++;
}
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
}
mTrace("acct:%s, all dbs is is set dirty", pAcct->user, numOfDbs);
......
此差异已折叠。
......@@ -19,9 +19,9 @@
#include "tmodule.h"
#include "tsched.h"
#include "mnode.h"
#include "taccount.h"
#include "mgmtAcct.h"
#include "tbalance.h"
#include "tcluster.h"
#include "mgmtDnode.h"
#include "tgrant.h"
#include "mpeer.h"
#include "mgmtDb.h"
......@@ -74,7 +74,7 @@ int32_t mgmtStartSystem() {
return -1;
}
if (acctInit() < 0) {
if (mgmtInitAccts() < 0) {
mError("failed to init accts");
return -1;
}
......@@ -89,7 +89,7 @@ int32_t mgmtStartSystem() {
return -1;
}
if (clusterInit() < 0) {
if (mgmtInitDnodes() < 0) {
mError("failed to init dnodes");
return -1;
}
......@@ -160,9 +160,9 @@ void mgmtCleanUpSystem() {
mgmtCleanUpTables();
mgmtCleanUpVgroups();
mgmtCleanUpDbs();
clusterCleanUp();
mgmtCleanupDnodes();
mgmtCleanUpUsers();
acctCleanUp();
mgmtCleanUpAccts();
sdbCleanUp();
taosTmrCleanUp(tsMgmtTmr);
mPrint("mgmt is cleaned up");
......
......@@ -16,8 +16,8 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "taosmsg.h"
#include "taccount.h"
#include "tcluster.h"
#include "mgmtAcct.h"
#include "mgmtDnode.h"
#include "mgmtDb.h"
#include "mpeer.h"
#include "mgmtProfile.h"
......@@ -787,11 +787,11 @@ void mgmtFreeQueuedMsg(SQueuedMsg *pMsg) {
if (pMsg != NULL) {
rpcFreeCont(pMsg->pCont);
if (pMsg->pUser) mgmtReleaseUser(pMsg->pUser);
if (pMsg->pDb) mgmtReleaseDb(pMsg->pDb);
if (pMsg->pDb) mgmtDecDbRef(pMsg->pDb);
if (pMsg->pVgroup) mgmtReleaseVgroup(pMsg->pVgroup);
if (pMsg->pTable) mgmtDecTableRef(pMsg->pTable);
if (pMsg->pAcct) acctReleaseAcct(pMsg->pAcct);
if (pMsg->pDnode) clusterReleaseDnode(pMsg->pDnode);
if (pMsg->pAcct) mgmtDecAcctRef(pMsg->pAcct);
if (pMsg->pDnode) mgmtReleaseDnode(pMsg->pDnode);
free(pMsg);
}
}
......
......@@ -22,10 +22,10 @@
#include "tsched.h"
#include "dnode.h"
#include "mnode.h"
#include "taccount.h"
#include "mgmtAcct.h"
#include "tbalance.h"
#include "mgmtDb.h"
#include "tcluster.h"
#include "mgmtDnode.h"
#include "tgrant.h"
#include "mpeer.h"
#include "mgmtProfile.h"
......
......@@ -23,10 +23,10 @@
#include "taosmsg.h"
#include "tscompression.h"
#include "name.h"
#include "taccount.h"
#include "mgmtAcct.h"
#include "mgmtDClient.h"
#include "mgmtDb.h"
#include "tcluster.h"
#include "mgmtDnode.h"
#include "mgmtDServer.h"
#include "tgrant.h"
#include "mpeer.h"
......@@ -101,14 +101,14 @@ static int32_t mgmtChildTableActionInsert(SSdbOperDesc *pOper) {
mError("ctable:%s, vgroup:%d not in db:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName);
return TSDB_CODE_INVALID_DB;
}
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
SAcctObj *pAcct = acctGetAcct(pDb->cfg.acct);
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
if (pAcct == NULL) {
mError("ctable:%s, account:%s not exists", pTable->info.tableId, pDb->cfg.acct);
return TSDB_CODE_INVALID_ACCT;
}
acctReleaseAcct(pAcct);
mgmtDecAcctRef(pAcct);
if (pTable->info.type == TSDB_CHILD_TABLE) {
pTable->superTable = mgmtGetSuperTable(pTable->superTableId);
......@@ -143,14 +143,14 @@ static int32_t mgmtChildTableActionDelete(SSdbOperDesc *pOper) {
mError("ctable:%s, vgroup:%d not in DB:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName);
return TSDB_CODE_INVALID_DB;
}
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
SAcctObj *pAcct = acctGetAcct(pDb->cfg.acct);
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
if (pAcct == NULL) {
mError("ctable:%s, account:%s not exists", pTable->info.tableId, pDb->cfg.acct);
return TSDB_CODE_INVALID_ACCT;
}
acctReleaseAcct(pAcct);
mgmtDecAcctRef(pAcct);
if (pTable->info.type == TSDB_CHILD_TABLE) {
grantRestore(TSDB_GRANT_TIMESERIES, pTable->superTable->numOfColumns - 1);
......@@ -258,7 +258,7 @@ static int32_t mgmtChildTableActionRestored() {
pNode = pLastNode;
continue;
}
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
SVgObj *pVgroup = mgmtGetVgroup(pTable->vgId);
if (pVgroup == NULL) {
......@@ -401,7 +401,7 @@ static int32_t mgmtSuperTableActionInsert(SSdbOperDesc *pOper) {
if (pDb != NULL) {
mgmtAddSuperTableIntoDb(pDb);
}
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
return TSDB_CODE_SUCCESS;
}
......@@ -413,7 +413,7 @@ static int32_t mgmtSuperTableActionDelete(SSdbOperDesc *pOper) {
mgmtRemoveSuperTableFromDb(pDb);
mgmtDropAllChildTablesInStable((SSuperTableObj *)pStable);
}
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
return TSDB_CODE_SUCCESS;
}
......@@ -923,10 +923,10 @@ static int32_t mgmtAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSc
pStable->numOfColumns += ncols;
pStable->sversion++;
SAcctObj *pAcct = acctGetAcct(pDb->cfg.acct);
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
if (pAcct != NULL) {
pAcct->acctInfo.numOfTimeSeries += (ncols * pStable->numOfTables);
acctReleaseAcct(pAcct);
mgmtDecAcctRef(pAcct);
}
SSdbOperDesc oper = {
......@@ -960,10 +960,10 @@ static int32_t mgmtDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, ch
int32_t schemaSize = sizeof(SSchema) * (pStable->numOfTags + pStable->numOfColumns);
pStable->schema = realloc(pStable->schema, schemaSize);
SAcctObj *pAcct = acctGetAcct(pDb->cfg.acct);
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
if (pAcct != NULL) {
pAcct->acctInfo.numOfTimeSeries -= pStable->numOfTables;
acctReleaseAcct(pAcct);
mgmtDecAcctRef(pAcct);
}
SSdbOperDesc oper = {
......@@ -1029,7 +1029,7 @@ static int32_t mgmtGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow,
pShow->numOfRows = pDb->numOfSuperTables;
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
return 0;
}
......@@ -1094,7 +1094,7 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v
}
pShow->numOfReads += numOfRows;
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
return numOfRows;
}
......@@ -1191,14 +1191,14 @@ static void mgmtProcessSuperTableVgroupMsg(SQueuedMsg *pMsg) {
pRsp->vgroups[vg].vgId = htonl(vgId);
for (int32_t vn = 0; vn < pVgroup->numOfVnodes; ++vn) {
SDnodeObj *pDnode = clusterGetDnode(pVgroup->vnodeGid[vn].dnodeId);
SDnodeObj *pDnode = mgmtGetDnode(pVgroup->vnodeGid[vn].dnodeId);
if (pDnode == NULL) break;
pRsp->vgroups[vg].ipAddr[vn].ip = htonl(pDnode->privateIp);
pRsp->vgroups[vg].ipAddr[vn].port = htons(tsDnodeShellPort);
pRsp->vgroups[vg].numOfIps++;
clusterReleaseDnode(pDnode);
mgmtReleaseDnode(pDnode);
}
mgmtReleaseVgroup(pVgroup);
......@@ -1500,10 +1500,10 @@ static int32_t mgmtAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSc
pTable->numOfColumns += ncols;
pTable->sversion++;
SAcctObj *pAcct = acctGetAcct(pDb->cfg.acct);
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
if (pAcct != NULL) {
pAcct->acctInfo.numOfTimeSeries += ncols;
acctReleaseAcct(pAcct);
mgmtDecAcctRef(pAcct);
}
SSdbOperDesc oper = {
......@@ -1534,10 +1534,10 @@ static int32_t mgmtDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, ch
pTable->numOfColumns--;
pTable->sversion++;
SAcctObj *pAcct = acctGetAcct(pDb->cfg.acct);
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
if (pAcct != NULL) {
pAcct->acctInfo.numOfTimeSeries--;
acctReleaseAcct(pAcct);
mgmtDecAcctRef(pAcct);
}
SSdbOperDesc oper = {
......@@ -1600,7 +1600,7 @@ static int32_t mgmtDoGetChildTableMeta(SQueuedMsg *pMsg, STableMetaMsg *pMeta) {
}
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
SDnodeObj *pDnode = clusterGetDnode(pVgroup->vnodeGid[i].dnodeId);
SDnodeObj *pDnode = mgmtGetDnode(pVgroup->vnodeGid[i].dnodeId);
if (pDnode == NULL) break;
if (usePublicIp) {
pMeta->vgroup.ipAddr[i].ip = htonl(pDnode->publicIp);
......@@ -1610,7 +1610,7 @@ static int32_t mgmtDoGetChildTableMeta(SQueuedMsg *pMsg, STableMetaMsg *pMeta) {
pMeta->vgroup.ipAddr[i].port = htonl(tsDnodeShellPort);
}
pMeta->vgroup.numOfIps++;
clusterReleaseDnode(pDnode);
mgmtReleaseDnode(pDnode);
}
pMeta->vgroup.vgId = htonl(pVgroup->vgId);
......@@ -1730,7 +1730,7 @@ static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) {
}
static SChildTableObj* mgmtGetTableByPos(uint32_t dnodeId, int32_t vnode, int32_t sid) {
SDnodeObj *pObj = clusterGetDnode(dnodeId);
SDnodeObj *pObj = mgmtGetDnode(dnodeId);
SVgObj *pVgroup = mgmtGetVgroup(vnode);
if (pObj == NULL || pVgroup == NULL) {
......@@ -1968,7 +1968,7 @@ static int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void
pShow->numOfRows = pDb->numOfTables;
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
return 0;
}
......@@ -2045,7 +2045,7 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows,
const int32_t NUM_OF_COLUMNS = 4;
mgmtVacuumResult(data, NUM_OF_COLUMNS, numOfRows, rows, pShow);
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
return numOfRows;
}
......
......@@ -18,7 +18,7 @@
#include "trpc.h"
#include "ttime.h"
#include "tutil.h"
#include "taccount.h"
#include "mgmtAcct.h"
#include "tgrant.h"
#include "mpeer.h"
#include "mgmtSdb.h"
......@@ -40,10 +40,10 @@ static int32_t mgmtUserActionDestroy(SSdbOperDesc *pOper) {
static int32_t mgmtUserActionInsert(SSdbOperDesc *pOper) {
SUserObj *pUser = pOper->pObj;
SAcctObj *pAcct = acctGetAcct(pUser->acct);
SAcctObj *pAcct = mgmtGetAcct(pUser->acct);
if (pAcct != NULL) {
acctAddUser(pAcct, pUser);
mgmtAddUserToAcct(pAcct, pUser);
}
else {
mError("user:%s, acct:%s info not exist in sdb", pUser->user, pUser->acct);
......@@ -55,10 +55,10 @@ static int32_t mgmtUserActionInsert(SSdbOperDesc *pOper) {
static int32_t mgmtUserActionDelete(SSdbOperDesc *pOper) {
SUserObj *pUser = pOper->pObj;
SAcctObj *pAcct = acctGetAcct(pUser->acct);
SAcctObj *pAcct = mgmtGetAcct(pUser->acct);
if (pAcct != NULL) {
acctRemoveUser(pAcct, pUser);
mgmtDropUserFromAcct(pAcct, pUser);
}
return TSDB_CODE_SUCCESS;
......@@ -92,11 +92,11 @@ static int32_t mgmtUserActionDecode(SSdbOperDesc *pOper) {
static int32_t mgmtUserActionRestored() {
if (strcmp(tsMasterIp, tsPrivateIp) == 0) {
SAcctObj *pAcct = acctGetAcct("root");
SAcctObj *pAcct = mgmtGetAcct("root");
mgmtCreateUser(pAcct, "root", "taosdata");
mgmtCreateUser(pAcct, "monitor", tsInternalPass);
mgmtCreateUser(pAcct, "_root", tsInternalPass);
acctReleaseAcct(pAcct);
mgmtDecAcctRef(pAcct);
}
return 0;
......@@ -167,7 +167,7 @@ static int32_t mgmtUpdateUser(SUserObj *pUser) {
}
int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
int32_t code = acctCheck(pAcct, TSDB_ACCT_USER);
int32_t code = acctCheck(pAcct, ACCT_GRANT_USER);
if (code != 0) {
return code;
}
......
......@@ -19,7 +19,7 @@
#include "tlog.h"
#include "tbalance.h"
#include "tsync.h"
#include "tcluster.h"
#include "mgmtDnode.h"
#include "mnode.h"
#include "mgmtDb.h"
#include "mgmtDClient.h"
......@@ -63,7 +63,7 @@ static int32_t mgmtVgroupActionInsert(SSdbOperDesc *pOper) {
if (pDb == NULL) {
return TSDB_CODE_INVALID_DB;
}
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
pVgroup->pDb = pDb;
pVgroup->prev = NULL;
......@@ -84,12 +84,12 @@ static int32_t mgmtVgroupActionInsert(SSdbOperDesc *pOper) {
}
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
SDnodeObj *pDnode = clusterGetDnode(pVgroup->vnodeGid[i].dnodeId);
SDnodeObj *pDnode = mgmtGetDnode(pVgroup->vnodeGid[i].dnodeId);
if (pDnode != NULL) {
pVgroup->vnodeGid[i].privateIp = pDnode->privateIp;
pVgroup->vnodeGid[i].publicIp = pDnode->publicIp;
atomic_add_fetch_32(&pDnode->openVnodes, 1);
clusterReleaseDnode(pDnode);
mgmtReleaseDnode(pDnode);
}
}
......@@ -106,14 +106,14 @@ static int32_t mgmtVgroupActionDelete(SSdbOperDesc *pOper) {
mgmtRemoveVgroupFromDb(pVgroup);
}
mgmtReleaseDb(pVgroup->pDb);
mgmtDecDbRef(pVgroup->pDb);
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
SDnodeObj *pDnode = clusterGetDnode(pVgroup->vnodeGid[i].dnodeId);
SDnodeObj *pDnode = mgmtGetDnode(pVgroup->vnodeGid[i].dnodeId);
if (pDnode) {
atomic_sub_fetch_32(&pDnode->openVnodes, 1);
}
clusterReleaseDnode(pDnode);
mgmtReleaseDnode(pDnode);
}
return TSDB_CODE_SUCCESS;
......@@ -381,18 +381,18 @@ int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
pShow->pNode = pVgroup;
}
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
return 0;
}
char *mgmtGetVnodeStatus(SVgObj *pVgroup, SVnodeGid *pVnode) {
SDnodeObj *pDnode = clusterGetDnode(pVnode->dnodeId);
SDnodeObj *pDnode = mgmtGetDnode(pVnode->dnodeId);
if (pDnode == NULL) {
mError("vgroup:%d, not exist in dnode:%d", pVgroup->vgId, pDnode->dnodeId);
return "null";
}
clusterReleaseDnode(pDnode);
mgmtReleaseDnode(pDnode);
if (pDnode->status == TAOS_DN_STATUS_OFFLINE) {
return "offline";
......@@ -467,7 +467,7 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo
}
pShow->numOfReads += numOfRows;
mgmtReleaseDb(pDb);
mgmtDecDbRef(pDb);
return numOfRows;
}
......@@ -676,13 +676,13 @@ static void mgmtProcessVnodeCfgMsg(SRpcMsg *rpcMsg) {
pCfg->dnodeId = htonl(pCfg->dnodeId);
pCfg->vgId = htonl(pCfg->vgId);
SDnodeObj *pDnode = clusterGetDnode(pCfg->dnodeId);
SDnodeObj *pDnode = mgmtGetDnode(pCfg->dnodeId);
if (pDnode == NULL) {
mTrace("dnode:%s, invalid dnode", taosIpStr(pCfg->dnodeId), pCfg->vgId);
mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_NOT_ACTIVE_VNODE);
return;
}
clusterReleaseDnode(pDnode);
mgmtReleaseDnode(pDnode);
SVgObj *pVgroup = mgmtGetVgroup(pCfg->vgId);
if (pVgroup == NULL) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册