use of org.apache.hadoop.hbase.HColumnDescriptor in project hbase by apache.
the class TestSnapshotMetadata method runRestoreWithAdditionalMetadata.
private void runRestoreWithAdditionalMetadata(boolean changeMetadata, boolean addData) throws Exception {
if (admin.isTableDisabled(originalTableName)) {
admin.enableTable(originalTableName);
}
// populate it with data
final byte[] familyForUpdate = BLOCKSIZE_FAM;
List<byte[]> familiesWithDataList = new ArrayList<>();
List<byte[]> emptyFamiliesList = new ArrayList<>();
if (addData) {
Table original = UTIL.getConnection().getTable(originalTableName);
// family arbitrarily chosen
UTIL.loadTable(original, familyForUpdate);
original.close();
for (byte[] family : families) {
if (family != familyForUpdate) {
emptyFamiliesList.add(family);
}
}
familiesWithDataList.add(familyForUpdate);
} else {
Collections.addAll(emptyFamiliesList, families);
}
// take a "disabled" snapshot
final String snapshotNameAsString = "snapshot" + originalTableName + System.currentTimeMillis();
final byte[] snapshotName = Bytes.toBytes(snapshotNameAsString);
SnapshotTestingUtils.createSnapshotAndValidate(admin, originalTableName, familiesWithDataList, emptyFamiliesList, snapshotNameAsString, rootDir, fs, /* onlineSnapshot= */
false);
admin.enableTable(originalTableName);
if (changeMetadata) {
final String newFamilyNameAsString = "newFamily" + System.currentTimeMillis();
final byte[] newFamilyName = Bytes.toBytes(newFamilyNameAsString);
admin.disableTable(originalTableName);
HColumnDescriptor hcd = new HColumnDescriptor(newFamilyName);
admin.addColumnFamily(originalTableName, hcd);
assertTrue("New column family was not added.", admin.getTableDescriptor(originalTableName).toString().contains(newFamilyNameAsString));
}
// restore it
if (!admin.isTableDisabled(originalTableName)) {
admin.disableTable(originalTableName);
}
admin.restoreSnapshot(snapshotName);
admin.enableTable(originalTableName);
// verify that the descrption is reverted
Table original = UTIL.getConnection().getTable(originalTableName);
try {
assertTrue(originalTableDescriptor.equals(admin.getTableDescriptor(originalTableName)));
assertTrue(originalTableDescriptor.equals(original.getTableDescriptor()));
} finally {
original.close();
}
}
use of org.apache.hadoop.hbase.HColumnDescriptor in project hbase by apache.
the class TestReplicationAdminWithClusters method testEnableReplicationWhenReplicationNotEnabled.
@Test(timeout = 300000)
public void testEnableReplicationWhenReplicationNotEnabled() throws Exception {
HTableDescriptor table = admin1.getTableDescriptor(tableName);
for (HColumnDescriptor fam : table.getColumnFamilies()) {
fam.setScope(HConstants.REPLICATION_SCOPE_LOCAL);
}
admin1.disableTable(tableName);
admin1.modifyTable(tableName, table);
admin1.enableTable(tableName);
admin2.disableTable(tableName);
admin2.modifyTable(tableName, table);
admin2.enableTable(tableName);
admin1.enableTableReplication(tableName);
table = admin1.getTableDescriptor(tableName);
for (HColumnDescriptor fam : table.getColumnFamilies()) {
assertEquals(fam.getScope(), HConstants.REPLICATION_SCOPE_GLOBAL);
}
}
use of org.apache.hadoop.hbase.HColumnDescriptor in project hbase by apache.
the class TestConstraint method testConstraintPasses.
/**
* Test that we run a passing constraint
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Test
public void testConstraintPasses() throws Exception {
// create the table
// it would be nice if this was also a method on the util
HTableDescriptor desc = new HTableDescriptor(tableName);
for (byte[] family : new byte[][] { dummy, test }) {
desc.addFamily(new HColumnDescriptor(family));
}
// add a constraint
Constraints.add(desc, CheckWasRunConstraint.class);
util.getAdmin().createTable(desc);
Table table = util.getConnection().getTable(tableName);
try {
// test that we don't fail on a valid put
Put put = new Put(row1);
byte[] value = Integer.toString(10).getBytes();
byte[] qualifier = new byte[0];
put.addColumn(dummy, qualifier, value);
table.put(put);
} finally {
table.close();
}
assertTrue(CheckWasRunConstraint.wasRun);
}
use of org.apache.hadoop.hbase.HColumnDescriptor in project hbase by apache.
the class TestConstraint method testDisableConstraint.
/**
* Check that if we just disable one constraint, then
* @throws Throwable
*/
@SuppressWarnings("unchecked")
@Test
public void testDisableConstraint() throws Throwable {
// create the table
HTableDescriptor desc = new HTableDescriptor(tableName);
// add a family to the table
for (byte[] family : new byte[][] { dummy, test }) {
desc.addFamily(new HColumnDescriptor(family));
}
// add a constraint to make sure it others get run
Constraints.add(desc, CheckWasRunConstraint.class);
// Add Constraint to check
Constraints.add(desc, AllFailConstraint.class);
// and then disable the failing constraint
Constraints.disableConstraint(desc, AllFailConstraint.class);
util.getAdmin().createTable(desc);
Table table = util.getConnection().getTable(tableName);
try {
// test that we don't fail because its disabled
Put put = new Put(row1);
byte[] qualifier = new byte[0];
put.addColumn(dummy, qualifier, "pass".getBytes());
table.put(put);
} finally {
table.close();
}
assertTrue(CheckWasRunConstraint.wasRun);
}
use of org.apache.hadoop.hbase.HColumnDescriptor in project hbase by apache.
the class TestPrefetch method testPrefetchSetInHCDWorks.
@Test
public void testPrefetchSetInHCDWorks() {
HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toBytes("f"));
hcd.setPrefetchBlocksOnOpen(true);
Configuration c = HBaseConfiguration.create();
assertFalse(c.getBoolean(CacheConfig.PREFETCH_BLOCKS_ON_OPEN_KEY, false));
CacheConfig cc = new CacheConfig(c, hcd);
assertTrue(cc.shouldPrefetchOnOpen());
}
Aggregations