Skip to content

Commit

Permalink
replace cache usage with a map
Browse files Browse the repository at this point in the history
Introduced a cache in apache#4853 but found that it was not needed because the
code clears it on each pass through all of the tablets.  Had assumed
it was a long lived cache.
  • Loading branch information
keith-turner committed Sep 5, 2024
1 parent 41d9e3a commit 360c1a0
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

/**
* The LargestFirstMemoryManager attempts to keep memory between 80% and 90% full. It adapts over
* time the point at which it should start a compaction based on how full memory gets between
Expand All @@ -60,8 +57,7 @@ public class LargestFirstMemoryManager {
private double compactionThreshold;
private long maxObserved;
private final HashMap<TableId,Long> mincIdleThresholds = new HashMap<>();
private final Cache<TableId,Long> mincAgeThresholds =
Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build();
private final HashMap<TableId,Long> mincAgeThresholds = new HashMap<>();
private ServerContext context = null;

private static class TabletInfo {
Expand Down Expand Up @@ -144,17 +140,14 @@ public LargestFirstMemoryManager() {

protected long getMinCIdleThreshold(KeyExtent extent) {
TableId tableId = extent.tableId();
if (!mincIdleThresholds.containsKey(tableId)) {
mincIdleThresholds.put(tableId, context.getTableConfiguration(tableId)
.getTimeInMillis(Property.TABLE_MINC_COMPACT_IDLETIME));
}
return mincIdleThresholds.get(tableId);
return mincIdleThresholds.computeIfAbsent(tableId, tid -> context.getTableConfiguration(tid)
.getTimeInMillis(Property.TABLE_MINC_COMPACT_IDLETIME));
}

protected long getMaxAge(KeyExtent extent) {
TableId tableId = extent.tableId();
return mincAgeThresholds.asMap().computeIfAbsent(tableId, tid -> context
.getTableConfiguration(tid).getTimeInMillis(Property.TABLE_MINC_COMPACT_MAXAGE));
return mincAgeThresholds.computeIfAbsent(tableId, tid -> context.getTableConfiguration(tid)
.getTimeInMillis(Property.TABLE_MINC_COMPACT_MAXAGE));
}

protected boolean tableExists(TableId tableId) {
Expand All @@ -175,6 +168,8 @@ public List<KeyExtent> tabletsToMinorCompact(List<TabletMemoryReport> tablets) {
final int maxMinCs = maxConcurrentMincs * numWaitingMultiplier;

mincIdleThresholds.clear();
mincAgeThresholds.clear();

final List<KeyExtent> tabletsToMinorCompact = new ArrayList<>();

LargestMap largestMemTablets = new LargestMap(maxMinCs);
Expand Down

0 comments on commit 360c1a0

Please sign in to comment.