private synchronized CurrentDbState getCurrentDbState() {
        if (!currentDbStateFactory.isStoreLatestEventReference()) {
            return null;
        }

        final AtomicReference<CurrentDbState> currentDbStateAtomicReference = new AtomicReference<>();
        final KeyRange<ByteBuffer> keyRange = LmdbRowKeyFactoryFactory.DB_STATE_KEY_RANGE;
        env.read(readTxn -> db.iterate(readTxn, keyRange, iterator -> {
            if (iterator.hasNext()) {
                final KeyVal<ByteBuffer> keyVal = iterator.next();
                final ByteBuffer key = keyVal.key();
                if (LmdbRowKeyFactoryFactory.isStateKey(key)) {
                    final ByteBuffer val = keyVal.val();
                    final long streamId = Objects.requireNonNull(getLong(val, 0),
                            "streamId not present in DB state");
                    final Long eventId = getLong(val, Long.BYTES);
                    final Long lastEventTime = getLong(val, Long.BYTES + Long.BYTES);
                    currentDbStateAtomicReference.set(new CurrentDbState(streamId, eventId, lastEventTime));
                }
            }
        }));

        return currentDbStateAtomicReference.get();
    }
Write data from the data store to an output removing them from the datastore as we go as they will be transferred
to another store.

@param output The output to write to.
stroom-query/stroom-query-common/src/main/java/stroom/query/common/v2/LmdbDataStore.java