Skip to content

Commit

Permalink
[opt](catalog) cache the converted properties (#30668)
Browse files Browse the repository at this point in the history
convert properties may be a heavy operation, so we cache the result.
  • Loading branch information
morningman authored and Doris-Extras committed Feb 6, 2024
1 parent cde74cb commit 06ed578
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit 06ed578

Please sign in to comment.