Skip to content
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

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

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion oak-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
Expand Down
3 changes: 1 addition & 2 deletions oak-examples/standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>${mongo.driver.version}</version>
<artifactId>mongodb-driver-sync</artifactId>
<optional>true</optional>
</dependency>
<!-- Required for the persistent cache -->
Expand Down
2 changes: 1 addition & 1 deletion oak-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<artifactId>mongodb-driver-sync</artifactId>
<optional>true</optional>
<scope>test</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion oak-jcr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<artifactId>mongodb-driver-sync</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoClient;

/**
* Test for external events from another cluster node.
Expand Down Expand Up @@ -108,7 +108,7 @@ public void dispose(NodeStore nodeStore) {
nodeStores.remove(nodeStore);
if (nodeStores.size() == 0) {
try (MongoClient c = createClient()) {
c.dropDatabase(dbName);
c.getDatabase(dbName).drop();
} catch (Exception e) {
log.error("dispose: Can't close Mongo", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
import org.apache.jackrabbit.oak.spi.state.NodeStore;

import com.mongodb.DB;

/**
* A randomized test that writes to two repositories (using different storage
* backends), and compares the results. The test uses low cache sizes, and low
Expand Down
2 changes: 1 addition & 1 deletion oak-lucene/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<artifactId>mongodb-driver-sync</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions oak-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<segment.db>SegmentMK</segment.db>
<lucene.version>4.7.2</lucene.version>
<solr.version>8.11.1</solr.version>
<mongo.driver.version>3.12.14</mongo.driver.version>
<mongo.driver.version>5.2.0</mongo.driver.version>
<slf4j.api.version>1.7.36</slf4j.api.version>
<slf4j.version>1.7.36</slf4j.version> <!-- sync with logback version -->
<logback.version>1.2.13</logback.version>
Expand Down Expand Up @@ -558,7 +558,7 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<artifactId>mongodb-driver-sync</artifactId>
<version>${mongo.driver.version}</version>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion oak-pojosr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<artifactId>mongodb-driver-sync</artifactId>
<optional>true</optional>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion oak-run-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import java.util.ArrayList;
import java.util.List;

import com.mongodb.MongoClientURI;
import com.mongodb.ConnectionString;

import static java.util.Arrays.asList;
import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder;
Expand Down Expand Up @@ -109,7 +109,7 @@ static OakFixture newCompositeMongoFixture(String name, String uri, boolean drop
boolean throttlingEnabled) {
return new CompositeStoreFixture(name) {

private String database = new MongoClientURI(uri).getDatabase();
private String database = new ConnectionString(uri).getDatabase();
private DocumentNodeStore ns;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.jackrabbit.oak.index.indexer.document;

import com.codahale.metrics.MetricRegistry;
import com.mongodb.MongoClientURI;
import com.mongodb.ConnectionString;
import com.mongodb.client.MongoDatabase;
import org.apache.jackrabbit.guava.common.base.Stopwatch;
import org.apache.jackrabbit.guava.common.io.Closer;
Expand Down Expand Up @@ -483,8 +482,8 @@ private MongoDocumentStore getMongoDocumentStore() {
return requireNonNull(indexHelper.getService(MongoDocumentStore.class));
}

private MongoClientURI getMongoClientURI() {
return requireNonNull(indexHelper.getService(MongoClientURI.class));
private ConnectionString getMongoClientURI() {
return requireNonNull(indexHelper.getService(ConnectionString.class));
}

private MongoDatabase getMongoDatabase() {
Expand All @@ -508,7 +507,7 @@ private void configureEstimators(IndexingProgressReporter progressReporter) {
private long getEstimatedDocumentCount() {
MongoConnection mongoConnection = indexHelper.getService(MongoConnection.class);
if (mongoConnection != null) {
return mongoConnection.getDatabase().getCollection("nodes").count();
return mongoConnection.getDatabase().getCollection("nodes").countDocuments();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return mongoConnection.getDatabase().getCollection("nodes").countDocuments();
return mongoConnection.getDatabase().getCollection("nodes").estimatedDocumentCount();

countDcuments is very slow. I would use estimatedDocumentCount for faster results.

See https://www.mongodb.com/community/forums/t/countdocuments-is-extremly-slow/207357

}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.apache.jackrabbit.oak.index.indexer.document.flatfile;

import com.mongodb.MongoClientURI;
import com.mongodb.ConnectionString;
import com.mongodb.client.MongoDatabase;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.guava.common.collect.Iterables;
Expand Down Expand Up @@ -112,7 +112,7 @@ public class FlatFileNodeStoreBuilder {
private String checkpoint;
private StatisticsProvider statisticsProvider = StatisticsProvider.NOOP;
private IndexingReporter indexingReporter = IndexingReporter.NOOP;
private MongoClientURI mongoClientURI;
private ConnectionString mongoClientURI;
private boolean withAheadOfTimeBlobDownloading = false;

public enum SortStrategyType {
Expand Down Expand Up @@ -191,7 +191,7 @@ public FlatFileNodeStoreBuilder withCheckpoint(String checkpoint) {
return this;
}

public FlatFileNodeStoreBuilder withMongoClientURI(MongoClientURI mongoClientURI) {
public FlatFileNodeStoreBuilder withMongoClientURI(ConnectionString mongoClientURI) {
this.mongoClientURI = mongoClientURI;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoClientURI;
import com.mongodb.MongoException;
import com.mongodb.MongoIncompatibleDriverException;
import com.mongodb.MongoInterruptedException;
Expand Down Expand Up @@ -204,7 +203,7 @@ public String toString() {
static final String THREAD_NAME_PREFIX = "mongo-dump";


private final MongoClientURI mongoClientURI;
private final ConnectionString mongoClientURI;
private final MongoDocumentStore docStore;
private final int maxBatchSizeBytes;
private final int maxBatchNumberOfDocuments;
Expand All @@ -229,7 +228,7 @@ public String toString() {
private final DownloadStageStatistics downloadStageStatistics = new DownloadStageStatistics();
private Instant lastDelayedEnqueueWarningMessageLoggedTimestamp = Instant.now();

public PipelinedMongoDownloadTask(MongoClientURI mongoClientURI,
public PipelinedMongoDownloadTask(ConnectionString mongoClientURI,
MongoDocumentStore docStore,
int maxBatchSizeBytes,
int maxBatchNumberOfDocuments,
Expand All @@ -240,7 +239,7 @@ public PipelinedMongoDownloadTask(MongoClientURI mongoClientURI,
this(mongoClientURI, docStore, maxBatchSizeBytes, maxBatchNumberOfDocuments, queue, pathFilters, statisticsProvider, reporter, new ThreadFactoryBuilder().setDaemon(true).build());
}

public PipelinedMongoDownloadTask(MongoClientURI mongoClientURI,
public PipelinedMongoDownloadTask(ConnectionString mongoClientURI,
MongoDocumentStore docStore,
int maxBatchSizeBytes,
int maxBatchNumberOfDocuments,
Expand Down Expand Up @@ -343,7 +342,7 @@ public Result call() throws Exception {
);

MongoClientSettings.Builder settingsBuilder = MongoClientSettings.builder()
.applyConnectionString(new ConnectionString(mongoClientURI.getURI()))
.applyConnectionString(mongoClientURI)
.readPreference(ReadPreference.secondaryPreferred());
if (parallelDump && parallelDumpSecondariesOnly) {
// Set a custom server selector that is able to distribute the two connections between the two secondaries.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined;

import com.mongodb.MongoClientURI;
import com.mongodb.ConnectionString;
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.guava.common.base.Preconditions;
import org.apache.jackrabbit.guava.common.base.Stopwatch;
Expand Down Expand Up @@ -179,7 +179,7 @@ private static void prettyPrintTransformStatisticsHistograms(TransformStageStati
}

private final MongoDocumentStore docStore;
private final MongoClientURI mongoClientURI;
private final ConnectionString mongoClientURI;
private final DocumentNodeStore documentNodeStore;
private final RevisionVector rootRevision;
private final BlobStore blobStore;
Expand All @@ -204,7 +204,7 @@ private static void prettyPrintTransformStatisticsHistograms(TransformStageStati
* @param statisticsProvider Used to collect statistics about the indexing process.
* @param indexingReporter Used to collect diagnostics, metrics and statistics and report them at the end of the indexing process.
*/
public PipelinedStrategy(MongoClientURI mongoClientURI,
public PipelinedStrategy(ConnectionString mongoClientURI,
MongoDocumentStore documentStore,
DocumentNodeStore documentNodeStore,
RevisionVector rootRevision,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined;

import com.mongodb.MongoClientURI;
import com.mongodb.ConnectionString;
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.guava.common.base.Preconditions;
import org.apache.jackrabbit.guava.common.base.Stopwatch;
Expand Down Expand Up @@ -166,7 +166,7 @@ private static void prettyPrintTransformStatisticsHistograms(TransformStageStati
}

private final MongoDocumentStore docStore;
private final MongoClientURI mongoClientURI;
private final ConnectionString mongoClientURI;
private final DocumentNodeStore documentNodeStore;
private final RevisionVector rootRevision;
private final BlobStore blobStore;
Expand All @@ -190,7 +190,7 @@ private static void prettyPrintTransformStatisticsHistograms(TransformStageStati
* @param statisticsProvider Used to collect statistics about the indexing process.
* @param indexingReporter Used to collect diagnostics, metrics and statistics and report them at the end of the indexing process.
*/
public PipelinedTreeStoreStrategy(MongoClientURI mongoClientURI,
public PipelinedTreeStoreStrategy(ConnectionString mongoClientURI,
MongoDocumentStore documentStore,
DocumentNodeStore documentNodeStore,
RevisionVector rootRevision,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

import javax.sql.DataSource;

import com.mongodb.ConnectionString;
import com.mongodb.client.MongoDatabase;
import org.apache.jackrabbit.guava.common.io.Closer;
import com.mongodb.MongoClientURI;
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder;
Expand Down Expand Up @@ -101,14 +101,14 @@ static DocumentNodeStore configureDocumentMk(Options options,

DocumentNodeStore dns;
if (commonOpts.isMongo()) {
MongoClientURI uri = new MongoClientURI(commonOpts.getStoreArg());
ConnectionString uri = new ConnectionString(commonOpts.getStoreArg());
if (uri.getDatabase() == null) {
System.err.println("Database missing in MongoDB URI: "
+ uri.getURI());
+ uri);
System.exit(1);
}
MongoConnection mongo = new MongoConnection(uri.getURI());
wb.register(MongoClientURI.class, uri, emptyMap());
MongoConnection mongo = new MongoConnection(uri.getConnectionString());
wb.register(ConnectionString.class, uri, emptyMap());
wb.register(MongoConnection.class, mongo, emptyMap());
wb.register(MongoDatabase.class, mongo.getDatabase(), emptyMap());
closer.register(mongo::close);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined;

import com.mongodb.MongoClientURI;
import com.mongodb.ConnectionString;
import com.mongodb.client.MongoDatabase;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
Expand All @@ -27,12 +27,12 @@
import java.io.IOException;

class MongoTestBackend implements Closeable {
final MongoClientURI mongoClientURI;
final ConnectionString mongoClientURI;
final MongoDocumentStore mongoDocumentStore;
final DocumentNodeStore documentNodeStore;
final MongoDatabase mongoDatabase;

public MongoTestBackend(MongoClientURI mongoClientURI, MongoDocumentStore mongoDocumentStore, DocumentNodeStore documentNodeStore, MongoDatabase mongoDatabase) {
public MongoTestBackend(ConnectionString mongoClientURI, MongoDocumentStore mongoDocumentStore, DocumentNodeStore documentNodeStore, MongoDatabase mongoDatabase) {
this.mongoClientURI = mongoClientURI;
this.mongoDocumentStore = mongoDocumentStore;
this.documentNodeStore = documentNodeStore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined;

import com.mongodb.MongoClientURI;
import com.mongodb.ConnectionString;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.commons.Compression;
import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
Expand Down Expand Up @@ -179,7 +179,7 @@ static MongoTestBackend createNodeStore(boolean readOnly, MongoConnectionFactory
}

static MongoTestBackend createNodeStore(boolean readOnly, String mongoUri, DocumentMKBuilderProvider builderProvider) {
MongoClientURI mongoClientUri = new MongoClientURI(mongoUri);
ConnectionString mongoClientUri = new ConnectionString(mongoUri);
DocumentMK.Builder builder = builderProvider.newBuilder();
builder.setMongoDB(mongoUri, "oak", 0);
if (readOnly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined;

import com.mongodb.MongoClient;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.model.Filters;
import org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.MongoRegexPathFilterFactory.MongoFilterPaths;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
Expand Down Expand Up @@ -336,8 +336,8 @@ private void assertBsonEquals(Bson actual, Bson expected) {
throw new AssertionError("One of the bson is null. Actual: " + actual + ", expected: " + expected);
}
assertEquals(
actual.toBsonDocument(BsonDocument.class, MongoClient.getDefaultCodecRegistry()),
expected.toBsonDocument(BsonDocument.class, MongoClient.getDefaultCodecRegistry())
actual.toBsonDocument(BsonDocument.class, MongoClientSettings.getDefaultCodecRegistry()),
expected.toBsonDocument(BsonDocument.class, MongoClientSettings.getDefaultCodecRegistry())
);
}

Expand Down
2 changes: 1 addition & 1 deletion oak-run/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>
<dependency>
<groupId>org.mapdb</groupId>
Expand Down
Loading
Loading