forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run compaction as a supervisor on Overlord (apache#16768)
Description ----------- Auto-compaction currently poses several challenges as it: 1. may get stuck on a failing interval. 2. may get stuck on the latest interval if more data keeps coming into it. 3. always picks the latest interval regardless of the level of compaction in it. 4. may never pick a datasource if its intervals are not very recent. 5. requires setting an explicit period which does not cater to the changing needs of a Druid cluster. This PR introduces various improvements to compaction scheduling to tackle the above problems. Change Summary -------------- 1. Run compaction for a datasource as a supervisor of type `autocompact` on Overlord. 2. Make compaction policy extensible and configurable. 3. Track status of recently submitted compaction tasks and pass this info to policy. 4. Add `/simulate` API on both Coordinator and Overlord to run compaction simulations. 5. Redirect compaction status APIs to the Overlord when compaction supervisors are enabled.
- Loading branch information
Showing
96 changed files
with
5,736 additions
and
2,138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
indexing-service/src/main/java/org/apache/druid/guice/SupervisorModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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.guice; | ||
|
||
import com.fasterxml.jackson.databind.Module; | ||
import com.fasterxml.jackson.databind.jsontype.NamedType; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.inject.Binder; | ||
import org.apache.druid.indexing.compact.CompactionSupervisorSpec; | ||
import org.apache.druid.indexing.overlord.supervisor.SupervisorStateManagerConfig; | ||
import org.apache.druid.initialization.DruidModule; | ||
import org.apache.druid.server.coordinator.CompactionSupervisorConfig; | ||
|
||
import java.util.List; | ||
|
||
public class SupervisorModule implements DruidModule | ||
{ | ||
@Override | ||
public void configure(Binder binder) | ||
{ | ||
JsonConfigProvider.bind(binder, "druid.supervisor", SupervisorStateManagerConfig.class); | ||
JsonConfigProvider.bind(binder, "druid.supervisor.compaction", CompactionSupervisorConfig.class); | ||
} | ||
|
||
@Override | ||
public List<? extends Module> getJacksonModules() | ||
{ | ||
return ImmutableList.of( | ||
new SimpleModule(getClass().getSimpleName()) | ||
.registerSubtypes( | ||
new NamedType(CompactionSupervisorSpec.class, CompactionSupervisorSpec.TYPE) | ||
) | ||
); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
indexing-service/src/main/java/org/apache/druid/indexing/compact/CompactionScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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 org.apache.druid.server.compaction.CompactionSimulateResult; | ||
import org.apache.druid.server.coordinator.AutoCompactionSnapshot; | ||
import org.apache.druid.server.coordinator.ClusterCompactionConfig; | ||
import org.apache.druid.server.coordinator.CompactionConfigValidationResult; | ||
import org.apache.druid.server.coordinator.CompactionSupervisorConfig; | ||
import org.apache.druid.server.coordinator.DataSourceCompactionConfig; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Compaction scheduler that runs on the Overlord if {@link CompactionSupervisorConfig} | ||
* is enabled. | ||
* <p> | ||
* Usage: | ||
* <ul> | ||
* <li>When an active {@link CompactionSupervisor} starts, it should register | ||
* itself by calling {@link #startCompaction}.</li> | ||
* <li>When a suspended {@link CompactionSupervisor} starts, it should stop | ||
* compaction by calling {@link #stopCompaction}.</li> | ||
* <li>When stopping, any {@link CompactionSupervisor} (active or suspended) | ||
* should call {@link #stopCompaction}.</li> | ||
* </ul> | ||
*/ | ||
public interface CompactionScheduler | ||
{ | ||
void start(); | ||
|
||
void stop(); | ||
|
||
boolean isRunning(); | ||
|
||
CompactionConfigValidationResult validateCompactionConfig(DataSourceCompactionConfig compactionConfig); | ||
|
||
void startCompaction(String dataSourceName, DataSourceCompactionConfig compactionConfig); | ||
|
||
void stopCompaction(String dataSourceName); | ||
|
||
Map<String, AutoCompactionSnapshot> getAllCompactionSnapshots(); | ||
|
||
AutoCompactionSnapshot getCompactionSnapshot(String dataSource); | ||
|
||
CompactionSimulateResult simulateRunWithConfigUpdate(ClusterCompactionConfig updateRequest); | ||
|
||
} |
156 changes: 156 additions & 0 deletions
156
indexing-service/src/main/java/org/apache/druid/indexing/compact/CompactionSupervisor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
* 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 org.apache.druid.indexing.overlord.DataSourceMetadata; | ||
import org.apache.druid.indexing.overlord.supervisor.Supervisor; | ||
import org.apache.druid.indexing.overlord.supervisor.SupervisorReport; | ||
import org.apache.druid.indexing.overlord.supervisor.SupervisorStateManager; | ||
import org.apache.druid.indexing.overlord.supervisor.autoscaler.LagStats; | ||
import org.apache.druid.java.util.common.DateTimes; | ||
import org.apache.druid.java.util.common.logger.Logger; | ||
import org.apache.druid.server.coordinator.AutoCompactionSnapshot; | ||
|
||
/** | ||
* Supervisor for compaction of a single datasource. | ||
*/ | ||
public class CompactionSupervisor implements Supervisor | ||
{ | ||
private static final Logger log = new Logger(CompactionSupervisor.class); | ||
|
||
private final String dataSource; | ||
private final CompactionScheduler scheduler; | ||
private final CompactionSupervisorSpec supervisorSpec; | ||
|
||
public CompactionSupervisor( | ||
CompactionSupervisorSpec supervisorSpec, | ||
CompactionScheduler scheduler | ||
) | ||
{ | ||
this.supervisorSpec = supervisorSpec; | ||
this.scheduler = scheduler; | ||
this.dataSource = supervisorSpec.getSpec().getDataSource(); | ||
} | ||
|
||
@Override | ||
public void start() | ||
{ | ||
if (supervisorSpec.isSuspended()) { | ||
log.info("Suspending compaction for dataSource[%s].", dataSource); | ||
scheduler.stopCompaction(dataSource); | ||
} else { | ||
log.info("Starting compaction for dataSource[%s].", dataSource); | ||
scheduler.startCompaction(dataSource, supervisorSpec.getSpec()); | ||
} | ||
} | ||
|
||
@Override | ||
public void stop(boolean stopGracefully) | ||
{ | ||
log.info("Stopping compaction for dataSource[%s].", dataSource); | ||
scheduler.stopCompaction(dataSource); | ||
} | ||
|
||
@Override | ||
public SupervisorReport<AutoCompactionSnapshot> getStatus() | ||
{ | ||
final AutoCompactionSnapshot snapshot; | ||
if (supervisorSpec.isSuspended()) { | ||
snapshot = AutoCompactionSnapshot.builder(dataSource) | ||
.withStatus(AutoCompactionSnapshot.AutoCompactionScheduleStatus.NOT_ENABLED) | ||
.build(); | ||
} else { | ||
snapshot = scheduler.getCompactionSnapshot(dataSource); | ||
} | ||
|
||
return new SupervisorReport<>(supervisorSpec.getId(), DateTimes.nowUtc(), snapshot); | ||
} | ||
|
||
@Override | ||
public SupervisorStateManager.State getState() | ||
{ | ||
if (!scheduler.isRunning()) { | ||
return State.SCHEDULER_STOPPED; | ||
} else if (supervisorSpec.isSuspended()) { | ||
return State.SUSPENDED; | ||
} else { | ||
return State.RUNNING; | ||
} | ||
} | ||
|
||
// Un-implemented methods used only by streaming supervisors | ||
|
||
@Override | ||
public void reset(DataSourceMetadata dataSourceMetadata) | ||
{ | ||
throw new UnsupportedOperationException("Resetting not supported for 'autocompact' supervisors."); | ||
} | ||
|
||
@Override | ||
public void resetOffsets(DataSourceMetadata resetDataSourceMetadata) | ||
{ | ||
throw new UnsupportedOperationException("Resetting offsets not supported for 'autocompact' supervisors."); | ||
} | ||
|
||
@Override | ||
public void checkpoint(int taskGroupId, DataSourceMetadata checkpointMetadata) | ||
{ | ||
throw new UnsupportedOperationException("Checkpointing not supported for 'autocompact' supervisors."); | ||
} | ||
|
||
@Override | ||
public LagStats computeLagStats() | ||
{ | ||
throw new UnsupportedOperationException("Lag stats not supported for 'autocompact' supervisors."); | ||
} | ||
|
||
@Override | ||
public int getActiveTaskGroupsCount() | ||
{ | ||
throw new UnsupportedOperationException("Task groups not supported for 'autocompact' supervisors."); | ||
} | ||
|
||
public enum State implements SupervisorStateManager.State | ||
{ | ||
SCHEDULER_STOPPED(true), | ||
RUNNING(true), | ||
SUSPENDED(true), | ||
UNHEALTHY(false); | ||
|
||
private final boolean healthy; | ||
|
||
State(boolean healthy) | ||
{ | ||
this.healthy = healthy; | ||
} | ||
|
||
@Override | ||
public boolean isFirstRunOnly() | ||
{ | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isHealthy() | ||
{ | ||
return healthy; | ||
} | ||
} | ||
} |
Oops, something went wrong.