ChenSammi commented on code in PR #5978:
URL: https://github.com/apache/ozone/pull/5978#discussion_r1456849438
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java:
##########
@@ -175,11 +195,262 @@ public void testOBSRecoveryShouldFail() throws Exception
{
conf.get(OZONE_OM_ADDRESS_KEY));
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, rootPath);
- final String dir = OZONE_ROOT + bucket.getVolumeName() +
+ final String directory = OZONE_ROOT + bucket.getVolumeName() +
OZONE_URI_DELIMITER + bucket.getName();
- final Path file = new Path(dir, "file");
+ final Path f = new Path(directory, "file");
RootedOzoneFileSystem fs = (RootedOzoneFileSystem) FileSystem.get(conf);
- assertThrows(IllegalArgumentException.class, () -> fs.recoverLease(file));
+ assertThrows(IllegalArgumentException.class, () -> fs.recoverLease(f));
+ }
+
+ @Test
+ public void testFinalizeBlockFailure() throws Exception {
+ RootedOzoneFileSystem fs = (RootedOzoneFileSystem)FileSystem.get(conf);
+ int dataSize = 100;
+ final byte[] data = getData(dataSize);
+
+ final FSDataOutputStream stream = fs.create(file, true);
+ try {
+ stream.write(data);
+ stream.hsync();
+ assertFalse(fs.isFileClosed(file));
+
+ // write more data without hsync
+ stream.write(data);
+ stream.flush();
+
+ FaultInjectorImpl injector = new FaultInjectorImpl();
+ KeyValueHandler.setInjector(injector);
+ StorageContainerException sce = new StorageContainerException(
+ "Requested operation not allowed as ContainerState is CLOSED",
+ ContainerProtos.Result.CLOSED_CONTAINER_IO);
+ injector.setException(sce);
+ GenericTestUtils.LogCapturer logs =
+
GenericTestUtils.LogCapturer.captureLogs(BasicRootedOzoneClientAdapterImpl.LOG);
+
+ fs.recoverLease(file);
+ assertTrue(logs.getOutput().contains("Failed to execute finalizeBlock
command"));
+ assertTrue(logs.getOutput().contains("Requested operation not allowed as
ContainerState is CLOSED"));
+
+ // The lease should have been recovered.
+ assertTrue("File should be closed", fs.isFileClosed(file));
+ FileStatus fileStatus = fs.getFileStatus(file);
+ assertEquals(dataSize * 2, fileStatus.getLen());
+ } finally {
+ closeIgnoringKeyNotFound(stream);
+ }
+
+ // open it again, make sure the data is correct
+ verifyData(data, dataSize * 2, file, fs);
+ }
+
+ @Test
+ public void testBlockPipelineClosed() throws Exception {
+ RootedOzoneFileSystem fs = (RootedOzoneFileSystem)FileSystem.get(conf);
+ int dataSize = 100;
+ final byte[] data = getData(dataSize);
+
+ final FSDataOutputStream stream = fs.create(file, true);
+ try {
+ stream.write(data);
+ stream.hsync();
+ assertFalse(fs.isFileClosed(file));
+
+ // write more data without hsync
+ stream.write(data);
+ stream.flush();
+
+ // close the pipeline
+ StorageContainerManager scm = cluster.getStorageContainerManager();
+ ContainerInfo container =
scm.getContainerManager().getContainers().get(0);
+ OzoneTestUtils.closeContainer(scm, container);
+ GenericTestUtils.waitFor(() -> {
+ try {
+ return
scm.getPipelineManager().getPipeline(container.getPipelineID()).isClosed();
Review Comment:
Container closed before pipeline closed. So there is chance pipeline is
still OPEN when container is closed. The explicitly check here is to make sure
the pipeline is closed too.
--
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]