Skip to content

OAK-9447: Upgrade Mongo java driver to 5.2 #2226

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

Open
wants to merge 22 commits into
base: trunk
Choose a base branch
from
Open

Conversation

Joscorbe
Copy link
Member

Starting from base PR created by rgambelli #1761

Some conflicts still need to be resolved before merging

* OAK-9447

* Conflict with trunk resolved

* Conflict resolved

* conflict resolved

* Reordered imports like original classes and fixed oak-run about new
mongodb-driver-sync

* Reordered imports like original classes

* Upgraded com.mongodb and org.bson versions in Import-Package

* Restored original formatting

* Restored original import ordering

* Restored original import ordering

---------

Co-authored-by: raffaega <raffaega@CI00298583>
Co-authored-by: raffaega <raffaega@host.docker.internal>
Co-authored-by: Raffaele Gambelli <r.gambelli@gmail.com>
Co-authored-by: Raffaele Gambelli <raffaele.gambelli@cegeka.com>
Copy link

github-actions bot commented Apr 12, 2025

Commit-Check ❌

Commit rejected by Commit-Check.                                  
                                                                  
  (c).-.(c)    (c).-.(c)    (c).-.(c)    (c).-.(c)    (c).-.(c)  
   / ._. \      / ._. \      / ._. \      / ._. \      / ._. \   
 __\( C )/__  __\( H )/__  __\( E )/__  __\( C )/__  __\( K )/__ 
(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)
   || E ||      || R ||      || R ||      || O ||      || R ||   
 _.' '-' '._  _.' '-' '._  _.' '-' '._  _.' '-' '._  _.' '-' '._ 
(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)
 `-´     `-´  `-´     `-´  `-´     `-´  `-´     `-´  `-´     `-´ 
                                                                  
Commit rejected.                                                  
                                                                  
Type message check failed => Merge branch 'OAK-9447-joscorbe' of https://github.com/apache/jackrabbit-oak into OAK-9447-joscorbe

 
It doesn't match regex: ^OAK-\d+:?\s\S+.*
The commit message must start with 'OAK-<ID>[:] ' followed by some descriptive text
Suggest: Please check your commit message whether it matches above regex

@Joscorbe
Copy link
Member Author

This PR will likely contain many commits, so plan it to squash it into a single commit when ready.

@@ -89,11 +89,11 @@ public void readWriteMode() throws InterruptedException {
assertEquals(WriteConcern.MAJORITY, mem.getWriteConcern());

op = new UpdateOp(list.get(0).getId(), false);
op.set("readWriteMode", "read:nearest, write:fsynced");
op.set("readWriteMode", "read:nearest, write:w2");
Copy link
Member Author

Choose a reason for hiding this comment

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

FSYNCED doesn't exist anymore, the correct replacement is W2.

// bimap.put(WriteConcern.REPLICAS_SAFE,"REPLICAS_SAFE");
bimap.put(WriteConcern.SAFE,"SAFE");
bimap.put(WriteConcern.ACKNOWLEDGED,"ACKNOWLEDGED");
Copy link
Member Author

Choose a reason for hiding this comment

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

Those WriteConcerns are removed:

  • FSYNC_SAFE and JOURNAL_SAFE replaced by JOURNALED
  • NORMAL and SAFE replaced by ACKNOWLEDGED

@@ -2361,8 +2364,7 @@ private boolean withClientSession() {
}

private boolean secondariesWithinAcceptableLag() {
return getClient().getReplicaSetStatus() == null
|| connection.getStatus().getReplicaSetLagEstimate() < acceptableLagMillis;
return connection.getStatus().getReplicaSetLagEstimate() < acceptableLagMillis;
Copy link
Member Author

Choose a reason for hiding this comment

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

getStatus() can't be null.

Copy link
Member Author

Choose a reason for hiding this comment

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

getReplicaSetLagEstimate() returns 0 when Mongo is not a replica set.

import static com.mongodb.client.model.Filters.or;
import static com.mongodb.client.model.Projections.include;
import static com.mongodb.client.model.Sorts.ascending;

import static java.util.Collections.emptyList;
Copy link
Member Author

Choose a reason for hiding this comment

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

Not keeping the old imports ordering because they made no sense.

@@ -99,19 +87,30 @@
import org.slf4j.LoggerFactory;

import com.mongodb.BasicDBObject;
import com.mongodb.ConnectionString;
Copy link
Member Author

Choose a reason for hiding this comment

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

Not keeping the old imports ordering because they made no sense.

@Joscorbe Joscorbe marked this pull request as ready for review April 28, 2025 09:39
@Joscorbe Joscorbe changed the title OAK-9447: Upgrade Mongo java driver to 5.2 (WIP) OAK-9447: Upgrade Mongo java driver to 5.2 Apr 28, 2025
@Joscorbe
Copy link
Member Author

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
75.7% Coverage on New Code (required ≥ 80%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link
Contributor

@nfsantos nfsantos left a comment

Choose a reason for hiding this comment

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

The new Java driver seems to work correctly with indexing.

@Joscorbe
Copy link
Member Author

Joscorbe commented May 5, 2025

Thanks @nfsantos!

com.mongodb*;version="[3.8, 4)";resolution:=optional,
org.bson*;version="[3.8, 4)";resolution:=optional,
com.mongodb*;version="[5.2, 5.3)";resolution:=optional,
org.bson*;version="[5.2, 5.3)";resolution:=optional,
Copy link
Contributor

Choose a reason for hiding this comment

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

we already have version 5.5.0 released for mongo-driver-sync [1]

[1] https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-sync

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but we should test it before allowing it. We can do it in a new PR after this is merged, to avoid further delays on this PR.

WriteConcern wc = new MongoClientURI(requireNonNull(uri), builder)
.getOptions().getWriteConcern();
return !WC_UNKNOWN.equals(wc);
ConnectionString connectionString = new ConnectionString(requireNonNull(uri));
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need need to change this behavior here, this might cause an regression.

Copy link
Member Author

Choose a reason for hiding this comment

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

The behavior is the same: both implementations check whether the URI explicitly sets a writeConcern. The previous version used a workaround with WC_UNKNOWN to detect this, but the new API exposes this check directly via getWriteConcern().

Since now there is a native method in the driver that does exactly what we need, I don't think we need the workaround anymore.

There are tests that checks this and I introduced a few more test cases in MongoConnectionTest.java to ensure no regressions are introduced.

@@ -155,18 +153,6 @@ public void setUpdateLimit() throws Exception {
assertEquals(17, store.getUpdateLimit());
}

@Test
public void keepAlive() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

keepAlive config is only marked as deprecated not removed. I would suggest to keep these test till we remove that.

Copy link
Member Author

Choose a reason for hiding this comment

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

This test checks for getMongoClientOptions().isSocketKeepAlive(), which doesn't exist at all in modern driver, so this test would have no sense at all.

I marked keepAlive and all related properties as deprecated just to help to detect any uses in any application using Oak as dependency, to avoid breaking changes, but all those options should be completely removed.

@@ -85,26 +95,6 @@ public void sufficientReadConcern() throws Exception {
sufficientReadConcernSingleNode(ReadConcern.MAJORITY, true);
}

@Test
public void socketKeepAlive() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, I would keep this alive till we remove the config.

Copy link
Member Author

Choose a reason for hiding this comment

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

As before, Mongo doesn't have any related isSocketKeepAlive method anymore. The only way to keep this test is to make it a NOOP test, which doesn't make much sense to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

In Mongo Java Driver 3.6 it was already deprecated, and in 4.0 removed.

@Joscorbe Joscorbe requested a review from rishabhdaim May 15, 2025 14:55
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