branch-2.1: [fix](statistics)Fix replace table doesn't remove table stat meta memory leak bug. (#49345) (#49367)
Cherry-picked from https://github.com/apache/doris/pull/49345
This commit is contained in:
@ -685,6 +685,7 @@ public class Alter {
|
||||
if (origTable.getType() == TableType.MATERIALIZED_VIEW) {
|
||||
Env.getCurrentEnv().getMtmvService().deregisterMTMV((MTMV) origTable);
|
||||
}
|
||||
Env.getCurrentEnv().getAnalysisManager().removeTableStats(origTable.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -116,19 +116,24 @@ public class StatisticsCleaner extends MasterDaemon {
|
||||
// If ctlName, dbName and tblName exist, it means the table stats is created under new version.
|
||||
// First try to find the table by the given names. If table exists, means the tableMeta is valid,
|
||||
// it should be kept in memory.
|
||||
boolean tableExist = false;
|
||||
try {
|
||||
StatisticsUtil.findTable(stats.ctlName, stats.dbName, stats.tblName);
|
||||
continue;
|
||||
TableIf table = StatisticsUtil.findTable(stats.ctlName, stats.dbName, stats.tblName);
|
||||
// Tables may have identical names but different id, e.g. replace table.
|
||||
tableExist = table.getId() == id;
|
||||
} catch (Exception e) {
|
||||
LOG.debug("Table {}.{}.{} not found.", stats.ctlName, stats.dbName, stats.tblName);
|
||||
}
|
||||
// If we couldn't find table by names, try to find it in internal catalog. This is to support older
|
||||
// version which the tableStats object doesn't store the names but only table id.
|
||||
// If we couldn't find table by names, try to find it in internal catalog by id.
|
||||
// This is to support older version which the tableStats object doesn't store the names
|
||||
// but only table id.
|
||||
// We may remove external table's tableStats here, but it's not a big problem.
|
||||
// Because the stats in column_statistics table is still available,
|
||||
// the only disadvantage is auto analyze may be triggered for this table.
|
||||
// But it only happens once, the new table stats object will have all the catalog, db and table names.
|
||||
if (tableExistInInternalCatalog(internalCatalog, id)) {
|
||||
// the only disadvantage is auto analyze may be triggered for this table again.
|
||||
// But it only happens once, the new table stats object will have all the catalog,
|
||||
// db and table names.
|
||||
// Also support REPLACE TABLE
|
||||
if (tableExist || tableExistInInternalCatalog(internalCatalog, id)) {
|
||||
continue;
|
||||
}
|
||||
LOG.info("Table {}.{}.{} with id {} not exist, remove its table stats record.",
|
||||
|
||||
Reference in New Issue
Block a user