@Override public CloseableIterator<KVPair> getRange(byte[] minKey, byte[] maxKey, boolean reverse) { Preconditions.checkState(!this.closed.get(), "transaction closed"); return new XodusIter(this.store.openCursor(this.tx), minKey, maxKey, reverse); }
InnerIterator( final LocalDB.DB db ) { this.transaction = environment.beginReadonlyTransaction(); this.cursor = getStore( db ).openCursor( transaction ); doNext(); }
@Benchmark public void readCrc(final Reader r, final Blackhole bh) { r.crc.reset(); try (Cursor c = r.store.openCursor(r.tx)) { while (c.getNext()) { r.crc.update(c.getKey().getBytesUnsafe(), 0, r.keySize); r.crc.update(c.getValue().getBytesUnsafe(), 0, r.valSize); } } bh.consume(r.crc.getValue()); }
@Override public void removeRange(byte[] minKey, byte[] maxKey) { Preconditions.checkState(!this.closed.get(), "transaction closed"); Preconditions.checkState(!this.txType.isReadOnly(), "read-only transaction"); try (final Cursor cursor = this.store.openCursor(this.tx)) { boolean found = minKey != null && minKey.length > 0 ? cursor.getSearchKeyRange(new ArrayByteIterable(minKey)) != null : cursor.getNext(); while (found) { if (maxKey != null && ByteUtil.compare(XodusKVStore.get(cursor.getKey(), false), maxKey) >= 0) break; cursor.deleteCurrent(); found = cursor.getNext(); } } }
@Benchmark public void readSeq(final Reader r, final Blackhole bh) { try (Cursor c = r.store.openCursor(r.tx)) { while (c.getNext()) { bh.consume(c.getValue().getBytesUnsafe()); } } }
@Override public KVPair getAtLeast(byte[] minKey, byte[] maxKey) { Preconditions.checkState(!this.closed.get(), "transaction closed"); try (final Cursor cursor = this.store.openCursor(this.tx)) { final boolean found = minKey != null && minKey.length > 0 ? cursor.getSearchKeyRange(new ArrayByteIterable(minKey)) != null : cursor.getNext(); if (!found) return null; final byte[] key = XodusKVStore.get(cursor.getKey(), true); if (maxKey != null && ByteUtil.compare(key, maxKey) >= 0) return null; return new KVPair(key, XodusKVStore.get(cursor.getValue(), true)); } }
@Benchmark public void readRev(final Reader r, final Blackhole bh) { try (Cursor c = r.store.openCursor(r.tx)) { c.getLast(); do { bh.consume(c.getValue().getBytesUnsafe()); } while (c.getPrev()); } }
@Override public KVPair getAtMost(byte[] maxKey, byte[] minKey) { Preconditions.checkState(!this.closed.get(), "transaction closed"); try (final Cursor cursor = this.store.openCursor(this.tx)) { // It's possible somebody could be simultaneously inserting keys just after maxKey, in which case we // could be tricked into returning a key > maxKey. This is unlikely, but make sure it can't affect us. while (true) { if (maxKey != null) cursor.getSearchKeyRange(new ArrayByteIterable(maxKey)); if (!cursor.getPrev()) return null; final byte[] key = XodusKVStore.get(cursor.getKey(), true); if (maxKey != null && ByteUtil.compare(key, maxKey) >= 0) continue; if (minKey != null && ByteUtil.compare(key, minKey) < 0) return null; return new KVPair(key, XodusKVStore.get(cursor.getValue(), true)); } } }
@Benchmark public void readXxh64(final Reader r, final Blackhole bh) { long result = 0; try (Cursor c = r.store.openCursor(r.tx)) { while (c.getNext()) { result += xx_r39().hashBytes(c.getKey().getBytesUnsafe(), 0, r.keySize); result += xx_r39(). hashBytes(c.getValue().getBytesUnsafe(), 0, r.valSize); } } bh.consume(result); }