Skip to content

Conversation

@HanaPearlman
Copy link
Contributor

No description provided.


# Retry writes on MMAPv1 should raise an actionable error, so we change the error message.
def raise_unsupported_error(e)
raise e, "This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string."
Copy link
Contributor

Choose a reason for hiding this comment

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

The original exception class and message need to be included in the final message following the #{e.class}: #{e} pattern.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the class of exception is not changing, it may also make sense to preserve the backtrace which looks like this:

new_e = Error::OperationFailure.new(new_msg)
new_e.set_backtrace(e.backtrace)
raise new_e

Copy link
Contributor Author

@HanaPearlman HanaPearlman Aug 7, 2019

Choose a reason for hiding this comment

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

Is there another place in the driver where we compose multiple error messages like above? I would have assumed that the helpful error message here ("This MongoDB deployment does not support retryable writes...") should come first, but your comment about not including a trailing period is making me think it should come after the original exception class and message.

Copy link
Contributor

Choose a reason for hiding this comment

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

The pattern I usually use is when translating one exception class to another, the message of the new class goes first, but when adding information to the existing exception and/or message, the information gets added at the end.

Example exceptions which get extended error messages are:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

retry_write(e, session, txn_num, &block)
rescue Error::OperationFailure => e
if (session.in_transaction? && !ending_transaction) || !e.write_retryable?
if e.code == 20 && e.message.start_with?("Transaction numbers")
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that OperationFailure already contains a bunch of logic for figuring out whether a specific error occurred, I think this logic should be moved to OperationFailure in a similar fashion to https://github.com/mongodb/mongo-ruby-driver/blob/master/lib/mongo/error/operation_failure.rb#L252.

it 'raises an exception with the correct error message' do
expect {
retryable.write
}.to raise_error(Mongo::Error::OperationFailure, 'This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the Ruby option should also be mentioned, e.g. Please add retryWrites=false to your connection string or retry_writes: false Ruby client option. And we do not include trailing periods in exception messages for composability. (I am aware of the spec language mandating this exact message.)

@p-mongo
Copy link
Contributor

p-mongo commented Aug 7, 2019

If a client has retry_reads: true set on an mmapv1 deployment, do the reads work?

@HanaPearlman
Copy link
Contributor Author

From what I can see yes, the reads succeed.

@HanaPearlman HanaPearlman changed the title WIP RUBY-1896 Raise an actionable error message when retryWrites fails due to using an unsupported storage engine RUBY-1896 Raise an actionable error message when retryWrites fails due to using an unsupported storage engine Aug 7, 2019
@HanaPearlman HanaPearlman requested a review from p-mongo August 7, 2019 20:49
@HanaPearlman HanaPearlman merged commit 3a1a083 into mongodb:master Aug 8, 2019
p-mongo pushed a commit that referenced this pull request Aug 8, 2019
…e to using an unsupported storage engine (#1481)

* initial actionable error message and tests

* integration test for mmapv1 retryable write

* remove unsupported error check from legacy retry writes, as it is not subject to current spec

* implemented feedback
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.

2 participants