[
https://issues.apache.org/jira/browse/HADOOP-18340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17577550#comment-17577550
]
ASF GitHub Bot commented on HADOOP-18340:
-----------------------------------------
steveloughran commented on code in PR #4608:
URL: https://github.com/apache/hadoop/pull/4608#discussion_r940572367
##########
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3ADeleteOnExit.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.fs.s3a;
+
+import org.junit.Test;
+
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.contract.ContractTestUtils;
+import org.apache.hadoop.io.IOUtils;
+
+/**
+ * Test deleteOnExit for S3A.
+ * The following cases for deleteOnExit are tested:
+ * 1. A nonexist file, which is added to deleteOnExit set.
+ * 2. An existing file
+ * 3. A file is added to deleteOnExist set first, then created.
+ * 4. A directory with some files under it.
+ */
+public class ITestS3ADeleteOnExit extends AbstractS3ATestBase {
+
+ private static final String PARENT_DIR_PATH_STR = "testDeleteOnExitDir";
+ private static final String NON_EXIST_FILE_PATH_STR =
+ PARENT_DIR_PATH_STR + "/nonExistFile";
+ private static final String INORDER_FILE_PATH_STR =
+ PARENT_DIR_PATH_STR + "/inOrderFile";
+ private static final String OUT_OF_ORDER_FILE_PATH_STR =
+ PARENT_DIR_PATH_STR + "/outOfOrderFile";
+ private static final String SUBDIR_PATH_STR =
+ PARENT_DIR_PATH_STR + "/subDir";
+ private static final String FILE_UNDER_SUBDIR_PATH_STR =
+ SUBDIR_PATH_STR + "/subDirFile";
+
+ @Test
+ public void testDeleteOnExit() throws Exception {
+ FileSystem fs = getFileSystem();
+
+ // Get a new filesystem object which is same as fs.
+ FileSystem s3aFs = new S3AFileSystem();
+ s3aFs.initialize(fs.getUri(), fs.getConf());
+ Path nonExistFilePath = path(NON_EXIST_FILE_PATH_STR);
+ Path inOrderFilePath = path(INORDER_FILE_PATH_STR);
+ Path outOfOrderFilePath = path(OUT_OF_ORDER_FILE_PATH_STR);
+ Path subDirPath = path(SUBDIR_PATH_STR);
+ Path fileUnderSubDirPath = path(FILE_UNDER_SUBDIR_PATH_STR);
+ // 1. set up the test directory.
+ Path dir = path("testDeleteOnExitDir");
+ s3aFs.mkdirs(dir);
+
+ // 2. Add a nonexisting file to DeleteOnExit set.
+ s3aFs.deleteOnExit(nonExistFilePath);
+ ContractTestUtils.assertPathDoesNotExist(s3aFs,
+ "File " + NON_EXIST_FILE_PATH_STR + " should not exist",
nonExistFilePath);
+
+ // 3. create a file and then add it to DeleteOnExit set.
+ FSDataOutputStream stream = s3aFs.create(inOrderFilePath, true);
+ byte[] data = ContractTestUtils.dataset(16, 'a', 26);
+ try {
+ stream.write(data);
+ } finally {
+ IOUtils.closeStream(stream);
+ }
+
+ ContractTestUtils.assertPathExists(s3aFs,
+ "File " + INORDER_FILE_PATH_STR + " should exist",
inOrderFilePath);
+
+ s3aFs.deleteOnExit(inOrderFilePath);
+
+ // 4. add a path to DeleteOnExit set first, then create it.
+ s3aFs.deleteOnExit(outOfOrderFilePath);
+ stream = s3aFs.create(outOfOrderFilePath, true);
+ try {
+ stream.write(data);
+ } finally {
+ IOUtils.closeStream(stream);
+ }
+
+ ContractTestUtils.assertPathExists(s3aFs,
+ "File " + OUT_OF_ORDER_FILE_PATH_STR + " should exist",
outOfOrderFilePath);
+
+ // 5. create a subdirectory, a file under it, and add subdirectory
DeleteOnExit set.
+ s3aFs.mkdirs(subDirPath);
+ s3aFs.deleteOnExit(subDirPath);
+
+ stream = s3aFs.create(fileUnderSubDirPath, true);
+ try {
Review Comment:
same thing
> deleteOnExit does not work with S3AFileSystem
> ---------------------------------------------
>
> Key: HADOOP-18340
> URL: https://issues.apache.org/jira/browse/HADOOP-18340
> Project: Hadoop Common
> Issue Type: Bug
> Components: fs/s3
> Affects Versions: 3.3.3
> Reporter: Huaxiang Sun
> Priority: Minor
> Labels: pull-request-available
> Time Spent: 2h 40m
> Remaining Estimate: 0h
>
> When deleteOnExit is set on some paths, they are not removed when file system
> object is closed. The following exception is logged when printing out the
> exception in info log.
> {code:java}
> 2022-07-15 19:29:12,552 [main] INFO fs.FileSystem
> (FileSystem.java:processDeleteOnExit(1810)) - Ignoring failure to
> deleteOnExit for path /file, exception {}
> java.io.IOException: s3a://mock-bucket: FileSystem is closed!
> at
> org.apache.hadoop.fs.s3a.S3AFileSystem.checkNotClosed(S3AFileSystem.java:3887)
> at
> org.apache.hadoop.fs.s3a.S3AFileSystem.trackDurationAndSpan(S3AFileSystem.java:2333)
> at
> org.apache.hadoop.fs.s3a.S3AFileSystem.trackDurationAndSpan(S3AFileSystem.java:2355)
> at
> org.apache.hadoop.fs.s3a.S3AFileSystem.exists(S3AFileSystem.java:4402)
> at
> org.apache.hadoop.fs.FileSystem.processDeleteOnExit(FileSystem.java:1805)
> at org.apache.hadoop.fs.FileSystem.close(FileSystem.java:2669)
> at
> org.apache.hadoop.fs.s3a.S3AFileSystem.close(S3AFileSystem.java:3830)
> at
> org.apache.hadoop.fs.s3a.TestS3AGetFileStatus.testFile(TestS3AGetFileStatus.java:87)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
> at
> org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:258)
> at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
> at
> org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
> at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
> at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
> at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
> at
> org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
> at
> org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273)
> at
> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
> at
> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
> at
> org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
> at
> org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
> at
> org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
> at
> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]