提交 e7411183 编写于 作者: B Benguang Zhao

enh: create SDB_DB entry in prepareAction

上级 f01a26f6
...@@ -448,6 +448,16 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) { ...@@ -448,6 +448,16 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
if (pCfg->tsdbPageSize <= 0) pCfg->tsdbPageSize = TSDB_DEFAULT_TSDB_PAGESIZE; if (pCfg->tsdbPageSize <= 0) pCfg->tsdbPageSize = TSDB_DEFAULT_TSDB_PAGESIZE;
} }
static int32_t mndSetCreateDbPrepareActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
SSdbRaw *pDbRaw = mndDbActionEncode(pDb);
if (pDbRaw == NULL) return -1;
STransAction action = {.pRaw = pDbRaw, .msgType = TDMT_MND_CREATE_DB};
if (mndTransAppendPrepareAction(pTrans, &action) != 0) return -1;
if (sdbSetRawStatus(pDbRaw, SDB_STATUS_CREATING) != 0) return -1;
return 0;
}
static int32_t mndSetNewVgPrepareActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) { static int32_t mndSetNewVgPrepareActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) { for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) {
if (mndAddNewVgPrepareAction(pMnode, pTrans, (pVgroups + v)) != 0) return -1; if (mndAddNewVgPrepareAction(pMnode, pTrans, (pVgroups + v)) != 0) return -1;
...@@ -459,7 +469,7 @@ static int32_t mndSetCreateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD ...@@ -459,7 +469,7 @@ static int32_t mndSetCreateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD
SSdbRaw *pDbRaw = mndDbActionEncode(pDb); SSdbRaw *pDbRaw = mndDbActionEncode(pDb);
if (pDbRaw == NULL) return -1; if (pDbRaw == NULL) return -1;
if (mndTransAppendRedolog(pTrans, pDbRaw) != 0) return -1; if (mndTransAppendRedolog(pTrans, pDbRaw) != 0) return -1;
if (sdbSetRawStatus(pDbRaw, SDB_STATUS_CREATING) != 0) return -1; if (sdbSetRawStatus(pDbRaw, SDB_STATUS_UPDATE) != 0) return -1;
for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) { for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) {
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v); SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
...@@ -633,6 +643,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, ...@@ -633,6 +643,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER; if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
mndTransSetOper(pTrans, MND_OPER_CREATE_DB); mndTransSetOper(pTrans, MND_OPER_CREATE_DB);
if (mndSetCreateDbPrepareActions(pMnode, pTrans, &dbObj) != 0) goto _OVER;
if (mndSetNewVgPrepareActions(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER; if (mndSetNewVgPrepareActions(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
if (mndSetCreateDbRedoLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER; if (mndSetCreateDbRedoLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
if (mndSetCreateDbUndoLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER; if (mndSetCreateDbUndoLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "mndSync.h" #include "mndSync.h"
#include "mndCluster.h" #include "mndCluster.h"
#include "mndDb.h"
#include "mndTrans.h" #include "mndTrans.h"
#include "mndVgroup.h" #include "mndVgroup.h"
...@@ -74,23 +75,37 @@ static int32_t mndSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) { ...@@ -74,23 +75,37 @@ static int32_t mndSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) {
return code; return code;
} }
static int32_t mndTransValidatePrepareAction(SMnode *pMnode, STrans *pTrans, STransAction *pAction) { static int32_t mndValidateNewVgPrepareAction(SMnode *pMnode, STrans *pTrans, STransAction *pAction) {
SSdbRow *pRow = NULL; int code = -1;
int32_t code = -1; SSdbRow *pRow = (pMnode->pSdb->decodeFps[SDB_VGROUP])(pAction->pRaw);
if (pRow == NULL) goto _OUT;
SVgObj *pVgroup = sdbGetRowObj(pRow);
if (pVgroup == NULL) goto _OUT;
if (pAction->msgType == TDMT_MND_CREATE_VG) { int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP);
pRow = mndVgroupActionDecode(pAction->pRaw); if (maxVgId > pVgroup->vgId) {
if (pRow == NULL) goto _OUT; mError("trans:%d, vgroup id %d already in use. maxVgId:%d", pTrans->id, pVgroup->vgId, maxVgId);
goto _OUT;
}
SVgObj *pVgroup = sdbGetRowObj(pRow); code = 0;
if (pVgroup == NULL) goto _OUT; _OUT:
taosMemoryFreeClear(pRow);
return code;
}
int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP); static int32_t mndValidateCreateDbPrepareAction(SMnode *pMnode, STrans *pTrans, STransAction *pAction) {
if (maxVgId > pVgroup->vgId) { int code = -1;
mError("trans:%d, failed to satisfy vgroup id %d of prepare action. maxVgId:%d", pTrans->id, pVgroup->vgId, SSdbRow *pRow = (pMnode->pSdb->decodeFps[SDB_DB])(pAction->pRaw);
maxVgId); if (pRow == NULL) goto _OUT;
goto _OUT; SDbObj *pNewDb = sdbGetRowObj(pRow);
} if (pNewDb == NULL) goto _OUT;
SDbObj *pOldDb = sdbAcquire(pMnode->pSdb, SDB_DB, pNewDb->name);
if (pOldDb != NULL) {
mError("trans:%d, db name already in use. name: %s", pTrans->id, pNewDb->name);
sdbRelease(pMnode->pSdb, pOldDb);
goto _OUT;
} }
code = 0; code = 0;
...@@ -99,6 +114,22 @@ _OUT: ...@@ -99,6 +114,22 @@ _OUT:
return code; return code;
} }
static int32_t mndTransValidatePrepareAction(SMnode *pMnode, STrans *pTrans, STransAction *pAction) {
int32_t code = 0;
switch (pAction->pRaw->type) {
case SDB_VGROUP:
code = mndValidateNewVgPrepareAction(pMnode, pTrans, pAction);
break;
case SDB_DB:
code = mndValidateCreateDbPrepareAction(pMnode, pTrans, pAction);
break;
default:
}
return code;
}
static int32_t mndTransValidatePrepareStage(SMnode *pMnode, STrans *pTrans) { static int32_t mndTransValidatePrepareStage(SMnode *pMnode, STrans *pTrans) {
int32_t code = -1; int32_t code = -1;
int32_t action = 0; int32_t action = 0;
......
...@@ -79,6 +79,8 @@ const char *sdbStatusName(ESdbStatus status) { ...@@ -79,6 +79,8 @@ const char *sdbStatusName(ESdbStatus status) {
return "dropped"; return "dropped";
case SDB_STATUS_INIT: case SDB_STATUS_INIT:
return "init"; return "init";
case SDB_STATUS_UPDATE:
return "update";
default: default:
return "undefine"; return "undefine";
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册