devmadhuu commented on code in PR #11965:
URL: https://github.com/apache/ozone/pull/11965#discussion_r4536618618
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/diskbalancer/DiskBalancerService.java:
##########
@@ -544,6 +544,11 @@ public BackgroundTaskResult call() {
LOG.warn("Container {} is in {} state, skipping move process.",
containerId, containerState);
return BackgroundTaskResult.EmptyTaskResult.newResult();
}
+ if (sourceVolume.getStorageType() != destVolume.getStorageType()) {
+ LOG.warn("Skipping disk balancing move for container {} from storage
type {} to {}",
Review Comment:
Done.
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/diskbalancer/TestDiskBalancerTask.java:
##########
@@ -285,6 +292,93 @@ public void cleanup() throws IOException {
DiskBalancerService.setInjector(null);
}
+ @ParameterizedTest
+ @CsvSource({"SSD, DISK", "DISK, SSD", "SSD, ARCHIVE", "ARCHIVE, SSD", "DISK,
ARCHIVE", "ARCHIVE, DISK"})
+ public void testCustomPolicyCannotMoveAcrossStorageTypes(StorageType
sourceType, StorageType destinationType)
+ throws IOException {
+ // Keep the real volumes and container files, overriding only their
configured type labels.
+ sourceVolume = spy(sourceVolume);
+ destVolume = spy(destVolume);
+ doReturn(sourceType).when(sourceVolume).getStorageType();
+ doReturn(destinationType).when(destVolume).getStorageType();
+ Container container = createContainer(CONTAINER_ID, sourceVolume,
State.CLOSED);
+ ContainerController controller = spy(ozoneContainer.getController());
+ when(ozoneContainer.getController()).thenReturn(controller);
+ byte[] originalYaml =
Files.readAllBytes(container.getContainerFile().toPath());
+ long sourceUsed = sourceVolume.getCurrentUsage().getUsedSpace();
+ long destUsed = destVolume.getCurrentUsage().getUsedSpace();
+ // Existing reservations and deltas must survive rejection of this
particular move.
+ destVolume.incCommittedBytes(42L);
+ long destCommitted = destVolume.getCommittedBytes();
+ diskBalancerService.getDeltaSizes().put(sourceVolume, 17L);
+ setCustomPolicyCandidate(container);
+
+ DiskBalancerService.DiskBalancerTask task = getTask();
+ assertNotNull(task);
+ assertEquals(destCommitted + CONTAINER_SIZE,
destVolume.getCommittedBytes());
+ assertEquals(17L - CONTAINER_SIZE,
diskBalancerService.getDeltaSizes().get(sourceVolume));
+
assertTrue(diskBalancerService.getInProgressContainers().contains(ContainerID.valueOf(CONTAINER_ID)));
+ task.call();
+
+ verify(controller, never()).copyContainer(any(), any());
+ assertSame(container, containerSet.getContainer(CONTAINER_ID));
+ assertSame(sourceVolume, container.getContainerData().getVolume());
+ assertEquals(State.CLOSED, container.getContainerState());
+ assertArrayEquals(originalYaml,
Files.readAllBytes(container.getContainerFile().toPath()));
+
assertFalse(Files.exists(destVolume.getTmpDir().toPath().resolve(DISK_BALANCER_DIR)
+ .resolve(String.valueOf(CONTAINER_ID))));
+ assertFalse(destVolume.getContainerIterator().hasNext());
+ assertEquals(sourceUsed, sourceVolume.getCurrentUsage().getUsedSpace());
+ assertEquals(destUsed, destVolume.getCurrentUsage().getUsedSpace());
+ assertEquals(destCommitted, destVolume.getCommittedBytes());
+ assertEquals(17L, diskBalancerService.getDeltaSizes().get(sourceVolume));
+
assertFalse(diskBalancerService.getInProgressContainers().contains(ContainerID.valueOf(CONTAINER_ID)));
+ assertEquals(1, diskBalancerService.getMetrics().getFailureCount());
+ assertEquals(0, diskBalancerService.getMetrics().getSuccessCount());
+ assertEquals(0, diskBalancerService.getMetrics().getSuccessBytes());
+ }
+
+ @ParameterizedTest
+ @EnumSource(names = {"DISK", "SSD", "ARCHIVE"})
+ public void
testCustomPolicySameTypeMovePreservesDifferentRecordedType(StorageType
volumeType) throws IOException {
Review Comment:
Added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]