errose28 commented on code in PR #7981:
URL: https://github.com/apache/ozone/pull/7981#discussion_r1989895457
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/replication/TestReplicationSupervisor.java:
##########
@@ -327,6 +347,108 @@ public void
testDownloadAndImportReplicatorFailure(ContainerLayoutVersion layout
.contains("Container 1 replication was unsuccessful.");
}
+ @ContainerLayoutTestInfo.ContainerTest
+ public void testReplicationImportReserveSpace(ContainerLayoutVersion layout)
+ throws IOException, InterruptedException, TimeoutException {
+ this.layoutVersion = layout;
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.set(ScmConfigKeys.HDDS_DATANODE_DIR_KEY, tempDir.getAbsolutePath());
+
+ long containerSize = (long) conf.getStorageSize(
+ ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE,
+ ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT, StorageUnit.BYTES);
+
+ ReplicationSupervisor supervisor = ReplicationSupervisor.newBuilder()
+ .stateContext(context)
+ .executor(newDirectExecutorService())
+ .clock(clock)
+ .build();
+
+ long containerId = 1;
+ // create container
+ KeyValueContainerData containerData = new
KeyValueContainerData(containerId,
+ ContainerLayoutVersion.FILE_PER_BLOCK, 100, "test", "test");
+ KeyValueContainer container = new KeyValueContainer(containerData, conf);
+ ContainerController controllerMock = mock(ContainerController.class);
+ Semaphore semaphore = new Semaphore(1);
+ when(controllerMock.importContainer(any(), any(), any()))
+ .thenAnswer((invocation) -> {
+ semaphore.acquire();
+ return container;
+ });
+ MutableVolumeSet volumeSet = new
MutableVolumeSet(datanode.getUuidString(), conf, null,
+ StorageVolume.VolumeType.DATA_VOLUME, null);
+ File tarFile = containerTarFile(containerId, containerData);
+
+ SimpleContainerDownloader moc =
+ mock(SimpleContainerDownloader.class);
+ when(
+ moc.getContainerDataFromReplicas(anyLong(), anyList(),
+ any(Path.class), any()))
+ .thenReturn(tarFile.toPath());
+
+ ContainerImporter importer =
+ new ContainerImporter(conf, set, controllerMock, volumeSet);
+
+ HddsVolume vol1 = (HddsVolume) volumeSet.getVolumesList().get(0);
+ // Increase committed bytes so that volume has only remaining 3 times
container size space
+ vol1.incCommittedBytes(vol1.getCurrentUsage().getCapacity() -
containerSize * 3);
+ ContainerReplicator replicator =
+ new DownloadAndImportReplicator(conf, set, importer, moc);
+ replicatorRef.set(replicator);
+
+ GenericTestUtils.LogCapturer logCapturer = GenericTestUtils.LogCapturer
+ .captureLogs(DownloadAndImportReplicator.LOG);
+
+ // Acquire semaphore so that container import will pause after reserving
space.
+ semaphore.acquire();
+ CompletableFuture.runAsync(() -> {
+ try {
+ supervisor.addTask(createTask(containerId));
+ } catch (Exception ex) {
+ }
+ });
+
+ // Wait such that first container import reserve space
+ GenericTestUtils.waitFor(() ->
+ vol1.getCommittedBytes() > vol1.getCurrentUsage().getCapacity() -
containerSize * 3,
Review Comment:
The space should be moved from committed to used after this. Can we add a
test for this?
--
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]