googleapis / googleapis/google-cloud-go
firestore: Return []WriteResult from RunTransaction in Go
- Dominant language
- Go
- Stars
- 4.5k
- Forks
- 1.6k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 109
Description
We need access to the []WriteResult from RunTransaction in the Golang SDK for Firestore, so that we can detect when snapshots are not created from updates (where the update operation results in the same document state).
We use document snapshots to reconstruct transactions made in Firestore, so that we can send transaction "batches" to clients instead of just snapshot updates - this allows clients to always have a transactionally consistent view of the database, something not possible if you're just listening for snapshot changes to collections at the application level.
We have an issue right now where our transaction operation code performs updates to documents, records the key of the document as being "mutated" and then later on the transaction reconstruction code waits to see that document snapshot arrive. However, if the document doesn't actually change, no snapshot is generated, so the code waits forever (before detecting it's not making process and panicking).
You can see how [transactions are made here](https://github.com/networknext/configstore/blob/master/server/transaction_process.go), and [how they're reconstructed here](https://github.com/networknext/configstore/blob/master/server/transaction_watcher.go).
We can sort of workaround the issue for now by making a get before performing the update, and checking to see if we would actually change the document. Note however this isn't perfect - if two requests make the same update to the same document at the same time, and they both read the old version, they'll both think they can make the update and get a snapshot, when in fact only one of the transactions will result in a snapshot, and the transaction reconstruction will stall again. So we really do need to access the []WriteResult from the commit so we can omit `mutatedKeys` that weren't actually updated in the transaction operation.
Contributor guide
Assessment
This issue has not been assessed yet.