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

Improve error message when resource group selector cannot be loaded #13036

Merged
merged 1 commit into from
Aug 29, 2019
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 @@ -63,8 +63,10 @@
import static com.google.common.base.Preconditions.checkState;
import static io.airlift.concurrent.Threads.daemonThreadsNamed;
import static io.airlift.units.Duration.succinctNanos;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

public class DbResourceGroupConfigurationManager
extends AbstractResourceConfigurationManager
Expand Down Expand Up @@ -116,9 +118,8 @@ protected Optional<Duration> getCpuQuotaPeriod()
@Override
protected List<ResourceGroupSpec> getRootGroups()
{
if (lastRefresh.get() == 0) {
throw new PrestoException(CONFIGURATION_UNAVAILABLE, "Root groups cannot be fetched from database");
}
checkMaxRefreshInterval();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function will print cannot fetch selectors but this should be about root groups. They are likely to fail at the same time so I'm ok with printing the same message for both, but it should not print selectors in that case.


if (this.selectors.get().isEmpty()) {
throw new PrestoException(CONFIGURATION_INVALID, "No root groups are configured");
}
Expand Down Expand Up @@ -156,9 +157,8 @@ public void configure(ResourceGroup group, SelectionContext<VariableMap> criteri
@Override
public Optional<SelectionContext<VariableMap>> match(SelectionCriteria criteria)
{
if (lastRefresh.get() == 0) {
throw new PrestoException(CONFIGURATION_UNAVAILABLE, "Selectors cannot be fetched from database");
}
checkMaxRefreshInterval();

if (selectors.get().isEmpty()) {
throw new PrestoException(CONFIGURATION_INVALID, "No selectors are configured");
}
Expand All @@ -173,9 +173,8 @@ public Optional<SelectionContext<VariableMap>> match(SelectionCriteria criteria)
@VisibleForTesting
public List<ResourceGroupSelector> getSelectors()
{
if (lastRefresh.get() == 0) {
throw new PrestoException(CONFIGURATION_UNAVAILABLE, "Selectors cannot be fetched from database");
}
checkMaxRefreshInterval();

if (selectors.get().isEmpty()) {
throw new PrestoException(CONFIGURATION_INVALID, "No selectors are configured");
}
Expand Down Expand Up @@ -237,11 +236,11 @@ public synchronized void load()
lastRefresh.set(System.nanoTime());
}
catch (Throwable e) {
if (succinctNanos(System.nanoTime() - lastRefresh.get()).compareTo(maxRefreshInterval) > 0) {
lastRefresh.set(0);
}
refreshFailures.update(1);
log.error(e, "Error loading configuration from db");
if (lastRefresh.get() != 0) {
log.debug("Last successful configuration loading was %s ago", succinctNanos(System.nanoTime() - lastRefresh.get()).toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this line be useful in test clusters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@highker : "Test clusters"? -- I am thinking it will help when something goes wrong and oncall can check the log.

}
}
}

Expand Down Expand Up @@ -367,6 +366,18 @@ private ResourceGroup getRootGroup(ResourceGroupId groupId)
return groups.get(groupId);
}

private void checkMaxRefreshInterval()
{
if (System.nanoTime() - lastRefresh.get() > maxRefreshInterval.toMillis() * MILLISECONDS.toNanos(1)) {
String message = "Resource group configuration cannot be fetched from database.";
if (lastRefresh.get() != 0) {
message += format(" Current resource group configuration is loaded %s ago", succinctNanos(System.nanoTime() - lastRefresh.get()).toString());
}

throw new PrestoException(CONFIGURATION_UNAVAILABLE, message);
}
}

@Managed
@Nested
public CounterStat getRefreshFailures()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,15 @@ public void testRefreshInterval()
fail("Expected unavailable configuration exception");
}
catch (Exception e) {
assertEquals(e.getMessage(), "Selectors cannot be fetched from database");
assertTrue(e.getMessage().startsWith("Resource group configuration cannot be fetched from database."));
}

try {
manager.getRootGroups();
fail("Expected unavailable configuration exception");
}
catch (Exception e) {
assertEquals(e.getMessage(), "Root groups cannot be fetched from database");
assertTrue(e.getMessage().startsWith("Resource group configuration cannot be fetched from database."));
}

manager.destroy();
Expand Down