Read-only transactions

This article (FoundationDB: A Distributed Unbundled Transactional Key Value Store (Sigmod 2021)) claims:

In addition to the above read-write transactions, FDB also supports read-only transactions and snapshot reads.

Question: How to create a read-only transaction (using C API)?

You never write anything and you don’t call fdb_transaction_commit :slight_smile:. There’s really nothing special here, read transactions are not differently started than write transactions.

Snapshot reads are a bit different as they change the conflict resolution of a transaction. Basically, they allow you to disable read-write conflict resolution for some of your reads. For a read-only transaction doing snapshot reads doesn’t have any effects. This is documented here.

Thanks for your explanation!

@markus.pilman is the “don’t call commit” part really needed? I’ve tried some read transactions in a hot loop and committing:

public static void main(String[] args) {
        FDB fdb = FDB.selectAPIVersion(710);
        var db = fdb.open();
        while(true) {
            var tr = db.createTransaction();
            tr.get("foo".getBytes()).join();
            tr.commit();
            tr.close();
        }
    }
Workload:
  Read rate              - 760 Hz
  Write rate             - 0 Hz
  Transactions started   - 746 Hz
  Transactions committed - 1 Hz
  Conflict rate          - 0 Hz

So even if I commit, the server cluster receives no commits. Is this optimized on the client side? We use Java annotation based declarative transactions, so we always commit even in read only situations, can we continue to do so relying on this optimization?

Yes, this is a client side optimization. You can still call commit, it will be a no-op.

2 Likes