Search in sources :

Example 26 with ColumnFamilyDescriptor

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

the class TestCompactionPolicy method initialize.

/**
 * Setting up a Store
 * @throws IOException with error
 */
protected void initialize() throws IOException {
    Path basedir = new Path(DIR);
    String logName = "logs";
    Path logdir = new Path(DIR, logName);
    ColumnFamilyDescriptor familyDescriptor = ColumnFamilyDescriptorBuilder.of(Bytes.toBytes("family"));
    FileSystem fs = FileSystem.get(conf);
    fs.delete(logdir, true);
    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TableName.valueOf(Bytes.toBytes("table"))).setColumnFamily(familyDescriptor).build();
    RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
    hlog = new FSHLog(fs, basedir, logName, conf);
    hlog.init();
    ChunkCreator.initialize(MemStoreLAB.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null, MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT);
    region = HRegion.createHRegion(info, basedir, conf, tableDescriptor, hlog);
    region.close();
    Path tableDir = CommonFSUtils.getTableDir(basedir, tableDescriptor.getTableName());
    region = new HRegion(tableDir, hlog, fs, conf, info, tableDescriptor, null);
    store = new HStore(region, familyDescriptor, conf, false);
    TEST_FILE = region.getRegionFileSystem().createTempName();
    fs.createNewFile(TEST_FILE);
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) FSHLog(org.apache.hadoop.hbase.regionserver.wal.FSHLog)

Example 27 with ColumnFamilyDescriptor

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

the class TestDeleteMobTable method testDeleteNonMobTable.

@Test
public void testDeleteNonMobTable() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    TableDescriptor htd = createTableDescriptor(tableName, false);
    ColumnFamilyDescriptor hcd = htd.getColumnFamily(FAMILY);
    Table table = createTableWithOneFile(htd);
    try {
        // the mob file doesn't exist
        Assert.assertEquals(0, countMobFiles(tableName, hcd.getNameAsString()));
        Assert.assertEquals(0, countArchiveMobFiles(tableName, hcd.getNameAsString()));
        Assert.assertFalse(mobTableDirExist(tableName));
    } finally {
        table.close();
        TEST_UTIL.deleteTable(tableName);
    }
    Assert.assertFalse(TEST_UTIL.getAdmin().tableExists(tableName));
    Assert.assertEquals(0, countMobFiles(tableName, hcd.getNameAsString()));
    Assert.assertEquals(0, countArchiveMobFiles(tableName, hcd.getNameAsString()));
    Assert.assertFalse(mobTableDirExist(tableName));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

Example 28 with ColumnFamilyDescriptor

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

the class TestDeleteMobTable method testMobFamilyDelete.

