hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeffr...@apache.org
Subject svn commit: r1571529 - in /hbase/trunk/hbase-server/src: main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java
Date Tue, 25 Feb 2014 01:58:01 GMT
Author: jeffreyz
Date: Tue Feb 25 01:58:01 2014
New Revision: 1571529

URL: http://svn.apache.org/r1571529
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/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java?rev=1571529&r1=1571528&r2=1571529&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java
Tue Feb 25 01:58:01 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/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java?rev=1571529&r1=1571528&r2=1571529&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java
Tue Feb 25 01:58:01 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);
+    }
+  }
+}



Mime
View raw message