public PutOutcome put(final Txn<ByteBuffer> writeTxn,
                          final ByteBuffer keyBuffer,
                          final ByteBuffer valueBuffer,
                          final boolean overwriteExisting,
                          final boolean isAppending) {
        try {
            boolean didPutSucceed;

            // First try with nooverwrite flag so the put will fail if the key exists
            // For use cases with heavy updates to existing entries this two-step put is not ideal,
            // we would need some kind of flag to indicate if we care about what was there before or not.
            // If we know the puts are in key order then using MDB_APPEND speeds up the puts a lot.
            final PutFlags[] initialPutFlags = isAppending
                    ? NO_OVERWRITE_AND_APPEND
                    : NO_OVERWRITE;
            didPutSucceed = lmdbDbi.put(writeTxn, keyBuffer, valueBuffer, initialPutFlags);

            final PutOutcome putOutcome;
            if (didPutSucceed) {
                putOutcome = PutOutcome.newEntry();
            } else {
                // Already have an entry for this key
                if (overwriteExisting) {
                    // Now try again without the overwrite flag set
                    // Can't use MDB_APPEND here as we know there is an existing value, which would make lmdb barf
                    didPutSucceed = lmdbDbi.put(writeTxn, keyBuffer, valueBuffer);

                    putOutcome = didPutSucceed
                            ? PutOutcome.replacedEntry()
                            : PutOutcome.failed();
                } else {
                    putOutcome = PutOutcome.failed();
                }
            }

            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("PutOutcome {} for key [{}], value [{}]",
                        putOutcome,
                        ByteBufferUtils.byteBufferInfo(keyBuffer),
                        ByteBufferUtils.byteBufferInfo(valueBuffer));
            }

            return putOutcome;
        } catch (RuntimeException e) {
            throw new RuntimeException(LogUtil.message("Error putting key {}, value {}",
                    ByteBufferUtils.byteBufferInfo(keyBuffer), ByteBufferUtils.byteBufferInfo(valueBuffer)), e);
        }
    }
This will fail if you are already inside a txn.
stroom-lmdb/src/main/java/stroom/lmdb/AbstractLmdbDb.java