You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by gx...@apache.org on 2019/11/07 02:11:21 UTC
[hbase] branch branch-2.2 updated: HBASE-22980 HRegionPartioner
getPartition() method incorrectly partitions the regions of the table.
(#590)
This is an automated email from the ASF dual-hosted git repository.
gxcheng pushed a commit to branch branch-2.2
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.2 by this push:
new c7a84a9 HBASE-22980 HRegionPartioner getPartition() method incorrectly partitions the regions of the table. (#590)
c7a84a9 is described below
commit c7a84a96f6224eca320f8a8063554c3cca992fb9
Author: Shardul Singh <sh...@gmail.com>
AuthorDate: Wed Nov 6 19:37:44 2019 +0530
HBASE-22980 HRegionPartioner getPartition() method incorrectly partitions the regions of the table. (#590)
Signed-off-by: Michael Stack <st...@apache.org>
Signed-off-by: Guangxu Cheng <gu...@gmail.com>
---
.../hadoop/hbase/mapred/HRegionPartitioner.java | 2 +-
.../hadoop/hbase/mapreduce/HRegionPartitioner.java | 2 +-
.../hbase/mapreduce/TestHRegionPartitioner.java | 24 ++++++++++++++++++++++
3 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapred/HRegionPartitioner.java b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapred/HRegionPartitioner.java
index b0674bf..7806258 100644
--- a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapred/HRegionPartitioner.java
+++ b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapred/HRegionPartitioner.java
@@ -82,7 +82,7 @@ implements Partitioner<ImmutableBytesWritable, V2> {
}
for (int i = 0; i < this.startKeys.length; i++){
if (Bytes.compareTo(region, this.startKeys[i]) == 0 ){
- if (i >= numPartitions-1){
+ if (i >= numPartitions){
// cover if we have less reduces then regions.
return (Integer.toString(i).hashCode()
& Integer.MAX_VALUE) % numPartitions;
diff --git a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HRegionPartitioner.java b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HRegionPartitioner.java
index b48ecf0..12f2e86 100644
--- a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HRegionPartitioner.java
+++ b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HRegionPartitioner.java
@@ -89,7 +89,7 @@ implements Configurable {
}
for (int i = 0; i < this.startKeys.length; i++){
if (Bytes.compareTo(region, this.startKeys[i]) == 0 ){
- if (i >= numPartitions-1){
+ if (i >= numPartitions){
// cover if we have less reduces then regions.
return (Integer.toString(i).hashCode()
& Integer.MAX_VALUE) % numPartitions;
diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHRegionPartitioner.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHRegionPartitioner.java
index 562a009..2095b87 100644
--- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHRegionPartitioner.java
+++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHRegionPartitioner.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.MetaTableAccessor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.testclassification.MapReduceTests;
@@ -77,4 +78,27 @@ public class TestHRegionPartitioner {
assertEquals(1, partitioner.getPartition(writable, 10L, 3));
assertEquals(0, partitioner.getPartition(writable, 10L, 1));
}
+
+ @Test
+ public void testHRegionPartitionerMoreRegions() throws Exception {
+
+ byte[][] families = { Bytes.toBytes("familyA"), Bytes.toBytes("familyB") };
+
+ TableName tableName = TableName.valueOf(name.getMethodName());
+ UTIL.createTable(tableName, families, 1, Bytes.toBytes("aa"), Bytes.toBytes("cc"), 5);
+
+ Configuration configuration = UTIL.getConfiguration();
+ int numberOfRegions = MetaTableAccessor.getRegionCount(configuration, tableName);
+ assertEquals(5, numberOfRegions);
+
+ HRegionPartitioner<Long, Long> partitioner = new HRegionPartitioner<>();
+ configuration.set(TableOutputFormat.OUTPUT_TABLE, name.getMethodName());
+ partitioner.setConf(configuration);
+
+ // Get some rowKey for the lastRegion
+ ImmutableBytesWritable writable = new ImmutableBytesWritable(Bytes.toBytes("df"));
+
+ // getPartition should return 4 since number of partition = number of reduces.
+ assertEquals(4, partitioner.getPartition(writable, 10L, 5));
+ }
}