-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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(); | ||
|
||
if (this.selectors.get().isEmpty()) { | ||
throw new PrestoException(CONFIGURATION_INVALID, "No root groups are configured"); | ||
} | ||
|
@@ -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"); | ||
} | ||
|
@@ -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"); | ||
} | ||
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this line be useful in test clusters? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} | ||
} | ||
|
||
|
@@ -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() | ||
|
There was a problem hiding this comment.
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.