@Test
public void testMobFamilyDelete() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    TableDescriptor tableDescriptor = createTableDescriptor(tableName, true);
    ColumnFamilyDescriptor familyDescriptor = tableDescriptor.getColumnFamily(FAMILY);
    tableDescriptor = TableDescriptorBuilder.newBuilder(tableDescriptor).setColumnFamily(ColumnFamilyDescriptorBuilder.of(Bytes.toBytes("family2"))).build();
    Table table = createTableWithOneFile(tableDescriptor);
    try {
        // the mob file exists
        Assert.assertEquals(1, countMobFiles(tableName, familyDescriptor.getNameAsString()));
        Assert.assertEquals(0, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString()));
        String fileName = assertHasOneMobRow(table, tableName, familyDescriptor.getNameAsString());
        Assert.assertFalse(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName));
        Assert.assertTrue(mobTableDirExist(tableName));
        TEST_UTIL.getAdmin().deleteColumnFamily(tableName, FAMILY);
        Assert.assertEquals(0, countMobFiles(tableName, familyDescriptor.getNameAsString()));
        Assert.assertEquals(1, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString()));
        Assert.assertTrue(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName));
        Assert.assertFalse(mobColumnFamilyDirExist(tableName, familyDescriptor.getNameAsString()));
    } finally {
        table.close();
        TEST_UTIL.deleteTable(tableName);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

Example 29 with ColumnFamilyDescriptor

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

the class TestThriftConnection method testThriftAdmin.

private void testThriftAdmin(Connection connection, String namespace, String table) throws Exception {
    try (Admin admin = connection.getAdmin()) {
        // create name space
        NamespaceDescriptor namespaceDescriptor = NamespaceDescriptor.create(namespace).build();
        namespaceDescriptor.setConfiguration("key1", "value1");
        namespaceDescriptor.setConfiguration("key2", "value2");
        admin.createNamespace(namespaceDescriptor);
        // list namespace
        NamespaceDescriptor[] namespaceDescriptors = admin.listNamespaceDescriptors();
        boolean found = false;
        for (NamespaceDescriptor nd : namespaceDescriptors) {
            if (nd.getName().equals(namespace)) {
                found = true;
                break;
            }
        }
        assertTrue(found);
        // modify namesapce
        namespaceDescriptor.setConfiguration("kye3", "value3");
        admin.modifyNamespace(namespaceDescriptor);
        // get namespace
        NamespaceDescriptor namespaceDescriptorReturned = admin.getNamespaceDescriptor(namespace);
        assertTrue(namespaceDescriptorReturned.getConfiguration().size() == 3);
        // create table
        TableDescriptor tableDescriptor = createTable(admin, table);
        // modify table
        TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor);
        builder.setDurability(Durability.ASYNC_WAL);
        admin.modifyTable(builder.build());
        // modify column family
        ColumnFamilyDescriptor familyA = tableDescriptor.getColumnFamily(FAMILYA);
        ColumnFamilyDescriptorBuilder familyABuilder = ColumnFamilyDescriptorBuilder.newBuilder(familyA);
        familyABuilder.setInMemory(true);
        admin.modifyColumnFamily(tableDescriptor.getTableName(), familyABuilder.build());
        // add column family
        ColumnFamilyDescriptorBuilder familyDBuilder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILYD);
        familyDBuilder.setDataBlockEncoding(DataBlockEncoding.PREFIX);
        admin.addColumnFamily(tableDescriptor.getTableName(), familyDBuilder.build());
        // get table descriptor
        TableDescriptor tableDescriptorReturned = admin.getDescriptor(tableDescriptor.getTableName());
        assertTrue(tableDescriptorReturned.getColumnFamilies().length == 4);
        assertTrue(tableDescriptorReturned.getDurability() == Durability.ASYNC_WAL);
        ColumnFamilyDescriptor columnFamilyADescriptor1Returned = tableDescriptorReturned.getColumnFamily(FAMILYA);
        assertTrue(columnFamilyADescriptor1Returned.isInMemory() == true);
        // delete column family
        admin.deleteColumnFamily(tableDescriptor.getTableName(), FAMILYA);
        tableDescriptorReturned = admin.getDescriptor(tableDescriptor.getTableName());
        assertTrue(tableDescriptorReturned.getColumnFamilies().length == 3);
        // disable table
        admin.disableTable(tableDescriptor.getTableName());
        assertTrue(admin.isTableDisabled(tableDescriptor.getTableName()));
        // enable table
        admin.enableTable(tableDescriptor.getTableName());
        assertTrue(admin.isTableEnabled(tableDescriptor.getTableName()));
        assertTrue(admin.isTableAvailable(tableDescriptor.getTableName()));
        // truncate table
        admin.disableTable(tableDescriptor.getTableName());
        admin.truncateTable(tableDescriptor.getTableName(), true);
        assertTrue(admin.isTableAvailable(tableDescriptor.getTableName()));
        // delete table
        admin.disableTable(tableDescriptor.getTableName());
        admin.deleteTable(tableDescriptor.getTableName());
        assertFalse(admin.tableExists(tableDescriptor.getTableName()));
        // delete namespace
        admin.deleteNamespace(namespace);
        namespaceDescriptors = admin.listNamespaceDescriptors();
        // should have 2 namespace, default and hbase
        found = false;
        for (NamespaceDescriptor nd : namespaceDescriptors) {
            if (nd.getName().equals(namespace)) {
                found = true;
                break;
            }
        }
        assertTrue(found == false);
    }
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Admin(org.apache.hadoop.hbase.client.Admin) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 30 with ColumnFamilyDescriptor

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

