提交 de1e0a0a 编写于 作者: K kailixu

chore: more code

上级 30b0af90
......@@ -131,7 +131,7 @@ STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg);
int tsdbCreateTable(STsdbRepo *repo, STableCfg *pCfg);
int tsdbDropTable(STsdbRepo *pRepo, STableId tableId);
int tsdbUpdateTableTagValue(STsdbRepo *repo, SUpdateTableTagValMsg *pMsg);
int tsdbPrintTables(STsdbRepo *repo);
int tsdbPrintTables(STsdbRepo *repo, uint64_t qId);
uint32_t tsdbGetFileInfo(STsdbRepo *repo, char *name, uint32_t *index, uint32_t eindex, int64_t *size);
......
......@@ -52,6 +52,8 @@
// informal
#define META_SYNC_TABLE_NAME "_taos_meta_sync_table_name_taos_"
#define META_SYNC_TABLE_NAME_LEN 32
#define META_SYNC_DROP_TABLE "_taos_meta_sync_drop_table_taos_"
#define META_SYNC_DROP_TABLE_LEN 32
// informal
int64_t tsCTableRid = -1;
......@@ -86,6 +88,7 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg);
static void mnodeProcessDropSuperTableRsp(SRpcMsg *rpcMsg);
static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg);
static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg);
static int32_t mnodeProcessMetaSyncDropTableMsg(SMnodeMsg *pMsg);
static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg);
static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg);
......@@ -1015,6 +1018,10 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) {
}
#endif
if (tsMetaSyncOption && strstr(pDrop->name, META_SYNC_DROP_TABLE)) {
return mnodeProcessMetaSyncDropTableMsg(pMsg);
}
if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pDrop->name);
if (pMsg->pTable == NULL) {
if (pDrop->igNotExists) {
......@@ -2437,6 +2444,92 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) {
return code;
}
static int32_t mnodeProcessMetaSyncDropTableMsg(SMnodeMsg *pMsg) {
int32_t code = 0;
int32_t vgId = -1;
int32_t tid = -1;
uint64_t uid = 0;
int32_t tableType = 0;
char tbName[TSDB_TABLE_FNAME_LEN] = "";
int32_t fnum = 0;
char *fStr = NULL;
char **fnameList = NULL;
SCTableObj ctableObj = {0};
SCMDropTableMsg *pDrop = pMsg->rpcMsg.pCont;
pMsg->pTable = (struct STableObj *)&ctableObj;
SCTableObj *pTable = (SCTableObj *)pMsg->pTable;
// META_SYNC_DROP_TABLE: _taos_meta_sync_drop_table_taos_tableType_vgId_uid_tid_tbName;
fStr = strndup(pDrop->name, strlen(pDrop->name));
if(!fStr) {
code = TSDB_CODE_MND_OUT_OF_MEMORY;
goto _exit;
}
fnameList = strsplit(fStr, ".", &fnum);
if (fnum > 6 && 0 == strncmp(fnameList[2], META_SYNC_DROP_TABLE, META_SYNC_DROP_TABLE_LEN)) {
tableType = atoi(fnameList[3]);
if (errno != 0) {
code = TAOS_SYSTEM_ERROR(errno);
goto _exit;
}
vgId = atoi(fnameList[4]);
if (errno != 0) {
code = TAOS_SYSTEM_ERROR(errno);
goto _exit;
}
uid = strtoull(fnameList[5], NULL, 10);
if (errno != 0) {
code = TAOS_SYSTEM_ERROR(errno);
goto _exit;
}
tid = atoi(fnameList[6]);
if (errno != 0) {
code = TAOS_SYSTEM_ERROR(errno);
goto _exit;
}
strncpy(tbName, fnameList[0], TSDB_TABLE_FNAME_LEN);
tbName[strlen(tbName)] = '.';
strncpy(tbName + strlen(tbName), fnameList[1], TSDB_TABLE_FNAME_LEN - strlen(tbName));
tbName[strlen(tbName)] = '.';
if (strchr(pDrop->name, ' ')) {
strncpy(tbName + strlen(tbName), pDrop->name + 1, TSDB_TABLE_FNAME_LEN - strlen(tbName));
}
} else {
code = TSDB_CODE_TSC_INVALID_TABLE_NAME;
goto _exit;
}
if (tableType != TSDB_CHILD_TABLE && tableType != TSDB_NORMAL_TABLE) {
code = TSDB_CODE_TSC_INVALID_TABLE_NAME;
goto _exit;
}
pTable->info.type = TSDB_CHILD_TABLE;
pTable->info.tableId = tbName;
pTable->uid = uid;
pTable->tid = tid;
pTable->vgId = vgId;
if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(vgId);
if (pMsg->pVgroup == NULL) {
mError("%s:%d, msg:%p, app:%p table:%s, failed to drop table, vgroup not exist", __func__, __LINE__, pMsg,
pMsg->rpcMsg.ahandle, pTable->info.tableId);
code = TSDB_CODE_MND_APP_ERROR;
goto _exit;
}
mnodeSendDropChildTableMsg(pMsg, false);
_exit:
if (code) {
mError("%s:%d, msg:%p, app:%p table:%s, failed to drop table since %s", __func__, __LINE__, pMsg,
pMsg->rpcMsg.ahandle, pDrop->name, tstrerror(code));
}
tfree(fStr);
tfree(fnameList);
return code;
}
static int32_t mnodeFindNormalTableColumnIndex(SCTableObj *pTable, char *colName) {
SSchema *schema = (SSchema *) pTable->schema;
for (int32_t col = 0; col < pTable->numOfColumns; col++) {
......
......@@ -165,34 +165,43 @@ int tsdbDropTable(STsdbRepo *repo, STableId tableId) {
STable *pTable = tsdbGetTableByUid(pMeta, uid);
if (pTable == NULL) {
tsdbError("vgId:%d failed to drop table since table not exists! tid:%d uid %" PRIu64, REPO_ID(pRepo), tableId.tid,
tsdbError("vgId:%d, failed to drop table since table not exists! tid:%d, uid:%" PRIu64, REPO_ID(pRepo), tableId.tid,
uid);
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
return -1;
}
tsdbDebug("vgId:%d try to drop table %s type %d", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TYPE(pTable));
tsdbDebug("vgId:%d, try to drop table %s type %d", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TYPE(pTable));
tid = TABLE_TID(pTable);
tbname = strdup(TABLE_CHAR_NAME(pTable));
if (tbname == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
tsdbError("vgId:%d, failed to drop table %s since %s! tid:%d, uid:%" PRIu64, REPO_ID(pRepo), tbname,
tstrerror(terrno), tableId.tid, uid);
return -1;
}
// Write to KV store first
if (tsdbRemoveTableFromStore(pRepo, pTable) < 0) {
tsdbError("vgId:%d failed to drop table %s since %s", REPO_ID(pRepo), tbname, tstrerror(terrno));
tsdbError("vgId:%d, failed to drop table %s since %s! tid:%d, uid:%" PRIu64, REPO_ID(pRepo), tbname,
tstrerror(terrno), tableId.tid, uid);
goto _err;
}
// Remove table from Meta
if (tsdbRmTableFromMeta(pRepo, pTable) < 0) {
tsdbError("vgId:%d failed to drop table %s since %s", REPO_ID(pRepo), tbname, tstrerror(terrno));
tsdbError("vgId:%d, failed to drop table %s since %s! tid:%d, uid:%" PRIu64, REPO_ID(pRepo), tbname,
tstrerror(terrno), tableId.tid, uid);
goto _err;
}
if (tsMetaSyncOption) {
tsdbInfo("vgId:%d, table %s is dropped! tid:%d, uid:%" PRId64, pRepo->config.tsdbId, tbname, tid, uid);
} else {
tsdbDebug("vgId:%d, table %s is dropped! tid:%d, uid:%" PRId64, pRepo->config.tsdbId, tbname, tid, uid);
}
free(tbname);
if (tsdbCheckCommit(pRepo) < 0) goto _err;
......@@ -204,13 +213,14 @@ _err:
return -1;
}
int tsdbPrintTables(STsdbRepo *pRepo) {
int tsdbPrintTables(STsdbRepo *pRepo, uint64_t qId) {
STsdbMeta *pMeta = pRepo->tsdbMeta;
if (tsdbRLockRepoMeta(pRepo) < 0) return -1;
for (int32_t i = 0; i < pMeta->maxTables; ++i) {
if (pMeta->tables[i] != NULL) {
STable *pTable = pMeta->tables[i];
tsdbDebug("vgId:%d tbname:%s tid:%d uid:%" PRIu64, REPO_ID(pRepo), pTable->name->data, pTable->tableId.tid,
tsdbInfo("vgId:%d QID:%" PRIu64 " stb:%s tbn:%s tid:%d uid:%" PRIu64, REPO_ID(pRepo), qId,
pTable->pSuper ? pTable->pSuper->name->data : "-", pTable->name->data, pTable->tableId.tid,
pTable->tableId.uid);
}
}
......
......@@ -2810,7 +2810,7 @@ int32_t tsdbGetFileBlocksDistInfo(TsdbQueryHandleT* queryHandle, STableBlockDist
tsdbUnLockFS(pFileHandle);
if(tsMetaSyncOption) {
tsdbPrintTables(pQueryHandle->pTsdb);
tsdbPrintTables(pQueryHandle->pTsdb, pQueryHandle->qId);
}
pTableBlockInfo->numOfFiles += 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册