-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Enhancement] modify statistic cache expire-update logical #53344
Conversation
if (columnStatistic.isPresent()) { | ||
columnStatistics.add(StatisticsUtils.estimateColumnStatistics(table, column, columnStatistic.get())); | ||
columnStatistics.add( | ||
StatisticsUtils.estimateColumnStatistics(table, column, columnStatistic.get())); | ||
} else { | ||
columnStatistics.add(ConnectorTableColumnStats.unknown()); | ||
} |
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.
The most risky bug in this code is:
Potentially blocking operation in asynchronous execution.
You can modify the code like this:
try {
ColumnBasicStatsCacheLoader loader = new ColumnBasicStatsCacheLoader();
CompletableFuture<Map<ColumnStatsCacheKey, Optional<ColumnStatistic>>> future =
loader.asyncLoadAll(cacheKeys, statsCacheRefresherExecutor);
if (isSync) {
// Use get() with a timeout to avoid indefinitely blocking if the operation hangs
Map<ColumnStatsCacheKey, Optional<ColumnStatistic>> result = future.get(60, TimeUnit.SECONDS);
columnStatistics.synchronous().putAll(result);
} else {
columnStatistics.synchronous().refresh();
future.whenComplete((res, e) -> {
if (e != null) {
LOG.error("Error loading column statistics", e);
} else {
columnStatistics.synchronous().putAll(res);
}
});
}
} catch (TimeoutException e) {
LOG.error("Timeout occurred while refreshing column statistics", e);
} catch (Exception e) {
LOG.warn("Failed to refresh getColumnStatistics", e);
}
This modification includes a timeout for the future.get()
call to prevent indefinite blocking, and error handling within whenComplete
to log any exceptions encountered during asynchronous execution.
Signed-off-by: Seaven <[email protected]>
Signed-off-by: Seaven <[email protected]>
Signed-off-by: Seaven <[email protected]>
Quality Gate failedFailed conditions See analysis details on SonarQube Cloud Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE |
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 51 / 57 (89.47%) file detail
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
Why I'm doing:
What I'm doing:
Before this PR:
This PR:
Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: