-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Allow different jdbc metadata cache ttls for schema and tables lists #16090
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
Changes from all commits
55cd59b
807255d
73015f2
46afd66
215ed86
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 |
|---|---|---|
|
|
@@ -20,27 +20,31 @@ | |
| import io.airlift.units.Duration; | ||
| import io.airlift.units.MinDuration; | ||
|
|
||
| import javax.annotation.PostConstruct; | ||
| import javax.validation.constraints.AssertTrue; | ||
| import javax.validation.constraints.Min; | ||
| import javax.validation.constraints.NotNull; | ||
| import javax.validation.constraints.Pattern; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
| import static com.google.common.base.Strings.nullToEmpty; | ||
| import static java.lang.String.format; | ||
| import static java.util.concurrent.TimeUnit.MILLISECONDS; | ||
| import static javax.validation.constraints.Pattern.Flag.CASE_INSENSITIVE; | ||
|
|
||
| public class BaseJdbcConfig | ||
| { | ||
| public static final String METADATA_CACHE_TTL = "metadata.cache-ttl"; | ||
| public static final String METADATA_SCHEMAS_CACHE_TTL = "metadata.schemas.cache-ttl"; | ||
| public static final String METADATA_TABLES_CACHE_TTL = "metadata.tables.cache-ttl"; | ||
| public static final String METADATA_CACHE_MAXIMUM_SIZE = "metadata.cache-maximum-size"; | ||
|
|
||
| private String connectionUrl; | ||
| private Set<String> jdbcTypesMappedToVarchar = ImmutableSet.of(); | ||
| public static final Duration CACHING_DISABLED = new Duration(0, MILLISECONDS); | ||
| private Duration metadataCacheTtl = CACHING_DISABLED; | ||
| private Optional<Duration> schemaNamesCacheTtl = Optional.empty(); | ||
| private Optional<Duration> tableNamesCacheTtl = Optional.empty(); | ||
| private boolean cacheMissing; | ||
| public static final long DEFAULT_METADATA_CACHE_SIZE = 10000; | ||
| private long cacheMaximumSize = DEFAULT_METADATA_CACHE_SIZE; | ||
|
|
@@ -87,6 +91,34 @@ public BaseJdbcConfig setMetadataCacheTtl(Duration metadataCacheTtl) | |
| return this; | ||
| } | ||
|
|
||
| @NotNull | ||
| public Duration getSchemaNamesCacheTtl() | ||
|
||
| { | ||
| return schemaNamesCacheTtl.orElse(metadataCacheTtl); | ||
| } | ||
|
|
||
| @Config(METADATA_SCHEMAS_CACHE_TTL) | ||
| @ConfigDescription("Determines how long schema names list information will be cached") | ||
| public BaseJdbcConfig setSchemaNamesCacheTtl(Duration schemaNamesCacheTtl) | ||
| { | ||
| this.schemaNamesCacheTtl = Optional.ofNullable(schemaNamesCacheTtl); | ||
| return this; | ||
| } | ||
|
|
||
| @NotNull | ||
| public Duration getTableNamesCacheTtl() | ||
| { | ||
| return tableNamesCacheTtl.orElse(metadataCacheTtl); | ||
| } | ||
|
|
||
| @Config(METADATA_TABLES_CACHE_TTL) | ||
| @ConfigDescription("Determines how long table names list information will be cached") | ||
| public BaseJdbcConfig setTableNamesCacheTtl(Duration tableNamesCacheTtl) | ||
| { | ||
| this.tableNamesCacheTtl = Optional.ofNullable(tableNamesCacheTtl); | ||
| return this; | ||
| } | ||
|
|
||
| public boolean isCacheMissing() | ||
| { | ||
| return cacheMissing; | ||
|
|
@@ -114,12 +146,21 @@ public BaseJdbcConfig setCacheMaximumSize(long cacheMaximumSize) | |
| return this; | ||
| } | ||
|
|
||
| @PostConstruct | ||
| public void validate() | ||
atanasenko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @AssertTrue(message = METADATA_CACHE_TTL + " must be set to a non-zero value when " + METADATA_CACHE_MAXIMUM_SIZE + " is set") | ||
| public boolean isCacheMaximumSizeConsistent() | ||
| { | ||
| return !metadataCacheTtl.equals(CACHING_DISABLED) || cacheMaximumSize == BaseJdbcConfig.DEFAULT_METADATA_CACHE_SIZE; | ||
Praveen2112 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
atanasenko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @AssertTrue(message = METADATA_SCHEMAS_CACHE_TTL + " must not be set when " + METADATA_CACHE_TTL + " is not set") | ||
| public boolean isSchemaNamesCacheTtlConsistent() | ||
Praveen2112 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| return !metadataCacheTtl.equals(CACHING_DISABLED) || schemaNamesCacheTtl.isEmpty(); | ||
| } | ||
|
|
||
| @AssertTrue(message = METADATA_TABLES_CACHE_TTL + " must not be set when " + METADATA_CACHE_TTL + " is not set") | ||
| public boolean isTableNamesCacheTtlConsistent() | ||
| { | ||
| if (metadataCacheTtl.equals(CACHING_DISABLED) && cacheMaximumSize != BaseJdbcConfig.DEFAULT_METADATA_CACHE_SIZE) { | ||
| throw new IllegalArgumentException( | ||
| format("%s must be set to a non-zero value when %s is set", METADATA_CACHE_TTL, METADATA_CACHE_MAXIMUM_SIZE)); | ||
| } | ||
| return !metadataCacheTtl.equals(CACHING_DISABLED) || tableNamesCacheTtl.isEmpty(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.