the class TestThriftServer method testMetricsWithException.

@Test
public void testMetricsWithException() throws Exception {
    String rowkey = "row1";
    String family = "f";
    String col = "c";
    // create a table which will throw exceptions for requests
    final TableName tableName = TableName.valueOf(name.getMethodName());
    try {
        ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family)).build();
        TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName).setCoprocessor(ErrorThrowingGetObserver.class.getName()).setColumnFamily(columnFamilyDescriptor).build();
        Table table = UTIL.createTable(tableDescriptor, null);
        long now = EnvironmentEdgeManager.currentTime();
        table.put(new Put(Bytes.toBytes(rowkey)).addColumn(Bytes.toBytes(family), Bytes.toBytes(col), now, Bytes.toBytes("val1")));
        Configuration conf = UTIL.getConfiguration();
        ThriftMetrics metrics = getMetrics(conf);
        ThriftHBaseServiceHandler hbaseHandler = new ThriftHBaseServiceHandler(UTIL.getConfiguration(), UserProvider.instantiate(UTIL.getConfiguration()));
        Hbase.Iface handler = HbaseHandlerMetricsProxy.newInstance(hbaseHandler, metrics, conf);
        ByteBuffer tTableName = asByteBuffer(tableName.getNameAsString());
        // check metrics increment with a successful get
        long preGetCounter = metricsHelper.checkCounterExists("getRow_num_ops", metrics.getSource()) ? metricsHelper.getCounter("getRow_num_ops", metrics.getSource()) : 0;
        List<TRowResult> tRowResult = handler.getRow(tTableName, asByteBuffer(rowkey), null);
        assertEquals(1, tRowResult.size());
        TRowResult tResult = tRowResult.get(0);
        TCell expectedColumnValue = new TCell(asByteBuffer("val1"), now);
        assertArrayEquals(Bytes.toBytes(rowkey), tResult.getRow());
        Collection<TCell> returnedColumnValues = tResult.getColumns().values();
        assertEquals(1, returnedColumnValues.size());
        assertEquals(expectedColumnValue, returnedColumnValues.iterator().next());
        metricsHelper.assertCounter("getRow_num_ops", preGetCounter + 1, metrics.getSource());
        // check metrics increment when the get throws each exception type
        for (ErrorThrowingGetObserver.ErrorType type : ErrorThrowingGetObserver.ErrorType.values()) {
            testExceptionType(handler, metrics, tTableName, rowkey, type);
        }
    } finally {
        UTIL.deleteTable(tableName);
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Configuration(org.apache.hadoop.conf.Configuration) TCell(org.apache.hadoop.hbase.thrift.generated.TCell) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) ByteBuffer(java.nio.ByteBuffer) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Put(org.apache.hadoop.hbase.client.Put) TableName(org.apache.hadoop.hbase.TableName) TRowResult(org.apache.hadoop.hbase.thrift.generated.TRowResult) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase) Test(org.junit.Test)

Aggregations

ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)199 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)95 Test (org.junit.Test)92 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)78 IOException (java.io.IOException)44 TableName (org.apache.hadoop.hbase.TableName)44 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)42 Path (org.apache.hadoop.fs.Path)41 Admin (org.apache.hadoop.hbase.client.Admin)36 Configuration (org.apache.hadoop.conf.Configuration)34 ArrayList (java.util.ArrayList)32 Put (org.apache.hadoop.hbase.client.Put)32 FileSystem (org.apache.hadoop.fs.FileSystem)28 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)24 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)22 Get (org.apache.hadoop.hbase.client.Get)20 Result (org.apache.hadoop.hbase.client.Result)19 ColumnFamilyDescriptorBuilder (org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder)17 Scan (org.apache.hadoop.hbase.client.Scan)17 Table (org.apache.hadoop.hbase.client.Table)17