You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2010/03/30 07:34:27 UTC
svn commit: r928995 - in /hadoop/hbase/trunk: CHANGES.txt
core/src/main/java/org/apache/hadoop/hbase/io/ImmutableBytesWritable.java
core/src/test/java/org/apache/hadoop/hbase/io/TestImmutableBytesWritable.java
Author: stack
Date: Tue Mar 30 05:34:26 2010
New Revision: 928995
URL: http://svn.apache.org/viewvc?rev=928995&view=rev
Log:
HBASE-2378 Bulk insert with multiple reducers broken due to improper ImmutableBytesWritable comparator
Added:
hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/io/TestImmutableBytesWritable.java
Modified:
hadoop/hbase/trunk/CHANGES.txt
hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/io/ImmutableBytesWritable.java
Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=928995&r1=928994&r2=928995&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Tue Mar 30 05:34:26 2010
@@ -254,6 +254,8 @@ Release 0.21.0 - Unreleased
HBASE-2358 Store doReconstructionLog will fail if oldlogfile.log is empty
and won't load region (Cosmin Lehene via Stack)
HBASE-2370 saveVersion.sh doesnt properly grab the git revision
+ HBASE-2378 Bulk insert with multiple reducers broken due to improper
+ ImmutableBytesWritable comparator (Todd Lipcon via Stack)
IMPROVEMENTS
HBASE-1760 Cleanup TODOs in HTable
Modified: hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/io/ImmutableBytesWritable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/io/ImmutableBytesWritable.java?rev=928995&r1=928994&r2=928995&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/io/ImmutableBytesWritable.java (original)
+++ hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/io/ImmutableBytesWritable.java Tue Mar 30 05:34:26 2010
@@ -178,10 +178,7 @@ implements WritableComparable<ImmutableB
* negative if left is smaller than right.
*/
public int compareTo(final byte [] that) {
- int diff = this.length - that.length;
- return (diff != 0)?
- diff:
- WritableComparator.compareBytes(this.bytes, 0, this.length, that,
+ return WritableComparator.compareBytes(this.bytes, 0, this.length, that,
0, that.length);
}
Added: hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/io/TestImmutableBytesWritable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/io/TestImmutableBytesWritable.java?rev=928995&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/io/TestImmutableBytesWritable.java (added)
+++ hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/io/TestImmutableBytesWritable.java Tue Mar 30 05:34:26 2010
@@ -0,0 +1,96 @@
+/**
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.io;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.hbase.util.Bytes;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public class TestImmutableBytesWritable extends TestCase {
+ public void testComparison() throws Exception {
+ runTests("aa", "b", -1);
+ runTests("aa", "aa", 0);
+ runTests("aa", "ab", -1);
+ runTests("aa", "aaa", -1);
+ runTests("", "", 0);
+ runTests("", "a", -1);
+ }
+
+ private void runTests(String aStr, String bStr, int signum)
+ throws Exception {
+ ImmutableBytesWritable a = new ImmutableBytesWritable(
+ Bytes.toBytes(aStr));
+ ImmutableBytesWritable b = new ImmutableBytesWritable(
+ Bytes.toBytes(bStr));
+
+ doComparisonsOnObjects(a, b, signum);
+ doComparisonsOnRaw(a, b, signum);
+ }
+
+
+ private int signum(int i) {
+ if (i > 0) return 1;
+ if (i == 0) return 0;
+ return -1;
+ }
+
+ private void doComparisonsOnRaw(ImmutableBytesWritable a,
+ ImmutableBytesWritable b,
+ int expectedSignum)
+ throws IOException {
+ ImmutableBytesWritable.Comparator comparator =
+ new ImmutableBytesWritable.Comparator();
+
+ ByteArrayOutputStream baosA = new ByteArrayOutputStream();
+ ByteArrayOutputStream baosB = new ByteArrayOutputStream();
+
+ a.write(new DataOutputStream(baosA));
+ b.write(new DataOutputStream(baosB));
+
+ assertEquals(
+ "Comparing " + a + " and " + b + " as raw",
+ signum(comparator.compare(baosA.toByteArray(), 0, baosA.size(),
+ baosB.toByteArray(), 0, baosB.size())),
+ expectedSignum);
+
+ assertEquals(
+ "Comparing " + a + " and " + b + " as raw (inverse)",
+ -signum(comparator.compare(baosB.toByteArray(), 0, baosB.size(),
+ baosA.toByteArray(), 0, baosA.size())),
+ expectedSignum);
+ }
+
+ private void doComparisonsOnObjects(ImmutableBytesWritable a,
+ ImmutableBytesWritable b,
+ int expectedSignum) {
+ ImmutableBytesWritable.Comparator comparator =
+ new ImmutableBytesWritable.Comparator();
+ assertEquals(
+ "Comparing " + a + " and " + b + " as objects",
+ signum(comparator.compare(a, b)), expectedSignum);
+ assertEquals(
+ "Comparing " + a + " and " + b + " as objects (inverse)",
+ -signum(comparator.compare(b, a)), expectedSignum);
+ }
+}
\ No newline at end of file