-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Add session property for jdbc metadata, pool size, caching enabled #23844
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ public class JdbcMetadataConfig | |
private Duration metadataCacheTtl = new Duration(0, TimeUnit.SECONDS); | ||
private Duration metadataCacheRefreshInterval = new Duration(0, TimeUnit.SECONDS); | ||
private long metadataCacheMaximumSize = 10000; | ||
private int metadataCacheThreadPoolSize = 10; | ||
private boolean jdbcMetadataCacheEnabled; | ||
|
||
public boolean isAllowDropTable() | ||
{ | ||
|
@@ -83,4 +85,29 @@ public JdbcMetadataConfig setMetadataCacheMaximumSize(long metadataCacheMaximumS | |
this.metadataCacheMaximumSize = metadataCacheMaximumSize; | ||
return this; | ||
} | ||
|
||
public int getMetadataCacheThreadPoolSize() | ||
{ | ||
return metadataCacheThreadPoolSize; | ||
} | ||
|
||
@Min(1) | ||
@Config("metadata-cache-thread-pool-size") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The value represents the max background fetch threads for refreshing metadata, which IMO we should document. @steveburnett I don't think we document these JdbcMetadataConfig properties at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aaneja thanks for the suggestion! Maybe a good place for documenting these features would be a new section in Presto Session Properties, titled JDBC Properties? Let me know what you think, especially if you have a better idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with you. A dedicated section for common JDBC properties that we link to from other JDBC connectors would be ideal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @aaneja! Normally I would recommend that documentation for new configuration or session properties should be part of the PR. In this specific case that there is nowhere good to put them at this time, I've opened a new issue #23918 (doc PR to follow from that) to add a JDBC Properties topic to Presto Session Properties and populate it with these JdbcMetadataConfig properties to begin with. Other JDBC properties can be added to the new doc section in later PRs, and this code PR can move forward. Sound reasonable? |
||
public JdbcMetadataConfig setMetadataCacheThreadPoolSize(int threadPoolSize) | ||
{ | ||
this.metadataCacheThreadPoolSize = threadPoolSize; | ||
return this; | ||
} | ||
|
||
public boolean isJdbcMetadataCacheEnabled() | ||
{ | ||
return jdbcMetadataCacheEnabled; | ||
} | ||
|
||
@Config("metadata-jdbc-cache-enabled") | ||
public JdbcMetadataConfig setJdbcMetadataCacheEnabled(boolean jdbcMetadataCacheEnabled) | ||
{ | ||
this.jdbcMetadataCacheEnabled = jdbcMetadataCacheEnabled; | ||
return this; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.plugin.jdbc; | ||
|
||
import com.facebook.presto.spi.ConnectorSession; | ||
import com.facebook.presto.spi.session.PropertyMetadata; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import javax.inject.Inject; | ||
|
||
import java.util.List; | ||
|
||
import static com.facebook.presto.spi.session.PropertyMetadata.booleanProperty; | ||
|
||
public class JdbcMetadataSessionPropertiesProvider | ||
implements JdbcSessionPropertiesProvider | ||
{ | ||
private final List<PropertyMetadata<?>> sessionProperties; | ||
private static final String USE_JDBC_METADATA_CACHE = "use_jdbc_metadata_cache"; | ||
|
||
@Inject | ||
public JdbcMetadataSessionPropertiesProvider(JdbcMetadataConfig jdbcMetadataConfig) | ||
{ | ||
this.sessionProperties = ImmutableList.of( | ||
booleanProperty( | ||
USE_JDBC_METADATA_CACHE, | ||
"Whether Jdbc Metadata In Memory Cache is Enabled", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets make this more descriptive - |
||
jdbcMetadataConfig.isJdbcMetadataCacheEnabled(), | ||
false)); | ||
} | ||
|
||
@Override | ||
public List<PropertyMetadata<?>> getSessionProperties() | ||
{ | ||
return sessionProperties; | ||
} | ||
|
||
public static boolean isJdbcMetadataCacheEnabled(ConnectorSession session) | ||
{ | ||
try { | ||
return session.getProperty(USE_JDBC_METADATA_CACHE, Boolean.class); | ||
} | ||
catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,9 @@ public void testDefaults() | |
.setAllowDropTable(false) | ||
.setMetadataCacheTtl(new Duration(0, SECONDS)) | ||
.setMetadataCacheRefreshInterval(new Duration(0, SECONDS)) | ||
.setMetadataCacheMaximumSize(10000)); | ||
.setMetadataCacheMaximumSize(10000) | ||
.setMetadataCacheThreadPoolSize(10) | ||
.setJdbcMetadataCacheEnabled(false)); | ||
} | ||
|
||
@Test | ||
|
@@ -45,13 +47,17 @@ public void testExplicitPropertyMappings() | |
.put("metadata-cache-ttl", "1h") | ||
.put("metadata-cache-refresh-interval", "10s") | ||
.put("metadata-cache-maximum-size", "100") | ||
.put("metadata-cache-thread-pool-size", "50") | ||
.put("metadata-jdbc-cache-enabled", "true") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to test another case where this config is not in the property and False should be expected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is done in "testDefaults" test above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we also need to test the branch where "session.getProperty(JDBC_METADATA_CACHE_ENABLED, Boolean.class)" throws an exception? Is there a way to generate the coverage report like JaCoCo? |
||
.build(); | ||
|
||
JdbcMetadataConfig expected = new JdbcMetadataConfig() | ||
.setAllowDropTable(true) | ||
.setMetadataCacheTtl(new Duration(1, HOURS)) | ||
.setMetadataCacheRefreshInterval(new Duration(10, SECONDS)) | ||
.setMetadataCacheMaximumSize(100); | ||
.setMetadataCacheMaximumSize(100) | ||
.setMetadataCacheThreadPoolSize(50) | ||
.setJdbcMetadataCacheEnabled(true); | ||
|
||
assertFullMapping(properties, expected); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also change the underlying feature flag methods and this to use names similar to
useJdbcMetadataCache
?