Search in sources :

Example 71 with TableDescriptorBuilder

use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.

the class TestHRegionReplayEvents method setUp.

@Before
public void setUp() throws Exception {
    CONF = TEST_UTIL.getConfiguration();
    dir = TEST_UTIL.getDataTestDir("TestHRegionReplayEvents").toString();
    method = name.getMethodName();
    tableName = Bytes.toBytes(name.getMethodName());
    rootDir = new Path(dir + method);
    TEST_UTIL.getConfiguration().set(HConstants.HBASE_DIR, rootDir.toString());
    method = name.getMethodName();
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TableName.valueOf(method));
    for (byte[] family : families) {
        builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
    }
    htd = builder.build();
    long time = EnvironmentEdgeManager.currentTime();
    ChunkCreator.initialize(MemStoreLAB.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null, MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT);
    primaryHri = RegionInfoBuilder.newBuilder(htd.getTableName()).setRegionId(time).setReplicaId(0).build();
    secondaryHri = RegionInfoBuilder.newBuilder(htd.getTableName()).setRegionId(time).setReplicaId(1).build();
    WALFactory wals = TestHRegion.createWALFactory(CONF, rootDir);
    walPrimary = wals.getWAL(primaryHri);
    walSecondary = wals.getWAL(secondaryHri);
    rss = mock(RegionServerServices.class);
    when(rss.getServerName()).thenReturn(ServerName.valueOf("foo", 1, 1));
    when(rss.getConfiguration()).thenReturn(CONF);
    when(rss.getRegionServerAccounting()).thenReturn(new RegionServerAccounting(CONF));
    String string = org.apache.hadoop.hbase.executor.EventType.RS_COMPACTED_FILES_DISCHARGER.toString();
    ExecutorService es = new ExecutorService(string);
    es.startExecutorService(es.new ExecutorConfig().setCorePoolSize(1).setExecutorType(ExecutorType.RS_COMPACTED_FILES_DISCHARGER));
    when(rss.getExecutorService()).thenReturn(es);
    primaryRegion = HRegion.createHRegion(primaryHri, rootDir, CONF, htd, walPrimary);
    primaryRegion.close();
    List<HRegion> regions = new ArrayList<>();
    regions.add(primaryRegion);
    Mockito.doReturn(regions).when(rss).getRegions();
    primaryRegion = HRegion.openHRegion(rootDir, primaryHri, htd, walPrimary, CONF, rss, null);
    secondaryRegion = HRegion.openHRegion(secondaryHri, htd, null, CONF, rss, null);
    reader = null;
}
Also used : Path(org.apache.hadoop.fs.Path) ArrayList(java.util.ArrayList) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ExecutorService(org.apache.hadoop.hbase.executor.ExecutorService) WALFactory(org.apache.hadoop.hbase.wal.WALFactory) Before(org.junit.Before)

Example 72 with TableDescriptorBuilder

use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.

the class TestFSTableDescriptors method testTableDescriptorsNoCache.

@Test
public void testTableDescriptorsNoCache() throws IOException, InterruptedException {
    FileSystem fs = FileSystem.get(UTIL.getConfiguration());
    // Cleanup old tests if any debris laying around.
    FSTableDescriptors htds = new FSTableDescriptorsTest(fs, testDir, false);
    final int count = 10;
    // Write out table infos.
    for (int i = 0; i < count; i++) {
        htds.createTableDescriptor(TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName() + i)).build());
    }
    for (int i = 0; i < 2 * count; i++) {
        assertNotNull("Expected HTD, got null instead", htds.get(TableName.valueOf(name.getMethodName() + i % 2)));
    }
    // Update the table infos
    for (int i = 0; i < count; i++) {
        TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName() + i));
        builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of("" + i));
        htds.update(builder.build());
    }
    for (int i = 0; i < count; i++) {
        assertNotNull("Expected HTD, got null instead", htds.get(TableName.valueOf(name.getMethodName() + i)));
        assertTrue("Column Family " + i + " missing", htds.get(TableName.valueOf(name.getMethodName() + i)).hasColumnFamily(Bytes.toBytes("" + i)));
    }
    assertEquals(count * 4, htds.invocations);
    assertEquals("expected=0, actual=" + htds.cachehits, 0, htds.cachehits);
}
Also used : FileSystem(org.apache.hadoop.fs.FileSystem) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Test(org.junit.Test)

Example 73 with TableDescriptorBuilder

use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.

the class TestFSTableDescriptors method testTableDescriptors.

