Skip to content

Commit

Permalink
HDDS-11367. Fix review notice. Refactor saving iteration statistic.
Browse files Browse the repository at this point in the history
  • Loading branch information
juncevich committed Nov 25, 2024
1 parent 15a8558 commit 5d1932f
Showing 1 changed file with 39 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ private void balance() {
return;
}

IterationResult iR = doIteration();
saveIterationStatistic(i + 1, iR);
IterationResult currentIterationResult = doIteration();
ContainerBalancerTaskIterationStatusInfo iterationStatistic =
getIterationStatistic(i + 1, currentIterationResult, getCurrentIterationDuration());
iterationsStatistic.offer(iterationStatistic);

isCurrentIterationInProgress.compareAndSet(true, false);

Expand All @@ -284,17 +286,17 @@ private void balance() {

metrics.incrementNumIterations(1);

LOG.info("Result of this iteration of Container Balancer: {}", iR);
LOG.info("Result of this iteration of Container Balancer: {}", currentIterationResult);

// if no new move option is generated, it means the cluster cannot be
// balanced anymore; so just stop balancer
if (iR == IterationResult.CAN_NOT_BALANCE_ANY_MORE) {
tryStopWithSaveConfiguration(iR.toString());
if (currentIterationResult == IterationResult.CAN_NOT_BALANCE_ANY_MORE) {
tryStopWithSaveConfiguration(currentIterationResult.toString());
return;
}

// persist next iteration index
if (iR == IterationResult.ITERATION_COMPLETED) {
if (currentIterationResult == IterationResult.ITERATION_COMPLETED) {
try {
saveConfiguration(config, true, i + 1);
} catch (IOException | TimeoutException e) {
Expand Down Expand Up @@ -325,30 +327,45 @@ private void balance() {
tryStopWithSaveConfiguration("Completed all iterations.");
}

private void saveIterationStatistic(Integer iterationNumber, IterationResult currentIterationResult) {
long iterationDuration = now().toEpochSecond() - currentIterationStarted.toEpochSecond();
private ContainerBalancerTaskIterationStatusInfo getIterationStatistic(Integer iterationNumber,
IterationResult currentIterationResult,
long iterationDuration) {
String currentIterationResultName = currentIterationResult == null ? null : currentIterationResult.name();
Map<UUID, Long> sizeEnteringDataToNodes =
convertToNodeIdToTrafficMap(findTargetStrategy.getSizeEnteringNodes());
Map<UUID, Long> sizeLeavingDataFromNodes =
convertToNodeIdToTrafficMap(findSourceStrategy.getSizeLeavingNodes());
IterationInfo iterationInfo = new IterationInfo(
iterationNumber,
currentIterationResult.name(),
currentIterationResultName,
iterationDuration
);
ContainerMoveInfo containerMoveInfo = new ContainerMoveInfo(metrics);
DataMoveInfo dataMoveInfo = new DataMoveInfo(
getSizeScheduledForMoveInLatestIteration(),
metrics.getDataSizeMovedInLatestIteration(),
sizeEnteringDataToNodes,
sizeLeavingDataFromNodes
);
ContainerBalancerTaskIterationStatusInfo iterationStatistic = new ContainerBalancerTaskIterationStatusInfo(
iterationInfo,
containerMoveInfo,
dataMoveInfo
);
iterationsStatistic.offer(iterationStatistic);

DataMoveInfo dataMoveInfo =
getDataMoveInfo(currentIterationResultName, sizeEnteringDataToNodes, sizeLeavingDataFromNodes);
return new ContainerBalancerTaskIterationStatusInfo(iterationInfo, containerMoveInfo, dataMoveInfo);
}

private DataMoveInfo getDataMoveInfo(String currentIterationResultName, Map<UUID, Long> sizeEnteringDataToNodes,
Map<UUID, Long> sizeLeavingDataFromNodes) {
if (currentIterationResultName == null) {
// For unfinished iteration
return new DataMoveInfo(
getSizeScheduledForMoveInLatestIteration(),
sizeActuallyMovedInLatestIteration,
sizeEnteringDataToNodes,
sizeLeavingDataFromNodes
);
} else {
// For finished iteration
return new DataMoveInfo(
getSizeScheduledForMoveInLatestIteration(),
metrics.getDataSizeMovedInLatestIteration(),
sizeEnteringDataToNodes,
sizeLeavingDataFromNodes
);
}
}

private Map<UUID, Long> convertToNodeIdToTrafficMap(Map<DatanodeDetails, Long> nodeTrafficMap) {
Expand Down Expand Up @@ -388,7 +405,7 @@ private ContainerBalancerTaskIterationStatusInfo createCurrentIterationStatistic
long iterationDuration = getCurrentIterationDuration();

if (isCurrentIterationInProgress.get()) {
return getFilledCurrentIterationStatistic(lastIterationNumber, iterationDuration);
return getIterationStatistic(lastIterationNumber + 1, null, iterationDuration);
} else {
return null;
}
Expand Down

0 comments on commit 5d1932f

Please sign in to comment.