Skip to content

Commit

Permalink
Add configs for ttl of Alluxio cache
Browse files Browse the repository at this point in the history
  • Loading branch information
beinan committed Jun 21, 2023
1 parent 024b792 commit 6edab30
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static io.airlift.units.DataSize.Unit.GIGABYTE;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.HOURS;
import static java.util.concurrent.TimeUnit.SECONDS;

public class AlluxioCacheConfig
Expand All @@ -38,6 +39,9 @@ public class AlluxioCacheConfig
private EvictionPolicy evictionPolicy = EvictionPolicy.LRU;
private boolean shadowCacheEnabled;
private Duration shadowCacheWindow = new Duration(7, DAYS);
private boolean ttlEnabled;
private Duration ttlCheckInterval = new Duration(1, HOURS);
private Duration ttlThreshold = new Duration(14, DAYS);

public boolean isMetricsCollectionEnabled()
{
Expand Down Expand Up @@ -220,4 +224,43 @@ public AlluxioCacheConfig setShadowCacheWindow(Duration shadowCacheWindow)
this.shadowCacheWindow = shadowCacheWindow;
return this;
}

@Config("cache.alluxio.ttl-enabled")
@ConfigDescription("If the alluxio caching enables the TTL")
public AlluxioCacheConfig setTtlEnabled(boolean ttlEnabled)
{
this.ttlEnabled = ttlEnabled;
return this;
}

public boolean isTtlEnabled()
{
return ttlEnabled;
}

public Duration getTtlCheckInterval()
{
return ttlCheckInterval;
}

@Config("cache.alluxio.ttl-check-interval")
@ConfigDescription("TTL check interval for alluxio cache")
public AlluxioCacheConfig setTtlCheckInterval(Duration ttlCheckInterval)
{
this.ttlCheckInterval = ttlCheckInterval;
return this;
}

public Duration getTtlThreshold()
{
return ttlThreshold;
}

@Config("cache.alluxio.ttl-threshold")
@ConfigDescription("TTL threshold for alluxio cache")
public AlluxioCacheConfig setTtlThreshold(Duration ttlThreshold)
{
this.ttlThreshold = ttlThreshold;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public void updateConfiguration(Configuration configuration, HdfsContext context
}
configuration.set("alluxio.user.client.cache.shadow.enabled", String.valueOf(alluxioCacheConfig.isShadowCacheEnabled()));
configuration.set("alluxio.user.client.cache.shadow.window", String.valueOf(alluxioCacheConfig.getShadowCacheWindow().toMillis()));
configuration.set("alluxio.user.client.cache.ttl.enabled", String.valueOf(alluxioCacheConfig.isTtlEnabled()));
if (alluxioCacheConfig.isTtlEnabled()) {
configuration.set("alluxio.user.client.cache.ttl.check.interval.seconds",
String.valueOf(alluxioCacheConfig.getTtlCheckInterval().toMillis() / 1000));
configuration.set("alluxio.user.client.cache.ttl.threshold.seconds",
String.valueOf(alluxioCacheConfig.getTtlThreshold().toMillis() / 1000));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import static io.airlift.units.DataSize.Unit.GIGABYTE;
import static io.airlift.units.DataSize.Unit.MEGABYTE;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.HOURS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;

public class TestAlluxioCacheConfig
Expand All @@ -47,7 +49,10 @@ public void testDefaults()
.setTimeoutThreads(64)
.setCacheQuotaEnabled(false)
.setShadowCacheEnabled(false)
.setShadowCacheWindow(new Duration(7, DAYS)));
.setShadowCacheWindow(new Duration(7, DAYS))
.setTtlCheckInterval(new Duration(1, HOURS))
.setTtlEnabled(false)
.setTtlThreshold(new Duration(14, DAYS)));
}

@Test
Expand All @@ -68,6 +73,9 @@ public void testExplicitPropertyMappings()
.put("cache.alluxio.quota-enabled", "true")
.put("cache.alluxio.shadow-cache-enabled", "true")
.put("cache.alluxio.shadow-cache-window", "1d")
.put("cache.alluxio.ttl-check-interval", "60s")
.put("cache.alluxio.ttl-enabled", "true")
.put("cache.alluxio.ttl-threshold", "60m")
.build();

AlluxioCacheConfig expected = new AlluxioCacheConfig()
Expand All @@ -84,7 +92,10 @@ public void testExplicitPropertyMappings()
.setTimeoutThreads(512)
.setCacheQuotaEnabled(true)
.setShadowCacheEnabled(true)
.setShadowCacheWindow(new Duration(1, DAYS));
.setShadowCacheWindow(new Duration(1, DAYS))
.setTtlCheckInterval(new Duration(60, SECONDS))
.setTtlEnabled(true)
.setTtlThreshold(new Duration(60, MINUTES));

assertFullMapping(properties, expected);
}
Expand Down

0 comments on commit 6edab30

Please sign in to comment.