You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by en...@apache.org on 2014/06/28 02:30:49 UTC
[03/49] git commit: HBASE-10348. HTableDescriptor changes for region
replicas
HBASE-10348. HTableDescriptor changes for region replicas
git-svn-id: https://svn.apache.org/repos/asf/hbase/branches/hbase-10070@1565658 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/481a116e
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/481a116e
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/481a116e
Branch: refs/heads/master
Commit: 481a116e26faea7472328420469b6aa72ce378f1
Parents: d8ea476
Author: Devaraj Das <dd...@apache.org>
Authored: Fri Feb 7 13:55:28 2014 +0000
Committer: Enis Soztutar <en...@apache.org>
Committed: Fri Jun 27 16:39:36 2014 -0700
----------------------------------------------------------------------
.../apache/hadoop/hbase/HTableDescriptor.java | 30 ++++++++++++++++++++
.../hadoop/hbase/TestHTableDescriptor.java | 2 ++
hbase-shell/src/main/ruby/hbase.rb | 1 +
hbase-shell/src/main/ruby/hbase/admin.rb | 4 +++
.../src/main/ruby/shell/commands/create.rb | 2 +-
5 files changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/481a116e/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java
index c1add47..08d0b6d 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java
@@ -182,6 +182,13 @@ public class HTableDescriptor implements WritableComparable<HTableDescriptor> {
private static final ImmutableBytesWritable DURABILITY_KEY =
new ImmutableBytesWritable(Bytes.toBytes("DURABILITY"));
+ /**
+ * <em>INTERNAL</em> number of region replicas for the table.
+ */
+ public static final String REGION_REPLICATION = "REGION_REPLICATION";
+ private static final ImmutableBytesWritable REGION_REPLICATION_KEY =
+ new ImmutableBytesWritable(Bytes.toBytes(REGION_REPLICATION));
+
/** Default durability for HTD is USE_DEFAULT, which defaults to HBase-global default value */
private static final Durability DEFAULT_DURABLITY = Durability.USE_DEFAULT;
@@ -214,6 +221,8 @@ public class HTableDescriptor implements WritableComparable<HTableDescriptor> {
*/
public static final long DEFAULT_MEMSTORE_FLUSH_SIZE = 1024*1024*128L;
+ public static final int DEFAULT_REGION_REPLICATION = 1;
+
private final static Map<String, String> DEFAULT_VALUES
= new HashMap<String, String>();
private final static Set<ImmutableBytesWritable> RESERVED_KEYWORDS
@@ -227,6 +236,7 @@ public class HTableDescriptor implements WritableComparable<HTableDescriptor> {
DEFAULT_VALUES.put(DEFERRED_LOG_FLUSH,
String.valueOf(DEFAULT_DEFERRED_LOG_FLUSH));
DEFAULT_VALUES.put(DURABILITY, DEFAULT_DURABLITY.name()); //use the enum name
+ DEFAULT_VALUES.put(REGION_REPLICATION, String.valueOf(DEFAULT_REGION_REPLICATION));
for (String s : DEFAULT_VALUES.keySet()) {
RESERVED_KEYWORDS.add(new ImmutableBytesWritable(Bytes.toBytes(s)));
}
@@ -1068,6 +1078,26 @@ public class HTableDescriptor implements WritableComparable<HTableDescriptor> {
}
/**
+ * Returns the configured replicas per region
+ */
+ public int getRegionReplication() {
+ byte[] val = getValue(REGION_REPLICATION_KEY);
+ if (val == null || val.length == 0) {
+ return DEFAULT_REGION_REPLICATION;
+ }
+ return Integer.parseInt(Bytes.toString(val));
+ }
+
+ /**
+ * Sets the number of replicas per region.
+ * @param regionReplication the replication factor per region
+ */
+ public void setRegionReplication(int regionReplication) {
+ setValue(REGION_REPLICATION_KEY,
+ new ImmutableBytesWritable(Bytes.toBytes(Integer.toString(regionReplication))));
+ }
+
+ /**
* Returns all the column family names of the current table. The map of
* HTableDescriptor contains mapping of family name to HColumnDescriptors.
* This returns all the keys of the family map which represents the column
http://git-wip-us.apache.org/repos/asf/hbase/blob/481a116e/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
index 82a132f..0c0b165 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
@@ -49,12 +49,14 @@ public class TestHTableDescriptor {
htd.setMaxFileSize(v);
htd.setDurability(Durability.ASYNC_WAL);
htd.setReadOnly(true);
+ htd.setRegionReplication(2);
byte [] bytes = htd.toByteArray();
HTableDescriptor deserializedHtd = HTableDescriptor.parseFrom(bytes);
assertEquals(htd, deserializedHtd);
assertEquals(v, deserializedHtd.getMaxFileSize());
assertTrue(deserializedHtd.isReadOnly());
assertEquals(Durability.ASYNC_WAL, deserializedHtd.getDurability());
+ assertEquals(deserializedHtd.getRegionReplication(), 2);
}
/**
http://git-wip-us.apache.org/repos/asf/hbase/blob/481a116e/hbase-shell/src/main/ruby/hbase.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/hbase.rb b/hbase-shell/src/main/ruby/hbase.rb
index 7ac5e0d..bbff134 100644
--- a/hbase-shell/src/main/ruby/hbase.rb
+++ b/hbase-shell/src/main/ruby/hbase.rb
@@ -57,6 +57,7 @@ module HBaseConstants
SPLITS_FILE = 'SPLITS_FILE'
SPLITALGO = 'SPLITALGO'
NUMREGIONS = 'NUMREGIONS'
+ REGION_REPLICATION = 'REGION_REPLICATION'
CONFIGURATION = org.apache.hadoop.hbase.HConstants::CONFIGURATION
ATTRIBUTES="ATTRIBUTES"
VISIBILITY="VISIBILITY"
http://git-wip-us.apache.org/repos/asf/hbase/blob/481a116e/hbase-shell/src/main/ruby/hbase/admin.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb
index 43ccad3..46d2883 100644
--- a/hbase-shell/src/main/ruby/hbase/admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/admin.rb
@@ -220,6 +220,10 @@ module Hbase
has_columns = true
next
end
+ if arg.has_key?(REGION_REPLICATION)
+ region_replication = JInteger.valueOf(arg.delete(REGION_REPLICATION))
+ htd.setRegionReplication(region_replication)
+ end
# Get rid of the "METHOD", which is deprecated for create.
# We'll do whatever it used to do below if it's table_att.
http://git-wip-us.apache.org/repos/asf/hbase/blob/481a116e/hbase-shell/src/main/ruby/shell/commands/create.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/create.rb b/hbase-shell/src/main/ruby/shell/commands/create.rb
index cd0fdea..ab3a3d1 100644
--- a/hbase-shell/src/main/ruby/shell/commands/create.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/create.rb
@@ -49,7 +49,7 @@ Examples:
hbase> # Optionally pre-split the table into NUMREGIONS, using
hbase> # SPLITALGO ("HexStringSplit", "UniformSplit" or classname)
hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}
- hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit', CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}}
+ hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit', REGION_REPLICATION => 2, CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}}
You can also keep around a reference to the created table: