@Test public void testMultiLimits() throws Exception { final TableName name = TableName.valueOf("testMultiLimits"); Table t = TEST_UTIL.createTable(name, FAMILY); TEST_UTIL.loadTable(t, FAMILY, false); // Split the table to make sure that the chunking happens accross regions. try (final Admin admin = TEST_UTIL.getHBaseAdmin()) { admin.split(name); TEST_UTIL.waitFor(60000, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return admin.getTableRegions(name).size() > 1; } }); } List<Get> gets = new ArrayList<>(MAX_SIZE); for (int i = 0; i < MAX_SIZE; i++) { gets.add(new Get(HBaseTestingUtility.ROWS[i])); } RpcServerInterface rpcServer = TEST_UTIL.getHBaseCluster().getRegionServer(0).getRpcServer(); BaseSource s = rpcServer.getMetrics().getMetricsSource(); long startingExceptions = METRICS_ASSERT.getCounter("exceptions", s); long startingMultiExceptions = METRICS_ASSERT.getCounter("exceptions.multiResponseTooLarge", s); Result[] results = t.get(gets); assertEquals(MAX_SIZE, results.length); // Cells from TEST_UTIL.loadTable have a length of 27. // Multiplying by less than that gives an easy lower bound on size. // However in reality each kv is being reported as much higher than that. METRICS_ASSERT.assertCounterGt("exceptions", startingExceptions + ((MAX_SIZE * 25) / MAX_SIZE), s); METRICS_ASSERT.assertCounterGt("exceptions.multiResponseTooLarge", startingMultiExceptions + ((MAX_SIZE * 25) / MAX_SIZE), s); }
@Override public long getCounter(String name, BaseSource source) { getMetrics(source); String cName = canonicalizeMetricName(name); assertNotNull("Should get counter "+cName + " but did not",counters.get(cName)); return counters.get(cName).longValue(); }
@Override public double getGaugeDouble(String name, BaseSource source) { getMetrics(source); String cName = canonicalizeMetricName(name); assertNotNull("Should get gauge "+cName + " but did not",gauges.get(cName)); return gauges.get(cName).doubleValue(); }
@Override public long getGaugeLong(String name, BaseSource source) { getMetrics(source); String cName = canonicalizeMetricName(name); assertNotNull("Should get gauge " + cName + " but did not", gauges.get(cName)); return gauges.get(cName).longValue(); }
private void getMetrics(BaseSource source) { reset(); if (!(source instanceof MetricsSource)) { assertTrue("The Source passed must be a MetricsSource", false); } MetricsSource impl = (MetricsSource) source; impl.getMetrics(new MockMetricsBuilder(), true); }
@Test public void testMultiLimits() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); Table t = TEST_UTIL.createTable(tableName, FAMILY); TEST_UTIL.loadTable(t, FAMILY, false); // Split the table to make sure that the chunking happens accross regions. try (final Admin admin = TEST_UTIL.getAdmin()) { admin.split(tableName); TEST_UTIL.waitFor(60000, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return admin.getTableRegions(tableName).size() > 1; } }); } List<Get> gets = new ArrayList<>(MAX_SIZE); for (int i = 0; i < MAX_SIZE; i++) { gets.add(new Get(HBaseTestingUtility.ROWS[i])); } RpcServerInterface rpcServer = TEST_UTIL.getHBaseCluster().getRegionServer(0).getRpcServer(); BaseSource s = rpcServer.getMetrics().getMetricsSource(); long startingExceptions = METRICS_ASSERT.getCounter("exceptions", s); long startingMultiExceptions = METRICS_ASSERT.getCounter("exceptions.multiResponseTooLarge", s); Result[] results = t.get(gets); assertEquals(MAX_SIZE, results.length); // Cells from TEST_UTIL.loadTable have a length of 27. // Multiplying by less than that gives an easy lower bound on size. // However in reality each kv is being reported as much higher than that. METRICS_ASSERT.assertCounterGt("exceptions", startingExceptions + ((MAX_SIZE * 25) / MAX_SIZE), s); METRICS_ASSERT.assertCounterGt("exceptions.multiResponseTooLarge", startingMultiExceptions + ((MAX_SIZE * 25) / MAX_SIZE), s); }
@Override public String toDebugString(BaseSource source) { getMetrics(source); StringBuilder sb = new StringBuilder(); sb.append("Tags=").append(tags).append(", Counters=").append(counters); return sb.append(", Gauges=").append(gauges).toString(); }
@Test public void testBlockMultiLimits() throws Exception { final TableName name = TableName.valueOf("testBlockMultiLimits"); HTableDescriptor desc = new HTableDescriptor(name); HColumnDescriptor hcd = new HColumnDescriptor(FAMILY); hcd.setDataBlockEncoding(DataBlockEncoding.FAST_DIFF); desc.addFamily(hcd); TEST_UTIL.getHBaseAdmin().createTable(desc); Table t = TEST_UTIL.getConnection().getTable(name); final HRegionServer regionServer = TEST_UTIL.getHBaseCluster().getRegionServer(0); RpcServerInterface rpcServer = regionServer.getRpcServer(); BaseSource s = rpcServer.getMetrics().getMetricsSource(); long startingExceptions = METRICS_ASSERT.getCounter("exceptions", s); long startingMultiExceptions = METRICS_ASSERT.getCounter("exceptions.multiResponseTooLarge", s); byte[] row = Bytes.toBytes("TEST"); byte[][] cols = new byte[][]{ Bytes.toBytes("0"), // Get this Bytes.toBytes("1"), // Buffer Bytes.toBytes("2"), // Buffer Bytes.toBytes("3"), // Get This Bytes.toBytes("4"), // Buffer Bytes.toBytes("5"), // Buffer }; // Set the value size so that one result will be less than the MAX_SIE // however the block being reference will be larger than MAX_SIZE. // This should cause the regionserver to try and send a result immediately. byte[] value = new byte[MAX_SIZE - 100]; ThreadLocalRandom.current().nextBytes(value); for (byte[] col:cols) { Put p = new Put(row); p.addImmutable(FAMILY, col, value); t.put(p); } // Make sure that a flush happens try (final Admin admin = TEST_UTIL.getHBaseAdmin()) { admin.flush(name); TEST_UTIL.waitFor(60000, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return regionServer.getOnlineRegions(name).get(0).getMaxFlushedSeqId() > 3; } }); } List<Get> gets = new ArrayList<>(2); Get g0 = new Get(row); g0.addColumn(FAMILY, cols[0]); gets.add(g0); Get g2 = new Get(row); g2.addColumn(FAMILY, cols[3]); gets.add(g2); Result[] results = t.get(gets); assertEquals(2, results.length); METRICS_ASSERT.assertCounterGt("exceptions", startingExceptions, s); METRICS_ASSERT.assertCounterGt("exceptions.multiResponseTooLarge", startingMultiExceptions, s); }