-
Notifications
You must be signed in to change notification settings - Fork 340
Improvements to the Transaction API #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…rrors; Returning the new value when the txn commits.
firebase_admin/db.py
Outdated
|
||
Args: | ||
transaction_update: function that takes in current database data as a parameter. | ||
transaction_update: A function which will be passed tbe current data stored at this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/tbe/the
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
value of this reference into a new value. If another client writes to this location before | ||
the new value is successfully saved, the update function is called again with the new | ||
current value, and the write will be retried. In case of repeated failures, this method | ||
will retry the transaction up to 25 times before giving up and raising a TransactionError. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to make this number configurable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's reasonable. I've created #58 to implement it. Since this requires an API review, I'll defer it to a future development cycle.
while tries < _TRANSACTION_MAX_RETRIES: | ||
success, etag, snapshot = self._update_with_etag(val, etag) | ||
new_data = transaction_update(data) | ||
success, etag, data = self._update_with_etag(new_data, etag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we using the etag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in the next iteration of the loop etag
gets passed to the _update_with_etag()
call.
return False | ||
return new_data | ||
tries += 1 | ||
raise TransactionError('Transaction aborted after failed retries.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add the number of retries attempted to this error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets report that at #58 to be fixed in the future. We are trying to get a release build out at the moment.
Follow up to #54. Implements #56.
transaction()
method.