Skip to content

Commit c798aac

Browse files
authored
fix fs close return cache and control symbolic in listStatus (#105)
Co-authored-by: alantong(佟明达) <[email protected]>
1 parent c083016 commit c798aac

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.qcloud.cos</groupId>
88
<artifactId>hadoop-cos</artifactId>
9-
<version>8.2.3</version>
9+
<version>8.2.4</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Apache Hadoop Tencent Cloud COS Support</name>

src/main/java/org/apache/hadoop/fs/CosFileSystem.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.HashMap;
2525
import java.util.List;
2626
import java.util.Map;
27+
import java.util.concurrent.atomic.AtomicBoolean;
2728

2829
import static org.apache.hadoop.fs.CosNUtils.propagateBucketOptions;
2930

@@ -54,6 +55,7 @@ public class CosFileSystem extends FileSystem {
5455
private boolean isPosixUseOFSRanger;
5556
private boolean isPosixImpl = false;
5657
private FileSystem actualImplFS = null;
58+
private final AtomicBoolean closed = new AtomicBoolean(false);
5759

5860
private URI uri;
5961
private Path workingDir;
@@ -126,8 +128,9 @@ public void initialize(URI uri, Configuration originalConf) throws IOException {
126128
this.actualImplFS = getActualFileSystemByClassName(posixBucketFSImpl);
127129

128130
// judge normal impl first, skip the class nodef error when only use normal bucket
131+
// outside can use native store to tell whether is posix bucket, not need head bucket twice. can be used by flink cos.
132+
this.nativeStore.setPosixBucket(true);
129133
if (this.actualImplFS instanceof CosNFileSystem) {
130-
this.nativeStore.setPosixBucket(true);
131134
((CosNFileSystem) this.actualImplFS).withStore(this.nativeStore).withBucket(bucket)
132135
.withPosixBucket(isPosixFSStore).withRangerCredentialsClient(rangerCredentialsClient);
133136
} else if (this.actualImplFS instanceof CHDFSHadoopFileSystemAdapter) {
@@ -656,11 +659,19 @@ private void checkInitialized() throws IOException {
656659
@Override
657660
public void close() throws IOException {
658661
LOG.info("begin to close cos file system");
659-
this.actualImplFS.close();
660-
if (null != this.nativeStore && this.isDefaultNativeStore) {
661-
// close range client later, inner native store
662-
this.nativeStore.close();
662+
if (this.closed.getAndSet(true)) {
663+
// already closed
664+
return;
663665
}
664666
this.initialized = false;
667+
try {
668+
super.close();
669+
} finally {
670+
this.actualImplFS.close();
671+
if (null != this.nativeStore && this.isDefaultNativeStore) {
672+
// close range client later, inner native store
673+
this.nativeStore.close();
674+
}
675+
}
665676
}
666677
}

src/main/java/org/apache/hadoop/fs/CosNFileSystem.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ public FileStatus[] listStatus(Path f) throws IOException {
662662
LOG.debug("This is just the directory we have been asked to list. cos key: {}.",
663663
fileMetadata.getKey());
664664
} else {
665-
if (fileMetadata.getLength() < this.symbolicLinkSizeThreshold) {
665+
if (this.supportsSymlinks() && fileMetadata.getLength() < this.symbolicLinkSizeThreshold) {
666666
CosNSymlinkMetadata cosNSymlinkMetadata = this.nativeStore.retrieveSymlinkMetadata(
667667
fileMetadata.getKey());
668668
if (null != cosNSymlinkMetadata) {

0 commit comments

Comments
 (0)