You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ka...@apache.org on 2011/11/18 00:02:00 UTC

svn commit: r1203413 - in /hbase/trunk/src/main: java/org/apache/hadoop/hbase/util/RegionSplitter.java ruby/hbase.rb ruby/hbase/admin.rb ruby/shell/commands/create.rb

Author: kannan
Date: Thu Nov 17 23:01:59 2011
New Revision: 1203413

URL: http://svn.apache.org/viewvc?rev=1203413&view=rev
Log:
HBASE-4628 [jira] Enhance Table Create Presplit Functionality within the HBase
Shell

Summary:
HBase shell can algorithmically split a new table at creation

This change adds optional arguments to the HBase shell's create command
to split a table into a specified number of regions using a specified
splitting algorithm as defined by RegionSplitter.

Currently, we allow the user to presplit in the HBase shell by explicitly
listing the startkey of all the region shards that they want.  Instead, we
should provide the RegionSplitter functionality of choosing a split algorithm,
followed by the number of splits that they want.

Test Plan:
Created tables with and without splits using the shell; also attampted
to give incorrect arguments to shell create command.

Reviewers: nspiegelberg, JIRA

Reviewed By: nspiegelberg

CC: nspiegelberg, lhofhansl

Differential Revision: 429

Modified:
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java
    hbase/trunk/src/main/ruby/hbase.rb
    hbase/trunk/src/main/ruby/hbase/admin.rb
    hbase/trunk/src/main/ruby/shell/commands/create.rb

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java?rev=1203413&r1=1203412&r2=1203413&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java Thu Nov 17 23:01:59 2011
@@ -584,7 +584,7 @@ public class RegionSplitter {
    * @throws IOException if the specified SplitAlgorithm class couldn't be
    * instantiated
    */
-  static SplitAlgorithm newSplitAlgoInstance(Configuration conf,
+  public static SplitAlgorithm newSplitAlgoInstance(Configuration conf,
           String splitClassName) throws IOException {
     Class<?> splitClass;
 

Modified: hbase/trunk/src/main/ruby/hbase.rb
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/ruby/hbase.rb?rev=1203413&r1=1203412&r2=1203413&view=diff
==============================================================================
--- hbase/trunk/src/main/ruby/hbase.rb (original)
+++ hbase/trunk/src/main/ruby/hbase.rb Thu Nov 17 23:01:59 2011
@@ -53,6 +53,8 @@ module HBaseConstants
   FILTER = 'FILTER'
   SPLITS = 'SPLITS'
   SPLITS_FILE = 'SPLITS_FILE'
+  SPLITALGO = 'SPLITALGO'
+  NUMREGIONS = 'NUMREGIONS'
 
   # Load constants from hbase java API
   def self.promote_constants(constants)

Modified: hbase/trunk/src/main/ruby/hbase/admin.rb
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/ruby/hbase/admin.rb?rev=1203413&r1=1203412&r2=1203413&view=diff
==============================================================================
--- hbase/trunk/src/main/ruby/hbase/admin.rb (original)
+++ hbase/trunk/src/main/ruby/hbase/admin.rb Thu Nov 17 23:01:59 2011
@@ -30,6 +30,7 @@ module Hbase
     def initialize(configuration, formatter)
       @admin = org.apache.hadoop.hbase.client.HBaseAdmin.new(configuration)
       connection = @admin.getConnection()
+      @conf = configuration
       @zk_wrapper = connection.getZooKeeperWatcher()
       zk = @zk_wrapper.getRecoverableZooKeeper().getZooKeeper()
       @zk_main = org.apache.zookeeper.ZooKeeperMain.new(zk)
@@ -198,6 +199,13 @@ module Hbase
             splits[idx] = split.to_java_bytes
             idx = idx + 1
           end
+        elsif arg.kind_of?(Hash) and (arg.has_key?(NUMREGIONS) or arg.has_key?(SLITALGO))
+          raise(ArgumentError, "Number of regions must be specified") unless arg.has_key?(NUMREGIONS)
+          raise(ArgumentError, "Split algorithm must be specified") unless arg.has_key?(SPLITALGO)
+          raise(ArgumentError, "Number of regions must be geter than 1") unless arg[NUMREGIONS] > 1
+          num_regions = arg[NUMREGIONS]
+          split_algo = org.apache.hadoop.hbase.util.RegionSplitter.newSplitAlgoInstance(@conf, arg[SPLITALGO])
+          splits = split_algo.split(JInteger.valueOf(num_regions))
         else
           # Add column to the table
           descriptor = hcd(arg, htd)

Modified: hbase/trunk/src/main/ruby/shell/commands/create.rb
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/ruby/shell/commands/create.rb?rev=1203413&r1=1203412&r2=1203413&view=diff
==============================================================================
--- hbase/trunk/src/main/ruby/shell/commands/create.rb (original)
+++ hbase/trunk/src/main/ruby/shell/commands/create.rb Thu Nov 17 23:01:59 2011
@@ -35,6 +35,9 @@ Examples:
   hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}
   hbase> create 't1', 'f1', {SPLITS => ['10', '20', '30', '40']}
   hbase> create 't1', 'f1', {SPLITS_FILE => 'splits.txt'}
+  hbase> # Optionally pre-split the table into NUMREGIONS, using
+  hbase> # SPLITALGO ("HexStringSplit", "UniformSplit" or classname)
+  hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}
 EOF
       end