From aaa463378fbc5f56b321cea4f9267b668a1c70e1 Mon Sep 17 00:00:00 2001 From: Esteban Gutierrez Date: Wed, 11 Oct 2017 15:00:50 -0500 Subject: [PATCH] HBASE-18987 Raise value of HConstants#MAX_ROW_LENGTH --- .../java/org/apache/hadoop/hbase/HConstants.java | 4 +-- .../hadoop/hbase/regionserver/TestHRegionInfo.java | 41 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java index 7577644d32..6338d03259 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java @@ -543,9 +543,9 @@ public final class HConstants { public static final byte [] LAST_ROW = EMPTY_BYTE_ARRAY; /** - * Max length a row can have because of the limitation in TFile. + * Max length a row can have. */ - public static final int MAX_ROW_LENGTH = Short.MAX_VALUE; + public static final int MAX_ROW_LENGTH = Integer.MAX_VALUE - 1; /** * Timestamp to use when we want to refer to the latest cell. diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java index a20fccb563..c1d97fb2ad 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java @@ -26,6 +26,7 @@ import static org.junit.Assert.fail; import java.io.IOException; +import org.apache.commons.lang.RandomStringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.Path; @@ -33,6 +34,8 @@ import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.exceptions.DeserializationException; import org.apache.hadoop.hbase.master.RegionState; import org.apache.hadoop.hbase.shaded.com.google.protobuf.UnsafeByteOperations; @@ -118,6 +121,44 @@ public class TestHRegionInfo { nameStr); } + @Test + public void testCreateOversizedHRegionInfoName() throws Exception { + final String tableName = name.getMethodName(); + final TableName tn = TableName.valueOf(tableName); + String startKey = RandomStringUtils.randomAlphabetic(Short.MAX_VALUE + 64); // Old MAX_ROW_LENGTH == Short.MAX_VALUE + final byte[] sk = Bytes.toBytes(startKey); + String id = "id"; + + // old format region name + byte [] name = HRegionInfo.createRegionName(tn, sk, id, false); + String nameStr = Bytes.toString(name); + assertTrue(nameStr.length() <= HConstants.MAX_ROW_LENGTH); + + // new format region name. + String md5HashInHex = MD5Hash.getMD5AsHex(name, 0, name.length); + name = HRegionInfo.createRegionName(tn, sk, id, true); + nameStr = Bytes.toString(name); + assertTrue(nameStr.length() <= HConstants.MAX_ROW_LENGTH); + } + + @Test + public void testOversizedRegionNameForPut() throws Exception { + final String tableName = name.getMethodName(); + final TableName tn = TableName.valueOf(tableName); + String startKey = RandomStringUtils.randomAlphabetic(Short.MAX_VALUE + 64); // Old MAX_ROW_LENGTH == Short.MAX_VALUE + final byte[] sk = Bytes.toBytes(startKey); + String id = "id"; + + // old format region name + byte [] name = HRegionInfo.createRegionName(tn, sk, id, false); + String nameStr = Bytes.toString(name); + try { + Put hri_a = new Put(sk); + } catch (Exception e) { + fail("Put shouldn't have failed with oversized row key"); + } + } + @Test public void testContainsRange() { HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); -- 2.14.2