Skip to content

DATAMONGO-1158 - Add Support for mongo-java-driver 3.0 #273

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

Closed
wants to merge 8 commits into from

Conversation

christophstrobl
Copy link
Member

We now support both mongo-java-driver 2.13 and 3.0 along with MongoDB Server 2.6.7 and 3.0.0.

Pleaes note that some of the configurations options might no longer be valid when used with version 3 of the mongo-java-driver. Have a look at the table below so see some of the major differences in using version 2.x or 3.0

                      | 2.x                   | 3.0
----------------------+-----------------------+-----------------------------------------------
default WriteConcern  | NONE                  | UNACKNOWLEDGED
----------------------+-----------------------+-----------------------------------------------
option for slaveOk    | available             | ignored
----------------------+-----------------------+-----------------------------------------------
option for autoConnect| available             | ignored
----------------------+-----------------------+-----------------------------------------------
write result checking | available             | defaults WriteConncern to ACKNOWLEGED for EXCEPTION
----------------------+-----------------------+-----------------------------------------------
rest index cache      | available             | throws UnsupportedOperationException
----------------------+-----------------------+-----------------------------------------------
DBRef resolution      | via DBRef.fetch       | via collection.findOne
----------------------+-----------------------+-----------------------------------------------
MapReduce Options     | applied               | ignored
----------------------+-----------------------+-----------------------------------------------
authentication        | via UserCredentials   | via MongoClient
----------------------+-----------------------+-----------------------------------------------
WriteConcernException | not available         | translated to DataIntegretyViolationException
----------------------+-----------------------+-----------------------------------------------
executeInSession      | available             | requestStart/requestDone commands ignored.
----------------------+-----------------------+-----------------------------------------------
index creation        | via createIndex       | via createIndex
----------------------+-----------------------+-----------------------------------------------

This PR will actually not set the version for mongo-java-driver to any 3.0-SNAPSHOT but will remain using 2.13.0. Please run mvn clean install -P mongo-3-next to build against lastest mongo-java-driver snapshots.

This pull request should supersed #269 (thanks @jyemin kicking this off - has been an invaluable help!)

@jyemin
Copy link
Contributor

jyemin commented Feb 12, 2015

Is the behavior change illustrated by MongoTemplateTests#throwsExceptionForDuplicateIds going to be an issue for users? Comparing the default profile (2.x driver) with mongo-3-next, I see that, although the test passes:

  • With the 3.x driver a org.springframework.dao.DuplicateKeyException is thrown
  • With the 2.x driver a org.springframework.data.mongodb.core.MongoDataIntegrityViolationException is thrown

And if I change the test to do this regardless of driver version:

template.setWriteConcern(WriteConcern.UNACKNOWLEDGED);
template.setWriteResultChecking(WriteResultChecking.EXCEPTION);

the behavior with the 2.x driver doesn't change, but with the 3.x driver it fails to throw an exception at all.

Would you consider changing MongoTemplate such that if WriteResultChecking.EXCEPTION is enabled, and WriteConcern.w < 1, it's changed to WriteConcern.ACKNOWLEDGED?

@christophstrobl
Copy link
Member Author

Thanks @jyemin good catch, seems I totally overlooked that one. Guess it would make sense to change the WriteConcern accordingly. I'll give it a spin.

@christophstrobl
Copy link
Member Author

Just ran the tests against MongoDB Server 3.0-rc7 with --storageEngine=wiredTiger and found that in that case we've some failing tests...

@odrotbohm
Copy link
Member

A few quick observations:

  • we should check all the newly introduced reflective invoker types for hideability in more nested packages (potentially even in package protected visibility) as they're basically mitigators between driver versions. Exposing them publicly in a very root package is a bit suboptimal.
  • please keep the Assert.notNull(…) etc. methods without a static import. Creating an inconsistency with the rest of the codebase doesn't add any value here and decreases readability. Static imports are fine for JUnit assertions as the methods still contain assert….
  • should we have a dedicated MongoClientFactoryBean instead of adding MongoClient support to MongoFactoryBean?
  • we should check the changes to SimpleMongoDbFactory against Spring Boot's Mongo auto-configuration. I can imagine that while we're retaining binary compatibility, an already build Spring Boot 1.2.x might call the constructor taking a Mongo instance with a MongoClient parameter. That might just work fine, I'd just like to to double check for unexpected glitches in that area.
  • do we need to reject <mongo:options /> in the XML namespace on 3.0?
  • it would be cool if we could add a few notes to the documentation in terms of what users might have to adapt or expect to change if they run on a 3.0 driver

