GeezerVison is showing github.com — Datastore transactions don't provide read-after-write semantics · Issue #1134 · googleapis/google-cloud-java
Datastore transactions don't provide read-after-write semantics #1134DescriptionHere is a simple repro to demonstrate the issue. Reads in transactions will not reflect writes from the same transaction:
// 1. Setup
Datastore datastore = ...
KeyFactory keyFactory = datastore.newKeyFactory().kind("test");
Key key = keyFactory.newKey(1);
// 1. Set initial value of entity to "old"
datastore.put(Entity.builder(keyFactory.newKey(1)).set("value", "old").build());
// 2. Start transaction and make sure value is "old"
Transaction transaction = datastore.newTransaction();
Entity entity1 = transaction.get(key);
if (!entity1.getString("value").equals("old")) {
throw new IllegalStateException("Unexpected value");
}
// 3. Write "new" value
transaction.put(Entity.builder(entity1).set("value", "new").build());
// 4. Read entity again, value is still "old"
Entity entity2 = transaction.get(key);
if (!entity2.getString("value").equals("new")) {
throw new IllegalStateException("Unexpected value"); // throws here
}
AFAIK Datastore v1beta3 makes this explicit by forcing all writes into the commit, making it impossible to read after a write. This behavior should also be reflected in the Java API, perhaps by throwing if there is a read attempt after a write. Activitymziccard commented on Aug 8, 2016 Hi @jdimond, thanks for the report!
I am not sure we should throw here or rather document what's going on. @aozarov thoughts? aozarov commented on Aug 8, 2016 I think this is already documented.
I don't think we should throw an exception in this case. jdimond commented on Aug 8, 2016 I think this goes beyond documenting (since I also believe most devs only read documentations when they run into errors). It is non-obvious that transactions don't have read-after-write semantics, and developers might run into this without noticing, which seems very dangerous given the nature of transactions. If they are running into this exception they will be made aware of the limitations of Datastore transactions and can decide whether they are fine with missing read-after-write semantics by working around the no reads after writes (similar to what the SDK does automatically today). aozarov commented on Aug 8, 2016 Note that this is the same for App Engine Datastore API and documentation seemed to be sufficient. mziccard commented on Sep 6, 2016 I am closing this as documentation seems sufficient in this case.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|