From 26c291aba4f916d10c743f637d48abe98b351b17 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 3 Jun 2020 08:30:06 +0000 Subject: [PATCH] TD-90 --- src/tsdb/inc/tsdbMain.h | 4 ++++ src/tsdb/src/tsdbMain.c | 11 ++++++++++- src/tsdb/src/tsdbMeta.c | 7 ++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/tsdb/inc/tsdbMain.h b/src/tsdb/inc/tsdbMain.h index db1dcbd35d..3d7a672ee6 100644 --- a/src/tsdb/inc/tsdbMain.h +++ b/src/tsdb/inc/tsdbMain.h @@ -509,6 +509,10 @@ void tsdbAdjustCacheBlocks(STsdbCache *pCache); int32_t tsdbGetMetaFileName(char *rootDir, char *fname); int tsdbUpdateFileHeader(SFile *pFile, uint32_t version); int tsdbUpdateTable(STsdbMeta *pMeta, STable *pTable, STableCfg *pCfg); +int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable); +int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable); + +#define DEFAULT_TAG_INDEX_COLUMN 0 // skip list built based on the first column of tags #ifdef __cplusplus } diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 8f58e5fe06..5c420d6f56 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -445,14 +445,23 @@ int tsdbUpdateTagValue(TsdbRepoT *repo, SUpdateTableTagValMsg *pMsg) { rpcFreeCont(msg); } - if (schemaVersion(tsdbGetTableTagSchema(pMeta, pTable)) > tversion) { + STSchema *pTagSchema = tsdbGetTableTagSchema(pMeta, pTable); + + if (schemaVersion(pTagSchema) > tversion) { tsdbError( "vgId:%d failed to update tag value of table %s since version out of date, client tag version:%d server tag " "version:%d", pRepo->config.tsdbId, varDataVal(pTable->name), tversion, schemaVersion(pTable->tagSchema)); return TSDB_CODE_TAG_VER_OUT_OF_DATE; } + if (schemaColAt(pTagSchema, DEFAULT_TAG_INDEX_COLUMN)->colId == htons(pMsg->colId)) { + tsdbRemoveTableFromIndex(pMeta, pTable); + } + // TODO: remove table from index if it is the first column of tag tdSetKVRowDataOfCol(&pTable->tagVal, htons(pMsg->colId), htons(pMsg->type), pMsg->data); + if (schemaColAt(pTagSchema, DEFAULT_TAG_INDEX_COLUMN)->colId == htons(pMsg->colId)) { + tsdbAddTableIntoIndex(pMeta, pTable); + } return TSDB_CODE_SUCCESS; } diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 6aaece59eb..5e8412a1ec 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -8,13 +8,10 @@ #define TSDB_SUPER_TABLE_SL_LEVEL 5 // TODO: may change here // #define TSDB_META_FILE_NAME "META" -const int32_t DEFAULT_TAG_INDEX_COLUMN = 0; // skip list built based on the first column of tags static int tsdbFreeTable(STable *pTable); static int32_t tsdbCheckTableCfg(STableCfg *pCfg); static int tsdbAddTableToMeta(STsdbMeta *pMeta, STable *pTable, bool addIdx); -static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable); -static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable); static int tsdbRemoveTableFromMeta(STsdbMeta *pMeta, STable *pTable, bool rmFromIdx); /** @@ -719,7 +716,7 @@ static int tsdbRemoveTableFromMeta(STsdbMeta *pMeta, STable *pTable, bool rmFrom return 0; } -static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable) { +int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable) { assert(pTable->type == TSDB_CHILD_TABLE && pTable != NULL); STable* pSTable = tsdbGetTableByUid(pMeta, pTable->superUid); assert(pSTable != NULL); @@ -744,7 +741,7 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable) { return 0; } -static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) { +int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) { assert(pTable->type == TSDB_CHILD_TABLE && pTable != NULL); STable* pSTable = tsdbGetTableByUid(pMeta, pTable->superUid); -- GitLab