提交 0bea3475 编写于 作者: dengyihao's avatar dengyihao

add/drop dynamic idx

上级 c2a6988d
...@@ -1191,7 +1191,7 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb ...@@ -1191,7 +1191,7 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb
int nVal = 0; int nVal = 0;
int ret; int ret;
int c; int c;
tb_uid_t uid; tb_uid_t uid, suid;
int64_t oversion; int64_t oversion;
const void *pData = NULL; const void *pData = NULL;
int nData = 0; int nData = 0;
...@@ -1216,12 +1216,12 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb ...@@ -1216,12 +1216,12 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb
ret = -1; ret = -1;
goto _err; goto _err;
} }
suid = ((SUidIdxVal *)pVal)[0].suid;
STbDbKey tbDbKey = {0}; STbDbKey tbDbKey = {0};
tbDbKey.uid = uid; tbDbKey.uid = suid;
tbDbKey.version = ((SUidIdxVal *)pVal)[0].version; tbDbKey.version = ((SUidIdxVal *)pVal)[0].version;
tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pVal, &nVal); tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pVal, &nVal);
tDecoderInit(&dc, pVal, nVal); tDecoderInit(&dc, pVal, nVal);
ret = metaDecodeEntry(&dc, &stbEntry); ret = metaDecodeEntry(&dc, &stbEntry);
if (ret < 0) { if (ret < 0) {
...@@ -1252,13 +1252,13 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb ...@@ -1252,13 +1252,13 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb
terrno = TSDB_CODE_VND_COL_NOT_EXISTS; terrno = TSDB_CODE_VND_COL_NOT_EXISTS;
goto _err; goto _err;
} }
/* /*
* iterator all pTdDbc by uid and version * iterator all pTdDbc by uid and version
*/ */
// drop all child tables
TBC *pCtbIdxc = NULL; TBC *pCtbIdxc = NULL;
tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL);
int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = uid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c); int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c);
if (rc < 0) { if (rc < 0) {
tdbTbcClose(pCtbIdxc); tdbTbcClose(pCtbIdxc);
goto _err; goto _err;
...@@ -1307,6 +1307,11 @@ _err: ...@@ -1307,6 +1307,11 @@ _err:
return -1; return -1;
} }
typedef struct SMetaPair {
void *key;
int nkey;
} SMetaPair;
static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) {
SMetaEntry stbEntry = {0}; SMetaEntry stbEntry = {0};
void *pVal = NULL; void *pVal = NULL;
...@@ -1374,7 +1379,7 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT ...@@ -1374,7 +1379,7 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT
terrno = TSDB_CODE_VND_COL_NOT_EXISTS; terrno = TSDB_CODE_VND_COL_NOT_EXISTS;
goto _err; goto _err;
} }
SArray *tagIdxList = taosArrayInit(512, sizeof(STagIdxKey *)); SArray *tagIdxList = taosArrayInit(512, sizeof(SMetaPair));
TBC *pTagIdxc = NULL; TBC *pTagIdxc = NULL;
tdbTbcOpen(pMeta->pTagIdx, &pTagIdxc, NULL); tdbTbcOpen(pMeta->pTagIdx, &pTagIdxc, NULL);
...@@ -1385,15 +1390,24 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT ...@@ -1385,15 +1390,24 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT
int nKey, nVal; int nKey, nVal;
rc = tdbTbcNext(pTagIdxc, &pKey, &nKey, &pVal, &nVal); rc = tdbTbcNext(pTagIdxc, &pKey, &nKey, &pVal, &nVal);
STagIdxKey *pIdxKey = (STagIdxKey *)pKey; STagIdxKey *pIdxKey = (STagIdxKey *)pKey;
if (pIdxKey->suid != suid) { if (pIdxKey->suid != suid || pIdxKey->cid != pCol->colId) {
tdbFree(pKey); tdbFree(pKey);
tdbFree(pVal); tdbFree(pVal);
continue; continue;
} }
taosArrayPush(tagIdxList, &pIdxKey);
SMetaPair pair = {.key = pKey, nKey = nKey};
taosArrayPush(tagIdxList, &pair);
} }
tdbTbcClose(pTagIdxc); tdbTbcClose(pTagIdxc);
for (int i = 0; i < taosArrayGetSize(tagIdxList); i++) {
SMetaPair *pair = taosArrayGet(tagIdxList, i);
tdbTbDelete(pMeta->pTagIdx, pair->key, pair->nkey, pMeta->txn);
}
taosArrayDestroy(tagIdxList);
// drop index // drop index
return 0; return 0;
_err: _err:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册