@Test
public void testTableDescriptors() throws IOException, InterruptedException {
    FileSystem fs = FileSystem.get(UTIL.getConfiguration());
    // Cleanup old tests if any debris laying around.
    FSTableDescriptors htds = new FSTableDescriptors(fs, testDir) {

        @Override
        public TableDescriptor get(TableName tablename) {
            LOG.info(tablename + ", cachehits=" + this.cachehits);
            return super.get(tablename);
        }
    };
    final int count = 10;
    // Write out table infos.
    for (int i = 0; i < count; i++) {
        htds.createTableDescriptor(TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName() + i)).build());
    }
    for (int i = 0; i < count; i++) {
        assertTrue(htds.get(TableName.valueOf(name.getMethodName() + i)) != null);
    }
    for (int i = 0; i < count; i++) {
        assertTrue(htds.get(TableName.valueOf(name.getMethodName() + i)) != null);
    }
    // Update the table infos
    for (int i = 0; i < count; i++) {
        TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName() + i));
        builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of("" + i));
        htds.update(builder.build());
    }
    // Wait a while so mod time we write is for sure different.
    Thread.sleep(100);
    for (int i = 0; i < count; i++) {
        assertTrue(htds.get(TableName.valueOf(name.getMethodName() + i)) != null);
    }
    for (int i = 0; i < count; i++) {
        assertTrue(htds.get(TableName.valueOf(name.getMethodName() + i)) != null);
    }
    assertEquals(count * 4, htds.invocations);
    assertTrue("expected=" + (count * 2) + ", actual=" + htds.cachehits, htds.cachehits >= (count * 2));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) FileSystem(org.apache.hadoop.fs.FileSystem) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Test(org.junit.Test)

Example 74 with TableDescriptorBuilder

use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.

the class TestHBaseFsckEncryption method setUp.

@Before
public void setUp() throws Exception {
    conf = TEST_UTIL.getConfiguration();
    conf.setInt("hfile.format.version", 3);
    conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
    conf.set(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, "hbase");
    // Create the test encryption key
    SecureRandom rng = new SecureRandom();
    byte[] keyBytes = new byte[AES.KEY_LENGTH];
    rng.nextBytes(keyBytes);
    String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES);
    cfKey = new SecretKeySpec(keyBytes, algorithm);
    // Start the minicluster
    TEST_UTIL.startMiniCluster(3);
    // Create the table
    TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(TableName.valueOf("default", "TestHBaseFsckEncryption"));
    ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf")).setEncryptionType(algorithm).setEncryptionKey(EncryptionUtil.wrapKey(conf, conf.get(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, User.getCurrent().getShortName()), cfKey)).build();
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
    tableDescriptor = tableDescriptorBuilder.build();
    TEST_UTIL.getAdmin().createTable(tableDescriptor);
    TEST_UTIL.waitTableAvailable(tableDescriptor.getTableName(), 5000);
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) SecureRandom(java.security.SecureRandom) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) KeyProviderForTesting(org.apache.hadoop.hbase.io.crypto.KeyProviderForTesting) Before(org.junit.Before)

Example 75 with TableDescriptorBuilder

use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.

the class TestRegionReplicaSplit method createTableAndLoadData.

private static Table createTableAndLoadData(final TableName tableName) throws IOException {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    builder.setRegionReplication(3);
    // create a table with 3 replication
    Table table = HTU.createTable(builder.build(), new byte[][] { f }, getSplits(2), new Configuration(HTU.getConfiguration()));
    HTU.loadTable(HTU.getConnection().getTable(tableName), f);
    HTU.flush(tableName);
    return table;
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Configuration(org.apache.hadoop.conf.Configuration) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder)

Aggregations

TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)190 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)76 Test (org.junit.Test)68 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)61 ColumnFamilyDescriptorBuilder (org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder)47 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)39 TableName (org.apache.hadoop.hbase.TableName)34 Path (org.apache.hadoop.fs.Path)31 Admin (org.apache.hadoop.hbase.client.Admin)29 Put (org.apache.hadoop.hbase.client.Put)25 IOException (java.io.IOException)24 Configuration (org.apache.hadoop.conf.Configuration)20 Table (org.apache.hadoop.hbase.client.Table)18 ArrayList (java.util.ArrayList)17 FileSystem (org.apache.hadoop.fs.FileSystem)15 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)15 Before (org.junit.Before)12 Cell (org.apache.hadoop.hbase.Cell)11 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)10 HashMap (java.util.HashMap)9