Skip to content
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

DRIVERS-2584 Errors handling in Convenient Transactions API #1475

Conversation

comandeo
Copy link

@comandeo comandeo commented Nov 15, 2023

Please complete the following before merging:

  • Update changelog.
  • Make sure there are generated JSON files from the YAML test files - not applicable.
  • Test changes in at least one language driver - not applicable.
  • Test these changes against all server versions and topologies (including standalone, replica set, sharded clusters, and serverless) - not applicable.

Ruby Implementation

comandeo-mongo and others added 2 commits November 15, 2023 15:30
….rst

Co-authored-by: Andreas Braun <alcaeus@users.noreply.github.com>
@comandeo comandeo marked this pull request as ready for review November 15, 2023 16:29
@comandeo comandeo requested a review from a team as a code owner November 15, 2023 16:30
@comandeo comandeo requested review from durran and removed request for a team November 15, 2023 16:30
@ShaneHarvey
Copy link
Member

The underlying issue of suppressing command errors is also a pitfall in the core transaction API. Should we update that spec too?

@comandeo
Copy link
Author

The underlying issue of suppressing command errors is also a pitfall in the core transaction API. Should we update that spec too?

Good point, thank you! Added some clarification to the core API.

Handling command errors
-----------------------

Drivers MUST document that command errors that do not have the
Copy link
Contributor

@kmahar kmahar Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just be "command errors may abort the transaction on the server", regardless of the label. the server also aborts the transaction on many (if not all) transient transaction errors (e.g. WriteConflict).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we recommend re-raising all command errors inside with_transaction callback then? Since we do not have a reliable indicator which command aborts the transaction and with does not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the distinction is perhaps relevant in that, if the user doesn't re-raise an error but it's a TransientTransactionError, the driver still ends up doing the correct thing and retrying, since it gets NoSuchTransaction, a different TransientTransactionError.
whereas for a non-transient error we end up with the infinite loop issue.

so I think it's less strictly necessary to recommend re-raising TransientTransactionErrors. however, the reason it happens to work in that case is a little funny. so for simplicity maybe it's best to not distinguish so users don't have to think about error labels and just say re-raise all errors?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I agree. We should recommend re-raising all errors. If a user has some specific use case, core API will be a better choice.

will result in an infinite loop.


Drivers SHOULD recommend that the callback re-throw command errors if they
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, why are these a SHOULD and not a MUST? It seems to me like it would be required, 1) to lower the potential cases and 2) to have a quick point of reference for all drivers when users run into this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable, changed to MUST.

@comandeo comandeo requested a review from durran November 24, 2023 09:11
….rst

Co-authored-by: Jeremy Mikola <jmikola@gmail.com>
For example, ``DuplicateKeyError`` is an error that aborts a transaction on the
server. If the callback catches ``DuplicateKeyError`` and does not re-throw it,
the driver will attempt to commit the transaction. The server will reject the
commit attempt with ``NoSuchTransaction`` error. This error has the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@comandeo: @alcaeus will bring this up with you, but when talking about this earlier today we discussed whether "NoSuchTransaction" should trigger an early break from the withTransaction retry loop since it may indicate that the callback did something unexpected.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this with @alcaeus last week, and decided to keep the existing commit logic.

Rationale: when a driver receives NoSuchTransaction, we do not know what happened. This situation may be a result of some server side situation, like a fail-over. If this is the case, the driver should retry the transaction completely.

Since we cannot distinguish between situations where the callback did something unexpected and where something went wrong on the server, we should try to be safe, and retry. With the changes proposed in this PR we give users clear instructions to let the driver decide how to handle errors.

@comandeo comandeo merged commit 13117d6 into mongodb:master Dec 5, 2023
3 checks passed
@comandeo comandeo deleted the 2584-document-errors-handlinging-convenient-api branch December 5, 2023 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants