-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
MongoDB with Panache: allow setting per collection read preference #30118
Conversation
This comment has been minimized.
This comment has been minimized.
I have one question about this: What happens if the user enters an incorrect value? |
My guess would be that |
@gsmet we also do this when we build the MongoClient as we can pass the default read preference from the config. Currently, this would generate an IAE: I can try/catch and give a more meaningful message but this will still be an IAE |
A more meaningful / contextual message is always better :) |
3af5026
to
bb402b2
Compare
try { | ||
collection = collection.withReadPreference(ReadPreference.valueOf(mongoEntity.readPreference())); | ||
} catch (IllegalArgumentException iae) { | ||
throw new IllegalArgumentException("Illegal read preference " + mongoEntity.readPreference() |
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.
We should probably pass the original exception as the cause
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 agree this is usually a good practice but here it will not give additional information.
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.
Okay, if you have actually seen what it looks like, I trust you :)
} catch (IllegalArgumentException iae) { | ||
throw new IllegalArgumentException("Illegal read preference " + mongoEntity.readPreference() | ||
+ " configured in the @MongoEntity annotation of " + entityClass.getName() + "." | ||
+ " Supported values are primary|primaryPreferred|secondary|secondaryPreferred|nearest"); |
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.
Just asking: you cannot extract the values from the enum? (I haven't checked)
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.
No, this is not en enum but a regular class.
Failing Jobs - Building bb402b2
Full information is available in the Build summary check run. Failures⚙️ JVM Tests - JDK 17 MacOS M1 #- Failing: integration-tests/mongodb-panache
📦 integration-tests/mongodb-panache✖
✖
✖
✖
|
Weird how the M1 tests are failing on some Mongo tests... Is it related? |
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.
Let's get this in. As for the M1 failures, it's hard to know and we don't have a M1 host anymore.
Fixes #29997