Skip to content

Commit

Permalink
[BugFix] unify the behavior of default AutoCollector (backport #51723) (
Browse files Browse the repository at this point in the history
#51871)

Co-authored-by: Murphy <[email protected]>
  • Loading branch information
mergify[bot] and murphyatwork authored Oct 14, 2024
1 parent c54c1c7 commit e2983e0
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ protected void runAfterCatalogReady() {
public List<StatisticsCollectJob> runJobs() {
List<StatisticsCollectJob> result = Lists.newArrayList();

// TODO: define the priority in the job instead
List<NativeAnalyzeJob> allNativeAnalyzeJobs =
GlobalStateMgr.getCurrentState().getAnalyzeMgr().getAllNativeAnalyzeJobList();
allNativeAnalyzeJobs.sort((o1, o2) -> Long.compare(o2.getId(), o1.getId()));
Expand All @@ -102,12 +103,8 @@ public List<StatisticsCollectJob> runJobs() {

if (Config.enable_collect_full_statistic) {
LOG.info("auto collect full statistic on all databases start");
List<StatisticsCollectJob> allJobs = StatisticsCollectJobFactory.buildStatisticsCollectJob(
new NativeAnalyzeJob(StatsConstants.DEFAULT_ALL_ID, StatsConstants.DEFAULT_ALL_ID, null, null,
AnalyzeType.FULL, ScheduleType.SCHEDULE,
Maps.newHashMap(),
ScheduleStatus.PENDING,
LocalDateTime.MIN));
List<StatisticsCollectJob> allJobs =
StatisticsCollectJobFactory.buildStatisticsCollectJob(createDefaultJobAnalyzeAll());
for (StatisticsCollectJob statsJob : allJobs) {
// user-created analyze job has a higher priority
if (statsJob.isAnalyzeTable() && analyzeTableSet.contains(statsJob.getTable().getId())) {
Expand Down Expand Up @@ -149,18 +146,28 @@ public List<StatisticsCollectJob> runJobs() {
return result;
}

/**
* Choose user-created jobs first, fallback to default job if it doesn't exist
*/
private void initDefaultJob() {
// Add a default sample job if wasn't collect
List<NativeAnalyzeJob> allNativeAnalyzeJobs =
GlobalStateMgr.getCurrentState().getAnalyzeMgr().getAllNativeAnalyzeJobList();
if (allNativeAnalyzeJobs.stream().anyMatch(j -> j.getScheduleType() == ScheduleType.SCHEDULE)) {
return;
}

NativeAnalyzeJob nativeAnalyzeJob = new NativeAnalyzeJob(StatsConstants.DEFAULT_ALL_ID, StatsConstants.DEFAULT_ALL_ID,
Collections.emptyList(), Collections.emptyList(), AnalyzeType.SAMPLE, ScheduleType.SCHEDULE,
NativeAnalyzeJob job = createDefaultJobAnalyzeAll();
GlobalStateMgr.getCurrentState().getAnalyzeMgr().addAnalyzeJob(job);
}

/**
* Create a default job to analyze all tables in the system
*/
private NativeAnalyzeJob createDefaultJobAnalyzeAll() {
AnalyzeType analyzeType = Config.enable_collect_full_statistic ? AnalyzeType.FULL : AnalyzeType.SAMPLE;
return new NativeAnalyzeJob(StatsConstants.DEFAULT_ALL_ID, StatsConstants.DEFAULT_ALL_ID,
Collections.emptyList(), Collections.emptyList(), analyzeType, ScheduleType.SCHEDULE,
Maps.newHashMap(), ScheduleStatus.PENDING, LocalDateTime.MIN);
GlobalStateMgr.getCurrentState().getAnalyzeMgr().addAnalyzeJob(nativeAnalyzeJob);
}

private boolean checkoutAnalyzeTime(LocalTime now) {
Expand Down

0 comments on commit e2983e0

Please sign in to comment.