提交 79519165 编写于 作者: S Shengliang Guan

add sdb interface

上级 6d6b55ea
...@@ -16,62 +16,130 @@ ...@@ -16,62 +16,130 @@
#ifndef _TD_SDB_H_ #ifndef _TD_SDB_H_
#define _TD_SDB_H_ #define _TD_SDB_H_
#include "cJSON.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define SDB_GET_BINARY_VAL(pData, dataLen, val, valLen, code) \
{ \
if ((dataLen) >= (valLen)) { \
memcpy((val), (char *)(pData), (valLen)); \
(dataLen) -= (valLen); \
(pData) = (char *)(pData) + (valLen); \
} else { \
code = TSDB_CODE_SDB_INVAID_RAW_DATA_LEN; \
} \
}
#define SDB_GET_INT32_VAL(pData, dataLen, val, code) \
{ \
if (dataLen >= sizeof(int32_t)) { \
*(int32_t *)(pData) = (int32_t)(val); \
(dataLen) -= sizeof(int32_t); \
(pData) = (char *)(pData) + sizeof(int32_t); \
} else { \
code = TSDB_CODE_SDB_INVAID_RAW_DATA_LEN; \
} \
}
#define SDB_GET_INT64_VAL(pData, dataLen, val, code) \
{ \
if (dataLen >= sizeof(int64_t)) { \
*(int64_t *)(pData) = (int64_t)(val); \
(dataLen) -= sizeof(int64_t); \
(pData) = (char *)(pData) + sizeof(int64_t); \
} else { \
code = TSDB_CODE_SDB_INVAID_RAW_DATA_LEN; \
} \
}
#define SDB_SET_INT64_VAL(pData, dataLen, val) \
{ \
*(int64_t *)(pData) = (int64_t)(val); \
(dataLen) += sizeof(int64_t); \
(pData) += sizeof(int64_t); \
}
#define SDB_SET_INT32_VAL(pData, dataLen, val) \
{ \
*(int32_t *)(pData) = (int32_t)(val); \
(dataLen) += sizeof(int32_t); \
(pData) += sizeof(int32_t); \
}
#define SDB_SET_BINARY_VAL(pData, dataLen, val, valLen) \
{ \
memcpy((char *)(pData), (val), (valLen)); \
(dataLen) += (valLen); \
(pData) += (valLen); \
}
typedef enum { typedef enum {
MN_SDB_START = 0, SDB_START = 0,
MN_SDB_CLUSTER = 1, SDB_VERSION = 1,
MN_SDB_DNODE = 2, SDB_CLUSTER = 2,
MN_SDB_MNODE = 3, SDB_DNODE = 3,
MN_SDB_ACCT = 4, SDB_MNODE = 4,
MN_SDB_AUTH = 5, SDB_ACCT = 5,
MN_SDB_USER = 6, SDB_AUTH = 6,
MN_SDB_DB = 7, SDB_USER = 7,
MN_SDB_VGROUP = 8, SDB_DB = 8,
MN_SDB_STABLE = 9, SDB_VGROUP = 9,
MN_SDB_FUNC = 10, SDB_STABLE = 10,
MN_SDB_OPER = 11, SDB_FUNC = 11,
MN_SDB_MAX = 12 SDB_OPER = 12,
} EMnSdb; SDB_MAX = 13
} ESdbType;
typedef enum { MN_OP_START = 0, MN_OP_INSERT = 1, MN_OP_UPDATE = 2, MN_OP_DELETE = 3, MN_OP_MAX = 4 } EMnOp;
typedef enum { SDB_ACTION_INSERT = 1, SDB_ACTION_UPDATE = 2, SDB_ACTION_DELETE = 3 } ESdbAction;
typedef enum { MN_KEY_START = 0, MN_KEY_BINARY = 1, MN_KEY_INT32 = 2, MN_KEY_INT64 = 3, MN_KEY_MAX } EMnKey; typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyType;
typedef enum { SDB_STATUS_CREATING = 1, SDB_STATUS_READY, SDB_STATUS_DROPPING, SDB_STATUS_DROPPED } ESdbStatus;
typedef enum { MN_SDB_STAT_AVAIL = 0, MN_SDB_STAT_DROPPED = 1 } EMnSdbStat;
typedef struct { typedef struct {
int8_t type; int8_t type;
int8_t status; int8_t sver;
int8_t align[6]; int8_t status;
} SdbHead; int8_t action;
int8_t reserved[4];
int32_t cksum;
int32_t dataLen;
char data[];
} SSdbRawData;
typedef int32_t (*SdbInsertFp)(void *pObj);
typedef int32_t (*SdbUpdateFp)(void *pSrcObj, void *pDstObj);
typedef int32_t (*SdbDeleteFp)(void *pObj);
typedef int32_t (*SdbDeployFp)();
typedef void *(*SdbDecodeFp)(SSdbRawData *pRaw);
typedef SSdbRawData *(*SdbEncodeFp)(void *pObj);
typedef void (*SdbDeployFp)(); typedef struct {
typedef void *(*SdbDecodeFp)(cJSON *root); ESdbType sdbType;
typedef int32_t (*SdbEncodeFp)(void *pHead, char *buf, int32_t maxLen); EKeyType keyType;
SdbDeployFp deployFp;
SdbEncodeFp encodeFp;
SdbDecodeFp decodeFp;
SdbInsertFp insertFp;
SdbUpdateFp updateFp;
SdbDeleteFp deleteFp;
} SSdbDesc;
int32_t sdbInit(); int32_t sdbInit();
void sdbCleanup(); void sdbCleanup();
void sdbSetHandler(SSdbDesc desc);
int32_t sdbRead(); int32_t sdbRead();
int32_t sdbWrite(SSdbRawData *pRawData);
int32_t sdbCommit(); int32_t sdbCommit();
int32_t sdbDeploy(); int32_t sdbDeploy();
void sdbUnDeploy(); void sdbUnDeploy();
void *sdbInsertRow(EMnSdb sdb, void *pObj); void *sdbAcquire(ESdbType sdb, void *pKey);
void sdbDeleteRow(EMnSdb sdb, void *pHead); void sdbRelease(ESdbType sdb, void *pObj);
void *sdbUpdateRow(EMnSdb sdb, void *pHead); void *sdbFetch(ESdbType sdb, void *pIter);
void *sdbGetRow(EMnSdb sdb, void *pKey); void sdbCancelFetch(ESdbType sdb, void *pIter);
void *sdbFetchRow(EMnSdb sdb, void *pIter); int32_t sdbGetSize(ESdbType sdb);
void sdbCancelFetch(EMnSdb sdb, void *pIter);
int32_t sdbGetCount(EMnSdb sdb);
void sdbSetFp(EMnSdb, EMnKey, SdbDeployFp, SdbEncodeFp, SdbDecodeFp, int32_t dataSize);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -131,12 +131,15 @@ int32_t* taosGetErrno(); ...@@ -131,12 +131,15 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_FAILED_TO_CREATE_DIR TAOS_DEF_ERROR_CODE(0, 0x0313) //"failed to create mnode dir") #define TSDB_CODE_MND_FAILED_TO_CREATE_DIR TAOS_DEF_ERROR_CODE(0, 0x0313) //"failed to create mnode dir")
#define TSDB_CODE_MND_FAILED_TO_INIT_STEP TAOS_DEF_ERROR_CODE(0, 0x0314) //"failed to init components") #define TSDB_CODE_MND_FAILED_TO_INIT_STEP TAOS_DEF_ERROR_CODE(0, 0x0314) //"failed to init components")
#define TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE TAOS_DEF_ERROR_CODE(0, 0x0320) //"Object already there") #define TSDB_CODE_SDB_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0320)
#define TSDB_CODE_MND_SDB_ERROR TAOS_DEF_ERROR_CODE(0, 0x0321) //"Unexpected generic error in sdb") #define TSDB_CODE_SDB_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0321)
#define TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE TAOS_DEF_ERROR_CODE(0, 0x0322) //"Invalid table type") #define TSDB_CODE_SDB_OBJ_ALREADY_THERE TAOS_DEF_ERROR_CODE(0, 0x0322)
#define TSDB_CODE_MND_SDB_OBJ_NOT_THERE TAOS_DEF_ERROR_CODE(0, 0x0323) //"Object not there") #define TSDB_CODE_SDB_OBJ_NOT_THERE TAOS_DEF_ERROR_CODE(0, 0x0323)
#define TSDB_CODE_MND_SDB_INVAID_META_ROW TAOS_DEF_ERROR_CODE(0, 0x0324) //"Invalid meta row") #define TSDB_CODE_SDB_INVAID_RAW_DATA_VER TAOS_DEF_ERROR_CODE(0, 0x0324)
#define TSDB_CODE_MND_SDB_INVAID_KEY_TYPE TAOS_DEF_ERROR_CODE(0, 0x0325) //"Invalid key type") #define TSDB_CODE_SDB_INVAID_RAW_DATA_LEN TAOS_DEF_ERROR_CODE(0, 0x0325)
#define TSDB_CODE_SDB_INVALID_TABLE_TYPE TAOS_DEF_ERROR_CODE(0, 0x0326)
#define TSDB_CODE_SDB_INVAID_META_ROW TAOS_DEF_ERROR_CODE(0, 0x0327)
#define TSDB_CODE_SDB_INVAID_KEY_TYPE TAOS_DEF_ERROR_CODE(0, 0x0328)
#define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0330) //"DNode already exists") #define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0330) //"DNode already exists")
#define TSDB_CODE_MND_DNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0331) //"DNode does not exist") #define TSDB_CODE_MND_DNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0331) //"DNode does not exist")
...@@ -155,12 +158,12 @@ int32_t* taosGetErrno(); ...@@ -155,12 +158,12 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_DNODE_EP_NOT_CONFIGURED TAOS_DEF_ERROR_CODE(0, 0x033E) //"Dnode Ep not configured") #define TSDB_CODE_MND_DNODE_EP_NOT_CONFIGURED TAOS_DEF_ERROR_CODE(0, 0x033E) //"Dnode Ep not configured")
#define TSDB_CODE_MND_ACCT_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0340) //"Account already exists") #define TSDB_CODE_MND_ACCT_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0340) //"Account already exists")
#define TSDB_CODE_MND_INVALID_ACCT TAOS_DEF_ERROR_CODE(0, 0x0341) //"Invalid account") #define TSDB_CODE_MND_ACCT_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0341) //"Invalid account")
#define TSDB_CODE_MND_INVALID_ACCT_OPTION TAOS_DEF_ERROR_CODE(0, 0x0342) //"Invalid account options") #define TSDB_CODE_MND_INVALID_ACCT_OPTION TAOS_DEF_ERROR_CODE(0, 0x0342) //"Invalid account options")
#define TSDB_CODE_MND_ACCT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0343) //"Account authorization has expired") #define TSDB_CODE_MND_ACCT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0343) //"Account authorization has expired")
#define TSDB_CODE_MND_USER_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0350) //"User already exists") #define TSDB_CODE_MND_USER_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0350) //"User already exists")
#define TSDB_CODE_MND_INVALID_USER TAOS_DEF_ERROR_CODE(0, 0x0351) //"Invalid user") #define TSDB_CODE_MND_USER_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0351) //"Invalid user")
#define TSDB_CODE_MND_INVALID_USER_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0352) //"Invalid user format") #define TSDB_CODE_MND_INVALID_USER_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0352) //"Invalid user format")
#define TSDB_CODE_MND_INVALID_PASS_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0353) //"Invalid password format") #define TSDB_CODE_MND_INVALID_PASS_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0353) //"Invalid password format")
#define TSDB_CODE_MND_NO_USER_FROM_CONN TAOS_DEF_ERROR_CODE(0, 0x0354) //"Can not get user from conn") #define TSDB_CODE_MND_NO_USER_FROM_CONN TAOS_DEF_ERROR_CODE(0, 0x0354) //"Can not get user from conn")
......
...@@ -81,7 +81,6 @@ typedef enum { ...@@ -81,7 +81,6 @@ typedef enum {
typedef struct SClusterObj { typedef struct SClusterObj {
SdbHead head;
int64_t id; int64_t id;
char uid[TSDB_CLUSTER_ID_LEN]; char uid[TSDB_CLUSTER_ID_LEN];
int64_t createdTime; int64_t createdTime;
...@@ -89,7 +88,6 @@ typedef struct SClusterObj { ...@@ -89,7 +88,6 @@ typedef struct SClusterObj {
} SClusterObj; } SClusterObj;
typedef struct SDnodeObj { typedef struct SDnodeObj {
SdbHead head;
int32_t id; int32_t id;
int32_t vnodes; int32_t vnodes;
int64_t createdTime; int64_t createdTime;
...@@ -106,7 +104,6 @@ typedef struct SDnodeObj { ...@@ -106,7 +104,6 @@ typedef struct SDnodeObj {
} SDnodeObj; } SDnodeObj;
typedef struct SMnodeObj { typedef struct SMnodeObj {
SdbHead head;
int32_t id; int32_t id;
int8_t status; int8_t status;
int8_t role; int8_t role;
...@@ -122,8 +119,8 @@ typedef struct { ...@@ -122,8 +119,8 @@ typedef struct {
int32_t maxDbs; int32_t maxDbs;
int32_t maxTimeSeries; int32_t maxTimeSeries;
int32_t maxStreams; int32_t maxStreams;
int64_t maxStorage; // In unit of GB int64_t maxStorage; // In unit of GB
int8_t accessState; // Configured only by command int32_t accessState; // Configured only by command
} SAcctCfg; } SAcctCfg;
typedef struct { typedef struct {
...@@ -136,18 +133,16 @@ typedef struct { ...@@ -136,18 +133,16 @@ typedef struct {
} SAcctInfo; } SAcctInfo;
typedef struct SAcctObj { typedef struct SAcctObj {
SdbHead head;
char acct[TSDB_USER_LEN]; char acct[TSDB_USER_LEN];
int64_t createdTime; int64_t createdTime;
int64_t updateTime; int64_t updateTime;
int32_t acctId; int32_t acctId;
int8_t status; int32_t status;
SAcctCfg cfg; SAcctCfg cfg;
SAcctInfo info; SAcctInfo info;
} SAcctObj; } SAcctObj;
typedef struct SUserObj { typedef struct SUserObj {
SdbHead head;
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN]; char pass[TSDB_KEY_LEN];
char acct[TSDB_USER_LEN]; char acct[TSDB_USER_LEN];
...@@ -182,7 +177,6 @@ typedef struct { ...@@ -182,7 +177,6 @@ typedef struct {
} SDbCfg; } SDbCfg;
typedef struct SDbObj { typedef struct SDbObj {
SdbHead head;
char name[TSDB_FULL_DB_NAME_LEN]; char name[TSDB_FULL_DB_NAME_LEN];
char acct[TSDB_USER_LEN]; char acct[TSDB_USER_LEN];
int64_t createdTime; int64_t createdTime;
...@@ -226,7 +220,6 @@ typedef struct SVgObj { ...@@ -226,7 +220,6 @@ typedef struct SVgObj {
} SVgObj; } SVgObj;
typedef struct SSTableObj { typedef struct SSTableObj {
SdbHead head;
char tableId[TSDB_TABLE_NAME_LEN]; char tableId[TSDB_TABLE_NAME_LEN];
uint64_t uid; uint64_t uid;
int64_t createdTime; int64_t createdTime;
...@@ -237,7 +230,6 @@ typedef struct SSTableObj { ...@@ -237,7 +230,6 @@ typedef struct SSTableObj {
} SSTableObj; } SSTableObj;
typedef struct SFuncObj { typedef struct SFuncObj {
SdbHead head;
char name[TSDB_FUNC_NAME_LEN]; char name[TSDB_FUNC_NAME_LEN];
char path[128]; char path[128];
int32_t contLen; int32_t contLen;
......
...@@ -14,133 +14,117 @@ ...@@ -14,133 +14,117 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h"
#include "mnodeInt.h" #include "mnodeInt.h"
static void mnodeCreateDefaultAcct() { #define ACCT_VER 1
int32_t code = TSDB_CODE_SUCCESS;
SAcctObj acctObj = {0}; static SSdbRawData *mnodeAcctActionEncode(SAcctObj *pAcct) {
tstrncpy(acctObj.acct, TSDB_DEFAULT_USER, TSDB_USER_LEN); SSdbRawData *pRaw = calloc(1, sizeof(SAcctObj) + sizeof(SSdbRawData));
acctObj.cfg = (SAcctCfg){.maxUsers = 128, if (pRaw == NULL) {
.maxDbs = 128, terrno = TSDB_CODE_MND_OUT_OF_MEMORY;
.maxTimeSeries = INT32_MAX, return NULL;
.maxStreams = 1000, }
.maxStorage = INT64_MAX,
.accessState = TSDB_VN_ALL_ACCCESS};
acctObj.acctId = 1;
acctObj.createdTime = taosGetTimestampMs();
acctObj.updateTime = taosGetTimestampMs();
sdbInsertRow(MN_SDB_ACCT, &acctObj); int32_t dataLen = 0;
char *pData = pRaw->data;
SDB_SET_BINARY_VAL(pData, dataLen, pAcct->acct, TSDB_USER_LEN)
SDB_SET_INT64_VAL(pData, dataLen, pAcct->createdTime)
SDB_SET_INT64_VAL(pData, dataLen, pAcct->updateTime)
SDB_SET_INT32_VAL(pData, dataLen, pAcct->acctId)
SDB_SET_INT32_VAL(pData, dataLen, pAcct->status)
SDB_SET_INT32_VAL(pData, dataLen, pAcct->cfg.maxUsers)
SDB_SET_INT32_VAL(pData, dataLen, pAcct->cfg.maxDbs)
SDB_SET_INT32_VAL(pData, dataLen, pAcct->cfg.maxTimeSeries)
SDB_SET_INT32_VAL(pData, dataLen, pAcct->cfg.maxStreams)
SDB_SET_INT64_VAL(pData, dataLen, pAcct->cfg.maxStorage)
SDB_SET_INT32_VAL(pData, dataLen, pAcct->cfg.accessState)
pRaw->dataLen = dataLen;
pRaw->type = SDB_ACCT;
pRaw->sver = ACCT_VER;
return pRaw;
} }
int32_t mnodeEncodeAcct(SAcctObj *pAcct, char *buf, int32_t maxLen) { static SAcctObj *mnodeAcctActionDecode(SSdbRawData *pRaw) {
int32_t len = 0; if (pRaw->sver != ACCT_VER) {
terrno = TSDB_CODE_SDB_INVAID_RAW_DATA_VER;
len += snprintf(buf + len, maxLen - len, "{\"type\":%d, ", MN_SDB_ACCT); return NULL;
len += snprintf(buf + len, maxLen - len, "\"acct\":\"%s\", ", pAcct->acct); }
len += snprintf(buf + len, maxLen - len, "\"acctId\":\"%d\", ", pAcct->acctId);
len += snprintf(buf + len, maxLen - len, "\"maxUsers\":\"%d\", ", pAcct->cfg.maxUsers);
len += snprintf(buf + len, maxLen - len, "\"maxDbs\":\"%d\", ", pAcct->cfg.maxDbs);
len += snprintf(buf + len, maxLen - len, "\"maxTimeSeries\":\"%d\", ", pAcct->cfg.maxTimeSeries);
len += snprintf(buf + len, maxLen - len, "\"maxStreams\":\"%d\", ", pAcct->cfg.maxStreams);
len += snprintf(buf + len, maxLen - len, "\"maxStorage\":\"%" PRIu64 "\", ", pAcct->cfg.maxStorage);
len += snprintf(buf + len, maxLen - len, "\"accessState\":\"%d\", ", pAcct->cfg.accessState);
len += snprintf(buf + len, maxLen - len, "\"createdTime\":\"%" PRIu64 "\", ", pAcct->createdTime);
len += snprintf(buf + len, maxLen - len, "\"updateTime\":\"%" PRIu64 "\"}\n", pAcct->updateTime);
return len;
}
SAcctObj *mnodeDecodeAcct(cJSON *root) {
int32_t code = -1;
SAcctObj *pAcct = calloc(1, sizeof(SAcctObj)); SAcctObj *pAcct = calloc(1, sizeof(SAcctObj));
if (pAcct == NULL) {
cJSON *acct = cJSON_GetObjectItem(root, "acct"); terrno = TSDB_CODE_MND_OUT_OF_MEMORY;
if (!acct || acct->type != cJSON_String) { return NULL;
mError("failed to parse acct since acct not found");
goto DECODE_ACCT_OVER;
} }
tstrncpy(pAcct->acct, acct->valuestring, TSDB_USER_LEN);
cJSON *acctId = cJSON_GetObjectItem(root, "acctId"); int32_t code = 0;
if (!acctId || acctId->type != cJSON_String) { int32_t dataLen = pRaw->dataLen;
mError("acct:%s, failed to parse since acctId not found", pAcct->acct); char *pData = pRaw->data;
goto DECODE_ACCT_OVER; SDB_GET_BINARY_VAL(pData, dataLen, pAcct->acct, TSDB_USER_LEN, code)
} SDB_GET_INT64_VAL(pData, dataLen, pAcct->createdTime, code)
pAcct->acctId = atol(acctId->valuestring); SDB_GET_INT64_VAL(pData, dataLen, pAcct->updateTime, code)
SDB_GET_INT32_VAL(pData, dataLen, pAcct->acctId, code)
SDB_GET_INT32_VAL(pData, dataLen, pAcct->status, code)
SDB_GET_INT32_VAL(pData, dataLen, pAcct->cfg.maxUsers, code)
SDB_GET_INT32_VAL(pData, dataLen, pAcct->cfg.maxDbs, code)
SDB_GET_INT32_VAL(pData, dataLen, pAcct->cfg.maxTimeSeries, code)
SDB_GET_INT32_VAL(pData, dataLen, pAcct->cfg.maxStreams, code)
SDB_GET_INT64_VAL(pData, dataLen, pAcct->cfg.maxStorage, code)
SDB_GET_INT32_VAL(pData, dataLen, pAcct->cfg.accessState, code)
cJSON *maxUsers = cJSON_GetObjectItem(root, "maxUsers"); if (code != 0) {
if (!maxUsers || maxUsers->type != cJSON_String) { tfree(pAcct);
mError("acct:%s, failed to parse since maxUsers not found", pAcct->acct); terrno = code;
goto DECODE_ACCT_OVER; return NULL;
} }
pAcct->cfg.maxUsers = atol(maxUsers->valuestring);
cJSON *maxDbs = cJSON_GetObjectItem(root, "maxDbs"); return pAcct;
if (!maxDbs || maxDbs->type != cJSON_String) { }
mError("acct:%s, failed to parse since maxDbs not found", pAcct->acct);
goto DECODE_ACCT_OVER;
}
pAcct->cfg.maxDbs = atol(maxDbs->valuestring);
cJSON *maxTimeSeries = cJSON_GetObjectItem(root, "maxTimeSeries"); static int32_t mnodeAcctActionInsert(SAcctObj *pAcct) { return 0; }
if (!maxTimeSeries || maxTimeSeries->type != cJSON_String) {
mError("acct:%s, failed to parse since maxTimeSeries not found", pAcct->acct);
goto DECODE_ACCT_OVER;
}
pAcct->cfg.maxTimeSeries = atol(maxTimeSeries->valuestring);
cJSON *maxStreams = cJSON_GetObjectItem(root, "maxStreams"); static int32_t mnodeAcctActionDelete(SAcctObj *pAcct) { return 0; }
if (!maxStreams || maxStreams->type != cJSON_String) {
mError("acct:%s, failed to parse since maxStreams not found", pAcct->acct);
goto DECODE_ACCT_OVER;
}
pAcct->cfg.maxStreams = atol(maxStreams->valuestring);
cJSON *maxStorage = cJSON_GetObjectItem(root, "maxStorage"); static int32_t mnodeAcctActionUpdate(SAcctObj *pSrcAcct, SAcctObj *pDstAcct) {
if (!maxStorage || maxStorage->type != cJSON_String) { memcpy(pDstAcct, pSrcAcct, (int32_t)((char *)&pDstAcct->info - (char *)&pDstAcct));
mError("acct:%s, failed to parse since maxStorage not found", pAcct->acct); return 0;
goto DECODE_ACCT_OVER; }
}
pAcct->cfg.maxStorage = atoll(maxStorage->valuestring);
cJSON *accessState = cJSON_GetObjectItem(root, "accessState"); static int32_t mnodeCreateDefaultAcct() {
if (!accessState || accessState->type != cJSON_String) { int32_t code = 0;
mError("acct:%s, failed to parse since accessState not found", pAcct->acct);
goto DECODE_ACCT_OVER;
}
pAcct->cfg.accessState = atol(accessState->valuestring);
cJSON *createdTime = cJSON_GetObjectItem(root, "createdTime"); SAcctObj acctObj = {0};
if (!createdTime || createdTime->type != cJSON_String) { tstrncpy(acctObj.acct, TSDB_DEFAULT_USER, TSDB_USER_LEN);
mError("acct:%s, failed to parse since createdTime not found", pAcct->acct); acctObj.createdTime = taosGetTimestampMs();
goto DECODE_ACCT_OVER; acctObj.updateTime = taosGetTimestampMs();
} acctObj.acctId = 1;
pAcct->createdTime = atol(createdTime->valuestring); acctObj.cfg = (SAcctCfg){.maxUsers = 128,
.maxDbs = 128,
.maxTimeSeries = INT32_MAX,
.maxStreams = 1000,
.maxStorage = INT64_MAX,
.accessState = TSDB_VN_ALL_ACCCESS};
cJSON *updateTime = cJSON_GetObjectItem(root, "updateTime"); SSdbRawData *pRaw = mnodeAcctActionEncode(&acctObj);
if (!updateTime || updateTime->type != cJSON_String) { if (pRaw != NULL) {
mError("acct:%s, failed to parse since updateTime not found", pAcct->acct); code = sdbWrite(pRaw);
goto DECODE_ACCT_OVER; } else {
code = terrno;
} }
pAcct->updateTime = atol(updateTime->valuestring);
code = 0;
mTrace("acct:%s, parse success", pAcct->acct);
DECODE_ACCT_OVER: return code;
if (code != 0) {
free(pAcct);
pAcct = NULL;
}
return pAcct;
} }
int32_t mnodeInitAcct() { int32_t mnodeInitAcct() {
sdbSetFp(MN_SDB_ACCT, MN_KEY_BINARY, mnodeCreateDefaultAcct, (SdbEncodeFp)mnodeEncodeAcct, SSdbDesc desc = {.sdbType = SDB_ACCT,
(SdbDecodeFp)(mnodeDecodeAcct), sizeof(SAcctObj)); .keyType = SDB_KEY_BINARY,
.deployFp = (SdbDeployFp)mnodeCreateDefaultAcct,
.encodeFp = (SdbEncodeFp)mnodeAcctActionEncode,
.decodeFp = (SdbDecodeFp)mnodeAcctActionDecode,
.insertFp = (SdbInsertFp)mnodeAcctActionInsert,
.updateFp = (SdbUpdateFp)mnodeAcctActionUpdate,
.deleteFp = (SdbDeleteFp)mnodeAcctActionDelete};
sdbSetHandler(desc);
return 0; return 0;
} }
......
...@@ -19,111 +19,142 @@ ...@@ -19,111 +19,142 @@
#include "tglobal.h" #include "tglobal.h"
#include "mnodeInt.h" #include "mnodeInt.h"
static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) { #define USER_VER 1
int32_t code = TSDB_CODE_SUCCESS;
SUserObj userObj = {0}; static SSdbRawData *mnodeUserActionEncode(SUserObj *pUser) {
tstrncpy(userObj.user, user, TSDB_USER_LEN); SSdbRawData *pRaw = calloc(1, sizeof(SUserObj) + sizeof(SSdbRawData));
tstrncpy(userObj.acct, acct, TSDB_USER_LEN); if (pRaw == NULL) {
taosEncryptPass((uint8_t *)pass, strlen(pass), userObj.pass); terrno = TSDB_CODE_MND_OUT_OF_MEMORY;
userObj.createdTime = taosGetTimestampMs(); return NULL;
userObj.updateTime = taosGetTimestampMs();
if (strcmp(user, TSDB_DEFAULT_USER) == 0) {
userObj.rootAuth = 1;
} }
sdbInsertRow(MN_SDB_USER, &userObj); int32_t dataLen = 0;
char *pData = pRaw->data;
SDB_SET_BINARY_VAL(pData, dataLen, pUser->user, TSDB_USER_LEN)
SDB_SET_BINARY_VAL(pData, dataLen, pUser->pass, TSDB_KEY_LEN)
SDB_SET_BINARY_VAL(pData, dataLen, pUser->acct, TSDB_KEY_LEN)
SDB_SET_INT64_VAL(pData, dataLen, pUser->createdTime)
SDB_SET_INT64_VAL(pData, dataLen, pUser->updateTime)
SDB_SET_INT32_VAL(pData, dataLen, pUser->rootAuth)
pRaw->dataLen = dataLen;
pRaw->type = SDB_USER;
pRaw->sver = USER_VER;
return pRaw;
} }
static void mnodeCreateDefaultUsers() { static SUserObj *mnodeUserActionDecode(SSdbRawData *pRaw) {
mnodeCreateDefaultUser(TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS); if (pRaw->sver != USER_VER) {
mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "monitor", tsInternalPass); terrno = TSDB_CODE_SDB_INVAID_RAW_DATA_VER;
mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, tsInternalPass); return NULL;
} }
int32_t mnodeEncodeUser(SUserObj *pUser, char *buf, int32_t maxLen) { SUserObj *pUser = calloc(1, sizeof(SUserObj));
int32_t len = 0; if (pUser == NULL) {
char *base64 = base64_encode((const unsigned char *)pUser->pass, TSDB_KEY_LEN); terrno = TSDB_CODE_MND_OUT_OF_MEMORY;
return NULL;
}
len += snprintf(buf + len, maxLen - len, "{\"type\":%d, ", MN_SDB_USER); int32_t code = 0;
len += snprintf(buf + len, maxLen - len, "\"user\":\"%s\", ", pUser->user); int32_t dataLen = pRaw->dataLen;
len += snprintf(buf + len, maxLen - len, "\"auth\":\"%24s\", ", base64); char *pData = pRaw->data;
len += snprintf(buf + len, maxLen - len, "\"acct\":\"%s\", ", pUser->acct); SDB_GET_BINARY_VAL(pData, dataLen, pUser->user, TSDB_USER_LEN, code)
len += snprintf(buf + len, maxLen - len, "\"createdTime\":\"%" PRIu64 "\", ", pUser->createdTime); SDB_GET_BINARY_VAL(pData, dataLen, pUser->pass, TSDB_KEY_LEN, code)
len += snprintf(buf + len, maxLen - len, "\"updateTime\":\"%" PRIu64 "\"}\n", pUser->updateTime); SDB_GET_BINARY_VAL(pData, dataLen, pUser->acct, TSDB_USER_LEN, code)
SDB_GET_INT64_VAL(pData, dataLen, pUser->createdTime, code)
SDB_GET_INT64_VAL(pData, dataLen, pUser->updateTime, code)
SDB_GET_INT32_VAL(pData, dataLen, pUser->rootAuth, code)
free(base64); if (code != 0) {
return len; tfree(pUser);
} terrno = code;
return NULL;
}
SUserObj *mnodeDecodeUser(cJSON *root) { return pUser;
int32_t code = -1; }
SUserObj *pUser = calloc(1, sizeof(SUserObj));
cJSON *user = cJSON_GetObjectItem(root, "user"); static int32_t mnodeUserActionInsert(SUserObj *pUser) {
if (!user || user->type != cJSON_String) { pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
mError("failed to parse user since user not found"); if (pUser->prohibitDbHash == NULL) {
goto DECODE_USER_OVER; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
tstrncpy(pUser->user, user->valuestring, TSDB_USER_LEN);
if (strcmp(pUser->user, TSDB_DEFAULT_USER) == 0) { pUser->pAcct = sdbAcquire(SDB_ACCT, pUser->acct);
pUser->rootAuth = 1; if (pUser->pAcct == NULL) {
return TSDB_CODE_MND_ACCT_NOT_EXIST;
} }
cJSON *pass = cJSON_GetObjectItem(root, "auth"); return 0;
if (!pass || pass->type != cJSON_String) { }
mError("user:%s, failed to parse since auth not found", pUser->user);
goto DECODE_USER_OVER;
}
int32_t outlen = 0; static int32_t mnodeUserActionDelete(SUserObj *pUser) {
char *base64 = (char *)base64_decode(pass->valuestring, strlen(pass->valuestring), &outlen); if (pUser->prohibitDbHash) {
if (outlen != TSDB_KEY_LEN) { taosHashCleanup(pUser->prohibitDbHash);
mError("user:%s, failed to parse since invalid auth format", pUser->user); pUser->prohibitDbHash = NULL;
free(base64);
goto DECODE_USER_OVER;
} else {
memcpy(pUser->pass, base64, outlen);
free(base64);
} }
cJSON *acct = cJSON_GetObjectItem(root, "acct"); if (pUser->acct != NULL) {
if (!acct || acct->type != cJSON_String) { sdbRelease(SDB_ACCT, pUser->pAcct);
mError("user:%s, failed to parse since acct not found", pUser->user); pUser->pAcct = NULL;
goto DECODE_USER_OVER;
} }
tstrncpy(pUser->acct, acct->valuestring, TSDB_USER_LEN);
cJSON *createdTime = cJSON_GetObjectItem(root, "createdTime"); return 0;
if (!createdTime || createdTime->type != cJSON_String) { }
mError("user:%s, failed to parse since createdTime not found", pUser->user);
goto DECODE_USER_OVER; static int32_t mnodeUserActionUpdate(SUserObj *pSrcUser, SUserObj *pDstUser) {
memcpy(pDstUser, pSrcUser, (int32_t)((char *)&pDstUser->prohibitDbHash - (char *)&pDstUser));
return 0;
}
static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) {
int32_t code = 0;
SUserObj userObj = {0};
tstrncpy(userObj.user, user, TSDB_USER_LEN);
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
taosEncryptPass((uint8_t *)pass, strlen(pass), userObj.pass);
userObj.createdTime = taosGetTimestampMs();
userObj.updateTime = taosGetTimestampMs();
if (strcmp(user, TSDB_DEFAULT_USER) == 0) {
userObj.rootAuth = 1;
} }
pUser->createdTime = atol(createdTime->valuestring);
cJSON *updateTime = cJSON_GetObjectItem(root, "updateTime"); SSdbRawData *pRaw = mnodeUserActionEncode(&userObj);
if (!updateTime || updateTime->type != cJSON_String) { if (pRaw != NULL) {
mError("user:%s, failed to parse since updateTime not found", pUser->user); code = sdbWrite(pRaw);
goto DECODE_USER_OVER; } else {
code = terrno;
} }
pUser->updateTime = atol(updateTime->valuestring);
code = 0; return code;
mTrace("user:%s, parse success", pUser->user); }
DECODE_USER_OVER: static int32_t mnodeCreateDefaultUsers() {
if (code != 0) { int32_t code = mnodeCreateDefaultUser(TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS);
free(pUser); if (code != 0) return code;
pUser = NULL;
} code = mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "monitor", tsInternalPass);
return pUser; if (code != 0) return code;
code = mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, tsInternalPass);
if (code != 0) return code;
return code;
} }
int32_t mnodeInitUser() { int32_t mnodeInitUser() {
sdbSetFp(MN_SDB_USER, MN_KEY_BINARY, mnodeCreateDefaultUsers, (SdbEncodeFp)mnodeEncodeUser, SSdbDesc desc = {.sdbType = SDB_USER,
(SdbDecodeFp)(mnodeDecodeUser), sizeof(SUserObj)); .keyType = SDB_KEY_BINARY,
.deployFp = (SdbDeployFp)mnodeCreateDefaultUsers,
.encodeFp = (SdbEncodeFp)mnodeUserActionEncode,
.decodeFp = (SdbDecodeFp)mnodeUserActionDecode,
.insertFp = (SdbInsertFp)mnodeUserActionInsert,
.updateFp = (SdbUpdateFp)mnodeUserActionUpdate,
.deleteFp = (SdbDeleteFp)mnodeUserActionDelete};
sdbSetHandler(desc);
return 0; return 0;
} }
......
...@@ -50,7 +50,7 @@ static SMnMsg *mnodeInitMsg2(SRpcMsg *pRpcMsg) { ...@@ -50,7 +50,7 @@ static SMnMsg *mnodeInitMsg2(SRpcMsg *pRpcMsg) {
SRpcConnInfo connInfo = {0}; SRpcConnInfo connInfo = {0};
if (rpcGetConnInfo(pMsg->rpcMsg.handle, &connInfo) == 0) { if (rpcGetConnInfo(pMsg->rpcMsg.handle, &connInfo) == 0) {
pMsg->pUser = sdbGetRow(MN_SDB_USER, connInfo.user); pMsg->pUser = sdbAcquire(SDB_USER, connInfo.user);
} }
if (pMsg->pUser == NULL) { if (pMsg->pUser == NULL) {
...@@ -77,7 +77,7 @@ static void mnodeDispatchToWriteQueue(SRpcMsg *pRpcMsg) { ...@@ -77,7 +77,7 @@ static void mnodeDispatchToWriteQueue(SRpcMsg *pRpcMsg) {
} else { } else {
SMnMsg *pMsg = mnodeInitMsg2(pRpcMsg); SMnMsg *pMsg = mnodeInitMsg2(pRpcMsg);
if (pMsg == NULL) { if (pMsg == NULL) {
SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_INVALID_USER}; SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_USER_NOT_EXIST};
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
} else { } else {
mTrace("msg:%p, app:%p type:%s is put into wqueue", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); mTrace("msg:%p, app:%p type:%s is put into wqueue", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
...@@ -103,7 +103,7 @@ static void mnodeDispatchToReadQueue(SRpcMsg *pRpcMsg) { ...@@ -103,7 +103,7 @@ static void mnodeDispatchToReadQueue(SRpcMsg *pRpcMsg) {
} else { } else {
SMnMsg *pMsg = mnodeInitMsg2(pRpcMsg); SMnMsg *pMsg = mnodeInitMsg2(pRpcMsg);
if (pMsg == NULL) { if (pMsg == NULL) {
SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_INVALID_USER}; SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_USER_NOT_EXIST};
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
} else { } else {
mTrace("msg:%p, app:%p type:%s is put into rqueue", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); mTrace("msg:%p, app:%p type:%s is put into rqueue", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
...@@ -120,7 +120,7 @@ static void mnodeDispatchToPeerQueue(SRpcMsg *pRpcMsg) { ...@@ -120,7 +120,7 @@ static void mnodeDispatchToPeerQueue(SRpcMsg *pRpcMsg) {
} else { } else {
SMnMsg *pMsg = mnodeInitMsg2(pRpcMsg); SMnMsg *pMsg = mnodeInitMsg2(pRpcMsg);
if (pMsg == NULL) { if (pMsg == NULL) {
SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_INVALID_USER}; SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_USER_NOT_EXIST};
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
} else { } else {
mTrace("msg:%p, app:%p type:%s is put into peer req queue", pMsg, pMsg->rpcMsg.ahandle, mTrace("msg:%p, app:%p type:%s is put into peer req queue", pMsg, pMsg->rpcMsg.ahandle,
...@@ -135,7 +135,7 @@ static void mnodeDispatchToPeerQueue(SRpcMsg *pRpcMsg) { ...@@ -135,7 +135,7 @@ static void mnodeDispatchToPeerQueue(SRpcMsg *pRpcMsg) {
void mnodeDispatchToPeerRspQueue(SRpcMsg *pRpcMsg) { void mnodeDispatchToPeerRspQueue(SRpcMsg *pRpcMsg) {
SMnMsg *pMsg = mnodeInitMsg2(pRpcMsg); SMnMsg *pMsg = mnodeInitMsg2(pRpcMsg);
if (pMsg == NULL) { if (pMsg == NULL) {
SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_INVALID_USER}; SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_USER_NOT_EXIST};
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
} else { } else {
mTrace("msg:%p, app:%p type:%s is put into peer rsp queue", pMsg, pMsg->rpcMsg.ahandle, mTrace("msg:%p, app:%p type:%s is put into peer rsp queue", pMsg, pMsg->rpcMsg.ahandle,
......
...@@ -161,7 +161,7 @@ int32_t mnodeDeploy(char *path, SMnodeCfg *pCfg) { ...@@ -161,7 +161,7 @@ int32_t mnodeDeploy(char *path, SMnodeCfg *pCfg) {
if (code != 0) { if (code != 0) {
mError("failed to deploy mnode since init step1 error"); mError("failed to deploy mnode since init step1 error");
tsMint.state = MN_STATUS_UNINIT; tsMint.state = MN_STATUS_UNINIT;
return TSDB_CODE_MND_SDB_ERROR; return TSDB_CODE_MND_APP_ERROR;
} }
code = mnodeInitStep2(); code = mnodeInitStep2();
...@@ -169,7 +169,7 @@ int32_t mnodeDeploy(char *path, SMnodeCfg *pCfg) { ...@@ -169,7 +169,7 @@ int32_t mnodeDeploy(char *path, SMnodeCfg *pCfg) {
mnodeCleanupStep1(); mnodeCleanupStep1();
mError("failed to deploy mnode since init step2 error"); mError("failed to deploy mnode since init step2 error");
tsMint.state = MN_STATUS_UNINIT; tsMint.state = MN_STATUS_UNINIT;
return TSDB_CODE_MND_SDB_ERROR; return TSDB_CODE_MND_APP_ERROR;
} }
mDebug("mnode is deployed and waiting for raft to confirm"); mDebug("mnode is deployed and waiting for raft to confirm");
......
...@@ -17,17 +17,17 @@ ...@@ -17,17 +17,17 @@
#define _TD_SDB_INT_H_ #define _TD_SDB_INT_H_
#include "os.h" #include "os.h"
#include "sdb.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tlog.h"
#include "thash.h"
#include "tglobal.h" #include "tglobal.h"
#include "sdb.h" #include "thash.h"
#include "tlockfree.h"
#include "tlog.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
// mnode log function
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }} #define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }}
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }} #define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }}
#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }} #define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }}
...@@ -35,6 +35,32 @@ extern "C" { ...@@ -35,6 +35,32 @@ extern "C" {
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }} #define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }} #define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
#define SDB_MAX_SIZE (32*1024)
typedef struct {
char *currDir;
char *syncDir;
char *tmpDir;
int64_t lastCommitVer;
int64_t curVer;
EKeyType keyTypes[SDB_MAX];
SHashObj *hashObjs[SDB_MAX];
SRWLatch locks[SDB_MAX];
SdbInsertFp insertFps[SDB_MAX];
SdbUpdateFp updateFps[SDB_MAX];
SdbDeleteFp deleteFps[SDB_MAX];
SdbDeployFp deployFps[SDB_MAX];
SdbEncodeFp encodeFps[SDB_MAX];
SdbDecodeFp decodeFps[SDB_MAX];
} SSdbObj;
typedef struct {
ESdbStatus status;
int32_t refCount;
int32_t dataLen;
char *data[];
} SSdbRow;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -14,21 +14,9 @@ ...@@ -14,21 +14,9 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "cJSON.h"
#include "sdbInt.h" #include "sdbInt.h"
static struct { static SSdbObj tsSdb = {0};
char currDir[PATH_MAX];
char backDir[PATH_MAX];
char tmpDir[PATH_MAX];
int64_t version;
EMnKey hashKey[MN_SDB_MAX];
int32_t dataSize[MN_SDB_MAX];
SHashObj *hashObj[MN_SDB_MAX];
SdbDeployFp deployFp[MN_SDB_MAX];
SdbEncodeFp encodeFp[MN_SDB_MAX];
SdbDecodeFp decodeFp[MN_SDB_MAX];
} tsSdb = {0};
static int32_t sdbCreateDir() { static int32_t sdbCreateDir() {
if (!taosMkDir(tsSdb.currDir)) { if (!taosMkDir(tsSdb.currDir)) {
...@@ -36,8 +24,8 @@ static int32_t sdbCreateDir() { ...@@ -36,8 +24,8 @@ static int32_t sdbCreateDir() {
return TAOS_SYSTEM_ERROR(errno); return TAOS_SYSTEM_ERROR(errno);
} }
if (!taosMkDir(tsSdb.backDir)) { if (!taosMkDir(tsSdb.syncDir)) {
mError("failed to create dir:%s", tsSdb.backDir); mError("failed to create dir:%s", tsSdb.syncDir);
return -1; return -1;
} }
...@@ -50,8 +38,8 @@ static int32_t sdbCreateDir() { ...@@ -50,8 +38,8 @@ static int32_t sdbCreateDir() {
} }
static int32_t sdbRunDeployFp() { static int32_t sdbRunDeployFp() {
for (int32_t i = MN_SDB_START; i < MN_SDB_MAX; ++i) { for (int32_t i = SDB_START; i < SDB_MAX; ++i) {
SdbDeployFp fp = tsSdb.deployFp[i]; SdbDeployFp fp = tsSdb.deployFps[i];
if (fp) { if (fp) {
(*fp)(); (*fp)();
} }
...@@ -60,152 +48,147 @@ static int32_t sdbRunDeployFp() { ...@@ -60,152 +48,147 @@ static int32_t sdbRunDeployFp() {
return 0; return 0;
} }
static int32_t sdbReadVersion(cJSON *root) { static SHashObj *sdbGetHash(int32_t sdb) {
cJSON *ver = cJSON_GetObjectItem(root, "version"); if (sdb >= SDB_MAX || sdb <= SDB_START) {
if (!ver || ver->type != cJSON_String) { return NULL;
mError("failed to parse version since version not found");
return -1;
} }
tsSdb.version = (int64_t)atoll(ver->valuestring); SHashObj *hash = tsSdb.hashObjs[sdb];
mTrace("parse version success, version:%" PRIu64, tsSdb.version); if (hash == NULL) {
return NULL;
}
return 0; return hash;
} }
static void sdbWriteVersion(FileFd fd) { int32_t sdbWrite(SSdbRawData *pRaw) {
char content[128]; SHashObj *hash = sdbGetHash(pRaw->type);
int32_t len = switch (pRaw->action) {
snprintf(content, sizeof(content), "{\"type\":0, \"version\":\"%" PRIu64 "\", \"updateTime\":\"%" PRIu64 "\"}\n", case SDB_ACTION_INSERT:
tsSdb.version, taosGetTimestampMs()); break;
taosWriteFile(fd, content, len); case SDB_ACTION_UPDATE:
} break;
case SDB_ACTION_DELETE:
break;
static int32_t sdbReadDataFile() { default:
ssize_t _bytes = 0; break;
size_t len = 4096;
char *line = calloc(1, len);
int32_t code = -1;
FILE *fp = NULL;
cJSON *root = NULL;
char file[PATH_MAX + 20];
snprintf(file, sizeof(file), "%ssdb.data", tsSdb.currDir);
fp = fopen(file, "r");
if (!fp) {
mDebug("failed to open file:%s for read since %s", file, strerror(errno));
goto PARSE_SDB_DATA_ERROR;
} }
while (!feof(fp)) { return 0;
memset(line, 0, len); }
_bytes = tgetline(&line, &len, fp);
if (_bytes < 0) {
break;
}
line[len - 1] = 0; static int32_t sdbWriteVersion(FileFd fd) { return 0; }
if (len <= 10) continue;
root = cJSON_Parse(line); static int32_t sdbReadVersion(FileFd fd) { return 0; }
if (root == NULL) {
mError("failed to parse since invalid json format, %s", line);
goto PARSE_SDB_DATA_ERROR;
}
cJSON *type = cJSON_GetObjectItem(root, "type"); static int32_t sdbReadDataFile() {
if (!type || type->type != cJSON_Number) { int32_t code = 0;
mError("failed to parse since invalid type not found, %s", line);
goto PARSE_SDB_DATA_ERROR;
}
if (type->valueint >= MN_SDB_MAX || type->valueint < MN_SDB_START) { SSdbRawData *pRaw = malloc(SDB_MAX_SIZE);
mError("failed to parse since invalid type, %s", line); if (pRaw == NULL) {
goto PARSE_SDB_DATA_ERROR; return TSDB_CODE_MND_OUT_OF_MEMORY;
}
char file[PATH_MAX] = {0};
snprintf(file, sizeof(file), "%ssdb.data", tsSdb.currDir);
FileFd fd = taosOpenFileCreateWrite(file);
if (fd <= 0) {
code = TAOS_SYSTEM_ERROR(errno);
mError("failed to open file:%s for read since %s", file, tstrerror(code));
return code;
}
int64_t offset = 0;
while (1) {
int32_t ret = (int32_t)taosReadFile(fd, pRaw, sizeof(SSdbRawData));
if (ret == 0) break;
if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno);
mError("failed to read file:%s since %s", file, tstrerror(code));
break;
} }
if (type->valueint == MN_SDB_START) { if (ret < sizeof(SSdbRawData)) {
if (sdbReadVersion(root) != 0) { code = TSDB_CODE_SDB_INTERNAL_ERROR;
mError("failed to parse version, %s", line); mError("failed to read file:%s since %s", file, tstrerror(code));
goto PARSE_SDB_DATA_ERROR; break;
}
cJSON_Delete(root);
root = NULL;
continue;
} }
SdbDecodeFp decodeFp = tsSdb.decodeFp[type->valueint]; code = sdbWrite(pRaw);
SdbHead *pHead = (*decodeFp)(root); if (code != 0) {
if (pHead == NULL) { mError("failed to read file:%s since %s", file, tstrerror(code));
mError("failed to parse since decode error, %s", line);
goto PARSE_SDB_DATA_ERROR; goto PARSE_SDB_DATA_ERROR;
} }
pHead->type = type->valueint;
pHead->status = MN_SDB_STAT_AVAIL;
sdbInsertRow(pHead->type, pHead);
free(pHead);
cJSON_Delete(root);
root = NULL;
} }
code = 0; code = 0;
PARSE_SDB_DATA_ERROR: PARSE_SDB_DATA_ERROR:
if (line) free(line); taosCloseFile(fd);
if (fp) fclose(fp);
if (root) cJSON_Delete(root);
return code; return code;
} }
static int32_t sdbWriteDataFile() { static int32_t sdbWriteDataFile() {
char file[PATH_MAX + 20] = {0}; int32_t code = 0;
snprintf(file, sizeof(file), "%ssdb.data", tsSdb.currDir);
FileFd fd = taosOpenFileCreateWrite(file); char tmpfile[PATH_MAX] = {0};
snprintf(tmpfile, sizeof(tmpfile), "%ssdb.data", tsSdb.tmpDir);
FileFd fd = taosOpenFileCreateWrite(tmpfile);
if (fd <= 0) { if (fd <= 0) {
mError("failed to open file:%s for write since %s", file, strerror(errno)); code = TAOS_SYSTEM_ERROR(errno);
return -1; mError("failed to open file:%s for write since %s", tmpfile, tstrerror(code));
return code;
} }
int32_t len; for (int32_t i = SDB_START; i < SDB_MAX; ++i) {
int32_t maxLen = 10240; SHashObj *hash = tsSdb.hashObjs[i];
char *buf = malloc(maxLen);
for (int32_t i = MN_SDB_START; i < MN_SDB_MAX; ++i) {
SHashObj *hash = tsSdb.hashObj[i];
if (!hash) continue; if (!hash) continue;
SdbEncodeFp encodeFp = tsSdb.encodeFp[i]; SdbEncodeFp encodeFp = tsSdb.encodeFps[i];
if (!encodeFp) continue; if (!encodeFp) continue;
SdbHead *pHead = taosHashIterate(hash, NULL); SSdbRow *pRow = taosHashIterate(hash, NULL);
while (pHead != NULL) { while (pRow != NULL) {
len = (*encodeFp)(pHead, buf, maxLen); if (pRow->status == SDB_STATUS_READY) continue;
if (len >= 0) { SSdbRawData *pRaw = (*encodeFp)(pRow->data);
taosWriteFile(fd, buf, len); if (pRaw != NULL) {
taosWriteFile(fd, pRaw, sizeof(SSdbRawData) + pRaw->dataLen);
} else {
taosHashCancelIterate(hash, pRow);
code = TSDB_CODE_SDB_INTERNAL_ERROR;
break;
} }
pHead = taosHashIterate(hash, pHead); pRow = taosHashIterate(hash, pRow);
} }
} }
sdbWriteVersion(fd); if (code == 0) {
taosFsyncFile(fd); code = sdbWriteVersion(fd);
}
taosCloseFile(fd); taosCloseFile(fd);
mInfo("write file:%s successfully", file); if (code == 0) {
return 0; code = taosFsyncFile(fd);
} }
int32_t sdbCommit() {
int32_t code = sdbWriteDataFile();
if (code != 0) { if (code != 0) {
return code; char curfile[PATH_MAX] = {0};
snprintf(curfile, sizeof(curfile), "%ssdb.data", tsSdb.currDir);
code = taosRenameFile(tmpfile, curfile);
} }
return 0; if (code != 0) {
mError("failed to write sdb file since %s", tstrerror(code));
} else {
mInfo("write sdb file successfully");
}
return code;
} }
int32_t sdbRead() { int32_t sdbRead() {
...@@ -218,6 +201,15 @@ int32_t sdbRead() { ...@@ -218,6 +201,15 @@ int32_t sdbRead() {
return -1; return -1;
} }
int32_t sdbCommit() {
int32_t code = sdbWriteDataFile();
if (code != 0) {
return code;
}
return 0;
}
int32_t sdbDeploy() { int32_t sdbDeploy() {
if (sdbCreateDir() != 0) { if (sdbCreateDir() != 0) {
return -1; return -1;
...@@ -231,38 +223,32 @@ int32_t sdbDeploy() { ...@@ -231,38 +223,32 @@ int32_t sdbDeploy() {
return -1; return -1;
} }
// if (!taosMkDir())
// if (pMinfos == NULL) { // first deploy
// tsMint.dnodeId = 1;
// bool getuid = taosGetSystemUid(tsMint.clusterId);
// if (!getuid) {
// strcpy(tsMint.clusterId, "tdengine3.0");
// mError("deploy new mnode but failed to get uid, set to default val %s", tsMint.clusterId);
// } else {
// mDebug("deploy new mnode and uid is %s", tsMint.clusterId);
// }
// } else { // todo
// }
// if (mkdir(tsMnodeDir, 0755) != 0 && errno != EEXIST) {
// mError("failed to init mnode dir:%s, reason:%s", tsMnodeDir, strerror(errno));
// return -1;
// }
return 0; return 0;
} }
void sdbUnDeploy() {} void sdbUnDeploy() {}
int32_t sdbInit() { int32_t sdbInit() {
snprintf(tsSdb.currDir, PATH_MAX, "%s%scurrent%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP); char path[PATH_MAX + 100];
snprintf(tsSdb.backDir, PATH_MAX, "%s%sbackup%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
snprintf(tsSdb.tmpDir, PATH_MAX, "%s%stmp%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP); snprintf(path, PATH_MAX + 100, "%s%scurrent%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
tsSdb.currDir = strdup(path);
for (int32_t i = 0; i < MN_SDB_MAX; ++i) { snprintf(path, PATH_MAX + 100, "%s%ssync%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
tsSdb.syncDir = strdup(path);
snprintf(path, PATH_MAX + 100, "%s%stmp%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
tsSdb.tmpDir = strdup(path);
if (tsSdb.currDir == NULL || tsSdb.currDir == NULL || tsSdb.currDir == NULL) {
return TSDB_CODE_MND_OUT_OF_MEMORY;
}
for (int32_t i = 0; i < SDB_MAX; ++i) {
int32_t type; int32_t type;
if (tsSdb.hashKey[i] == MN_KEY_INT32) { if (tsSdb.keyTypes[i] == SDB_KEY_INT32) {
type = TSDB_DATA_TYPE_INT; type = TSDB_DATA_TYPE_INT;
} else if (tsSdb.hashKey[i] == MN_KEY_INT64) { } else if (tsSdb.keyTypes[i] == SDB_KEY_INT64) {
type = TSDB_DATA_TYPE_BIGINT; type = TSDB_DATA_TYPE_BIGINT;
} else { } else {
type = TSDB_DATA_TYPE_BINARY; type = TSDB_DATA_TYPE_BINARY;
...@@ -270,65 +256,72 @@ int32_t sdbInit() { ...@@ -270,65 +256,72 @@ int32_t sdbInit() {
SHashObj *hash = taosHashInit(128, taosGetDefaultHashFunction(type), true, HASH_NO_LOCK); SHashObj *hash = taosHashInit(128, taosGetDefaultHashFunction(type), true, HASH_NO_LOCK);
if (hash == NULL) { if (hash == NULL) {
return -1; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
tsSdb.hashObj[i] = hash; tsSdb.hashObjs[i] = hash;
taosInitRWLatch(&tsSdb.locks[i]);
} }
return 0; return 0;
} }
void sdbCleanup() { void sdbCleanup() {
for (int32_t i = 0; i < MN_SDB_MAX; ++i) { if (tsSdb.curVer != tsSdb.lastCommitVer) {
SHashObj *hash = tsSdb.hashObj[i]; sdbCommit();
if (hash != NULL) {
taosHashCleanup(hash);
}
tsSdb.hashObj[i] = NULL;
} }
}
void sdbSetFp(EMnSdb sdb, EMnKey keyType, SdbDeployFp deployFp, SdbEncodeFp encodeFp, SdbDecodeFp decodeFp, if (tsSdb.currDir != NULL) {
int32_t dataSize) { tfree(tsSdb.currDir);
tsSdb.deployFp[sdb] = deployFp; }
tsSdb.encodeFp[sdb] = encodeFp;
tsSdb.decodeFp[sdb] = decodeFp;
tsSdb.dataSize[sdb] = dataSize;
tsSdb.hashKey[sdb] = keyType;
}
static SHashObj *sdbGetHash(int32_t sdb) { if (tsSdb.syncDir != NULL) {
if (sdb >= MN_SDB_MAX || sdb <= MN_SDB_START) { tfree(tsSdb.syncDir);
return NULL;
} }
SHashObj *hash = tsSdb.hashObj[sdb]; if (tsSdb.tmpDir != NULL) {
if (hash == NULL) { tfree(tsSdb.tmpDir);
return NULL;
} }
return hash; for (int32_t i = 0; i < SDB_MAX; ++i) {
SHashObj *hash = tsSdb.hashObjs[i];
if (hash != NULL) {
taosHashCleanup(hash);
}
tsSdb.hashObjs[i] = NULL;
}
} }
void *sdbInsertRow(EMnSdb sdb, void *p) { void sdbSetHandler(SSdbDesc desc) {
ESdbType sdb = desc.sdbType;
tsSdb.keyTypes[sdb] = desc.keyType;
tsSdb.insertFps[sdb] = desc.insertFp;
tsSdb.updateFps[sdb] = desc.updateFp;
tsSdb.deleteFps[sdb] = desc.deleteFp;
tsSdb.deployFps[sdb] = desc.deployFp;
tsSdb.encodeFps[sdb] = desc.encodeFp;
tsSdb.decodeFps[sdb] = desc.decodeFp;
}
#if 0
void *sdbInsertRow(ESdbType sdb, void *p) {
SdbHead *pHead = p; SdbHead *pHead = p;
pHead->type = sdb; pHead->type = sdb;
pHead->status = MN_SDB_STAT_AVAIL; pHead->status = SDB_AVAIL;
char *pKey = (char *)pHead + sizeof(pHead); char *pKey = (char *)pHead + sizeof(pHead);
int32_t keySize; int32_t keySize;
EMnKey keyType = tsSdb.hashKey[pHead->type]; EKeyType keyType = tsSdb.keyTypes[pHead->type];
int32_t dataSize = tsSdb.dataSize[pHead->type]; int32_t dataSize = tsSdb.dataSize[pHead->type];
SHashObj *hash = sdbGetHash(pHead->type); SHashObj *hash = sdbGetHash(pHead->type);
if (hash == NULL) { if (hash == NULL) {
return NULL; return NULL;
} }
if (keyType == MN_KEY_INT32) { if (keyType == SDBINT32) {
keySize = sizeof(int32_t); keySize = sizeof(int32_t);
} else if (keyType == MN_KEY_BINARY) { } else if (keyType == SDB_KEY_BINARY) {
keySize = strlen(pKey) + 1; keySize = strlen(pKey) + 1;
} else { } else {
keySize = sizeof(int64_t); keySize = sizeof(int64_t);
...@@ -338,34 +331,58 @@ void *sdbInsertRow(EMnSdb sdb, void *p) { ...@@ -338,34 +331,58 @@ void *sdbInsertRow(EMnSdb sdb, void *p) {
return taosHashGet(hash, pKey, keySize); return taosHashGet(hash, pKey, keySize);
} }
void sdbDeleteRow(EMnSdb sdb, void *p) { void sdbDeleteRow(ESdbType sdb, void *p) {
SdbHead *pHead = p; SdbHead *pHead = p;
pHead->status = MN_SDB_STAT_DROPPED; pHead->status = SDB_STATUS_DROPPED;
} }
void *sdbUpdateRow(EMnSdb sdb, void *pHead) { return sdbInsertRow(sdb, pHead); } void *sdbUpdateRow(ESdbType sdb, void *pHead) { return sdbInsertRow(sdb, pHead); }
#endif
void *sdbAcquire(ESdbType sdb, void *pKey) {
terrno = 0;
void *sdbGetRow(EMnSdb sdb, void *pKey) {
SHashObj *hash = sdbGetHash(sdb); SHashObj *hash = sdbGetHash(sdb);
if (hash == NULL) { if (hash == NULL) {
return NULL; return NULL;
} }
int32_t keySize; int32_t keySize;
EMnKey keyType = tsSdb.hashKey[sdb]; EKeyType keyType = tsSdb.keyTypes[sdb];
if (keyType == MN_KEY_INT32) { switch (keyType) {
keySize = sizeof(int32_t); case SDB_KEY_INT32:
} else if (keyType == MN_KEY_BINARY) { keySize = sizeof(int32_t);
keySize = strlen(pKey) + 1; break;
case SDB_KEY_INT64:
keySize = sizeof(int64_t);
break;
case SDB_KEY_BINARY:
keySize = strlen(pKey) + 1;
break;
default:
keySize = sizeof(int32_t);
}
SSdbRow *pRow = taosHashGet(hash, pKey, keySize);
if (pRow == NULL) return NULL;
if (pRow->status == SDB_STATUS_READY) {
atomic_add_fetch_32(&pRow->refCount, 1);
return pRow->data;
} else { } else {
keySize = sizeof(int64_t); terrno = -1; // todo
return NULL;
} }
}
return taosHashGet(hash, pKey, keySize); void sdbRelease(ESdbType sdb, void *pObj) {
SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow));
atomic_sub_fetch_32(&pRow->refCount, 1);
} }
void *sdbFetchRow(EMnSdb sdb, void *pIter) { void *sdbFetchRow(ESdbType sdb, void *pIter) {
SHashObj *hash = sdbGetHash(sdb); SHashObj *hash = sdbGetHash(sdb);
if (hash == NULL) { if (hash == NULL) {
return NULL; return NULL;
...@@ -374,16 +391,15 @@ void *sdbFetchRow(EMnSdb sdb, void *pIter) { ...@@ -374,16 +391,15 @@ void *sdbFetchRow(EMnSdb sdb, void *pIter) {
return taosHashIterate(hash, pIter); return taosHashIterate(hash, pIter);
} }
void sdbCancelFetch(EMnSdb sdb, void *pIter) { void sdbCancelFetch(ESdbType sdb, void *pIter) {
SHashObj *hash = sdbGetHash(sdb); SHashObj *hash = sdbGetHash(sdb);
if (hash == NULL) { if (hash == NULL) {
return; return;
} }
taosHashCancelIterate(hash, pIter); taosHashCancelIterate(hash, pIter);
} }
int32_t sdbGetCount(EMnSdb sdb) { int32_t sdbGetSize(ESdbType sdb) {
SHashObj *hash = sdbGetHash(sdb); SHashObj *hash = sdbGetHash(sdb);
if (hash == NULL) { if (hash == NULL) {
return 0; return 0;
......
...@@ -1582,7 +1582,7 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) { ...@@ -1582,7 +1582,7 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) {
code = htonl(pHead->code); code = htonl(pHead->code);
if (code == TSDB_CODE_RPC_INVALID_TIME_STAMP || code == TSDB_CODE_RPC_AUTH_FAILURE || if (code == TSDB_CODE_RPC_INVALID_TIME_STAMP || code == TSDB_CODE_RPC_AUTH_FAILURE ||
code == TSDB_CODE_RPC_INVALID_VERSION || code == TSDB_CODE_RPC_INVALID_VERSION ||
code == TSDB_CODE_RPC_AUTH_REQUIRED || code == TSDB_CODE_MND_INVALID_USER || code == TSDB_CODE_RPC_NOT_READY) { code == TSDB_CODE_RPC_AUTH_REQUIRED || code == TSDB_CODE_MND_USER_NOT_EXIST || code == TSDB_CODE_RPC_NOT_READY) {
pHead->msgLen = (int32_t)htonl((uint32_t)pHead->msgLen); pHead->msgLen = (int32_t)htonl((uint32_t)pHead->msgLen);
// tTrace("%s, dont check authentication since code is:0x%x", pConn->info, code); // tTrace("%s, dont check authentication since code is:0x%x", pConn->info, code);
return 0; return 0;
......
...@@ -142,12 +142,15 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_FAILED_TO_START_SYNC, "failed to start sync" ...@@ -142,12 +142,15 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_FAILED_TO_START_SYNC, "failed to start sync"
TAOS_DEFINE_ERROR(TSDB_CODE_MND_FAILED_TO_CREATE_DIR, "failed to create mnode dir") TAOS_DEFINE_ERROR(TSDB_CODE_MND_FAILED_TO_CREATE_DIR, "failed to create mnode dir")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_FAILED_TO_INIT_STEP, "failed to init components") TAOS_DEFINE_ERROR(TSDB_CODE_MND_FAILED_TO_INIT_STEP, "failed to init components")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE, "Object already there") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INTERNAL_ERROR, "Unexpected generic error in sdb")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_ERROR, "Unexpected generic error in sdb") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_OUT_OF_MEMORY, "Out of memory in sdb")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE, "Invalid table type") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_OBJ_ALREADY_THERE, "Object already there")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_NOT_THERE, "Object not there") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_OBJ_NOT_THERE, "Object not there")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVAID_META_ROW, "Invalid meta row") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVAID_RAW_DATA_VER, "Invalid raw data version")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVAID_KEY_TYPE, "Invalid key type") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVAID_RAW_DATA_LEN, "Invalid raw data len")
TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_TABLE_TYPE, "Invalid table type")
TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVAID_META_ROW, "Invalid meta row")
TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVAID_KEY_TYPE, "Invalid key type")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ALREADY_EXIST, "DNode already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ALREADY_EXIST, "DNode already exists")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_EXIST, "DNode does not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_EXIST, "DNode does not exist")
...@@ -166,12 +169,12 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ID_NOT_CONFIGURED, "Dnode Id not configur ...@@ -166,12 +169,12 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ID_NOT_CONFIGURED, "Dnode Id not configur
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_EP_NOT_CONFIGURED, "Dnode Ep not configured") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_EP_NOT_CONFIGURED, "Dnode Ep not configured")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_ALREADY_EXIST, "Account already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_ALREADY_EXIST, "Account already exists")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT, "Invalid account") TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_NOT_EXIST, "Invalid account")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT_OPTION, "Invalid account options") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT_OPTION, "Invalid account options")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_EXPIRED, "Account authorization has expired") TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_EXPIRED, "Account authorization has expired")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_USER_ALREADY_EXIST, "User already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_USER_ALREADY_EXIST, "User already exists")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_USER, "Invalid user") TAOS_DEFINE_ERROR(TSDB_CODE_MND_USER_NOT_EXIST, "Invalid user")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_USER_FORMAT, "Invalid user format") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_USER_FORMAT, "Invalid user format")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_PASS_FORMAT, "Invalid password format") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_PASS_FORMAT, "Invalid password format")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_USER_FROM_CONN, "Can not get user from conn") TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_USER_FROM_CONN, "Can not get user from conn")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册