HDFS-13453. RBF: getMountPointDates should fetch latest subdir time/date when parent dir is not present but /parent/child dirs are present in mount table. Contributed by Dibyendu Karmakar.
(cherry picked from commit 1134af9ad1daf683204df8f95a8f03d7baaa74d4)
This commit is contained in:
parent
070bee57a3
commit
f8330d969d
@ -2284,18 +2284,11 @@ private boolean isPathReadOnly(final String path) {
|
|||||||
private Map<String, Long> getMountPointDates(String path) {
|
private Map<String, Long> getMountPointDates(String path) {
|
||||||
Map<String, Long> ret = new TreeMap<>();
|
Map<String, Long> ret = new TreeMap<>();
|
||||||
if (subclusterResolver instanceof MountTableResolver) {
|
if (subclusterResolver instanceof MountTableResolver) {
|
||||||
MountTableResolver mountTable = (MountTableResolver)subclusterResolver;
|
|
||||||
String srcPath;
|
|
||||||
try {
|
try {
|
||||||
final List<String> children = subclusterResolver.getMountPoints(path);
|
final List<String> children = subclusterResolver.getMountPoints(path);
|
||||||
for (String child : children) {
|
for (String child : children) {
|
||||||
if (path.equals(Path.SEPARATOR)) {
|
Long modTime = getModifiedTime(ret, path, child);
|
||||||
srcPath = Path.SEPARATOR + child;
|
ret.put(child, modTime);
|
||||||
} else {
|
|
||||||
srcPath = path + Path.SEPARATOR + child;
|
|
||||||
}
|
|
||||||
MountTable entry = mountTable.getMountPoint(srcPath);
|
|
||||||
ret.put(child, entry.getDateModified());
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.error("Cannot get mount point", e);
|
LOG.error("Cannot get mount point", e);
|
||||||
@ -2304,6 +2297,50 @@ private Map<String, Long> getMountPointDates(String path) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get modified time for child. If the child is present in mount table it
|
||||||
|
* will return the modified time. If the child is not present but subdirs of
|
||||||
|
* this child are present then it will return latest modified subdir's time
|
||||||
|
* as modified time of the requested child.
|
||||||
|
* @param ret contains children and modified times.
|
||||||
|
* @param mountTable.
|
||||||
|
* @param path Name of the path to start checking dates from.
|
||||||
|
* @param child child of the requested path.
|
||||||
|
* @return modified time.
|
||||||
|
*/
|
||||||
|
private long getModifiedTime(Map<String, Long> ret, String path,
|
||||||
|
String child) {
|
||||||
|
MountTableResolver mountTable = (MountTableResolver)subclusterResolver;
|
||||||
|
String srcPath;
|
||||||
|
if (path.equals(Path.SEPARATOR)) {
|
||||||
|
srcPath = Path.SEPARATOR + child;
|
||||||
|
} else {
|
||||||
|
srcPath = path + Path.SEPARATOR + child;
|
||||||
|
}
|
||||||
|
Long modTime = 0L;
|
||||||
|
try {
|
||||||
|
// Get mount table entry for the srcPath
|
||||||
|
MountTable entry = mountTable.getMountPoint(srcPath);
|
||||||
|
// if srcPath is not in mount table but its subdirs are in mount
|
||||||
|
// table we will display latest modified subdir date/time.
|
||||||
|
if (entry == null) {
|
||||||
|
List<MountTable> entries = mountTable.getMounts(srcPath);
|
||||||
|
for (MountTable eachEntry : entries) {
|
||||||
|
// Get the latest date
|
||||||
|
if (ret.get(child) == null ||
|
||||||
|
ret.get(child) < eachEntry.getDateModified()) {
|
||||||
|
modTime = eachEntry.getDateModified();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
modTime = entry.getDateModified();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.error("Cannot get mount point", e);
|
||||||
|
}
|
||||||
|
return modTime;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new file status for a mount point.
|
* Create a new file status for a mount point.
|
||||||
*
|
*
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
@ -167,6 +168,12 @@ public void testListFilesTime() throws Exception {
|
|||||||
addEntry = MountTable.newInstance(
|
addEntry = MountTable.newInstance(
|
||||||
"/testdir/subdir", Collections.singletonMap("ns0", "/testdir/subdir"));
|
"/testdir/subdir", Collections.singletonMap("ns0", "/testdir/subdir"));
|
||||||
assertTrue(addMountTable(addEntry));
|
assertTrue(addMountTable(addEntry));
|
||||||
|
addEntry = MountTable.newInstance(
|
||||||
|
"/testdir3/subdir1", Collections.singletonMap("ns0", "/testdir3"));
|
||||||
|
assertTrue(addMountTable(addEntry));
|
||||||
|
addEntry = MountTable.newInstance(
|
||||||
|
"/testA/testB/testC/testD", Collections.singletonMap("ns0", "/test"));
|
||||||
|
assertTrue(addMountTable(addEntry));
|
||||||
|
|
||||||
// Create test dir in NN
|
// Create test dir in NN
|
||||||
final FileSystem nnFs = nnContext.getFileSystem();
|
final FileSystem nnFs = nnContext.getFileSystem();
|
||||||
@ -174,8 +181,18 @@ public void testListFilesTime() throws Exception {
|
|||||||
|
|
||||||
Map<String, Long> pathModTime = new TreeMap<>();
|
Map<String, Long> pathModTime = new TreeMap<>();
|
||||||
for (String mount : mountTable.getMountPoints("/")) {
|
for (String mount : mountTable.getMountPoints("/")) {
|
||||||
|
if (mountTable.getMountPoint("/"+mount) != null) {
|
||||||
pathModTime.put(mount, mountTable.getMountPoint("/"+mount)
|
pathModTime.put(mount, mountTable.getMountPoint("/"+mount)
|
||||||
.getDateModified());
|
.getDateModified());
|
||||||
|
} else {
|
||||||
|
List<MountTable> entries = mountTable.getMounts("/"+mount);
|
||||||
|
for (MountTable entry : entries) {
|
||||||
|
if (pathModTime.get(mount) == null ||
|
||||||
|
pathModTime.get(mount) < entry.getDateModified()) {
|
||||||
|
pathModTime.put(mount, entry.getDateModified());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FileStatus[] iterator = nnFs.listStatus(new Path("/"));
|
FileStatus[] iterator = nnFs.listStatus(new Path("/"));
|
||||||
for (FileStatus file : iterator) {
|
for (FileStatus file : iterator) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user