public void deleteMapEntries(final BatchingWriteTxn batchingWriteTxn,
                                 final UID mapUid,
                                 final EntryConsumer entryConsumer) {

        try (PooledByteBuffer startKeyIncPooledBuffer = getPooledKeyBuffer();
                PooledByteBuffer endKeyExcPooledBuffer = getPooledKeyBuffer()) {

            final KeyRange<ByteBuffer> singleMapUidKeyRange = buildSingleMapUidKeyRange(
                    mapUid,
                    startKeyIncPooledBuffer.getByteBuffer(),
                    endKeyExcPooledBuffer.getByteBuffer());

            boolean isComplete = false;
            int totalCount = 0;

            // We need the outer loop as the inner loop may reach batch full state part way through
            // and break out. After the inner loop we commit the txn, so the iterable has to be re-created.
            while (!isComplete) {
                boolean foundMatchingEntry;
                // Scan over all entries from our start key and test each one to check we
                // haven't gone past the ones we want.
                try (CursorIterable<ByteBuffer> cursorIterable = getLmdbDbi().iterate(
                        batchingWriteTxn.getTxn(), singleMapUidKeyRange)) {

                    boolean didBreakOutEarly = false;
                    int batchCount = 0;
                    foundMatchingEntry = false;
                    final Iterator<KeyVal<ByteBuffer>> iterator = cursorIterable.iterator();

                    while (iterator.hasNext()) {
                        final KeyVal<ByteBuffer> keyVal = iterator.next();
                        LOGGER.trace(() -> LogUtil.message("Entry {} {}",
                                ByteBufferUtils.byteBufferInfo(keyVal.key()),
                                ByteBufferUtils.byteBufferInfo(keyVal.val())));

                        foundMatchingEntry = true;
                        // prefixed with our UID

                        // Pass the found kv pair from this entry to the consumer.
                        // Consumer MUST not hold on to the key/value references as they can change
                        // once the cursor is closed or moves position
                        entryConsumer.accept(batchingWriteTxn.getTxn(), keyVal.key(), keyVal.val());
                        // Delete this entry
                        iterator.remove();
                        batchCount++;

                        // Can't use batchingWriteTxn.commitIfRequired() as the commit would close
                        // the txn which then causes an error in the cursorIterable auto close
                        if (batchingWriteTxn.incrementBatchCount()) {
                            // Batch is full so break out
                            didBreakOutEarly = true;
                            break;
                        }
                    }

                    if (foundMatchingEntry) {
                        isComplete = !didBreakOutEarly;
                        totalCount += batchCount;
                        LOGGER.debug("Deleted {} {} entries this iteration, total deleted: {}",
                                batchCount, DB_NAME, totalCount);
                    } else {
                        isComplete = true;
                    }
                }

                if (foundMatchingEntry) {
                    // Force the commit as we either have a full batch or we have finished
                    // We may now have a partial purge committed, but we are still under write
                    // lock so no other threads can purge or load and there is a lock on the
                    // ref stream.
                    LOGGER.debug("Committing, totalCount {}", totalCount);
                    batchingWriteTxn.commit();
                } else {
                    LOGGER.debug("No entry found since last commit, not committing, totalCount {}",
                            totalCount);
                }
            }
        }
    }
Apply the passes entryConsumer for each entry found matching the supplied UID
stroom-pipeline/src/main/java/stroom/pipeline/refdata/store/offheapstore/databases/RangeStoreDb.java