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
Changes from 3 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 @@ -117,7 +117,7 @@ public class ContainerBalancerTask implements Runnable {
private IterationResult iterationResult;
private int nextIterationIndex;
private boolean delayStart;
private List<ContainerBalancerTaskIterationStatusInfo> iterationsStatistic;
private final List<ContainerBalancerTaskIterationStatusInfo> iterationsStatistic;

/**
* Constructs ContainerBalancerTask with the specified arguments.
Expand Down Expand Up @@ -344,45 +344,47 @@ private void saveIterationStatistic(Integer iterationNumber, IterationResult iR)

public List<ContainerBalancerTaskIterationStatusInfo> getCurrentIterationsStatistic() {

int lastIterationNumber = iterationsStatistic.stream()
.mapToInt(ContainerBalancerTaskIterationStatusInfo::getIterationNumber)
.max()
.orElse(0);

ContainerBalancerTaskIterationStatusInfo currentIterationStatistic = new ContainerBalancerTaskIterationStatusInfo(
lastIterationNumber + 1,
null,
getSizeScheduledForMoveInLatestIteration() / OzoneConsts.GB,
sizeActuallyMovedInLatestIteration / OzoneConsts.GB,
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
)
)
);
List<ContainerBalancerTaskIterationStatusInfo> resultList = new ArrayList<>(iterationsStatistic);
resultList.add(currentIterationStatistic);
return resultList;
synchronized (iterationsStatistic) {
sarvekshayr marked this conversation as resolved.
Show resolved Hide resolved
int lastIterationNumber = iterationsStatistic.stream()
.mapToInt(ContainerBalancerTaskIterationStatusInfo::getIterationNumber)
.max()
.orElse(0);

ContainerBalancerTaskIterationStatusInfo currentIterationStatistic = new ContainerBalancerTaskIterationStatusInfo(
lastIterationNumber + 1,
null,
getSizeScheduledForMoveInLatestIteration() / OzoneConsts.GB,
sizeActuallyMovedInLatestIteration / OzoneConsts.GB,
metrics.getNumContainerMovesScheduledInLatestIteration(),
metrics.getNumContainerMovesCompletedInLatestIteration(),
metrics.getNumContainerMovesFailedInLatestIteration(),
metrics.getNumContainerMovesTimeoutInLatestIteration(),
new ConcurrentHashMap<>(findTargetStrategy.getSizeEnteringNodes())
.entrySet()
.stream()
.filter(Objects::nonNull)
.filter(datanodeDetailsLongEntry -> datanodeDetailsLongEntry.getValue() > 0)
.collect(Collectors.toMap(
entry -> entry.getKey().getUuid(),
entry -> entry.getValue() / OzoneConsts.GB
)
),
new ConcurrentHashMap<>(findSourceStrategy.getSizeLeavingNodes())
.entrySet()
.stream()
.filter(Objects::nonNull)
.filter(datanodeDetailsLongEntry -> datanodeDetailsLongEntry.getValue() > 0)
.collect(
Collectors.toMap(
entry -> entry.getKey().getUuid(),
entry -> entry.getValue() / OzoneConsts.GB
)
)
);
List<ContainerBalancerTaskIterationStatusInfo> resultList = new ArrayList<>(iterationsStatistic);
resultList.add(currentIterationStatistic);
return resultList;
}
}

/**
Expand Down