Return-Path: X-Original-To: apmail-hadoop-hdfs-commits-archive@minotaur.apache.org Delivered-To: apmail-hadoop-hdfs-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 37E891000A for ; Wed, 10 Apr 2013 22:24:52 +0000 (UTC) Received: (qmail 43130 invoked by uid 500); 10 Apr 2013 22:24:52 -0000 Delivered-To: apmail-hadoop-hdfs-commits-archive@hadoop.apache.org Received: (qmail 43095 invoked by uid 500); 10 Apr 2013 22:24:52 -0000 Mailing-List: contact hdfs-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hdfs-dev@hadoop.apache.org Delivered-To: mailing list hdfs-commits@hadoop.apache.org Received: (qmail 43086 invoked by uid 99); 10 Apr 2013 22:24:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Apr 2013 22:24:51 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Apr 2013 22:24:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id B061D23888E4; Wed, 10 Apr 2013 22:24:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1466718 - in /hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs: ./ src/main/java/org/apache/hadoop/hdfs/server/namenode/ src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/ Date: Wed, 10 Apr 2013 22:24:30 -0000 To: hdfs-commits@hadoop.apache.org From: szetszwo@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130410222430.B061D23888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: szetszwo Date: Wed Apr 10 22:24:30 2013 New Revision: 1466718 URL: http://svn.apache.org/r1466718 Log: HDFS-4684. Use INode id for image serialization when writing INodeReference. Modified: hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java Modified: hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt?rev=1466718&r1=1466717&r2=1466718&view=diff ============================================================================== --- hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt (original) +++ hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt Wed Apr 10 22:24:30 2013 @@ -228,3 +228,6 @@ Branch-2802 Snapshot (Unreleased) HDFS-4647. Rename should call setLocalName after an inode is removed from snapshots. (Arpit Agarwal via szetszwo) + + HDFS-4684. Use INode id for image serialization when writing INodeReference. + (szetszwo) Modified: hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java?rev=1466718&r1=1466717&r2=1466718&view=diff ============================================================================== --- hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java (original) +++ hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java Wed Apr 10 22:24:30 2013 @@ -270,10 +270,6 @@ public class FSImageFormat { } else { imgTxId = 0; } - - if (supportSnapshot) { - snapshotMap = namesystem.getSnapshotManager().read(in, this); - } // read the last allocated inode id in the fsimage if (LayoutVersion.supports(Feature.ADD_INODE_ID, imgVersion)) { @@ -289,6 +285,10 @@ public class FSImageFormat { } } + if (supportSnapshot) { + snapshotMap = namesystem.getSnapshotManager().read(in, this); + } + // read compression related info FSImageCompression compression; if (LayoutVersion.supports(Feature.FSIMAGE_COMPRESSION, imgVersion)) { @@ -843,7 +843,6 @@ public class FSImageFormat { context.checkCancelled(); fout.getChannel().force(true); } finally { - referenceMap.removeAllINodeReferenceWithId(); out.close(); } Modified: hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java?rev=1466718&r1=1466717&r2=1466718&view=diff ============================================================================== --- hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java (original) +++ hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java Wed Apr 10 22:24:30 2013 @@ -41,8 +41,6 @@ import org.apache.hadoop.hdfs.tools.snap import org.apache.hadoop.hdfs.util.Diff.ListType; import org.apache.hadoop.hdfs.util.ReadOnlyList; -import com.google.common.base.Preconditions; - /** * A helper class defining static methods for reading/writing snapshot related * 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. */ public static class ReferenceMap { private final Map referenceMap = new HashMap(); - private long referenceId = 0; public void writeINodeReferenceWithCount(INodeReference.WithCount withCount, DataOutput out, boolean writeUnderConstruction) throws IOException { 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); if (firstReferred) { FSImageSerialization.saveINode2Image(referred, out, writeUnderConstruction, this); - final long id = ++referenceId; referenceMap.put(id, withCount); - - final INodeReferenceWithId withId = new INodeReferenceWithId( - withCount, referred, id); - withCount.setReferredINode(withId); - referred.setParentReference(withId); } else { - final long id = ((INodeReferenceWithId)referred).getReferenceId(); - Preconditions.checkState(referenceMap.containsKey(id)); out.writeLong(id); } } @@ -360,7 +335,7 @@ public class SnapshotFSImageFormat { if (firstReferred) { final INode referred = loader.loadINodeWithLocalName(isSnapshotINode, in); withCount = new INodeReference.WithCount(null, referred); - referenceMap.put(++referenceId, withCount); + referenceMap.put(withCount.getId(), withCount); } else { final long id = in.readLong(); withCount = referenceMap.get(id); @@ -368,16 +343,5 @@ public class SnapshotFSImageFormat { } 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(); - } } }