hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nspiegelb...@apache.org
Subject svn commit: r1203000 - in /hbase/branches/0.89-fb/src/main/ruby: hbase.rb hbase/admin.rb shell/commands/create.rb
Date Thu, 17 Nov 2011 01:48:05 GMT
Author: nspiegelberg
Date: Thu Nov 17 01:48:05 2011
New Revision: 1203000

URL: http://svn.apache.org/viewvc?rev=1203000&view=rev
Log:
HBase shell can pre-split a new table at creation

Summary:
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.

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

Reviewers: kranganathan, nspiegelberg

Reviewed By: nspiegelberg

CC: hbase-eng@lists, nspiegelberg, cgist, alasla

Differential Revision: 353287

Task ID: 743529

Modified:
    hbase/branches/0.89-fb/src/main/ruby/hbase.rb
    hbase/branches/0.89-fb/src/main/ruby/hbase/admin.rb
    hbase/branches/0.89-fb/src/main/ruby/shell/commands/create.rb

Modified: hbase/branches/0.89-fb/src/main/ruby/hbase.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/ruby/hbase.rb?rev=1203000&r1=1202999&r2=1203000&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/ruby/hbase.rb (original)
+++ hbase/branches/0.89-fb/src/main/ruby/hbase.rb Thu Nov 17 01:48:05 2011
@@ -55,6 +55,8 @@ module HBaseConstants
   INTERVAL = 'INTERVAL'
   CACHE = 'CACHE'
   FILTER = 'FILTER'
+  SPLITALGO = 'SPLITALGO'
+  NUMREGIONS = 'NUMREGIONS'
 
   # Load constants from hbase java API
   def self.promote_constants(constants)

Modified: hbase/branches/0.89-fb/src/main/ruby/hbase/admin.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/ruby/hbase/admin.rb?rev=1203000&r1=1202999&r2=1203000&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/ruby/hbase/admin.rb (original)
+++ hbase/branches/0.89-fb/src/main/ruby/hbase/admin.rb Thu Nov 17 01:48:05 2011
@@ -29,6 +29,7 @@ java_import org.apache.hadoop.hbase.HTab
 java_import org.apache.hadoop.hbase.io.hfile.Compression
 java_import org.apache.hadoop.hbase.regionserver.StoreFile
 java_import org.apache.hadoop.hbase.util.Pair
+java_import org.apache.hadoop.hbase.util.RegionSplitter
 java_import org.apache.hadoop.hbase.HRegionInfo
 java_import org.apache.zookeeper.ZooKeeper
 
@@ -147,6 +148,10 @@ module Hbase
       # Start defining the table
       htd = HTableDescriptor.new(table_name)
 
+      # Parameters for pre-splitting the table
+      num_regions = nil
+      split_algo = nil
+
       # All args are columns, add them to the table definition
       # TODO: add table options support
       args.each do |arg|
@@ -154,12 +159,28 @@ module Hbase
           raise(ArgumentError, "#{arg.class} of #{arg.inspect} is not of Hash or String type")
         end
 
-        # Add column to the table
-        htd.addFamily(hcd(arg, htd))
+        if arg.kind_of?(Hash) and (arg.has_key?(NUMREGIONS) or arg.has_key?(SPLITALGO))
+          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 = RegionSplitter.newSplitAlgoInstance(@conf, arg[SPLITALGO])
+        else
+          # Add column to the table
+          htd.addFamily(hcd(arg, htd))
+        end
       end
 
-      # Perform the create table call
-      @admin.createTable(htd)
+      if num_regions.nil?
+        # Perform the create table call
+        @admin.createTable(htd)
+      else
+        # Compute the splits for the predefined number of regions
+        splits = split_algo.split(JInteger.valueOf(num_regions))
+
+        # Perform the create table call
+        @admin.createTable(htd, splits)
+      end
     end
 
     #----------------------------------------------------------------------------------------------

Modified: hbase/branches/0.89-fb/src/main/ruby/shell/commands/create.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/ruby/shell/commands/create.rb?rev=1203000&r1=1202999&r2=1203000&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/ruby/shell/commands/create.rb (original)
+++ hbase/branches/0.89-fb/src/main/ruby/shell/commands/create.rb Thu Nov 17 01:48:05 2011
@@ -24,7 +24,7 @@ module Shell
       def help
         return <<-EOF
           Create table; pass table name, a dictionary of specifications per
-          column family, and optionally a dictionary of table configuration.
+          column family, and optionally a dictionary of split parameters.
           Dictionaries are described below in the GENERAL NOTES section.
           Examples:
 
@@ -34,6 +34,10 @@ module Shell
           hbase> create 't1', 'f1', 'f2', 'f3'
           hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000,
                  BLOCKCACHE => true}
+          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
 



Mime
View raw message