You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/10/11 04:07:29 UTC

svn commit: r1181425 - /hbase/branches/0.89/src/main/ruby/hbase/admin.rb

Author: nspiegelberg
Date: Tue Oct 11 02:07:29 2011
New Revision: 1181425

URL: http://svn.apache.org/viewvc?rev=1181425&view=rev
Log:
import 2984: alter should be incremental

Summary:
import patch for HBASE-2984.

The patch had some minor bugs with compression and bloom settings. I have fixed
those issue in this diff, and also update the public JIRA.

Test Plan:
hbase(main):005:0> create 't', {NAME => 'cf1', VERSIONS => 100, BLOOMFILTER =>
'ROWCOL', COMPRESSION => 'LZO'}
0 row(s) in 1.1430 seconds

hbase(main):006:0> disable 't'
0 row(s) in 1.0690 seconds

hbase(main):007:0> describe 't'
DESCRIPTION

 ENABLED

 {NAME => 't', FAMILIES => [{NAME => 'cf1', BLOOMFILTER => 'ROWCOL',
REPLICATION_SCOPE => '0', VERSIONS => '100', COMPRESSION => 'LZO', TTL =>
'2147483647', BLOC false

 KSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}]}

1 row(s) in 0.0430 seconds

hbase(main):008:0> alter 't', {NAME => 'cf1', VERSIONS => 50}
0 row(s) in 0.0630 seconds

hbase(main):009:0> describe 't'
DESCRIPTION

 ENABLED

 {NAME => 't', FAMILIES => [{NAME => 'cf1', BLOOMFILTER => 'ROWCOL',
REPLICATION_SCOPE => '0', VERSIONS => '50', COMPRESSION => 'LZO', TTL =>
'2147483647', BLOCK false

 SIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}]}

1 row(s) in 0.0460 seconds

hbase(main):010:0> alter 't', {NAME => 'cf2', VERSIONS => 50}
0 row(s) in 0.0570 seconds

hbase(main):011:0> describe 't'
DESCRIPTION

 ENABLED

 {NAME => 't', FAMILIES => [{NAME => 'cf1', BLOOMFILTER => 'ROWCOL',
REPLICATION_SCOPE => '0', COMPRESSION => 'LZO', VERSIONS => '50', TTL =>
'2147483647', BLOCK false

 SIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}, {NAME => 'cf2',
BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', COMPRESSION => 'NONE', VERSIONS
=

 > '50', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'false',
BLOCKCACHE => 'true'}]}

1 row(s) in 0.0440 seconds

DiffCamp Revision: 176127
Reviewed By: jgray
Commenters: kranganathan
CC: jgray, kranganathan, hbase@lists
Revert Plan:
OK

Modified:
    hbase/branches/0.89/src/main/ruby/hbase/admin.rb

Modified: hbase/branches/0.89/src/main/ruby/hbase/admin.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/ruby/hbase/admin.rb?rev=1181425&r1=1181424&r2=1181425&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/ruby/hbase/admin.rb (original)
+++ hbase/branches/0.89/src/main/ruby/hbase/admin.rb Tue Oct 11 02:07:29 2011
@@ -24,6 +24,8 @@ java_import org.apache.hadoop.hbase.clie
 java_import org.apache.zookeeper.ZooKeeperMain
 java_import org.apache.hadoop.hbase.HColumnDescriptor
 java_import org.apache.hadoop.hbase.HTableDescriptor
+java_import org.apache.hadoop.hbase.io.hfile.Compression
+java_import org.apache.hadoop.hbase.regionserver.StoreFile
 java_import org.apache.hadoop.hbase.HRegionInfo
 java_import org.apache.zookeeper.ZooKeeper
 
@@ -132,7 +134,7 @@ module Hbase
         end
 
         # Add column to the table
-        htd.addFamily(hcd(arg))
+        htd.addFamily(hcd(arg, htd))
       end
 
       # Perform the create table call
@@ -215,7 +217,7 @@ module Hbase
 
         # No method parameter, try to use the args as a column definition
         unless method = arg.delete(METHOD)
-          descriptor = hcd(arg)
+          descriptor = hcd(arg, htd)
           column_name = descriptor.getNameAsString
 
           # If column already exist, then try to alter it. Create otherwise.
