Skip to content

Commit

Permalink
[core] Remove useless codes in CachingCatalog
Browse files Browse the repository at this point in the history
  • Loading branch information
JingsongLi committed Dec 12, 2024
1 parent f50507d commit 30dcfb5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,9 @@

import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Cache;
import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Caffeine;
import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.RemovalCause;
import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.RemovalListener;
import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Ticker;
import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Weigher;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;

import java.time.Duration;
Expand All @@ -59,8 +53,6 @@
/** A {@link Catalog} to cache databases and tables and manifests. */
public class CachingCatalog extends DelegateCatalog {

private static final Logger LOG = LoggerFactory.getLogger(CachingCatalog.class);

private final Duration expirationInterval;
private final int snapshotMaxNumPerTable;

Expand Down Expand Up @@ -125,7 +117,6 @@ public CachingCatalog(
this.tableCache =
Caffeine.newBuilder()
.softValues()
.removalListener(new TableInvalidatingRemovalListener())
.executor(Runnable::run)
.expireAfterAccess(expirationInterval)
.ticker(ticker)
Expand Down Expand Up @@ -201,8 +192,12 @@ public void dropTable(Identifier identifier, boolean ignoreIfNotExists)
throws TableNotExistException {
super.dropTable(identifier, ignoreIfNotExists);
invalidateTable(identifier);
if (identifier.isMainTable()) {
invalidateAttachedTables(identifier);

// clear all branch tables of this table
for (Identifier i : tableCache.asMap().keySet()) {
if (identifier.getTableName().equals(i.getTableName())) {
tableCache.invalidate(i);
}
}
}

Expand Down Expand Up @@ -302,16 +297,6 @@ public void dropPartition(Identifier identifier, Map<String, String> partitions)
}
}

private class TableInvalidatingRemovalListener implements RemovalListener<Identifier, Table> {
@Override
public void onRemoval(Identifier identifier, Table table, @NonNull RemovalCause cause) {
LOG.debug("Evicted {} from the table cache ({})", identifier, cause);
if (RemovalCause.EXPIRED.equals(cause)) {
// ignore now
}
}
}

@Override
public void invalidateTable(Identifier identifier) {
tableCache.invalidate(identifier);
Expand All @@ -320,15 +305,6 @@ public void invalidateTable(Identifier identifier) {
}
}

/** invalidate attached tables, such as cached branches. */
private void invalidateAttachedTables(Identifier identifier) {
for (@NonNull Identifier i : tableCache.asMap().keySet()) {
if (identifier.getTableName().equals(i.getTableName())) {
tableCache.invalidate(i);
}
}
}

// ================================== refresh ================================================
// following caches will affect the latency of table, so refresh method is provided for engine

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,6 @@ public String getBranchNameOrDefault() {
return systemTable;
}

public boolean isMainTable() {
return getBranchName() == null && getSystemTableName() == null;
}

public boolean isBranch() {
return getBranchName() != null && getSystemTableName() == null;
}

public boolean isSystemTable() {
return getSystemTableName() != null;
}
Expand Down

0 comments on commit 30dcfb5

Please sign in to comment.