Skip to content
Jonathan Colt edited this page Jun 29, 2018 · 1 revision

These are snipents from HelloLAB

Create an index

File root = Files.createTempDir();
AtomicLong globalHeapCostInBytes = new AtomicLong();
LABStats stats = new LABStats(globalHeapCostInBytes);

LABEnvironment labEnvironment = HelloLAB.buildEnv(globalHeapCostInBytes, stats, root);
ValueIndex<byte[]> index = HelloLAB.buildValueIndex(labEnvironment, "foo");

Write to index

BolBuffer rawEntryBuffer = new BolBuffer();
BolBuffer keyBuffer = new BolBuffer();
long timestamp = System.currentTimeMillis();
index.append((stream) -> {

  for (int i = 0; i < count; i++) {
    if (i % modulo == 0) {
      stream.stream(i, UIO.intBytes(i), timestamp, delete, version.incrementAndGet(), UIO.intBytes(i));
    }
  }
  return true;
}, fsync, rawEntryBuffer, keyBuffer);

Read from to index

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;
};

int key = 16
byte[] keyBytes = UIO.intBytes(key);
index.get((keyStream) -> {
    keyStream.key(0, keyBytes, 0, keyBytes.length);
    return true;
  },
  valueStream,
  true);

Output

index:0 key:16 value:16 timestamp:1530236944682 version:52 tombstoned:true

Range scan index

int from = 16;
int to = 32;
byte[] fromBytes = from == -1 ? null : UIO.intBytes(from);
byte[] toBytes = to == -1 ? null : UIO.intBytes(to);

index.rangeScan(fromBytes, toBytes, valueStream, true);

Output

index:-1 key:16 value:16 timestamp:1530236944682 version:52 tombstoned:false
index:-1 key:18 value:18 timestamp:1530236944607 version:10 tombstoned:false
index:-1 key:20 value:20 timestamp:1530236944607 version:11 tombstoned:false
index:-1 key:22 value:22 timestamp:1530236944607 version:12 tombstoned:false
index:-1 key:24 value:24 timestamp:1530236944607 version:13 tombstoned:false
index:-1 key:26 value:26 timestamp:1530236944607 version:14 tombstoned:false
index:-1 key:28 value:28 timestamp:1530236944607 version:15 tombstoned:false
index:-1 key:30 value:30 timestamp:1530236944607 version:16 tombstoned:false
Clone this wiki locally