Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor code cleanup #12334

Merged
merged 2 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.trino.plugin.hive.HiveConfig;
import io.trino.plugin.hive.HivePartition;
import io.trino.plugin.hive.HiveType;
import io.trino.plugin.hive.HiveViewNotSupportedException;
import io.trino.plugin.hive.PartitionNotFoundException;
import io.trino.plugin.hive.PartitionStatistics;
import io.trino.plugin.hive.SchemaAlreadyExistsException;
Expand Down Expand Up @@ -347,7 +346,7 @@ public Optional<Table> getTable(HiveIdentity identity, String databaseName, Stri
{
try {
return retry()
.stopOn(NoSuchObjectException.class, HiveViewNotSupportedException.class)
tangjiangling marked this conversation as resolved.
Show resolved Hide resolved
.stopOn(NoSuchObjectException.class)
.stopOnIllegalExceptions()
.run("getTable", stats.getGetTable().wrap(() -> {
Table table = getTableFromMetastore(identity, databaseName, tableName);
Expand Down Expand Up @@ -397,7 +396,7 @@ private Map<String, HiveColumnStatistics> getTableColumnStatistics(HiveIdentity
{
try {
return retry()
.stopOn(NoSuchObjectException.class, HiveViewNotSupportedException.class)
.stopOn(NoSuchObjectException.class)
.stopOnIllegalExceptions()
.run("getTableColumnStatistics", stats.getGetTableColumnStatistics().wrap(() -> {
try (ThriftMetastoreClient client = createMetastoreClient(identity)) {
Expand Down Expand Up @@ -492,7 +491,7 @@ private Map<String, List<ColumnStatisticsObj>> getMetastorePartitionColumnStatis
{
try {
return retry()
.stopOn(NoSuchObjectException.class, HiveViewNotSupportedException.class)
.stopOn(NoSuchObjectException.class)
.stopOnIllegalExceptions()
.run("getPartitionColumnStatistics", stats.getGetPartitionColumnStatistics().wrap(() -> {
try (ThriftMetastoreClient client = createMetastoreClient(identity)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class RetryDriver
private final Duration maxSleepTime;
private final double scaleFactor;
private final Duration maxRetryTime;
private final List<Class<? extends Exception>> allowedExceptions;
private final List<Class<? extends Exception>> stopOnExceptions;
private final Optional<Runnable> retryRunnable;

private RetryDriver(
Expand All @@ -50,15 +50,15 @@ private RetryDriver(
Duration maxSleepTime,
double scaleFactor,
Duration maxRetryTime,
List<Class<? extends Exception>> allowedExceptions,
List<Class<? extends Exception>> stopOnExceptions,
Optional<Runnable> retryRunnable)
{
this.maxAttempts = maxAttempts;
this.minSleepTime = minSleepTime;
this.maxSleepTime = maxSleepTime;
this.scaleFactor = scaleFactor;
this.maxRetryTime = maxRetryTime;
this.allowedExceptions = allowedExceptions;
this.stopOnExceptions = stopOnExceptions;
this.retryRunnable = retryRunnable;
}

Expand All @@ -80,25 +80,25 @@ public static RetryDriver retry()

public final RetryDriver maxAttempts(int maxAttempts)
{
return new RetryDriver(maxAttempts, minSleepTime, maxSleepTime, scaleFactor, maxRetryTime, allowedExceptions, retryRunnable);
return new RetryDriver(maxAttempts, minSleepTime, maxSleepTime, scaleFactor, maxRetryTime, stopOnExceptions, retryRunnable);
}

public final RetryDriver exponentialBackoff(Duration minSleepTime, Duration maxSleepTime, Duration maxRetryTime, double scaleFactor)
{
return new RetryDriver(maxAttempts, minSleepTime, maxSleepTime, scaleFactor, maxRetryTime, allowedExceptions, retryRunnable);
return new RetryDriver(maxAttempts, minSleepTime, maxSleepTime, scaleFactor, maxRetryTime, stopOnExceptions, retryRunnable);
}

public final RetryDriver onRetry(Runnable retryRunnable)
{
return new RetryDriver(maxAttempts, minSleepTime, maxSleepTime, scaleFactor, maxRetryTime, allowedExceptions, Optional.ofNullable(retryRunnable));
return new RetryDriver(maxAttempts, minSleepTime, maxSleepTime, scaleFactor, maxRetryTime, stopOnExceptions, Optional.ofNullable(retryRunnable));
}

@SafeVarargs
public final RetryDriver stopOn(Class<? extends Exception>... classes)
{
requireNonNull(classes, "classes is null");
List<Class<? extends Exception>> exceptions = ImmutableList.<Class<? extends Exception>>builder()
.addAll(allowedExceptions)
.addAll(stopOnExceptions)
.addAll(Arrays.asList(classes))
.build();

Expand Down Expand Up @@ -130,7 +130,7 @@ public <V> V run(String callableName, Callable<V> callable)
return callable.call();
}
catch (Exception e) {
for (Class<? extends Exception> clazz : allowedExceptions) {
for (Class<? extends Exception> clazz : stopOnExceptions) {
if (clazz.isInstance(e)) {
addSuppressed(e, suppressedExceptions);
throw e;
Expand Down