|
22 | 22 | import org.apache.flink.cdc.connectors.mysql.table.StartupOptions; |
23 | 23 | import org.apache.flink.table.catalog.ObjectPath; |
24 | 24 |
|
| 25 | +import org.apache.flink.shaded.guava31.com.google.common.cache.CacheBuilder; |
| 26 | +import org.apache.flink.shaded.guava31.com.google.common.cache.CacheLoader; |
| 27 | +import org.apache.flink.shaded.guava31.com.google.common.cache.LoadingCache; |
| 28 | + |
25 | 29 | import io.debezium.config.Configuration; |
26 | 30 | import io.debezium.connector.mysql.MySqlConnectorConfig; |
27 | 31 | import io.debezium.relational.RelationalTableFilters; |
|
35 | 39 | import java.util.List; |
36 | 40 | import java.util.Map; |
37 | 41 | import java.util.Properties; |
38 | | -import java.util.concurrent.ConcurrentHashMap; |
39 | 42 | import java.util.function.Predicate; |
40 | 43 |
|
41 | 44 | import static org.apache.flink.util.Preconditions.checkNotNull; |
42 | 45 |
|
43 | 46 | /** A MySql Source configuration which is used by {@link MySqlSource}. */ |
44 | 47 | public class MySqlSourceConfig implements Serializable { |
45 | 48 | private static final long serialVersionUID = 1L; |
| 49 | + private static final Duration TABLE_FILTER_CACHE_EXPIRE_DURATION = Duration.ofHours(1); |
| 50 | + private static final long TABLE_FILTER_CACHE_MAXIMUM_SIZE = 1024; |
46 | 51 |
|
47 | 52 | private final String hostname; |
48 | 53 | private final int port; |
@@ -283,10 +288,19 @@ public Predicate<TableId> getTableFilter() { |
283 | 288 |
|
284 | 289 | static Tables.TableFilter createCachedTableFilter( |
285 | 290 | Tables.TableFilter tableFilter, @Nullable Selectors excludeTableFilter) { |
286 | | - Map<TableId, Boolean> tableFilterCache = new ConcurrentHashMap<>(); |
287 | | - return tableId -> |
288 | | - tableFilterCache.computeIfAbsent( |
289 | | - tableId, id -> isTableIncluded(tableFilter, excludeTableFilter, id)); |
| 291 | + LoadingCache<TableId, Boolean> tableFilterCache = |
| 292 | + CacheBuilder.newBuilder() |
| 293 | + .expireAfterAccess(TABLE_FILTER_CACHE_EXPIRE_DURATION) |
| 294 | + .maximumSize(TABLE_FILTER_CACHE_MAXIMUM_SIZE) |
| 295 | + .build( |
| 296 | + new CacheLoader<TableId, Boolean>() { |
| 297 | + @Override |
| 298 | + public Boolean load(TableId tableId) { |
| 299 | + return isTableIncluded( |
| 300 | + tableFilter, excludeTableFilter, tableId); |
| 301 | + } |
| 302 | + }); |
| 303 | + return tableFilterCache::getUnchecked; |
290 | 304 | } |
291 | 305 |
|
292 | 306 | private static boolean isTableIncluded( |
|
0 commit comments