/** * @param server server location where the target region is hosted * @param regionName name of the region which we are going to write some data * @return the amount of time the client should wait until it submit a request to the * specified server and region */ private Long getBackoff(ServerName server, byte[] regionName) { ServerStatisticTracker tracker = asyncProcess.connection.getStatisticsTracker(); ServerStatistics stats = tracker.getStats(server); return asyncProcess.connection.getBackoffPolicy() .getBackoffTime(server, regionName, stats); }
@VisibleForTesting protected void updateStats(ServerName server, Map<byte[], MultiResponse.RegionResult> results) { boolean metrics = asyncProcess.connection.getConnectionMetrics() != null; boolean stats = asyncProcess.connection.getStatisticsTracker() != null; if (!stats && !metrics) { return; } for (Map.Entry<byte[], MultiResponse.RegionResult> regionStats : results.entrySet()) { byte[] regionName = regionStats.getKey(); ClientProtos.RegionLoadStats stat = regionStats.getValue().getStat(); if (stat == null) { LOG.error("No ClientProtos.RegionLoadStats found for server=" + server + ", region=" + Bytes.toStringBinary(regionName)); continue; } RegionLoadStats regionLoadstats = ProtobufUtil.createRegionLoadStats(stat); ResultStatsUtil.updateStats(asyncProcess.connection.getStatisticsTracker(), server, regionName, regionLoadstats); ResultStatsUtil.updateStats(asyncProcess.connection.getConnectionMetrics(), server, regionName, regionLoadstats); } }
@Test public void testTaskCountWithClientBackoffPolicy() throws IOException, InterruptedException { Configuration copyConf = new Configuration(CONF); copyConf.setBoolean(HConstants.ENABLE_CLIENT_BACKPRESSURE, true); MyClientBackoffPolicy bp = new MyClientBackoffPolicy(); ClusterConnection conn = createHConnection(); Mockito.when(conn.getConfiguration()).thenReturn(copyConf); Mockito.when(conn.getStatisticsTracker()).thenReturn(ServerStatisticTracker.create(copyConf)); Mockito.when(conn.getBackoffPolicy()).thenReturn(bp); final String defaultClazz = conn.getConfiguration().get(RequestControllerFactory.REQUEST_CONTROLLER_IMPL_CONF_KEY); conn.getConfiguration().set(RequestControllerFactory.REQUEST_CONTROLLER_IMPL_CONF_KEY, SimpleRequestController.class.getName()); MyAsyncProcess ap = new MyAsyncProcess(conn, copyConf); testTaskCount(ap); if (defaultClazz != null) { conn.getConfiguration().set(RequestControllerFactory.REQUEST_CONTROLLER_IMPL_CONF_KEY, defaultClazz); } }
RpcRetryingCallerFactory.instantiate(configuration, connection.getStatisticsTracker()), RpcControllerFactory.instantiate(configuration));
int numAttempt) { if (asyncProcess.connection.getStatisticsTracker() == null) { if (asyncProcess.connection.getConnectionMetrics() != null) { asyncProcess.connection.getConnectionMetrics().incrNormalRunners();
@Test public void testMutateRowStats() throws IOException { Configuration conf = UTIL.getConfiguration(); ClusterConnection conn = (ClusterConnection) ConnectionFactory.createConnection(conf); Table table = conn.getTable(tableName); HRegionServer rs = UTIL.getHBaseCluster().getRegionServer(0); Region region = rs.getRegions(tableName).get(0); RowMutations mutations = new RowMutations(Bytes.toBytes("row")); Put p = new Put(Bytes.toBytes("row")); p.addColumn(family, qualifier, Bytes.toBytes("value2")); mutations.add(p); table.mutateRow(mutations); ServerStatisticTracker stats = conn.getStatisticsTracker(); assertNotNull( "No stats configured for the client!", stats); // get the names so we can query the stats ServerName server = rs.getServerName(); byte[] regionName = region.getRegionInfo().getRegionName(); // check to see we found some load on the memstore ServerStatistics serverStats = stats.getServerStatsForTesting(server); ServerStatistics.RegionStatistics regionStats = serverStats.getStatsForRegion(regionName); assertNotNull(regionStats); assertTrue(regionStats.getMemStoreLoadPercent() > 0); } }
backoffPolicy instanceof ExponentialClientBackoffPolicy); ServerStatisticTracker stats = conn.getStatisticsTracker(); assertNotNull( "No stats configured for the client!", stats);
/** * @param server server location where the target region is hosted * @param regionName name of the region which we are going to write some data * @return the amount of time the client should wait until it submit a request to the * specified server and region */ private Long getBackoff(ServerName server, byte[] regionName) { ServerStatisticTracker tracker = asyncProcess.connection.getStatisticsTracker(); ServerStatistics stats = tracker.getStats(server); return asyncProcess.connection.getBackoffPolicy() .getBackoffTime(server, regionName, stats); }
@VisibleForTesting protected void updateStats(ServerName server, Map<byte[], MultiResponse.RegionResult> results) { boolean metrics = asyncProcess.connection.getConnectionMetrics() != null; boolean stats = asyncProcess.connection.getStatisticsTracker() != null; if (!stats && !metrics) { return; } for (Map.Entry<byte[], MultiResponse.RegionResult> regionStats : results.entrySet()) { byte[] regionName = regionStats.getKey(); ClientProtos.RegionLoadStats stat = regionStats.getValue().getStat(); if (stat == null) { LOG.error("No ClientProtos.RegionLoadStats found for server=" + server + ", region=" + Bytes.toStringBinary(regionName)); continue; } RegionLoadStats regionLoadstats = ProtobufUtil.createRegionLoadStats(stat); ResultStatsUtil.updateStats(asyncProcess.connection.getStatisticsTracker(), server, regionName, regionLoadstats); ResultStatsUtil.updateStats(asyncProcess.connection.getConnectionMetrics(), server, regionName, regionLoadstats); } }
@Test public void testTaskCountWithClientBackoffPolicy() throws IOException, InterruptedException { Configuration copyConf = new Configuration(CONF); copyConf.setBoolean(HConstants.ENABLE_CLIENT_BACKPRESSURE, true); MyClientBackoffPolicy bp = new MyClientBackoffPolicy(); ClusterConnection conn = createHConnection(); Mockito.when(conn.getConfiguration()).thenReturn(copyConf); Mockito.when(conn.getStatisticsTracker()).thenReturn(ServerStatisticTracker.create(copyConf)); Mockito.when(conn.getBackoffPolicy()).thenReturn(bp); final String defaultClazz = conn.getConfiguration().get(RequestControllerFactory.REQUEST_CONTROLLER_IMPL_CONF_KEY); conn.getConfiguration().set(RequestControllerFactory.REQUEST_CONTROLLER_IMPL_CONF_KEY, SimpleRequestController.class.getName()); MyAsyncProcess ap = new MyAsyncProcess(conn, copyConf); testTaskCount(ap); if (defaultClazz != null) { conn.getConfiguration().set(RequestControllerFactory.REQUEST_CONTROLLER_IMPL_CONF_KEY, defaultClazz); } }
RpcRetryingCallerFactory.instantiate(configuration, connection.getStatisticsTracker()), RpcControllerFactory.instantiate(configuration));
@Override public ServerStatisticTracker getStatisticsTracker() { return wrappedConnection.getStatisticsTracker(); }
int numAttempt) { if (asyncProcess.connection.getStatisticsTracker() == null) { if (asyncProcess.connection.getConnectionMetrics() != null) { asyncProcess.connection.getConnectionMetrics().incrNormalRunners();
/** * @param server server location where the target region is hosted * @param regionName name of the region which we are going to write some data * @return the amount of time the client should wait until it submit a request to the * specified server and region */ private Long getBackoff(ServerName server, byte[] regionName) { ServerStatisticTracker tracker = AsyncProcess.this.connection.getStatisticsTracker(); ServerStatistics stats = tracker.getStats(server); return AsyncProcess.this.connection.getBackoffPolicy() .getBackoffTime(server, regionName, stats); }
/** * @param server server location where the target region is hosted * @param regionName name of the region which we are going to write some data * @return the amount of time the client should wait until it submit a request to the * specified server and region */ private Long getBackoff(ServerName server, byte[] regionName) { ServerStatisticTracker tracker = asyncProcess.connection.getStatisticsTracker(); ServerStatistics stats = tracker.getStats(server); return asyncProcess.connection.getBackoffPolicy() .getBackoffTime(server, regionName, stats); }
@VisibleForTesting protected void updateStats(ServerName server, Map<byte[], MultiResponse.RegionResult> results) { boolean metrics = asyncProcess.connection.getConnectionMetrics() != null; boolean stats = asyncProcess.connection.getStatisticsTracker() != null; if (!stats && !metrics) { return; } for (Map.Entry<byte[], MultiResponse.RegionResult> regionStats : results.entrySet()) { byte[] regionName = regionStats.getKey(); ClientProtos.RegionLoadStats stat = regionStats.getValue().getStat(); if (stat == null) { LOG.error("No ClientProtos.RegionLoadStats found for server=" + server + ", region=" + Bytes.toStringBinary(regionName)); continue; } RegionLoadStats regionLoadstats = ProtobufUtil.createRegionLoadStats(stat); ResultStatsUtil.updateStats(asyncProcess.connection.getStatisticsTracker(), server, regionName, regionLoadstats); ResultStatsUtil.updateStats(asyncProcess.connection.getConnectionMetrics(), server, regionName, regionLoadstats); } }
int numAttempt) { if (AsyncProcess.this.connection.getStatisticsTracker() == null) { if (connection.getConnectionMetrics() != null) { connection.getConnectionMetrics().incrNormalRunners();
int numAttempt) { if (asyncProcess.connection.getStatisticsTracker() == null) { if (asyncProcess.connection.getConnectionMetrics() != null) { asyncProcess.connection.getConnectionMetrics().incrNormalRunners();
@Test public void testMutateRowStats() throws IOException { Configuration conf = UTIL.getConfiguration(); ClusterConnection conn = (ClusterConnection) ConnectionFactory.createConnection(conf); Table table = conn.getTable(tableName); HRegionServer rs = UTIL.getHBaseCluster().getRegionServer(0); Region region = rs.getRegions(tableName).get(0); RowMutations mutations = new RowMutations(Bytes.toBytes("row")); Put p = new Put(Bytes.toBytes("row")); p.addColumn(family, qualifier, Bytes.toBytes("value2")); mutations.add(p); table.mutateRow(mutations); ServerStatisticTracker stats = conn.getStatisticsTracker(); assertNotNull( "No stats configured for the client!", stats); // get the names so we can query the stats ServerName server = rs.getServerName(); byte[] regionName = region.getRegionInfo().getRegionName(); // check to see we found some load on the memstore ServerStatistics serverStats = stats.getServerStatsForTesting(server); ServerStatistics.RegionStatistics regionStats = serverStats.getStatsForRegion(regionName); assertNotNull(regionStats); assertTrue(regionStats.getMemStoreLoadPercent() > 0); } }
backoffPolicy instanceof ExponentialClientBackoffPolicy); ServerStatisticTracker stats = conn.getStatisticsTracker(); assertNotNull( "No stats configured for the client!", stats);