From dc8e7ebc8257755ff7149bcff2be3098e93295c2 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 23 Jul 2020 17:56:35 +0800 Subject: [PATCH] fix invalid write --- src/tsdb/src/tsdbMain.c | 2 +- src/tsdb/src/tsdbMeta.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 11a84cd552..89a19c15af 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -382,7 +382,7 @@ int tsdbGetNextMaxTables(int tid) { int maxTables = TSDB_INIT_NTABLES; while (true) { maxTables = MIN(maxTables, TSDB_MAX_TABLES); - if (tid <= maxTables + 1) break; + if (tid <= maxTables) break; maxTables *= 2; } diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 8d237ab673..684c87462c 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -781,7 +781,9 @@ static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx, boo goto _err; } } else { - if (tsdbAdjustMetaTables(pRepo, TABLE_TID(pTable)) < 0) goto _err; + if (TABLE_TID(pTable) >= pMeta->maxTables) { + if (tsdbAdjustMetaTables(pRepo, TABLE_TID(pTable)) < 0) goto _err; + } if (TABLE_TYPE(pTable) == TSDB_CHILD_TABLE && addIdx) { // add STABLE to the index if (tsdbAddTableIntoIndex(pMeta, pTable, true) < 0) { tsdbDebug("vgId:%d failed to add table %s to meta while add table to index since %s", REPO_ID(pRepo), @@ -789,6 +791,7 @@ static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx, boo goto _err; } } + ASSERT(TABLE_TID(pTable) < pMeta->maxTables); pMeta->tables[TABLE_TID(pTable)] = pTable; pMeta->nTables++; } @@ -1271,7 +1274,7 @@ static int tsdbRmTableFromMeta(STsdbRepo *pRepo, STable *pTable) { static int tsdbAdjustMetaTables(STsdbRepo *pRepo, int tid) { STsdbMeta *pMeta = pRepo->tsdbMeta; - if (pMeta->maxTables >= tid) return 0; + ASSERT(tid >= pMeta->maxTables); int maxTables = tsdbGetNextMaxTables(tid);