@Override public int readInt() throws IOException { int i = buf.getInt(offset); offset += 4; return i; }
@Override public BolBuffer key( BolBuffer rawEntry, BolBuffer keyBuffer) { int length = rawEntry.getInt(0); rawEntry.sliceInto(4, length, keyBuffer); return keyBuffer; }
@Override public long version( BolBuffer rawEntrys) { return rawEntrys.getLong(4 + rawEntrys.getInt(0) + 8 + 1); }
@Override public BolBuffer key( BolBuffer rawEntry, BolBuffer keyBuffer) { rawEntry.sliceInto(4, rawEntry.getInt(0), keyBuffer); return keyBuffer; }
@Override public long timestamp( BolBuffer rawEntrys) { return rawEntrys.getLong(4 + rawEntrys.getInt(0)); }
@Override public boolean tombstone( BolBuffer rawEntrys) { return rawEntrys.get(4 + rawEntrys.getInt(0) + 8) != 0; }
@Override public BolBuffer merge( BolBuffer currentRawEntry, BolBuffer addingRawEntry) { int currentKeyLength = currentRawEntry.getInt(0); int addingKeyLength = addingRawEntry.getInt(0); long currentsTimestamp = currentRawEntry.getLong(4 + currentKeyLength); long currentsVersion = currentRawEntry.getLong(4 + currentKeyLength + 8 + 1); long addingsTimestamp = addingRawEntry.getLong(4 + addingKeyLength); long addingsVersion = addingRawEntry.getLong(4 + addingKeyLength + 8 + 1); if ((currentsTimestamp > addingsTimestamp) || (currentsTimestamp == addingsTimestamp && currentsVersion > addingsVersion)) { return currentRawEntry; } else { return addingRawEntry; } }
@Override public boolean streamRawEntry(int index, BolBuffer rawEntry, BolBuffer keyBuffer, BolBuffer valueBuffer, ValueStream stream) throws Exception { if (rawEntry == null) { return stream.stream(index, null, -1, false, -1, null); } int keyLength = rawEntry.getInt(0); BolBuffer key = rawEntry.sliceInto(4, keyLength, keyBuffer); BolBuffer payload = null; if (valueBuffer != null) { int payloadLength = rawEntry.getInt(4 + keyLength); if (payloadLength >= 0) { payload = rawEntry.sliceInto(4 + keyLength + 4, payloadLength, valueBuffer); } } return stream.stream(index, key, 0, false, 0, payload); }
@Override public boolean streamRawEntry(int index, BolBuffer rawEntry, BolBuffer keyBuffer, BolBuffer valueBuffer, ValueStream stream) throws Exception { if (rawEntry == null) { return stream.stream(index, null, -1, false, -1, null); } int keyLength = rawEntry.getInt(0); BolBuffer key = rawEntry.sliceInto(4, keyLength, keyBuffer); long timestamp = rawEntry.getLong(4 + keyLength); boolean tombstone = rawEntry.get(4 + keyLength + 8) != 0; long version = rawEntry.getLong(4 + keyLength + 8 + 1); BolBuffer payload = null; if (valueBuffer != null) { int payloadLength = rawEntry.getInt(4 + keyLength + 8 + 1 + 8); if (payloadLength >= 0) { payload = rawEntry.sliceInto(4 + keyLength + 8 + 1 + 8 + 4, payloadLength, valueBuffer); } } return stream.stream(index, key, timestamp, tombstone, version, payload); }
public static void main(String[] args) throws Exception { File root = Files.createTempDir(); AtomicLong globalHeapCostInBytes = new AtomicLong(); LABStats stats = new LABStats(globalHeapCostInBytes); LABEnvironment labEnvironment = buildEnv(globalHeapCostInBytes, stats, root); ValueIndex<byte[]> index = buildValueIndex(labEnvironment, "foo"); update(index, false, 100, 2, true); index.commitAndWait(0, true); ValueStream valueStream = (index1, key, timestamp, tombstoned, version, payload) -> { String keyString = key == null ? null : String.valueOf(key.getInt(0)); String valueString = payload == null ? null : String.valueOf(payload.getInt(0)); System.out.println( "\tindex:" + index1 + " key:" + keyString + " value:" + valueString + " timestamp:" + timestamp + " version:" + version + " tombstoned:" + tombstoned); return true; }; pointGet(index, 16, valueStream); pointRangeScan(index, 16, 32, valueStream); pointRangeScan(index, 15, 32, valueStream); // no results because 15 isn't a valid point start of scan rangeScan(index, 15, 32, valueStream); update(index, true, 100, 16, true); index.commitAndWait(0, true); pointGet(index, 16, valueStream); pointRangeScan(index, 16, 32, valueStream); pointRangeScan(index, 15, 32, valueStream); // no results because 15 isn't a valid point start of scan rangeScan(index, 15, 32, valueStream); index.rowScan(valueStream, true); labEnvironment.shutdown(); }
@Override public boolean streamRawEntry(int index, BolBuffer rawEntry, BolBuffer keyBuffer, BolBuffer valueBuffer, ValueStream stream) throws Exception { if (rawEntry == null) { return stream.stream(index, null, -1, false, -1, null); } BolBuffer key = rawEntry.sliceInto(0, keyLength, keyBuffer); long timestamp = rawEntry.getLong( keyLength); boolean tombstone = rawEntry.get( keyLength + 8) != 0; long version = rawEntry.getLong(keyLength + 8 + 1); BolBuffer payload = null; if (valueBuffer != null) { int payloadLength = rawEntry.getInt(keyLength + 8 + 1 + 8); if (payloadLength >= 0) { payload = rawEntry.sliceInto( keyLength + 8 + 1 + 8 + 4, payloadLength, valueBuffer); } } return stream.stream(index, key, timestamp, tombstone, version, payload); }