forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-35770][s3] Make s5cmd copyFiles interruptable through Closeabl…
…eRegistry to improve job cancellation behavior during restore.
- Loading branch information
1 parent
4faf096
commit 9b67415
Showing
5 changed files
with
196 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
...s/flink-s3-fs-base/src/test/java/org/apache/flink/fs/s3/common/FlinkS3FileSystemTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* 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.flink.fs.s3.common; | ||
|
||
import org.apache.flink.configuration.Configuration; | ||
import org.apache.flink.core.fs.CloseableRegistry; | ||
import org.apache.flink.core.fs.ICloseableRegistry; | ||
import org.apache.flink.core.fs.Path; | ||
import org.apache.flink.core.fs.PathsCopyingFileSystem; | ||
import org.apache.flink.util.Preconditions; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.DisabledOnOs; | ||
import org.junit.jupiter.api.condition.OS; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import java.io.Closeable; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.nio.charset.Charset; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static org.apache.flink.fs.s3.common.AbstractS3FileSystemFactory.ACCESS_KEY; | ||
import static org.apache.flink.fs.s3.common.AbstractS3FileSystemFactory.ENDPOINT; | ||
import static org.apache.flink.fs.s3.common.AbstractS3FileSystemFactory.S5CMD_EXTRA_ARGS; | ||
import static org.apache.flink.fs.s3.common.AbstractS3FileSystemFactory.S5CMD_PATH; | ||
import static org.apache.flink.fs.s3.common.AbstractS3FileSystemFactory.SECRET_KEY; | ||
|
||
/** Unit tests for FlinkS3FileSystem. */ | ||
class FlinkS3FileSystemTest { | ||
@TempDir public static File temporaryDirectory; | ||
|
||
@Test | ||
@DisabledOnOs({OS.WINDOWS, OS.OTHER}) // OS must support SLEEP command | ||
public void testCopyCommandInterruptible() throws Exception { | ||
|
||
File cmdFile = new File(temporaryDirectory, "cmd"); | ||
|
||
FileUtils.writeStringToFile(cmdFile, "sleep 1000", Charset.defaultCharset()); | ||
|
||
Preconditions.checkState(cmdFile.setExecutable(true), "Cannot set script file executable."); | ||
|
||
final Configuration conf = new Configuration(); | ||
conf.set(S5CMD_PATH, cmdFile.getAbsolutePath()); | ||
conf.set(S5CMD_EXTRA_ARGS, ""); | ||
conf.set(ACCESS_KEY, "test-access-key"); | ||
conf.set(SECRET_KEY, "test-secret-key"); | ||
conf.set(ENDPOINT, "test-endpoint"); | ||
|
||
TestS3FileSystemFactory factory = new TestS3FileSystemFactory(); | ||
factory.configure(conf); | ||
|
||
FlinkS3FileSystem fs = (FlinkS3FileSystem) factory.create(new URI("s3://test")); | ||
|
||
AtomicReference<IOException> actualException = new AtomicReference<>(); | ||
CountDownLatch registerLatch = new CountDownLatch(1); | ||
ICloseableRegistry closeableRegistry = | ||
new CloseableRegistry() { | ||
@Override | ||
protected void doRegister( | ||
@Nonnull Closeable closeable, | ||
@Nonnull Map<Closeable, Object> closeableMap) { | ||
super.doRegister(closeable, closeableMap); | ||
registerLatch.countDown(); | ||
} | ||
}; | ||
|
||
Thread thread = | ||
new Thread( | ||
() -> { | ||
try { | ||
fs.copyFiles( | ||
Collections.singletonList( | ||
new PathsCopyingFileSystem.CopyTask( | ||
Path.fromLocalFile(new File("")), | ||
Path.fromLocalFile(new File("")))), | ||
closeableRegistry); | ||
} catch (IOException ex) { | ||
actualException.set(ex); | ||
} | ||
}); | ||
|
||
thread.start(); | ||
registerLatch.await(); | ||
closeableRegistry.close(); | ||
thread.join(60_000L); | ||
Assertions.assertThat(thread.isAlive()).isFalse(); | ||
Assertions.assertThat(actualException.get()) | ||
.hasStackTraceContaining("Copy process destroyed by CloseableRegistry."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...flink-s3-fs-base/src/test/java/org/apache/flink/fs/s3/common/TestS3FileSystemFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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.flink.fs.s3.common; | ||
|
||
import org.apache.flink.fs.s3.common.writer.S3AccessHelper; | ||
import org.apache.flink.runtime.util.HadoopConfigLoader; | ||
|
||
import org.apache.hadoop.fs.FileSystem; | ||
import org.mockito.Mockito; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import java.net.URI; | ||
import java.util.Collections; | ||
|
||
final class TestS3FileSystemFactory extends AbstractS3FileSystemFactory { | ||
|
||
TestS3FileSystemFactory() { | ||
super( | ||
"testFs", | ||
new HadoopConfigLoader( | ||
new String[0], | ||
new String[0][], | ||
"", | ||
Collections.emptySet(), | ||
Collections.emptySet(), | ||
"")); | ||
} | ||
|
||
@Override | ||
protected org.apache.hadoop.fs.FileSystem createHadoopFileSystem() { | ||
return Mockito.mock(org.apache.hadoop.fs.FileSystem.class); | ||
} | ||
|
||
@Override | ||
protected URI getInitURI(URI fsUri, org.apache.hadoop.conf.Configuration hadoopConfig) { | ||
return fsUri; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
protected S3AccessHelper getS3AccessHelper(FileSystem fs) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getScheme() { | ||
return "test"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters