kfaraz commented on code in PR #16768: URL: https://github.com/apache/druid/pull/16768#discussion_r1734808361
########## indexing-service/src/main/java/org/apache/druid/indexing/compact/OverlordCompactionScheduler.java: ########## @@ -0,0 +1,290 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.indexing.compact; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Supplier; +import com.google.inject.Inject; +import org.apache.druid.indexing.overlord.TaskMaster; +import org.apache.druid.indexing.overlord.TaskQueryTool; +import org.apache.druid.java.util.common.Stopwatch; +import org.apache.druid.java.util.common.concurrent.ScheduledExecutorFactory; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.java.util.emitter.service.ServiceEmitter; +import org.apache.druid.java.util.emitter.service.ServiceMetricEvent; +import org.apache.druid.metadata.SegmentsMetadataManager; +import org.apache.druid.rpc.indexing.OverlordClient; +import org.apache.druid.server.compaction.CompactionRunSimulator; +import org.apache.druid.server.compaction.CompactionSimulateResult; +import org.apache.druid.server.compaction.CompactionStatusTracker; +import org.apache.druid.server.coordinator.AutoCompactionSnapshot; +import org.apache.druid.server.coordinator.ClusterCompactionConfig; +import org.apache.druid.server.coordinator.CompactionSupervisorsConfig; +import org.apache.druid.server.coordinator.CoordinatorOverlordServiceConfig; +import org.apache.druid.server.coordinator.DataSourceCompactionConfig; +import org.apache.druid.server.coordinator.DruidCompactionConfig; +import org.apache.druid.server.coordinator.duty.CompactSegments; +import org.apache.druid.server.coordinator.stats.CoordinatorRunStats; +import org.apache.druid.server.coordinator.stats.CoordinatorStat; +import org.apache.druid.server.coordinator.stats.Dimension; +import org.apache.druid.timeline.SegmentTimeline; +import org.joda.time.Duration; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * Implementation of {@link CompactionScheduler}. + * <p> + * When {@link CompactionSupervisorsConfig} is enabled, this class performs the + * following responsibilities on the leader Overlord: + * <ul> + * <li>Poll segments from metadata</li> + * <li>Check compaction status every 5 seconds</li> + * <li>Submit compaction tasks for active datasources</li> + * <li>Track status of submitted compaction tasks</li> + * </ul> + * Internally, this class uses an instance of {@link CompactSegments} duty. + */ +public class OverlordCompactionScheduler implements CompactionScheduler +{ + private static final Logger log = new Logger(OverlordCompactionScheduler.class); + + private static final long SCHEDULE_PERIOD_SECONDS = 5; Review Comment: Yes, the primary limitation with the existing Coordinator duty-based flow was that it involved HTTP communication between Coordinator and Overlord. Also, the Overlord would often answer these HTTP requests by querying the metadata store. But with the newly `CompactionStatusTracker`, we maintain status of recently completed tasks in memory, thus avoiding load on the metadata store. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
