VersionStamp vs CommittedVersion

I read through the linked discussion but still have a few questions:

  • Is 8-byte Transaction Version unique across transactions?
  • What is the significance of Transaction Batch Order (last 2 bytes out of total 10 bytes that are stored on server); how is it computed? I suspect that it is providing some ordering for multiple writes happening in same transaction; Is that correct?
  • Is the Transaction Batch Order related to user version that Java client API exposes? How?
  • Seems like the user version only a client-side concept. How is it used to determine the final 10 bytes stored on server.

My use-case is that I am trying to write an API to generate a unique long if for a given key: long getOrCreateId(String guidKey)

I am trying to using VersionStamp’s first 8 bytes to get the Transaction Version which I am assuming to be a unique id globally.

byte[] ver = db.run(tx -> {
    final byte[] guidBytes = Tuple.from("key").pack();
    {
        // string->id
        final byte[] v = Tuple.from(Versionstamp.incomplete()).packWithVersionstamp();
        tx.mutate(MutationType.SET_VERSIONSTAMPED_VALUE, guidBytes, v);
    }
    {
        // id->string
        final byte[] k = new Tuple().add(Versionstamp.incomplete()).packWithVersionstamp();
        tx.mutate(MutationType.SET_VERSIONSTAMPED_KEY, k, guidBytes);
    }
    return tx.getVersionstamp();
});

ver.thenApply(versionStamp -> {
  final ByteBuffer bb = ByteBuffer.allocate(Long.BYTES).put(versionStamp, 0, Long.BYTES).order(ByteOrder.BIG_ENDIAN);
        bb.flip();
        return bb.getLong();
  });

At some later point, if I only have the “Transaction Version” (8 bytes) available, can I create a key using it to lookup the row in “id->string” index? In other words, I do not have a need for the last “2 bytes” of server stored VersionStamp; can I force it to be 0 (for above write transaction)?


thanks,
gaurav