serailze db req
This commit is contained in:
parent
1755559d94
commit
d7fc732de3
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
|
#include "mndAuth.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
|
@ -369,7 +370,7 @@ static int32_t mndSetCreateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
||||||
action.pCont = pReq;
|
action.pCont = pReq;
|
||||||
action.contLen = sizeof(SDropVnodeReq);
|
action.contLen = sizeof(SDropVnodeReq);
|
||||||
action.msgType = TDMT_DND_DROP_VNODE;
|
action.msgType = TDMT_DND_DROP_VNODE;
|
||||||
action.acceptableCode = TSDB_CODE_DND_VNODE_NOT_DEPLOYED;
|
action.acceptableCode = TSDB_CODE_DND_VNODE_NOT_DEPLOYED;
|
||||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||||
free(pReq);
|
free(pReq);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -451,54 +452,54 @@ CREATE_DB_OVER:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessCreateDbReq(SMnodeMsg *pReq) {
|
static int32_t mndProcessCreateDbReq(SMnodeMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->pMnode;
|
SMnode *pMnode = pReq->pMnode;
|
||||||
SCreateDbReq *pCreate = pReq->rpcMsg.pCont;
|
int32_t code = -1;
|
||||||
|
SDbObj *pDb = NULL;
|
||||||
|
SUserObj *pUser = NULL;
|
||||||
|
SCreateDbReq createReq = {0};
|
||||||
|
|
||||||
pCreate->numOfVgroups = htonl(pCreate->numOfVgroups);
|
if (tDeserializeSCreateDbReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &createReq) != 0) {
|
||||||
pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize);
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
pCreate->totalBlocks = htonl(pCreate->totalBlocks);
|
goto CREATE_DB_OVER;
|
||||||
pCreate->daysPerFile = htonl(pCreate->daysPerFile);
|
}
|
||||||
pCreate->daysToKeep0 = htonl(pCreate->daysToKeep0);
|
|
||||||
pCreate->daysToKeep1 = htonl(pCreate->daysToKeep1);
|
|
||||||
pCreate->daysToKeep2 = htonl(pCreate->daysToKeep2);
|
|
||||||
pCreate->minRows = htonl(pCreate->minRows);
|
|
||||||
pCreate->maxRows = htonl(pCreate->maxRows);
|
|
||||||
pCreate->commitTime = htonl(pCreate->commitTime);
|
|
||||||
pCreate->fsyncPeriod = htonl(pCreate->fsyncPeriod);
|
|
||||||
|
|
||||||
mDebug("db:%s, start to create, vgroups:%d", pCreate->db, pCreate->numOfVgroups);
|
mDebug("db:%s, start to create, vgroups:%d", createReq.db, createReq.numOfVgroups);
|
||||||
|
|
||||||
SDbObj *pDb = mndAcquireDb(pMnode, pCreate->db);
|
pDb = mndAcquireDb(pMnode, createReq.db);
|
||||||
if (pDb != NULL) {
|
if (pDb != NULL) {
|
||||||
mndReleaseDb(pMnode, pDb);
|
if (createReq.ignoreExist) {
|
||||||
if (pCreate->ignoreExist) {
|
mDebug("db:%s, already exist, ignore exist is set", createReq.db);
|
||||||
mDebug("db:%s, already exist, ignore exist is set", pCreate->db);
|
code = 0;
|
||||||
return 0;
|
goto CREATE_DB_OVER;
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_MND_DB_ALREADY_EXIST;
|
terrno = TSDB_CODE_MND_DB_ALREADY_EXIST;
|
||||||
mError("db:%s, failed to create since %s", pCreate->db, terrstr());
|
goto CREATE_DB_OVER;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
} else if (terrno != TSDB_CODE_MND_DB_NOT_EXIST) {
|
} else if (terrno != TSDB_CODE_MND_DB_NOT_EXIST) {
|
||||||
mError("db:%s, failed to create since %s", pCreate->db, terrstr());
|
goto CREATE_DB_OVER;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user);
|
pUser = mndAcquireUser(pMnode, pReq->user);
|
||||||
if (pOperUser == NULL) {
|
if (pUser == NULL) {
|
||||||
mError("db:%s, failed to create since %s", pCreate->db, terrstr());
|
goto CREATE_DB_OVER;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = mndCreateDb(pMnode, pReq, pCreate, pOperUser);
|
if (mndCheckCreateDbAuth(pUser) != 0) {
|
||||||
mndReleaseUser(pMnode, pOperUser);
|
goto CREATE_DB_OVER;
|
||||||
|
|
||||||
if (code != 0) {
|
|
||||||
mError("db:%s, failed to create since %s", pCreate->db, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
code = mndCreateDb(pMnode, pReq, &createReq, pUser);
|
||||||
|
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
CREATE_DB_OVER:
|
||||||
|
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||||
|
mError("db:%s, failed to create since %s", createReq.db, terrstr());
|
||||||
|
}
|
||||||
|
|
||||||
|
mndReleaseDb(pMnode, pDb);
|
||||||
|
mndReleaseUser(pMnode, pUser);
|
||||||
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) {
|
static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) {
|
||||||
|
@ -818,7 +819,7 @@ static int32_t mndProcessDropDbReq(SMnodeMsg *pReq) {
|
||||||
|
|
||||||
static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SVgroupInfo *vgList, int32_t *vgNum) {
|
static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SVgroupInfo *vgList, int32_t *vgNum) {
|
||||||
int32_t vindex = 0;
|
int32_t vindex = 0;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
while (vindex < pDb->cfg.numOfVgroups) {
|
while (vindex < pDb->cfg.numOfVgroups) {
|
||||||
|
@ -833,9 +834,9 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SVgroupInfo *vgLis
|
||||||
pInfo->hashEnd = htonl(pVgroup->hashEnd);
|
pInfo->hashEnd = htonl(pVgroup->hashEnd);
|
||||||
pInfo->epset.numOfEps = pVgroup->replica;
|
pInfo->epset.numOfEps = pVgroup->replica;
|
||||||
for (int32_t gid = 0; gid < pVgroup->replica; ++gid) {
|
for (int32_t gid = 0; gid < pVgroup->replica; ++gid) {
|
||||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[gid];
|
SVnodeGid *pVgid = &pVgroup->vnodeGid[gid];
|
||||||
SEp * pEp = &pInfo->epset.eps[gid];
|
SEp *pEp = &pInfo->epset.eps[gid];
|
||||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||||
if (pDnode != NULL) {
|
if (pDnode != NULL) {
|
||||||
memcpy(pEp->fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
memcpy(pEp->fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||||
pEp->port = htons(pDnode->port);
|
pEp->port = htons(pDnode->port);
|
||||||
|
@ -895,12 +896,12 @@ static int32_t mndProcessUseDbReq(SMnodeMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndValidateDBInfo(SMnode *pMnode, SDbVgVersion *dbs, int32_t num, void **rsp, int32_t *rspLen) {
|
int32_t mndValidateDBInfo(SMnode *pMnode, SDbVgVersion *dbs, int32_t num, void **rsp, int32_t *rspLen) {
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
int32_t bufSize = num * (sizeof(SUseDbRsp) + TSDB_DEFAULT_VN_PER_DB * sizeof(SVgroupInfo));
|
int32_t bufSize = num * (sizeof(SUseDbRsp) + TSDB_DEFAULT_VN_PER_DB * sizeof(SVgroupInfo));
|
||||||
void *buf = malloc(bufSize);
|
void *buf = malloc(bufSize);
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
int32_t contLen = 0;
|
int32_t contLen = 0;
|
||||||
int32_t bufOffset = 0;
|
int32_t bufOffset = 0;
|
||||||
SUseDbRsp *pRsp = NULL;
|
SUseDbRsp *pRsp = NULL;
|
||||||
|
|
||||||
for (int32_t i = 0; i < num; ++i) {
|
for (int32_t i = 0; i < num; ++i) {
|
||||||
|
@ -909,11 +910,11 @@ int32_t mndValidateDBInfo(SMnode *pMnode, SDbVgVersion *dbs, int32_t num, void *
|
||||||
db->vgVersion = ntohl(db->vgVersion);
|
db->vgVersion = ntohl(db->vgVersion);
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
|
|
||||||
SDbObj *pDb = mndAcquireDb(pMnode, db->dbFName);
|
SDbObj *pDb = mndAcquireDb(pMnode, db->dbFName);
|
||||||
if (pDb == NULL) {
|
if (pDb == NULL) {
|
||||||
mInfo("db %s not exist", db->dbFName);
|
mInfo("db %s not exist", db->dbFName);
|
||||||
|
|
||||||
len = sizeof(SUseDbRsp);
|
len = sizeof(SUseDbRsp);
|
||||||
} else if (pDb->uid != db->dbId || db->vgVersion < pDb->vgVersion) {
|
} else if (pDb->uid != db->dbId || db->vgVersion < pDb->vgVersion) {
|
||||||
len = sizeof(SUseDbRsp) + pDb->cfg.numOfVgroups * sizeof(SVgroupInfo);
|
len = sizeof(SUseDbRsp) + pDb->cfg.numOfVgroups * sizeof(SVgroupInfo);
|
||||||
|
@ -921,16 +922,16 @@ int32_t mndValidateDBInfo(SMnode *pMnode, SDbVgVersion *dbs, int32_t num, void *
|
||||||
|
|
||||||
if (0 == len) {
|
if (0 == len) {
|
||||||
mndReleaseDb(pMnode, pDb);
|
mndReleaseDb(pMnode, pDb);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
contLen += len;
|
contLen += len;
|
||||||
|
|
||||||
if (contLen > bufSize) {
|
if (contLen > bufSize) {
|
||||||
buf = realloc(buf, contLen);
|
buf = realloc(buf, contLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
pRsp = (SUseDbRsp *)((char *)buf + bufOffset);
|
pRsp = (SUseDbRsp *)((char *)buf + bufOffset);
|
||||||
memcpy(pRsp->db, db->dbFName, TSDB_DB_FNAME_LEN);
|
memcpy(pRsp->db, db->dbFName, TSDB_DB_FNAME_LEN);
|
||||||
if (pDb) {
|
if (pDb) {
|
||||||
|
@ -949,7 +950,7 @@ int32_t mndValidateDBInfo(SMnode *pMnode, SDbVgVersion *dbs, int32_t num, void *
|
||||||
}
|
}
|
||||||
|
|
||||||
bufOffset += len;
|
bufOffset += len;
|
||||||
|
|
||||||
mndReleaseDb(pMnode, pDb);
|
mndReleaseDb(pMnode, pDb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,29 +53,31 @@ TEST_F(MndTestDb, 01_ShowDb) {
|
||||||
|
|
||||||
TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
|
TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
|
||||||
{
|
{
|
||||||
int32_t contLen = sizeof(SCreateDbReq);
|
SCreateDbReq createReq = {0};
|
||||||
|
strcpy(createReq.db, "1.d1");
|
||||||
|
createReq.numOfVgroups = 2;
|
||||||
|
createReq.cacheBlockSize = 16;
|
||||||
|
createReq.totalBlocks = 10;
|
||||||
|
createReq.daysPerFile = 10;
|
||||||
|
createReq.daysToKeep0 = 3650;
|
||||||
|
createReq.daysToKeep1 = 3650;
|
||||||
|
createReq.daysToKeep2 = 3650;
|
||||||
|
createReq.minRows = 100;
|
||||||
|
createReq.maxRows = 4096;
|
||||||
|
createReq.commitTime = 3600;
|
||||||
|
createReq.fsyncPeriod = 3000;
|
||||||
|
createReq.walLevel = 1;
|
||||||
|
createReq.precision = 0;
|
||||||
|
createReq.compression = 2;
|
||||||
|
createReq.replications = 1;
|
||||||
|
createReq.quorum = 1;
|
||||||
|
createReq.update = 0;
|
||||||
|
createReq.cacheLastRow = 0;
|
||||||
|
createReq.ignoreExist = 1;
|
||||||
|
|
||||||
SCreateDbReq* pReq = (SCreateDbReq*)rpcMallocCont(contLen);
|
int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
|
||||||
strcpy(pReq->db, "1.d1");
|
void* pReq = rpcMallocCont(contLen);
|
||||||
pReq->numOfVgroups = htonl(2);
|
tSerializeSCreateDbReq(pReq, contLen, &createReq);
|
||||||
pReq->cacheBlockSize = htonl(16);
|
|
||||||
pReq->totalBlocks = htonl(10);
|
|
||||||
pReq->daysPerFile = htonl(10);
|
|
||||||
pReq->daysToKeep0 = htonl(3650);
|
|
||||||
pReq->daysToKeep1 = htonl(3650);
|
|
||||||
pReq->daysToKeep2 = htonl(3650);
|
|
||||||
pReq->minRows = htonl(100);
|
|
||||||
pReq->maxRows = htonl(4096);
|
|
||||||
pReq->commitTime = htonl(3600);
|
|
||||||
pReq->fsyncPeriod = htonl(3000);
|
|
||||||
pReq->walLevel = 1;
|
|
||||||
pReq->precision = 0;
|
|
||||||
pReq->compression = 2;
|
|
||||||
pReq->replications = 1;
|
|
||||||
pReq->quorum = 1;
|
|
||||||
pReq->update = 0;
|
|
||||||
pReq->cacheLastRow = 0;
|
|
||||||
pReq->ignoreExist = 1;
|
|
||||||
|
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
|
@ -217,29 +219,31 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
|
||||||
|
|
||||||
TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) {
|
TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) {
|
||||||
{
|
{
|
||||||
int32_t contLen = sizeof(SCreateDbReq);
|
SCreateDbReq createReq = {0};
|
||||||
|
strcpy(createReq.db, "1.d2");
|
||||||
|
createReq.numOfVgroups = 2;
|
||||||
|
createReq.cacheBlockSize = 16;
|
||||||
|
createReq.totalBlocks = 10;
|
||||||
|
createReq.daysPerFile = 10;
|
||||||
|
createReq.daysToKeep0 = 3650;
|
||||||
|
createReq.daysToKeep1 = 3650;
|
||||||
|
createReq.daysToKeep2 = 3650;
|
||||||
|
createReq.minRows = 100;
|
||||||
|
createReq.maxRows = 4096;
|
||||||
|
createReq.commitTime = 3600;
|
||||||
|
createReq.fsyncPeriod = 3000;
|
||||||
|
createReq.walLevel = 1;
|
||||||
|
createReq.precision = 0;
|
||||||
|
createReq.compression = 2;
|
||||||
|
createReq.replications = 1;
|
||||||
|
createReq.quorum = 1;
|
||||||
|
createReq.update = 0;
|
||||||
|
createReq.cacheLastRow = 0;
|
||||||
|
createReq.ignoreExist = 1;
|
||||||
|
|
||||||
SCreateDbReq* pReq = (SCreateDbReq*)rpcMallocCont(contLen);
|
int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
|
||||||
strcpy(pReq->db, "1.d2");
|
void* pReq = rpcMallocCont(contLen);
|
||||||
pReq->numOfVgroups = htonl(2);
|
tSerializeSCreateDbReq(pReq, contLen, &createReq);
|
||||||
pReq->cacheBlockSize = htonl(16);
|
|
||||||
pReq->totalBlocks = htonl(10);
|
|
||||||
pReq->daysPerFile = htonl(10);
|
|
||||||
pReq->daysToKeep0 = htonl(3650);
|
|
||||||
pReq->daysToKeep1 = htonl(3650);
|
|
||||||
pReq->daysToKeep2 = htonl(3650);
|
|
||||||
pReq->minRows = htonl(100);
|
|
||||||
pReq->maxRows = htonl(4096);
|
|
||||||
pReq->commitTime = htonl(3600);
|
|
||||||
pReq->fsyncPeriod = htonl(3000);
|
|
||||||
pReq->walLevel = 1;
|
|
||||||
pReq->precision = 0;
|
|
||||||
pReq->compression = 2;
|
|
||||||
pReq->replications = 1;
|
|
||||||
pReq->quorum = 1;
|
|
||||||
pReq->update = 0;
|
|
||||||
pReq->cacheLastRow = 0;
|
|
||||||
pReq->ignoreExist = 1;
|
|
||||||
|
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
|
|
|
@ -38,29 +38,31 @@ class MndTestStb : public ::testing::Test {
|
||||||
Testbase MndTestStb::test;
|
Testbase MndTestStb::test;
|
||||||
|
|
||||||
void* MndTestStb::BuildCreateDbReq(const char* dbname, int32_t* pContLen) {
|
void* MndTestStb::BuildCreateDbReq(const char* dbname, int32_t* pContLen) {
|
||||||
int32_t contLen = sizeof(SCreateDbReq);
|
SCreateDbReq createReq = {0};
|
||||||
|
strcpy(createReq.db, dbname);
|
||||||
|
createReq.numOfVgroups = 2;
|
||||||
|
createReq.cacheBlockSize = 16;
|
||||||
|
createReq.totalBlocks = 10;
|
||||||
|
createReq.daysPerFile = 10;
|
||||||
|
createReq.daysToKeep0 = 3650;
|
||||||
|
createReq.daysToKeep1 = 3650;
|
||||||
|
createReq.daysToKeep2 = 3650;
|
||||||
|
createReq.minRows = 100;
|
||||||
|
createReq.maxRows = 4096;
|
||||||
|
createReq.commitTime = 3600;
|
||||||
|
createReq.fsyncPeriod = 3000;
|
||||||
|
createReq.walLevel = 1;
|
||||||
|
createReq.precision = 0;
|
||||||
|
createReq.compression = 2;
|
||||||
|
createReq.replications = 1;
|
||||||
|
createReq.quorum = 1;
|
||||||
|
createReq.update = 0;
|
||||||
|
createReq.cacheLastRow = 0;
|
||||||
|
createReq.ignoreExist = 1;
|
||||||
|
|
||||||
SCreateDbReq* pReq = (SCreateDbReq*)rpcMallocCont(contLen);
|
int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
|
||||||
strcpy(pReq->db, dbname);
|
void* pReq = rpcMallocCont(contLen);
|
||||||
pReq->numOfVgroups = htonl(2);
|
tSerializeSCreateDbReq(pReq, contLen, &createReq);
|
||||||
pReq->cacheBlockSize = htonl(16);
|
|
||||||
pReq->totalBlocks = htonl(10);
|
|
||||||
pReq->daysPerFile = htonl(10);
|
|
||||||
pReq->daysToKeep0 = htonl(3650);
|
|
||||||
pReq->daysToKeep1 = htonl(3650);
|
|
||||||
pReq->daysToKeep2 = htonl(3650);
|
|
||||||
pReq->minRows = htonl(100);
|
|
||||||
pReq->maxRows = htonl(4096);
|
|
||||||
pReq->commitTime = htonl(3600);
|
|
||||||
pReq->fsyncPeriod = htonl(3000);
|
|
||||||
pReq->walLevel = 1;
|
|
||||||
pReq->precision = 0;
|
|
||||||
pReq->compression = 2;
|
|
||||||
pReq->replications = 1;
|
|
||||||
pReq->quorum = 1;
|
|
||||||
pReq->update = 0;
|
|
||||||
pReq->cacheLastRow = 0;
|
|
||||||
pReq->ignoreExist = 1;
|
|
||||||
|
|
||||||
*pContLen = contLen;
|
*pContLen = contLen;
|
||||||
return pReq;
|
return pReq;
|
||||||
|
|
|
@ -319,29 +319,31 @@ TEST_F(MndTestUser, 03_Alter_User) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
int32_t contLen = sizeof(SCreateDbReq);
|
SCreateDbReq createReq = {0};
|
||||||
|
strcpy(createReq.db, "1.d2");
|
||||||
|
createReq.numOfVgroups = 2;
|
||||||
|
createReq.cacheBlockSize = 16;
|
||||||
|
createReq.totalBlocks = 10;
|
||||||
|
createReq.daysPerFile = 10;
|
||||||
|
createReq.daysToKeep0 = 3650;
|
||||||
|
createReq.daysToKeep1 = 3650;
|
||||||
|
createReq.daysToKeep2 = 3650;
|
||||||
|
createReq.minRows = 100;
|
||||||
|
createReq.maxRows = 4096;
|
||||||
|
createReq.commitTime = 3600;
|
||||||
|
createReq.fsyncPeriod = 3000;
|
||||||
|
createReq.walLevel = 1;
|
||||||
|
createReq.precision = 0;
|
||||||
|
createReq.compression = 2;
|
||||||
|
createReq.replications = 1;
|
||||||
|
createReq.quorum = 1;
|
||||||
|
createReq.update = 0;
|
||||||
|
createReq.cacheLastRow = 0;
|
||||||
|
createReq.ignoreExist = 1;
|
||||||
|
|
||||||
SCreateDbReq* pReq = (SCreateDbReq*)rpcMallocCont(contLen);
|
int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
|
||||||
strcpy(pReq->db, "1.d2");
|
void* pReq = rpcMallocCont(contLen);
|
||||||
pReq->numOfVgroups = htonl(2);
|
tSerializeSCreateDbReq(pReq, contLen, &createReq);
|
||||||
pReq->cacheBlockSize = htonl(16);
|
|
||||||
pReq->totalBlocks = htonl(10);
|
|
||||||
pReq->daysPerFile = htonl(10);
|
|
||||||
pReq->daysToKeep0 = htonl(3650);
|
|
||||||
pReq->daysToKeep1 = htonl(3650);
|
|
||||||
pReq->daysToKeep2 = htonl(3650);
|
|
||||||
pReq->minRows = htonl(100);
|
|
||||||
pReq->maxRows = htonl(4096);
|
|
||||||
pReq->commitTime = htonl(3600);
|
|
||||||
pReq->fsyncPeriod = htonl(3000);
|
|
||||||
pReq->walLevel = 1;
|
|
||||||
pReq->precision = 0;
|
|
||||||
pReq->compression = 2;
|
|
||||||
pReq->replications = 1;
|
|
||||||
pReq->quorum = 1;
|
|
||||||
pReq->update = 0;
|
|
||||||
pReq->cacheLastRow = 0;
|
|
||||||
pReq->ignoreExist = 1;
|
|
||||||
|
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace {
|
||||||
extern "C" int32_t ctgGetTableMetaFromCache(struct SCatalog *pCatalog, const SName *pTableName, STableMeta **pTableMeta,
|
extern "C" int32_t ctgGetTableMetaFromCache(struct SCatalog *pCatalog, const SName *pTableName, STableMeta **pTableMeta,
|
||||||
int32_t *exist);
|
int32_t *exist);
|
||||||
extern "C" int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *output);
|
extern "C" int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *output);
|
||||||
extern "C" int32_t ctgDbgGetClusterCacheNum(struct SCatalog* pCatalog, int32_t type);
|
extern "C" int32_t ctgDbgGetClusterCacheNum(struct SCatalog *pCatalog, int32_t type);
|
||||||
|
|
||||||
void ctgTestSetPrepareTableMeta();
|
void ctgTestSetPrepareTableMeta();
|
||||||
void ctgTestSetPrepareCTableMeta();
|
void ctgTestSetPrepareCTableMeta();
|
||||||
|
@ -52,14 +52,14 @@ bool ctgTestDeadLoop = false;
|
||||||
int32_t ctgTestPrintNum = 200000;
|
int32_t ctgTestPrintNum = 200000;
|
||||||
int32_t ctgTestMTRunSec = 5;
|
int32_t ctgTestMTRunSec = 5;
|
||||||
|
|
||||||
int32_t ctgTestCurrentVgVersion = 0;
|
int32_t ctgTestCurrentVgVersion = 0;
|
||||||
int32_t ctgTestVgVersion = 1;
|
int32_t ctgTestVgVersion = 1;
|
||||||
int32_t ctgTestVgNum = 10;
|
int32_t ctgTestVgNum = 10;
|
||||||
int32_t ctgTestColNum = 2;
|
int32_t ctgTestColNum = 2;
|
||||||
int32_t ctgTestTagNum = 1;
|
int32_t ctgTestTagNum = 1;
|
||||||
int32_t ctgTestSVersion = 1;
|
int32_t ctgTestSVersion = 1;
|
||||||
int32_t ctgTestTVersion = 1;
|
int32_t ctgTestTVersion = 1;
|
||||||
int32_t ctgTestSuid = 2;
|
int32_t ctgTestSuid = 2;
|
||||||
uint64_t ctgTestDbId = 33;
|
uint64_t ctgTestDbId = 33;
|
||||||
|
|
||||||
uint64_t ctgTestClusterId = 0x1;
|
uint64_t ctgTestClusterId = 0x1;
|
||||||
|
@ -69,31 +69,35 @@ char *ctgTestCTablename = "ctable1";
|
||||||
char *ctgTestSTablename = "stable1";
|
char *ctgTestSTablename = "stable1";
|
||||||
|
|
||||||
void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) {
|
void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) {
|
||||||
SCreateDbReq *pReq = (SCreateDbReq *)rpcMallocCont(sizeof(SCreateDbReq));
|
SCreateDbReq createReq = {0};
|
||||||
strcpy(pReq->db, "1.db1");
|
strcpy(createReq.db, "1.db1");
|
||||||
pReq->numOfVgroups = htonl(2);
|
createReq.numOfVgroups = 2;
|
||||||
pReq->cacheBlockSize = htonl(16);
|
createReq.cacheBlockSize = 16;
|
||||||
pReq->totalBlocks = htonl(10);
|
createReq.totalBlocks = 10;
|
||||||
pReq->daysPerFile = htonl(10);
|
createReq.daysPerFile = 10;
|
||||||
pReq->daysToKeep0 = htonl(3650);
|
createReq.daysToKeep0 = 3650;
|
||||||
pReq->daysToKeep1 = htonl(3650);
|
createReq.daysToKeep1 = 3650;
|
||||||
pReq->daysToKeep2 = htonl(3650);
|
createReq.daysToKeep2 = 3650;
|
||||||
pReq->minRows = htonl(100);
|
createReq.minRows = 100;
|
||||||
pReq->maxRows = htonl(4096);
|
createReq.maxRows = 4096;
|
||||||
pReq->commitTime = htonl(3600);
|
createReq.commitTime = 3600;
|
||||||
pReq->fsyncPeriod = htonl(3000);
|
createReq.fsyncPeriod = 3000;
|
||||||
pReq->walLevel = 1;
|
createReq.walLevel = 1;
|
||||||
pReq->precision = 0;
|
createReq.precision = 0;
|
||||||
pReq->compression = 2;
|
createReq.compression = 2;
|
||||||
pReq->replications = 1;
|
createReq.replications = 1;
|
||||||
pReq->quorum = 1;
|
createReq.quorum = 1;
|
||||||
pReq->update = 0;
|
createReq.update = 0;
|
||||||
pReq->cacheLastRow = 0;
|
createReq.cacheLastRow = 0;
|
||||||
pReq->ignoreExist = 1;
|
createReq.ignoreExist = 1;
|
||||||
|
|
||||||
|
int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
|
||||||
|
void *pReq = rpcMallocCont(contLen);
|
||||||
|
tSerializeSCreateDbReq(pReq, contLen, &createReq);
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg rpcMsg = {0};
|
||||||
rpcMsg.pCont = pReq;
|
rpcMsg.pCont = pReq;
|
||||||
rpcMsg.contLen = sizeof(SCreateDbReq);
|
rpcMsg.contLen = contLen;
|
||||||
rpcMsg.msgType = TDMT_MND_CREATE_DB;
|
rpcMsg.msgType = TDMT_MND_CREATE_DB;
|
||||||
|
|
||||||
SRpcMsg rpcRsp = {0};
|
SRpcMsg rpcRsp = {0};
|
||||||
|
@ -210,7 +214,6 @@ void ctgTestBuildDBVgroup(SDBVgroupInfo **pdbVgroup) {
|
||||||
*pdbVgroup = dbVgroup;
|
*pdbVgroup = dbVgroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) {
|
void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) {
|
||||||
strcpy(rspMsg->dbFName, ctgTestDbname);
|
strcpy(rspMsg->dbFName, ctgTestDbname);
|
||||||
sprintf(rspMsg->tbName, "%s", ctgTestSTablename);
|
sprintf(rspMsg->tbName, "%s", ctgTestSTablename);
|
||||||
|
@ -248,7 +251,6 @@ void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ctgTestPrepareDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
void ctgTestPrepareDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||||
SUseDbRsp *rspMsg = NULL; // todo
|
SUseDbRsp *rspMsg = NULL; // todo
|
||||||
|
|
||||||
|
@ -372,8 +374,8 @@ void ctgTestPrepareSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpc
|
||||||
pRsp->pCont = calloc(1, pRsp->contLen);
|
pRsp->pCont = calloc(1, pRsp->contLen);
|
||||||
rspMsg = (STableMetaRsp *)pRsp->pCont;
|
rspMsg = (STableMetaRsp *)pRsp->pCont;
|
||||||
strcpy(rspMsg->dbFName, ctgTestDbname);
|
strcpy(rspMsg->dbFName, ctgTestDbname);
|
||||||
strcpy(rspMsg->tbName, ctgTestSTablename);
|
strcpy(rspMsg->tbName, ctgTestSTablename);
|
||||||
strcpy(rspMsg->stbName, ctgTestSTablename);
|
strcpy(rspMsg->stbName, ctgTestSTablename);
|
||||||
rspMsg->numOfTags = htonl(ctgTestTagNum);
|
rspMsg->numOfTags = htonl(ctgTestTagNum);
|
||||||
rspMsg->numOfColumns = htonl(ctgTestColNum);
|
rspMsg->numOfColumns = htonl(ctgTestColNum);
|
||||||
rspMsg->precision = 1;
|
rspMsg->precision = 1;
|
||||||
|
@ -635,7 +637,7 @@ void *ctgTestGetDbVgroupThread(void *param) {
|
||||||
void *ctgTestSetSameDbVgroupThread(void *param) {
|
void *ctgTestSetSameDbVgroupThread(void *param) {
|
||||||
struct SCatalog *pCtg = (struct SCatalog *)param;
|
struct SCatalog *pCtg = (struct SCatalog *)param;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SDBVgroupInfo *dbVgroup = NULL;
|
SDBVgroupInfo *dbVgroup = NULL;
|
||||||
int32_t n = 0;
|
int32_t n = 0;
|
||||||
|
|
||||||
while (!ctgTestStop) {
|
while (!ctgTestStop) {
|
||||||
|
@ -656,11 +658,10 @@ void *ctgTestSetSameDbVgroupThread(void *param) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *ctgTestSetDiffDbVgroupThread(void *param) {
|
void *ctgTestSetDiffDbVgroupThread(void *param) {
|
||||||
struct SCatalog *pCtg = (struct SCatalog *)param;
|
struct SCatalog *pCtg = (struct SCatalog *)param;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SDBVgroupInfo *dbVgroup = NULL;
|
SDBVgroupInfo *dbVgroup = NULL;
|
||||||
int32_t n = 0;
|
int32_t n = 0;
|
||||||
|
|
||||||
while (!ctgTestStop) {
|
while (!ctgTestStop) {
|
||||||
|
@ -681,7 +682,6 @@ void *ctgTestSetDiffDbVgroupThread(void *param) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *ctgTestGetCtableMetaThread(void *param) {
|
void *ctgTestGetCtableMetaThread(void *param) {
|
||||||
struct SCatalog *pCtg = (struct SCatalog *)param;
|
struct SCatalog *pCtg = (struct SCatalog *)param;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -741,7 +741,6 @@ void *ctgTestSetCtableMetaThread(void *param) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(tableMeta, normalTable) {
|
TEST(tableMeta, normalTable) {
|
||||||
struct SCatalog *pCtg = NULL;
|
struct SCatalog *pCtg = NULL;
|
||||||
void *mockPointer = (void *)0x1;
|
void *mockPointer = (void *)0x1;
|
||||||
|
@ -914,7 +913,7 @@ TEST(tableMeta, childTableCase) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stbNum) {
|
if (stbNum) {
|
||||||
printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
|
printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
|
||||||
free(stb);
|
free(stb);
|
||||||
stb = NULL;
|
stb = NULL;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1016,7 +1015,7 @@ TEST(tableMeta, superTableCase) {
|
||||||
|
|
||||||
if (stbNum) {
|
if (stbNum) {
|
||||||
printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
|
printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
|
||||||
|
|
||||||
free(stb);
|
free(stb);
|
||||||
stb = NULL;
|
stb = NULL;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1078,7 +1077,7 @@ TEST(tableMeta, rmStbMeta) {
|
||||||
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 0);
|
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 0);
|
||||||
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1);
|
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1);
|
||||||
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 0);
|
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 0);
|
||||||
|
|
||||||
catalogDestroy();
|
catalogDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1146,12 +1145,10 @@ TEST(tableMeta, updateStbMeta) {
|
||||||
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
|
||||||
tfree(tableMeta);
|
tfree(tableMeta);
|
||||||
|
|
||||||
catalogDestroy();
|
catalogDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST(tableDistVgroup, normalTable) {
|
TEST(tableDistVgroup, normalTable) {
|
||||||
struct SCatalog *pCtg = NULL;
|
struct SCatalog *pCtg = NULL;
|
||||||
void *mockPointer = (void *)0x1;
|
void *mockPointer = (void *)0x1;
|
||||||
|
@ -1258,7 +1255,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
|
||||||
void *mockPointer = (void *)0x1;
|
void *mockPointer = (void *)0x1;
|
||||||
SVgroupInfo vgInfo = {0};
|
SVgroupInfo vgInfo = {0};
|
||||||
SVgroupInfo *pvgInfo = NULL;
|
SVgroupInfo *pvgInfo = NULL;
|
||||||
SDBVgroupInfo *dbVgroup = NULL;
|
SDBVgroupInfo *dbVgroup = NULL;
|
||||||
SArray *vgList = NULL;
|
SArray *vgList = NULL;
|
||||||
|
|
||||||
ctgTestInitLogFile();
|
ctgTestInitLogFile();
|
||||||
|
@ -1418,8 +1415,6 @@ TEST(multiThread, getSetRmDiffDbVgroup) {
|
||||||
catalogDestroy();
|
catalogDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST(multiThread, ctableMeta) {
|
TEST(multiThread, ctableMeta) {
|
||||||
struct SCatalog *pCtg = NULL;
|
struct SCatalog *pCtg = NULL;
|
||||||
void *mockPointer = (void *)0x1;
|
void *mockPointer = (void *)0x1;
|
||||||
|
@ -1470,8 +1465,6 @@ TEST(multiThread, ctableMeta) {
|
||||||
catalogDestroy();
|
catalogDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST(rentTest, allRent) {
|
TEST(rentTest, allRent) {
|
||||||
struct SCatalog *pCtg = NULL;
|
struct SCatalog *pCtg = NULL;
|
||||||
void *mockPointer = (void *)0x1;
|
void *mockPointer = (void *)0x1;
|
||||||
|
@ -1530,7 +1523,8 @@ TEST(rentTest, allRent) {
|
||||||
printf("%d - expired stableNum:%d\n", i, num);
|
printf("%d - expired stableNum:%d\n", i, num);
|
||||||
if (stable) {
|
if (stable) {
|
||||||
for (int32_t n = 0; n < num; ++n) {
|
for (int32_t n = 0; n < num; ++n) {
|
||||||
printf("suid:%" PRId64 ", dbFName:%s, stbName:%s, sversion:%d, tversion:%d\n", stable[n].suid, stable[n].dbFName, stable[n].stbName, stable[n].sversion, stable[n].tversion);
|
printf("suid:%" PRId64 ", dbFName:%s, stbName:%s, sversion:%d, tversion:%d\n", stable[n].suid,
|
||||||
|
stable[n].dbFName, stable[n].stbName, stable[n].sversion, stable[n].tversion);
|
||||||
}
|
}
|
||||||
free(stable);
|
free(stable);
|
||||||
stable = NULL;
|
stable = NULL;
|
||||||
|
|
|
@ -77,7 +77,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PTR, "Invalid pointer")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MEMORY_CORRUPTED, "Memory corrupted")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MEMORY_CORRUPTED, "Memory corrupted")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_FILE_CORRUPTED, "Data file corrupted")
|
TAOS_DEFINE_ERROR(TSDB_CODE_FILE_CORRUPTED, "Data file corrupted")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_CHECKSUM_ERROR, "Checksum error")
|
TAOS_DEFINE_ERROR(TSDB_CODE_CHECKSUM_ERROR, "Checksum error")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG, "Invalid config message")
|
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG, "Invalid message")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MSG_NOT_PROCESSED, "Message not processed")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MSG_NOT_PROCESSED, "Message not processed")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PARA, "Invalid parameters")
|
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PARA, "Invalid parameters")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_REPEAT_INIT, "Repeat initialization")
|
TAOS_DEFINE_ERROR(TSDB_CODE_REPEAT_INIT, "Repeat initialization")
|
||||||
|
|
Loading…
Reference in New Issue