Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1F5F21025C for ; Thu, 20 Mar 2014 23:06:33 +0000 (UTC) Received: (qmail 82123 invoked by uid 500); 20 Mar 2014 23:06:31 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 82037 invoked by uid 500); 20 Mar 2014 23:06:31 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 82030 invoked by uid 99); 20 Mar 2014 23:06:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Mar 2014 23:06:31 +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; Thu, 20 Mar 2014 23:06:29 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F225423888E4; Thu, 20 Mar 2014 23:06:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1579813 - /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DataOutputBuffer.java Date: Thu, 20 Mar 2014 23:06:07 -0000 To: common-commits@hadoop.apache.org From: jing9@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140320230607.F225423888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jing9 Date: Thu Mar 20 23:06:06 2014 New Revision: 1579813 URL: http://svn.apache.org/r1579813 Log: HDFS-6038. Allow JournalNode to handle editlog produced by new release with future layoutversion. Contributed by Jing Zhao. Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DataOutputBuffer.java Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DataOutputBuffer.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DataOutputBuffer.java?rev=1579813&r1=1579812&r2=1579813&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DataOutputBuffer.java (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DataOutputBuffer.java Thu Mar 20 23:06:06 2014 @@ -23,6 +23,8 @@ import java.io.*; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; +import com.google.common.base.Preconditions; + /** A reusable {@link DataOutput} implementation that writes to an in-memory * buffer. * @@ -68,6 +70,18 @@ public class DataOutputBuffer extends Da in.readFully(buf, count, len); count = newcount; } + + /** + * Set the count for the current buf. + * @param newCount the new count to set + * @return the original count + */ + private int setCount(int newCount) { + Preconditions.checkArgument(newCount >= 0 && newCount <= buf.length); + int oldCount = count; + count = newCount; + return oldCount; + } } private Buffer buffer; @@ -110,4 +124,21 @@ public class DataOutputBuffer extends Da public void writeTo(OutputStream out) throws IOException { buffer.writeTo(out); } + + /** + * Overwrite an integer into the internal buffer. Note that this call can only + * be used to overwrite existing data in the buffer, i.e., buffer#count cannot + * be increased, and DataOutputStream#written cannot be increased. + */ + public void writeInt(int v, int offset) throws IOException { + Preconditions.checkState(offset + 4 <= buffer.getLength()); + byte[] b = new byte[4]; + b[0] = (byte) ((v >>> 24) & 0xFF); + b[1] = (byte) ((v >>> 16) & 0xFF); + b[2] = (byte) ((v >>> 8) & 0xFF); + b[3] = (byte) ((v >>> 0) & 0xFF); + int oldCount = buffer.setCount(offset); + buffer.write(b); + buffer.setCount(oldCount); + } }