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 @@ -44,6 +44,7 @@
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -52,6 +53,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -472,7 +474,7 @@ private IterationResult doIteration() {
findTargetStrategy.reInitialize(potentialTargets, config, upperLimit);
findSourceStrategy.reInitialize(getPotentialSources(), config, lowerLimit);

moveSelectionToFutureMap = new HashMap<>(underUtilizedNodes.size() + overUtilizedNodes.size());
moveSelectionToFutureMap = new ConcurrentHashMap<>();
boolean isMoveGeneratedInThisIteration = false;
iterationResult = IterationResult.ITERATION_COMPLETED;
boolean canAdaptWhenNearingLimits = true;
Expand Down Expand Up @@ -598,21 +600,25 @@ private void checkIterationResults(boolean isMoveGeneratedInThisIteration) {
*/
private void checkIterationMoveResults() {
this.countDatanodesInvolvedPerIteration = 0;
CompletableFuture<Void> allFuturesResult = CompletableFuture.allOf(
moveSelectionToFutureMap.values()
.toArray(new CompletableFuture[moveSelectionToFutureMap.size()]));
try {
allFuturesResult.get(config.getMoveTimeout().toMillis(),
TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
LOG.warn("Container balancer is interrupted");
Thread.currentThread().interrupt();
} catch (TimeoutException e) {
long timeoutCounts = cancelMovesThatExceedTimeoutDuration();
LOG.warn("{} Container moves are canceled.", timeoutCounts);
metrics.incrementNumContainerMovesTimeoutInLatestIteration(timeoutCounts);
} catch (ExecutionException e) {
LOG.error("Got exception while checkIterationMoveResults", e);
Collection<CompletableFuture<MoveManager.MoveResult>> futures =
moveSelectionToFutureMap.values();
if (!futures.isEmpty()) {
CompletableFuture<Void> allFuturesResult = CompletableFuture.allOf(
futures.toArray(new CompletableFuture[futures.size()]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intellij recommends changing this to

CompletableFuture.allOf(
          futures.toArray(new CompletableFuture[0]));

try {
allFuturesResult.get(config.getMoveTimeout().toMillis(),
TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
LOG.warn("Container balancer is interrupted");
Thread.currentThread().interrupt();
} catch (TimeoutException e) {
long timeoutCounts = cancelMovesThatExceedTimeoutDuration();
LOG.warn("{} Container moves are canceled.", timeoutCounts);
metrics.incrementNumContainerMovesTimeoutInLatestIteration(
timeoutCounts);
} catch (ExecutionException e) {
LOG.error("Got exception while checkIterationMoveResults", e);
}
}

countDatanodesInvolvedPerIteration =
Expand Down Expand Up @@ -828,6 +834,7 @@ private boolean moveContainer(DatanodeDetails source,

future = future.whenComplete((result, ex) -> {
metrics.incrementCurrentIterationContainerMoveMetric(result, 1);
moveSelectionToFutureMap.remove(moveSelection);
if (ex != null) {
LOG.info("Container move for container {} from source {} to " +
"target {} failed with exceptions.",
Expand Down Expand Up @@ -883,7 +890,6 @@ private boolean moveContainer(DatanodeDetails source,
return false;
} else {
MoveManager.MoveResult result = future.join();
moveSelectionToFutureMap.put(moveSelection, future);
if (result == MoveManager.MoveResult.REPLICATION_FAIL_NOT_EXIST_IN_SOURCE ||
result == MoveManager.MoveResult.REPLICATION_FAIL_EXIST_IN_TARGET ||
result == MoveManager.MoveResult.REPLICATION_FAIL_CONTAINER_NOT_CLOSED ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.scm.container.ContainerID;

import java.util.Objects;

/**
* This class represents a target datanode and the container to be moved from
* a source to that target.
Expand Down Expand Up @@ -52,4 +54,24 @@ public void setContainerID(
ContainerID containerID) {
this.containerID = containerID;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ContainerMoveSelection that = (ContainerMoveSelection) o;
if (targetNode != that.targetNode) {
return false;
}
return containerID == that.containerID;
}

@Override
public int hashCode() {
return Objects.hash(targetNode, containerID);
}
}