adoroszlai commented on code in PR #8550:
URL: https://github.com/apache/ozone/pull/8550#discussion_r2147188087
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/replication/TestContainerImporter.java:
##########
@@ -187,6 +194,37 @@ public void
testInconsistentChecksumContainerShouldThrowError() throws Exception
contains("Container checksum error"));
}
+ @Test
+ public void testImportContainerTriggersOnDemandScanner() throws Exception {
+ long containerId = 1;
+ try (MockedStatic<OnDemandContainerDataScanner> mockedStatic =
mockStatic(OnDemandContainerDataScanner.class)) {
+ // 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);
+ when(controllerMock.importContainer(any(), any(),
any())).thenReturn(container);
+
+ // create containerImporter object
+ ContainerSet containerSet = newContainerSet(0);
+ MutableVolumeSet volumeSet = new MutableVolumeSet("test", conf, null,
+ StorageVolume.VolumeType.DATA_VOLUME, null);
+ HddsVolume targetVolume = mock(HddsVolume.class);
+ doNothing().when(targetVolume).incrementUsedSpace(anyLong());
+ ContainerImporter containerImporter = new ContainerImporter(conf,
+ containerSet, controllerMock, volumeSet, volumeChoosingPolicy);
+
+ // import the container
+ File tarFile = containerTarFile(containerId, containerData);
+ containerImporter.importContainer(containerId, tarFile.toPath(),
+ targetVolume, NO_COMPRESSION);
Review Comment:
Pleasse reduce duplication, most of this is the same as in other tests.
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/replication/ContainerImporter.java:
##########
@@ -120,9 +123,15 @@ public void importContainer(long containerID, Path
tarFilePath,
try (InputStream input = Files.newInputStream(tarFilePath)) {
Container container = controller.importContainer(
containerData, input, packer);
- // After container import is successful, increase used space for the
volume
+ // After container import is successful, increase used space for the
volume and schedule an OnDemand scan for it
targetVolume.incrementUsedSpace(container.getContainerData().getBytesUsed());
containerSet.addContainerByOverwriteMissingContainer(container);
+ Optional<Future<?>> scanFuture =
OnDemandContainerDataScanner.scanContainer(container);
+ if (scanFuture.isPresent()) {
+ LOG.info("Scheduled on-demand scan for imported container {}",
containerID);
+ } else {
+ LOG.debug("Skipped on-demand scan for imported container {}",
containerID);
+ }
Review Comment:
- `scanContainer` should log whether it triggered a scan or not, so that
callers do not need to repeat this logic
- add a parameter to indicate the reason ("import" in this case) to let
`scanContainer` include it in the log
--
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]