Source:
IndexValue find(StoreKey keyToFind) throws StoreException { try { rwLock.readLock().lock(); if (!(mapped.get())) { return index.get(keyToFind); } else { metrics.bloomAccessedCount.inc(); if (bloomFilter == null || bloomFilter.isPresent(ByteBuffer.wrap(keyToFind.toBytes()))) { metrics.bloomPositiveCount.inc(1); logger.trace(bloomFilter == null ? "IndexSegment bloom filter empty. Searching file with start offset and for key " : "IndexSegment found in bloom filter for index with start offset and for key ", indexFile.getAbsolutePath(), startOffset, keyToFind); ByteBuffer duplicate = mmap.duplicate(); int low = 0; int high = numberOfEntries(duplicate) - 1; logger.trace("binary search low : high : {}", low, high); while (low <= high) { int mid = (int) (Math.ceil(high / 2.0 + low / 2.0)); StoreKey found = getKeyAt(duplicate, mid); logger.trace("Index Segment binary search - key found on iteration {}", indexFile.getAbsolutePath(), found); int result = found.compareTo(keyToFind); if (result == 0) { byte[] buf = new byte[valueSize]; duplicate.get(buf); return new IndexValue(startOffset.getName(), ByteBuffer.wrap(buf)); } else if (result < 0) { low = mid + 1; } else { high = mid - 1; } } metrics.bloomFalsePositiveCount.inc(1); } return null; } } catch (IOException e) { throw new StoreException("IndexSegment : " + indexFile.getAbsolutePath() + " IO error while searching", e, StoreErrorCodes.IOError); } finally { rwLock.readLock().unlock(); } }

Target:
IndexValue find(StoreKey keyToFind) throws StoreException { IndexValue toReturn = null; try { rwLock.readLock().lock(); if (!mapped.get()) { IndexValue value = index.get(keyToFind); if (value != null) { metrics.blobFoundInActiveSegmentCount.inc(); } toReturn = value; } else { if (bloomFilter != null) { metrics.bloomAccessedCount.inc(); } if (bloomFilter == null || bloomFilter.isPresent(ByteBuffer.wrap(keyToFind.toBytes()))) { if (bloomFilter == null) { logger.trace("IndexSegment bloom filter empty. Searching file with start offset and for key {}", indexFile.getAbsolutePath(), startOffset, keyToFind); } else { metrics.bloomPositiveCount.inc(); logger.trace("IndexSegment found in bloom filter for index with start offset and for key ", indexFile.getAbsolutePath(), startOffset, keyToFind); } ByteBuffer duplicate = mmap.duplicate(); int low = 0; int high = numberOfEntries(duplicate) - 1; logger.trace("binary search low : high : {}", low, high); while (low <= high) { int mid = (int) (Math.ceil(high / 2.0 + low / 2.0)); StoreKey found = getKeyAt(duplicate, mid); logger.trace("Index Segment binary search - key found on iteration {}", indexFile.getAbsolutePath(), found); int result = found.compareTo(keyToFind); if (result == 0) { byte[] buf = new byte[valueSize]; duplicate.get(buf); toReturn = new IndexValue(startOffset.getName(), ByteBuffer.wrap(buf)); break; } else if (result < 0) { low = mid + 1; } else { high = mid - 1; } } if (bloomFilter != null && toReturn == null) { metrics.bloomFalsePositiveCount.inc(); } } } } catch (IOException e) { throw new StoreException("IndexSegment : " + indexFile.getAbsolutePath() + " IO error while searching", e, StoreErrorCodes.IOError); } finally { rwLock.readLock().unlock(); } return toReturn; }