[Fix](multi-catalog) Invalidate cache when enable auto refresh catalog. (#21070)
The default value of RefreshCatalogStmt.invalidCache is false now, but the RefreshManager.RefreshTask does not invoke RefreshCatalogStmt.analyze() so it will not invalidate the cache. This pr mainly fix this problem
This commit is contained in:
@ -38,7 +38,12 @@ public class RefreshCatalogStmt extends DdlStmt {
|
||||
|
||||
private final String catalogName;
|
||||
private Map<String, String> properties;
|
||||
private boolean invalidCache = false;
|
||||
|
||||
/**
|
||||
* Set default value to true, otherwise
|
||||
* {@link org.apache.doris.catalog.RefreshManager.RefreshTask} will lost the default value
|
||||
*/
|
||||
private boolean invalidCache = true;
|
||||
|
||||
public RefreshCatalogStmt(String catalogName, Map<String, String> properties) {
|
||||
this.catalogName = catalogName;
|
||||
@ -66,9 +71,9 @@ public class RefreshCatalogStmt extends DdlStmt {
|
||||
ErrorReport.reportAnalysisException(ErrorCode.ERR_CATALOG_ACCESS_DENIED,
|
||||
analyzer.getQualifiedUser(), catalogName);
|
||||
}
|
||||
String invalidConfig = properties == null ? null : properties.get(INVALID_CACHE);
|
||||
// Default is to invalid cache.
|
||||
invalidCache = invalidConfig == null ? true : invalidConfig.equalsIgnoreCase("true");
|
||||
|
||||
// Set to false only if user set the property "invalid_cache"="false"
|
||||
invalidCache = !(properties != null && properties.get(INVALID_CACHE).equalsIgnoreCase("false"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -77,4 +82,5 @@ public class RefreshCatalogStmt extends DdlStmt {
|
||||
stringBuilder.append("REFRESH CATALOG ").append("`").append(catalogName).append("`");
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -189,6 +189,11 @@ public class RefreshManager {
|
||||
CatalogIf catalog = Env.getCurrentEnv().getCatalogMgr().getCatalog(catalogId);
|
||||
if (catalog != null) {
|
||||
String catalogName = catalog.getName();
|
||||
/**
|
||||
* Now do not invoke
|
||||
* {@link org.apache.doris.analysis.RefreshCatalogStmt#analyze(Analyzer)} is ok,
|
||||
* because the default value of invalidCache is true.
|
||||
* */
|
||||
RefreshCatalogStmt refreshCatalogStmt = new RefreshCatalogStmt(catalogName, null);
|
||||
try {
|
||||
DdlExecutor.execute(Env.getCurrentEnv(), refreshCatalogStmt);
|
||||
|
||||
@ -76,6 +76,7 @@ public class RefreshTableTest extends TestWithFeService {
|
||||
table.makeSureInitialized();
|
||||
Assertions.assertTrue(table.isObjectCreated());
|
||||
RefreshCatalogStmt refreshCatalogStmt = new RefreshCatalogStmt("test1", null);
|
||||
Assertions.assertTrue(refreshCatalogStmt.isInvalidCache());
|
||||
try {
|
||||
DdlExecutor.execute(Env.getCurrentEnv(), refreshCatalogStmt);
|
||||
} catch (Exception e) {
|
||||
@ -97,6 +98,7 @@ public class RefreshTableTest extends TestWithFeService {
|
||||
} catch (Exception e) {
|
||||
// Do nothing
|
||||
}
|
||||
Assertions.assertFalse(((ExternalCatalog) test1).isInitialized());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user