commit
41b9a1610f
|
@ -726,6 +726,7 @@ typedef struct {
|
|||
char tbName[TSDB_TABLE_NAME_LEN];
|
||||
char stbName[TSDB_TABLE_NAME_LEN];
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
uint64_t dbId;
|
||||
int32_t numOfTags;
|
||||
int32_t numOfColumns;
|
||||
int8_t precision;
|
||||
|
|
|
@ -32,6 +32,15 @@ extern "C" {
|
|||
|
||||
struct SCatalog;
|
||||
|
||||
enum {
|
||||
CTG_DBG_DB_NUM = 1,
|
||||
CTG_DBG_META_NUM,
|
||||
CTG_DBG_STB_NUM,
|
||||
CTG_DBG_DB_RENT_NUM,
|
||||
CTG_DBG_STB_RENT_NUM,
|
||||
};
|
||||
|
||||
|
||||
typedef struct SCatalogReq {
|
||||
SArray *pTableName; // element is SNAME
|
||||
SArray *pUdf; // udf name
|
||||
|
@ -99,7 +108,7 @@ int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName,
|
|||
*/
|
||||
int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const char* pDBName, bool forceUpdate, SArray** pVgroupList);
|
||||
|
||||
int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo);
|
||||
int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, uint64_t dbId, SDBVgroupInfo* dbInfo);
|
||||
|
||||
int32_t catalogRemoveDB(struct SCatalog* pCatalog, const char* dbName, uint64_t dbId);
|
||||
|
||||
|
@ -127,6 +136,8 @@ int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void * pTransporter, cons
|
|||
*/
|
||||
int32_t catalogGetSTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
|
||||
|
||||
int32_t catalogUpdateSTableMeta(struct SCatalog* pCatalog, STableMetaRsp *rspMsg);
|
||||
|
||||
|
||||
/**
|
||||
* Force renew a table's local cached meta data.
|
||||
|
|
|
@ -81,7 +81,6 @@ typedef struct STableMeta {
|
|||
} STableMeta;
|
||||
|
||||
typedef struct SDBVgroupInfo {
|
||||
uint64_t dbId;
|
||||
int32_t vgVersion;
|
||||
int8_t hashMethod;
|
||||
SHashObj *vgHash; //key:vgId, value:SVgroupInfo
|
||||
|
@ -89,6 +88,7 @@ typedef struct SDBVgroupInfo {
|
|||
|
||||
typedef struct SUseDbOutput {
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
uint64_t dbId;
|
||||
SDBVgroupInfo *dbVgroup;
|
||||
} SUseDbOutput;
|
||||
|
||||
|
@ -102,6 +102,7 @@ enum {
|
|||
|
||||
typedef struct STableMetaOutput {
|
||||
int32_t metaType;
|
||||
uint64_t dbId;
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
char ctbName[TSDB_TABLE_NAME_LEN];
|
||||
char tbName[TSDB_TABLE_NAME_LEN];
|
||||
|
@ -159,6 +160,8 @@ void initQueryModuleMsgHandle();
|
|||
const SSchema* tGetTbnameColumnSchema();
|
||||
bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);
|
||||
|
||||
int32_t queryCreateTableMetaFromMsg(STableMetaRsp* msg, bool isSuperTable, STableMeta **pMeta);
|
||||
|
||||
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen);
|
||||
extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t msgSize);
|
||||
|
||||
|
|
|
@ -435,6 +435,8 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_CTG_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x2402) //catalog is not ready
|
||||
#define TSDB_CODE_CTG_MEM_ERROR TAOS_DEF_ERROR_CODE(0, 0x2403) //catalog memory error
|
||||
#define TSDB_CODE_CTG_SYS_ERROR TAOS_DEF_ERROR_CODE(0, 0x2404) //catalog system error
|
||||
#define TSDB_CODE_CTG_DB_DROPPED TAOS_DEF_ERROR_CODE(0, 0x2405) //Database is dropped
|
||||
#define TSDB_CODE_CTG_OUT_OF_SERVICE TAOS_DEF_ERROR_CODE(0, 0x2406) //catalog is out of service
|
||||
|
||||
//scheduler
|
||||
#define TSDB_CODE_SCH_STATUS_ERROR TAOS_DEF_ERROR_CODE(0, 0x2501) //scheduler status error
|
||||
|
|
|
@ -44,7 +44,6 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog
|
|||
code = catalogRemoveDB(pCatalog, rsp->db, rsp->uid);
|
||||
} else {
|
||||
SDBVgroupInfo vgInfo = {0};
|
||||
vgInfo.dbId = rsp->uid;
|
||||
vgInfo.vgVersion = rsp->vgVersion;
|
||||
vgInfo.hashMethod = rsp->hashMethod;
|
||||
vgInfo.vgHash = taosHashInit(rsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
|
@ -69,7 +68,7 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog
|
|||
}
|
||||
}
|
||||
|
||||
code = catalogUpdateDBVgroup(pCatalog, rsp->db, &vgInfo);
|
||||
code = catalogUpdateDBVgroup(pCatalog, rsp->db, rsp->uid, &vgInfo);
|
||||
if (code) {
|
||||
taosHashCleanup(vgInfo.vgHash);
|
||||
}
|
||||
|
@ -101,50 +100,33 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo
|
|||
|
||||
tscDebug("hb remove stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName);
|
||||
|
||||
code = catalogRemoveSTableMeta(pCatalog, rsp->dbFName, rsp->stbName, rsp->suid);
|
||||
catalogRemoveSTableMeta(pCatalog, rsp->dbFName, rsp->stbName, rsp->suid);
|
||||
} else {
|
||||
tscDebug("hb update stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName);
|
||||
|
||||
rsp->numOfTags = ntohl(rsp->numOfTags);
|
||||
rsp->sversion = ntohl(rsp->sversion);
|
||||
rsp->tversion = ntohl(rsp->tversion);
|
||||
rsp->tuid = be64toh(rsp->tuid);
|
||||
rsp->vgId = ntohl(rsp->vgId);
|
||||
|
||||
SSchema* pSchema = rsp->pSchema;
|
||||
|
||||
schemaNum = rsp->numOfColumns + rsp->numOfTags;
|
||||
/*
|
||||
rsp->vgNum = ntohl(rsp->vgNum);
|
||||
rsp->uid = be64toh(rsp->uid);
|
||||
|
||||
SDBVgroupInfo vgInfo = {0};
|
||||
vgInfo.dbId = rsp->uid;
|
||||
vgInfo.vgVersion = rsp->vgVersion;
|
||||
vgInfo.hashMethod = rsp->hashMethod;
|
||||
vgInfo.vgHash = taosHashInit(rsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
if (NULL == vgInfo.vgHash) {
|
||||
tscError("hash init[%d] failed", rsp->vgNum);
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
for (int i = 0; i < schemaNum; ++i) {
|
||||
pSchema->bytes = ntohl(pSchema->bytes);
|
||||
pSchema->colId = ntohl(pSchema->colId);
|
||||
|
||||
pSchema++;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < rsp->vgNum; ++i) {
|
||||
rsp->vgroupInfo[i].vgId = ntohl(rsp->vgroupInfo[i].vgId);
|
||||
rsp->vgroupInfo[i].hashBegin = ntohl(rsp->vgroupInfo[i].hashBegin);
|
||||
rsp->vgroupInfo[i].hashEnd = ntohl(rsp->vgroupInfo[i].hashEnd);
|
||||
if (rsp->pSchema[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
tscError("invalid colId[%d] for the first column in table meta rsp msg", rsp->pSchema[0].colId);
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
for (int32_t n = 0; n < rsp->vgroupInfo[i].epset.numOfEps; ++n) {
|
||||
rsp->vgroupInfo[i].epset.eps[n].port = ntohs(rsp->vgroupInfo[i].epset.eps[n].port);
|
||||
}
|
||||
|
||||
if (0 != taosHashPut(vgInfo.vgHash, &rsp->vgroupInfo[i].vgId, sizeof(rsp->vgroupInfo[i].vgId), &rsp->vgroupInfo[i], sizeof(rsp->vgroupInfo[i]))) {
|
||||
tscError("hash push failed, errno:%d", errno);
|
||||
taosHashCleanup(vgInfo.vgHash);
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
code = catalogUpdateDBVgroup(pCatalog, rsp->db, &vgInfo);
|
||||
if (code) {
|
||||
taosHashCleanup(vgInfo.vgHash);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if (code) {
|
||||
return code;
|
||||
catalogUpdateSTableMeta(pCatalog, rsp);
|
||||
}
|
||||
|
||||
msgLen += sizeof(STableMetaRsp) + schemaNum * sizeof(SSchema);
|
||||
|
|
|
@ -1165,6 +1165,7 @@ static int32_t mndProcessStbMetaReq(SMnodeMsg *pReq) {
|
|||
strcpy(pMeta->dbFName, pStb->db);
|
||||
strcpy(pMeta->tbName, pInfo->tbName);
|
||||
strcpy(pMeta->stbName, pInfo->tbName);
|
||||
pMeta->dbId = htobe64(pDb->uid);
|
||||
pMeta->numOfTags = htonl(pStb->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pStb->numOfColumns);
|
||||
pMeta->precision = pDb->cfg.precision;
|
||||
|
|
|
@ -48,18 +48,22 @@ enum {
|
|||
};
|
||||
|
||||
typedef struct SCtgDebug {
|
||||
int32_t lockDebug;
|
||||
bool lockDebug;
|
||||
bool cacheDebug;
|
||||
uint32_t showCachePeriodSec;
|
||||
} SCtgDebug;
|
||||
|
||||
|
||||
typedef struct SCtgTbMetaCache {
|
||||
SRWLatch stbLock;
|
||||
SHashObj *cache; //key:tbname, value:STableMeta
|
||||
SRWLatch metaLock; // RC between cache destroy and all other operations
|
||||
SHashObj *metaCache; //key:tbname, value:STableMeta
|
||||
SHashObj *stbCache; //key:suid, value:STableMeta*
|
||||
} SCtgTbMetaCache;
|
||||
|
||||
typedef struct SCtgDBCache {
|
||||
SRWLatch vgLock;
|
||||
uint64_t dbId;
|
||||
int8_t deleted;
|
||||
SDBVgroupInfo *vgInfo;
|
||||
SCtgTbMetaCache tbCache;
|
||||
|
@ -81,6 +85,7 @@ typedef struct SCtgRentMgmt {
|
|||
|
||||
typedef struct SCatalog {
|
||||
uint64_t clusterId;
|
||||
SRWLatch dbLock;
|
||||
SHashObj *dbCache; //key:dbname, value:SCtgDBCache
|
||||
SCtgRentMgmt dbRent;
|
||||
SCtgRentMgmt stbRent;
|
||||
|
@ -105,6 +110,8 @@ typedef struct SCatalogStat {
|
|||
} SCatalogStat;
|
||||
|
||||
typedef struct SCatalogMgmt {
|
||||
bool exit;
|
||||
SRWLatch lock;
|
||||
SHashObj *pCluster; //key: clusterId, value: SCatalog*
|
||||
SCatalogStat stat;
|
||||
SCatalogCfg cfg;
|
||||
|
@ -132,11 +139,8 @@ typedef uint32_t (*tableNameHashFp)(const char *, uint32_t);
|
|||
#define ctgDebug(param, ...) qDebug("CTG:%p " param, pCatalog, __VA_ARGS__)
|
||||
#define ctgTrace(param, ...) qTrace("CTG:%p " param, pCatalog, __VA_ARGS__)
|
||||
|
||||
#define CTG_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
|
||||
#define CTG_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
|
||||
#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
|
||||
|
||||
#define CTG_LOCK_DEBUG(...) do { if (gCTGDebug.lockDebug) { qDebug(__VA_ARGS__); } } while (0)
|
||||
#define CTG_CACHE_DEBUG(...) do { if (gCTGDebug.cacheDebug) { qDebug(__VA_ARGS__); } } while (0)
|
||||
|
||||
#define TD_RWLATCH_WRITE_FLAG_COPY 0x40000000
|
||||
|
||||
|
@ -172,6 +176,15 @@ typedef uint32_t (*tableNameHashFp)(const char *, uint32_t);
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define CTG_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
|
||||
#define CTG_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
|
||||
#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
|
||||
|
||||
#define CTG_API_ENTER() do { CTG_LOCK(CTG_READ, &ctgMgmt.lock); if (atomic_load_8(&ctgMgmt.exit)) { CTG_RET(TSDB_CODE_CTG_OUT_OF_SERVICE); } } while (0)
|
||||
#define CTG_API_LEAVE(c) do { int32_t __code = c; CTG_UNLOCK(CTG_READ, &ctgMgmt.lock); CTG_RET(__code); } while (0)
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -39,6 +39,7 @@ namespace {
|
|||
extern "C" int32_t ctgGetTableMetaFromCache(struct SCatalog *pCatalog, const SName *pTableName, STableMeta **pTableMeta,
|
||||
int32_t *exist);
|
||||
extern "C" int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *output);
|
||||
extern "C" int32_t ctgDbgGetClusterCacheNum(struct SCatalog* pCatalog, int32_t type);
|
||||
|
||||
void ctgTestSetPrepareTableMeta();
|
||||
void ctgTestSetPrepareCTableMeta();
|
||||
|
@ -49,7 +50,7 @@ bool ctgTestStop = false;
|
|||
bool ctgTestEnableSleep = false;
|
||||
bool ctgTestDeadLoop = false;
|
||||
int32_t ctgTestPrintNum = 200000;
|
||||
int32_t ctgTestMTRunSec = 30;
|
||||
int32_t ctgTestMTRunSec = 5;
|
||||
|
||||
int32_t ctgTestCurrentVgVersion = 0;
|
||||
int32_t ctgTestVgVersion = 1;
|
||||
|
@ -107,6 +108,7 @@ void ctgTestInitLogFile() {
|
|||
const int32_t maxLogFileNum = 10;
|
||||
|
||||
tsAsyncLog = 0;
|
||||
qDebugFlag = 159;
|
||||
|
||||
char temp[128] = {0};
|
||||
sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix);
|
||||
|
@ -185,7 +187,6 @@ void ctgTestBuildDBVgroup(SDBVgroupInfo **pdbVgroup) {
|
|||
ctgTestCurrentVgVersion = dbVgroup->vgVersion;
|
||||
|
||||
dbVgroup->hashMethod = 0;
|
||||
dbVgroup->dbId = ctgTestDbId;
|
||||
dbVgroup->vgHash = taosHashInit(ctgTestVgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
|
||||
vgNum = ctgTestGetVgNumFromVgVersion(dbVgroup->vgVersion);
|
||||
|
@ -209,6 +210,45 @@ void ctgTestBuildDBVgroup(SDBVgroupInfo **pdbVgroup) {
|
|||
*pdbVgroup = dbVgroup;
|
||||
}
|
||||
|
||||
|
||||
void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) {
|
||||
strcpy(rspMsg->dbFName, ctgTestDbname);
|
||||
sprintf(rspMsg->tbName, "%s", ctgTestSTablename);
|
||||
sprintf(rspMsg->stbName, "%s", ctgTestSTablename);
|
||||
rspMsg->numOfTags = ctgTestTagNum;
|
||||
rspMsg->numOfColumns = ctgTestColNum;
|
||||
rspMsg->precision = 1 + 1;
|
||||
rspMsg->tableType = TSDB_SUPER_TABLE;
|
||||
rspMsg->update = 1 + 1;
|
||||
rspMsg->sversion = ctgTestSVersion + 1;
|
||||
rspMsg->tversion = ctgTestTVersion + 1;
|
||||
rspMsg->suid = ctgTestSuid + 1;
|
||||
rspMsg->tuid = ctgTestSuid + 1;
|
||||
rspMsg->vgId = 1;
|
||||
|
||||
SSchema *s = NULL;
|
||||
s = &rspMsg->pSchema[0];
|
||||
s->type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
s->colId = 1;
|
||||
s->bytes = 8;
|
||||
strcpy(s->name, "ts");
|
||||
|
||||
s = &rspMsg->pSchema[1];
|
||||
s->type = TSDB_DATA_TYPE_INT;
|
||||
s->colId = 2;
|
||||
s->bytes = 4;
|
||||
strcpy(s->name, "col1s");
|
||||
|
||||
s = &rspMsg->pSchema[2];
|
||||
s->type = TSDB_DATA_TYPE_BINARY;
|
||||
s->colId = 3;
|
||||
s->bytes = 12 + 1;
|
||||
strcpy(s->name, "tag1s");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void ctgTestPrepareDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
SUseDbRsp *rspMsg = NULL; // todo
|
||||
|
||||
|
@ -592,7 +632,7 @@ void *ctgTestGetDbVgroupThread(void *param) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void *ctgTestSetDbVgroupThread(void *param) {
|
||||
void *ctgTestSetSameDbVgroupThread(void *param) {
|
||||
struct SCatalog *pCtg = (struct SCatalog *)param;
|
||||
int32_t code = 0;
|
||||
SDBVgroupInfo *dbVgroup = NULL;
|
||||
|
@ -600,7 +640,7 @@ void *ctgTestSetDbVgroupThread(void *param) {
|
|||
|
||||
while (!ctgTestStop) {
|
||||
ctgTestBuildDBVgroup(&dbVgroup);
|
||||
code = catalogUpdateDBVgroup(pCtg, ctgTestDbname, dbVgroup);
|
||||
code = catalogUpdateDBVgroup(pCtg, ctgTestDbname, ctgTestDbId, dbVgroup);
|
||||
if (code) {
|
||||
assert(0);
|
||||
}
|
||||
|
@ -616,6 +656,32 @@ void *ctgTestSetDbVgroupThread(void *param) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void *ctgTestSetDiffDbVgroupThread(void *param) {
|
||||
struct SCatalog *pCtg = (struct SCatalog *)param;
|
||||
int32_t code = 0;
|
||||
SDBVgroupInfo *dbVgroup = NULL;
|
||||
int32_t n = 0;
|
||||
|
||||
while (!ctgTestStop) {
|
||||
ctgTestBuildDBVgroup(&dbVgroup);
|
||||
code = catalogUpdateDBVgroup(pCtg, ctgTestDbname, ctgTestDbId++, dbVgroup);
|
||||
if (code) {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
if (ctgTestEnableSleep) {
|
||||
usleep(rand() % 5);
|
||||
}
|
||||
if (++n % ctgTestPrintNum == 0) {
|
||||
printf("Set:%d\n", n);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void *ctgTestGetCtableMetaThread(void *param) {
|
||||
struct SCatalog *pCtg = (struct SCatalog *)param;
|
||||
int32_t code = 0;
|
||||
|
@ -681,6 +747,8 @@ TEST(tableMeta, normalTable) {
|
|||
void *mockPointer = (void *)0x1;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
ctgTestSetPrepareDbVgroups();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
@ -771,6 +839,8 @@ TEST(tableMeta, childTableCase) {
|
|||
void *mockPointer = (void *)0x1;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
ctgTestSetPrepareDbVgroupsAndChildMeta();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
@ -964,6 +1034,124 @@ TEST(tableMeta, superTableCase) {
|
|||
catalogDestroy();
|
||||
}
|
||||
|
||||
TEST(tableMeta, rmStbMeta) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
void *mockPointer = (void *)0x1;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
ctgTestSetPrepareDbVgroupsAndSuperMeta();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
int32_t code = catalogInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
// sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||
strcpy(n.dbname, "db1");
|
||||
strcpy(n.tname, ctgTestSTablename);
|
||||
|
||||
STableMeta *tableMeta = NULL;
|
||||
code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(tableMeta->vgId, 0);
|
||||
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
||||
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||
ASSERT_EQ(tableMeta->uid, ctgTestSuid);
|
||||
ASSERT_EQ(tableMeta->suid, ctgTestSuid);
|
||||
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||
|
||||
code = catalogRemoveSTableMeta(pCtg, "1.db1", ctgTestSTablename, ctgTestSuid);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1);
|
||||
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_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_STB_RENT_NUM), 0);
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
TEST(tableMeta, updateStbMeta) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
void *mockPointer = (void *)0x1;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
ctgTestSetPrepareDbVgroupsAndSuperMeta();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
int32_t code = catalogInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
// sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||
strcpy(n.dbname, "db1");
|
||||
strcpy(n.tname, ctgTestSTablename);
|
||||
|
||||
STableMeta *tableMeta = NULL;
|
||||
code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(tableMeta->vgId, 0);
|
||||
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
||||
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||
ASSERT_EQ(tableMeta->uid, ctgTestSuid);
|
||||
ASSERT_EQ(tableMeta->suid, ctgTestSuid);
|
||||
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||
|
||||
tfree(tableMeta);
|
||||
|
||||
STableMetaRsp rsp = {0};
|
||||
ctgTestBuildSTableMetaRsp(&rsp);
|
||||
|
||||
code = catalogUpdateSTableMeta(pCtg, &rsp);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1);
|
||||
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 1);
|
||||
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 1);
|
||||
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1);
|
||||
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 1);
|
||||
|
||||
code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(tableMeta->vgId, 0);
|
||||
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
||||
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion + 1);
|
||||
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion + 1);
|
||||
ASSERT_EQ(tableMeta->uid, ctgTestSuid + 1);
|
||||
ASSERT_EQ(tableMeta->suid, ctgTestSuid + 1);
|
||||
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||
ASSERT_EQ(tableMeta->tableInfo.precision, 1 + 1);
|
||||
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||
|
||||
tfree(tableMeta);
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST(tableDistVgroup, normalTable) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
void *mockPointer = (void *)0x1;
|
||||
|
@ -1109,7 +1297,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
|
|||
taosArrayDestroy(vgList);
|
||||
|
||||
ctgTestBuildDBVgroup(&dbVgroup);
|
||||
code = catalogUpdateDBVgroup(pCtg, ctgTestDbname, dbVgroup);
|
||||
code = catalogUpdateDBVgroup(pCtg, ctgTestDbname, ctgTestDbId, dbVgroup);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
|
||||
|
@ -1128,7 +1316,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
|
|||
catalogDestroy();
|
||||
}
|
||||
|
||||
TEST(multiThread, getSetDbVgroupCase) {
|
||||
TEST(multiThread, getSetRmSameDbVgroup) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
void *mockPointer = (void *)0x1;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
|
@ -1159,10 +1347,10 @@ TEST(multiThread, getSetDbVgroupCase) {
|
|||
pthread_attr_init(&thattr);
|
||||
|
||||
pthread_t thread1, thread2;
|
||||
pthread_create(&(thread1), &thattr, ctgTestSetDbVgroupThread, pCtg);
|
||||
pthread_create(&(thread1), &thattr, ctgTestSetSameDbVgroupThread, pCtg);
|
||||
|
||||
sleep(1);
|
||||
pthread_create(&(thread1), &thattr, ctgTestGetDbVgroupThread, pCtg);
|
||||
pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
|
||||
|
||||
while (true) {
|
||||
if (ctgTestDeadLoop) {
|
||||
|
@ -1179,6 +1367,58 @@ TEST(multiThread, getSetDbVgroupCase) {
|
|||
catalogDestroy();
|
||||
}
|
||||
|
||||
TEST(multiThread, getSetRmDiffDbVgroup) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
void *mockPointer = (void *)0x1;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SVgroupInfo *pvgInfo = NULL;
|
||||
SDBVgroupInfo dbVgroup = {0};
|
||||
SArray *vgList = NULL;
|
||||
ctgTestStop = false;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
ctgTestSetPrepareDbVgroups();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
// sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||
|
||||
int32_t code = catalogInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||
strcpy(n.dbname, "db1");
|
||||
strcpy(n.tname, ctgTestTablename);
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
|
||||
pthread_t thread1, thread2;
|
||||
pthread_create(&(thread1), &thattr, ctgTestSetDiffDbVgroupThread, pCtg);
|
||||
|
||||
sleep(1);
|
||||
pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
|
||||
|
||||
while (true) {
|
||||
if (ctgTestDeadLoop) {
|
||||
sleep(1);
|
||||
} else {
|
||||
sleep(ctgTestMTRunSec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ctgTestStop = true;
|
||||
sleep(1);
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST(multiThread, ctableMeta) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
|
|
|
@ -119,9 +119,9 @@ int32_t queryProcessUseDBRsp(void* output, char *msg, int32_t msgSize) {
|
|||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pOut->dbId = pRsp->uid;
|
||||
pOut->dbVgroup->vgVersion = pRsp->vgVersion;
|
||||
pOut->dbVgroup->hashMethod = pRsp->hashMethod;
|
||||
pOut->dbVgroup->dbId = pRsp->uid;
|
||||
pOut->dbVgroup->vgHash = taosHashInit(pRsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
if (NULL == pOut->dbVgroup->vgHash) {
|
||||
qError("taosHashInit %d failed", pRsp->vgNum);
|
||||
|
@ -159,6 +159,7 @@ _return:
|
|||
}
|
||||
|
||||
static int32_t queryConvertTableMetaMsg(STableMetaRsp* pMetaMsg) {
|
||||
pMetaMsg->dbId = be64toh(pMetaMsg->dbId);
|
||||
pMetaMsg->numOfTags = ntohl(pMetaMsg->numOfTags);
|
||||
pMetaMsg->numOfColumns = ntohl(pMetaMsg->numOfColumns);
|
||||
pMetaMsg->sversion = ntohl(pMetaMsg->sversion);
|
||||
|
@ -258,6 +259,8 @@ int32_t queryProcessTableMetaRsp(void* output, char *msg, int32_t msgSize) {
|
|||
}
|
||||
|
||||
strcpy(pOut->dbFName, pMetaMsg->dbFName);
|
||||
|
||||
pOut->dbId = pMetaMsg->dbId;
|
||||
|
||||
if (pMetaMsg->tableType == TSDB_CHILD_TABLE) {
|
||||
SET_META_TYPE_BOTH_TABLE(pOut->metaType);
|
||||
|
|
|
@ -418,6 +418,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_CTG_INVALID_INPUT, "invalid catalog input
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_NOT_READY, "catalog is not ready")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_MEM_ERROR, "catalog memory error")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_SYS_ERROR, "catalog system error")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_DB_DROPPED, "Database is dropped")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_OUT_OF_SERVICE, "catalog is out of service")
|
||||
|
||||
//scheduler
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SCH_STATUS_ERROR, "scheduler status error")
|
||||
|
|
Loading…
Reference in New Issue