Search in sources :

Example 1 with TTableName

use of org.apache.hadoop.hbase.thrift2.generated.TTableName in project hbase by apache.

the class TestThrift2ServerCmdLine method talkToThriftServer.

@Override
protected void talkToThriftServer(int port) throws Exception {
    TSocket sock = new TSocket(InetAddress.getLoopbackAddress().getHostName(), port);
    TTransport transport = sock;
    if (specifyFramed || implType.isAlwaysFramed()) {
        transport = new TFramedTransport(transport);
    }
    sock.open();
    try {
        TProtocol tProtocol;
        if (specifyCompact) {
            tProtocol = new TCompactProtocol(transport);
        } else {
            tProtocol = new TBinaryProtocol(transport);
        }
        THBaseService.Client client = new THBaseService.Client(tProtocol);
        TTableName tTableName = new TTableName();
        tTableName.setNs(Bytes.toBytes(""));
        tTableName.setQualifier(Bytes.toBytes(TABLENAME));
        if (!tableCreated) {
            Assert.assertTrue(!client.tableExists(tTableName));
            TTableDescriptor tTableDescriptor = new TTableDescriptor();
            tTableDescriptor.setTableName(tTableName);
            TColumnFamilyDescriptor columnFamilyDescriptor = new TColumnFamilyDescriptor();
            columnFamilyDescriptor.setName(Bytes.toBytes(TABLENAME));
            tTableDescriptor.addToColumns(columnFamilyDescriptor);
            client.createTable(tTableDescriptor, new ArrayList<>());
            tableCreated = true;
        }
        Assert.assertTrue("tableCreated " + tableCreated, client.tableExists(tTableName));
    } finally {
        sock.close();
    }
}
Also used : TTableName(org.apache.hadoop.hbase.thrift2.generated.TTableName) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.layered.TFramedTransport) TColumnFamilyDescriptor(org.apache.hadoop.hbase.thrift2.generated.TColumnFamilyDescriptor) TTableDescriptor(org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket) THBaseService(org.apache.hadoop.hbase.thrift2.generated.THBaseService)

Example 2 with TTableName

use of org.apache.hadoop.hbase.thrift2.generated.TTableName in project hbase by apache.

the class TestThriftHBaseServiceHandler method testMetricsPrecision.

/**
 * See HBASE-17611
 *
 * Latency metrics were capped at ~ 2 seconds due to the use of an int variable to capture the
 * duration.
 */
