hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject git commit: HBASE-12329 Table create with duplicate column family names quietly succeeds (Jingcheng Du)
Date Thu, 06 Nov 2014 01:34:04 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 625a1ea06 -> 15f96c7a0


HBASE-12329 Table create with duplicate column family names quietly succeeds (Jingcheng Du)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/15f96c7a
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/15f96c7a
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/15f96c7a

Branch: refs/heads/branch-1
Commit: 15f96c7a00cceb92b797d852b4c95893e0077ba1
Parents: 625a1ea
Author: stack <stack@apache.org>
Authored: Wed Nov 5 17:32:21 2014 -0800
Committer: stack <stack@apache.org>
Committed: Wed Nov 5 17:33:54 2014 -0800

----------------------------------------------------------------------
 .../apache/hadoop/hbase/HTableDescriptor.java   | 24 +++++++++++++-
 .../client/UnmodifyableHTableDescriptor.java    |  5 +++
 .../hadoop/hbase/TestHTableDescriptor.java      | 35 ++++++++++++++++++++
 .../hadoop/hbase/master/MasterFileSystem.java   |  2 +-
 .../hbase/client/TestFromClientSide3.java       |  4 +--
 .../apache/hadoop/hbase/filter/TestFilter.java  |  1 -
 .../hbase/regionserver/TestRowTooBig.java       | 12 +++++--
 .../hadoop/hbase/regionserver/TestStore.java    |  6 +++-
 .../hbase/snapshot/SnapshotTestingUtils.java    |  1 -
 hbase-shell/src/main/ruby/hbase/admin.rb        |  9 ++++-
 10 files changed, 89 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/15f96c7a/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 cff5a40..fd0de03 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
