Skip to content

Commit fc72fe8

Browse files
committed
HADOOP-19052.Hadoop use Shell command to get the count of the hard link which takes a lot of time
1 parent f810715 commit fc72fe8

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/HardLink.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ public static void createHardLinkMult(File parentDir, String[] fileBaseNames,
209209
parentDir.toPath().resolve(name));
210210
}
211211
}
212+
@VisibleForTesting
213+
static boolean supportsHardLink(File f) {
214+
try {
215+
FileStore store = Files.getFileStore(f.toPath());
216+
return store.supportsFileAttributeView(FileAttributeView);
217+
} catch (IOException e) {
218+
return false;
219+
}
220+
}
212221

213222
/**
214223
* Retrieves the number of links to the specified file.
@@ -226,7 +235,7 @@ public static int getLinkCount(File fileName) throws IOException {
226235
throw new FileNotFoundException(fileName + " not found.");
227236
}
228237

229-
if (Files.getFileStore(fileName.toPath()).supportsFileAttributeView(FileAttributeView)) {
238+
if (supportsHardLink(fileName)) {
230239
return (int) Files.getAttribute(fileName.toPath(), FileAttribute);
231240
}
232241

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestHardLink.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,7 @@ private String fetchFileContents(File file)
207207
return new String(result);
208208
}
209209

210-
private boolean supportsHardLink(File f) {
211-
try {
212-
FileStore store = Files.getFileStore(f.toPath());
213-
return store.supportsFileAttributeView("unix");
214-
} catch (IOException e) {
215-
return false;
216-
}
217-
}
210+
218211

219212
/**
220213
* Sanity check the simplest case of HardLink.getLinkCount()

0 commit comments

Comments
 (0)