HBASE-10582: 0.94->0.96 Upgrade: ACL can't be repopulated when ACL table contains row for table '-ROOT' or '.META.'
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1571529 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3fe9d15c18
commit
577c1ee7d7
|
@ -453,21 +453,43 @@ public class NamespaceUpgrade implements Tool {
|
|||
* @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
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue