private byte[] readDelegate(byte[] key) throws IOException { try { if (!getBloomFilter().mightContain(key)) { // bloom filter check failed, the key is not present in this hoplog return null; } } catch (IllegalArgumentException e) { if (IOException.class.isAssignableFrom(e.getCause().getClass())) { throw (IOException) e.getCause(); } else { throw e; } } byte[] valueBytes = null; ByteBuffer bb = get(key); if (bb != null) { valueBytes = new byte[bb.remaining()]; bb.get(valueBytes); } else { stats.getBloom().falsePositive(); } return valueBytes; }
@Override public boolean mightContain(byte[] key) { assert key != null; long start = sopConfig.getStatistics().getBloom().begin(); boolean foundKey = hbloom.contains(key, 0, key.length, null); sopConfig.getStatistics().getBloom().end(start); if (logger.finestEnabled()) { logger.finest(String.format("Bloom check on %s for key %s: %b", path, Hex.toHex(key), foundKey)); } return foundKey; } };
public void testBloomStats() throws Exception { HoplogOrganizer bucket = regionManager.create(0); // create 10 hoplogs for (int j = 0; j < 5; j++) { ArrayList<TestEvent> items = new ArrayList<TestEvent>(); for (int i = 0; i < 100; i++) { String key = ("key-" + (j * 100 + i)); String value = ("value-" + System.nanoTime()); items.add(new TestEvent(key, value)); } bucket.flush(items.iterator(), 100); } // initially bloom stat will be zero // reading key in first hop will increase bloom hit by 1 (key 0 to 99) // reading key in 5 hoplog will increase bloom hit by 5 (key 400 to 499) assertEquals(0, stats.getBloom().getCount()); bucket.read(BlobHelper.serializeToBlob("key-450")); assertEquals(1, stats.getBloom().getCount()); bucket.read(BlobHelper.serializeToBlob("key-50")); assertEquals(6, stats.getBloom().getCount()); }
private byte[] readDelegate(byte[] key) throws IOException { try { if (!getBloomFilter().mightContain(key)) { // bloom filter check failed, the key is not present in this hoplog return null; } } catch (IllegalArgumentException e) { if (IOException.class.isAssignableFrom(e.getCause().getClass())) { throw (IOException) e.getCause(); } else { throw e; } } byte[] valueBytes = null; ByteBuffer bb = get(key); if (bb != null) { valueBytes = new byte[bb.remaining()]; bb.get(valueBytes); } else { stats.getBloom().falsePositive(); } return valueBytes; }
@Override public ByteBuffer read(byte[] key) throws IOException { assert key != null; if (logger.finestEnabled()) { logger.finest(String.format("Reading key %s from %s", Hex.toHex(key), path)); } long start = sopConfig.getStatistics().getRead().begin(); try { HFileScanner seek = reader.getScanner(true, true); if (seek.seekTo(key) == 0) { ByteBuffer val = seek.getValue(); sopConfig.getStatistics().getRead().end(val.remaining(), start); return val; } sopConfig.getStatistics().getRead().end(start); sopConfig.getStatistics().getBloom().falsePositive(); return null; } catch (IOException e) { sopConfig.getStatistics().getRead().error(start); throw (IOException) e.fillInStackTrace(); } }