From a12c6b231157d41b49944df65afba9e2631981ba Mon Sep 17 00:00:00 2001 From: Guangxu Cheng Date: Wed, 13 Sep 2017 17:46:29 +0800 Subject: [PATCH] HBASE-18804 Sanity check the number of regions when creating a table --- .../org/apache/hadoop/hbase/master/HMaster.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 87594a5..9c79034 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -1737,6 +1737,7 @@ public class HMaster extends HRegionServer implements MasterServices { this.clusterSchemaService.getNamespace(namespace); HRegionInfo[] newRegions = ModifyRegionUtils.createHRegionInfos(tableDescriptor, splitKeys); + sanityCheckNumberOfRegions(tableDescriptor, newRegions.length); sanityCheckTableDescriptor(tableDescriptor); return MasterProcedureUtil.submitProcedure( @@ -1908,6 +1909,32 @@ public class HMaster extends HRegionServer implements MasterServices { } } + /** + * Check whether the pre-split regions of the table exceeds the limit + * @param numberRegions pre-split regions + * @throws IOException + */ + private void sanityCheckNumberOfRegions(final TableDescriptor htd, + final int numberRegions) throws IOException { + + final String CONF_KEY = "hbase.table.sanity.checks"; + boolean logWarn = false; + if (!conf.getBoolean(CONF_KEY, true)) { + logWarn = true; + } + String tableVal = htd.getValue(CONF_KEY); + if (tableVal != null && !Boolean.valueOf(tableVal)) { + logWarn = true; + } + + //check pre-split regions + if (numberRegions > conf.getLong("hbase.table.pre-split.regions.limit", 125000)) { + String message = "Too many pre-split regions which might cause the master down."; + warnOrThrowExceptionForFailure(logWarn, CONF_KEY, message, null); + } + } + + private void checkReplicationScope(ColumnFamilyDescriptor hcd) throws IOException{ // check replication scope WALProtos.ScopeType scop = WALProtos.ScopeType.valueOf(hcd.getScope()); -- 1.9.5.msysgit.0