svn merge -c 1416034 FIXES: HDFS-4247. saveNamespace should be tolerant of dangling lease (daryn)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1416035 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
77933c6327
commit
85a5ad4bf9
|
@ -1736,6 +1736,8 @@ Release 0.23.6 - UNRELEASED
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
||||||
|
HDFS-4247. saveNamespace should be tolerant of dangling lease (daryn)
|
||||||
|
|
||||||
Release 0.23.5 - UNRELEASED
|
Release 0.23.5 - UNRELEASED
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -4896,19 +4896,13 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
||||||
// lock on our behalf. If we took the read lock here, we could block
|
// lock on our behalf. If we took the read lock here, we could block
|
||||||
// for fairness if a writer is waiting on the lock.
|
// for fairness if a writer is waiting on the lock.
|
||||||
synchronized (leaseManager) {
|
synchronized (leaseManager) {
|
||||||
out.writeInt(leaseManager.countPath()); // write the size
|
Map<String, INodeFileUnderConstruction> nodes =
|
||||||
|
leaseManager.getINodesUnderConstruction();
|
||||||
for (Lease lease : leaseManager.getSortedLeases()) {
|
out.writeInt(nodes.size()); // write the size
|
||||||
for(String path : lease.getPaths()) {
|
for (Map.Entry<String, INodeFileUnderConstruction> entry
|
||||||
// verify that path exists in namespace
|
: nodes.entrySet()) {
|
||||||
final INodeFileUnderConstruction cons;
|
FSImageSerialization.writeINodeUnderConstruction(
|
||||||
try {
|
out, entry.getValue(), entry.getKey());
|
||||||
cons = INodeFileUnderConstruction.valueOf(dir.getINode(path), path);
|
|
||||||
} catch (UnresolvedLinkException e) {
|
|
||||||
throw new AssertionError("Lease files should reside on this FS");
|
|
||||||
}
|
|
||||||
FSImageSerialization.writeINodeUnderConstruction(out, cons, path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -429,6 +429,26 @@ public class LeaseManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of inodes corresponding to valid leases.
|
||||||
|
* @return list of inodes
|
||||||
|
* @throws UnresolvedLinkException
|
||||||
|
*/
|
||||||
|
Map<String, INodeFileUnderConstruction> getINodesUnderConstruction() {
|
||||||
|
Map<String, INodeFileUnderConstruction> inodes =
|
||||||
|
new TreeMap<String, INodeFileUnderConstruction>();
|
||||||
|
for (String p : sortedLeasesByPath.keySet()) {
|
||||||
|
// verify that path exists in namespace
|
||||||
|
try {
|
||||||
|
INode node = fsnamesystem.dir.getINode(p);
|
||||||
|
inodes.put(p, INodeFileUnderConstruction.valueOf(node, p));
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
LOG.error(ioe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return inodes;
|
||||||
|
}
|
||||||
|
|
||||||
/** Check the leases beginning from the oldest.
|
/** Check the leases beginning from the oldest.
|
||||||
* @return true is sync is needed.
|
* @return true is sync is needed.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -603,6 +603,24 @@ public class TestSaveNamespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSaveNamespaceWithDanglingLease() throws Exception {
|
||||||
|
MiniDFSCluster cluster = new MiniDFSCluster.Builder(new Configuration())
|
||||||
|
.numDataNodes(1).build();
|
||||||
|
cluster.waitActive();
|
||||||
|
DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem();
|
||||||
|
try {
|
||||||
|
cluster.getNamesystem().leaseManager.addLease("me", "/non-existent");
|
||||||
|
fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
|
||||||
|
cluster.getNameNodeRpc().saveNamespace();
|
||||||
|
fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
|
||||||
|
} finally {
|
||||||
|
if (cluster != null) {
|
||||||
|
cluster.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void doAnEdit(FSNamesystem fsn, int id) throws IOException {
|
private void doAnEdit(FSNamesystem fsn, int id) throws IOException {
|
||||||
// Make an edit
|
// Make an edit
|
||||||
fsn.mkdirs(
|
fsn.mkdirs(
|
||||||
|
|
Loading…
Reference in New Issue