@Test
public void testMetricsPrecision() throws Exception {
    byte[] rowkey = Bytes.toBytes("row1");
    byte[] family = Bytes.toBytes("f");
    byte[] col = Bytes.toBytes("c");
    // create a table which will throw exceptions for requests
    TableName tableName = TableName.valueOf("testMetricsPrecision");
    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName).setCoprocessor(DelayingRegionObserver.class.getName()).setColumnFamily(ColumnFamilyDescriptorBuilder.of(family)).build();
    Table table = null;
    try {
        table = UTIL.createTable(tableDescriptor, null);
        table.put(new Put(rowkey).addColumn(family, col, Bytes.toBytes("val1")));
        ThriftHBaseServiceHandler hbaseHandler = createHandler();
        ThriftMetrics metrics = getMetrics(UTIL.getConfiguration());
        THBaseService.Iface handler = HbaseHandlerMetricsProxy.newInstance(hbaseHandler, metrics, null);
        ByteBuffer tTableName = wrap(tableName.getName());
        // check metrics latency with a successful get
        TGet tGet = new TGet(wrap(rowkey));
        TResult tResult = handler.get(tTableName, tGet);
        List<TColumnValue> expectedColumnValues = Lists.newArrayList(new TColumnValue(wrap(family), wrap(col), wrap(Bytes.toBytes("val1"))));
        assertArrayEquals(rowkey, tResult.getRow());
        List<TColumnValue> returnedColumnValues = tResult.getColumnValues();
        assertTColumnValuesEqual(expectedColumnValues, returnedColumnValues);
        metricsHelper.assertGaugeGt("get_max", 3000L, metrics.getSource());
    } finally {
        if (table != null) {
            try {
                table.close();
            } catch (IOException ignored) {
            }
            UTIL.deleteTable(tableName);
        }
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TTableDescriptor(org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Put(org.apache.hadoop.hbase.client.Put) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) TableName(org.apache.hadoop.hbase.TableName) TTableName(org.apache.hadoop.hbase.thrift2.generated.TTableName) ThriftMetrics(org.apache.hadoop.hbase.thrift.ThriftMetrics) THBaseService(org.apache.hadoop.hbase.thrift2.generated.THBaseService) Test(org.junit.Test)

Example 3 with TTableName

use of org.apache.hadoop.hbase.thrift2.generated.TTableName in project hbase by apache.

the class TestThriftHBaseServiceHandler method testDDLOpertions.

@Test
public void testDDLOpertions() throws Exception {
    String namespace = "testDDLOpertionsNamespace";
    String table = "testDDLOpertionsTable";
    TTableName tTableName = new TTableName();
    tTableName.setNs(Bytes.toBytes(namespace));
    tTableName.setQualifier(Bytes.toBytes(table));
    ThriftHBaseServiceHandler handler = createHandler();
    // create name space
    TNamespaceDescriptor namespaceDescriptor = new TNamespaceDescriptor();
    namespaceDescriptor.setName(namespace);
    namespaceDescriptor.putToConfiguration("key1", "value1");
    namespaceDescriptor.putToConfiguration("key2", "value2");
    handler.createNamespace(namespaceDescriptor);
    // list namespace
    List<TNamespaceDescriptor> namespaceDescriptors = handler.listNamespaceDescriptors();
    // should have 3 namespace, default hbase and testDDLOpertionsNamespace
    assertTrue(namespaceDescriptors.size() == 3);
    // modify namesapce
    namespaceDescriptor.putToConfiguration("kye3", "value3");
    handler.modifyNamespace(namespaceDescriptor);
    // get namespace
    TNamespaceDescriptor namespaceDescriptorReturned = handler.getNamespaceDescriptor(namespace);
    assertTrue(namespaceDescriptorReturned.getConfiguration().size() == 3);
    // create table
    TTableDescriptor tableDescriptor = new TTableDescriptor();
    tableDescriptor.setTableName(tTableName);
    TColumnFamilyDescriptor columnFamilyDescriptor1 = new TColumnFamilyDescriptor();
    columnFamilyDescriptor1.setName(familyAname);
    columnFamilyDescriptor1.setDataBlockEncoding(TDataBlockEncoding.DIFF);
    tableDescriptor.addToColumns(columnFamilyDescriptor1);
    List<ByteBuffer> splitKeys = new ArrayList<>();
    splitKeys.add(ByteBuffer.wrap(Bytes.toBytes(5)));
    handler.createTable(tableDescriptor, splitKeys);
    // modify table
    tableDescriptor.setDurability(TDurability.ASYNC_WAL);
    handler.modifyTable(tableDescriptor);
    // modify column family
    columnFamilyDescriptor1.setInMemory(true);
    handler.modifyColumnFamily(tTableName, columnFamilyDescriptor1);
    // add column family
    TColumnFamilyDescriptor columnFamilyDescriptor2 = new TColumnFamilyDescriptor();
    columnFamilyDescriptor2.setName(familyBname);
    columnFamilyDescriptor2.setDataBlockEncoding(TDataBlockEncoding.PREFIX);
    handler.addColumnFamily(tTableName, columnFamilyDescriptor2);
    // get table descriptor
    TTableDescriptor tableDescriptorReturned = handler.getTableDescriptor(tTableName);
    assertTrue(tableDescriptorReturned.getColumns().size() == 2);
    assertTrue(tableDescriptorReturned.getDurability() == TDurability.ASYNC_WAL);
    TColumnFamilyDescriptor columnFamilyDescriptor1Returned = tableDescriptorReturned.getColumns().stream().filter(desc -> Bytes.equals(desc.getName(), familyAname)).findFirst().get();
    assertTrue(columnFamilyDescriptor1Returned.isInMemory() == true);
    // delete column family
    handler.deleteColumnFamily(tTableName, ByteBuffer.wrap(familyBname));
    tableDescriptorReturned = handler.getTableDescriptor(tTableName);
    assertTrue(tableDescriptorReturned.getColumns().size() == 1);
    // disable table
    handler.disableTable(tTableName);
    assertTrue(handler.isTableDisabled(tTableName));
    // enable table
    handler.enableTable(tTableName);
    assertTrue(handler.isTableEnabled(tTableName));
    assertTrue(handler.isTableAvailable(tTableName));
    // truncate table
    handler.disableTable(tTableName);
    handler.truncateTable(tTableName, true);
    assertTrue(handler.isTableAvailable(tTableName));
    // delete table
    handler.disableTable(tTableName);
    handler.deleteTable(tTableName);
    assertFalse(handler.tableExists(tTableName));
    // delete namespace
    handler.deleteNamespace(namespace);
    namespaceDescriptors = handler.listNamespaceDescriptors();
    // should have 2 namespace, default and hbase
    assertTrue(namespaceDescriptors.size() == 2);
}
Also used : TTableName(org.apache.hadoop.hbase.thrift2.generated.TTableName) TColumnFamilyDescriptor(org.apache.hadoop.hbase.thrift2.generated.TColumnFamilyDescriptor) ArrayList(java.util.ArrayList) TTableDescriptor(org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor) TNamespaceDescriptor(org.apache.hadoop.hbase.thrift2.generated.TNamespaceDescriptor) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with TTableName

use of org.apache.hadoop.hbase.thrift2.generated.TTableName in project hbase by apache.

the class TestThriftHBaseServiceHandler method testMetricsWithException.

@Test
public void testMetricsWithException() throws Exception {
    byte[] rowkey = Bytes.toBytes("row1");
    byte[] family = Bytes.toBytes("f");
    byte[] col = Bytes.toBytes("c");
    // create a table which will throw exceptions for requests
    TableName tableName = TableName.valueOf(name.getMethodName());
    TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tableName).setCoprocessor(ErrorThrowingGetObserver.class.getName()).setColumnFamily(ColumnFamilyDescriptorBuilder.of(family)).build();
    Table table = UTIL.createTable(tableDesc, null);
    table.put(new Put(rowkey).addColumn(family, col, Bytes.toBytes("val1")));
    ThriftHBaseServiceHandler hbaseHandler = createHandler();
    ThriftMetrics metrics = getMetrics(UTIL.getConfiguration());
    THBaseService.Iface handler = HbaseHandlerMetricsProxy.newInstance(hbaseHandler, metrics, null);
    ByteBuffer tTableName = wrap(tableName.getName());
    // check metrics increment with a successful get
    long preGetCounter = metricsHelper.checkCounterExists("get_num_ops", metrics.getSource()) ? metricsHelper.getCounter("get_num_ops", metrics.getSource()) : 0;
    TGet tGet = new TGet(wrap(rowkey));
    TResult tResult = handler.get(tTableName, tGet);
    List<TColumnValue> expectedColumnValues = Lists.newArrayList(new TColumnValue(wrap(family), wrap(col), wrap(Bytes.toBytes("val1"))));
    assertArrayEquals(rowkey, tResult.getRow());
    List<TColumnValue> returnedColumnValues = tResult.getColumnValues();
    assertTColumnValuesEqual(expectedColumnValues, returnedColumnValues);
    metricsHelper.assertCounter("get_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);
    }
}
Also used : ErrorThrowingGetObserver(org.apache.hadoop.hbase.thrift.ErrorThrowingGetObserver) Table(org.apache.hadoop.hbase.client.Table) TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TTableDescriptor(org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Put(org.apache.hadoop.hbase.client.Put) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) TableName(org.apache.hadoop.hbase.TableName) TTableName(org.apache.hadoop.hbase.thrift2.generated.TTableName) ThriftMetrics(org.apache.hadoop.hbase.thrift.ThriftMetrics) THBaseService(org.apache.hadoop.hbase.thrift2.generated.THBaseService) Test(org.junit.Test)

Example 5 with TTableName

use of org.apache.hadoop.hbase.thrift2.generated.TTableName in project hbase by apache.

the class ThriftHBaseServiceHandler method enableTable.

@Override
public void enableTable(TTableName tableName) throws TIOError, TException {
    try {
        TableName table = tableNameFromThrift(tableName);
        connectionCache.getAdmin().enableTable(table);
    } catch (IOException e) {
        throw getTIOError(e);
    }
}
Also used : TTableName(org.apache.hadoop.hbase.thrift2.generated.TTableName) TableName(org.apache.hadoop.hbase.TableName) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException)

Aggregations

TTableName (org.apache.hadoop.hbase.thrift2.generated.TTableName)18 IOException (java.io.IOException)12 TableName (org.apache.hadoop.hbase.TableName)12 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)9 TColumnFamilyDescriptor (org.apache.hadoop.hbase.thrift2.generated.TColumnFamilyDescriptor)7 TTableDescriptor (org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor)6 ByteBuffer (java.nio.ByteBuffer)4 THBaseService (org.apache.hadoop.hbase.thrift2.generated.THBaseService)4 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)3 TGet (org.apache.hadoop.hbase.thrift2.generated.TGet)3 TResult (org.apache.hadoop.hbase.thrift2.generated.TResult)3 TException (org.apache.thrift.TException)3 Test (org.junit.Test)3 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)2 Put (org.apache.hadoop.hbase.client.Put)2 Table (org.apache.hadoop.hbase.client.Table)2 ThriftMetrics (org.apache.hadoop.hbase.thrift.ThriftMetrics)2 TColumnValue (org.apache.hadoop.hbase.thrift2.generated.TColumnValue)2 TPut (org.apache.hadoop.hbase.thrift2.generated.TPut)2 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)2