提交 d1a4e2d2 编写于 作者: H Hongze Cheng

feat: drop stable

上级 b6738d6d
...@@ -23,6 +23,7 @@ static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME); ...@@ -23,6 +23,7 @@ static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME);
static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME); static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME);
static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME); static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME);
static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry); static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry);
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type);
int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
SMetaEntry me = {0}; SMetaEntry me = {0};
...@@ -116,7 +117,7 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) { ...@@ -116,7 +117,7 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) {
for (int32_t iChild = 0; iChild < taosArrayGetSize(pArray); iChild++) { for (int32_t iChild = 0; iChild < taosArrayGetSize(pArray); iChild++) {
tb_uid_t uid = *(tb_uid_t *)taosArrayGet(pArray, iChild); tb_uid_t uid = *(tb_uid_t *)taosArrayGet(pArray, iChild);
metaDropTableByUid(pMeta, uid); metaDropTableByUid(pMeta, uid, NULL);
} }
taosArrayDestroy(pArray); taosArrayDestroy(pArray);
...@@ -263,122 +264,63 @@ _err: ...@@ -263,122 +264,63 @@ _err:
} }
int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUids) { int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUids) {
TBC *pTbDbc = NULL; void *pData = NULL;
TBC *pUidIdxc = NULL; int nData = 0;
TBC *pNameIdxc = NULL; int rc = 0;
const void *pData; tb_uid_t uid;
int nData; int type;
tb_uid_t uid;
int64_t tver;
SMetaEntry me = {0};
SDecoder coder = {0};
int8_t type;
int64_t ctime;
tb_uid_t suid;
int c = 0, ret;
// search & delete the name idx
tdbTbcOpen(pMeta->pNameIdx, &pNameIdxc, &pMeta->txn);
ret = tdbTbcMoveTo(pNameIdxc, pReq->name, strlen(pReq->name) + 1, &c);
if (ret < 0 || !tdbTbcIsValid(pNameIdxc) || c) {
tdbTbcClose(pNameIdxc);
terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
return -1;
}
ret = tdbTbcGet(pNameIdxc, NULL, NULL, &pData, &nData); rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData);
if (ret < 0) { if (rc < 0) {
ASSERT(0); terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
return -1; return -1;
} }
uid = *(tb_uid_t *)pData; uid = *(tb_uid_t *)pData;
tdbTbcDelete(pNameIdxc); metaWLock(pMeta);
tdbTbcClose(pNameIdxc); metaDropTableByUid(pMeta, uid, &type);
metaULock(pMeta);
// search & delete uid idx
tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn);
ret = tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
if (ret < 0 || c != 0) {
ASSERT(0);
return -1;
}
ret = tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
if (ret < 0) {
ASSERT(0);
return -1;
}
tver = *(int64_t *)pData;
tdbTbcDelete(pUidIdxc);
tdbTbcClose(pUidIdxc);
// search and get meta entry
tdbTbcOpen(pMeta->pTbDb, &pTbDbc, &pMeta->txn);
ret = tdbTbcMoveTo(pTbDbc, &(STbDbKey){.uid = uid, .version = tver}, sizeof(STbDbKey), &c);
if (ret < 0 || c != 0) {
ASSERT(0);
return -1;
}
ret = tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); if (type == TSDB_CHILD_TABLE && tbUids) {
if (ret < 0) { taosArrayPush(tbUids, &uid);
ASSERT(0);
return -1;
} }
// decode entry tdbFree(pData);
void *pDataCopy = taosMemoryMalloc(nData); // remove the copy (todo) return 0;
memcpy(pDataCopy, pData, nData); }
tDecoderInit(&coder, pDataCopy, nData);
ret = metaDecodeEntry(&coder, &me);
if (ret < 0) {
ASSERT(0);
return -1;
}
type = me.type; static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
if (type == TSDB_CHILD_TABLE) { void *pData = NULL;
ctime = me.ctbEntry.ctime; int nData = 0;
suid = me.ctbEntry.suid; int rc = 0;
taosArrayPush(tbUids, &me.uid); int64_t version;
} else if (type == TSDB_NORMAL_TABLE) { SMetaEntry e = {0};
ctime = me.ntbEntry.ctime; SDecoder dc = {0};
suid = 0;
} else {
ASSERT(0);
}
taosMemoryFree(pDataCopy); rc = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData);
tDecoderClear(&coder); version = *(int64_t *)pData;
tdbTbcClose(pTbDbc);
if (type == TSDB_CHILD_TABLE) { tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData);
// remove the pCtbIdx
TBC *pCtbIdxc = NULL;
tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, &pMeta->txn);
ret = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = uid}, sizeof(SCtbIdxKey), &c); tDecoderInit(&dc, pData, nData);
if (ret < 0 || c != 0) { metaDecodeEntry(&dc, &e);
ASSERT(0);
return -1;
}
tdbTbcDelete(pCtbIdxc); if (type) *type = e.type;
tdbTbcClose(pCtbIdxc);
// remove tags from pTagIdx (todo) tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pMeta->txn);
} else if (type == TSDB_NORMAL_TABLE) { tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn);
// remove from pSkmDb tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn);
} else { if (e.type == TSDB_CHILD_TABLE) {
ASSERT(0); tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), &pMeta->txn);
} else if (e.type == TSDB_NORMAL_TABLE) {
// drop schema.db (todo)
// drop ttl.idx (todo)
} else if (e.type == TSDB_SUPER_TABLE) {
// drop schema.db (todo)
} }
// remove from ttl (todo) tDecoderClear(&dc);
if (ctime > 0) { tdbFree(pData);
}
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册