Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opt](catalog) cache the converted properties #30668

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public abstract class ExternalCatalog

private ExternalSchemaCache schemaCache;
private String comment;
// A cached and being converted properties for external catalog.
// generated from catalog properties.
private byte[] propLock = new byte[0];
private Map<String, String> convertedProperties = null;

public ExternalCatalog() {
}
Expand Down Expand Up @@ -298,6 +302,9 @@ protected void init() {
public void onRefresh(boolean invalidCache) {
this.objectCreated = false;
this.initialized = false;
synchronized (this.propLock) {
this.convertedProperties = null;
}
this.invalidCacheInInit = invalidCache;
if (invalidCache) {
Env.getCurrentEnv().getExtMetaCacheMgr().invalidateCatalogCache(id);
Expand Down Expand Up @@ -421,7 +428,17 @@ public List<Long> getDbIds() {

@Override
public Map<String, String> getProperties() {
return PropertyConverter.convertToMetaProperties(catalogProperty.getProperties());
// convert properties may be a heavy operation, so we cache the result.
if (convertedProperties != null) {
return convertedProperties;
}
synchronized (propLock) {
if (convertedProperties != null) {
return convertedProperties;
}
convertedProperties = PropertyConverter.convertToMetaProperties(catalogProperty.getProperties());
return convertedProperties;
}
}

@Override
Expand Down Expand Up @@ -552,6 +569,7 @@ public void gsonPostProcess() throws IOException {
}
}
}
this.propLock = new byte[0];
}

public void addDatabaseForTest(ExternalDatabase<? extends ExternalTable> db) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void replayJdbcCatalogTest() throws DdlException {
Map<String, String> newProperties = Maps.newHashMap();
newProperties.put(JdbcResource.CONNECTION_POOL_MIN_SIZE, "2");
jdbcExternalCatalog.getCatalogProperty().modifyCatalogProps(newProperties);
jdbcExternalCatalog.notifyPropertiesUpdated(newProperties);
JdbcExternalCatalog replayJdbcCatalog2 = (JdbcExternalCatalog) CatalogFactory.createFromLog(
jdbcExternalCatalog.constructEditLog());
Map<String, String> properties2 = replayJdbcCatalog2.getProperties();
Expand Down
Loading