Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.accumulo.core.util.compaction;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.ECOMP;
import static org.apache.accumulo.core.util.threads.ThreadPoolNames.COMPACTOR_RUNNING_COMPACTIONS_POOL;
import static org.apache.accumulo.core.util.threads.ThreadPoolNames.COMPACTOR_RUNNING_COMPACTION_IDS_POOL;

Expand Down Expand Up @@ -47,6 +48,8 @@
import org.apache.accumulo.core.lock.ServiceLockPaths.AddressSelector;
import org.apache.accumulo.core.lock.ServiceLockPaths.ResourceGroupPredicate;
import org.apache.accumulo.core.lock.ServiceLockPaths.ServiceLockPath;
import org.apache.accumulo.core.metadata.schema.Ample;
import org.apache.accumulo.core.metadata.schema.CompactionMetadata;
import org.apache.accumulo.core.metadata.schema.ExternalCompactionId;
import org.apache.accumulo.core.rpc.RpcFuture;
import org.apache.accumulo.core.rpc.ThriftUtil;
Expand Down Expand Up @@ -313,4 +316,29 @@ public static void cancelCompaction(ClientContext context, HostAndPort compactor
ThriftUtil.returnClient(client, context);
}
}

public static Optional<HostAndPort> findCompactorRunningCompaction(ClientContext context,
ExternalCompactionId ecid) {
for (var level : Ample.DataLevel.values()) {
var compactor = findCompactorRunningCompaction(context, level, ecid);
if (compactor.isPresent()) {
return compactor;
}
}

return Optional.empty();
}

private static Optional<HostAndPort> findCompactorRunningCompaction(ClientContext context,
Ample.DataLevel level, ExternalCompactionId ecid) {
try (var tablets = context.getAmple().readTablets().forLevel(level).fetch(ECOMP).build()) {
Optional<Map.Entry<ExternalCompactionId,CompactionMetadata>> ecomp =
tablets.stream().flatMap(tm -> tm.getExternalCompactions().entrySet().stream())
.filter(e -> e.getKey().equals(ecid)).findFirst();
return ecomp.map(entry -> HostAndPort.fromString(entry.getValue().getCompactorId()));
} catch (Exception e) {
throw new IllegalStateException("Exception calling cancel compaction for " + ecid, e);
}
}

}
Loading