UID getOrCreateUid(final MapDefinition mapDefinition,
                       final PooledByteBuffer uidPooledBuffer) {
        return lmdbEnv.getWithWriteTxn(writeTxn -> {
            try (final PooledByteBuffer mapDefinitionPooledBuffer = mapUidForwardDb.getPooledKeyBuffer()) {

                final ByteBuffer mapDefinitionBuffer = mapDefinitionPooledBuffer.getByteBuffer();

                mapUidForwardDb.serializeKey(mapDefinitionBuffer, mapDefinition);

                // if we already have a UID for this mapDefinition return it
                // if not, create the pair of entries and return the created UID
                return mapUidForwardDb.getAsBytes(writeTxn, mapDefinitionBuffer)
                        .map(uidBuffer -> {
                            LOGGER.trace(() ->
                                    LogUtil.message("Found existing UID {}",
                                            ByteBufferUtils.byteBufferInfo(uidBuffer)));
                            // uidBuffer belongs to LMDB so we must copy it before leaving the txn
                            final ByteBuffer uidBufferCopy = uidPooledBuffer.getByteBuffer();
                            ByteBufferUtils.copy(uidBuffer, uidBufferCopy);
                            return mapUidForwardDb.deserializeValue(uidBufferCopy);
                        })
                        .orElseGet(() -> {
                            // The returned UID wraps uidPooledBuffer so no copy needed
                            return createForwardReversePair(writeTxn, mapDefinitionBuffer, uidPooledBuffer);
                        });
            }
        });
    }
Returns the UID corresponding to the passed mapDefinition if it exists in the two mapping DBs. If it doesn't
exist, a forward and reverse mapping will be created and the new UID returned. The returned UID wraps a
direct allocation {@link ByteBuffer} owned by LMDB, so it may ONLY be used whilst still inside the passed
{@link Txn}.
stroom-pipeline/src/main/java/stroom/pipeline/refdata/store/offheapstore/MapDefinitionUIDStore.java