Search in sources :

Example 96 with HColumnDescriptor

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();
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) ArrayList(java.util.ArrayList)

Example 97 with HColumnDescriptor

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);
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 98 with HColumnDescriptor

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);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 99 with HColumnDescriptor

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);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 100 with HColumnDescriptor

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());
}
Also used : HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Test(org.junit.Test)

Aggregations

HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)671 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)554 Test (org.junit.Test)358 TableName (org.apache.hadoop.hbase.TableName)200 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)137 Put (org.apache.hadoop.hbase.client.Put)132 Table (org.apache.hadoop.hbase.client.Table)117 Admin (org.apache.hadoop.hbase.client.Admin)110 IOException (java.io.IOException)109 Path (org.apache.hadoop.fs.Path)81 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)71 ArrayList (java.util.ArrayList)66 Configuration (org.apache.hadoop.conf.Configuration)65 Connection (org.apache.hadoop.hbase.client.Connection)51 Scan (org.apache.hadoop.hbase.client.Scan)50 Result (org.apache.hadoop.hbase.client.Result)45 FileSystem (org.apache.hadoop.fs.FileSystem)44 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)42 Connection (java.sql.Connection)41 Properties (java.util.Properties)38