@@ -313,29 +315,26 @@ module Hbase
 
     #----------------------------------------------------------------------------------------------
     # Return a new HColumnDescriptor made of passed args
-    def hcd(arg)
+    def hcd(arg, htd)
       # String arg, single parameter constructor
       return HColumnDescriptor.new(arg) if arg.kind_of?(String)
 
-      # TODO: This is brittle code.
-      # Here is current HCD constructor:
-      # public HColumnDescriptor(final byte [] familyName, final int maxVersions,
-      # final String compression, final boolean inMemory,
-      # final boolean blockCacheEnabled, final int blocksize,
-      # final int timeToLive, final boolean bloomFilter, final int scope) {
       raise(ArgumentError, "Column family #{arg} must have a name") unless name = arg[NAME]
 
-      # TODO: What encoding are Strings in jruby?
-      return HColumnDescriptor.new(name.to_java_bytes,
-        # JRuby uses longs for ints. Need to convert.  Also constants are String
-        arg.include?(VERSIONS)? JInteger.new(arg[VERSIONS]): HColumnDescriptor::DEFAULT_VERSIONS,
-        arg.include?(HColumnDescriptor::COMPRESSION)? arg[HColumnDescriptor::COMPRESSION]: HColumnDescriptor::DEFAULT_COMPRESSION,
-        arg.include?(IN_MEMORY)? JBoolean.valueOf(arg[IN_MEMORY]): HColumnDescriptor::DEFAULT_IN_MEMORY,
-        arg.include?(HColumnDescriptor::BLOCKCACHE)? JBoolean.valueOf(arg[HColumnDescriptor::BLOCKCACHE]): HColumnDescriptor::DEFAULT_BLOCKCACHE,
-        arg.include?(HColumnDescriptor::BLOCKSIZE)? JInteger.valueOf(arg[HColumnDescriptor::BLOCKSIZE]): HColumnDescriptor::DEFAULT_BLOCKSIZE,
-        arg.include?(HColumnDescriptor::TTL)? JInteger.new(arg[HColumnDescriptor::TTL]): HColumnDescriptor::DEFAULT_TTL,
-        arg.include?(HColumnDescriptor::BLOOMFILTER)? arg[HColumnDescriptor::BLOOMFILTER]: HColumnDescriptor::DEFAULT_BLOOMFILTER,
-        arg.include?(HColumnDescriptor::REPLICATION_SCOPE)? JInteger.new(arg[REPLICATION_SCOPE]): HColumnDescriptor::DEFAULT_REPLICATION_SCOPE)
+      family = htd.getFamily(name.to_java_bytes)
+      # create it if it's a new family
+      family ||= HColumnDescriptor.new(name.to_java_bytes)
+
+      family.setBlockCacheEnabled(JBoolean.valueOf(arg[HColumnDescriptor::BLOCKCACHE])) if arg.include?(HColumnDescriptor::BLOCKCACHE)
+      family.setBloomFilterType(StoreFile::BloomType.valueOf(arg[HColumnDescriptor::BLOOMFILTER])) if arg.include?(HColumnDescriptor::BLOOMFILTER)
+      family.setScope(JInteger.valueOf(arg[REPLICATION_SCOPE])) if arg.include?(HColumnDescriptor::REPLICATION_SCOPE)
+      family.setInMemory(JBoolean.valueOf(arg[IN_MEMORY])) if arg.include?(HColumnDescriptor::IN_MEMORY)
+      family.setTimeToLive(JInteger.valueOf(arg[HColumnDescriptor::TTL])) if arg.include?(HColumnDescriptor::TTL)
+      family.setCompressionType(Compression::Algorithm.valueOf(arg[HColumnDescriptor::COMPRESSION])) if arg.include?(HColumnDescriptor::COMPRESSION)
+      family.setBlocksize(JInteger.valueOf(arg[HColumnDescriptor::BLOCKSIZE])) if arg.include?(HColumnDescriptor::BLOCKSIZE)
+      family.setMaxVersions(JInteger.valueOf(arg[VERSIONS])) if arg.include?(HColumnDescriptor::VERSIONS)
+
+      return family
     end
 
     #----------------------------------------------------------------------------------------------