提交 f6265074 编写于 作者: S slguan

reorganize the file mgmtAcct.c and mgmtUser.c

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