public Optional<ByteBuffer> getAsBytes(final Txn<ByteBuffer> txn,
                                           final UID mapDefinitionUid,
                                           final long key) {
        LOGGER.trace(() -> "get called for " + mapDefinitionUid + ", key " + key);

        try (final PooledByteBuffer startKeyPolledBuffer = getPooledKeyBuffer()) {

            final KeyRange<ByteBuffer> keyRange = buildKeyRange(
                    mapDefinitionUid,
                    key,
                    startKeyPolledBuffer.getByteBuffer());

            // these lines are useful for debugging with SMALL data volumes
//        logDatabaseContents(txn);
//        logRawDatabaseContents(txn);
//        LmdbUtils.logRawContentsInRange(lmdbEnvironment, lmdbDbi, txn, keyRange);
//        LmdbUtils.logContentsInRange(
//                lmdbEnvironment,
//                lmdbDbi,
//                txn,
//                keyRange,
//                buf -> keySerde.deserialize(buf).toString(),
//                buf -> valueSerde.deserialize(buf).toString());

            final AtomicInteger cnt = new AtomicInteger();
            try (CursorIterable<ByteBuffer> cursorIterable = getLmdbDbi().iterate(
                    txn, keyRange)) {
                // loop backwards over all rows with the same mapDefinitionUid, starting at key
                for (final CursorIterable.KeyVal<ByteBuffer> keyVal : cursorIterable) {
                    cnt.incrementAndGet();
                    final ByteBuffer keyBuffer = keyVal.key();

                    final CompareResult compareResult = RangeStoreKeySerde.isKeyInRange(
                            keyBuffer,
                            mapDefinitionUid,
                            key);

                    if (LOGGER.isTraceEnabled()) {
                        final RangeStoreKey rangeStoreKey = keySerde.deserialize(keyBuffer);
                        LOGGER.trace("rangeStoreKey {}, keyBuffer {}, compareResult {}",
                                rangeStoreKey,
                                ByteBufferUtils.byteBufferInfo(keyBuffer),
                                compareResult);
                    }

                    if (CompareResult.IN_RANGE.equals(compareResult)) {
                        final UID uidOfFoundKey = UIDSerde.extractUid(keyBuffer);
                        // double check to be sure we have the right mapDefinitionUid
                        if (!uidOfFoundKey.equals(mapDefinitionUid)) {
                            throw new RuntimeException(LogUtil.message(
                                    "Found a key with a different mapDefinitionUid, found: {}, expected {}",
                                    uidOfFoundKey, mapDefinitionUid));
                        }
                        LOGGER.trace(() -> "key " + key + " is in the range, " +
                                "found the required value after " + cnt.get() + " iterations");

                        // TODO we are returning the cursor buffer out of the cursor scope so we must first copy it.
                        //  Better still we could accept an arg of a Function<ByteBuffer, ByteBuffer> to map the
                        //  valueStoreKey buffer into the actual value bytebuffer from the valueStoreDb.
                        //  This would save a buffer copy.
                        //if (cnt.get() > 1) {
                        //LOGGER.info("{} iterations", cnt.get());
                        //}
                        return Optional.of(keyVal.val());
                    } else {
                        // If we are not inside the range then we have no hit.
                        // This assumes ranges are non-overlapping.
                        // e.g. if an entry exists with key [10-20] and we lookup with key 15,
                        // the cursor start key will be [15-Long.MAX_VAL]. Thus [10-20] will be
                        // the first one found.  If the first one found was [0-10] then we could safely
                        // bomb out.
                        break;
                    }
                }
            }
            LOGGER.trace(() ->
                    "Value not found for " + mapDefinitionUid + ", key " + key + ", iterations " + cnt.get());
            return Optional.empty();
        }
    }
Looks up the supplied mapDefinitionUid and key in the store and attempts to find a range that includes the
passed key. It will scan backwards from key until it finds the first matching range. If no matching range
is found an empty Optional is returned.
stroom-pipeline/src/main/java/stroom/pipeline/refdata/store/offheapstore/databases/RangeStoreDb.java