@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)); } }
@Override public void close() { synchronized (this) { if (this.closed) return; this.closed = true; } if (XodusKVStore.this.log.isTraceEnabled()) XodusKVStore.this.log.trace("closing " + this); try { this.cursor.close(); } catch (Throwable e) { XodusKVStore.this.log.debug("caught exception closing Xodus cursor (ignoring)", e); } }
@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 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()); }
if (this.reverse) { if (this.maxKey != null) { final boolean found = this.cursor.getSearchKeyRange(new ArrayByteIterable(this.maxKey)) != null; assert !found || ByteUtil.compare(XodusKVStore.get(this.cursor.getKey(), false), this.maxKey) >= 0 : "cusor.getSearchKeyRange() returned " + ByteUtil.toString(XodusKVStore.get(this.cursor.getKey(), false)) + " < " + ByteUtil.toString(this.maxKey); if (XodusKVStore.this.log.isTraceEnabled()) final boolean found = this.cursor.getSearchKeyRange(new ArrayByteIterable(this.minKey)) != null; if (XodusKVStore.this.log.isTraceEnabled()) XodusKVStore.this.log.trace("initial seek to " + ByteUtil.toString(this.minKey) + " -> " + found); if (found) { final byte[] key = XodusKVStore.get(cursor.getKey(), true); assert ByteUtil.compare(key, this.minKey) >= 0 : "cusor.getSearchKeyRange() returned " + ByteUtil.toString(key) + " < " + ByteUtil.toString(this.minKey); this.finished = true; else this.next = new KVPair(key, XodusKVStore.get(cursor.getValue(), true)); } else { if (XodusKVStore.this.log.isTraceEnabled())
@Override public synchronized void remove() { Preconditions.checkState(!this.closed, "iterator closed"); Preconditions.checkState(this.removeKey != null); Preconditions.checkState(!XodusKVStore.this.txType.isReadOnly(), "read-only transaction"); if (XodusKVStore.this.log.isTraceEnabled()) XodusKVStore.this.log.trace("remove " + ByteUtil.toString(this.removeKey)); if (this.removable) this.cursor.deleteCurrent(); else XodusKVStore.this.remove(this.removeKey); this.removeKey = null; this.removable = false; }
@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); }
@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)); } } }
@Override public void close( ) { if ( closed ) { return; } cursor.close(); transaction.abort(); nextValue = null; closed = true; }
if (!this.cursor.getPrev()) { if (XodusKVStore.this.log.isTraceEnabled()) XodusKVStore.this.log.trace("seek previous -> DONE"); return false; key = XodusKVStore.get(this.cursor.getKey(), true); + ByteUtil.toString(key) + " >= " + ByteUtil.toString(this.maxKey)); this.cursor.getSearchKeyRange(new ArrayByteIterable(this.maxKey)); // recalibrate and try again continue; if (!this.cursor.getNext()) { if (XodusKVStore.this.log.isTraceEnabled()) XodusKVStore.this.log.trace("seek next -> DONE"); return false; key = XodusKVStore.get(this.cursor.getKey(), true); this.next = new KVPair(key, XodusKVStore.get(cursor.getValue(), true)); if (XodusKVStore.this.log.isTraceEnabled()) XodusKVStore.this.log.trace("seek " + (this.reverse ? "previous" : "next") + " -> " + this.next);