@@ -779,11 +779,33 @@ public class HTableDescriptor implements WritableComparable<HTableDescriptor>
{
 
   /**
    * Adds a column family.
+   * For the updating purpose please use {@link #modifyFamily(HColumnDescriptor)} instead.
    * @param family HColumnDescriptor of family to add.
    */
   public HTableDescriptor addFamily(final HColumnDescriptor family) {
     if (family.getName() == null || family.getName().length <= 0) {
-      throw new NullPointerException("Family name cannot be null or empty");
+      throw new IllegalArgumentException("Family name cannot be null or empty");
+    }
+    if (hasFamily(family.getName())) {
+      throw new IllegalArgumentException("Family '" +
+        family.getNameAsString() + "' already exists so cannot be added");
+    }
+    this.families.put(family.getName(), family);
+    return this;
+  }
+
+  /**
+   * Modifies the existing column family.
+   * @param family HColumnDescriptor of family to update
+   * @return this (for chained invocation)
+   */
+  public HTableDescriptor modifyFamily(final HColumnDescriptor family) {
+    if (family.getName() == null || family.getName().length <= 0) {
+      throw new IllegalArgumentException("Family name cannot be null or empty");
+    }
+    if (!hasFamily(family.getName())) {
+      throw new IllegalArgumentException("Column family '" + family.getNameAsString()
+        + "' does not exist");
     }
     this.families.put(family.getName(), family);
     return this;

http://git-wip-us.apache.org/repos/asf/hbase/blob/15f96c7a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/UnmodifyableHTableDescriptor.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/UnmodifyableHTableDescriptor.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/UnmodifyableHTableDescriptor.java
index 9a58837..361e63e 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/UnmodifyableHTableDescriptor.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/UnmodifyableHTableDescriptor.java
@@ -67,6 +67,11 @@ public class UnmodifyableHTableDescriptor extends HTableDescriptor {
     throw new UnsupportedOperationException("HTableDescriptor is read-only");
   }
 
+  @Override
+  public HTableDescriptor modifyFamily(HColumnDescriptor family) {
+    throw new UnsupportedOperationException("HTableDescriptor is read-only");
+  }
+
   /**
    * @param column
    * @return Column descriptor for the passed family name or the family on

http://git-wip-us.apache.org/repos/asf/hbase/blob/15f96c7a/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
b/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
index 188d06e..25e20e9 100644
--- a/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
+++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
@@ -223,4 +223,39 @@ public class TestHTableDescriptor {
 
     BuilderStyleTest.assertClassesAreBuilderStyle(HTableDescriptor.class);
   }
+
+  @Test
+  public void testModifyFamily() {
+    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("table"));
+    byte[] familyName = Bytes.toBytes("cf");
+    HColumnDescriptor hcd = new HColumnDescriptor(familyName);
+    hcd.setBlocksize(1000);
+    htd.addFamily(hcd);
+    assertEquals(1000, htd.getFamily(familyName).getBlocksize());
+    hcd = new HColumnDescriptor(familyName);
+    hcd.setBlocksize(2000);
+    htd.modifyFamily(hcd);
+    assertEquals(2000, htd.getFamily(familyName).getBlocksize());
+  }
+
+  @Test(expected=IllegalArgumentException.class)
+  public void testModifyInexistentFamily() {
+    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("table"));
+    byte[] familyName = Bytes.toBytes("cf");
+    HColumnDescriptor hcd = new HColumnDescriptor(familyName);
+    htd.modifyFamily(hcd);
+  }
+
+  @Test(expected=IllegalArgumentException.class)
+  public void testAddDuplicateFamilies() {
+    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("table"));
+    byte[] familyName = Bytes.toBytes("cf");
+    HColumnDescriptor hcd = new HColumnDescriptor(familyName);
+    hcd.setBlocksize(1000);
+    htd.addFamily(hcd);
+    assertEquals(1000, htd.getFamily(familyName).getBlocksize());
+    hcd = new HColumnDescriptor(familyName);
+    hcd.setBlocksize(2000);
+    htd.addFamily(hcd);
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/15f96c7a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java
index f5677a1..3affa5a 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java
@@ -614,7 +614,7 @@ public class MasterFileSystem {
       throw new InvalidFamilyOperationException("Family '" +
         Bytes.toString(familyName) + "' doesn't exists so cannot be modified");
     }
-    htd.addFamily(hcd);
+    htd.modifyFamily(hcd);
     this.services.getTableDescriptors().add(htd);
     return htd;
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/15f96c7a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
index fee836f..a1ec82f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
@@ -221,7 +221,7 @@ public class TestFromClientSide3 {
     LOG.info("hbase.hstore.compaction.min should now be 2");
     HColumnDescriptor hcd = new HColumnDescriptor(htd.getFamily(FAMILY));
     hcd.setValue("hbase.hstore.compaction.min", String.valueOf(2));
-    htd.addFamily(hcd);
+    htd.modifyFamily(hcd);
     admin.modifyTable(TABLE, htd);
     while (null != (st = admin.getAlterStatus(TABLE)) && st.getFirst() > 0) {
       LOG.debug(st.getFirst() + " regions left to update");
@@ -256,7 +256,7 @@ public class TestFromClientSide3 {
     LOG.info("hbase.hstore.compaction.min should now be 5");
     hcd = new HColumnDescriptor(htd.getFamily(FAMILY));
     hcd.setValue("hbase.hstore.compaction.min", null);
-    htd.addFamily(hcd);
+    htd.modifyFamily(hcd);
     admin.modifyTable(TABLE, htd);
     while (null != (st = admin.getAlterStatus(TABLE)) && st.getFirst() > 0) {
       LOG.debug(st.getFirst() + " regions left to update");

http://git-wip-us.apache.org/repos/asf/hbase/blob/15f96c7a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java
index ec0f989..b71473e 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java
@@ -141,7 +141,6 @@ public class TestFilter {
     htd.addFamily(new HColumnDescriptor(FAMILIES_1[1]));
     htd.addFamily(new HColumnDescriptor(NEW_FAMILIES[0]));
     htd.addFamily(new HColumnDescriptor(NEW_FAMILIES[1]));
-    htd.addFamily(new HColumnDescriptor(FAMILIES_1[1]));
     HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
     this.region = HRegion.createHRegion(info, TEST_UTIL.getDataTestDir(),
             TEST_UTIL.getConfiguration(), htd);

http://git-wip-us.apache.org/repos/asf/hbase/blob/15f96c7a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowTooBig.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowTooBig.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowTooBig.java
index 573a5c9..f1df5f7 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowTooBig.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowTooBig.java
@@ -70,7 +70,11 @@ public class TestRowTooBig {
 
     HTableDescriptor htd = TEST_HTD;
     HColumnDescriptor hcd = new HColumnDescriptor(fam1);
-    htd.addFamily(hcd);
+    if (htd.hasFamily(hcd.getName())) {
+      htd.modifyFamily(hcd);
+    } else {
+      htd.addFamily(hcd);
+    }
 
     final HRegionInfo hri =
       new HRegionInfo(htd.getTableName(), HConstants.EMPTY_END_ROW,
@@ -108,7 +112,11 @@ public class TestRowTooBig {
 
     HTableDescriptor htd = TEST_HTD;
     HColumnDescriptor hcd = new HColumnDescriptor(fam1);
-    htd.addFamily(hcd);
+    if (htd.hasFamily(hcd.getName())) {
+      htd.modifyFamily(hcd);
+    } else {
+      htd.addFamily(hcd);
+    }
 
     final HRegionInfo hri =
       new HRegionInfo(htd.getTableName(), HConstants.EMPTY_END_ROW,

http://git-wip-us.apache.org/repos/asf/hbase/blob/15f96c7a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java
index acfe4ff..a2c99b3 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java
@@ -174,7 +174,11 @@ public class TestStore {
 
     fs.delete(logdir, true);
 
-    htd.addFamily(hcd);
+    if (htd.hasFamily(hcd.getName())) {
+      htd.modifyFamily(hcd);
+    } else {
+      htd.addFamily(hcd);
+    }
     HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
     HLog hlog = HLogFactory.createHLog(fs, basedir, logName, conf);
     HRegion region = new HRegion(tableDir, hlog, fs, conf, info, htd, null);

http://git-wip-us.apache.org/repos/asf/hbase/blob/15f96c7a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java
index 3da3b10..186436c 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java
@@ -552,7 +552,6 @@ public class SnapshotTestingUtils {
     private SnapshotBuilder createSnapshot(final String snapshotName, final int version)
         throws IOException {
       HTableDescriptor htd = createHtd(snapshotName);
-      htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
 
       RegionData[] regions = createTable(htd, TEST_NUM_REGIONS);
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/15f96c7a/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 100d3e9..52d9df7 100644
--- a/hbase-shell/src/main/ruby/hbase/admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/admin.rb
@@ -217,7 +217,14 @@ module Hbase
         if arg.kind_of?(String) or arg.has_key?(NAME)
           # If the arg is a string, default action is to add a column to the table.
           # If arg has a name, it must also be a column descriptor.
-          htd.addFamily(hcd(arg, htd))
+          descriptor = hcd(arg, htd);
+          # Warn if duplicate columns are added
+          if htd.hasFamily(descriptor.getName)
+            puts "Family '" + descriptor.getNameAsString() + "' already exists, the old one
will be replaced"
+            htd.modifyFamily(descriptor)
+          else
+            htd.addFamily(descriptor)
+          end
           has_columns = true
           next
         end


Mime
View raw message