Skip to content

Commit

Permalink
Use Optional instead of very large value by default
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Oct 11, 2019
1 parent e0c3e2b commit 5b08a90
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
Expand Up @@ -112,13 +112,16 @@ public CachingHiveMetastore(@ForCachingHiveMetastore HiveMetastore delegate, @Fo
config.getMetastoreCacheMaximumSize());
}

public CachingHiveMetastore(HiveMetastore delegate, Executor executor, Duration cacheTtl, Duration refreshInterval, long maximumSize)
public CachingHiveMetastore(HiveMetastore delegate, Executor executor, Duration cacheTtl, Optional<Duration> refreshInterval, long maximumSize)
{
this(
delegate,
executor,
OptionalLong.of(cacheTtl.toMillis()),
OptionalLong.of(refreshInterval.toMillis()),
refreshInterval
.map(Duration::toMillis)
.map(OptionalLong::of)
.orElseGet(OptionalLong::empty),
maximumSize);
}

Expand Down
Expand Up @@ -20,12 +20,13 @@
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import java.util.Optional;
import java.util.concurrent.TimeUnit;

public class CachingHiveMetastoreConfig
{
private Duration metastoreCacheTtl = new Duration(0, TimeUnit.SECONDS);
private Duration metastoreRefreshInterval = new Duration(Integer.MAX_VALUE, TimeUnit.DAYS);
private Optional<Duration> metastoreRefreshInterval = Optional.empty();
private long metastoreCacheMaximumSize = 10000;
private int maxMetastoreRefreshThreads = 100;

Expand All @@ -44,7 +45,7 @@ public CachingHiveMetastoreConfig setMetastoreCacheTtl(Duration metastoreCacheTt
}

@NotNull
public Duration getMetastoreRefreshInterval()
public Optional<Duration> getMetastoreRefreshInterval()
{
return metastoreRefreshInterval;
}
Expand All @@ -53,7 +54,7 @@ public Duration getMetastoreRefreshInterval()
@Config("hive.metastore-refresh-interval")
public CachingHiveMetastoreConfig setMetastoreRefreshInterval(Duration metastoreRefreshInterval)
{
this.metastoreRefreshInterval = metastoreRefreshInterval;
this.metastoreRefreshInterval = Optional.ofNullable(metastoreRefreshInterval);
return this;
}

Expand Down
Expand Up @@ -707,7 +707,7 @@ protected final void setup(String host, int port, String databaseName, String ti
new BridgingHiveMetastore(new ThriftHiveMetastore(metastoreLocator, new ThriftMetastoreConfig(), new HiveAuthenticationConfig())),
executor,
Duration.valueOf("1m"),
Duration.valueOf("15s"),
Optional.of(Duration.valueOf("15s")),
10000);

setup(databaseName, hiveConfig, metastore);
Expand Down
Expand Up @@ -70,7 +70,7 @@ public void setUp()
new BridgingHiveMetastore(thriftHiveMetastore),
executor,
new Duration(5, TimeUnit.MINUTES),
new Duration(1, TimeUnit.MINUTES),
Optional.of(new Duration(1, TimeUnit.MINUTES)),
1000);
stats = thriftHiveMetastore.getStats();
}
Expand Down
Expand Up @@ -31,7 +31,7 @@ public void testDefaults()
{
assertRecordedDefaults(recordDefaults(CachingHiveMetastoreConfig.class)
.setMetastoreCacheTtl(new Duration(0, TimeUnit.SECONDS))
.setMetastoreRefreshInterval(new Duration(Integer.MAX_VALUE, TimeUnit.DAYS))
.setMetastoreRefreshInterval(null)
.setMetastoreCacheMaximumSize(10000)
.setMaxMetastoreRefreshThreads(100));
}
Expand Down

0 comments on commit 5b08a90

Please sign in to comment.