Suppose you want a transaction with these properties:
- The transaction allows changes, and within the transaction you read back any changes you have made.
- The transaction is read-only, in the sense that you can make changes but any changes made during the transaction are discarded when the transaction ends.
- The transaction presents an up-to-date, fully consistent view of the database.
The traditional way to get this in SQL is to create the transaction with the necessary isolation level (e.g.
SERIALIZABLE), do whatever including possibly making changes, and then rollback the transaction instead of committing it.
You get the consistency of #3 pretty much automatically from lock-based databases, and from databases that are not clustered.
But is it possible to get such a transaction with CockroachDB?
The reason I ask is that in some distributed databases (e.g., FoundationDB was one), the data read from a transaction is not guaranteed to have been up-to-date (even in a read-only transaction) unless the transaction was committed and the
commit() operation completed successfully.
But in SQL, I don’t know of any way to say “commit this transaction but discard all the changes”. This implies that either CockroachDB doesn’t support this kind of transaction, or else even a transaction that has gets rolled back guarantees up-to-date views.
Which is it?