提交 f6265074 编写于 作者: S slguan

reorganize the file mgmtAcct.c and mgmtUser.c

上级 dfafa1be
...@@ -51,7 +51,6 @@ extern int tsAcctUpdateSize; ...@@ -51,7 +51,6 @@ extern int tsAcctUpdateSize;
extern int tsDbUpdateSize; extern int tsDbUpdateSize;
extern int tsDnodeUpdateSize; extern int tsDnodeUpdateSize;
extern int tsMnodeUpdateSize; extern int tsMnodeUpdateSize;
extern int tsUserUpdateSize;
extern int tsVgUpdateSize; extern int tsVgUpdateSize;
typedef struct { typedef struct {
......
...@@ -22,21 +22,13 @@ extern "C" { ...@@ -22,21 +22,13 @@ extern "C" {
#include "mnode.h" #include "mnode.h"
int32_t mgmtCreateAcct(char *name, char *pass, SAcctCfg *pCfg);
int32_t mgmtUpdateAcct(SAcctObj *pAcct);
int32_t mgmtDropAcct(char *name);
int32_t mgmtAddDbIntoAcct(SAcctObj *pAcct, SDbObj *pDb); int32_t mgmtAddDbIntoAcct(SAcctObj *pAcct, SDbObj *pDb);
int32_t mgmtRemoveDbFromAcct(SAcctObj *pAcct, SDbObj *pDb); int32_t mgmtRemoveDbFromAcct(SAcctObj *pAcct, SDbObj *pDb);
int32_t mgmtAddUserIntoAcct(SAcctObj *pAcct, SUserObj *pUser); int32_t mgmtAddUserIntoAcct(SAcctObj *pAcct, SUserObj *pUser);
int32_t mgmtRemoveUserFromAcct(SAcctObj *pAcct, SUserObj *pUser); int32_t mgmtRemoveUserFromAcct(SAcctObj *pAcct, SUserObj *pUser);
int32_t mgmtAddConnIntoAcct(SConnObj *pConn);
int32_t mgmtRemoveConnFromAcct(SConnObj *pConn);
int32_t mgmtAlterAcct(char *name, char *pass, SAcctCfg *pCfg);
int64_t mgmtGetAcctStatistic(SAcctObj *pAcct);
extern int32_t (*mgmtInitAccts)(); extern int32_t (*mgmtInitAccts)();
extern SAcctObj* (*mgmtGetAcct)(char *acctName); extern SAcctObj* (*mgmtGetAcct)(char *acctName);
extern void (*mgmtCreateRootAcct)();
extern int32_t (*mgmtCheckUserLimit)(SAcctObj *pAcct); extern int32_t (*mgmtCheckUserLimit)(SAcctObj *pAcct);
extern int32_t (*mgmtCheckDbLimit)(SAcctObj *pAcct); extern int32_t (*mgmtCheckDbLimit)(SAcctObj *pAcct);
extern int32_t (*mgmtCheckTableLimit)(SAcctObj *pAcct, SCreateTableMsg *pCreate); extern int32_t (*mgmtCheckTableLimit)(SAcctObj *pAcct, SCreateTableMsg *pCreate);
...@@ -45,10 +37,6 @@ extern void (*mgmtCleanUpAccts)(); ...@@ -45,10 +37,6 @@ extern void (*mgmtCleanUpAccts)();
extern int32_t (*mgmtGetAcctMeta)(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn); extern int32_t (*mgmtGetAcctMeta)(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn);
extern int32_t (*mgmtRetrieveAccts)(SShowObj *pShow, char *data, int32_t rows, SConnObj *pConn); extern int32_t (*mgmtRetrieveAccts)(SShowObj *pShow, char *data, int32_t rows, SConnObj *pConn);
void mgmtAddMeterStatisticToAcct(SAcctObj *pAcct, int numOfColumns);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -24,13 +24,13 @@ extern "C" { ...@@ -24,13 +24,13 @@ extern "C" {
#include <stdbool.h> #include <stdbool.h>
#include "mnode.h" #include "mnode.h"
int mgmtInitUsers(); int32_t mgmtInitUsers();
SUserObj *mgmtGetUser(char *name); SUserObj *mgmtGetUser(char *name);
int mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass); int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass);
int mgmtDropUser(SAcctObj *pAcct, char *name); int32_t mgmtDropUser(SAcctObj *pAcct, char *name);
int mgmtUpdateUser(SUserObj *pUser); int32_t mgmtUpdateUser(SUserObj *pUser);
int mgmtGetUserMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn); int32_t mgmtGetUserMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn);
int mgmtRetrieveUsers(SShowObj *pShow, char *data, int rows, SConnObj *pConn); int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, SConnObj *pConn);
void mgmtCleanUpUsers(); void mgmtCleanUpUsers();
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -15,26 +15,25 @@ ...@@ -15,26 +15,25 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "tschemautil.h"
#include "taoserror.h"
#include "mnode.h" #include "mnode.h"
#include "mgmtAcct.h" #include "mgmtAcct.h"
#include "mgmtTable.h" #include "mgmtTable.h"
#include "mgmtUser.h" #include "mgmtUser.h"
#include "tschemautil.h"
#include "taoserror.h"
extern void *userSdb; extern void *tsUserSdb;
extern void *dbSdb; extern void *tsDbSdb;
SAcctObj acctObj; SAcctObj acctObj;
int mgmtGetAcctsNum(); int32_t mgmtAddDbIntoAcct(SAcctObj *pAcct, SDbObj *pDb) {
SShowObj *mgmtGetNextAcct(SShowObj *pShow, SAcctObj **pAcct);
int mgmtAddDbIntoAcct(SAcctObj *pAcct, SDbObj *pDb) {
pthread_mutex_lock(&pAcct->mutex); pthread_mutex_lock(&pAcct->mutex);
pDb->next = pAcct->pHead; pDb->next = pAcct->pHead;
pDb->prev = NULL; pDb->prev = NULL;
if (pAcct->pHead) pAcct->pHead->prev = pDb; if (pAcct->pHead) {
pAcct->pHead->prev = pDb;
}
pAcct->pHead = pDb; pAcct->pHead = pDb;
pAcct->acctInfo.numOfDbs++; pAcct->acctInfo.numOfDbs++;
...@@ -43,13 +42,19 @@ int mgmtAddDbIntoAcct(SAcctObj *pAcct, SDbObj *pDb) { ...@@ -43,13 +42,19 @@ int mgmtAddDbIntoAcct(SAcctObj *pAcct, SDbObj *pDb) {
return 0; return 0;
} }
int mgmtRemoveDbFromAcct(SAcctObj *pAcct, SDbObj *pDb) { int32_t mgmtRemoveDbFromAcct(SAcctObj *pAcct, SDbObj *pDb) {
pthread_mutex_lock(&pAcct->mutex); pthread_mutex_lock(&pAcct->mutex);
if (pDb->prev) pDb->prev->next = pDb->next; if (pDb->prev) {
pDb->prev->next = pDb->next;
}
if (pDb->next) pDb->next->prev = pDb->prev; if (pDb->next) {
pDb->next->prev = pDb->prev;
}
if (pDb->prev == NULL) pAcct->pHead = pDb->next; if (pDb->prev == NULL) {
pAcct->pHead = pDb->next;
}
pAcct->acctInfo.numOfDbs--; pAcct->acctInfo.numOfDbs--;
pthread_mutex_unlock(&pAcct->mutex); pthread_mutex_unlock(&pAcct->mutex);
...@@ -57,12 +62,14 @@ int mgmtRemoveDbFromAcct(SAcctObj *pAcct, SDbObj *pDb) { ...@@ -57,12 +62,14 @@ int mgmtRemoveDbFromAcct(SAcctObj *pAcct, SDbObj *pDb) {
return 0; return 0;
} }
int mgmtAddUserIntoAcct(SAcctObj *pAcct, SUserObj *pUser) { int32_t mgmtAddUserIntoAcct(SAcctObj *pAcct, SUserObj *pUser) {
pthread_mutex_lock(&pAcct->mutex); pthread_mutex_lock(&pAcct->mutex);
pUser->next = pAcct->pUser; pUser->next = pAcct->pUser;
pUser->prev = NULL; pUser->prev = NULL;
if (pAcct->pUser) pAcct->pUser->prev = pUser; if (pAcct->pUser) {
pAcct->pUser->prev = pUser;
}
pAcct->pUser = pUser; pAcct->pUser = pUser;
pAcct->acctInfo.numOfUsers++; pAcct->acctInfo.numOfUsers++;
...@@ -71,13 +78,17 @@ int mgmtAddUserIntoAcct(SAcctObj *pAcct, SUserObj *pUser) { ...@@ -71,13 +78,17 @@ int mgmtAddUserIntoAcct(SAcctObj *pAcct, SUserObj *pUser) {
return 0; return 0;
} }
int mgmtRemoveUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) { int32_t mgmtRemoveUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) {
pthread_mutex_lock(&pAcct->mutex); pthread_mutex_lock(&pAcct->mutex);
if (pUser->prev) pUser->prev->next = pUser->next; if (pUser->prev) {
pUser->prev->next = pUser->next;
}
if (pUser->next) pUser->next->prev = pUser->prev; if (pUser->next) pUser->next->prev = pUser->prev;
if (pUser->prev == NULL) pAcct->pUser = pUser->next; if (pUser->prev == NULL) {
pAcct->pUser = pUser->next;
}
pAcct->acctInfo.numOfUsers--; pAcct->acctInfo.numOfUsers--;
pthread_mutex_unlock(&pAcct->mutex); pthread_mutex_unlock(&pAcct->mutex);
...@@ -85,85 +96,44 @@ int mgmtRemoveUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) { ...@@ -85,85 +96,44 @@ int mgmtRemoveUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) {
return 0; return 0;
} }
int mgmtAddConnIntoAcct(SConnObj *pConn) { int32_t mgmtInitAcctsImp() {
SAcctObj *pAcct = pConn->pAcct;
if (pAcct == NULL) return 0;
pthread_mutex_lock(&pAcct->mutex);
assert(pConn != pAcct->pConn);
pConn->next = pAcct->pConn;
pConn->prev = NULL;
if (pAcct->pConn) pAcct->pConn->prev = pConn;
pAcct->pConn = pConn;
pAcct->acctInfo.numOfConns++;
pthread_mutex_unlock(&pAcct->mutex);
return 0;
}
int mgmtRemoveConnFromAcct(SConnObj *pConn) {
SAcctObj *pAcct = pConn->pAcct;
if (pAcct == NULL) return 0;
pthread_mutex_lock(&pAcct->mutex);
if (pConn->prev) pConn->prev->next = pConn->next;
if (pConn->next) pConn->next->prev = pConn->prev;
if (pConn->prev == NULL) pAcct->pConn = pConn->next;
pAcct->acctInfo.numOfConns--;
// pAcct->numOfUsers--;
if (pConn->pQList) {
pAcct->acctInfo.numOfQueries -= pConn->pQList->numOfQueries;
pAcct->acctInfo.numOfStreams -= pConn->pSList->numOfStreams;
}
pthread_mutex_unlock(&pAcct->mutex);
pConn->next = NULL;
pConn->prev = NULL;
return 0; return 0;
} }
int32_t mgmtInitAcctsImp() { return 0; }
int32_t (*mgmtInitAccts)() = mgmtInitAcctsImp; int32_t (*mgmtInitAccts)() = mgmtInitAcctsImp;
void mgmtCreateRootAcctImp() {} SAcctObj *mgmtGetAcctImp(char *acctName) {
void (*mgmtCreateRootAcct)() = mgmtCreateRootAcctImp; return &acctObj;
}
SAcctObj *mgmtGetAcctImp(char *acctName) { return &acctObj; } SAcctObj *(*mgmtGetAcct)(char *acctName) = mgmtGetAcctImp;
SAcctObj* (*mgmtGetAcct)(char *acctName) = mgmtGetAcctImp;
int32_t mgmtCheckUserLimitImp(SAcctObj *pAcct) { int32_t mgmtCheckUserLimitImp(SAcctObj *pAcct) {
int numOfUsers = sdbGetNumOfRows(userSdb); int32_t numOfUsers = sdbGetNumOfRows(tsUserSdb);
if (numOfUsers >= tsMaxUsers) { if (numOfUsers >= tsMaxUsers) {
mWarn("numOfUsers:%d, exceed tsMaxUsers:%d", numOfUsers, tsMaxUsers); mWarn("numOfUsers:%d, exceed tsMaxUsers:%d", numOfUsers, tsMaxUsers);
return TSDB_CODE_TOO_MANY_USERS; return TSDB_CODE_TOO_MANY_USERS;
} }
return 0; return 0;
} }
int32_t (*mgmtCheckUserLimit)(SAcctObj *pAcct) = mgmtCheckUserLimitImp; int32_t (*mgmtCheckUserLimit)(SAcctObj *pAcct) = mgmtCheckUserLimitImp;
int32_t mgmtCheckDbLimitImp(SAcctObj *pAcct) { int32_t mgmtCheckDbLimitImp(SAcctObj *pAcct) {
int numOfDbs = sdbGetNumOfRows(dbSdb); int32_t numOfDbs = sdbGetNumOfRows(tsDbSdb);
if (numOfDbs >= tsMaxDbs) { if (numOfDbs >= tsMaxDbs) {
mWarn("numOfDbs:%d, exceed tsMaxDbs:%d", numOfDbs, tsMaxDbs); mWarn("numOfDbs:%d, exceed tsMaxDbs:%d", numOfDbs, tsMaxDbs);
return TSDB_CODE_TOO_MANY_DATABASES; return TSDB_CODE_TOO_MANY_DATABASES;
} }
return 0; return 0;
} }
int32_t (*mgmtCheckDbLimit)(SAcctObj *pAcct) = mgmtCheckDbLimitImp; int32_t (*mgmtCheckDbLimit)(SAcctObj *pAcct) = mgmtCheckDbLimitImp;
int32_t mgmtCheckTableLimitImp(SAcctObj *pAcct, SCreateTableMsg *pCreate) { return 0; } int32_t mgmtCheckTableLimitImp(SAcctObj *pAcct, SCreateTableMsg *pCreate) {
return 0;
}
int32_t (*mgmtCheckTableLimit)(SAcctObj *pAcct, SCreateTableMsg *pCreate) = mgmtCheckTableLimitImp; int32_t (*mgmtCheckTableLimit)(SAcctObj *pAcct, SCreateTableMsg *pCreate) = mgmtCheckTableLimitImp;
void mgmtCheckAcctImp() { void mgmtCheckAcctImp() {
...@@ -175,19 +145,22 @@ void mgmtCheckAcctImp() { ...@@ -175,19 +145,22 @@ void mgmtCheckAcctImp() {
mgmtCreateUser(pAcct, "monitor", tsInternalPass); mgmtCreateUser(pAcct, "monitor", tsInternalPass);
mgmtCreateUser(pAcct, "_root", tsInternalPass); mgmtCreateUser(pAcct, "_root", tsInternalPass);
} }
void (*mgmtCheckAcct)() = mgmtCheckAcctImp;
void mgmtCleanUpAcctsImp() {} void (*mgmtCheckAcct)() = mgmtCheckAcctImp;
void (*mgmtCleanUpAccts)() = mgmtCleanUpAcctsImp;
int32_t mgmtGetAcctMetaImp(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { return TSDB_CODE_OPS_NOT_SUPPORT; } void mgmtCleanUpAcctsImp() {
int32_t (*mgmtGetAcctMeta)(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) = mgmtGetAcctMetaImp; }
int32_t mgmtRetrieveAcctsImp(SShowObj *pShow, char *data, int rows, SConnObj *pConn) { return 0; } void (*mgmtCleanUpAccts)() = mgmtCleanUpAcctsImp;
int32_t (*mgmtRetrieveAccts)(SShowObj *pShow, char *data, int rows, SConnObj *pConn) = mgmtRetrieveAcctsImp;
int32_t mgmtGetAcctMetaImp(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) {
return TSDB_CODE_OPS_NOT_SUPPORT;
}
int32_t (*mgmtGetAcctMeta)(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) = mgmtGetAcctMetaImp;
void mgmtAddMeterStatisticToAcct(SAcctObj *pAcct, int numOfColumns) { int32_t mgmtRetrieveAcctsImp(SShowObj *pShow, char *data, int32_t rows, SConnObj *pConn) {
pAcct->acctInfo.numOfTimeSeries += (numOfColumns - 1); return 0;
} }
int32_t (*mgmtRetrieveAccts)(SShowObj *pShow, char *data, int32_t rows, SConnObj *pConn) = mgmtRetrieveAcctsImp;
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "mnode.h" #include "mnode.h"
#include "taoserror.h" #include "taoserror.h"
void *dbSdb = NULL; void *tsDbSdb = NULL;
extern void *vgSdb; extern void *vgSdb;
int tsDbUpdateSize; int tsDbUpdateSize;
...@@ -83,14 +83,14 @@ int32_t mgmtInitDbs() { ...@@ -83,14 +83,14 @@ int32_t mgmtInitDbs() {
mgmtDbActionInit(); mgmtDbActionInit();
dbSdb = sdbOpenTable(tsMaxDbs, sizeof(SDbObj), "db", SDB_KEYTYPE_STRING, tsMgmtDirectory, mgmtDbAction); tsDbSdb = sdbOpenTable(tsMaxDbs, sizeof(SDbObj), "db", SDB_KEYTYPE_STRING, tsMgmtDirectory, mgmtDbAction);
if (dbSdb == NULL) { if (tsDbSdb == NULL) {
mError("failed to init db data"); mError("failed to init db data");
return -1; return -1;
} }
while (1) { while (1) {
pNode = sdbFetchRow(dbSdb, pNode, (void **)&pDb); pNode = sdbFetchRow(tsDbSdb, pNode, (void **)&pDb);
if (pDb == NULL) break; if (pDb == NULL) break;
pDb->pHead = NULL; pDb->pHead = NULL;
...@@ -118,7 +118,7 @@ int32_t mgmtInitDbs() { ...@@ -118,7 +118,7 @@ int32_t mgmtInitDbs() {
return 0; return 0;
} }
SDbObj *mgmtGetDb(char *db) { return (SDbObj *)sdbGetRow(dbSdb, db); } SDbObj *mgmtGetDb(char *db) { return (SDbObj *)sdbGetRow(tsDbSdb, db); }
SDbObj *mgmtGetDbByMeterId(char *meterId) { SDbObj *mgmtGetDbByMeterId(char *meterId) {
char db[TSDB_TABLE_ID_LEN], *pos; char db[TSDB_TABLE_ID_LEN], *pos;
...@@ -128,7 +128,7 @@ SDbObj *mgmtGetDbByMeterId(char *meterId) { ...@@ -128,7 +128,7 @@ SDbObj *mgmtGetDbByMeterId(char *meterId) {
memset(db, 0, sizeof(db)); memset(db, 0, sizeof(db));
strncpy(db, meterId, pos - meterId); strncpy(db, meterId, pos - meterId);
return (SDbObj *)sdbGetRow(dbSdb, db); return (SDbObj *)sdbGetRow(tsDbSdb, db);
} }
int mgmtCheckDbParams(SCreateDbMsg *pCreate) { int mgmtCheckDbParams(SCreateDbMsg *pCreate) {
...@@ -185,7 +185,7 @@ int mgmtCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate) { ...@@ -185,7 +185,7 @@ int mgmtCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate) {
return code; return code;
} }
pDb = (SDbObj *)sdbGetRow(dbSdb, pCreate->db); pDb = (SDbObj *)sdbGetRow(tsDbSdb, pCreate->db);
if (pDb != NULL) { if (pDb != NULL) {
return TSDB_CODE_DB_ALREADY_EXIST; return TSDB_CODE_DB_ALREADY_EXIST;
} }
...@@ -207,7 +207,7 @@ int mgmtCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate) { ...@@ -207,7 +207,7 @@ int mgmtCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate) {
pDb->createdTime = taosGetTimestampMs(); pDb->createdTime = taosGetTimestampMs();
pDb->cfg = *pCreate; pDb->cfg = *pCreate;
if (sdbInsertRow(dbSdb, pDb, 0) < 0) { if (sdbInsertRow(tsDbSdb, pDb, 0) < 0) {
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_SDB_ERROR;
tfree(pDb); tfree(pDb);
} }
...@@ -215,7 +215,7 @@ int mgmtCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate) { ...@@ -215,7 +215,7 @@ int mgmtCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate) {
return code; return code;
} }
int mgmtUpdateDb(SDbObj *pDb) { return sdbUpdateRow(dbSdb, pDb, tsDbUpdateSize, 1); } int mgmtUpdateDb(SDbObj *pDb) { return sdbUpdateRow(tsDbSdb, pDb, tsDbUpdateSize, 1); }
int mgmtSetDbDropping(SDbObj *pDb) { int mgmtSetDbDropping(SDbObj *pDb) {
if (pDb->dropStatus == TSDB_DB_STATUS_DROP_FROM_SDB) return 0; if (pDb->dropStatus == TSDB_DB_STATUS_DROP_FROM_SDB) return 0;
...@@ -288,7 +288,7 @@ void mgmtDropDbFromSdb(SDbObj *pDb) { ...@@ -288,7 +288,7 @@ void mgmtDropDbFromSdb(SDbObj *pDb) {
} }
mPrint("db:%s all meters drop finished", pDb->name); mPrint("db:%s all meters drop finished", pDb->name);
sdbDeleteRow(dbSdb, pDb); sdbDeleteRow(tsDbSdb, pDb);
mPrint("db:%s database drop finished", pDb->name); mPrint("db:%s database drop finished", pDb->name);
} }
...@@ -317,7 +317,7 @@ int mgmtDropDb(SDbObj *pDb) { ...@@ -317,7 +317,7 @@ int mgmtDropDb(SDbObj *pDb) {
int mgmtDropDbByName(SAcctObj *pAcct, char *name, short ignoreNotExists) { int mgmtDropDbByName(SAcctObj *pAcct, char *name, short ignoreNotExists) {
SDbObj *pDb; SDbObj *pDb;
pDb = (SDbObj *)sdbGetRow(dbSdb, name); pDb = (SDbObj *)sdbGetRow(tsDbSdb, name);
if (pDb == NULL) { if (pDb == NULL) {
if (ignoreNotExists) return TSDB_CODE_SUCCESS; if (ignoreNotExists) return TSDB_CODE_SUCCESS;
mWarn("db:%s is not there", name); mWarn("db:%s is not there", name);
...@@ -336,7 +336,7 @@ void mgmtMonitorDbDrop(void *unused, void *unusedt) { ...@@ -336,7 +336,7 @@ void mgmtMonitorDbDrop(void *unused, void *unusedt) {
SDbObj *pDb = NULL; SDbObj *pDb = NULL;
while (1) { while (1) {
pNode = sdbFetchRow(dbSdb, pNode, (void **)&pDb); pNode = sdbFetchRow(tsDbSdb, pNode, (void **)&pDb);
if (pDb == NULL) break; if (pDb == NULL) break;
if (pDb->dropStatus != TSDB_DB_STATUS_DROPPING) continue; if (pDb->dropStatus != TSDB_DB_STATUS_DROPPING) continue;
mgmtDropDb(pDb); mgmtDropDb(pDb);
...@@ -348,7 +348,7 @@ int mgmtAlterDb(SAcctObj *pAcct, SAlterDbMsg *pAlter) { ...@@ -348,7 +348,7 @@ int mgmtAlterDb(SAcctObj *pAcct, SAlterDbMsg *pAlter) {
SDbObj *pDb; SDbObj *pDb;
int code = TSDB_CODE_SUCCESS; int code = TSDB_CODE_SUCCESS;
pDb = (SDbObj *)sdbGetRow(dbSdb, pAlter->db); pDb = (SDbObj *)sdbGetRow(tsDbSdb, pAlter->db);
if (pDb == NULL) { if (pDb == NULL) {
mTrace("db:%s is not exist", pAlter->db); mTrace("db:%s is not exist", pAlter->db);
return TSDB_CODE_INVALID_DB; return TSDB_CODE_INVALID_DB;
...@@ -385,7 +385,7 @@ int mgmtAlterDb(SAcctObj *pAcct, SAlterDbMsg *pAlter) { ...@@ -385,7 +385,7 @@ int mgmtAlterDb(SAcctObj *pAcct, SAlterDbMsg *pAlter) {
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_INVALID_OPTION;
} }
if (sdbUpdateRow(dbSdb, pDb, tsDbUpdateSize, 1) < 0) { if (sdbUpdateRow(tsDbSdb, pDb, tsDbUpdateSize, 1) < 0) {
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_SDB_ERROR;
} }
...@@ -488,7 +488,7 @@ int mgmtShowTables(SAcctObj *pAcct, char *db) { ...@@ -488,7 +488,7 @@ int mgmtShowTables(SAcctObj *pAcct, char *db) {
return code; return code;
} }
void mgmtCleanUpDbs() { sdbCloseTable(dbSdb); } void mgmtCleanUpDbs() { sdbCloseTable(tsDbSdb); }
int mgmtGetDbMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { int mgmtGetDbMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) {
int cols = 0; int cols = 0;
...@@ -623,7 +623,7 @@ int mgmtGetDbMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { ...@@ -623,7 +623,7 @@ int mgmtGetDbMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) {
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
// pShow->numOfRows = sdbGetNumOfRows (dbSdb); // pShow->numOfRows = sdbGetNumOfRows (tsDbSdb);
pShow->numOfRows = pConn->pAcct->acctInfo.numOfDbs; pShow->numOfRows = pConn->pAcct->acctInfo.numOfDbs;
pShow->pNode = pConn->pAcct->pHead; pShow->pNode = pConn->pAcct->pHead;
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "mgmtSystem.h" #include "mgmtSystem.h"
#include "mgmtTable.h" #include "mgmtTable.h"
#include "mgmtShell.h" #include "mgmtShell.h"
#include "dnodeModule.h"
char tsMgmtDirectory[128] = {0}; char tsMgmtDirectory[128] = {0};
void *tsMgmtTmr = NULL; void *tsMgmtTmr = NULL;
......
...@@ -15,69 +15,58 @@ ...@@ -15,69 +15,58 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "tschemautil.h"
#include "ttime.h"
#include "mnode.h" #include "mnode.h"
#include "mgmtAcct.h" #include "mgmtAcct.h"
#include "mgmtUser.h" #include "mgmtUser.h"
#include "mgmtGrant.h" #include "mgmtGrant.h"
#include "mgmtTable.h" #include "mgmtTable.h"
#include "tschemautil.h"
#include "ttime.h"
void *userSdb = NULL; void *tsUserSdb = NULL;
int tsUserUpdateSize;
void *(*mgmtUserActionFp[SDB_MAX_ACTION_TYPES])(void *row, char *str, int size, int *ssize);
void *mgmtUserActionInsert(void *row, char *str, int size, int *ssize);
void *mgmtUserActionDelete(void *row, char *str, int size, int *ssize);
void *mgmtUserActionUpdate(void *row, char *str, int size, int *ssize);
void *mgmtUserActionEncode(void *row, char *str, int size, int *ssize);
void *mgmtUserActionDecode(void *row, char *str, int size, int *ssize);
void *mgmtUserActionBeforeBatchUpdate(void *row, char *str, int size, int *ssize);
void *mgmtUserActionBatchUpdate(void *row, char *str, int size, int *ssize);
void *mgmtUserActionAfterBatchUpdate(void *row, char *str, int size, int *ssize);
void *mgmtUserActionReset(void *row, char *str, int size, int *ssize);
void *mgmtUserActionDestroy(void *row, char *str, int size, int *ssize);
void *(*mgmtUserActionFp[SDB_MAX_ACTION_TYPES])(void *row, char *str, int32_t size, int32_t *ssize);
void *mgmtUserActionInsert(void *row, char *str, int32_t size, int32_t *ssize);
void *mgmtUserActionDelete(void *row, char *str, int32_t size, int32_t *ssize);
void *mgmtUserActionUpdate(void *row, char *str, int32_t size, int32_t *ssize);
void *mgmtUserActionEncode(void *row, char *str, int32_t size, int32_t *ssize);
void *mgmtUserActionDecode(void *row, char *str, int32_t size, int32_t *ssize);
void *mgmtUserActionReset(void *row, char *str, int32_t size, int32_t *ssize);
void *mgmtUserActionDestroy(void *row, char *str, int32_t size, int32_t *ssize);
void mgmtUserActionInit() { void mgmtUserActionInit() {
mgmtUserActionFp[SDB_TYPE_INSERT] = mgmtUserActionInsert; mgmtUserActionFp[SDB_TYPE_INSERT] = mgmtUserActionInsert;
mgmtUserActionFp[SDB_TYPE_DELETE] = mgmtUserActionDelete; mgmtUserActionFp[SDB_TYPE_DELETE] = mgmtUserActionDelete;
mgmtUserActionFp[SDB_TYPE_UPDATE] = mgmtUserActionUpdate; mgmtUserActionFp[SDB_TYPE_UPDATE] = mgmtUserActionUpdate;
mgmtUserActionFp[SDB_TYPE_ENCODE] = mgmtUserActionEncode; mgmtUserActionFp[SDB_TYPE_ENCODE] = mgmtUserActionEncode;
mgmtUserActionFp[SDB_TYPE_DECODE] = mgmtUserActionDecode; mgmtUserActionFp[SDB_TYPE_DECODE] = mgmtUserActionDecode;
mgmtUserActionFp[SDB_TYPE_BEFORE_BATCH_UPDATE] = mgmtUserActionBeforeBatchUpdate; mgmtUserActionFp[SDB_TYPE_RESET] = mgmtUserActionReset;
mgmtUserActionFp[SDB_TYPE_BATCH_UPDATE] = mgmtUserActionBatchUpdate;
mgmtUserActionFp[SDB_TYPE_AFTER_BATCH_UPDATE] = mgmtUserActionAfterBatchUpdate;
mgmtUserActionFp[SDB_TYPE_RESET] = mgmtUserActionReset;
mgmtUserActionFp[SDB_TYPE_DESTROY] = mgmtUserActionDestroy; mgmtUserActionFp[SDB_TYPE_DESTROY] = mgmtUserActionDestroy;
} }
void *mgmtUserAction(char action, void *row, char *str, int size, int *ssize) { void *mgmtUserAction(char action, void *row, char *str, int32_t size, int32_t *ssize) {
if (mgmtUserActionFp[(uint8_t)action] != NULL) { if (mgmtUserActionFp[(uint8_t) action] != NULL) {
return (*(mgmtUserActionFp[(uint8_t)action]))(row, str, size, ssize); return (*(mgmtUserActionFp[(uint8_t) action]))(row, str, size, ssize);
} }
return NULL; return NULL;
} }
int mgmtInitUsers() { int32_t mgmtInitUsers() {
void * pNode = NULL; void *pNode = NULL;
SUserObj *pUser = NULL; SUserObj *pUser = NULL;
SAcctObj *pAcct = NULL; SAcctObj *pAcct = NULL;
int numOfUsers = 0; int32_t numOfUsers = 0;
mgmtUserActionInit(); mgmtUserActionInit();
userSdb = sdbOpenTable(tsMaxUsers, sizeof(SUserObj), "user", SDB_KEYTYPE_STRING, tsMgmtDirectory, mgmtUserAction); tsUserSdb = sdbOpenTable(tsMaxUsers, sizeof(SUserObj), "user", SDB_KEYTYPE_STRING, tsMgmtDirectory, mgmtUserAction);
if (userSdb == NULL) { if (tsUserSdb == NULL) {
mError("failed to init user data"); mError("failed to init user data");
return -1; return -1;
} }
mgmtCreateRootAcct();
while (1) { while (1) {
pNode = sdbFetchRow(userSdb, pNode, (void **)&pUser); pNode = sdbFetchRow(tsUserSdb, pNode, (void **)&pUser);
if (pUser == NULL) break; if (pUser == NULL) break;
pUser->prev = NULL; pUser->prev = NULL;
...@@ -89,27 +78,28 @@ int mgmtInitUsers() { ...@@ -89,27 +78,28 @@ int mgmtInitUsers() {
numOfUsers++; numOfUsers++;
} }
SUserObj tObj;
tsUserUpdateSize = tObj.updateEnd - (char *)&tObj;
mTrace("user data is initialized"); mTrace("user data is initialized");
return 0; return 0;
} }
SUserObj *mgmtGetUser(char *name) { return (SUserObj *)sdbGetRow(userSdb, name); } SUserObj *mgmtGetUser(char *name) {
return (SUserObj *)sdbGetRow(tsUserSdb, name);
}
int mgmtUpdateUser(SUserObj *pUser) { return sdbUpdateRow(userSdb, pUser, 0, 1); } int32_t mgmtUpdateUser(SUserObj *pUser) {
return sdbUpdateRow(tsUserSdb, pUser, 0, 1);
}
int mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) { int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
SUserObj *pUser; SUserObj *pUser;
int code; int32_t code;
code = mgmtCheckUserLimit(pAcct); code = mgmtCheckUserLimit(pAcct);
if (code != 0) { if (code != 0) {
return code; return code;
} }
pUser = (SUserObj *)sdbGetRow(userSdb, name); pUser = (SUserObj *)sdbGetRow(tsUserSdb, name);
if (pUser != NULL) { if (pUser != NULL) {
mWarn("user:%s is already there", name); mWarn("user:%s is already there", name);
return TSDB_CODE_USER_ALREADY_EXIST; return TSDB_CODE_USER_ALREADY_EXIST;
...@@ -133,37 +123,38 @@ int mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) { ...@@ -133,37 +123,38 @@ int mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
} }
code = TSDB_CODE_SUCCESS; code = TSDB_CODE_SUCCESS;
if (sdbInsertRow(userSdb, pUser, 0) < 0) { if (sdbInsertRow(tsUserSdb, pUser, 0) < 0) {
tfree(pUser); tfree(pUser);
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_SDB_ERROR;
} }
// mgmtAddUserIntoAcct(pAcct, pUser);
return code; return code;
} }
int mgmtDropUser(SAcctObj *pAcct, char *name) { int32_t mgmtDropUser(SAcctObj *pAcct, char *name) {
SUserObj *pUser; SUserObj *pUser;
pUser = (SUserObj *)sdbGetRow(userSdb, name); pUser = (SUserObj *)sdbGetRow(tsUserSdb, name);
if (pUser == NULL) { if (pUser == NULL) {
mWarn("user:%s is not there", name); mWarn("user:%s is not there", name);
return TSDB_CODE_INVALID_USER; return TSDB_CODE_INVALID_USER;
} }
if (strcmp(pAcct->user, pUser->acct) != 0) return TSDB_CODE_NO_RIGHTS; if (strcmp(pAcct->user, pUser->acct) != 0) {
return TSDB_CODE_NO_RIGHTS;
}
// mgmtRemoveUserFromAcct(pAcct, pUser); sdbDeleteRow(tsUserSdb, pUser);
sdbDeleteRow(userSdb, pUser);
return 0; return 0;
} }
void mgmtCleanUpUsers() { sdbCloseTable(userSdb); } void mgmtCleanUpUsers() {
sdbCloseTable(tsUserSdb);
}
int mgmtGetUserMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { int32_t mgmtGetUserMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) {
int cols = 0; int32_t cols = 0;
SSchema *pSchema = tsGetSchema(pMeta); SSchema *pSchema = tsGetSchema(pMeta);
pShow->bytes[cols] = TSDB_USER_LEN; pShow->bytes[cols] = TSDB_USER_LEN;
...@@ -188,9 +179,8 @@ int mgmtGetUserMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { ...@@ -188,9 +179,8 @@ int mgmtGetUserMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) {
pShow->numOfColumns = cols; pShow->numOfColumns = cols;
pShow->offset[0] = 0; pShow->offset[0] = 0;
for (int i = 1; i < cols; ++i) pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; for (int32_t i = 1; i < cols; ++i) pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
// pShow->numOfRows = sdbGetNumOfRows (userSdb);
pShow->numOfRows = pConn->pAcct->acctInfo.numOfUsers; pShow->numOfRows = pConn->pAcct->acctInfo.numOfUsers;
pShow->pNode = pConn->pAcct->pUser; pShow->pNode = pConn->pAcct->pUser;
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
...@@ -198,14 +188,13 @@ int mgmtGetUserMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { ...@@ -198,14 +188,13 @@ int mgmtGetUserMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) {
return 0; return 0;
} }
int mgmtRetrieveUsers(SShowObj *pShow, char *data, int rows, SConnObj *pConn) { int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, SConnObj *pConn) {
int numOfRows = 0; int32_t numOfRows = 0;
SUserObj *pUser = NULL; SUserObj *pUser = NULL;
char * pWrite; char * pWrite;
int cols = 0; int32_t cols = 0;
while (numOfRows < rows) { while (numOfRows < rows) {
// pShow->pNode = sdbFetchRow(userSdb, pShow->pNode, (void **)&pUser);
pUser = (SUserObj *)pShow->pNode; pUser = (SUserObj *)pShow->pNode;
if (pUser == NULL) break; if (pUser == NULL) break;
pShow->pNode = (void *)pUser->next; pShow->pNode = (void *)pUser->next;
...@@ -236,26 +225,29 @@ int mgmtRetrieveUsers(SShowObj *pShow, char *data, int rows, SConnObj *pConn) { ...@@ -236,26 +225,29 @@ int mgmtRetrieveUsers(SShowObj *pShow, char *data, int rows, SConnObj *pConn) {
return numOfRows; return numOfRows;
} }
void *mgmtUserActionInsert(void *row, char *str, int size, int *ssize) { void *mgmtUserActionInsert(void *row, char *str, int32_t size, int32_t *ssize) {
SUserObj *pUser = (SUserObj *)row; SUserObj *pUser = (SUserObj *)row;
SAcctObj *pAcct = mgmtGetAcct(pUser->acct); SAcctObj *pAcct = mgmtGetAcct(pUser->acct);
mgmtAddUserIntoAcct(pAcct, pUser); mgmtAddUserIntoAcct(pAcct, pUser);
return NULL; return NULL;
} }
void *mgmtUserActionDelete(void *row, char *str, int size, int *ssize) {
void *mgmtUserActionDelete(void *row, char *str, int32_t size, int32_t *ssize) {
SUserObj *pUser = (SUserObj *)row; SUserObj *pUser = (SUserObj *)row;
SAcctObj *pAcct = mgmtGetAcct(pUser->acct); SAcctObj *pAcct = mgmtGetAcct(pUser->acct);
mgmtRemoveUserFromAcct(pAcct, pUser); mgmtRemoveUserFromAcct(pAcct, pUser);
return NULL; return NULL;
} }
void *mgmtUserActionUpdate(void *row, char *str, int size, int *ssize) {
void *mgmtUserActionUpdate(void *row, char *str, int32_t size, int32_t *ssize) {
return mgmtUserActionReset(row, str, size, ssize); return mgmtUserActionReset(row, str, size, ssize);
} }
void *mgmtUserActionEncode(void *row, char *str, int size, int *ssize) {
void *mgmtUserActionEncode(void *row, char *str, int32_t size, int32_t *ssize) {
SUserObj *pUser = (SUserObj *)row; SUserObj *pUser = (SUserObj *)row;
int tsize = pUser->updateEnd - (char *)pUser; int32_t tsize = pUser->updateEnd - (char *)pUser;
if (size < tsize) { if (size < tsize) {
*ssize = -1; *ssize = -1;
} else { } else {
...@@ -264,27 +256,26 @@ void *mgmtUserActionEncode(void *row, char *str, int size, int *ssize) { ...@@ -264,27 +256,26 @@ void *mgmtUserActionEncode(void *row, char *str, int size, int *ssize) {
} }
return NULL; return NULL;
} }
void *mgmtUserActionDecode(void *row, char *str, int size, int *ssize) {
void *mgmtUserActionDecode(void *row, char *str, int32_t size, int32_t *ssize) {
SUserObj *pUser = (SUserObj *)malloc(sizeof(SUserObj)); SUserObj *pUser = (SUserObj *)malloc(sizeof(SUserObj));
if (pUser == NULL) return NULL; if (pUser == NULL) return NULL;
memset(pUser, 0, sizeof(SUserObj)); memset(pUser, 0, sizeof(SUserObj));
int tsize = pUser->updateEnd - (char *)pUser; int32_t tsize = pUser->updateEnd - (char *)pUser;
memcpy(pUser, str, tsize); memcpy(pUser, str, tsize);
return (void *)pUser; return (void *)pUser;
} }
void *mgmtUserActionBeforeBatchUpdate(void *row, char *str, int size, int *ssize) { return NULL; }
void *mgmtUserActionBatchUpdate(void *row, char *str, int size, int *ssize) { return NULL; } void *mgmtUserActionReset(void *row, char *str, int32_t size, int32_t *ssize) {
void *mgmtUserActionAfterBatchUpdate(void *row, char *str, int size, int *ssize) { return NULL; }
void *mgmtUserActionReset(void *row, char *str, int size, int *ssize) {
SUserObj *pUser = (SUserObj *)row; SUserObj *pUser = (SUserObj *)row;
int tsize = pUser->updateEnd - (char *)pUser; int32_t tsize = pUser->updateEnd - (char *)pUser;
memcpy(pUser, str, tsize); memcpy(pUser, str, tsize);
return NULL; return NULL;
} }
void *mgmtUserActionDestroy(void *row, char *str, int size, int *ssize) { void *mgmtUserActionDestroy(void *row, char *str, int32_t size, int32_t *ssize) {
tfree(row); tfree(row);
return NULL; return NULL;
} }
...@@ -30,9 +30,9 @@ ...@@ -30,9 +30,9 @@
void * vgSdb = NULL; void * vgSdb = NULL;
int tsVgUpdateSize; int tsVgUpdateSize;
extern void *dbSdb; extern void *tsDbSdb;
extern void *acctSdb; extern void *acctSdb;
extern void *userSdb; extern void *tsUserSdb;
extern void *dnodeSdb; extern void *dnodeSdb;
void *(*mgmtVgroupActionFp[SDB_MAX_ACTION_TYPES])(void *row, char *str, int size, int *ssize); void *(*mgmtVgroupActionFp[SDB_MAX_ACTION_TYPES])(void *row, char *str, int size, int *ssize);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册