Other than that: a great thank you to both @jyemin and @christophstrobl, looks like quite a way but a great achievement in the end :).

@christophstrobl
Copy link
Member Author

Thanks @olivergierke. Already changed package assignment of reflective invokers, static imports and documentation.
Concerning the changes in SimpleMongoDbFactory I altered spring-data-examples for mongodb to use latest snapshots, which seemed to work just as expected.

I was not sure about a dedicated MongoClientFactoryBean and did not want to add antother piece to this PR. Might be a good idea to potentially do it in an sperate issue. Same applies to <mongo:options /> where parts are still valid even for the new driver, so I do not think that we should reject it.

@jyemin
Copy link
Contributor

jyemin commented Feb 23, 2015

@christophstrobl let me know if you want a second set of eyes for those failing tests.

We now support mongo-java-driver version 2.x and 3.0 along with MongoDB Server 2.6.7 and 3.0.0.

Pleaes note that some of the configurations options might no longer be valid when used with version 3 of the mongo-java-driver. Have a look at the table below so see some of the major differences in using version 2.x or 3.0

                      | 2.x                   | 3.0
----------------------+-----------------------+-----------------------------------------------
default WriteConcern  | NONE                  | UNACKNOWLEDGED
----------------------+-----------------------+-----------------------------------------------
option for slaveOk    | available             | ignored
----------------------+-----------------------+-----------------------------------------------
option for autoConnect| available             | ignored
----------------------+-----------------------+-----------------------------------------------
write result checking | available             | ignored (errors are exceptions anyway)
----------------------+-----------------------+-----------------------------------------------
rest index cache      | available             | throws UnsupportedOperationException
----------------------+-----------------------+-----------------------------------------------
DBRef resolution      | via DBRef.fetch       | via collection.findOne
----------------------+-----------------------+-----------------------------------------------
MapReduce Options     | applied               | ignored
----------------------+-----------------------+-----------------------------------------------
authentication        | via UserCredentials   | via MongoClient
----------------------+-----------------------+-----------------------------------------------
WriteConcernException | not available         | translated to DataIntegretyViolationException
----------------------+-----------------------+-----------------------------------------------
executeInSession      | available             | requestStart/requestDone commands ignored.
----------------------+-----------------------+-----------------------------------------------
index creation        | via createIndex       | via createIndex
----------------------+-----------------------+-----------------------------------------------
We now support mongo-java-driver version 2.x and 3.0 along with MongoDB Server 2.6.7 and 3.0.0.

Pleaes note that some of the configurations options might no longer be valid when used with version 3 of the mongo-java-driver. Have a look at the table below so see some of the major differences in using version 2.x or 3.0.

                      | 2.x                   | 3.0
----------------------+-----------------------+-----------------------------------------------
default WriteConcern  | NONE                  | UNACKNOWLEDGED
----------------------+-----------------------+-----------------------------------------------
option for slaveOk    | available             | ignored
----------------------+-----------------------+-----------------------------------------------
option for autoConnect| available             | ignored
----------------------+-----------------------+-----------------------------------------------
write result checking | available             | defaults WriteConncern to ACKNOWLEGED for EXCEPTION
----------------------+-----------------------+-----------------------------------------------
rest index cache      | available             | throws UnsupportedOperationException
----------------------+-----------------------+-----------------------------------------------
DBRef resolution      | via DBRef.fetch       | via collection.findOne
----------------------+-----------------------+-----------------------------------------------
MapReduce Options     | applied               | ignored
----------------------+-----------------------+-----------------------------------------------
authentication        | via UserCredentials   | via MongoClient
----------------------+-----------------------+-----------------------------------------------
WriteConcernException | not available         | translated to DataIntegretyViolationException
----------------------+-----------------------+-----------------------------------------------
executeInSession      | available             | requestStart/requestDone commands ignored.
----------------------+-----------------------+-----------------------------------------------
index creation        | via createIndex       | via createIndex
----------------------+-----------------------+-----------------------------------------------
We need to soften the exception validation a bit since the message is slightly different when using different storage engines in a MongoDB 3.0 environment.
* protected reflective invokers by moving them around.
* undo static imports.
* add usage notes to reference documentation.
We added an explicit mongo-client element and client-options to the configuration schema. These elements will replace existing mongo and options elements in a subsequent release.

Next we need to allow passing in credentials, so one is able to configure authentication for mongo-client.
Added credentials attribute to <monog-client> which allows to define a set of credentials used for setting up the MongoClient correctly using authentication data.
We now reject mongo-options configuration when using mongo-java-driver generation 3 and above.
christophstrobl added a commit that referenced this pull request Mar 2, 2015
We now support mongo-java-driver version 2.x and 3.0 along with MongoDB Server 2.6.7 and 3.0.0.

Please note that some of the configurations options might no longer be valid when used with version 3 of the MongoDB Java driver. Have a look at the table below so see some of the major differences in using version 2.x or 3.0

                      | 2.x                  | 3.0
----------------------+----------------------+-----------------------------------------------
default WriteConcern  | NONE                 | UNACKNOWLEDGED
----------------------+----------------------+-----------------------------------------------
option for slaveOk    | available            | ignored
----------------------+----------------------+-----------------------------------------------
option for autoConnect| available            | ignored
----------------------+----------------------+-----------------------------------------------
write result checking | available            | ignored (errors are exceptions anyway)
----------------------+----------------------+-----------------------------------------------
rest index cache      | available            | throws UnsupportedOperationException
----------------------+----------------------+-----------------------------------------------
DBRef resolution      | via DBRef.fetch      | via collection.findOne
----------------------+----------------------+-----------------------------------------------
MapReduce Options     | applied              | ignored
----------------------+----------------------+-----------------------------------------------
authentication        | via UserCredentials  | via MongoClient
----------------------+----------------------+-----------------------------------------------
WriteConcernException | not available        | translated to DataIntegretyViolationException
----------------------+----------------------+-----------------------------------------------
executeInSession      | available            | requestStart/requestDone commands ignored.
----------------------+----------------------+-----------------------------------------------
index creation        | via createIndex      | via createIndex
----------------------+----------------------+-----------------------------------------------

We need to soften the exception validation a bit since the message is slightly different when using different storage engines in a MongoDB 3.0 environment.

Added an explicit <mongo-client /> element and <client-options /> to the configuration schema. These elements will replace existing <mongo /> and <options /> elements in a subsequent release. Added credentials attribute to <mongo-client /> which allows to define a set of credentials used for setting up the MongoClient correctly using authentication data. We now reject <mongo-options /> configuration when using MongoDB Java driver generation 3.0 and above.

Original pull request: #273.
odrotbohm added a commit that referenced this pull request Mar 2, 2015
MongoFactoryBean, MongoOptionsFactoryBean, MongoClientFactoryBean and MongoClientOptionsFactoryBean now extend AbstractFactoryBean to get a lot of the lifecycle callbacks without further code.

Added non-null assertions to newly introduced methods on MongoOperations/MongoTemplate.

Moved MongoClientVersion into util package. Introduced static imports for ReflectionUtils and MongoClientVersion for all references in the newly introduced Invoker types.

Some formatting, JavaDoc polishes, suppress deprecation warnings. Added build profile for MongoDB Java driver 3.0 as well as the following snapshot.

Original pull request: #273.
odrotbohm added a commit that referenced this pull request Mar 2, 2015
MongoFactoryBean, MongoOptionsFactoryBean, MongoClientFactoryBean and MongoClientOptionsFactoryBean now extend AbstractFactoryBean to get a lot of the lifecycle callbacks without further code.

Added non-null assertions to newly introduced methods on MongoOperations/MongoTemplate.

Moved MongoClientVersion into util package. Introduced static imports for ReflectionUtils and MongoClientVersion for all references in the newly introduced Invoker types.

Some formatting, JavaDoc polishes, suppress deprecation warnings. Added build profile for MongoDB Java driver 3.0 as well as the following snapshot.

Original pull request: #273.
@odrotbohm
Copy link
Member

I've squashed the commits, polished things a little and published a snapshot of the Mongo 3 specific docs we will publish alongside the release. Thanks again for kicking this off!

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.

3 participants