wuchong commented on code in PR #20196:
URL: https://github.com/apache/flink/pull/20196#discussion_r933207081
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/source/lookup/cache/DefaultLookupCache.java:
##########
@@ -97,30 +97,36 @@ public static DefaultLookupCache fromConfig(ReadableConfig
config) {
@Override
public void open(CacheMetricGroup metricGroup) {
- // Initialize Guava cache
- CacheBuilder<Object, Object> guavaCacheBuilder =
CacheBuilder.newBuilder();
- if (expireAfterAccessDuration != null) {
- guavaCacheBuilder.expireAfterAccess(expireAfterAccessDuration);
- }
- if (expireAfterWriteDuration != null) {
- guavaCacheBuilder.expireAfterWrite(expireAfterWriteDuration);
- }
- if (maximumSize != null) {
- guavaCacheBuilder.maximumSize(maximumSize);
- }
- if (ticker != null) {
- guavaCacheBuilder.ticker(ticker);
+ synchronized (this) {
+ // The cache should already been opened if guava cache is not null
+ if (guavaCache != null) {
+ return;
Review Comment:
We may need to register the metrics to the given `metricGroup` again. Every
subtask will retrieve the shared cache and register cache metrics to the
operator metric group.
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/source/lookup/cache/DefaultLookupCache.java:
##########
@@ -222,11 +248,23 @@ public Builder cacheMissingKey(boolean cacheMissingKey) {
/** Creates the cache. */
public DefaultLookupCache build() {
+ sanityCheck();
return new DefaultLookupCache(
expireAfterAccessDuration,
expireAfterWriteDuration,
maximumSize,
cacheMissingKey);
}
+
+ private void sanityCheck() {
+ if (expireAfterWriteDuration == null
+ && expireAfterAccessDuration == null
+ && maximumSize == null) {
+ throw new IllegalArgumentException(
Review Comment:
Add check for
`org.apache.flink.table.connector.source.lookup.cache.DefaultLookupCache#fromConfig`
as well?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]