HDFS-4684. Use INode id for image serialization when writing INodeReference.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-2802@1466718 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3209d4a3c4
commit
4c00514ede
|
@ -228,3 +228,6 @@ Branch-2802 Snapshot (Unreleased)
|
||||||
|
|
||||||
HDFS-4647. Rename should call setLocalName after an inode is removed from
|
HDFS-4647. Rename should call setLocalName after an inode is removed from
|
||||||
snapshots. (Arpit Agarwal via szetszwo)
|
snapshots. (Arpit Agarwal via szetszwo)
|
||||||
|
|
||||||
|
HDFS-4684. Use INode id for image serialization when writing INodeReference.
|
||||||
|
(szetszwo)
|
||||||
|
|
|
@ -271,10 +271,6 @@ public class FSImageFormat {
|
||||||
imgTxId = 0;
|
imgTxId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (supportSnapshot) {
|
|
||||||
snapshotMap = namesystem.getSnapshotManager().read(in, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// read the last allocated inode id in the fsimage
|
// read the last allocated inode id in the fsimage
|
||||||
if (LayoutVersion.supports(Feature.ADD_INODE_ID, imgVersion)) {
|
if (LayoutVersion.supports(Feature.ADD_INODE_ID, imgVersion)) {
|
||||||
long lastInodeId = in.readLong();
|
long lastInodeId = in.readLong();
|
||||||
|
@ -289,6 +285,10 @@ public class FSImageFormat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (supportSnapshot) {
|
||||||
|
snapshotMap = namesystem.getSnapshotManager().read(in, this);
|
||||||
|
}
|
||||||
|
|
||||||
// read compression related info
|
// read compression related info
|
||||||
FSImageCompression compression;
|
FSImageCompression compression;
|
||||||
if (LayoutVersion.supports(Feature.FSIMAGE_COMPRESSION, imgVersion)) {
|
if (LayoutVersion.supports(Feature.FSIMAGE_COMPRESSION, imgVersion)) {
|
||||||
|
@ -843,7 +843,6 @@ public class FSImageFormat {
|
||||||
context.checkCancelled();
|
context.checkCancelled();
|
||||||
fout.getChannel().force(true);
|
fout.getChannel().force(true);
|
||||||
} finally {
|
} finally {
|
||||||
referenceMap.removeAllINodeReferenceWithId();
|
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,6 @@ import org.apache.hadoop.hdfs.tools.snapshot.SnapshotDiff;
|
||||||
import org.apache.hadoop.hdfs.util.Diff.ListType;
|
import org.apache.hadoop.hdfs.util.Diff.ListType;
|
||||||
import org.apache.hadoop.hdfs.util.ReadOnlyList;
|
import org.apache.hadoop.hdfs.util.ReadOnlyList;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper class defining static methods for reading/writing snapshot related
|
* A helper class defining static methods for reading/writing snapshot related
|
||||||
* information from/to FSImage.
|
* information from/to FSImage.
|
||||||
|
@ -307,46 +305,23 @@ public class SnapshotFSImageFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** A reference with a fixed id for fsimage serialization. */
|
|
||||||
private static class INodeReferenceWithId extends INodeReference {
|
|
||||||
final long id;
|
|
||||||
|
|
||||||
private INodeReferenceWithId(WithCount parent, INode referred, long id) {
|
|
||||||
super(parent, referred);
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return the reference id. */
|
|
||||||
private long getReferenceId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A reference map for fsimage serialization. */
|
/** A reference map for fsimage serialization. */
|
||||||
public static class ReferenceMap {
|
public static class ReferenceMap {
|
||||||
private final Map<Long, INodeReference.WithCount> referenceMap
|
private final Map<Long, INodeReference.WithCount> referenceMap
|
||||||
= new HashMap<Long, INodeReference.WithCount>();
|
= new HashMap<Long, INodeReference.WithCount>();
|
||||||
private long referenceId = 0;
|
|
||||||
|
|
||||||
public void writeINodeReferenceWithCount(INodeReference.WithCount withCount,
|
public void writeINodeReferenceWithCount(INodeReference.WithCount withCount,
|
||||||
DataOutput out, boolean writeUnderConstruction) throws IOException {
|
DataOutput out, boolean writeUnderConstruction) throws IOException {
|
||||||
final INode referred = withCount.getReferredINode();
|
final INode referred = withCount.getReferredINode();
|
||||||
final boolean firstReferred = !(referred instanceof INodeReferenceWithId);
|
final long id = withCount.getId();
|
||||||
|
final boolean firstReferred = !referenceMap.containsKey(id);
|
||||||
out.writeBoolean(firstReferred);
|
out.writeBoolean(firstReferred);
|
||||||
|
|
||||||
if (firstReferred) {
|
if (firstReferred) {
|
||||||
FSImageSerialization.saveINode2Image(referred, out,
|
FSImageSerialization.saveINode2Image(referred, out,
|
||||||
writeUnderConstruction, this);
|
writeUnderConstruction, this);
|
||||||
final long id = ++referenceId;
|
|
||||||
referenceMap.put(id, withCount);
|
referenceMap.put(id, withCount);
|
||||||
|
|
||||||
final INodeReferenceWithId withId = new INodeReferenceWithId(
|
|
||||||
withCount, referred, id);
|
|
||||||
withCount.setReferredINode(withId);
|
|
||||||
referred.setParentReference(withId);
|
|
||||||
} else {
|
} else {
|
||||||
final long id = ((INodeReferenceWithId)referred).getReferenceId();
|
|
||||||
Preconditions.checkState(referenceMap.containsKey(id));
|
|
||||||
out.writeLong(id);
|
out.writeLong(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -360,7 +335,7 @@ public class SnapshotFSImageFormat {
|
||||||
if (firstReferred) {
|
if (firstReferred) {
|
||||||
final INode referred = loader.loadINodeWithLocalName(isSnapshotINode, in);
|
final INode referred = loader.loadINodeWithLocalName(isSnapshotINode, in);
|
||||||
withCount = new INodeReference.WithCount(null, referred);
|
withCount = new INodeReference.WithCount(null, referred);
|
||||||
referenceMap.put(++referenceId, withCount);
|
referenceMap.put(withCount.getId(), withCount);
|
||||||
} else {
|
} else {
|
||||||
final long id = in.readLong();
|
final long id = in.readLong();
|
||||||
withCount = referenceMap.get(id);
|
withCount = referenceMap.get(id);
|
||||||
|
@ -368,16 +343,5 @@ public class SnapshotFSImageFormat {
|
||||||
}
|
}
|
||||||
return withCount;
|
return withCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAllINodeReferenceWithId() {
|
|
||||||
for(INodeReference.WithCount withCount : referenceMap.values()) {
|
|
||||||
final INodeReference ref = withCount.getReferredINode().asReference();
|
|
||||||
final INode referred = ref.getReferredINode();
|
|
||||||
withCount.setReferredINode(referred);
|
|
||||||
referred.setParentReference(withCount);
|
|
||||||
ref.clear();
|
|
||||||
}
|
|
||||||
referenceMap.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue