Add MongoDB's configuration properties for consistency#48879
Add MongoDB's configuration properties for consistency#48879jayychoi wants to merge 1 commit intospring-projects:mainfrom
Conversation
Closes spring-projectsgh-46261 Signed-off-by: Jay Choi <jayyoungchoi22@gmail.com>
| * Read concern level for read operations. Supported values are 'local', 'available', | ||
| * 'majority', 'linearizable', and 'snapshot'. Overrides the value in 'uri' if set. | ||
| */ | ||
| private @Nullable String readConcern; |
There was a problem hiding this comment.
Thanks for pointing that out. I was working with multiple properties and didn't think of it. I agree that using an enum would be better. In the same vein, I'm thinking of using an enum for ReadPreference.mode as well.
|
Thanks for the PR. It seems to ignore the ideas in #46261 (comment) without explaining why. It may be that those proposed properties are not adequate but we can't review this without an explanation of why that's the case. |
|
@wilkinsona Sorry for not clarifying this upfront. If I missed anything else, please let me know. Why
|
|
Thanks for the additional details. Using three separate properties to configure the write concern adds quite a bit of complexity for users. It means that they can't make use of the constants that, presumably, provide an easy way to use the most common configurations. That said, there may be some benefit to being able to configure a custom write concern that doesn't use one of the pre-canned constants. I'm not sure how best to do that using configuration properties. It may be that we only offer property-based configuration for the constants. Unfortunately, having looked at this more, it's clear that we need to do some design work before any progress can be made here. Sorry for the wasted effort but I think we need to take a step back as it's not clear that this PR is heading in the right direction. Thanks anyway for the PR, but I'm going to close this one and label the issue as requiring design work. |
|
Thanks for the review and feedback. I completely understand that design work needs to come first before implementation. Looking forward to contributing again once the direction is clearer. |
Related Issue
Closes gh-46261
Summary
This adds configuration properties for MongoDB's read and write consistency settings, enabling declarative configuration of
ReadConcern,WriteConcern, andReadPreferencevia application properties.Currently, configuring MongoDB consistency settings requires either:
?readPreference=secondaryPreferred)MongoClientSettingsBuilderCustomizerin JavaThis approach lacks consistency with other properties and increases configuration complexity for operations teams. This enhancement allows configuration like:
Changes
readConcernproperty toMongoPropertiesfor read concern level configurationWriteConcernnested class withw,journal, andwTimeoutpropertiesReadPreferencenested class withmode,tags, andmaxStalenesspropertiesMongoConnectionDetailsinterface withgetReadConcern(),getWriteConcern(), andgetReadPreference()methodsPropertiesMongoConnectionDetailsStandardMongoClientSettingsBuilderCustomizerDesign Decisions
applyConnectionString(), so individual properties override URI settings.PropertiesMongoConnectionDetailsthat createReadConcern,WriteConcern, andReadPreferenceobjects were written with reference to the logic inConnectionStringthat creates each object.InvalidConfigurationPropertyValueExceptionwhentagsormax-stalenessis configured withoutmode.read-preference.tagsproperty support priority-based fallback usingList<Map<String, String>>structure.read-preference.tagsproperty can accept an empty map as the last fallback, which can be specified using-or- {}in YAML. This is not supported inapplication.propertiesdue to format limitations.