feat: drop stable
This commit is contained in:
parent
b6738d6d01
commit
d1a4e2d232
|
@ -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) {
|
||||||
|
|
||||||
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:
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData);
|
||||||
tdbTbcOpen(pMeta->pNameIdx, &pNameIdxc, &pMeta->txn);
|
if (rc < 0) {
|
||||||
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;
|
terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = tdbTbcGet(pNameIdxc, NULL, NULL, &pData, &nData);
|
|
||||||
if (ret < 0) {
|
|
||||||
ASSERT(0);
|
|
||||||
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
|
if (type == TSDB_CHILD_TABLE && tbUids) {
|
||||||
tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn);
|
taosArrayPush(tbUids, &uid);
|
||||||
ret = tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
|
|
||||||
if (ret < 0 || c != 0) {
|
|
||||||
ASSERT(0);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
tdbFree(pData);
|
||||||
if (ret < 0) {
|
return 0;
|
||||||
ASSERT(0);
|
}
|
||||||
return -1;
|
|
||||||
|
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
||||||
|
void *pData = NULL;
|
||||||
|
int nData = 0;
|
||||||
|
int rc = 0;
|
||||||
|
int64_t version;
|
||||||
|
SMetaEntry e = {0};
|
||||||
|
SDecoder dc = {0};
|
||||||
|
|
||||||
|
rc = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData);
|
||||||
|
version = *(int64_t *)pData;
|
||||||
|
|
||||||
|
tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData);
|
||||||
|
|
||||||
|
tDecoderInit(&dc, pData, nData);
|
||||||
|
metaDecodeEntry(&dc, &e);
|
||||||
|
|
||||||
|
if (type) *type = e.type;
|
||||||
|
|
||||||
|
tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pMeta->txn);
|
||||||
|
tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn);
|
||||||
|
tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn);
|
||||||
|
if (e.type == TSDB_CHILD_TABLE) {
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
tver = *(int64_t *)pData;
|
tDecoderClear(&dc);
|
||||||
tdbTbcDelete(pUidIdxc);
|
tdbFree(pData);
|
||||||
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 (ret < 0) {
|
|
||||||
ASSERT(0);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// decode entry
|
|
||||||
void *pDataCopy = taosMemoryMalloc(nData); // remove the copy (todo)
|
|
||||||
memcpy(pDataCopy, pData, nData);
|
|
||||||
tDecoderInit(&coder, pDataCopy, nData);
|
|
||||||
ret = metaDecodeEntry(&coder, &me);
|
|
||||||
if (ret < 0) {
|
|
||||||
ASSERT(0);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
type = me.type;
|
|
||||||
if (type == TSDB_CHILD_TABLE) {
|
|
||||||
ctime = me.ctbEntry.ctime;
|
|
||||||
suid = me.ctbEntry.suid;
|
|
||||||
taosArrayPush(tbUids, &me.uid);
|
|
||||||
} else if (type == TSDB_NORMAL_TABLE) {
|
|
||||||
ctime = me.ntbEntry.ctime;
|
|
||||||
suid = 0;
|
|
||||||
} else {
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
taosMemoryFree(pDataCopy);
|
|
||||||
tDecoderClear(&coder);
|
|
||||||
tdbTbcClose(pTbDbc);
|
|
||||||
|
|
||||||
if (type == TSDB_CHILD_TABLE) {
|
|
||||||
// remove the pCtbIdx
|
|
||||||
TBC *pCtbIdxc = NULL;
|
|
||||||
tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, &pMeta->txn);
|
|
||||||
|
|
||||||
ret = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = uid}, sizeof(SCtbIdxKey), &c);
|
|
||||||
if (ret < 0 || c != 0) {
|
|
||||||
ASSERT(0);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
tdbTbcDelete(pCtbIdxc);
|
|
||||||
tdbTbcClose(pCtbIdxc);
|
|
||||||
|
|
||||||
// remove tags from pTagIdx (todo)
|
|
||||||
} else if (type == TSDB_NORMAL_TABLE) {
|
|
||||||
// remove from pSkmDb
|
|
||||||
} else {
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove from ttl (todo)
|
|
||||||
if (ctime > 0) {
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue