Search in sources :

Example 1 with ThriftMetrics

use of org.apache.hadoop.hbase.thrift.ThriftMetrics 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 2 with ThriftMetrics

use of org.apache.hadoop.hbase.thrift.ThriftMetrics 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 3 with ThriftMetrics

use of org.apache.hadoop.hbase.thrift.ThriftMetrics in project hbase by apache.

the class ThriftServer method run.

@Override
public int run(String[] args) throws Exception {
    final Configuration conf = getConf();
    TServer server = null;
    Options options = getOptions();
    CommandLine cmd = parseArguments(conf, options, args);
    int workerThreads = 0;
    int selectorThreads = 0;
    // use unbounded queue by default
    int maxCallQueueSize = -1;
    /**
     * This is to please both bin/hbase and bin/hbase-daemon. hbase-daemon provides "start" and "stop" arguments hbase
     * should print the help if no argument is provided
     */
    List<?> argList = cmd.getArgList();
    if (cmd.hasOption("help") || !argList.contains("start") || argList.contains("stop")) {
        printUsage();
        return 1;
    }
    // Get address to bind
    String bindAddress;
    if (cmd.hasOption("bind")) {
        bindAddress = cmd.getOptionValue("bind");
        conf.set("hbase.thrift.info.bindAddress", bindAddress);
    } else {
        bindAddress = conf.get("hbase.thrift.info.bindAddress");
    }
    // Get read timeout
    int readTimeout = THRIFT_SERVER_SOCKET_READ_TIMEOUT_DEFAULT;
    if (cmd.hasOption(READ_TIMEOUT_OPTION)) {
        try {
            readTimeout = Integer.parseInt(cmd.getOptionValue(READ_TIMEOUT_OPTION));
        } catch (NumberFormatException e) {
            throw new RuntimeException("Could not parse the value provided for the timeout option", e);
        }
    } else {
        readTimeout = conf.getInt(THRIFT_SERVER_SOCKET_READ_TIMEOUT_KEY, THRIFT_SERVER_SOCKET_READ_TIMEOUT_DEFAULT);
    }
    // Get port to bind to
    int listenPort = 0;
    try {
        if (cmd.hasOption("port")) {
            listenPort = Integer.parseInt(cmd.getOptionValue("port"));
        } else {
            listenPort = conf.getInt("hbase.regionserver.thrift.port", DEFAULT_LISTEN_PORT);
        }
    } catch (NumberFormatException e) {
        throw new RuntimeException("Could not parse the value provided for the port option", e);
    }
    // Thrift's implementation uses '0' as a placeholder for 'use the default.'
    int backlog = conf.getInt(BACKLOG_CONF_KEY, 0);
    // Local hostname and user name,
    // used only if QOP is configured.
    String host = null;
    String name = null;
    UserProvider userProvider = UserProvider.instantiate(conf);
    // login the server principal (if using secure Hadoop)
    boolean securityEnabled = userProvider.isHadoopSecurityEnabled() && userProvider.isHBaseSecurityEnabled();
    if (securityEnabled) {
        host = Strings.domainNamePointerToHostName(DNS.getDefaultHost(conf.get("hbase.thrift.dns.interface", "default"), conf.get("hbase.thrift.dns.nameserver", "default")));
        userProvider.login("hbase.thrift.keytab.file", "hbase.thrift.kerberos.principal", host);
    }
    UserGroupInformation realUser = userProvider.getCurrent().getUGI();
    String stringQop = conf.get(THRIFT_QOP_KEY);
    SaslUtil.QualityOfProtection qop = null;
    if (stringQop != null) {
        qop = SaslUtil.getQop(stringQop);
        if (!securityEnabled) {
            throw new IOException("Thrift server must" + " run in secure mode to support authentication");
        }
        // Extract the name from the principal
        name = SecurityUtil.getUserFromPrincipal(conf.get("hbase.thrift.kerberos.principal"));
    }
    boolean nonblocking = cmd.hasOption("nonblocking");
    boolean hsha = cmd.hasOption("hsha");
    boolean selector = cmd.hasOption("selector");
    ThriftMetrics metrics = new ThriftMetrics(conf, ThriftMetrics.ThriftServerType.TWO);
    final JvmPauseMonitor pauseMonitor = new JvmPauseMonitor(conf, metrics.getSource());
    String implType = "threadpool";
    if (nonblocking) {
        implType = "nonblocking";
    } else if (hsha) {
        implType = "hsha";
    } else if (selector) {
        implType = "selector";
    }
    conf.set("hbase.regionserver.thrift.server.type", implType);
    conf.setInt("hbase.regionserver.thrift.port", listenPort);
    registerFilters(conf);
    // Construct correct ProtocolFactory
    boolean compact = cmd.hasOption("compact") || conf.getBoolean("hbase.regionserver.thrift.compact", false);
    TProtocolFactory protocolFactory = getTProtocolFactory(compact);
    final ThriftHBaseServiceHandler hbaseHandler = new ThriftHBaseServiceHandler(conf, userProvider);
    THBaseService.Iface handler = ThriftHBaseServiceHandler.newInstance(hbaseHandler, metrics);
    final THBaseService.Processor p = new THBaseService.Processor(handler);
    conf.setBoolean("hbase.regionserver.thrift.compact", compact);
    TProcessor processor = p;
    boolean framed = cmd.hasOption("framed") || conf.getBoolean("hbase.regionserver.thrift.framed", false) || nonblocking || hsha;
    TTransportFactory transportFactory = getTTransportFactory(qop, name, host, framed, conf.getInt("hbase.regionserver.thrift.framed.max_frame_size_in_mb", 2) * 1024 * 1024);
    InetSocketAddress inetSocketAddress = bindToPort(bindAddress, listenPort);
    conf.setBoolean("hbase.regionserver.thrift.framed", framed);
    if (qop != null) {
        // Create a processor wrapper, to get the caller
        processor = new TProcessor() {

            @Override
            public boolean process(TProtocol inProt, TProtocol outProt) throws TException {
                TSaslServerTransport saslServerTransport = (TSaslServerTransport) inProt.getTransport();
                SaslServer saslServer = saslServerTransport.getSaslServer();
                String principal = saslServer.getAuthorizationID();
                hbaseHandler.setEffectiveUser(principal);
                return p.process(inProt, outProt);
            }
        };
    }
    if (cmd.hasOption("w")) {
        workerThreads = Integer.parseInt(cmd.getOptionValue("w"));
    }
    if (cmd.hasOption("s")) {
        selectorThreads = Integer.parseInt(cmd.getOptionValue("s"));
    }
    if (cmd.hasOption("q")) {
        maxCallQueueSize = Integer.parseInt(cmd.getOptionValue("q"));
    }
    // check for user-defined info server port setting, if so override the conf
    try {
        if (cmd.hasOption("infoport")) {
            String val = cmd.getOptionValue("infoport");
            conf.setInt("hbase.thrift.info.port", Integer.parseInt(val));
            log.debug("Web UI port set to " + val);
        }
    } catch (NumberFormatException e) {
        log.error("Could not parse the value provided for the infoport option", e);
        printUsage();
        System.exit(1);
    }
    // Put up info server.
    int port = conf.getInt("hbase.thrift.info.port", 9095);
    if (port >= 0) {
        conf.setLong("startcode", System.currentTimeMillis());
        String a = conf.get("hbase.thrift.info.bindAddress", "0.0.0.0");
        InfoServer infoServer = new InfoServer("thrift", a, port, false, conf);
        infoServer.setAttribute("hbase.conf", conf);
        infoServer.start();
    }
    if (nonblocking) {
        server = getTNonBlockingServer(protocolFactory, processor, transportFactory, inetSocketAddress);
    } else if (hsha) {
        server = getTHsHaServer(protocolFactory, processor, transportFactory, workerThreads, maxCallQueueSize, inetSocketAddress, metrics);
    } else if (selector) {
        server = getTThreadedSelectorServer(protocolFactory, processor, transportFactory, workerThreads, selectorThreads, maxCallQueueSize, inetSocketAddress, metrics);
    } else {
        server = getTThreadPoolServer(protocolFactory, processor, transportFactory, workerThreads, inetSocketAddress, backlog, readTimeout, metrics);
    }
    final TServer tserver = server;
    realUser.doAs(new PrivilegedAction<Object>() {

        @Override
        public Object run() {
            pauseMonitor.start();
            try {
                tserver.serve();
                return null;
            } finally {
                pauseMonitor.stop();
            }
        }
    });
    // when tserver.stop eventually happens we'll get here.
    return 0;
}
Also used : TException(org.apache.thrift.TException) Options(org.apache.commons.cli.Options) TProtocolFactory(org.apache.thrift.protocol.TProtocolFactory) TProcessor(org.apache.thrift.TProcessor) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) TServer(org.apache.thrift.server.TServer) InetSocketAddress(java.net.InetSocketAddress) SaslServer(javax.security.sasl.SaslServer) JvmPauseMonitor(org.apache.hadoop.hbase.util.JvmPauseMonitor) TProcessor(org.apache.thrift.TProcessor) UserProvider(org.apache.hadoop.hbase.security.UserProvider) TProtocol(org.apache.thrift.protocol.TProtocol) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) THBaseService(org.apache.hadoop.hbase.thrift2.generated.THBaseService) IOException(java.io.IOException) TTransportFactory(org.apache.thrift.transport.TTransportFactory) TSaslServerTransport(org.apache.thrift.transport.TSaslServerTransport) CommandLine(org.apache.commons.cli.CommandLine) ThriftMetrics(org.apache.hadoop.hbase.thrift.ThriftMetrics) InfoServer(org.apache.hadoop.hbase.http.InfoServer) SaslUtil(org.apache.hadoop.hbase.security.SaslUtil)

Example 4 with ThriftMetrics

use of org.apache.hadoop.hbase.thrift.ThriftMetrics in project hbase by apache.

the class TestThriftHBaseServiceHandler method testMetrics.

@Test
public void testMetrics() throws Exception {
    Configuration conf = UTIL.getConfiguration();
    ThriftMetrics metrics = getMetrics(conf);
    ThriftHBaseServiceHandler hbaseHandler = createHandler();
    THBaseService.Iface handler = HbaseHandlerMetricsProxy.newInstance(hbaseHandler, metrics, conf);
    byte[] rowName = Bytes.toBytes("testMetrics");
    ByteBuffer table = wrap(tableAname);
    TGet get = new TGet(wrap(rowName));
    assertFalse(handler.exists(table, get));
    List<TColumnValue> columnValues = new ArrayList<>(2);
    columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
    columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname)));
    TPut put = new TPut(wrap(rowName), columnValues);
    put.setColumnValues(columnValues);
    handler.put(table, put);
    assertTrue(handler.exists(table, get));
    metricsHelper.assertCounter("put_num_ops", 1, metrics.getSource());
    metricsHelper.assertCounter("exists_num_ops", 2, metrics.getSource());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ThriftMetrics(org.apache.hadoop.hbase.thrift.ThriftMetrics) TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) ArrayList(java.util.ArrayList) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) ByteBuffer(java.nio.ByteBuffer) THBaseService(org.apache.hadoop.hbase.thrift2.generated.THBaseService) Test(org.junit.Test)

Example 5 with ThriftMetrics

use of org.apache.hadoop.hbase.thrift.ThriftMetrics in project hbase by apache.

the class TestThriftHBaseServiceHandler method getMetrics.

private static ThriftMetrics getMetrics(Configuration conf) throws Exception {
    ThriftMetrics m = new ThriftMetrics(conf, ThriftMetrics.ThriftServerType.TWO);
    // Clear all the metrics
    m.getSource().init();
    return m;
}
Also used : ThriftMetrics(org.apache.hadoop.hbase.thrift.ThriftMetrics)

Aggregations

ThriftMetrics (org.apache.hadoop.hbase.thrift.ThriftMetrics)5 THBaseService (org.apache.hadoop.hbase.thrift2.generated.THBaseService)4 ByteBuffer (java.nio.ByteBuffer)3 TColumnValue (org.apache.hadoop.hbase.thrift2.generated.TColumnValue)3 TGet (org.apache.hadoop.hbase.thrift2.generated.TGet)3 TPut (org.apache.hadoop.hbase.thrift2.generated.TPut)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 Configuration (org.apache.hadoop.conf.Configuration)2 TableName (org.apache.hadoop.hbase.TableName)2 Put (org.apache.hadoop.hbase.client.Put)2 Table (org.apache.hadoop.hbase.client.Table)2 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)2 TResult (org.apache.hadoop.hbase.thrift2.generated.TResult)2 TTableDescriptor (org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor)2 TTableName (org.apache.hadoop.hbase.thrift2.generated.TTableName)2 InterruptedIOException (java.io.InterruptedIOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 SaslServer (javax.security.sasl.SaslServer)1