You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by je...@apache.org on 2014/02/25 03:04:23 UTC

svn commit: r1571536 - in /hbase/branches/0.96/hbase-server/src: main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java

Author: jeffreyz
Date: Tue Feb 25 02:04:23 2014
New Revision: 1571536

URL: http://svn.apache.org/r1571536
Log:
HBASE-10582: 0.94->0.96 Upgrade: ACL can't be repopulated when ACL table contains row for table '-ROOT' or '.META.'

Modified:
    hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java
    hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java

Modified: hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java?rev=1571536&r1=1571535&r2=1571536&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java (original)
+++ hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java Tue Feb 25 02:04:23 2014
@@ -453,21 +453,43 @@ public class NamespaceUpgrade implements
    * @param region
    * @throws IOException
    */
-  private void updateAcls(HRegion region) throws IOException {
+  void updateAcls(HRegion region) throws IOException {
     byte[] rowKey = Bytes.toBytes(NamespaceUpgrade.OLD_ACL);
     // get the old _acl_ entry, if present.
     Get g = new Get(rowKey);
     Result r = region.get(g);
-    if (r == null || r.size() == 0) return;
-    // create a put for new _acl_ entry with rowkey as hbase:acl
-    Put p = new Put(AccessControlLists.ACL_GLOBAL_NAME);
-    for (Cell c : r.rawCells()) {
-      p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c));
+    if (r != null && r.size() > 0) {
+      // create a put for new _acl_ entry with rowkey as hbase:acl
+      Put p = new Put(AccessControlLists.ACL_GLOBAL_NAME);
+      for (Cell c : r.rawCells()) {
+        p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c));
+      }
+      region.put(p);
+      // delete the old entry
+      Delete del = new Delete(rowKey);
+      region.delete(del);
     }
-    region.put(p);
-    // delete the old entry
+
+    // delete the old entry for '-ROOT-'
+    rowKey = Bytes.toBytes(TableName.OLD_ROOT_STR);
     Delete del = new Delete(rowKey);
     region.delete(del);
+
+    // rename .META. to hbase:meta
+    rowKey = Bytes.toBytes(TableName.OLD_META_STR);
+    g = new Get(rowKey);
+    r = region.get(g);
+    if (r != null && r.size() > 0) {
+      // create a put for new .META. entry with rowkey as hbase:meta
+      Put p = new Put(TableName.META_TABLE_NAME.getName());
+      for (Cell c : r.rawCells()) {
+        p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c));
+      }
+      region.put(p);
+      // delete the old entry
+      del = new Delete(rowKey);
+      region.delete(del);
+    }
   }
 
   //Culled from FSTableDescriptors

Modified: hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java?rev=1571536&r1=1571535&r2=1571536&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java (original)
+++ hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java Tue Feb 25 02:04:23 2014
@@ -35,20 +35,29 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.fs.FsShell;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.MediumTests;
 import org.apache.hadoop.hbase.NamespaceDescriptor;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.Waiter;
+import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.ResultScanner;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos;
 import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.hadoop.hbase.regionserver.HRegionFileSystem;
 import org.apache.hadoop.hbase.security.access.AccessControlLists;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.FSTableDescriptors;
 import org.apache.hadoop.hbase.util.FSUtils;
 import org.apache.hadoop.util.ToolRunner;
 import org.junit.AfterClass;
@@ -283,4 +292,59 @@ public class TestNamespaceUpgrade {
       assertTrue(dir, fs.exists(new Path(hbaseRootDir, dir)));
     }
   }
-}
\ No newline at end of file
+
+  @Test (timeout = 300000)
+  public void testACLTableMigration() throws IOException {
+    Path rootDir = TEST_UTIL.getDataTestDirOnTestFS("testACLTable");
+    FileSystem fs = TEST_UTIL.getTestFileSystem();
+    Configuration conf = TEST_UTIL.getConfiguration();
+    byte[] FAMILY = Bytes.toBytes("l");
+    byte[] QUALIFIER = Bytes.toBytes("testUser");
+    byte[] VALUE = Bytes.toBytes("RWCA");
+
+    // Create a Region
+    HTableDescriptor aclTable = new HTableDescriptor(TableName.valueOf("testACLTable"));
+    aclTable.addFamily(new HColumnDescriptor(FAMILY));
+    FSTableDescriptors fstd = new FSTableDescriptors(fs, rootDir);
+    fstd.createTableDescriptor(aclTable);
+    HRegionInfo hriAcl = new HRegionInfo(aclTable.getTableName(), null, null);
+    HRegion region = HRegion.createHRegion(hriAcl, rootDir, conf, aclTable);
+    try {
+      // Create rows
+      Put p = new Put(Bytes.toBytes("-ROOT-"));
+      p.addImmutable(FAMILY, QUALIFIER, VALUE);
+      region.put(p);
+      p = new Put(Bytes.toBytes(".META."));
+      p.addImmutable(FAMILY, QUALIFIER, VALUE);
+      region.put(p);
+      p = new Put(Bytes.toBytes("_acl_"));
+      p.addImmutable(FAMILY, QUALIFIER, VALUE);
+      region.put(p);
+
+      NamespaceUpgrade upgrade = new NamespaceUpgrade();
+      upgrade.updateAcls(region);
+
+      // verify rows -ROOT- is removed
+      Get g = new Get(Bytes.toBytes("-ROOT-"));
+      Result r = region.get(g);
+      assertTrue(r == null || r.size() == 0);
+
+      // verify rows _acl_ is renamed to hbase:acl
+      g = new Get(AccessControlLists.ACL_TABLE_NAME.toBytes());
+      r = region.get(g);
+      assertTrue(r != null && r.size() == 1);
+      assertTrue(Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIER)) == 0);
+
+      // verify rows .META. is renamed to hbase:meta
+      g = new Get(TableName.META_TABLE_NAME.toBytes());
+      r = region.get(g);
+      assertTrue(r != null && r.size() == 1);
+      assertTrue(Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIER)) == 0);
+    } finally {
+      region.close();
+      // Delete the region
+      HRegionFileSystem.deleteRegionFromFileSystem(conf, fs,
+        FSUtils.getTableDir(rootDir, hriAcl.getTable()), hriAcl);
+    }
+  }
+}