提交 7ee2e5a3 编写于 作者: S Shengliang Guan

refactor: let all operations of mnode into the sync log

上级 229cb7b7
...@@ -67,30 +67,33 @@ typedef enum { ...@@ -67,30 +67,33 @@ typedef enum {
typedef enum { typedef enum {
TRN_TYPE_BASIC_SCOPE = 1000, TRN_TYPE_BASIC_SCOPE = 1000,
TRN_TYPE_CREATE_USER = 1001, TRN_TYPE_CREATE_ACCT = 1001,
TRN_TYPE_ALTER_USER = 1002, TRN_TYPE_CREATE_CLUSTER = 1002,
TRN_TYPE_DROP_USER = 1003, TRN_TYPE_CREATE_USER = 1003,
TRN_TYPE_CREATE_FUNC = 1004, TRN_TYPE_ALTER_USER = 1004,
TRN_TYPE_DROP_FUNC = 1005, TRN_TYPE_DROP_USER = 1005,
TRN_TYPE_CREATE_FUNC = 1006,
TRN_TYPE_CREATE_SNODE = 1006, TRN_TYPE_DROP_FUNC = 1007,
TRN_TYPE_DROP_SNODE = 1007,
TRN_TYPE_CREATE_QNODE = 1008, TRN_TYPE_CREATE_SNODE = 1010,
TRN_TYPE_DROP_QNODE = 1009, TRN_TYPE_DROP_SNODE = 1011,
TRN_TYPE_CREATE_BNODE = 1010, TRN_TYPE_CREATE_QNODE = 1012,
TRN_TYPE_DROP_BNODE = 1011, TRN_TYPE_DROP_QNODE = 10013,
TRN_TYPE_CREATE_MNODE = 1012, TRN_TYPE_CREATE_BNODE = 1014,
TRN_TYPE_DROP_MNODE = 1013, TRN_TYPE_DROP_BNODE = 1015,
TRN_TYPE_CREATE_TOPIC = 1014, TRN_TYPE_CREATE_MNODE = 1016,
TRN_TYPE_DROP_TOPIC = 1015, TRN_TYPE_DROP_MNODE = 1017,
TRN_TYPE_SUBSCRIBE = 1016,
TRN_TYPE_REBALANCE = 1017, TRN_TYPE_CREATE_TOPIC = 1020,
TRN_TYPE_COMMIT_OFFSET = 1018, TRN_TYPE_DROP_TOPIC = 1021,
TRN_TYPE_CREATE_STREAM = 1019, TRN_TYPE_SUBSCRIBE = 1022,
TRN_TYPE_DROP_STREAM = 1020, TRN_TYPE_REBALANCE = 1023,
TRN_TYPE_ALTER_STREAM = 1021, TRN_TYPE_COMMIT_OFFSET = 1024,
TRN_TYPE_CONSUMER_LOST = 1022, TRN_TYPE_CREATE_STREAM = 1025,
TRN_TYPE_CONSUMER_RECOVER = 1023, TRN_TYPE_DROP_STREAM = 1026,
TRN_TYPE_ALTER_STREAM = 1027,
TRN_TYPE_CONSUMER_LOST = 1028,
TRN_TYPE_CONSUMER_RECOVER = 1029,
TRN_TYPE_BASIC_SCOPE_END, TRN_TYPE_BASIC_SCOPE_END,
TRN_TYPE_GLOBAL_SCOPE = 2000, TRN_TYPE_GLOBAL_SCOPE = 2000,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "mndAcct.h" #include "mndAcct.h"
#include "mndShow.h" #include "mndShow.h"
#include "mndTrans.h"
#define ACCT_VER_NUMBER 1 #define ACCT_VER_NUMBER 1
#define ACCT_RESERVE_SIZE 128 #define ACCT_RESERVE_SIZE 128
...@@ -31,14 +32,16 @@ static int32_t mndProcessAlterAcctReq(SRpcMsg *pReq); ...@@ -31,14 +32,16 @@ static int32_t mndProcessAlterAcctReq(SRpcMsg *pReq);
static int32_t mndProcessDropAcctReq(SRpcMsg *pReq); static int32_t mndProcessDropAcctReq(SRpcMsg *pReq);
int32_t mndInitAcct(SMnode *pMnode) { int32_t mndInitAcct(SMnode *pMnode) {
SSdbTable table = {.sdbType = SDB_ACCT, SSdbTable table = {
.keyType = SDB_KEY_BINARY, .sdbType = SDB_ACCT,
.deployFp = mndCreateDefaultAcct, .keyType = SDB_KEY_BINARY,
.encodeFp = (SdbEncodeFp)mndAcctActionEncode, .deployFp = mndCreateDefaultAcct,
.decodeFp = (SdbDecodeFp)mndAcctActionDecode, .encodeFp = (SdbEncodeFp)mndAcctActionEncode,
.insertFp = (SdbInsertFp)mndAcctActionInsert, .decodeFp = (SdbDecodeFp)mndAcctActionDecode,
.updateFp = (SdbUpdateFp)mndAcctActionUpdate, .insertFp = (SdbInsertFp)mndAcctActionInsert,
.deleteFp = (SdbDeleteFp)mndAcctActionDelete}; .updateFp = (SdbUpdateFp)mndAcctActionUpdate,
.deleteFp = (SdbDeleteFp)mndAcctActionDelete,
};
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctReq); mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctReq);
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctReq); mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctReq);
...@@ -56,25 +59,52 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) { ...@@ -56,25 +59,52 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
acctObj.updateTime = acctObj.createdTime; acctObj.updateTime = acctObj.createdTime;
acctObj.acctId = 1; acctObj.acctId = 1;
acctObj.status = 0; acctObj.status = 0;
acctObj.cfg = (SAcctCfg){.maxUsers = INT32_MAX, acctObj.cfg = (SAcctCfg){
.maxDbs = INT32_MAX, .maxUsers = INT32_MAX,
.maxStbs = INT32_MAX, .maxDbs = INT32_MAX,
.maxTbs = INT32_MAX, .maxStbs = INT32_MAX,
.maxTimeSeries = INT32_MAX, .maxTbs = INT32_MAX,
.maxStreams = INT32_MAX, .maxTimeSeries = INT32_MAX,
.maxFuncs = INT32_MAX, .maxStreams = INT32_MAX,
.maxConsumers = INT32_MAX, .maxFuncs = INT32_MAX,
.maxConns = INT32_MAX, .maxConsumers = INT32_MAX,
.maxTopics = INT32_MAX, .maxConns = INT32_MAX,
.maxStorage = INT64_MAX, .maxTopics = INT32_MAX,
.accessState = TSDB_VN_ALL_ACCCESS}; .maxStorage = INT64_MAX,
.accessState = TSDB_VN_ALL_ACCCESS,
};
SSdbRaw *pRaw = mndAcctActionEncode(&acctObj); SSdbRaw *pRaw = mndAcctActionEncode(&acctObj);
if (pRaw == NULL) return -1; if (pRaw == NULL) return -1;
sdbSetRawStatus(pRaw, SDB_STATUS_READY); sdbSetRawStatus(pRaw, SDB_STATUS_READY);
mDebug("acct:%s, will be created while deploy sdb, raw:%p", acctObj.acct, pRaw); mDebug("acct:%s, will be created while deploy sdb, raw:%p", acctObj.acct, pRaw);
#if 0
return sdbWrite(pMnode->pSdb, pRaw); return sdbWrite(pMnode->pSdb, pRaw);
#else
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_ACCT, NULL);
if (pTrans == NULL) {
mError("acct:%s, failed to create since %s", acctObj.acct, terrstr());
return -1;
}
mDebug("trans:%d, used to create acct:%s", pTrans->id, acctObj.acct);
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) {
mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
if (mndTransPrepare(pMnode, pTrans) != 0) {
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
mndTransDrop(pTrans);
return 0;
#endif
} }
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) { static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "mndCluster.h" #include "mndCluster.h"
#include "mndShow.h" #include "mndShow.h"
#include "mndTrans.h"
#define CLUSTER_VER_NUMBE 1 #define CLUSTER_VER_NUMBE 1
#define CLUSTER_RESERVE_SIZE 64 #define CLUSTER_RESERVE_SIZE 64
...@@ -177,7 +178,32 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) { ...@@ -177,7 +178,32 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
sdbSetRawStatus(pRaw, SDB_STATUS_READY); sdbSetRawStatus(pRaw, SDB_STATUS_READY);
mDebug("cluster:%" PRId64 ", will be created while deploy sdb, raw:%p", clusterObj.id, pRaw); mDebug("cluster:%" PRId64 ", will be created while deploy sdb, raw:%p", clusterObj.id, pRaw);
#if 0
return sdbWrite(pMnode->pSdb, pRaw); return sdbWrite(pMnode->pSdb, pRaw);
#else
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_CLUSTER, NULL);
if (pTrans == NULL) {
mError("cluster:%" PRId64 ", failed to create since %s", clusterObj.id, terrstr());
return -1;
}
mDebug("trans:%d, used to create cluster:%" PRId64, pTrans->id, clusterObj.id);
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) {
mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
if (mndTransPrepare(pMnode, pTrans) != 0) {
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
mndTransDrop(pTrans);
return 0;
#endif
} }
static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
......
...@@ -6,15 +6,6 @@ system sh/exec.sh -n dnode2 -s start ...@@ -6,15 +6,6 @@ system sh/exec.sh -n dnode2 -s start
sql connect sql connect
print =============== show dnodes print =============== show dnodes
sql show dnodes;
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
sql show mnodes; sql show mnodes;
if $rows != 1 then if $rows != 1 then
return -1 return -1
...@@ -30,35 +21,11 @@ endi ...@@ -30,35 +21,11 @@ endi
print =============== create dnodes print =============== create dnodes
sql create dnode $hostname port 7200 sql create dnode $hostname port 7200
sql create dnode $hostname port 7300
sleep 2000 sleep 2000
sql show dnodes; sql show dnodes;
if $rows != 2 then if $rows != 3 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data10 != 2 then
return -1
endi
print $data02
if $data02 != 0 then
return -1
endi
if $data12 != 0 then
return -1
endi
if $data04 != ready then
return -1
endi
if $data14 != ready then
return -1 return -1
endi endi
...@@ -82,3 +49,10 @@ if $rows != 2 then ...@@ -82,3 +49,10 @@ if $rows != 2 then
return -1 return -1
endi endi
return
sql create mnode on dnode 3
sql show mnodes
if $rows != 3 then
return -1
endi
...@@ -64,7 +64,7 @@ if $rows != 1 then ...@@ -64,7 +64,7 @@ if $rows != 1 then
return -1 return -1
endi endi
if $data[0][0] != 5 then if $data[0][0] != 7 then
return -1 return -1
endi endi
...@@ -114,7 +114,7 @@ if $rows != 1 then ...@@ -114,7 +114,7 @@ if $rows != 1 then
return -1 return -1
endi endi
if $data[0][0] != 7 then if $data[0][0] != 9 then
return -1 return -1
endi endi
...@@ -137,7 +137,7 @@ endi ...@@ -137,7 +137,7 @@ endi
sql_error create database d2 vgroups 2; sql_error create database d2 vgroups 2;
print =============== kill transaction print =============== kill transaction
sql kill transaction 7; sql kill transaction 9;
sleep 2000 sleep 2000
sql show transactions sql show transactions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册