Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-11386. Multithreading bug in ContainerBalancerTask #7339

Merged
merged 6 commits into from
Nov 25, 2024
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 @@ -32,11 +32,11 @@
import org.slf4j.Logger;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
Expand All @@ -56,7 +56,7 @@ protected AbstractFindTargetGreedy(
ContainerManager containerManager,
PlacementPolicyValidateProxy placementPolicyValidateProxy,
NodeManager nodeManager) {
sizeEnteringNode = new HashMap<>();
sizeEnteringNode = new ConcurrentHashMap<>();
this.containerManager = containerManager;
this.placementPolicyValidateProxy = placementPolicyValidateProxy;
this.nodeManager = nodeManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -117,7 +118,7 @@ public class ContainerBalancerTask implements Runnable {
private IterationResult iterationResult;
private int nextIterationIndex;
private boolean delayStart;
private List<ContainerBalancerTaskIterationStatusInfo> iterationsStatistic;
private Queue<ContainerBalancerTaskIterationStatusInfo> iterationsStatistic;

/**
* Constructs ContainerBalancerTask with the specified arguments.
Expand Down Expand Up @@ -166,7 +167,7 @@ public ContainerBalancerTask(StorageContainerManager scm,
findTargetStrategy = new FindTargetGreedyByUsageInfo(containerManager,
placementPolicyValidateProxy, nodeManager);
}
this.iterationsStatistic = new ArrayList<>();
this.iterationsStatistic = new ConcurrentLinkedQueue<>();
}

/**
Expand Down Expand Up @@ -308,43 +309,42 @@ private void balance() {

private void saveIterationStatistic(Integer iterationNumber, IterationResult iR) {
ContainerBalancerTaskIterationStatusInfo iterationStatistic = new ContainerBalancerTaskIterationStatusInfo(
iterationNumber,
iR.name(),
getSizeScheduledForMoveInLatestIteration() / OzoneConsts.GB,
metrics.getDataSizeMovedGBInLatestIteration(),
metrics.getNumContainerMovesScheduledInLatestIteration(),
metrics.getNumContainerMovesCompletedInLatestIteration(),
metrics.getNumContainerMovesFailedInLatestIteration(),
metrics.getNumContainerMovesTimeoutInLatestIteration(),
findTargetStrategy.getSizeEnteringNodes()
.entrySet()
.stream()
.filter(Objects::nonNull)
.filter(datanodeDetailsLongEntry -> datanodeDetailsLongEntry.getValue() > 0)
.collect(
Collectors.toMap(
entry -> entry.getKey().getUuid(),
entry -> entry.getValue() / OzoneConsts.GB
)
),
findSourceStrategy.getSizeLeavingNodes()
.entrySet()
.stream()
.filter(Objects::nonNull)
.filter(datanodeDetailsLongEntry -> datanodeDetailsLongEntry.getValue() > 0)
.collect(
Collectors.toMap(
entry -> entry.getKey().getUuid(),
entry -> entry.getValue() / OzoneConsts.GB
)
)
iterationNumber,
iR.name(),
getSizeScheduledForMoveInLatestIteration() / OzoneConsts.GB,
metrics.getDataSizeMovedGBInLatestIteration(),
metrics.getNumContainerMovesScheduledInLatestIteration(),
metrics.getNumContainerMovesCompletedInLatestIteration(),
metrics.getNumContainerMovesFailedInLatestIteration(),
metrics.getNumContainerMovesTimeoutInLatestIteration(),
findTargetStrategy.getSizeEnteringNodes()
.entrySet()
.stream()
.filter(datanodeDetailsLongEntry -> datanodeDetailsLongEntry.getValue() > 0)
.collect(
Collectors.toMap(
entry -> entry.getKey().getUuid(),
entry -> entry.getValue() / OzoneConsts.GB
)
),
findSourceStrategy.getSizeLeavingNodes()
.entrySet()
.stream()
.filter(datanodeDetailsLongEntry -> datanodeDetailsLongEntry.getValue() > 0)
.collect(
Collectors.toMap(
entry -> entry.getKey().getUuid(),
entry -> entry.getValue() / OzoneConsts.GB
)
)
);
iterationsStatistic.add(iterationStatistic);
iterationsStatistic.offer(iterationStatistic);
}

public List<ContainerBalancerTaskIterationStatusInfo> getCurrentIterationsStatistic() {
List<ContainerBalancerTaskIterationStatusInfo> resultList = new ArrayList<>(iterationsStatistic);

int lastIterationNumber = iterationsStatistic.stream()
int lastIterationNumber = resultList.stream()
.mapToInt(ContainerBalancerTaskIterationStatusInfo::getIterationNumber)
.max()
.orElse(0);
Expand All @@ -361,17 +361,16 @@ public List<ContainerBalancerTaskIterationStatusInfo> getCurrentIterationsStatis
findTargetStrategy.getSizeEnteringNodes()
.entrySet()
.stream()
.filter(Objects::nonNull)
.filter(datanodeDetailsLongEntry -> datanodeDetailsLongEntry.getValue() > 0)
.collect(Collectors.toMap(
.collect(
Collectors.toMap(
entry -> entry.getKey().getUuid(),
entry -> entry.getValue() / OzoneConsts.GB
)
),
findSourceStrategy.getSizeLeavingNodes()
.entrySet()
.stream()
.filter(Objects::nonNull)
.filter(datanodeDetailsLongEntry -> datanodeDetailsLongEntry.getValue() > 0)
.collect(
Collectors.toMap(
Expand All @@ -380,7 +379,6 @@ public List<ContainerBalancerTaskIterationStatusInfo> getCurrentIterationsStatis
)
)
);
List<ContainerBalancerTaskIterationStatusInfo> resultList = new ArrayList<>(iterationsStatistic);
resultList.add(currentIterationStatistic);
return resultList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
* The selection criteria for selecting source datanodes , the containers of
Expand All @@ -46,7 +46,7 @@ public class FindSourceGreedy implements FindSourceStrategy {
private Double lowerLimit;

FindSourceGreedy(NodeManager nodeManager) {
sizeLeavingNode = new HashMap<>();
sizeLeavingNode = new ConcurrentHashMap<>();
potentialSources = new PriorityQueue<>((a, b) -> {
double currentUsageOfA = a.calculateUtilization(
-sizeLeavingNode.get(a.getDatanodeDetails()));
Expand Down
Loading