From 84fa64f88082c85e2d40a1406cd9aa15ed36b45d Mon Sep 17 00:00:00 2001 From: raffaega Date: Fri, 4 Oct 2024 17:44:37 +0200 Subject: [PATCH 01/10] OAK-9447 --- oak-benchmarks/pom.xml | 2 +- oak-examples/standalone/pom.xml | 3 +- oak-it/pom.xml | 2 +- oak-jcr/pom.xml | 2 +- .../jcr/cluster/NonLocalObservationIT.java | 7 +- .../oak/jcr/random/RandomOpCompare.java | 4 - oak-lucene/pom.xml | 2 +- oak-parent/pom.xml | 6 +- oak-pojosr/pom.xml | 2 +- oak-run-commons/pom.xml | 2 +- .../oak/fixture/CompositeStoreFixture.java | 21 +- .../document/DocumentStoreIndexerBase.java | 73 ++--- .../flatfile/FlatFileNodeStoreBuilder.java | 38 ++- .../pipelined/PipelinedMongoDownloadTask.java | 81 +++-- .../flatfile/pipelined/PipelinedStrategy.java | 52 ++- .../pipelined/PipelinedTreeStoreStrategy.java | 38 ++- .../oak/run/cli/DocumentFixtureProvider.java | 27 +- .../flatfile/pipelined/MongoTestBackend.java | 13 +- .../flatfile/pipelined/PipelineITUtil.java | 20 +- .../PipelinedMongoDownloadTaskTest.java | 28 +- oak-run/pom.xml | 2 +- .../oak/index/DocumentStoreIndexerIT.java | 86 +++-- oak-store-composite/pom.xml | 2 +- oak-store-document/pom.xml | 2 +- .../document/DocumentNodeStoreService.java | 300 +++++++++--------- .../document/mongo/MongoBlobStore.java | 21 +- .../document/mongo/MongoDBConnection.java | 85 ++--- .../MongoDocumentNodeStoreBuilderBase.java | 74 ++--- .../document/mongo/MongoDocumentStore.java | 131 ++++---- .../document/mongo/MongoSessionFactory.java | 79 +++-- .../plugins/document/mongo/MongoStatus.java | 78 +++-- .../document/mongo/MongoVersionGCSupport.java | 35 +- .../document/mongo/ReplicaSetStatus.java | 62 ++-- .../plugins/document/mongo/RevisionEntry.java | 11 +- .../document/util/MongoConnection.java | 148 +++++---- .../oak/fixture/DocumentMongoFixture.java | 38 +-- .../document/AbstractMongoConnectionTest.java | 29 +- .../plugins/document/BlobThroughPutTest.java | 34 +- .../document/CacheConsistencyTest.java | 13 +- .../oak/plugins/document/ClusterInfoTest.java | 7 +- .../ConcurrentPrefetchAndUpdateIT.java | 15 +- .../document/DocumentMKBuilderTest.java | 10 +- .../DocumentNodeStoreServiceTest.java | 42 +-- .../oak/plugins/document/MongoDbTest.java | 7 +- .../oak/plugins/document/MongoUtils.java | 76 ++--- .../document/VersionGCSupportTest.java | 39 ++- .../mongo/AcquireRecoveryLockTest.java | 15 +- .../document/mongo/ClusterConflictTest.java | 7 +- .../document/mongo/MongoConnectionTest.java | 67 +--- .../document/mongo/MongoDBConfigTest.java | 25 +- .../document/mongo/MongoDBExceptionTest.java | 94 +++--- .../mongo/MongoDocumentStoreTestHelper.java | 2 +- .../document/mongo/MongoStatusTest.java | 95 +++--- .../document/mongo/MongoTestClient.java | 174 +++++++++- .../document/mongo/MongoTestCollection.java | 176 +++++----- .../document/mongo/MongoTestDatabase.java | 29 +- .../document/mongo/MongoUtilsTest.java | 43 ++- .../document/mongo/MongodProcessFactory.java | 13 +- .../mongo/ReplicaSetResilienceIT.java | 47 ++- .../document/mongo/ReplicaSetStatusTest.java | 17 +- .../plugins/document/mongo/RetryReadIT.java | 17 +- .../prefetch/CountingMongoDatabase.java | 19 +- oak-upgrade/pom.xml | 2 +- .../oak/upgrade/cli/node/MongoFactory.java | 20 +- .../container/MongoNodeStoreContainer.java | 31 +- 65 files changed, 1408 insertions(+), 1334 deletions(-) diff --git a/oak-benchmarks/pom.xml b/oak-benchmarks/pom.xml index 59958a3d3c0..d3982f3efcb 100644 --- a/oak-benchmarks/pom.xml +++ b/oak-benchmarks/pom.xml @@ -206,7 +206,7 @@ org.mongodb - mongo-java-driver + mongodb-driver-sync com.h2database diff --git a/oak-examples/standalone/pom.xml b/oak-examples/standalone/pom.xml index 04580efadd1..7cc9ec8e135 100644 --- a/oak-examples/standalone/pom.xml +++ b/oak-examples/standalone/pom.xml @@ -100,8 +100,7 @@ org.mongodb - mongo-java-driver - ${mongo.driver.version} + mongodb-driver-sync true diff --git a/oak-it/pom.xml b/oak-it/pom.xml index 1d296e13819..008d4cb596a 100644 --- a/oak-it/pom.xml +++ b/oak-it/pom.xml @@ -186,7 +186,7 @@ org.mongodb - mongo-java-driver + mongodb-driver-sync true test diff --git a/oak-jcr/pom.xml b/oak-jcr/pom.xml index 6eb3b6bc438..192346a4aa0 100644 --- a/oak-jcr/pom.xml +++ b/oak-jcr/pom.xml @@ -389,7 +389,7 @@ org.mongodb - mongo-java-driver + mongodb-driver-sync test diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java index 4c18043c99d..cb2774dd279 100644 --- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java +++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java @@ -19,13 +19,11 @@ import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_NS; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; - import java.util.Date; import java.util.HashSet; import java.util.Random; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; - import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; @@ -33,7 +31,6 @@ import javax.jcr.observation.EventIterator; import javax.jcr.observation.EventListener; import javax.jcr.observation.ObservationManager; - import org.apache.jackrabbit.api.observation.JackrabbitEvent; import org.apache.jackrabbit.oak.commons.FixturesHelper; import org.apache.jackrabbit.oak.fixture.DocumentMongoFixture; @@ -47,8 +44,8 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.mongodb.client.MongoClient; -import com.mongodb.MongoClient; /** * Test for external events from another cluster node. @@ -108,7 +105,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); } diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/random/RandomOpCompare.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/random/RandomOpCompare.java index 656964ce522..5fdd37951ff 100644 --- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/random/RandomOpCompare.java +++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/random/RandomOpCompare.java @@ -20,17 +20,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; - import java.io.Closeable; import java.io.IOException; import java.util.Random; - import javax.jcr.Node; import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.SimpleCredentials; - import org.apache.jackrabbit.oak.NodeStoreFixtures; import org.apache.jackrabbit.oak.fixture.NodeStoreFixture; import org.apache.jackrabbit.oak.jcr.Jcr; @@ -38,7 +35,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 diff --git a/oak-lucene/pom.xml b/oak-lucene/pom.xml index d3684328c59..758e2f7edd4 100644 --- a/oak-lucene/pom.xml +++ b/oak-lucene/pom.xml @@ -281,7 +281,7 @@ org.mongodb - mongo-java-driver + mongodb-driver-sync test diff --git a/oak-parent/pom.xml b/oak-parent/pom.xml index e0b46fba584..b568fba88fa 100644 --- a/oak-parent/pom.xml +++ b/oak-parent/pom.xml @@ -58,7 +58,7 @@ SegmentMK 4.7.2 8.11.1 - 3.12.11 + 5.2.0 1.7.36 1.7.36 1.2.13 @@ -558,9 +558,9 @@ org.mongodb - mongo-java-driver + mongodb-driver-sync ${mongo.driver.version} - + org.easymock easymock diff --git a/oak-pojosr/pom.xml b/oak-pojosr/pom.xml index 2b1c01a8f83..f7a7dd50fdc 100644 --- a/oak-pojosr/pom.xml +++ b/oak-pojosr/pom.xml @@ -121,7 +121,7 @@ org.mongodb - mongo-java-driver + mongodb-driver-sync true diff --git a/oak-run-commons/pom.xml b/oak-run-commons/pom.xml index d46e5ea5d63..f4961f635e0 100644 --- a/oak-run-commons/pom.xml +++ b/oak-run-commons/pom.xml @@ -117,7 +117,7 @@ org.mongodb - mongo-java-driver + mongodb-driver-sync commons-io diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/fixture/CompositeStoreFixture.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/fixture/CompositeStoreFixture.java index 4cfc278b98a..73f2eb370b5 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/fixture/CompositeStoreFixture.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/fixture/CompositeStoreFixture.java @@ -17,6 +17,13 @@ package org.apache.jackrabbit.oak.fixture; +import static java.util.Arrays.asList; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; +import static org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.apache.jackrabbit.oak.Oak; import org.apache.jackrabbit.oak.composite.CompositeNodeStore; import org.apache.jackrabbit.oak.composite.InitialContentMigrator; @@ -37,17 +44,7 @@ import org.apache.jackrabbit.oak.spi.mount.Mounts; import org.apache.jackrabbit.oak.spi.state.NodeStore; import org.apache.jackrabbit.oak.stats.StatisticsProvider; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import com.mongodb.MongoClientURI; - -import static java.util.Arrays.asList; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; -import static org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder; +import com.mongodb.ConnectionString; abstract class CompositeStoreFixture extends OakFixture { @@ -109,7 +106,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 diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/DocumentStoreIndexerBase.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/DocumentStoreIndexerBase.java index 1a25acc7c1d..f99c1adab8a 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/DocumentStoreIndexerBase.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/DocumentStoreIndexerBase.java @@ -19,9 +19,33 @@ package org.apache.jackrabbit.oak.index.indexer.document; -import com.codahale.metrics.MetricRegistry; -import com.mongodb.MongoClientURI; -import com.mongodb.client.MongoDatabase; +import static java.util.Objects.requireNonNull; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder.OAK_INDEXER_SORTED_FILE_PATH; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.DEFAULT_OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDED_PATHS; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.DEFAULT_OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDE_ENTRIES_REGEX; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.DEFAULT_OAK_INDEXER_PIPELINED_MONGO_REGEX_PATH_FILTERING; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDED_PATHS; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDE_ENTRIES_REGEX; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.OAK_INDEXER_PIPELINED_MONGO_REGEX_PATH_FILTERING; +import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME; +import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; +import java.io.Closeable; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.apache.jackrabbit.guava.common.base.Stopwatch; import org.apache.jackrabbit.guava.common.io.Closer; import org.apache.jackrabbit.oak.api.CommitFailedException; @@ -44,10 +68,10 @@ import org.apache.jackrabbit.oak.plugins.index.FormattingUtils; import org.apache.jackrabbit.oak.plugins.index.IndexConstants; import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback; +import org.apache.jackrabbit.oak.plugins.index.IndexingReporter; import org.apache.jackrabbit.oak.plugins.index.MetricsFormatter; import org.apache.jackrabbit.oak.plugins.index.MetricsUtils; import org.apache.jackrabbit.oak.plugins.index.NodeTraversalCallback; -import org.apache.jackrabbit.oak.plugins.index.IndexingReporter; import org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter; import org.apache.jackrabbit.oak.plugins.index.progress.MetricRateEstimator; import org.apache.jackrabbit.oak.plugins.index.search.ExtractedTextCache; @@ -61,37 +85,13 @@ import org.apache.jackrabbit.oak.spi.state.NodeStateUtils; import org.apache.jackrabbit.oak.spi.state.NodeStore; import org.apache.jackrabbit.oak.stats.StatisticsProvider; +import org.bson.Document; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.io.Closeable; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder.OAK_INDEXER_SORTED_FILE_PATH; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.DEFAULT_OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDED_PATHS; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.DEFAULT_OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDE_ENTRIES_REGEX; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.DEFAULT_OAK_INDEXER_PIPELINED_MONGO_REGEX_PATH_FILTERING; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDED_PATHS; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDE_ENTRIES_REGEX; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.OAK_INDEXER_PIPELINED_MONGO_REGEX_PATH_FILTERING; -import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME; -import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; +import com.codahale.metrics.MetricRegistry; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; public abstract class DocumentStoreIndexerBase implements Closeable { public static final String INDEXER_METRICS_PREFIX = "oak_indexer_"; @@ -483,8 +483,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() { @@ -508,7 +508,8 @@ private void configureEstimators(IndexingProgressReporter progressReporter) { private long getEstimatedDocumentCount() { MongoConnection mongoConnection = indexHelper.getService(MongoConnection.class); if (mongoConnection != null) { - return mongoConnection.getDatabase().getCollection("nodes").count(); + MongoCollection nodesCollection = mongoConnection.getDatabase().getCollection("nodes"); + return nodesCollection.countDocuments(); } return 0; } diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java index 60cfc3037c6..c7dee659b51 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java @@ -19,8 +19,20 @@ package org.apache.jackrabbit.oak.index.indexer.document.flatfile; -import com.mongodb.MongoClientURI; -import com.mongodb.client.MongoDatabase; +import static java.util.Collections.unmodifiableSet; +import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState; +import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_LZ4; +import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_ZIP; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.commons.Compression; @@ -51,22 +63,8 @@ import org.apache.jackrabbit.oak.stats.StatisticsProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import static java.util.Collections.unmodifiableSet; -import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState; -import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_LZ4; -import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_ZIP; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoDatabase; /** * This class is where the strategy being selected for building FlatFileStore. @@ -112,7 +110,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 { @@ -191,7 +189,7 @@ public FlatFileNodeStoreBuilder withCheckpoint(String checkpoint) { return this; } - public FlatFileNodeStoreBuilder withMongoClientURI(MongoClientURI mongoClientURI) { + public FlatFileNodeStoreBuilder withMongoClientURI(ConnectionString mongoClientURI) { this.mongoClientURI = mongoClientURI; return this; } diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTask.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTask.java index 2c7c78cd75c..03016b762e4 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTask.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTask.java @@ -18,21 +18,27 @@ */ package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined; -import com.mongodb.ConnectionString; -import com.mongodb.MongoClientSettings; -import com.mongodb.MongoClientURI; -import com.mongodb.MongoException; -import com.mongodb.MongoIncompatibleDriverException; -import com.mongodb.MongoInterruptedException; -import com.mongodb.ReadPreference; -import com.mongodb.client.FindIterable; -import com.mongodb.client.MongoClient; -import com.mongodb.client.MongoClients; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoCursor; -import com.mongodb.client.MongoDatabase; -import com.mongodb.client.model.Filters; -import com.mongodb.client.model.Sorts; +import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; +import java.time.Duration; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorCompletionService; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; import org.apache.jackrabbit.guava.common.base.Preconditions; import org.apache.jackrabbit.guava.common.base.Stopwatch; import org.apache.jackrabbit.guava.common.util.concurrent.ThreadFactoryBuilder; @@ -55,29 +61,20 @@ import org.bson.conversions.Bson; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.time.Duration; -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; - -import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; +import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings; +import com.mongodb.MongoException; +import com.mongodb.MongoIncompatibleDriverException; +import com.mongodb.MongoInterruptedException; +import com.mongodb.ReadPreference; +import com.mongodb.client.FindIterable; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoCursor; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.Sorts; public class PipelinedMongoDownloadTask implements Callable { private static final Logger LOG = LoggerFactory.getLogger(PipelinedMongoDownloadTask.class); @@ -204,7 +201,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; @@ -229,7 +226,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, @@ -240,7 +237,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, @@ -343,7 +340,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. diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedStrategy.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedStrategy.java index a3417a769bf..238fbd9102e 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedStrategy.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedStrategy.java @@ -18,7 +18,27 @@ */ package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined; -import com.mongodb.MongoClientURI; +import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCountBin; +import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorCompletionService; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.guava.common.base.Preconditions; import org.apache.jackrabbit.guava.common.base.Stopwatch; @@ -33,36 +53,14 @@ import org.apache.jackrabbit.oak.plugins.document.RevisionVector; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; import org.apache.jackrabbit.oak.plugins.index.FormattingUtils; -import org.apache.jackrabbit.oak.plugins.index.MetricsFormatter; import org.apache.jackrabbit.oak.plugins.index.IndexingReporter; +import org.apache.jackrabbit.oak.plugins.index.MetricsFormatter; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.filter.PathFilter; import org.apache.jackrabbit.oak.stats.StatisticsProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.function.Predicate; - -import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCountBin; -import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; +import com.mongodb.ConnectionString; /** * Downloads the contents of the MongoDB repository dividing the tasks in a pipeline with the following stages: @@ -179,7 +177,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; @@ -204,7 +202,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, diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedTreeStoreStrategy.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedTreeStoreStrategy.java index b5cb0371136..2291d559994 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedTreeStoreStrategy.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedTreeStoreStrategy.java @@ -18,7 +18,20 @@ */ package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined; -import com.mongodb.MongoClientURI; +import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorCompletionService; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.guava.common.base.Preconditions; import org.apache.jackrabbit.guava.common.base.Stopwatch; @@ -34,29 +47,14 @@ import org.apache.jackrabbit.oak.plugins.document.RevisionVector; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; import org.apache.jackrabbit.oak.plugins.index.FormattingUtils; -import org.apache.jackrabbit.oak.plugins.index.MetricsFormatter; import org.apache.jackrabbit.oak.plugins.index.IndexingReporter; +import org.apache.jackrabbit.oak.plugins.index.MetricsFormatter; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.filter.PathFilter; import org.apache.jackrabbit.oak.stats.StatisticsProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.function.Predicate; - -import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; +import com.mongodb.ConnectionString; /** * Downloads the contents of the MongoDB repository dividing the tasks in a pipeline with the following stages: @@ -166,7 +164,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; @@ -190,7 +188,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, diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java index 8535682ddf5..aa890fa4d71 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java @@ -18,14 +18,15 @@ */ package org.apache.jackrabbit.oak.run.cli; +import static java.util.Collections.emptyMap; +import static java.util.Objects.requireNonNull; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; +import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder.newRDBDocumentNodeStoreBuilder; +import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.getService; import java.io.IOException; - import javax.sql.DataSource; - -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.guava.common.io.Closer; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder; @@ -37,12 +38,8 @@ import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard; import org.apache.jackrabbit.oak.stats.StatisticsProvider; - -import static java.util.Collections.emptyMap; -import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; -import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder.newRDBDocumentNodeStoreBuilder; -import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.getService; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoDatabase; class DocumentFixtureProvider { static DocumentNodeStore configureDocumentMk(Options options, @@ -101,14 +98,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); diff --git a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/MongoTestBackend.java b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/MongoTestBackend.java index 243939a9c07..75f411c60be 100644 --- a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/MongoTestBackend.java +++ b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/MongoTestBackend.java @@ -18,21 +18,20 @@ */ package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined; -import com.mongodb.MongoClientURI; -import com.mongodb.client.MongoDatabase; -import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; - import java.io.Closeable; import java.io.IOException; +import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; +import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoDatabase; 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; diff --git a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelineITUtil.java b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelineITUtil.java index b5543a30fa6..30099c01e80 100644 --- a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelineITUtil.java +++ b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelineITUtil.java @@ -18,7 +18,13 @@ */ package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined; -import com.mongodb.MongoClientURI; +import static org.junit.Assert.assertEquals; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.commons.Compression; import org.apache.jackrabbit.oak.plugins.document.DocumentMK; @@ -40,15 +46,7 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import static org.junit.Assert.assertEquals; +import com.mongodb.ConnectionString; public class PipelineITUtil { private static final Logger LOG = LoggerFactory.getLogger(PipelineITUtil.class); @@ -179,7 +177,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) { diff --git a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTaskTest.java b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTaskTest.java index 7f4eb4a9476..a6b655c0581 100644 --- a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTaskTest.java +++ b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTaskTest.java @@ -18,8 +18,15 @@ */ package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined; -import com.mongodb.MongoClient; -import com.mongodb.client.model.Filters; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.MongoDownloaderRegexUtils.LONG_PATH_ID_PATTERN; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.MongoRegexPathFilterFactory.MongoFilterPaths; import org.apache.jackrabbit.oak.plugins.document.NodeDocument; import org.apache.jackrabbit.oak.spi.filter.PathFilter; @@ -29,17 +36,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.RestoreSystemProperties; - -import java.util.Arrays; -import java.util.List; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.MongoDownloaderRegexUtils.LONG_PATH_ID_PATTERN; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import com.mongodb.MongoClientSettings; +import com.mongodb.client.model.Filters; public class PipelinedMongoDownloadTaskTest { @@ -336,8 +334,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()) ); } diff --git a/oak-run/pom.xml b/oak-run/pom.xml index ff542d2e3d6..784f6511acf 100644 --- a/oak-run/pom.xml +++ b/oak-run/pom.xml @@ -296,7 +296,7 @@ org.mongodb - mongo-java-driver + mongodb-driver-sync org.mapdb diff --git a/oak-run/src/test/java/org/apache/jackrabbit/oak/index/DocumentStoreIndexerIT.java b/oak-run/src/test/java/org/apache/jackrabbit/oak/index/DocumentStoreIndexerIT.java index 317c5bca738..f0495190296 100644 --- a/oak-run/src/test/java/org/apache/jackrabbit/oak/index/DocumentStoreIndexerIT.java +++ b/oak-run/src/test/java/org/apache/jackrabbit/oak/index/DocumentStoreIndexerIT.java @@ -19,9 +19,42 @@ package org.apache.jackrabbit.oak.index; -import com.codahale.metrics.Counter; -import com.mongodb.MongoClientURI; -import com.mongodb.client.MongoDatabase; +import static java.util.Collections.emptyMap; +import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE; +import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_LZ4; +import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_ZIP; +import static org.apache.jackrabbit.oak.plugins.document.TestUtils.childBuilder; +import static org.apache.jackrabbit.oak.plugins.document.TestUtils.createChild; +import static org.apache.jackrabbit.oak.plugins.document.TestUtils.merge; +import static org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler.BUNDLOR; +import static org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler.DOCUMENT_NODE_STORE; +import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeNotNull; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.SortedMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.query.Query; +import javax.jcr.query.QueryManager; +import javax.jcr.query.QueryResult; +import javax.jcr.query.Row; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.oak.InitialContent; import org.apache.jackrabbit.oak.api.CommitFailedException; @@ -45,9 +78,9 @@ import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; import org.apache.jackrabbit.oak.plugins.document.util.Utils; -import org.apache.jackrabbit.oak.plugins.index.importer.ClusterNodeStoreLock; import org.apache.jackrabbit.oak.plugins.index.ConsoleIndexingReporter; import org.apache.jackrabbit.oak.plugins.index.IndexingReporter; +import org.apache.jackrabbit.oak.plugins.index.importer.ClusterNodeStoreLock; import org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexRootDirectory; import org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexDir; import org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder; @@ -73,44 +106,9 @@ import org.junit.rules.TestRule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.query.Query; -import javax.jcr.query.QueryManager; -import javax.jcr.query.QueryResult; -import javax.jcr.query.Row; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.SortedMap; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.function.Predicate; - -import static java.util.Collections.emptyMap; -import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE; -import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_LZ4; -import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_ZIP; -import static org.apache.jackrabbit.oak.plugins.document.TestUtils.childBuilder; -import static org.apache.jackrabbit.oak.plugins.document.TestUtils.createChild; -import static org.apache.jackrabbit.oak.plugins.document.TestUtils.merge; -import static org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler.BUNDLOR; -import static org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler.DOCUMENT_NODE_STORE; -import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeNotNull; +import com.codahale.metrics.Counter; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoDatabase; public class DocumentStoreIndexerIT extends LuceneAbstractIndexCommandTest { private final Logger LOG = LoggerFactory.getLogger(getClass()); @@ -319,7 +317,7 @@ public void bundling() throws Exception { Whiteboard wb = new DefaultWhiteboard(); MongoDocumentStore ds = (MongoDocumentStore) docBuilder.getDocumentStore(); Registration r1 = wb.register(MongoDocumentStore.class, ds, emptyMap()); - wb.register(MongoClientURI.class, c1.getMongoURI(), emptyMap()); + wb.register(ConnectionString.class, c1.getMongoURI(), emptyMap()); wb.register(StatisticsProvider.class, StatisticsProvider.NOOP, emptyMap()); wb.register(IndexingReporter.class, IndexingReporter.NOOP, emptyMap()); Registration c1Registration = wb.register(MongoDatabase.class, c1.getDatabase(), emptyMap()); @@ -408,7 +406,7 @@ public void metrics() throws Exception { wb.register(StatisticsProvider.class, metricsStatisticsProvider, emptyMap()); wb.register(IndexingReporter.class, new ConsoleIndexingReporter(), emptyMap()); Registration c1Registration = wb.register(MongoDatabase.class, mongoConnection.getDatabase(), emptyMap()); - wb.register(MongoClientURI.class, mongoConnection.getMongoURI(), emptyMap()); + wb.register(ConnectionString.class, mongoConnection.getMongoURI(), emptyMap()); configureIndex(store); diff --git a/oak-store-composite/pom.xml b/oak-store-composite/pom.xml index f05dda244f8..195404bfcf6 100644 --- a/oak-store-composite/pom.xml +++ b/oak-store-composite/pom.xml @@ -212,7 +212,7 @@ org.mongodb - mongo-java-driver + mongodb-driver-sync true test diff --git a/oak-store-document/pom.xml b/oak-store-document/pom.xml index 8b299b2ee7c..2429759b01a 100644 --- a/oak-store-document/pom.xml +++ b/oak-store-document/pom.xml @@ -161,7 +161,7 @@ org.mongodb - mongo-java-driver + mongodb-driver-sync true diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java index 115951f080e..44b794c09e8 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java @@ -1,19 +1,12 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work + * for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations * under the License. */ package org.apache.jackrabbit.oak.plugins.document; @@ -30,7 +23,6 @@ import static org.apache.jackrabbit.oak.spi.blob.osgi.SplitBlobStoreService.ONLY_STANDALONE_TARGET; import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean; import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.scheduleWithFixedDelay; - import java.io.Closeable; import java.io.IOException; import java.text.ParseException; @@ -47,29 +39,17 @@ import java.util.concurrent.TimeUnit; import java.util.function.Predicate; import java.util.function.Supplier; - import javax.sql.DataSource; - +import org.apache.commons.io.FilenameUtils; +import org.apache.jackrabbit.commons.SimpleValueFactory; import org.apache.jackrabbit.guava.common.base.Strings; import org.apache.jackrabbit.guava.common.io.Closer; import org.apache.jackrabbit.guava.common.util.concurrent.UncheckedExecutionException; -import com.mongodb.MongoClientURI; - -import org.apache.commons.io.FilenameUtils; -import org.apache.jackrabbit.commons.SimpleValueFactory; import org.apache.jackrabbit.oak.api.Descriptors; import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean; import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean; import org.apache.jackrabbit.oak.api.jmx.PersistentCacheStatsMBean; import org.apache.jackrabbit.oak.cache.CacheStats; -import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStoreMetrics; -import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder; -import org.apache.jackrabbit.oak.plugins.document.spi.lease.LeaseFailureHandler; -import org.apache.jackrabbit.oak.plugins.document.util.Utils; -import org.apache.jackrabbit.oak.spi.commit.ObserverTracker; import org.apache.jackrabbit.oak.osgi.OsgiWhiteboard; import org.apache.jackrabbit.oak.plugins.blob.BlobGC; import org.apache.jackrabbit.oak.plugins.blob.BlobGCMBean; @@ -79,14 +59,23 @@ import org.apache.jackrabbit.oak.plugins.blob.SharedDataStore; import org.apache.jackrabbit.oak.plugins.blob.datastore.BlobIdTracker; import org.apache.jackrabbit.oak.plugins.blob.datastore.SharedDataStoreUtils; +import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats; +import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder; +import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; +import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStoreMetrics; import org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCacheStats; +import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder; +import org.apache.jackrabbit.oak.plugins.document.spi.lease.LeaseFailureHandler; import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; -import org.apache.jackrabbit.oak.spi.cluster.ClusterRepositoryInfo; +import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.blob.BlobStoreWrapper; import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore; import org.apache.jackrabbit.oak.spi.blob.stats.BlobStoreStatsMBean; +import org.apache.jackrabbit.oak.spi.cluster.ClusterRepositoryInfo; import org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean; +import org.apache.jackrabbit.oak.spi.commit.ObserverTracker; +import org.apache.jackrabbit.oak.spi.descriptors.GenericDescriptors; import org.apache.jackrabbit.oak.spi.gc.DelegatingGCMonitor; import org.apache.jackrabbit.oak.spi.gc.GCMonitor; import org.apache.jackrabbit.oak.spi.gc.GCMonitorTracker; @@ -103,7 +92,6 @@ import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard; import org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardExecutor; import org.apache.jackrabbit.oak.stats.StatisticsProvider; -import org.apache.jackrabbit.oak.spi.descriptors.GenericDescriptors; import org.jetbrains.annotations.NotNull; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; @@ -121,6 +109,8 @@ import org.quartz.CronExpression; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings; /** * The OSGi service to start/stop a DocumentNodeStore instance. @@ -146,11 +136,11 @@ public class DocumentNodeStoreService { static final boolean DEFAULT_CUSTOM_BLOB_STORE = false; public static final String CONTINUOUS_RGC_EXPR = "*/5 * * * * ?"; public static final String CLASSIC_RGC_EXPR = "0 0 2 * * ?"; - public static final long DEFAULT_RGC_TIME_LIMIT_SECS = 3*60*60; // default is 3 hours + public static final long DEFAULT_RGC_TIME_LIMIT_SECS = 3 * 60 * 60; // default is 3 hours public static final double DEFAULT_RGC_DELAY_FACTOR = 0; private static final String DESCRIPTION = "oak.nodestore.description"; - static final long DEFAULT_JOURNAL_GC_INTERVAL_MILLIS = 5*60*1000; // default is 5min - static final long DEFAULT_JOURNAL_GC_MAX_AGE_MILLIS = 24*60*60*1000; // default is 24hours + static final long DEFAULT_JOURNAL_GC_INTERVAL_MILLIS = 5 * 60 * 1000; // default is 5min + static final long DEFAULT_JOURNAL_GC_MAX_AGE_MILLIS = 24 * 60 * 60 * 1000; // default is 24hours static final boolean DEFAULT_PREFETCH_EXTERNAL_CHANGES = false; private static final String DEFAULT_PROP_HOME = "./repository"; static final long DEFAULT_MAX_REPLICATION_LAG = 6 * 60 * 60; @@ -160,7 +150,7 @@ public class DocumentNodeStoreService { /** * Revisions older than this time would be garbage collected */ - static final long DEFAULT_VER_GC_MAX_AGE = 24 * 60 * 60; //TimeUnit.DAYS.toSeconds(1); + static final long DEFAULT_VER_GC_MAX_AGE = 24 * 60 * 60; // TimeUnit.DAYS.toSeconds(1); /** @@ -205,7 +195,8 @@ public class DocumentNodeStoreService { public static final String PROP_DS_TYPE = "documentStoreType"; private enum DocumentStoreType { - MONGO, RDB; + MONGO, + RDB; static DocumentStoreType fromString(String type) { if (type == null) { @@ -320,7 +311,11 @@ private void registerNodeStore() throws IOException { String db = config.db(); boolean soKeepAlive = config.socketKeepAlive(); - MongoClientURI mongoURI = new MongoClientURI(uri); + ConnectionString mongoURI = new ConnectionString(uri); + MongoClientSettings settings = MongoClientSettings.builder() + .applyConnectionString(mongoURI) + .build(); + String persistentCache = resolvePath(config.persistentCache(), DEFAULT_PERSISTENT_CACHE); String journalCache = resolvePath(config.journalCache(), DEFAULT_JOURNAL_CACHE); @@ -328,12 +323,12 @@ private void registerNodeStore() throws IOException { // Take care around not logging the uri directly as it // might contain passwords log.info("Starting DocumentNodeStore with host={}, db={}, cache size (MB)={}, persistentCache={}, " + - "journalCache={}, blobCacheSize (MB)={}, maxReplicationLagInSecs={}, " + - "clusterIdReuseDelayAfterRecoveryMillis={}, recoveryDelayMillis={}", + "journalCache={}, blobCacheSize (MB)={}, maxReplicationLagInSecs={}, " + + "clusterIdReuseDelayAfterRecoveryMillis={}, recoveryDelayMillis={}", mongoURI.getHosts(), db, config.cache(), persistentCache, journalCache, config.blobCacheSize(), config.maxReplicationLagInSecs(), config.clusterIdReuseDelayAfterRecoveryMillis(), config.recoveryDelayMillis()); - log.info("Mongo Connection details {}", MongoConnection.toString(mongoURI.getOptions())); + log.info("Mongo Connection details {}", MongoConnection.toString(settings)); } MongoDocumentNodeStoreBuilder builder = newMongoDocumentNodeStoreBuilder(); @@ -348,14 +343,15 @@ private void registerNodeStore() throws IOException { log.info("Connected to database '{}'", db); } - if (!customBlobStore){ + if (!customBlobStore) { defaultBlobStore = mkBuilder.getBlobStore(); log.info("Registering the BlobStore with ServiceRegistry"); - blobStoreReg = context.getBundleContext().registerService(BlobStore.class.getName(), - defaultBlobStore , null); + blobStoreReg = context.getBundleContext() + .registerService(BlobStore.class.getName(), + defaultBlobStore, null); } - //Set wrapping blob store after setting the DB + // Set wrapping blob store after setting the DB if (isWrappingCustomBlobStore()) { ((BlobStoreWrapper) blobStore).setBlobStore(mkBuilder.getBlobStore()); mkBuilder.setBlobStore(blobStore); @@ -379,14 +375,15 @@ private void registerNodeStore() throws IOException { nodeStore = mkBuilder.build(); - // ensure a clusterId is initialized + // ensure a clusterId is initialized // and expose it as 'oak.clusterid' repository descriptor GenericDescriptors clusterIdDesc = new GenericDescriptors(); - clusterIdDesc.put(ClusterRepositoryInfo.OAK_CLUSTERID_REPOSITORY_DESCRIPTOR_KEY, + clusterIdDesc.put(ClusterRepositoryInfo.OAK_CLUSTERID_REPOSITORY_DESCRIPTOR_KEY, new SimpleValueFactory().createValue( - ClusterRepositoryInfo.getOrCreateId(nodeStore)), true, false); + ClusterRepositoryInfo.getOrCreateId(nodeStore)), + true, false); whiteboard.register(Descriptors.class, clusterIdDesc, Collections.emptyMap()); - + // If a shared data store register the repo id in the data store if (SharedDataStoreUtils.isShared(blobStore)) { String repoId = null; @@ -400,12 +397,13 @@ private void registerNodeStore() throws IOException { if (blobStore instanceof BlobTrackingStore) { BlobTrackingStore trackingStore = (BlobTrackingStore) blobStore; if (trackingStore.getTracker() != null) { - trackingStore.getTracker().close(); + trackingStore.getTracker() + .close(); } ((BlobTrackingStore) blobStore).addTracker( - BlobIdTracker.build(getRepositoryHome(), repoId, - config.blobTrackSnapshotIntervalInSecs(), - (SharedDataStore) blobStore)); + BlobIdTracker.build(getRepositoryHome(), repoId, + config.blobTrackSnapshotIntervalInSecs(), + (SharedDataStore) blobStore)); } } @@ -427,12 +425,12 @@ private void registerNodeStore() throws IOException { String[] serviceClasses; if (isNodeStoreProvider()) { registerNodeStoreProvider(nodeStore); - serviceClasses = new String[]{ + serviceClasses = new String[] { DocumentNodeStore.class.getName(), Clusterable.class.getName() }; } else { - serviceClasses = new String[]{ + serviceClasses = new String[] { NodeStore.class.getName(), DocumentNodeStore.class.getName(), Clusterable.class.getName() @@ -445,16 +443,18 @@ private void registerNodeStore() throws IOException { // OAK-2844: in order to allow DocumentDiscoveryLiteService to directly // require a service DocumentNodeStore (instead of having to do an 'instanceof') // the registration is now done for both NodeStore and DocumentNodeStore here. - nodeStoreReg = context.getBundleContext().registerService( - serviceClasses, - nodeStore, props); + nodeStoreReg = context.getBundleContext() + .registerService( + serviceClasses, + nodeStore, props); } private LeaseFailureHandler createDefaultLeaseFailureHandler() { return new LeaseFailureHandler() { @Override public void handleLeaseFailure() { - Bundle bundle = context.getBundleContext().getBundle(); + Bundle bundle = context.getBundleContext() + .getBundle(); String bundleName = bundle.getSymbolicName(); try { // plan A: try stopping oak-store-document @@ -478,35 +478,36 @@ private void configureBuilder(DocumentNodeStoreBuilder builder) { String persistentCache = resolvePath(config.persistentCache(), DEFAULT_PERSISTENT_CACHE); String journalCache = resolvePath(config.journalCache(), DEFAULT_JOURNAL_CACHE); final Tracker leaseFailureHandlerTracker = whiteboard.track(LeaseFailureHandler.class); - builder.setStatisticsProvider(statisticsProvider). - setExecutor(executor). - memoryCacheSize(config.cache() * MB). - memoryCacheDistribution( + builder.setStatisticsProvider(statisticsProvider) + .setExecutor(executor) + .memoryCacheSize(config.cache() * MB) + .memoryCacheDistribution( config.nodeCachePercentage(), config.prevDocCachePercentage(), config.childrenCachePercentage(), - config.diffCachePercentage()). - setCacheSegmentCount(config.cacheSegmentCount()). - setCacheStackMoveDistance(config.cacheStackMoveDistance()). - setBundlingDisabled(config.bundlingDisabled()). - setJournalPropertyHandlerFactory(journalPropertyHandlerFactory). - setLeaseCheckMode(ClusterNodeInfo.DEFAULT_LEASE_CHECK_DISABLED ? LeaseCheckMode.DISABLED : LeaseCheckMode.valueOf(config.leaseCheckMode())). - setPrefetchFeature(prefetchFeature). - setDocStoreThrottlingFeature(docStoreThrottlingFeature). - setNoChildOrderCleanupFeature(noChildOrderCleanupFeature). - setCancelInvalidationFeature(cancelInvalidationFeature). - setDocStoreFullGCFeature(docStoreFullGCFeature). - setDocStoreEmbeddedVerificationFeature(docStoreEmbeddedVerificationFeature). - setThrottlingEnabled(config.throttlingEnabled()). - setFullGCEnabled(config.fullGCEnabled()). - setFullGCIncludePaths(config.fullGCIncludePaths()). - setFullGCExcludePaths(config.fullGCExcludePaths()). - setEmbeddedVerificationEnabled(config.embeddedVerificationEnabled()). - setFullGCMode(config.fullGCMode()). - setSuspendTimeoutMillis(config.suspendTimeoutMillis()). - setClusterIdReuseDelayAfterRecovery(config.clusterIdReuseDelayAfterRecoveryMillis()). - setRecoveryDelayMillis(config.recoveryDelayMillis()). - setLeaseFailureHandler(new LeaseFailureHandler() { + config.diffCachePercentage()) + .setCacheSegmentCount(config.cacheSegmentCount()) + .setCacheStackMoveDistance(config.cacheStackMoveDistance()) + .setBundlingDisabled(config.bundlingDisabled()) + .setJournalPropertyHandlerFactory(journalPropertyHandlerFactory) + .setLeaseCheckMode( + ClusterNodeInfo.DEFAULT_LEASE_CHECK_DISABLED ? LeaseCheckMode.DISABLED : LeaseCheckMode.valueOf(config.leaseCheckMode())) + .setPrefetchFeature(prefetchFeature) + .setDocStoreThrottlingFeature(docStoreThrottlingFeature) + .setNoChildOrderCleanupFeature(noChildOrderCleanupFeature) + .setCancelInvalidationFeature(cancelInvalidationFeature) + .setDocStoreFullGCFeature(docStoreFullGCFeature) + .setDocStoreEmbeddedVerificationFeature(docStoreEmbeddedVerificationFeature) + .setThrottlingEnabled(config.throttlingEnabled()) + .setFullGCEnabled(config.fullGCEnabled()) + .setFullGCIncludePaths(config.fullGCIncludePaths()) + .setFullGCExcludePaths(config.fullGCExcludePaths()) + .setEmbeddedVerificationEnabled(config.embeddedVerificationEnabled()) + .setFullGCMode(config.fullGCMode()) + .setSuspendTimeoutMillis(config.suspendTimeoutMillis()) + .setClusterIdReuseDelayAfterRecovery(config.clusterIdReuseDelayAfterRecoveryMillis()) + .setRecoveryDelayMillis(config.recoveryDelayMillis()) + .setLeaseFailureHandler(new LeaseFailureHandler() { private final LeaseFailureHandler defaultLeaseFailureHandler = createDefaultLeaseFailureHandler(); @@ -535,11 +536,11 @@ public void handleLeaseFailure() { } } } - }). - setPrefetchExternalChanges(config.prefetchExternalChanges()). - setUpdateLimit(config.updateLimit()). - setJournalGCMaxAge(config.journalGCMaxAge()). - setNodeCachePathPredicate(createCachePredicate()); + }) + .setPrefetchExternalChanges(config.prefetchExternalChanges()) + .setUpdateLimit(config.updateLimit()) + .setJournalGCMaxAge(config.journalGCMaxAge()) + .setNodeCachePathPredicate(createCachePredicate()); if (!Strings.isNullOrEmpty(persistentCache)) { builder.setPersistentCache(persistentCache); @@ -548,7 +549,7 @@ public void handleLeaseFailure() { builder.setJournalCache(journalCache); } - //Set blobstore before setting the document store + // Set blobstore before setting the document store if (customBlobStore && !isWrappingCustomBlobStore()) { requireNonNull(blobStore, String.format("Use of custom BlobStore enabled via [%s] but blobStore reference not " + "initialized", CUSTOM_BLOB_STORE)); @@ -572,7 +573,7 @@ private Predicate createCachePredicate() { if (config.persistentCacheIncludes().length == 0) { return x -> true; } - if (Arrays.equals(config.persistentCacheIncludes(), new String[]{"/"})) { + if (Arrays.equals(config.persistentCacheIncludes(), new String[] {"/"})) { return x -> true; } @@ -628,10 +629,11 @@ private String getVersionGCExpression() { private void registerNodeStoreProvider(final NodeStore ns) { Dictionary props = new Hashtable<>(); props.put(NodeStoreProvider.ROLE, config.role()); - nodeStoreReg = context.getBundleContext().registerService( - NodeStoreProvider.class.getName(), - (NodeStoreProvider) () -> ns, - props); + nodeStoreReg = context.getBundleContext() + .registerService( + NodeStoreProvider.class.getName(), + (NodeStoreProvider) () -> ns, + props); log.info("Registered NodeStoreProvider backed by DocumentNodeStore"); } @@ -641,7 +643,7 @@ protected void deactivate() { observerTracker.stop(); } - if (journalPropertyHandlerFactory != null){ + if (journalPropertyHandlerFactory != null) { journalPropertyHandlerFactory.stop(); } @@ -671,11 +673,10 @@ protected void deactivate() { @Reference(name = "blobStore", cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC, - target = ONLY_STANDALONE_TARGET - ) + target = ONLY_STANDALONE_TARGET) @SuppressWarnings("UnusedDeclaration") protected void bindBlobStore(BlobStore blobStore) throws IOException { - if (defaultBlobStore == blobStore){ + if (defaultBlobStore == blobStore) { return; } log.info("Initializing DocumentNodeStore with BlobStore [{}]", blobStore); @@ -685,7 +686,7 @@ protected void bindBlobStore(BlobStore blobStore) throws IOException { @SuppressWarnings("UnusedDeclaration") protected void unbindBlobStore(BlobStore blobStore) { - if (defaultBlobStore == blobStore){ + if (defaultBlobStore == blobStore) { return; } this.blobStore = null; @@ -695,8 +696,7 @@ protected void unbindBlobStore(BlobStore blobStore) { @Reference(name = "dataSource", cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC, - target = "(datasource.name=oak)" - ) + target = "(datasource.name=oak)") @SuppressWarnings("UnusedDeclaration") protected void bindDataSource(DataSource dataSource) throws IOException { if (this.dataSource != null) { @@ -725,8 +725,7 @@ protected void unbindDataSource(DataSource dataSource) { @Reference(name = "blobDataSource", cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC, - target = "(datasource.name=oak)" - ) + target = "(datasource.name=oak)") @SuppressWarnings("UnusedDeclaration") protected void bindBlobDataSource(DataSource dataSource) throws IOException { if (this.blobDataSource != null) { @@ -752,19 +751,18 @@ protected void unbindBlobDataSource(DataSource dataSource) { @Reference(name = "nodeStateCache", cardinality = ReferenceCardinality.OPTIONAL, - policy = ReferencePolicy.DYNAMIC - ) + policy = ReferencePolicy.DYNAMIC) @SuppressWarnings("UnusedDeclaration") protected void bindNodeStateCache(DocumentNodeStateCache nodeStateCache) throws IOException { - if (nodeStore != null){ - log.info("Registered DocumentNodeStateCache [{}] with DocumentNodeStore", nodeStateCache); - nodeStore.setNodeStateCache(nodeStateCache); - } + if (nodeStore != null) { + log.info("Registered DocumentNodeStateCache [{}] with DocumentNodeStore", nodeStateCache); + nodeStore.setNodeStateCache(nodeStateCache); + } } @SuppressWarnings("UnusedDeclaration") protected void unbindNodeStateCache(DocumentNodeStateCache nodeStateCache) { - if (nodeStore != null){ + if (nodeStore != null) { nodeStore.setNodeStateCache(DocumentNodeStateCache.NOOP); } } @@ -779,11 +777,11 @@ private void unregisterNodeStore() { nodeStoreReg = null; } - //If we exposed our BlobStore then unregister it *after* - //NodeStore service. This ensures that if any other component - //like SecondaryStoreCache depends on this then it remains active - //untill DocumentNodeStore get deactivated - if (blobStoreReg != null){ + // If we exposed our BlobStore then unregister it *after* + // NodeStore service. This ensures that if any other component + // like SecondaryStoreCache depends on this then it remains active + // untill DocumentNodeStore get deactivated + if (blobStoreReg != null) { blobStoreReg.unregister(); blobStoreReg = null; } @@ -799,8 +797,7 @@ private void unregisterNodeStore() { } } - private void registerJMXBeans(final DocumentNodeStore store, DocumentNodeStoreBuilder mkBuilder) throws - IOException { + private void registerJMXBeans(final DocumentNodeStore store, DocumentNodeStoreBuilder mkBuilder) throws IOException { registerCacheStatsMBean(store.getNodeCacheStats()); registerCacheStatsMBean(store.getNodeChildrenCacheStats()); for (CacheStats cs : store.getDiffCacheStats()) { @@ -819,8 +816,7 @@ private void registerJMXBeans(final DocumentNodeStore store, DocumentNodeStoreBu CheckpointMBean.class, new DocumentCheckpointMBean(store), CheckpointMBean.TYPE, - "Document node store checkpoint management") - ); + "Document node store checkpoint management")); } addRegistration( @@ -828,8 +824,7 @@ private void registerJMXBeans(final DocumentNodeStore store, DocumentNodeStoreBu DocumentNodeStoreMBean.class, store.getMBean(), DocumentNodeStoreMBean.TYPE, - "Document node store management") - ); + "Document node store management")); if (mkBuilder.getBlobStoreCacheStats() != null) { registerCacheStatsMBean(mkBuilder.getBlobStoreCacheStats()); @@ -841,42 +836,43 @@ private void registerJMXBeans(final DocumentNodeStore store, DocumentNodeStoreBu DocumentStoreStatsMBean.class, (DocumentStoreStatsMBean) mkBuilder.getDocumentStoreStatsCollector(), DocumentStoreStatsMBean.TYPE, - "DocumentStore Statistics") - ); + "DocumentStore Statistics")); } // register persistent cache stats Map persistenceCacheStats = mkBuilder.getPersistenceCacheStats(); - for (PersistentCacheStats pcs: persistenceCacheStats.values()) { + for (PersistentCacheStats pcs : persistenceCacheStats.values()) { addRegistration( registerMBean(whiteboard, PersistentCacheStatsMBean.class, pcs, PersistentCacheStatsMBean.TYPE, - pcs.getName()) - ); + pcs.getName())); } final long versionGcMaxAgeInSecs = config.versionGcMaxAgeInSecs(); final long blobGcMaxAgeInSecs = config.blobGcMaxAgeInSecs(); if (store.getBlobStore() instanceof GarbageCollectableBlobStore) { - BlobGarbageCollector gc = store.createBlobGarbageCollector(blobGcMaxAgeInSecs, - ClusterRepositoryInfo.getOrCreateId(nodeStore), - whiteboard, statisticsProvider); + BlobGarbageCollector gc = store.createBlobGarbageCollector(blobGcMaxAgeInSecs, + ClusterRepositoryInfo.getOrCreateId(nodeStore), + whiteboard, statisticsProvider); addRegistration(registerMBean(whiteboard, BlobGCMBean.class, new BlobGC(gc, executor), BlobGCMBean.TYPE, "Document node store blob garbage collection")); } Runnable startGC = new RevisionGCJob(store, versionGcMaxAgeInSecs, 0, DEFAULT_RGC_DELAY_FACTOR); - Runnable cancelGC = () -> store.getVersionGarbageCollector().cancel(); - Supplier status = () -> store.getVersionGarbageCollector().getStatus(); + Runnable cancelGC = () -> store.getVersionGarbageCollector() + .cancel(); + Supplier status = () -> store.getVersionGarbageCollector() + .getStatus(); RevisionGC revisionGC = new RevisionGC(startGC, cancelGC, status, executor); addRegistration(registerMBean(whiteboard, RevisionGCMBean.class, revisionGC, RevisionGCMBean.TYPE, "Document node store revision garbage collection")); addRegistration(registerMBean(whiteboard, RevisionGCStatsMBean.class, - store.getVersionGarbageCollector().getRevisionGCStats(), + store.getVersionGarbageCollector() + .getRevisionGCStats(), RevisionGCStatsMBean.TYPE, "Document node store revision garbage collection statistics")); @@ -886,13 +882,15 @@ private void registerJMXBeans(final DocumentNodeStore store, DocumentNodeStoreBu BlobStoreStatsMBean.class, blobStoreStats, BlobStoreStatsMBean.TYPE, - ds.getClass().getSimpleName())); + ds.getClass() + .getSimpleName())); } - if (!mkBuilder.isBundlingDisabled()){ + if (!mkBuilder.isBundlingDisabled()) { addRegistration(registerMBean(whiteboard, BackgroundObserverMBean.class, - store.getBundlingConfigHandler().getMBean(), + store.getBundlingConfigHandler() + .getMBean(), BackgroundObserverMBean.TYPE, "BundlingConfigObserver")); } @@ -904,11 +902,12 @@ private void registerCacheStatsMBean(CacheStats cacheStats) { } private void registerLastRevRecoveryJob(final DocumentNodeStore nodeStore) { - long leaseTime = toLong(context.getProperties().get(PROP_REV_RECOVERY_INTERVAL), + long leaseTime = toLong(context.getProperties() + .get(PROP_REV_RECOVERY_INTERVAL), ClusterNodeInfo.DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS); addRegistration(scheduleWithFixedDelay(whiteboard, new LastRevRecoveryJob(nodeStore), TimeUnit.MILLISECONDS.toSeconds(leaseTime), - false/*runOnSingleClusterNode*/, true /*use dedicated pool*/)); + false/* runOnSingleClusterNode */, true /* use dedicated pool */)); } private void registerJournalGC(final DocumentNodeStore nodeStore) { @@ -916,7 +915,7 @@ private void registerJournalGC(final DocumentNodeStore nodeStore) { new JournalGCJob(nodeStore), jobPropertiesFor(JournalGCJob.class), TimeUnit.MILLISECONDS.toSeconds(config.journalGCInterval()), - true/*runOnSingleClusterNode*/, true /*use dedicated pool*/)); + true/* runOnSingleClusterNode */, true /* use dedicated pool */)); } private void registerVersionGCJob(final DocumentNodeStore nodeStore) { @@ -1017,9 +1016,9 @@ static final class RevisionGCJob implements Runnable, Supplier { private VersionGCStats stats; RevisionGCJob(DocumentNodeStore ns, - long versionGcMaxAgeInSecs, - long versionGCTimeLimitInSecs, - double versionGCDelayFactor) { + long versionGcMaxAgeInSecs, + long versionGCTimeLimitInSecs, + double versionGCDelayFactor) { this.nodeStore = ns; this.versionGCMaxAgeInSecs = versionGcMaxAgeInSecs; this.versionGCTimeLimitInSecs = versionGCTimeLimitInSecs; @@ -1030,7 +1029,9 @@ static final class RevisionGCJob implements Runnable, Supplier { @Override public void run() { VersionGarbageCollector gc = nodeStore.getVersionGarbageCollector(); - gc.setOptions(gc.getOptions().withMaxDuration(TimeUnit.SECONDS, versionGCTimeLimitInSecs).withDelayFactor(versionGCDelayFactor)); + gc.setOptions(gc.getOptions() + .withMaxDuration(TimeUnit.SECONDS, versionGCTimeLimitInSecs) + .withDelayFactor(versionGCDelayFactor)); try { VersionGCStats s = gc.gc(versionGCMaxAgeInSecs, TimeUnit.SECONDS); stats.addRun(s); @@ -1048,8 +1049,7 @@ public void run() { } /** - * Returns the result of the last revision GC run. This method throws - * an {@link UncheckedExecutionException} if the last run failed with an + * Returns the result of the last revision GC run. This method throws an {@link UncheckedExecutionException} if the last run failed with an * exception. * * @return result of the last revision GC run. @@ -1063,12 +1063,14 @@ public String get() throws UncheckedExecutionException { } private void resetStats() { - lastLogTime = nodeStore.getClock().getTime(); + lastLogTime = nodeStore.getClock() + .getTime(); stats = new VersionGCStats(); } private void maybeLogStats() { - if (nodeStore.getClock().getTime() > lastLogTime + LOG_INTERVAL) { + if (nodeStore.getClock() + .getTime() > lastLogTime + LOG_INTERVAL) { LOGGER.info("Garbage collector stats since {}: {}", Utils.timestampToString(lastLogTime), stats); resetStats(); @@ -1086,7 +1088,8 @@ private static final class JournalGCJob implements Runnable { @Override public void run() { - nodeStore.getJournalGarbageCollector().gc(); + nodeStore.getJournalGarbageCollector() + .gc(); } } @@ -1100,7 +1103,8 @@ private static final class LastRevRecoveryJob implements Runnable { @Override public void run() { - nodeStore.getLastRevRecoveryAgent().performRecoveryIfNeeded(); + nodeStore.getLastRevRecoveryAgent() + .performRecoveryIfNeeded(); } } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoBlobStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoBlobStore.java index c391c371114..315bf939581 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoBlobStore.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoBlobStore.java @@ -16,16 +16,16 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static com.mongodb.ReadPreference.primary; +import static org.bson.codecs.configuration.CodecRegistries.fromCodecs; +import static org.bson.codecs.configuration.CodecRegistries.fromRegistries; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.stream.StreamSupport; - -import com.mongodb.ReadPreference; -import com.mongodb.client.model.UpdateOptions; -import com.mongodb.client.result.UpdateResult; +import org.apache.jackrabbit.guava.common.collect.AbstractIterator; import org.apache.jackrabbit.oak.commons.StringUtils; import org.apache.jackrabbit.oak.plugins.blob.CachingBlobStore; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder; @@ -36,19 +36,16 @@ import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import org.apache.jackrabbit.guava.common.collect.AbstractIterator; import com.mongodb.BasicDBObject; -import com.mongodb.MongoClient; +import com.mongodb.MongoClientSettings; import com.mongodb.MongoException; +import com.mongodb.ReadPreference; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoCursor; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Filters; - -import static com.mongodb.ReadPreference.primary; -import static org.bson.codecs.configuration.CodecRegistries.fromCodecs; -import static org.bson.codecs.configuration.CodecRegistries.fromRegistries; +import com.mongodb.client.model.UpdateOptions; +import com.mongodb.client.result.UpdateResult; /** * Implementation of blob store for the MongoDB extending from @@ -68,7 +65,7 @@ public class MongoBlobStore extends CachingBlobStore { private static final CodecRegistry CODEC_REGISTRY = fromRegistries( fromCodecs(new MongoBlobCodec()), - MongoClient.getDefaultCodecRegistry() + MongoClientSettings.getDefaultCodecRegistry() ); private final ReadPreference defaultReadPreference; diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConnection.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConnection.java index 4ef0151f52d..117dd0cd667 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConnection.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConnection.java @@ -1,41 +1,35 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work + * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations + * under the License. */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static java.util.Objects.requireNonNull; +import static org.apache.jackrabbit.oak.plugins.document.util.MongoConnection.readConcernLevel; +import java.util.concurrent.TimeUnit; +import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.mongodb.BasicDBObject; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientOptions; -import com.mongodb.MongoClientURI; +import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings.Builder; import com.mongodb.ReadConcernLevel; import com.mongodb.client.ClientSession; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; -import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.oak.plugins.document.util.MongoConnection.readConcernLevel; - /** - * Simple struct that contains {@code MongoClient}, {@code MongoDatabase} and - * {@code MongoStatus}. + * Simple struct that contains {@code MongoClient}, {@code MongoDatabase} and {@code MongoStatus}. */ final class MongoDBConnection { @@ -48,9 +42,9 @@ final class MongoDBConnection { private final MongoSessionFactory sessionFactory; MongoDBConnection(@NotNull MongoClient client, - @NotNull MongoDatabase database, - @NotNull MongoStatus status, - @NotNull MongoClock clock) { + @NotNull MongoDatabase database, + @NotNull MongoStatus status, + @NotNull MongoClock clock) { this.client = requireNonNull(client); this.db = requireNonNull(database); this.status = requireNonNull(status); @@ -59,22 +53,30 @@ final class MongoDBConnection { } static MongoDBConnection newMongoDBConnection(@NotNull String uri, - @NotNull String name, - @NotNull MongoClock clock, - int socketTimeout, - boolean socketKeepAlive) { + @NotNull String name, + @NotNull MongoClock clock, + int socketTimeout, + boolean socketKeepAlive) { CompositeServerMonitorListener serverMonitorListener = new CompositeServerMonitorListener(); - MongoClientOptions.Builder options = MongoConnection.getDefaultBuilder(); - options.addServerMonitorListener(serverMonitorListener); - options.socketKeepAlive(socketKeepAlive); - if (socketTimeout > 0) { - options.socketTimeout(socketTimeout); - } - MongoClient client = new MongoClient(new MongoClientURI(uri, options)); + + ConnectionString connectionString = new ConnectionString(uri); + Builder options = MongoConnection.getDefaultBuilder(); + options.applyConnectionString(connectionString); + options.applyToServerSettings(builder -> builder.addServerMonitorListener(serverMonitorListener)); + options.applyToSocketSettings(builder -> { + // It's not possible anymore setting keepalive, it was deprecated since at least 3.6.0 version + // builder.keepAlive(socketKeepAlive); + if (socketTimeout > 0) { + builder.readTimeout(socketTimeout, TimeUnit.MILLISECONDS); + } + }); + + MongoClient client = MongoClients.create(options.build()); + MongoStatus status = new MongoStatus(client, name); serverMonitorListener.addListener(status); MongoDatabase db = client.getDatabase(name); - if (!MongoConnection.hasWriteConcern(uri)) { + if (MongoConnection.hasMongoDbDefaultWriteConcern(uri)) { db = db.withWriteConcern(MongoConnection.getDefaultWriteConcern(client)); } if (status.isMajorityReadConcernSupported() @@ -120,8 +122,7 @@ void close() { } /** - * Checks read and write concern on the {@code MongoDatabase} and logs warn - * messages when they differ from the recommended values. + * Checks read and write concern on the {@code MongoDatabase} and logs warn messages when they differ from the recommended values. */ void checkReadWriteConcern() { if (!MongoConnection.isSufficientWriteConcern(client, db.getWriteConcern())) { diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentNodeStoreBuilderBase.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentNodeStoreBuilderBase.java index 46f6f7decdf..50d89b5980a 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentNodeStoreBuilderBase.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentNodeStoreBuilderBase.java @@ -1,25 +1,19 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work + * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations + * under the License. */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static org.apache.jackrabbit.guava.common.base.Suppliers.memoize; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConnection.newMongoDBConnection; import java.util.concurrent.TimeUnit; - -import com.mongodb.MongoClient; - import org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder; @@ -27,13 +21,10 @@ import org.apache.jackrabbit.oak.plugins.document.MissingLastRevSeeker; import org.apache.jackrabbit.oak.plugins.document.VersionGCSupport; import org.jetbrains.annotations.NotNull; - -import static org.apache.jackrabbit.guava.common.base.Suppliers.memoize; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConnection.newMongoDBConnection; +import com.mongodb.client.MongoClient; /** - * A base builder implementation for a {@link DocumentNodeStore} backed by - * MongoDB. + * A base builder implementation for a {@link DocumentNodeStore} backed by MongoDB. */ public abstract class MongoDocumentNodeStoreBuilderBase> extends DocumentNodeStoreBuilder { @@ -50,22 +41,18 @@ public abstract class MongoDocumentNodeStoreBuilderBase new MongoBlobStore(mongoDBConnection.getDatabase(), blobCacheSizeMB * 1024 * 1024L, MongoDocumentNodeStoreBuilderBase.this)); + () -> new MongoBlobStore(mongoDBConnection.getDatabase(), blobCacheSizeMB * 1024 * 1024L, + MongoDocumentNodeStoreBuilderBase.this)); } return thisBuilder(); diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java index baaaf8b9aef..2dc68ae4f09 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java @@ -16,6 +16,30 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static com.mongodb.client.model.Projections.include; +import static java.lang.Integer.MAX_VALUE; +import static java.util.Collections.emptyList; +import static java.util.Objects.isNull; +import static java.util.concurrent.TimeUnit.NANOSECONDS; +import static java.util.stream.Collectors.toList; +import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; +import static org.apache.jackrabbit.guava.common.collect.Maps.filterKeys; +import static org.apache.jackrabbit.guava.common.collect.Sets.difference; +import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; +import static org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.asDocumentStoreException; +import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.DELETED_ONCE; +import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS; +import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.NULL; +import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_MAX_REV_TIME_IN_SECS; +import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_TYPE; +import static org.apache.jackrabbit.oak.plugins.document.Throttler.NO_THROTTLING; +import static org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition.newEqualsCondition; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoThrottlerFactory.exponentialThrottler; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.createIndex; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.createPartialIndex; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.getDocumentStoreExceptionTypeFor; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.hasIndex; +import static org.apache.jackrabbit.oak.plugins.document.util.Utils.isThrottlingEnabled; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -28,40 +52,30 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; -import java.util.TreeMap; import java.util.Objects; import java.util.Optional; +import java.util.Set; +import java.util.TreeMap; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.Lock; +import java.util.function.Consumer; import java.util.stream.StreamSupport; - import org.apache.jackrabbit.guava.common.base.Stopwatch; import org.apache.jackrabbit.guava.common.collect.ImmutableList; import org.apache.jackrabbit.guava.common.collect.ImmutableMap; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.guava.common.collect.Lists; +import org.apache.jackrabbit.guava.common.collect.Maps; import org.apache.jackrabbit.guava.common.io.Closeables; import org.apache.jackrabbit.guava.common.util.concurrent.AtomicDouble; -import com.mongodb.Block; -import com.mongodb.DBObject; -import com.mongodb.MongoBulkWriteException; -import com.mongodb.MongoWriteException; -import com.mongodb.MongoCommandException; -import com.mongodb.WriteError; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientURI; -import com.mongodb.ReadPreference; - -import com.mongodb.client.model.CreateCollectionOptions; - import org.apache.jackrabbit.guava.common.util.concurrent.UncheckedExecutionException; import org.apache.jackrabbit.oak.cache.CacheStats; import org.apache.jackrabbit.oak.cache.CacheValue; +import org.apache.jackrabbit.oak.commons.PerfLogger; import org.apache.jackrabbit.oak.plugins.document.Collection; import org.apache.jackrabbit.oak.plugins.document.Document; import org.apache.jackrabbit.oak.plugins.document.DocumentStore; @@ -71,8 +85,8 @@ import org.apache.jackrabbit.oak.plugins.document.NodeDocument; import org.apache.jackrabbit.oak.plugins.document.Revision; import org.apache.jackrabbit.oak.plugins.document.StableRevisionComparator; -import org.apache.jackrabbit.oak.plugins.document.UpdateOp; import org.apache.jackrabbit.oak.plugins.document.Throttler; +import org.apache.jackrabbit.oak.plugins.document.UpdateOp; import org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition; import org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key; import org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation; @@ -85,7 +99,6 @@ import org.apache.jackrabbit.oak.plugins.document.locks.StripedNodeDocumentLocks; import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.apache.jackrabbit.oak.stats.Clock; -import org.apache.jackrabbit.oak.commons.PerfLogger; import org.bson.BSONException; import org.bson.BsonMaximumSizeExceededException; import org.bson.conversions.Bson; @@ -93,20 +106,28 @@ import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import org.apache.jackrabbit.guava.common.collect.Maps; import com.mongodb.BasicDBObject; +import com.mongodb.ConnectionString; +import com.mongodb.DBObject; +import com.mongodb.MongoBulkWriteException; +import com.mongodb.MongoClientSettings; +import com.mongodb.MongoCommandException; import com.mongodb.MongoException; +import com.mongodb.MongoWriteException; +import com.mongodb.ReadPreference; import com.mongodb.WriteConcern; +import com.mongodb.WriteError; import com.mongodb.bulk.BulkWriteError; import com.mongodb.bulk.BulkWriteResult; import com.mongodb.bulk.BulkWriteUpsert; import com.mongodb.client.ClientSession; import com.mongodb.client.FindIterable; +import com.mongodb.client.MongoClient; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoCursor; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.BulkWriteOptions; +import com.mongodb.client.model.CreateCollectionOptions; import com.mongodb.client.model.Filters; import com.mongodb.client.model.FindOneAndUpdateOptions; import com.mongodb.client.model.ReturnDocument; @@ -116,31 +137,6 @@ import com.mongodb.client.result.DeleteResult; import com.mongodb.client.result.UpdateResult; -import static java.util.Objects.isNull; -import static java.util.concurrent.TimeUnit.NANOSECONDS; -import static java.util.stream.Collectors.toList; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; -import static org.apache.jackrabbit.guava.common.collect.Maps.filterKeys; -import static org.apache.jackrabbit.guava.common.collect.Sets.difference; -import static com.mongodb.client.model.Projections.include; -import static java.lang.Integer.MAX_VALUE; -import static java.util.Collections.emptyList; -import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; -import static org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.asDocumentStoreException; -import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.DELETED_ONCE; -import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS; -import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.NULL; -import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_MAX_REV_TIME_IN_SECS; -import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_TYPE; -import static org.apache.jackrabbit.oak.plugins.document.Throttler.NO_THROTTLING; -import static org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition.newEqualsCondition; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoThrottlerFactory.exponentialThrottler; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.createIndex; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.createPartialIndex; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.getDocumentStoreExceptionTypeFor; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.hasIndex; -import static org.apache.jackrabbit.oak.plugins.document.util.Utils.isThrottlingEnabled; - /** * A document store that uses MongoDB as the backend. */ @@ -689,7 +685,7 @@ protected T findUncached(Collection collection, String k ReadPreference readPreference = getMongoReadPreference(collection, null, docReadPref); MongoCollection dbCollection = getDBCollection(collection, readPreference); - if(readPreference.isSlaveOk()){ + if (readPreference.isSecondaryOk()) { LOG.trace("Routing call to secondary for fetching [{}]", key); isSlaveOk = true; } @@ -835,7 +831,7 @@ && canUseModifiedTimeIdx(startValue)) { ReadPreference readPreference = getMongoReadPreference(collection, parentId, getDefaultReadPreference(collection)); - if(readPreference.isSlaveOk()){ + if (readPreference.isSecondaryOk()) { isSlaveOk = true; LOG.trace("Routing call to secondary for fetching children from [{}] to [{}]", fromKey, toKey); } @@ -1539,12 +1535,7 @@ private Map findDocuments(Collection collecti conditions.add(getByKeyQuery(key)); } MongoCollection dbCollection; - if (secondariesWithinAcceptableLag()) { - dbCollection = getDBCollection(collection); - } else { - lagTooHigh(); - dbCollection = getDBCollection(collection).withReadPreference(ReadPreference.primary()); - } + dbCollection = getDBCollection(collection); execute(session -> { FindIterable cursor; if (session != null) { @@ -1574,12 +1565,7 @@ private Map findDocumentsOneByOne(Collection Bson condition = getByKeyQuery(key); MongoCollection dbCollection; - if (secondariesWithinAcceptableLag()) { - dbCollection = getDBCollection(collection); - } else { - lagTooHigh(); - dbCollection = getDBCollection(collection).withReadPreference(ReadPreference.primary()); - } + dbCollection = getDBCollection(collection); execute(session -> { FindIterable cursor; if (session != null) { @@ -1774,7 +1760,7 @@ public void prefetch(Collection collection, ReadPreference readPreference = getMongoReadPreference(collection, null, getDefaultReadPreference(collection)); MongoCollection dbCollection = getDBCollection(collection, readPreference); - if (readPreference.isSlaveOk()) { + if (readPreference.isSecondaryOk()) { LOG.trace("Routing call to secondary for prefetching [{}]", keys); } @@ -1855,8 +1841,9 @@ private Map getModStamps(Iterable keys) Map modCounts = Maps.newHashMap(); nodes.withReadPreference(ReadPreference.primary()) - .find(Filters.in(Document.ID, keys)).projection(fields) - .forEach((Block) obj -> { + .find(Filters.in(Document.ID, keys)) + .projection(fields) + .forEach((Consumer) obj -> { String id = (String) obj.get(Document.ID); Long modCount = Utils.asLong((Number) obj.get(Document.MOD_COUNT)); if (modCount == null) { @@ -1902,10 +1889,10 @@ ReadPreference getMongoReadPreference(@NotNull Collection ReadPreference getMongoReadPreference(@NotNull Collection T withTransaction(@NotNull TransactionBody transactionBody) { @@ -160,7 +151,7 @@ public T withTransaction(@NotNull TransactionBody transactionBody) { @NotNull @Override public T withTransaction(@NotNull TransactionBody transactionBody, - @NotNull TransactionOptions options) { + @NotNull TransactionOptions options) { return session.withTransaction(transactionBody, options); } @@ -179,5 +170,43 @@ public void close() { clock.advanceSessionAndClock(session); session.close(); } + + @Override + public Object getTransactionContext() { + return session.getTransactionContext(); + } + + @Override + public void setTransactionContext(ServerAddress address, Object transactionContext) { + session.setTransactionContext(address, transactionContext); + + } + + @Override + public void clearTransactionContext() { + session.clearTransactionContext(); + + } + + @Override + public void setSnapshotTimestamp(BsonTimestamp snapshotTimestamp) { + session.setSnapshotTimestamp(snapshotTimestamp); + + } + + @Override + public BsonTimestamp getSnapshotTimestamp() { + return session.getSnapshotTimestamp(); + } + + @Override + public TimeoutContext getTimeoutContext() { + return session.getTimeoutContext(); + } + + @Override + public void notifyOperationInitiated(Object operation) { + session.notifyOperationInitiated(operation); + } } } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatus.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatus.java index 5ed5b7d5f2d..ece3d0501e2 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatus.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatus.java @@ -1,30 +1,32 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work + * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations + * under the License. */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Maps; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.mongodb.BasicDBObject; import com.mongodb.ClientSessionOptions; -import com.mongodb.MongoClient; import com.mongodb.MongoClientException; import com.mongodb.MongoCommandException; import com.mongodb.MongoQueryException; import com.mongodb.ReadConcern; +import com.mongodb.client.MongoClient; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoCursor; import com.mongodb.event.ServerHeartbeatFailedEvent; @@ -33,20 +35,11 @@ import com.mongodb.event.ServerMonitorListener; import com.mongodb.session.ClientSession; -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class MongoStatus implements ServerMonitorListener { private static final Logger LOG = LoggerFactory.getLogger(MongoStatus.class); - private static final ImmutableSet SERVER_DETAIL_FIELD_NAMES - = ImmutableSet.builder() + private static final ImmutableSet SERVER_DETAIL_FIELD_NAMES = ImmutableSet.builder() .add("host", "process", "connections", "repl", "storageEngine", "mem") .build(); @@ -69,7 +62,7 @@ public class MongoStatus implements ServerMonitorListener { private final ReplicaSetStatus replicaSetStatus = new ReplicaSetStatus(); public MongoStatus(@NotNull MongoClient client, - @NotNull String dbName) { + @NotNull String dbName) { this.client = client; this.dbName = dbName; } @@ -83,9 +76,8 @@ public void checkVersion() { } /** - * Check if the majority read concern is supported by this storage engine. - * The fact that read concern is supported doesn't it can be used - it also - * has to be enabled. + * Check if the majority read concern is supported by this storage engine. The fact that read concern is supported doesn't it can be used - it + * also has to be enabled. * * @return true if the majority read concern is supported */ @@ -121,7 +113,8 @@ public boolean isMajorityReadConcernEnabled() { .getCollection("emptyCollection-" + System.currentTimeMillis()); try (MongoCursor cursor = emptyCollection .withReadConcern(ReadConcern.MAJORITY) - .find(new BasicDBObject()).iterator()) { + .find(new BasicDBObject()) + .iterator()) { cursor.hasNext(); majorityReadConcernEnabled = true; } catch (MongoQueryException | IllegalArgumentException e) { @@ -159,7 +152,8 @@ public String getVersion() { boolean isVersion(int requiredMajor, int requiredMinor) { String v = getVersion(); - Matcher m = Pattern.compile("^(\\d+)\\.(\\d+)\\..*").matcher(v); + Matcher m = Pattern.compile("^(\\d+)\\.(\\d+)\\..*") + .matcher(v); if (!m.matches()) { throw new IllegalArgumentException("Malformed MongoDB version: " + v); } @@ -183,7 +177,8 @@ boolean isClientSessionSupported() { // must be at least 3.6 if (isVersion(3, 6)) { ClientSessionOptions options = ClientSessionOptions.builder() - .causallyConsistent(true).build(); + .causallyConsistent(true) + .build(); try (ClientSession ignored = client.startSession(options)) { clientSessionSupported = true; } catch (MongoClientException e) { @@ -197,13 +192,10 @@ boolean isClientSessionSupported() { } /** - * Returns an estimate of the replica-set lag in milliseconds. The returned - * value is not an accurate measurement of the replication lag and should - * only be used as a rough estimate to decide whether secondaries can be - * used for queries in general. + * Returns an estimate of the replica-set lag in milliseconds. The returned value is not an accurate measurement of the replication lag and should + * only be used as a rough estimate to decide whether secondaries can be used for queries in general. *

- * This method may return {@link ReplicaSetStatus#UNKNOWN_LAG} if the value - * is currently unknown. + * This method may return {@link ReplicaSetStatus#UNKNOWN_LAG} if the value is currently unknown. * * @return an estimate of the */ @@ -211,7 +203,7 @@ long getReplicaSetLagEstimate() { return replicaSetStatus.getLagEstimate(); } - //------------------------< ServerMonitorListener >------------------------- + // ------------------------< ServerMonitorListener >------------------------- @Override public void serverHearbeatStarted(ServerHeartbeatStartedEvent event) { @@ -233,13 +225,14 @@ public void serverHeartbeatFailed(ServerHeartbeatFailedEvent event) { replicaSetStatus.serverHeartbeatFailed(event); } - //-------------------------------< internal >------------------------------- + // -------------------------------< internal >------------------------------- private BasicDBObject getServerStatus() { if (serverStatus == null) { try { - serverStatus = client.getDatabase(dbName).runCommand( - new BasicDBObject("serverStatus", 1), BasicDBObject.class); + serverStatus = client.getDatabase(dbName) + .runCommand( + new BasicDBObject("serverStatus", 1), BasicDBObject.class); } catch (MongoCommandException e) { if (e.getErrorCode() == -1) { // OAK-7485: workaround when running on @@ -260,8 +253,9 @@ private BasicDBObject getServerStatus() { private BasicDBObject getBuildInfo() { if (buildInfo == null) { - buildInfo = client.getDatabase(dbName).runCommand( - new BasicDBObject("buildInfo", 1), BasicDBObject.class); + buildInfo = client.getDatabase(dbName) + .runCommand( + new BasicDBObject("buildInfo", 1), BasicDBObject.class); } return buildInfo; } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoVersionGCSupport.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoVersionGCSupport.java index e72991ff34f..317a172f461 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoVersionGCSupport.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoVersionGCSupport.java @@ -18,19 +18,19 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static com.mongodb.client.model.Filters.and; import static com.mongodb.client.model.Filters.eq; import static com.mongodb.client.model.Filters.exists; import static com.mongodb.client.model.Filters.gt; +import static com.mongodb.client.model.Filters.lt; import static com.mongodb.client.model.Filters.or; import static com.mongodb.client.model.Projections.include; +import static java.util.Collections.emptyList; import static java.util.Optional.empty; import static java.util.Optional.ofNullable; import static org.apache.jackrabbit.guava.common.collect.Iterables.concat; import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; -import static com.mongodb.client.model.Filters.and; -import static com.mongodb.client.model.Filters.lt; -import static java.util.Collections.emptyList; import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; import static org.apache.jackrabbit.oak.plugins.document.Document.ID; import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.DELETED_ONCE; @@ -42,7 +42,6 @@ import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType.DEFAULT_NO_BRANCH; import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.hasIndex; import static org.apache.jackrabbit.oak.plugins.document.util.CloseableIterable.wrap; - import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -50,9 +49,8 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; - -import com.mongodb.client.MongoCursor; - +import org.apache.jackrabbit.guava.common.base.Joiner; +import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.oak.commons.json.JsopBuilder; import org.apache.jackrabbit.oak.plugins.document.Document; import org.apache.jackrabbit.oak.plugins.document.NodeDocument; @@ -70,15 +68,12 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import org.apache.jackrabbit.guava.common.base.Joiner; - -import org.apache.jackrabbit.guava.common.collect.Lists; import com.mongodb.BasicDBObject; -import com.mongodb.Block; import com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoCursor; import com.mongodb.client.model.Filters; +import com.mongodb.client.model.Sorts; /** * Mongo specific version of VersionGCSupport which uses mongo queries @@ -258,7 +253,7 @@ public Iterable getModifiedDocs(final long fromModified, final lon and(gt(MODIFIED_IN_SECS, getModifiedInSecs(fromModified)), lt(MODIFIED_IN_SECS, getModifiedInSecs(toModified))))); // first sort by _modified and then by _id - final Bson sort = and(eq(MODIFIED_IN_SECS, 1), eq(ID, 1)); + final Bson sort = Sorts.ascending(MODIFIED_IN_SECS, ID); logQueryExplain("fullGC query explain details, hint : {} - explain : {}", query, modifiedIdHint); @@ -344,19 +339,17 @@ protected Iterable identifyGarbage(final Set gcTypes public long getOldestDeletedOnceTimestamp(Clock clock, long precisionMs) { LOG.debug("getOldestDeletedOnceTimestamp() <- start"); Bson query = Filters.eq(DELETED_ONCE, Boolean.TRUE); - Bson sort = Filters.eq(MODIFIED_IN_SECS, 1); + Bson sort = Sorts.ascending(MODIFIED_IN_SECS); + List result = new ArrayList<>(1); getNodeCollection().find(query).sort(sort).limit(1).forEach( - new Block() { - @Override - public void apply(BasicDBObject document) { + document -> { NodeDocument doc = store.convertFromDBObject(NODES, document); long modifiedMs = doc.getModified() * TimeUnit.SECONDS.toMillis(1); if (LOG.isDebugEnabled()) { LOG.debug("getOldestDeletedOnceTimestamp() -> {}", Utils.timestampToString(modifiedMs)); } result.add(modifiedMs); - } }); if (result.isEmpty()) { LOG.debug("getOldestDeletedOnceTimestamp() -> none found, return current time"); @@ -373,8 +366,8 @@ public void apply(BasicDBObject document) { */ @Override public Optional getOldestModifiedDoc(final Clock clock) { - final Bson sort = and(eq(MODIFIED_IN_SECS, 1), eq(ID, 1)); - + final Bson sort = Sorts.ascending(MODIFIED_IN_SECS, ID); + // we need to add query condition to ignore `previous` documents which doesn't have this field final Bson query = exists(MODIFIED_IN_SECS); @@ -459,7 +452,7 @@ private void logSplitDocIdsTobeDeleted(Bson query) { getNodeCollection() .withReadPreference(store.getConfiguredReadPreference(NODES)) .find(query).projection(keys) - .forEach((Block) doc -> ids.add(getID(doc))); + .forEach(doc -> ids.add(getID(doc))); StringBuilder sb = new StringBuilder("Split documents with following ids were deleted as part of GC \n"); Joiner.on(System.getProperty("line.separator")).appendTo(sb, ids); diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatus.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatus.java index 41a45911b04..0f44e837030 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatus.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatus.java @@ -1,18 +1,13 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work + * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations + * under the License. */ package org.apache.jackrabbit.oak.plugins.document.mongo; @@ -27,27 +22,22 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; - -import com.mongodb.ServerAddress; -import com.mongodb.event.ServerHeartbeatSucceededEvent; -import com.mongodb.event.ServerMonitorListenerAdapter; - import org.bson.BsonArray; import org.bson.BsonDocument; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.mongodb.ServerAddress; +import com.mongodb.event.ServerHeartbeatSucceededEvent; +import com.mongodb.event.ServerMonitorListener; /** - * Keeps track of the status of a replica set based on information provided - * by heartbeat events. This status provides a replica set lag estimate, which - * can be used to decide whether secondaries are sufficiently up-to-date and - * read operations can be sent to a secondary. This is particularly useful when - * causal consistent client sessions are used with the MongoDB Java driver. Read - * operations shouldn't be sent to a secondary when it lags too much behind, - * otherwise the read operation will block until it was able to catch up. + * Keeps track of the status of a replica set based on information provided by heartbeat events. This status provides a replica set lag estimate, + * which can be used to decide whether secondaries are sufficiently up-to-date and read operations can be sent to a secondary. This is particularly + * useful when causal consistent client sessions are used with the MongoDB Java driver. Read operations shouldn't be sent to a secondary when it lags + * too much behind, otherwise the read operation will block until it was able to catch up. */ -public class ReplicaSetStatus extends ServerMonitorListenerAdapter { +public class ReplicaSetStatus implements ServerMonitorListener { private static final Logger LOG = LoggerFactory.getLogger(ReplicaSetStatus.class); @@ -67,7 +57,9 @@ public class ReplicaSetStatus extends ServerMonitorListenerAdapter { @Override public void serverHeartbeatSucceeded(ServerHeartbeatSucceededEvent event) { synchronized (heartbeats) { - ServerAddress address = event.getConnectionId().getServerId().getAddress(); + ServerAddress address = event.getConnectionId() + .getServerId() + .getAddress(); Heartbeat beat = new Heartbeat(event); heartbeats.put(address, beat); members.addAll(beat.getHosts()); @@ -82,7 +74,8 @@ public long getLagEstimate() { } private void updateLag() { - if (!heartbeats.keySet().containsAll(members)) { + if (!heartbeats.keySet() + .containsAll(members)) { lagEstimate = UNKNOWN_LAG; return; } @@ -117,7 +110,7 @@ private void updateLag() { // average estimates over up to number of members and remove old value long estimate = 0; int i = 0; - for (Iterator it = estimatesPerMember.iterator(); it.hasNext(); ) { + for (Iterator it = estimatesPerMember.iterator(); it.hasNext();) { long v = it.next(); if (i++ < members.size()) { estimate += v; @@ -159,14 +152,18 @@ Date getLastWrite() { } private static List hostsFrom(ServerHeartbeatSucceededEvent event) { - return event.getReply().getArray("hosts", new BsonArray()).stream() - .map(bsonValue -> new ServerAddress(bsonValue.asString().getValue())) + return event.getReply() + .getArray("hosts", new BsonArray()) + .stream() + .map(bsonValue -> new ServerAddress(bsonValue.asString() + .getValue())) .collect(Collectors.toList()); } private static Date localTimeFrom(ServerHeartbeatSucceededEvent event) { BsonDocument reply = event.getReply(); - return new Date(reply.getDateTime("localTime").getValue()); + return new Date(reply.getDateTime("localTime") + .getValue()); } private static Date lastWriteFrom(ServerHeartbeatSucceededEvent event) { @@ -175,6 +172,7 @@ private static Date lastWriteFrom(ServerHeartbeatSucceededEvent event) { return null; } return new Date(reply.getDocument("lastWrite") - .getDateTime("lastWriteDate").getValue()); + .getDateTime("lastWriteDate") + .getValue()); } } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/RevisionEntry.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/RevisionEntry.java index bdc6fcc0440..d2a8430b6aa 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/RevisionEntry.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/RevisionEntry.java @@ -16,20 +16,16 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static java.util.Objects.requireNonNull; import java.util.Collections; import java.util.Map; import java.util.Set; - import org.apache.jackrabbit.oak.plugins.document.Revision; import org.bson.BSONObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; - import com.mongodb.BasicDBObject; import com.mongodb.DBObject; -import com.mongodb.util.JSON; - -import static java.util.Objects.requireNonNull; /** * A light-weight implementation of a MongoDB DBObject for a single revision @@ -86,11 +82,6 @@ public Object removeField(String key) { throw new UnsupportedOperationException(); } - @Override - public boolean containsKey(String s) { - return containsField(s); - } - @Override public boolean containsField(String s) { return revision.toString().equals(s); diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/MongoConnection.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/MongoConnection.java index 8a9b7c8b06f..96aaac789b6 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/MongoConnection.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/MongoConnection.java @@ -16,24 +16,27 @@ */ package org.apache.jackrabbit.oak.plugins.document.util; +import static java.util.Objects.requireNonNull; import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; - import org.apache.jackrabbit.guava.common.base.MoreObjects; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientOptions; -import com.mongodb.MongoClientURI; +import org.jetbrains.annotations.NotNull; +import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings; +import com.mongodb.MongoClientSettings.Builder; import com.mongodb.MongoException; import com.mongodb.ReadConcern; import com.mongodb.ReadConcernLevel; import com.mongodb.WriteConcern; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; import com.mongodb.client.MongoDatabase; - -import static java.util.Objects.requireNonNull; - -import org.jetbrains.annotations.NotNull; +import com.mongodb.connection.ClusterDescription; +import com.mongodb.connection.ClusterType; +import com.mongodb.connection.ConnectionPoolSettings; +import com.mongodb.connection.ServerSettings; +import com.mongodb.connection.SocketSettings; /** * The {@code MongoConnection} abstracts connection to the {@code MongoDB}. @@ -42,14 +45,16 @@ public class MongoConnection { private static final int DEFAULT_MAX_WAIT_TIME = (int) TimeUnit.MINUTES.toMillis(1); private static final int DEFAULT_HEARTBEAT_FREQUENCY_MS = (int) TimeUnit.SECONDS.toMillis(5); + + // TODO why using a non-sense "w"? values for w should those listed in the head comment of WriteConcern... private static final WriteConcern WC_UNKNOWN = new WriteConcern("unknown"); + private static final Set REPLICA_RC = Set.of(ReadConcernLevel.MAJORITY, ReadConcernLevel.LINEARIZABLE); - private final MongoClientURI mongoURI; + private final ConnectionString mongoURI; private final MongoClient mongo; /** - * Constructs a new connection using the specified MongoDB connection string. - * See also http://docs.mongodb.org/manual/reference/connection-string/ + * Constructs a new connection using the specified MongoDB connection string. See also http://docs.mongodb.org/manual/reference/connection-string/ * * @param uri the MongoDB URI * @throws MongoException if there are failures @@ -59,17 +64,19 @@ public MongoConnection(String uri) throws MongoException { } /** - * Constructs a new connection using the specified MongoDB connection - * String. The default client options are taken from the provided builder. + * Constructs a new connection using the specified MongoDB connection String. The default client options are taken from the provided builder. * * @param uri the connection URI. * @param builder the client option defaults. * @throws MongoException if there are failures */ - public MongoConnection(String uri, MongoClientOptions.Builder builder) + public MongoConnection(String uri, MongoClientSettings.Builder builder) throws MongoException { - mongoURI = new MongoClientURI(uri, builder); - mongo = new MongoClient(mongoURI); + + mongoURI = new ConnectionString(uri); + builder.applyConnectionString(mongoURI); + MongoClientSettings settings = builder.build(); + mongo = MongoClients.create(settings); } /** @@ -92,15 +99,19 @@ public MongoConnection(String host, int port, String database) * @param client the already connected client. */ public MongoConnection(String uri, MongoClient client) { - mongoURI = new MongoClientURI(uri, MongoConnection.getDefaultBuilder()); - mongo = client; + + Builder defaultBuilder = MongoConnection.getDefaultBuilder(); + mongoURI = new ConnectionString(uri); + defaultBuilder.applyConnectionString(mongoURI); + MongoClientSettings settings = defaultBuilder.build(); + mongo = MongoClients.create(settings); } /** * * @return the {@link MongoClientURI} for this connection */ - public MongoClientURI getMongoURI() { + public ConnectionString getMongoURI() { return mongoURI; } @@ -112,8 +123,7 @@ public MongoClient getMongoClient() { } /** - * Returns the {@link MongoDatabase} as passed in the URI of the - * constructor. + * Returns the {@link MongoDatabase} as passed in the URI of the constructor. * * @return the {@link MongoDatabase}. */ @@ -144,48 +154,57 @@ public void close() { mongo.close(); } - //--------------------------------------< Utility Methods > + // --------------------------------------< Utility Methods > /** * Constructs a builder with default options set. These can be overridden later * * @return builder with default options set */ - public static MongoClientOptions.Builder getDefaultBuilder() { - return new MongoClientOptions.Builder() - .description("MongoConnection for Oak DocumentMK") - .maxWaitTime(DEFAULT_MAX_WAIT_TIME) - .heartbeatFrequency(DEFAULT_HEARTBEAT_FREQUENCY_MS) - .threadsAllowedToBlockForConnectionMultiplier(100); + public static MongoClientSettings.Builder getDefaultBuilder() { + return MongoClientSettings.builder() + .applicationName("MongoConnection for Oak DocumentMK") + .applyToConnectionPoolSettings(builder -> builder + .maxWaitTime(DEFAULT_MAX_WAIT_TIME, java.util.concurrent.TimeUnit.MILLISECONDS)) + .applyToServerSettings(builder -> builder + .heartbeatFrequency(DEFAULT_HEARTBEAT_FREQUENCY_MS, java.util.concurrent.TimeUnit.MILLISECONDS)) + .applyToConnectionPoolSettings(builder -> builder + .maxSize(100)); } - public static String toString(MongoClientOptions opts) { - return MoreObjects.toStringHelper(opts) - .add("connectionsPerHost", opts.getConnectionsPerHost()) - .add("connectTimeout", opts.getConnectTimeout()) - .add("socketTimeout", opts.getSocketTimeout()) - .add("socketKeepAlive", opts.isSocketKeepAlive()) - .add("maxWaitTime", opts.getMaxWaitTime()) - .add("heartbeatFrequency", opts.getHeartbeatFrequency()) - .add("threadsAllowedToBlockForConnectionMultiplier", - opts.getThreadsAllowedToBlockForConnectionMultiplier()) - .add("readPreference", opts.getReadPreference().getName()) - .add("writeConcern", opts.getWriteConcern()) + public static String toString(MongoClientSettings settings) { + ConnectionPoolSettings poolSettings = settings.getConnectionPoolSettings(); + SocketSettings socketSettings = settings.getSocketSettings(); + ServerSettings serverSettings = settings.getServerSettings(); + + return MoreObjects.toStringHelper(settings) + .add("connectionsPerHost", poolSettings.getMaxSize()) + .add("connectTimeout", socketSettings.getConnectTimeout(java.util.concurrent.TimeUnit.MILLISECONDS)) + .add("socketTimeout", socketSettings.getReadTimeout(java.util.concurrent.TimeUnit.MILLISECONDS)) + .add("socketKeepAlive", "Unavailable in MongoClientSettings") + .add("maxWaitTime", poolSettings.getMaxWaitTime(java.util.concurrent.TimeUnit.MILLISECONDS)) + .add("heartbeatFrequency", serverSettings.getHeartbeatFrequency(java.util.concurrent.TimeUnit.MILLISECONDS)) + .add("threadsAllowedToBlockForConnectionMultiplier", "Handled via maxSize in connection pool") + .add("readPreference", settings.getReadPreference() + .getName()) + .add("writeConcern", settings.getWriteConcern()) .toString(); } /** * Returns {@code true} if the given {@code uri} has a write concern set. + * * @param uri the URI to check. - * @return {@code true} if the URI has a write concern set, {@code false} - * otherwise. + * @return {@code true} if the URI has a write concern set, {@code false} otherwise. */ - public static boolean hasWriteConcern(@NotNull String uri) { - MongoClientOptions.Builder builder = MongoClientOptions.builder(); - builder.writeConcern(WC_UNKNOWN); - WriteConcern wc = new MongoClientURI(requireNonNull(uri), builder) - .getOptions().getWriteConcern(); - return !WC_UNKNOWN.equals(wc); + public static boolean hasMongoDbDefaultWriteConcern(@NotNull String uri) { + ConnectionString connectionString = new ConnectionString(requireNonNull(uri)); + MongoClientSettings.Builder builder = MongoClientSettings.builder() + .applyConnectionString(connectionString); + MongoClientSettings settings = builder.build(); + + // ACKNOWLEDGE is the default of MongoClientSettings.Builder while the default of ConnectionString would be UNACKNOWLEDGED + return WriteConcern.ACKNOWLEDGED.equals(settings.getWriteConcern()); } /** @@ -195,9 +214,12 @@ public static boolean hasWriteConcern(@NotNull String uri) { * otherwise. */ public static boolean hasReadConcern(@NotNull String uri) { - ReadConcern rc = new MongoClientURI(requireNonNull(uri)) - .getOptions().getReadConcern(); - return readConcernLevel(rc) != null; + ConnectionString connectionString = new ConnectionString(requireNonNull(uri)); + MongoClientSettings.Builder builder = MongoClientSettings.builder() + .applyConnectionString(connectionString); + MongoClientSettings settings = builder.build(); + + return readConcernLevel(settings.getReadConcern()) != null; } /** @@ -211,13 +233,13 @@ public static boolean hasReadConcern(@NotNull String uri) { * @return the default write concern to use for Oak. */ public static WriteConcern getDefaultWriteConcern(@NotNull MongoClient client) { - WriteConcern w; - if (client.getReplicaSetStatus() != null) { - w = WriteConcern.MAJORITY; + ClusterDescription clusterDescription = client.getClusterDescription(); + + if (clusterDescription.getType() == ClusterType.REPLICA_SET) { + return WriteConcern.MAJORITY; } else { - w = WriteConcern.ACKNOWLEDGED; + return WriteConcern.ACKNOWLEDGED; } - return w; } /** @@ -233,7 +255,10 @@ public static WriteConcern getDefaultWriteConcern(@NotNull MongoClient client) { public static ReadConcern getDefaultReadConcern(@NotNull MongoClient client, @NotNull MongoDatabase db) { ReadConcern r; - if (requireNonNull(client).getReplicaSetStatus() != null && isMajorityWriteConcern(db)) { + + ClusterDescription clusterDescription = requireNonNull(client).getClusterDescription(); + + if (clusterDescription.getType() == ClusterType.REPLICA_SET && isMajorityWriteConcern(db)) { r = ReadConcern.MAJORITY; } else { r = ReadConcern.LOCAL; @@ -276,7 +301,9 @@ public static boolean isSufficientWriteConcern(@NotNull MongoClient client, throw new IllegalArgumentException( "Unknown write concern: " + wc); } - if (client.getReplicaSetStatus() != null) { + + ClusterDescription clusterDescription = client.getClusterDescription(); + if (clusterDescription.getType() == ClusterType.REPLICA_SET) { return w >= 2; } else { return w >= 1; @@ -295,7 +322,8 @@ public static boolean isSufficientWriteConcern(@NotNull MongoClient client, public static boolean isSufficientReadConcern(@NotNull MongoClient client, @NotNull ReadConcern rc) { ReadConcernLevel r = readConcernLevel(requireNonNull(rc)); - if (client.getReplicaSetStatus() == null) { + ClusterDescription clusterDescription = client.getClusterDescription(); + if (clusterDescription.getType() != ClusterType.REPLICA_SET) { return true; } else { return Objects.nonNull(r) && REPLICA_RC.contains(r); diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/fixture/DocumentMongoFixture.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/fixture/DocumentMongoFixture.java index e87f76ffb04..9fe3d24980a 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/fixture/DocumentMongoFixture.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/fixture/DocumentMongoFixture.java @@ -1,19 +1,12 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work + * for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations * under the License. */ @@ -22,7 +15,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; - import org.apache.jackrabbit.oak.plugins.document.DocumentMK; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; import org.apache.jackrabbit.oak.plugins.document.MongoUtils; @@ -33,9 +25,10 @@ import org.junit.AssumptionViolatedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import com.mongodb.MongoClient; -import com.mongodb.MongoClientURI; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoDatabase; public class DocumentMongoFixture extends NodeStoreFixture { @@ -71,7 +64,7 @@ public NodeStore createNodeStore() { } builder.setPersistentCache("target/persistentCache,time"); builder.setMongoDB(createClient(), getDBName(suffix)); - //do not reuse the whiteboard + // do not reuse the whiteboard setWhiteboard(new DefaultWhiteboard()); builder.setNoChildOrderCleanupFeature(Feature.newFeature("FT_NOCOCLEANUP_OAK-10660", getWhiteboard())); DocumentNodeStore ns = builder.getNodeStore(); @@ -83,11 +76,11 @@ public NodeStore createNodeStore() { } protected MongoClient createClient() { - return new MongoClient(new MongoClientURI(uri)); + return MongoClients.create(uri); } protected String getDBName(String suffix) { - String dbName = new MongoClientURI(uri).getDatabase(); + String dbName = new ConnectionString(uri).getDatabase(); return dbName + "-" + suffix; } @@ -110,7 +103,8 @@ public void dispose(NodeStore nodeStore) { String suffix = suffixes.remove(nodeStore); if (suffix != null) { try (MongoClient client = createClient()) { - client.dropDatabase(getDBName(suffix)); + MongoDatabase database = client.getDatabase(getDBName(suffix)); + database.drop(); } catch (Exception e) { log.error("Can't close Mongo", e); } @@ -121,4 +115,4 @@ public void dispose(NodeStore nodeStore) { public String toString() { return "DocumentNodeStore[Mongo] on " + this.uri; } -} \ No newline at end of file +} diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java index 0a0b45a06ab..e081d792839 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java @@ -1,22 +1,16 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work + * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations + * under the License. */ package org.apache.jackrabbit.oak.plugins.document; -import com.mongodb.MongoClient; import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; import org.apache.jackrabbit.oak.stats.Clock; @@ -25,11 +19,11 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; +import com.mongodb.client.MongoClient; /** - * Base class for test cases that need a {@link MongoConnection} - * to a clean test database. Tests in subclasses are automatically - * skipped if the configured MongoDB connection can not be created. + * Base class for test cases that need a {@link MongoConnection} to a clean test database. Tests in subclasses are automatically skipped if the + * configured MongoDB connection can not be created. */ public abstract class AbstractMongoConnectionTest extends DocumentMKTestBase { @@ -63,7 +57,8 @@ protected void setClusterNodeInfoClock(Clock c) { } protected DocumentMK.Builder newBuilder(MongoClient client, String dbName) throws Exception { - return addToBuilder(new DocumentMK.Builder()).clock(getTestClock()).setMongoDB(client, dbName); + return addToBuilder(new DocumentMK.Builder()).clock(getTestClock()) + .setMongoDB(client, dbName); } protected DocumentMK.Builder addToBuilder(DocumentMK.Builder mk) { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BlobThroughPutTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BlobThroughPutTest.java index cac59c145cd..c5084c84de8 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BlobThroughPutTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BlobThroughPutTest.java @@ -16,6 +16,8 @@ */ package org.apache.jackrabbit.oak.plugins.document; +import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount; +import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; @@ -26,23 +28,19 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; - import org.apache.commons.collections4.bidimap.DualHashBidiMap; import org.apache.jackrabbit.guava.common.io.ByteStreams; +import org.junit.Ignore; +import org.junit.Test; import com.mongodb.BasicDBObject; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientURI; +import com.mongodb.ConnectionString; import com.mongodb.WriteConcern; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Filters; -import org.junit.Ignore; -import org.junit.Test; - -import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount; -import static org.junit.Assert.assertNotNull; - public class BlobThroughPutTest { private static final int NO_OF_NODES = 100; private static final int BLOB_SIZE = 1024 * 1024 * 2; @@ -60,13 +58,11 @@ public class BlobThroughPutTest { static { Map bimap = new DualHashBidiMap(); - bimap.put(WriteConcern.FSYNC_SAFE,"FSYNC_SAFE"); - bimap.put(WriteConcern.JOURNAL_SAFE,"JOURNAL_SAFE"); + bimap.put(WriteConcern.JOURNALED,"JOURNALED"); // bimap.put(WriteConcern.MAJORITY,"MAJORITY"); bimap.put(WriteConcern.UNACKNOWLEDGED,"UNACKNOWLEDGED"); - bimap.put(WriteConcern.NORMAL,"NORMAL"); // bimap.put(WriteConcern.REPLICAS_SAFE,"REPLICAS_SAFE"); - bimap.put(WriteConcern.SAFE,"SAFE"); + bimap.put(WriteConcern.ACKNOWLEDGED,"ACKNOWLEDGED"); namedConcerns = Collections.unmodifiableMap(bimap); } @@ -76,8 +72,11 @@ public class BlobThroughPutTest { @Ignore @Test public void performBenchMark() throws InterruptedException { - MongoClient local = new MongoClient(new MongoClientURI(localServer)); - MongoClient remote = new MongoClient(new MongoClientURI(remoteServer)); + ConnectionString localServerConnectionString = new ConnectionString(localServer); + MongoClient local = MongoClients.create(localServerConnectionString); + + ConnectionString remoteServerConnectionString = new ConnectionString(remoteServer); + MongoClient remote = MongoClients.create(remoteServerConnectionString); run(local, false, false); run(local, true, false); @@ -90,7 +89,8 @@ public void performBenchMark() throws InterruptedException { @Ignore @Test public void performBenchMark_WriteConcern() throws InterruptedException { - MongoClient mongo = new MongoClient(new MongoClientURI(remoteServer)); + ConnectionString remoteServerConnectionString = new ConnectionString(remoteServer); + MongoClient mongo = MongoClients.create(remoteServerConnectionString); final MongoDatabase db = mongo.getDatabase(TEST_DB1); final MongoCollection nodes = db.getCollection("nodes", BasicDBObject.class); final MongoCollection blobs = db.getCollection("blobs", BasicDBObject.class); @@ -128,7 +128,7 @@ private void run(MongoClient mongo, boolean useSameDB, boolean remote) throws In for (int writers : WRITERS) { prepareDB(nodes, blobs); final Benchmark b = new Benchmark(nodes, blobs); - Result r = b.run(readers, writers, remote, WriteConcern.SAFE); + Result r = b.run(readers, writers, remote, WriteConcern.ACKNOWLEDGED); results.add(r); } } diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTest.java index 30ae23a7029..d379cf803f0 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTest.java @@ -16,10 +16,13 @@ */ package org.apache.jackrabbit.oak.plugins.document; +import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.Map; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; - +import org.apache.jackrabbit.guava.common.collect.Maps; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.apache.jackrabbit.oak.spi.state.NodeState; @@ -27,16 +30,10 @@ import org.jetbrains.annotations.Nullable; import org.junit.Before; import org.junit.Test; - -import org.apache.jackrabbit.guava.common.collect.Maps; import com.mongodb.DBObject; -import com.mongodb.MongoClient; +import com.mongodb.client.MongoClient; import com.mongodb.client.MongoDatabase; -import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - /** * Test for OAK-1897 */ diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterInfoTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterInfoTest.java index 9d9f50a85ed..ee8df05b346 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterInfoTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterInfoTest.java @@ -22,15 +22,12 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; - import java.util.List; - import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfo.ClusterNodeState; import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore; import org.apache.jackrabbit.oak.stats.Clock; import org.junit.After; import org.junit.Test; - import com.mongodb.ReadPreference; import com.mongodb.WriteConcern; @@ -89,11 +86,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"); mem.findAndUpdate(Collection.CLUSTER_NODES, op); ns1.renewClusterIdLease(); assertEquals(ReadPreference.nearest(), mem.getReadPreference()); - assertEquals(WriteConcern.FSYNCED, mem.getWriteConcern()); + assertEquals(WriteConcern.W2, mem.getWriteConcern()); ns1.dispose(); ns2.dispose(); diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentPrefetchAndUpdateIT.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentPrefetchAndUpdateIT.java index 9645ec0c014..64ea514dfbc 100755 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentPrefetchAndUpdateIT.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentPrefetchAndUpdateIT.java @@ -16,17 +16,15 @@ */ package org.apache.jackrabbit.oak.plugins.document; +import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; import java.util.concurrent.atomic.AtomicLong; - import org.apache.jackrabbit.guava.common.collect.Lists; -import com.mongodb.DBObject; -import com.mongodb.MongoClient; -import com.mongodb.client.MongoDatabase; - import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.jetbrains.annotations.NotNull; @@ -34,10 +32,9 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; - -import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import com.mongodb.DBObject; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoDatabase; public class ConcurrentPrefetchAndUpdateIT extends AbstractMongoConnectionTest { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java index 7cf6d9a9fd8..40d1213dab9 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java @@ -16,18 +16,16 @@ */ package org.apache.jackrabbit.oak.plugins.document; -import org.apache.jackrabbit.guava.common.collect.Iterables; -import com.mongodb.MongoClient; - -import org.apache.jackrabbit.oak.cache.CacheStats; -import org.junit.Test; - import static org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_CHILDREN_CACHE_PERCENTAGE; import static org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_DIFF_CACHE_PERCENTAGE; import static org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_NODE_CACHE_PERCENTAGE; import static org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_PREV_DOC_CACHE_PERCENTAGE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import org.apache.jackrabbit.guava.common.collect.Iterables; +import org.apache.jackrabbit.oak.cache.CacheStats; +import org.junit.Test; +import com.mongodb.client.MongoClient; public class DocumentMKBuilderTest extends AbstractMongoConnectionTest { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java index c0fb2299efa..b9f060fb549 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java @@ -16,18 +16,22 @@ */ package org.apache.jackrabbit.oak.plugins.document; +import static org.apache.jackrabbit.oak.plugins.document.Configuration.PID; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; +import static org.mockito.Mockito.mock; import java.io.File; import java.lang.reflect.Field; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; - -import org.apache.jackrabbit.guava.common.collect.Maps; -import com.mongodb.MongoClient; - import org.apache.commons.io.FilenameUtils; +import org.apache.jackrabbit.guava.common.collect.Maps; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStoreTestHelper; import org.apache.jackrabbit.oak.plugins.document.spi.JournalPropertyService; import org.apache.jackrabbit.oak.plugins.document.spi.lease.LeaseFailureHandler; import org.apache.jackrabbit.oak.spi.state.NodeStore; @@ -41,15 +45,6 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; -import static org.apache.jackrabbit.oak.plugins.document.Configuration.PID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; -import static org.mockito.Mockito.mock; - public class DocumentNodeStoreServiceTest { @Rule @@ -150,18 +145,6 @@ public void setUpdateLimit() throws Exception { assertEquals(17, store.getUpdateLimit()); } - @Test - public void keepAlive() throws Exception { - Map config = newConfig(repoHome); - config.put(DocumentNodeStoreServiceConfiguration.PROP_SO_KEEP_ALIVE, true); - MockOsgi.setConfigForPid(context.bundleContext(), PID, config); - MockOsgi.activate(service, context.bundleContext()); - DocumentNodeStore store = context.getService(DocumentNodeStore.class); - MongoDocumentStore mds = getMongoDocumentStore(store); - MongoClient client = MongoDocumentStoreTestHelper.getClient(mds); - assertTrue(client.getMongoClientOptions().isSocketKeepAlive()); - } - @Test public void continuousRGCDefault() throws Exception { Map config = newConfig(repoHome); @@ -217,8 +200,6 @@ public void preset() throws Exception { DocumentNodeStore store = context.getService(DocumentNodeStore.class); MongoDocumentStore mds = getMongoDocumentStore(store); assertNotNull(mds); - MongoClient client = MongoDocumentStoreTestHelper.getClient(mds); - assertTrue(client.getMongoClientOptions().isSocketKeepAlive()); } @Test @@ -233,11 +214,6 @@ public void presetOverride() throws Exception { MockOsgi.setConfigForPid(context.bundleContext(), PID, config); MockOsgi.activate(service, context.bundleContext()); - - DocumentNodeStore store = context.getService(DocumentNodeStore.class); - MongoDocumentStore mds = getMongoDocumentStore(store); - MongoClient client = MongoDocumentStoreTestHelper.getClient(mds); - assertFalse(client.getMongoClientOptions().isSocketKeepAlive()); } @Test diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoDbTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoDbTest.java index fbe09d223fe..a8dbbde41c0 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoDbTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoDbTest.java @@ -18,13 +18,12 @@ import java.util.ArrayList; import java.util.List; - import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; import org.bson.conversions.Bson; import org.junit.Ignore; import org.junit.Test; - import com.mongodb.BasicDBObject; +import com.mongodb.ExplainVerbosity; import com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; @@ -199,9 +198,9 @@ public void updateDocument() { c.close(); } - private static BasicDBObject explain(MongoCollection collection, + private static org.bson.Document explain(MongoCollection collection, Bson query) { - return collection.find(query).modifiers(new BasicDBObject("$explain", true)).first(); + return collection.find(query).explain(ExplainVerbosity.QUERY_PLANNER); } private static void log(String msg) { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java index 0e44843ec40..6a1014a79e2 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java @@ -1,18 +1,13 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work + * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations + * under the License. */ package org.apache.jackrabbit.oak.plugins.document; @@ -20,22 +15,18 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; - import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDockerRule; import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; import org.junit.runner.Description; import org.junit.runners.model.Statement; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import com.mongodb.BasicDBObject; -import com.mongodb.DB; -import com.mongodb.MongoClientURI; +import com.mongodb.ConnectionString; import com.mongodb.client.MongoDatabase; /** - * A utility class to get a {@link MongoConnection} to a local mongo instance - * and clean a test database. + * A utility class to get a {@link MongoConnection} to a local mongo instance and clean a test database. */ public class MongoUtils { @@ -80,7 +71,8 @@ public void evaluate() { host.set(dockerRule.getHost()); port.set(dockerRule.getPort()); } - }, Description.EMPTY).evaluate(); + }, Description.EMPTY) + .evaluate(); mongoUrl = "mongodb://" + host + ":" + port.get() + "/" + DB + "?" + OPTIONS; } catch (Throwable t) { LOG.warn("Unable to get MongoDB port from Docker", t); @@ -105,28 +97,30 @@ public static MongoConnection getConnection() { * @return the connection or null */ public static MongoConnection getConnection(String dbName) { - MongoClientURI clientURI; + ConnectionString connectionString; try { - clientURI = new MongoClientURI(URL); + connectionString = new ConnectionString(URL); } catch (IllegalArgumentException e) { - // configured URL is invalid return null; } + StringBuilder uri = new StringBuilder("mongodb://"); String separator = ""; - for (String host : clientURI.getHosts()) { + for (String host : connectionString.getHosts()) { uri.append(separator); separator = ","; uri.append(host); } - uri.append("/").append(dbName).append("?").append(OPTIONS); + uri.append("/") + .append(dbName) + .append("?") + .append(OPTIONS); return getConnectionByURL(uri.toString()); } /** - * Drop all user defined collections in the given database. System - * collections are not dropped. This method returns silently if MongoDB is - * not available. + * Drop all user defined collections in the given database. System collections are not dropped. This method returns silently if MongoDB is not + * available. * * @param dbName the database name. */ @@ -142,20 +136,6 @@ public static void dropCollections(String dbName) { } } - /** - * Drop all user defined collections. System collections are not dropped. - * - * @param db the connection - * @deprecated use {@link #dropCollections(MongoDatabase)} instead. - */ - public static void dropCollections(DB db) { - for (String name : db.getCollectionNames()) { - if (!name.startsWith("system.")) { - db.getCollection(name).drop(); - } - } - } - /** * Drop all user defined collections. System collections are not dropped. * @@ -164,14 +144,14 @@ public static void dropCollections(DB db) { public static void dropCollections(MongoDatabase db) { for (String name : db.listCollectionNames()) { if (!name.startsWith("system.")) { - db.getCollection(name).drop(); + db.getCollection(name) + .drop(); } } } /** - * Drops the database with the given name. This method returns silently if - * MongoDB is not available. + * Drops the database with the given name. This method returns silently if MongoDB is not available. * * @param dbName the name of the database to drop. */ @@ -181,7 +161,8 @@ public static void dropDatabase(String dbName) { return; } try { - c.getDatabase().drop(); + c.getDatabase() + .drop(); } finally { c.close(); } @@ -201,7 +182,7 @@ public static boolean isAvailable() { } } - //----------------------------< internal >---------------------------------- + // ----------------------------< internal >---------------------------------- /** * Get a connection if available. If not available, null is returned. @@ -216,7 +197,8 @@ private static MongoConnection getConnectionByURL(String url) { MongoConnection mongoConnection; try { mongoConnection = new MongoConnection(url); - mongoConnection.getDatabase().runCommand(new BasicDBObject("ping", 1)); + mongoConnection.getDatabase() + .runCommand(new BasicDBObject("ping", 1)); // dropCollections(mongoConnection.getDB()); } catch (Exception e) { exceptions.put(url, e); diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCSupportTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCSupportTest.java index 73044b74d43..e4f188e2d27 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCSupportTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCSupportTest.java @@ -18,27 +18,6 @@ */ package org.apache.jackrabbit.oak.plugins.document; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.stream.StreamSupport; - -import com.mongodb.ReadPreference; - -import org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture.RDBFixture; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoTestUtils; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport; -import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore; -import org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions; -import org.apache.jackrabbit.oak.plugins.document.rdb.RDBVersionGCSupport; -import org.apache.jackrabbit.oak.plugins.document.util.Utils; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - import static java.lang.Long.MAX_VALUE; import static java.util.Comparator.comparing; import static java.util.List.of; @@ -59,6 +38,24 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.stream.StreamSupport; +import org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture.RDBFixture; +import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; +import org.apache.jackrabbit.oak.plugins.document.mongo.MongoTestUtils; +import org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport; +import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore; +import org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions; +import org.apache.jackrabbit.oak.plugins.document.rdb.RDBVersionGCSupport; +import org.apache.jackrabbit.oak.plugins.document.util.Utils; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import com.mongodb.ReadPreference; @RunWith(Parameterized.class) public class VersionGCSupportTest { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/AcquireRecoveryLockTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/AcquireRecoveryLockTest.java index db79a5dc0d7..068631a8182 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/AcquireRecoveryLockTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/AcquireRecoveryLockTest.java @@ -16,10 +16,12 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeNotNull; import java.util.List; - -import com.mongodb.MongoClient; - import org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest; import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfo; import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfoDocument; @@ -30,12 +32,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; - -import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeNotNull; +import com.mongodb.client.MongoClient; public class AcquireRecoveryLockTest extends AbstractMongoConnectionTest { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ClusterConflictTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ClusterConflictTest.java index 182c2fa6e29..131db01d21f 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ClusterConflictTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ClusterConflictTest.java @@ -16,8 +16,9 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import com.mongodb.MongoClient; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest; @@ -33,9 +34,7 @@ import org.apache.jackrabbit.oak.spi.state.NodeStore; import org.jetbrains.annotations.NotNull; import org.junit.Test; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import com.mongodb.client.MongoClient; public class ClusterConflictTest extends AbstractMongoConnectionTest { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoConnectionTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoConnectionTest.java index e5a51920456..18523abd898 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoConnectionTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoConnectionTest.java @@ -16,29 +16,25 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientOptions; -import com.mongodb.ReadConcern; -import com.mongodb.ReplicaSetStatus; -import com.mongodb.WriteConcern; - -import org.apache.jackrabbit.oak.plugins.document.MongoUtils; -import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; +import org.junit.Test; +import com.mongodb.ReadConcern; +import com.mongodb.WriteConcern; +import com.mongodb.client.MongoClient; +import com.mongodb.connection.ClusterDescription; +import com.mongodb.connection.ClusterType; public class MongoConnectionTest { @Test public void hasWriteConcern() throws Exception { - assertFalse(MongoConnection.hasWriteConcern("mongodb://localhost:27017/foo")); - assertTrue(MongoConnection.hasWriteConcern("mongodb://localhost:27017/foo?w=1")); + assertTrue(MongoConnection.hasMongoDbDefaultWriteConcern("mongodb://localhost:27017/foo")); + assertFalse(MongoConnection.hasMongoDbDefaultWriteConcern("mongodb://localhost:27017/foo?w=1")); } @Test @@ -52,25 +48,13 @@ public void sufficientWriteConcern() throws Exception { sufficientWriteConcernReplicaSet(WriteConcern.ACKNOWLEDGED, false); sufficientWriteConcernReplicaSet(WriteConcern.JOURNALED, false); sufficientWriteConcernReplicaSet(WriteConcern.MAJORITY, true); - sufficientWriteConcernReplicaSet(WriteConcern.FSYNC_SAFE, false); - sufficientWriteConcernReplicaSet(WriteConcern.FSYNCED, false); - sufficientWriteConcernReplicaSet(WriteConcern.JOURNAL_SAFE, false); - sufficientWriteConcernReplicaSet(WriteConcern.NORMAL, false); - sufficientWriteConcernReplicaSet(WriteConcern.REPLICA_ACKNOWLEDGED, true); - sufficientWriteConcernReplicaSet(WriteConcern.REPLICAS_SAFE, true); - sufficientWriteConcernReplicaSet(WriteConcern.SAFE, false); + sufficientWriteConcernReplicaSet(WriteConcern.W2, true); sufficientWriteConcernReplicaSet(WriteConcern.UNACKNOWLEDGED, false); sufficientWriteConcernSingleNode(WriteConcern.ACKNOWLEDGED, true); sufficientWriteConcernSingleNode(WriteConcern.JOURNALED, true); sufficientWriteConcernSingleNode(WriteConcern.MAJORITY, true); - sufficientWriteConcernSingleNode(WriteConcern.FSYNC_SAFE, true); - sufficientWriteConcernSingleNode(WriteConcern.FSYNCED, true); - sufficientWriteConcernSingleNode(WriteConcern.JOURNAL_SAFE, true); - sufficientWriteConcernSingleNode(WriteConcern.NORMAL, false); - sufficientWriteConcernSingleNode(WriteConcern.REPLICA_ACKNOWLEDGED, true); - sufficientWriteConcernSingleNode(WriteConcern.REPLICAS_SAFE, true); - sufficientWriteConcernSingleNode(WriteConcern.SAFE, true); + sufficientWriteConcernReplicaSet(WriteConcern.W2, true); sufficientWriteConcernSingleNode(WriteConcern.UNACKNOWLEDGED, false); } @@ -85,26 +69,6 @@ public void sufficientReadConcern() throws Exception { sufficientReadConcernSingleNode(ReadConcern.MAJORITY, true); } - @Test - public void socketKeepAlive() throws Exception { - assumeTrue(MongoUtils.isAvailable()); - MongoClientOptions.Builder options = MongoConnection.getDefaultBuilder(); - options.socketKeepAlive(false); - MongoConnection c = new MongoConnection(MongoUtils.URL, options); - try { - assertFalse(c.getMongoClient().getMongoClientOptions().isSocketKeepAlive()); - } finally { - c.close(); - } - // default is with keep-alive (starting with 3.6 driver) - c = new MongoConnection(MongoUtils.URL); - try { - assertTrue(c.getMongoClient().getMongoClientOptions().isSocketKeepAlive()); - } finally { - c.close(); - } - } - private void sufficientWriteConcernReplicaSet(WriteConcern w, boolean sufficient) { sufficientWriteConcern(w, true, sufficient); @@ -139,14 +103,15 @@ private void sufficientReadConcern(ReadConcern r, } private MongoClient mockMongoClient(boolean replicaSet) { - ReplicaSetStatus status; + ClusterDescription description = mock(ClusterDescription.class); if (replicaSet) { - status = mock(ReplicaSetStatus.class); + when(description.getType()).thenReturn(ClusterType.REPLICA_SET); } else { - status = null; + when(description.getType()).thenReturn(ClusterType.STANDALONE); } MongoClient client = mock(MongoClient.class); - when(client.getReplicaSetStatus()).thenReturn(status); + when(client.getClusterDescription()).thenReturn(description); + return client; } } diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConfigTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConfigTest.java index de6646d98f0..114bf607987 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConfigTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConfigTest.java @@ -16,22 +16,19 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import com.mongodb.BasicDBObject; -import com.mongodb.MongoClient; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.COLLECTION_COMPRESSION_TYPE; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.STORAGE_CONFIG; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.STORAGE_ENGINE; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.getCollectionStorageOptions; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import java.util.Collections; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.CollectionCompressor; import org.bson.BsonDocument; import org.bson.conversions.Bson; import org.junit.Test; - -import java.util.Collections; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.getCollectionStorageOptions; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.COLLECTION_COMPRESSION_TYPE; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.STORAGE_CONFIG; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.STORAGE_ENGINE; +import com.mongodb.BasicDBObject; +import com.mongodb.MongoClientSettings; public class MongoDBConfigTest { @@ -39,7 +36,7 @@ public class MongoDBConfigTest { @Test public void defaultCollectionStorageOptions() { Bson bson = getCollectionStorageOptions(Collections.emptyMap()); - BsonDocument bsonDocument = bson.toBsonDocument(BasicDBObject.class, MongoClient.getDefaultCodecRegistry()); + BsonDocument bsonDocument = bson.toBsonDocument(BasicDBObject.class, MongoClientSettings.getDefaultCodecRegistry()); String configuredCompressor = bsonDocument.getDocument(STORAGE_ENGINE).getString(STORAGE_CONFIG).getValue(); assertTrue(configuredCompressor.indexOf(CollectionCompressor.SNAPPY.getName()) > 0); @@ -54,7 +51,7 @@ public void invalidCollectionStorageOptions() { @Test public void overrideDefaultCollectionStorageOptions() { Bson bson = getCollectionStorageOptions(Collections.singletonMap(COLLECTION_COMPRESSION_TYPE, "zstd")); - BsonDocument bsonDocument = bson.toBsonDocument(BasicDBObject.class, MongoClient.getDefaultCodecRegistry()); + BsonDocument bsonDocument = bson.toBsonDocument(BasicDBObject.class, MongoClientSettings.getDefaultCodecRegistry()); String configuredCompressor = bsonDocument.getDocument(STORAGE_ENGINE).getString(STORAGE_CONFIG).getValue(); assertTrue(configuredCompressor.indexOf(CollectionCompressor.ZSTD.getName()) > 0); diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java index 5dbe01d66b6..52754f6b2bd 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java @@ -1,21 +1,26 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work + * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations + * under the License. */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static java.util.Collections.singletonList; +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.apache.jackrabbit.oak.commons.junit.LogCustomizer; import org.apache.jackrabbit.oak.plugins.document.Collection; import org.apache.jackrabbit.oak.plugins.document.DocumentMK; import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException; @@ -25,24 +30,12 @@ import org.apache.jackrabbit.oak.plugins.document.Revision; import org.apache.jackrabbit.oak.plugins.document.UpdateOp; import org.apache.jackrabbit.oak.plugins.document.util.Utils; -import org.apache.jackrabbit.oak.commons.junit.LogCustomizer; import org.junit.After; import org.junit.Assume; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static java.util.Collections.singletonList; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assert.assertFalse; - public class MongoDBExceptionTest { private MongoDocumentStore store; @@ -83,9 +76,11 @@ public void idInExceptionMessage() { store.findAndUpdate(Collection.NODES, op); fail("DocumentStoreException expected"); } catch (DocumentStoreException e) { - assertTrue(e.getMessage().contains(exceptionMsg)); + assertTrue(e.getMessage() + .contains(exceptionMsg)); assertTrue("Exception message does not contain id: '" + e.getMessage() + "'", - e.getMessage().contains(id)); + e.getMessage() + .contains(id)); } exceptionMsg = "createOrUpdate failed"; @@ -94,9 +89,11 @@ public void idInExceptionMessage() { store.createOrUpdate(Collection.NODES, op); fail("DocumentStoreException expected"); } catch (DocumentStoreException e) { - assertTrue(e.getMessage().contains(exceptionMsg)); + assertTrue(e.getMessage() + .contains(exceptionMsg)); assertTrue("Exception message does not contain id: '" + e.getMessage() + "'", - e.getMessage().contains(id)); + e.getMessage() + .contains(id)); } exceptionMsg = "createOrUpdate (multiple) failed"; @@ -105,9 +102,11 @@ public void idInExceptionMessage() { store.createOrUpdate(Collection.NODES, singletonList(op)); fail("DocumentStoreException expected"); } catch (DocumentStoreException e) { - assertTrue(e.getMessage().contains(exceptionMsg)); + assertTrue(e.getMessage() + .contains(exceptionMsg)); assertTrue("Exception message does not contain id: '" + e.getMessage() + "'", - e.getMessage().contains(id)); + e.getMessage() + .contains(id)); } exceptionMsg = "find failed"; @@ -118,7 +117,8 @@ public void idInExceptionMessage() { } catch (DocumentStoreException e) { assertThat(e.getMessage(), containsString(exceptionMsg)); assertTrue("Exception message does not contain id: '" + e.getMessage() + "'", - e.getMessage().contains(id)); + e.getMessage() + .contains(id)); } Path foo = Path.fromString("/foo"); @@ -132,15 +132,18 @@ public void idInExceptionMessage() { } catch (DocumentStoreException e) { assertThat(e.getMessage(), containsString(exceptionMsg)); assertTrue("Exception message does not contain id: '" + e.getMessage() + "'", - e.getMessage().contains(fromKey)); + e.getMessage() + .contains(fromKey)); assertTrue("Exception message does not contain id: '" + e.getMessage() + "'", - e.getMessage().contains(toKey)); + e.getMessage() + .contains(toKey)); } } @Test public void createOrUpdate16MBDoc() { - LogCustomizer customizer = LogCustomizer.forLogger(MongoDocumentStore.class.getName()).create(); + LogCustomizer customizer = LogCustomizer.forLogger(MongoDocumentStore.class.getName()) + .create(); customizer.starting(); String id = "/foo"; UpdateOp updateOp = new UpdateOp(id, true); @@ -151,7 +154,8 @@ public void createOrUpdate16MBDoc() { fail("DocumentStoreException expected"); } catch (DocumentStoreException e) { assertThat(e.getMessage(), containsString(exceptionMsg)); - String log = customizer.getLogs().toString(); + String log = customizer.getLogs() + .toString(); assertTrue("Message doesn't contain the id", log.contains(id)); } customizer.finished(); @@ -179,7 +183,8 @@ public void update16MBDoc() { public void multiCreateOrUpdate16MBDoc() { List updateOps = new ArrayList<>(); - LogCustomizer customizer = LogCustomizer.forLogger(MongoDocumentStore.class.getName()).create(); + LogCustomizer customizer = LogCustomizer.forLogger(MongoDocumentStore.class.getName()) + .create(); customizer.starting(); String id1 = "/test"; String id2 = "/foo"; @@ -203,7 +208,8 @@ public void multiCreateOrUpdate16MBDoc() { fail("DocumentStoreException expected"); } catch (DocumentStoreException e) { assertThat(e.getMessage(), containsString(exceptionMsg)); - String log = customizer.getLogs().toString(); + String log = customizer.getLogs() + .toString(); assertTrue("Message doesn't contain the id", log.contains(id1)); } customizer.finished(); @@ -213,7 +219,8 @@ public void multiCreateOrUpdate16MBDoc() { public void create16MBDoc() { List updateOps = new ArrayList<>(); - LogCustomizer customizer = LogCustomizer.forLogger(MongoDocumentStore.class.getName()).create(); + LogCustomizer customizer = LogCustomizer.forLogger(MongoDocumentStore.class.getName()) + .create(); customizer.starting(); String id1 = "/test"; String id2 = "/foo"; @@ -227,7 +234,8 @@ public void create16MBDoc() { updateOps.add(op1); updateOps.add(op2); assertFalse(store.create(Collection.NODES, updateOps)); - String log = customizer.getLogs().toString(); + String log = customizer.getLogs() + .toString(); assertTrue("Message doesn't contain the id", log.contains(id2)); } @@ -245,7 +253,7 @@ public void findAndUpdate16MBDoc() throws Exception { } catch (DocumentStoreException e) { assertThat(e.getMessage(), containsString(exceptionMsg)); assertThat(e.getMessage(), containsString(id)); - } + } } private void setExceptionMsg() { @@ -263,11 +271,11 @@ private UpdateOp create1MBProp(UpdateOp op) { private UpdateOp create16MBProp(UpdateOp op) { // create a 1 MB property String content = create1MBContent(); - - //create 16MB property + + // create 16MB property for (int i = 0; i < 16; i++) { - op.set("property"+ i, content); + op.set("property" + i, content); } return op; } diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreTestHelper.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreTestHelper.java index 11e547e4644..bedf0bad776 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreTestHelper.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreTestHelper.java @@ -16,7 +16,7 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import com.mongodb.MongoClient; +import com.mongodb.client.MongoClient; import com.mongodb.client.MongoDatabase; public final class MongoDocumentStoreTestHelper { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatusTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatusTest.java index dc1a90e4e66..0d9bdfd1d52 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatusTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatusTest.java @@ -1,30 +1,24 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work + * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations + * under the License. */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static org.apache.jackrabbit.oak.plugins.document.MongoUtils.isAvailable; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; +import java.util.Iterator; import java.util.concurrent.atomic.AtomicReference; - -import com.mongodb.BasicDBObject; -import com.mongodb.MongoCommandException; -import com.mongodb.ReadPreference; -import com.mongodb.ServerAddress; -import com.mongodb.client.ClientSession; -import com.mongodb.client.MongoDatabase; - import org.apache.jackrabbit.oak.plugins.document.MongoConnectionFactory; import org.apache.jackrabbit.oak.plugins.document.MongoUtils; import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; @@ -39,13 +33,15 @@ import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; - -import static org.apache.jackrabbit.oak.plugins.document.MongoUtils.isAvailable; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; +import com.mongodb.BasicDBObject; +import com.mongodb.MongoClientSettings; +import com.mongodb.MongoCommandException; +import com.mongodb.ReadPreference; +import com.mongodb.ServerAddress; +import com.mongodb.client.ClientSession; +import com.mongodb.client.MongoDatabase; +import com.mongodb.connection.ClusterDescription; +import com.mongodb.connection.ServerDescription; public class MongoStatusTest { @@ -103,12 +99,13 @@ public void testReadConcern() { @Test public void testGetVersion() { - assertTrue(status.getVersion().matches("^\\d+\\.\\d+\\.\\d+$")); + assertTrue(status.getVersion() + .matches("^\\d+\\.\\d+\\.\\d+$")); } @Test public void testCheckVersionValid() { - for (String v : new String[] { "2.6.0", "2.7.0", "3.0.0"}) { + for (String v : new String[] {"2.6.0", "2.7.0", "3.0.0"}) { status.setVersion(v); status.checkVersion(); } @@ -116,7 +113,7 @@ public void testCheckVersionValid() { @Test public void testCheckVersionInvalid() { - for (String v : new String[] { "1.0.0", "2.0.0", "2.5.0"}) { + for (String v : new String[] {"1.0.0", "2.0.0", "2.5.0"}) { status.setVersion(v); try { status.checkVersion(); @@ -144,54 +141,54 @@ public void unauthorized() { @Override public @NotNull Document runCommand(@NotNull Bson command, - @NotNull ReadPreference readPreference) { + @NotNull ReadPreference readPreference) { unauthorizedIfServerStatus(command); return super.runCommand(command, readPreference); } @Override public @NotNull TResult runCommand(@NotNull Bson command, - @NotNull Class tResultClass) { + @NotNull Class tResultClass) { unauthorizedIfServerStatus(command); return super.runCommand(command, tResultClass); } @Override public @NotNull TResult runCommand(@NotNull Bson command, - @NotNull ReadPreference readPreference, - @NotNull Class tResultClass) { + @NotNull ReadPreference readPreference, + @NotNull Class tResultClass) { unauthorizedIfServerStatus(command); return super.runCommand(command, readPreference, tResultClass); } @Override public @NotNull Document runCommand(@NotNull ClientSession clientSession, - @NotNull Bson command) { + @NotNull Bson command) { unauthorizedIfServerStatus(command); return super.runCommand(clientSession, command); } @Override public @NotNull Document runCommand(@NotNull ClientSession clientSession, - @NotNull Bson command, - @NotNull ReadPreference readPreference) { + @NotNull Bson command, + @NotNull ReadPreference readPreference) { unauthorizedIfServerStatus(command); return super.runCommand(clientSession, command, readPreference); } @Override public @NotNull TResult runCommand(@NotNull ClientSession clientSession, - @NotNull Bson command, - @NotNull Class tResultClass) { + @NotNull Bson command, + @NotNull Class tResultClass) { unauthorizedIfServerStatus(command); return super.runCommand(clientSession, command, tResultClass); } @Override public @NotNull TResult runCommand(@NotNull ClientSession clientSession, - @NotNull Bson command, - @NotNull ReadPreference readPreference, - @NotNull Class tResultClass) { + @NotNull Bson command, + @NotNull ReadPreference readPreference, + @NotNull Class tResultClass) { unauthorizedIfServerStatus(command); return super.runCommand(clientSession, command, readPreference, tResultClass); } @@ -199,12 +196,22 @@ public void unauthorized() { } private void unauthorizedIfServerStatus(Bson command) { - if (command.toBsonDocument(BasicDBObject.class, getDefaultCodecRegistry()).containsKey("serverStatus")) { + if (command.toBsonDocument(BasicDBObject.class, MongoClientSettings.getDefaultCodecRegistry()) + .containsKey("serverStatus")) { BsonDocument response = new BsonDocument("ok", new BsonDouble(0.0)); response.put("errmsg", new BsonString("command serverStatus requires authentication")); response.put("code", new BsonInt32(13)); response.put("codeName", new BsonString("Unauthorized")); - ServerAddress address = getAddress(); + + ServerAddress address = null; + ClusterDescription clusterDescription = getClusterDescription(); + for (Iterator iterator = clusterDescription.getServerDescriptions().iterator(); iterator.hasNext();) { + ServerDescription serverDescription = iterator.next(); + + address = serverDescription.getAddress(); + break; + } + if (address == null) { // OAK-8459: use dummy/default address instead address = new ServerAddress(); diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoTestClient.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoTestClient.java index 28bc39e1c31..2f36610f0b2 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoTestClient.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoTestClient.java @@ -16,28 +16,45 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; - -import com.mongodb.MongoClient; -import com.mongodb.MongoClientURI; -import com.mongodb.client.MongoDatabase; - +import org.bson.Document; +import org.bson.codecs.configuration.CodecRegistry; +import org.bson.conversions.Bson; import org.jetbrains.annotations.NotNull; +import com.mongodb.ClientSessionOptions; +import com.mongodb.ConnectionString; +import com.mongodb.ReadConcern; +import com.mongodb.ReadPreference; +import com.mongodb.WriteConcern; +import com.mongodb.client.ChangeStreamIterable; +import com.mongodb.client.ClientSession; +import com.mongodb.client.ListDatabasesIterable; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCluster; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.MongoIterable; +import com.mongodb.connection.ClusterDescription; -class MongoTestClient extends MongoClient { +class MongoTestClient implements MongoClient { private AtomicReference beforeQueryException = new AtomicReference<>(); private AtomicReference beforeUpdateException = new AtomicReference<>(); private AtomicReference afterUpdateException = new AtomicReference<>(); + + private MongoClient delegate; MongoTestClient(String uri) { - super(new MongoClientURI(uri)); + ConnectionString connectionString = new ConnectionString(uri); + delegate = MongoClients.create(connectionString); } @NotNull @Override public MongoDatabase getDatabase(String databaseName) { - return new MongoTestDatabase(super.getDatabase(databaseName), + return new MongoTestDatabase(delegate.getDatabase(databaseName), beforeQueryException, beforeUpdateException, afterUpdateException); } @@ -52,4 +69,145 @@ void setExceptionBeforeUpdate(String msg) { void setExceptionAfterUpdate(String msg) { afterUpdateException.set(msg); } + + @Override + public CodecRegistry getCodecRegistry() { + return delegate.getCodecRegistry(); + } + + @Override + public ReadPreference getReadPreference() { + return delegate.getReadPreference(); + } + + @Override + public WriteConcern getWriteConcern() { + return delegate.getWriteConcern(); + } + + @Override + public ReadConcern getReadConcern() { + return delegate.getReadConcern(); + } + + @Override + public Long getTimeout(TimeUnit timeUnit) { + return delegate.getTimeout(timeUnit); + } + + @Override + public MongoCluster withCodecRegistry(CodecRegistry codecRegistry) { + return delegate.withCodecRegistry(codecRegistry); + } + + @Override + public MongoCluster withReadPreference(ReadPreference readPreference) { + return delegate.withReadPreference(readPreference); + } + + @Override + public MongoCluster withWriteConcern(WriteConcern writeConcern) { + return delegate.withWriteConcern(writeConcern); + } + + @Override + public MongoCluster withReadConcern(ReadConcern readConcern) { + return delegate.withReadConcern(readConcern); + } + + @Override + public MongoCluster withTimeout(long timeout, TimeUnit timeUnit) { + return delegate.withTimeout(timeout, timeUnit); + } + + @Override + public ClientSession startSession() { + return delegate.startSession(); + } + + @Override + public ClientSession startSession(ClientSessionOptions options) { + return delegate.startSession(options); + } + + @Override + public MongoIterable listDatabaseNames() { + return delegate.listDatabaseNames(); + } + + @Override + public MongoIterable listDatabaseNames(ClientSession clientSession) { + return delegate.listDatabaseNames(clientSession); + } + + @Override + public ListDatabasesIterable listDatabases() { + return delegate.listDatabases(); + } + + @Override + public ListDatabasesIterable listDatabases(ClientSession clientSession) { + return delegate.listDatabases(clientSession); + } + + @Override + public ListDatabasesIterable listDatabases(Class resultClass) { + return delegate.listDatabases(resultClass); + } + + @Override + public ListDatabasesIterable listDatabases(ClientSession clientSession, Class resultClass) { + return delegate.listDatabases(clientSession, resultClass); + } + + @Override + public ChangeStreamIterable watch() { + return delegate.watch(); + } + + @Override + public ChangeStreamIterable watch(Class resultClass) { + return delegate.watch(resultClass); + } + + @Override + public ChangeStreamIterable watch(List pipeline) { + return delegate.watch(pipeline); + } + + @Override + public ChangeStreamIterable watch(List pipeline, Class resultClass) { + return delegate.watch(pipeline, resultClass); + } + + @Override + public ChangeStreamIterable watch(ClientSession clientSession) { + return delegate.watch(clientSession); + } + + @Override + public ChangeStreamIterable watch(ClientSession clientSession, Class resultClass) { + return delegate.watch(clientSession, resultClass); + } + + @Override + public ChangeStreamIterable watch(ClientSession clientSession, List pipeline) { + return delegate.watch(clientSession, pipeline); + } + + @Override + public ChangeStreamIterable watch(ClientSession clientSession, List pipeline, Class resultClass) { + return delegate.watch(clientSession, pipeline, resultClass); + } + + @Override + public void close() { + delegate.close(); + + } + + @Override + public ClusterDescription getClusterDescription() { + return delegate.getClusterDescription(); + } } diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoTestCollection.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoTestCollection.java index 051f99d49db..7cf70a14a94 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoTestCollection.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoTestCollection.java @@ -17,8 +17,13 @@ package org.apache.jackrabbit.oak.plugins.document.mongo; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; - +import org.bson.Document; +import org.bson.codecs.configuration.CodecRegistry; +import org.bson.conversions.Bson; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import com.mongodb.MongoException; import com.mongodb.MongoNamespace; import com.mongodb.ReadConcern; @@ -31,12 +36,14 @@ import com.mongodb.client.DistinctIterable; import com.mongodb.client.FindIterable; import com.mongodb.client.ListIndexesIterable; +import com.mongodb.client.ListSearchIndexesIterable; import com.mongodb.client.MapReduceIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.model.BulkWriteOptions; import com.mongodb.client.model.CountOptions; import com.mongodb.client.model.CreateIndexOptions; import com.mongodb.client.model.DeleteOptions; +import com.mongodb.client.model.DropCollectionOptions; import com.mongodb.client.model.DropIndexOptions; import com.mongodb.client.model.EstimatedDocumentCountOptions; import com.mongodb.client.model.FindOneAndDeleteOptions; @@ -48,17 +55,14 @@ import com.mongodb.client.model.InsertOneOptions; import com.mongodb.client.model.RenameCollectionOptions; import com.mongodb.client.model.ReplaceOptions; +import com.mongodb.client.model.SearchIndexModel; import com.mongodb.client.model.UpdateOptions; import com.mongodb.client.model.WriteModel; import com.mongodb.client.result.DeleteResult; +import com.mongodb.client.result.InsertManyResult; +import com.mongodb.client.result.InsertOneResult; import com.mongodb.client.result.UpdateResult; -import org.bson.Document; -import org.bson.codecs.configuration.CodecRegistry; -import org.bson.conversions.Bson; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - public class MongoTestCollection implements MongoCollection { private final MongoCollection collection; @@ -143,44 +147,6 @@ public MongoCollection withReadConcern(@NotNull ReadConcern readConce return new MongoTestCollection<>(collection.withReadConcern(readConcern), beforeQueryException, beforeUpdateException, afterUpdateException); } - @Override - @Deprecated - public long count() { - return collection.count(); - } - - @Override - @Deprecated - public long count(@NotNull Bson filter) { - return collection.count(filter); - } - - @Override - @Deprecated - public long count(@NotNull Bson filter, @NotNull CountOptions options) { - return collection.count(filter, options); - } - - @Override - @Deprecated - public long count(@NotNull ClientSession clientSession) { - return collection.count(clientSession); - } - - @Override - @Deprecated - public long count(@NotNull ClientSession clientSession, @NotNull Bson filter) { - return collection.count(clientSession, filter); - } - - @Override - @Deprecated - public long count(@NotNull ClientSession clientSession, - @NotNull Bson filter, - @NotNull CountOptions options) { - return collection.count(clientSession, filter, options); - } - @Override public long countDocuments() { return collection.countDocuments(); @@ -472,65 +438,73 @@ public BulkWriteResult bulkWrite(@NotNull ClientSession clientSession, } @Override - public void insertOne(@NotNull TDocument tDocument) { + public InsertOneResult insertOne(@NotNull TDocument tDocument) { maybeThrowExceptionBeforeUpdate(); - collection.insertOne(tDocument); + InsertOneResult insertOne = collection.insertOne(tDocument); maybeThrowExceptionAfterUpdate(); + return insertOne; } @Override - public void insertOne(@NotNull TDocument tDocument, @NotNull InsertOneOptions options) { + public InsertOneResult insertOne(@NotNull TDocument tDocument, @NotNull InsertOneOptions options) { maybeThrowExceptionBeforeUpdate(); - collection.insertOne(tDocument, options); + InsertOneResult insertOne = collection.insertOne(tDocument, options); maybeThrowExceptionAfterUpdate(); + return insertOne; } @Override - public void insertOne(@NotNull ClientSession clientSession, @NotNull TDocument tDocument) { + public InsertOneResult insertOne(@NotNull ClientSession clientSession, @NotNull TDocument tDocument) { maybeThrowExceptionBeforeUpdate(); - collection.insertOne(clientSession, tDocument); + InsertOneResult insertOne = collection.insertOne(clientSession, tDocument); maybeThrowExceptionAfterUpdate(); + return insertOne; } @Override - public void insertOne(@NotNull ClientSession clientSession, + public InsertOneResult insertOne(@NotNull ClientSession clientSession, @NotNull TDocument tDocument, @NotNull InsertOneOptions options) { maybeThrowExceptionBeforeUpdate(); - collection.insertOne(clientSession, tDocument, options); + InsertOneResult insertOne = collection.insertOne(clientSession, tDocument, options); maybeThrowExceptionAfterUpdate(); + return insertOne; } @Override - public void insertMany(@NotNull List tDocuments) { + public InsertManyResult insertMany(@NotNull List tDocuments) { maybeThrowExceptionBeforeUpdate(); - collection.insertMany(tDocuments); + InsertManyResult insertMany = collection.insertMany(tDocuments); maybeThrowExceptionAfterUpdate(); + return insertMany; } @Override - public void insertMany(@NotNull List tDocuments, + public InsertManyResult insertMany(@NotNull List tDocuments, @NotNull InsertManyOptions options) { maybeThrowExceptionBeforeUpdate(); - collection.insertMany(tDocuments, options); + InsertManyResult insertMany = collection.insertMany(tDocuments, options); maybeThrowExceptionAfterUpdate(); + return insertMany; } @Override - public void insertMany(@NotNull ClientSession clientSession, + public InsertManyResult insertMany(@NotNull ClientSession clientSession, @NotNull List tDocuments) { maybeThrowExceptionBeforeUpdate(); - collection.insertMany(clientSession, tDocuments); + InsertManyResult insertMany = collection.insertMany(clientSession, tDocuments); maybeThrowExceptionAfterUpdate(); + return insertMany; } @Override - public void insertMany(@NotNull ClientSession clientSession, + public InsertManyResult insertMany(@NotNull ClientSession clientSession, @NotNull List tDocuments, @NotNull InsertManyOptions options) { maybeThrowExceptionBeforeUpdate(); - collection.insertMany(clientSession, tDocuments, options); + InsertManyResult insertMany = collection.insertMany(clientSession, tDocuments, options); maybeThrowExceptionAfterUpdate(); + return insertMany; } @NotNull @@ -618,18 +592,6 @@ public UpdateResult replaceOne(@NotNull Bson filter, @NotNull TDocument replacem return result; } - @NotNull - @Override - @Deprecated - public UpdateResult replaceOne(@NotNull Bson filter, - @NotNull TDocument replacement, - @NotNull UpdateOptions updateOptions) { - maybeThrowExceptionBeforeUpdate(); - UpdateResult result = collection.replaceOne(filter, replacement, updateOptions); - maybeThrowExceptionAfterUpdate(); - return result; - } - @NotNull @Override public UpdateResult replaceOne(@NotNull ClientSession clientSession, @@ -641,19 +603,6 @@ public UpdateResult replaceOne(@NotNull ClientSession clientSession, return result; } - @NotNull - @Override - @Deprecated - public UpdateResult replaceOne(@NotNull ClientSession clientSession, - @NotNull Bson filter, - @NotNull TDocument replacement, - @NotNull UpdateOptions updateOptions) { - maybeThrowExceptionBeforeUpdate(); - UpdateResult result = collection.replaceOne(clientSession, filter, replacement, updateOptions); - maybeThrowExceptionAfterUpdate(); - return result; - } - @NotNull @Override public UpdateResult replaceOne(@NotNull Bson filter, @@ -1194,6 +1143,61 @@ public void renameCollection(@NotNull ClientSession clientSession, @NotNull RenameCollectionOptions renameCollectionOptions) { collection.renameCollection(clientSession, newCollectionNamespace, renameCollectionOptions); } + + @Override + public Long getTimeout(TimeUnit timeUnit) { + return collection.getTimeout(timeUnit); + } + + @Override + public MongoCollection withTimeout(long timeout, TimeUnit timeUnit) { + return collection.withTimeout(timeout, timeUnit); + } + + @Override + public void drop(DropCollectionOptions dropCollectionOptions) { + collection.drop(dropCollectionOptions); + } + + @Override + public void drop(ClientSession clientSession, DropCollectionOptions dropCollectionOptions) { + collection.drop(clientSession, dropCollectionOptions); + } + + @Override + public String createSearchIndex(String indexName, Bson definition) { + return collection.createSearchIndex(indexName, definition); + } + + @Override + public String createSearchIndex(Bson definition) { + return collection.createSearchIndex(definition); + } + + @Override + public List createSearchIndexes(List searchIndexModels) { + return collection.createSearchIndexes(searchIndexModels); + } + + @Override + public void updateSearchIndex(String indexName, Bson definition) { + collection.updateSearchIndex(indexName, definition); + } + + @Override + public void dropSearchIndex(String indexName) { + collection.dropSearchIndex(indexName); + } + + @Override + public ListSearchIndexesIterable listSearchIndexes() { + return collection.listSearchIndexes(); + } + + @Override + public ListSearchIndexesIterable listSearchIndexes(Class resultClass) { + return collection.listSearchIndexes(resultClass); + } private void maybeThrowExceptionBeforeQuery() { String msg = beforeQueryException.get(); diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoTestDatabase.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoTestDatabase.java index 27d89cffc9f..db3c231b2f7 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoTestDatabase.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoTestDatabase.java @@ -17,26 +17,25 @@ package org.apache.jackrabbit.oak.plugins.document.mongo; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; - +import org.bson.Document; +import org.bson.codecs.configuration.CodecRegistry; +import org.bson.conversions.Bson; +import org.jetbrains.annotations.NotNull; import com.mongodb.ReadConcern; import com.mongodb.ReadPreference; import com.mongodb.WriteConcern; import com.mongodb.client.AggregateIterable; import com.mongodb.client.ChangeStreamIterable; import com.mongodb.client.ClientSession; +import com.mongodb.client.ListCollectionNamesIterable; import com.mongodb.client.ListCollectionsIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; -import com.mongodb.client.MongoIterable; import com.mongodb.client.model.CreateCollectionOptions; import com.mongodb.client.model.CreateViewOptions; -import org.bson.Document; -import org.bson.codecs.configuration.CodecRegistry; -import org.bson.conversions.Bson; -import org.jetbrains.annotations.NotNull; - public class MongoTestDatabase implements MongoDatabase { private final MongoDatabase db; @@ -194,7 +193,7 @@ public void drop(@NotNull ClientSession clientSession) { @NotNull @Override - public MongoIterable listCollectionNames() { + public ListCollectionNamesIterable listCollectionNames() { return db.listCollectionNames(); } @@ -212,7 +211,7 @@ public ListCollectionsIterable listCollections(@NotNull Class @NotNull @Override - public MongoIterable listCollectionNames(@NotNull ClientSession clientSession) { + public ListCollectionNamesIterable listCollectionNames(@NotNull ClientSession clientSession) { return db.listCollectionNames(clientSession); } @@ -366,4 +365,16 @@ public AggregateIterable aggregate(@NotNull ClientSession cli @NotNull Class tResultClass) { return db.aggregate(clientSession, pipeline, tResultClass); } + + @Override + public Long getTimeout(TimeUnit timeUnit) { + // TODO Auto-generated method stub + return null; + } + + @Override + public MongoDatabase withTimeout(long timeout, TimeUnit timeUnit) { + // TODO Auto-generated method stub + return null; + } } diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java index 5d24e77d3dc..55520e77866 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java @@ -16,21 +16,19 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.Type.GENERIC; +import static org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.Type.TRANSIENT; +import static org.apache.jackrabbit.oak.plugins.document.MongoUtils.isAvailable; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.getDocumentStoreExceptionTypeFor; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; +import static org.mockito.Mockito.mock; import java.io.IOException; import java.util.ArrayList; import java.util.List; - -import com.mongodb.BasicDBObject; -import com.mongodb.DuplicateKeyException; -import com.mongodb.MongoClient; -import com.mongodb.MongoCommandException; -import com.mongodb.MongoException; -import com.mongodb.MongoSocketException; -import com.mongodb.ServerAddress; -import com.mongodb.WriteConcernException; -import com.mongodb.client.ClientSession; -import com.mongodb.client.MongoCollection; - import org.apache.jackrabbit.oak.plugins.document.Collection; import org.apache.jackrabbit.oak.plugins.document.MongoConnectionFactory; import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; @@ -41,17 +39,16 @@ import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; - -import static org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.Type.GENERIC; -import static org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.Type.TRANSIENT; -import static org.apache.jackrabbit.oak.plugins.document.MongoUtils.isAvailable; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.getDocumentStoreExceptionTypeFor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; -import static org.mockito.Mockito.mock; +import com.mongodb.BasicDBObject; +import com.mongodb.DuplicateKeyException; +import com.mongodb.MongoCommandException; +import com.mongodb.MongoException; +import com.mongodb.MongoSocketException; +import com.mongodb.ServerAddress; +import com.mongodb.WriteConcernException; +import com.mongodb.client.ClientSession; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoCollection; public class MongoUtilsTest { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongodProcessFactory.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongodProcessFactory.java index 7ddcd850df3..de930362b5e 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongodProcessFactory.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongodProcessFactory.java @@ -18,6 +18,8 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongodProcess.join; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.net.InetAddress; import java.util.ArrayList; @@ -25,15 +27,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - import org.apache.jackrabbit.guava.common.base.Joiner; -import com.mongodb.MongoClient; - import org.bson.Document; import org.junit.rules.ExternalResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; import de.flapdoodle.embed.mongo.Command; import de.flapdoodle.embed.mongo.MongodStarter; import de.flapdoodle.embed.mongo.config.Defaults; @@ -43,9 +43,6 @@ import de.flapdoodle.embed.process.io.progress.Slf4jProgressListener; import de.flapdoodle.embed.process.runtime.Network; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongodProcess.join; -import static org.junit.Assert.assertTrue; - /** * External resource for mongod processes. */ @@ -145,7 +142,7 @@ private void initRS(String rs, int[] ports) { } Document config = new Document("_id", rs); config.append("members", members); - try (MongoClient c = new MongoClient(localhost(), ports[0])) { + try (MongoClient c = MongoClients.create("mongodb://" + localhost() + ":" + ports[0])) { c.getDatabase("admin").runCommand( new Document("replSetInitiate", config)); } diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetResilienceIT.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetResilienceIT.java index 77d949da489..b76f777b377 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetResilienceIT.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetResilienceIT.java @@ -18,6 +18,11 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeThat; import java.io.IOException; import java.io.UncheckedIOException; import java.util.ArrayList; @@ -31,12 +36,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; - import org.apache.jackrabbit.guava.common.base.Stopwatch; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientOptions; -import com.mongodb.ServerAddress; - import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; import org.apache.jackrabbit.oak.plugins.document.MongoUtils; @@ -49,12 +49,13 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeThat; +import com.mongodb.MongoClientSettings; +import com.mongodb.ServerAddress; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.connection.ClusterDescription; +import com.mongodb.connection.ServerDescription; +import com.mongodb.connection.ServerType; /** * A long running resilience IT. The test sets up a three node replica set and @@ -215,11 +216,29 @@ private void stopPrimary() { for (MongodProcess p : executables.values()) { seeds.add(p.getAddress()); } - try (MongoClient c = new MongoClient(seeds, - new MongoClientOptions.Builder().requiredReplicaSetName("rs").build())) { + + String replicaSetName = "rs"; + + MongoClientSettings settings = MongoClientSettings.builder() + .applyToClusterSettings(builder -> + builder.hosts(seeds).requiredReplicaSetName(replicaSetName) + ) + .build(); + + try (MongoClient c = MongoClients.create(settings)) { ServerAddress address = null; for (int i = 0; i < 5; i++) { - address = c.getReplicaSetStatus().getMaster(); + ClusterDescription clusterDescription = c.getClusterDescription(); + + for (Iterator iterator = clusterDescription.getServerDescriptions().iterator(); iterator.hasNext();) { + ServerDescription sd = iterator.next(); + + if (ServerType.REPLICA_SET_PRIMARY.equals(sd.getType())) { + address = sd.getAddress(); + break; + } + } + if (address == null) { LOG.info("Primary unavailable. Waiting one second..."); try { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatusTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatusTest.java index c334a1055b5..dc3e80dc94c 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatusTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatusTest.java @@ -16,24 +16,21 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; - -import com.mongodb.ServerAddress; -import com.mongodb.connection.ClusterId; -import com.mongodb.connection.ConnectionDescription; -import com.mongodb.connection.ServerId; -import com.mongodb.event.ServerHeartbeatSucceededEvent; - import org.bson.BsonArray; import org.bson.BsonDateTime; import org.bson.BsonDocument; import org.bson.BsonString; import org.bson.BsonValue; import org.junit.Test; - -import static org.junit.Assert.assertEquals; +import com.mongodb.ServerAddress; +import com.mongodb.connection.ClusterId; +import com.mongodb.connection.ConnectionDescription; +import com.mongodb.connection.ServerId; +import com.mongodb.event.ServerHeartbeatSucceededEvent; public class ReplicaSetStatusTest { @@ -104,6 +101,6 @@ private ServerHeartbeatSucceededEvent newEvent(int connectionIndex, long localTi reply.put("hosts", new BsonArray(hostValues)); BsonDocument lastWrite = new BsonDocument("lastWriteDate", new BsonDateTime(lastWriteDate)); reply.put("lastWrite", lastWrite); - return new ServerHeartbeatSucceededEvent(description.getConnectionId(), reply, 0); + return new ServerHeartbeatSucceededEvent(description.getConnectionId(), reply, 0, false); } } diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/RetryReadIT.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/RetryReadIT.java index a77ca245e0d..ccd6a790e84 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/RetryReadIT.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/RetryReadIT.java @@ -16,8 +16,13 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; +import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; +import static org.hamcrest.collection.IsEmptyCollection.empty; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; import java.util.List; - import org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest; import org.apache.jackrabbit.oak.plugins.document.Collection; import org.apache.jackrabbit.oak.plugins.document.Document; @@ -29,18 +34,10 @@ import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.jetbrains.annotations.NotNull; import org.junit.Test; - -import com.mongodb.MongoClient; import com.mongodb.MongoException; +import com.mongodb.client.MongoClient; import com.mongodb.client.MongoDatabase; -import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; -import static org.hamcrest.collection.IsEmptyCollection.empty; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - /** * Tests retry logic in MongoDocumentStore (OAK-1641). */ diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/prefetch/CountingMongoDatabase.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/prefetch/CountingMongoDatabase.java index e1e68b49353..02dffea6fac 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/prefetch/CountingMongoDatabase.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/prefetch/CountingMongoDatabase.java @@ -19,22 +19,21 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; - import org.bson.Document; import org.bson.codecs.configuration.CodecRegistry; import org.bson.conversions.Bson; - import com.mongodb.ReadConcern; import com.mongodb.ReadPreference; import com.mongodb.WriteConcern; import com.mongodb.client.AggregateIterable; import com.mongodb.client.ChangeStreamIterable; import com.mongodb.client.ClientSession; +import com.mongodb.client.ListCollectionNamesIterable; import com.mongodb.client.ListCollectionsIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; -import com.mongodb.client.MongoIterable; import com.mongodb.client.model.CreateCollectionOptions; import com.mongodb.client.model.CreateViewOptions; @@ -180,7 +179,7 @@ public void drop(ClientSession clientSession) { } @Override - public MongoIterable listCollectionNames() { + public ListCollectionNamesIterable listCollectionNames() { return delegate.listCollectionNames(); } @@ -199,7 +198,7 @@ public ListCollectionsIterable listCollections( } @Override - public MongoIterable listCollectionNames(ClientSession clientSession) { + public ListCollectionNamesIterable listCollectionNames(ClientSession clientSession) { return delegate.listCollectionNames(clientSession); } @@ -351,4 +350,14 @@ public AggregateIterable aggregate(ClientSession clientSessio } + @Override + public Long getTimeout(TimeUnit timeUnit) { + return delegate.getTimeout(timeUnit); + } + + @Override + public MongoDatabase withTimeout(long timeout, TimeUnit timeUnit) { + return delegate.withTimeout(timeout, timeUnit); + } + } diff --git a/oak-upgrade/pom.xml b/oak-upgrade/pom.xml index 4fc33e044d4..63fd382b609 100644 --- a/oak-upgrade/pom.xml +++ b/oak-upgrade/pom.xml @@ -169,7 +169,7 @@ org.mongodb - mongo-java-driver + mongodb-driver-sync org.apache.tomcat diff --git a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/node/MongoFactory.java b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/node/MongoFactory.java index cee39f4f507..a838c155b9e 100644 --- a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/node/MongoFactory.java +++ b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/node/MongoFactory.java @@ -16,30 +16,28 @@ */ package org.apache.jackrabbit.oak.upgrade.cli.node; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; +import java.io.IOException; +import org.apache.jackrabbit.guava.common.io.Closer; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoBlobStore; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.state.NodeStore; - -import org.apache.jackrabbit.guava.common.io.Closer; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientURI; - -import java.io.IOException; - -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; public class MongoFactory extends DocumentFactory { - private final MongoClientURI uri; + private final ConnectionString uri; private final int cacheSize; private final boolean readOnly; public MongoFactory(String repoDesc, int cacheSize, boolean readOnly) { - this.uri = new MongoClientURI(repoDesc); + this.uri = new ConnectionString(repoDesc); this.cacheSize = cacheSize; this.readOnly = readOnly; } @@ -65,7 +63,7 @@ public NodeStore create(BlobStore blobStore, Closer closer) throws IOException { } private MongoClient createClient(Closer closer) { - MongoClient client = new MongoClient(uri); + MongoClient client = MongoClients.create(uri); closer.register(client::close); return client; } diff --git a/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/container/MongoNodeStoreContainer.java b/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/container/MongoNodeStoreContainer.java index 2475e6516bc..9a5b550efcc 100644 --- a/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/container/MongoNodeStoreContainer.java +++ b/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/container/MongoNodeStoreContainer.java @@ -17,18 +17,18 @@ package org.apache.jackrabbit.oak.upgrade.cli.container; import java.io.IOException; +import java.util.Iterator; import java.util.concurrent.atomic.AtomicInteger; - +import org.apache.jackrabbit.guava.common.io.Closer; import org.apache.jackrabbit.oak.spi.state.NodeStore; import org.apache.jackrabbit.oak.upgrade.cli.node.MongoFactory; import org.junit.Assume; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import org.apache.jackrabbit.guava.common.io.Closer; -import com.mongodb.Mongo; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientURI; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoIterable; public class MongoNodeStoreContainer implements NodeStoreContainer { @@ -71,11 +71,16 @@ public static boolean isMongoAvailable() { } private static boolean testMongoAvailability() { - Mongo mongo = null; + MongoClient mongo = null; try { - MongoClientURI uri = new MongoClientURI(MONGO_URI + "?connectTimeoutMS=3000"); - mongo = new MongoClient(uri); - mongo.getDatabaseNames(); + ConnectionString uri = new ConnectionString(MONGO_URI + "?connectTimeoutMS=3000"); + mongo = MongoClients.create(uri); + MongoIterable listDatabaseNames = mongo.listDatabaseNames(); + + // To do real call to mongo and so test its availability we need to call iterator on just returned result + for (Iterator iterator = listDatabaseNames.iterator(); iterator.hasNext();) { + // do nothing... + } return true; } catch (Exception e) { return false; @@ -103,9 +108,9 @@ public void close() { @Override public void clean() throws IOException { - MongoClientURI uri = new MongoClientURI(mongoUri); - MongoClient client = new MongoClient(uri); - client.dropDatabase(uri.getDatabase()); + ConnectionString uri = new ConnectionString(mongoUri); + MongoClient client = MongoClients.create(uri); + client.getDatabase(uri.getDatabase()).drop(); blob.clean(); } From 435903a9fc3fe3c024405c4a4ede21f1b48c92b3 Mon Sep 17 00:00:00 2001 From: raffaega Date: Fri, 4 Oct 2024 21:36:38 +0200 Subject: [PATCH 02/10] Conflict with trunk resolved --- .../document/DocumentStoreFixture.java | 16 +++---- .../oak/plugins/document/MongoUtils.java | 48 ++++++++++--------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java index 3a4efe9db26..eb2585bac0c 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java @@ -16,13 +16,16 @@ */ package org.apache.jackrabbit.oak.plugins.document; +import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_MEM; +import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_NS; +import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_RDB; import java.io.Closeable; import java.io.IOException; import java.util.List; - import javax.sql.DataSource; - +import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.oak.commons.FixturesHelper; +import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier; import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory; @@ -33,12 +36,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.jackrabbit.guava.common.collect.Lists; - -import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_MEM; -import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_NS; -import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_RDB; - public abstract class DocumentStoreFixture { private static final Logger LOG = LoggerFactory.getLogger(DocumentStoreFixture.class); @@ -236,6 +233,9 @@ public void setRDBOptions(RDBOptions options) { } public static class MongoFixture extends DocumentStoreFixture { + + public static final boolean SKIP_MONGO = SystemPropertySupplier.create("oak.skipMongo", false).loggingTo(LOG).get(); + protected List connections = Lists.newArrayList(); @Override diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java index 6a1014a79e2..70655fc149b 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java @@ -53,29 +53,31 @@ private static String createMongoURL() { if (mongoUrl == null || mongoUrl.isEmpty()) { mongoUrl = "mongodb://" + HOST + ":" + PORT + "/" + DB + "?" + OPTIONS; } - // check if we can connect - MongoConnection c = getConnectionByURL(mongoUrl); - if (c != null) { - c.close(); - return mongoUrl; - } - // fallback to docker based MongoDB if available - MongoDockerRule dockerRule = new MongoDockerRule(); - if (MongoDockerRule.isDockerAvailable()) { - AtomicReference host = new AtomicReference<>(); - AtomicInteger port = new AtomicInteger(); - try { - dockerRule.apply(new Statement() { - @Override - public void evaluate() { - host.set(dockerRule.getHost()); - port.set(dockerRule.getPort()); - } - }, Description.EMPTY) - .evaluate(); - mongoUrl = "mongodb://" + host + ":" + port.get() + "/" + DB + "?" + OPTIONS; - } catch (Throwable t) { - LOG.warn("Unable to get MongoDB port from Docker", t); + if (!DocumentStoreFixture.MongoFixture.SKIP_MONGO) { + // check if we can connect + MongoConnection c = getConnectionByURL(mongoUrl); + if (c != null) { + c.close(); + return mongoUrl; + } + // fallback to docker based MongoDB if available + MongoDockerRule dockerRule = new MongoDockerRule(); + if (MongoDockerRule.isDockerAvailable()) { + AtomicReference host = new AtomicReference<>(); + AtomicInteger port = new AtomicInteger(); + try { + dockerRule.apply(new Statement() { + @Override + public void evaluate() { + host.set(dockerRule.getHost()); + port.set(dockerRule.getPort()); + } + }, Description.EMPTY) + .evaluate(); + mongoUrl = "mongodb://" + host + ":" + port.get() + "/" + DB + "?" + OPTIONS; + } catch (Throwable t) { + LOG.warn("Unable to get MongoDB port from Docker", t); + } } } return mongoUrl; From 50af9a3586ca0e44d107cd46ff4600fe65c69319 Mon Sep 17 00:00:00 2001 From: raffaega Date: Fri, 4 Oct 2024 21:44:45 +0200 Subject: [PATCH 03/10] Conflict resolved --- .../org/apache/jackrabbit/oak/plugins/document/MongoUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java index 70655fc149b..ff1b2bb405e 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java @@ -72,8 +72,7 @@ public void evaluate() { host.set(dockerRule.getHost()); port.set(dockerRule.getPort()); } - }, Description.EMPTY) - .evaluate(); + }, Description.EMPTY).evaluate(); mongoUrl = "mongodb://" + host + ":" + port.get() + "/" + DB + "?" + OPTIONS; } catch (Throwable t) { LOG.warn("Unable to get MongoDB port from Docker", t); From afd034e9bc01e657a6aaaba7104d30347c7aabd5 Mon Sep 17 00:00:00 2001 From: raffaega Date: Fri, 4 Oct 2024 21:53:13 +0200 Subject: [PATCH 04/10] conflict resolved --- .../oak/plugins/document/DocumentStoreFixture.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java index eb2585bac0c..2b8c0101608 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java @@ -16,14 +16,12 @@ */ package org.apache.jackrabbit.oak.plugins.document; -import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_MEM; -import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_NS; -import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_RDB; import java.io.Closeable; import java.io.IOException; import java.util.List; + import javax.sql.DataSource; -import org.apache.jackrabbit.guava.common.collect.Lists; + import org.apache.jackrabbit.oak.commons.FixturesHelper; import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier; import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore; @@ -36,6 +34,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.jackrabbit.guava.common.collect.Lists; + +import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_MEM; +import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_NS; +import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_RDB; + public abstract class DocumentStoreFixture { private static final Logger LOG = LoggerFactory.getLogger(DocumentStoreFixture.class); From 853b93dd67aad2b38783731f4bb10b90cafa02c7 Mon Sep 17 00:00:00 2001 From: raffaega Date: Fri, 4 Oct 2024 23:07:42 +0200 Subject: [PATCH 05/10] Reordered imports like original classes and fixed oak-run about new mongodb-driver-sync --- .../jcr/cluster/NonLocalObservationIT.java | 5 +- .../oak/jcr/random/RandomOpCompare.java | 3 + .../oak/fixture/CompositeStoreFixture.java | 17 ++-- .../document/DocumentStoreIndexerBase.java | 66 +++++++-------- .../flatfile/FlatFileNodeStoreBuilder.java | 34 ++++---- .../pipelined/PipelinedMongoDownloadTask.java | 72 ++++++++-------- .../flatfile/pipelined/PipelinedStrategy.java | 48 +++++------ .../pipelined/PipelinedTreeStoreStrategy.java | 34 ++++---- .../oak/run/cli/DocumentFixtureProvider.java | 19 +++-- .../flatfile/pipelined/MongoTestBackend.java | 9 +- .../flatfile/pipelined/PipelineITUtil.java | 18 ++-- .../PipelinedMongoDownloadTaskTest.java | 24 +++--- .../oak/run/DataStoreCheckCommand.java | 12 +-- .../oak/run/UnlockUpgradeCommand.java | 12 ++- .../org/apache/jackrabbit/oak/run/Utils.java | 17 ++-- .../oak/index/DocumentStoreIndexerIT.java | 82 ++++++++++--------- .../oak/index/IncrementalStoreTest.java | 6 +- 17 files changed, 251 insertions(+), 227 deletions(-) diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java index cb2774dd279..6557e1c746e 100644 --- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java +++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java @@ -19,11 +19,13 @@ import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.DOCUMENT_NS; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; + import java.util.Date; import java.util.HashSet; import java.util.Random; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; + import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; @@ -31,6 +33,7 @@ import javax.jcr.observation.EventIterator; import javax.jcr.observation.EventListener; import javax.jcr.observation.ObservationManager; + import org.apache.jackrabbit.api.observation.JackrabbitEvent; import org.apache.jackrabbit.oak.commons.FixturesHelper; import org.apache.jackrabbit.oak.fixture.DocumentMongoFixture; @@ -44,8 +47,8 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClient; /** * Test for external events from another cluster node. diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/random/RandomOpCompare.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/random/RandomOpCompare.java index 5fdd37951ff..6628c11a21e 100644 --- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/random/RandomOpCompare.java +++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/random/RandomOpCompare.java @@ -20,14 +20,17 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; + import java.io.Closeable; import java.io.IOException; import java.util.Random; + import javax.jcr.Node; import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.SimpleCredentials; + import org.apache.jackrabbit.oak.NodeStoreFixtures; import org.apache.jackrabbit.oak.fixture.NodeStoreFixture; import org.apache.jackrabbit.oak.jcr.Jcr; diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/fixture/CompositeStoreFixture.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/fixture/CompositeStoreFixture.java index 73f2eb370b5..851fbfe67ac 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/fixture/CompositeStoreFixture.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/fixture/CompositeStoreFixture.java @@ -17,13 +17,6 @@ package org.apache.jackrabbit.oak.fixture; -import static java.util.Arrays.asList; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; -import static org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import org.apache.jackrabbit.oak.Oak; import org.apache.jackrabbit.oak.composite.CompositeNodeStore; import org.apache.jackrabbit.oak.composite.InitialContentMigrator; @@ -44,8 +37,18 @@ import org.apache.jackrabbit.oak.spi.mount.Mounts; import org.apache.jackrabbit.oak.spi.state.NodeStore; import org.apache.jackrabbit.oak.stats.StatisticsProvider; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + import com.mongodb.ConnectionString; +import static java.util.Arrays.asList; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; +import static org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder; + abstract class CompositeStoreFixture extends OakFixture { private static final MountInfoProvider MOUNT_INFO_PROVIDER = Mounts.newBuilder() diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/DocumentStoreIndexerBase.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/DocumentStoreIndexerBase.java index f99c1adab8a..7e941f50961 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/DocumentStoreIndexerBase.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/DocumentStoreIndexerBase.java @@ -19,33 +19,10 @@ package org.apache.jackrabbit.oak.index.indexer.document; -import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder.OAK_INDEXER_SORTED_FILE_PATH; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.DEFAULT_OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDED_PATHS; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.DEFAULT_OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDE_ENTRIES_REGEX; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.DEFAULT_OAK_INDEXER_PIPELINED_MONGO_REGEX_PATH_FILTERING; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDED_PATHS; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDE_ENTRIES_REGEX; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.OAK_INDEXER_PIPELINED_MONGO_REGEX_PATH_FILTERING; -import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME; -import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; -import java.io.Closeable; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.regex.Pattern; -import java.util.stream.Collectors; +import com.codahale.metrics.MetricRegistry; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; import org.apache.jackrabbit.guava.common.base.Stopwatch; import org.apache.jackrabbit.guava.common.io.Closer; import org.apache.jackrabbit.oak.api.CommitFailedException; @@ -68,10 +45,10 @@ import org.apache.jackrabbit.oak.plugins.index.FormattingUtils; import org.apache.jackrabbit.oak.plugins.index.IndexConstants; import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback; -import org.apache.jackrabbit.oak.plugins.index.IndexingReporter; import org.apache.jackrabbit.oak.plugins.index.MetricsFormatter; import org.apache.jackrabbit.oak.plugins.index.MetricsUtils; import org.apache.jackrabbit.oak.plugins.index.NodeTraversalCallback; +import org.apache.jackrabbit.oak.plugins.index.IndexingReporter; import org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter; import org.apache.jackrabbit.oak.plugins.index.progress.MetricRateEstimator; import org.apache.jackrabbit.oak.plugins.index.search.ExtractedTextCache; @@ -88,10 +65,35 @@ import org.bson.Document; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.codahale.metrics.MetricRegistry; -import com.mongodb.ConnectionString; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoDatabase; + +import java.io.Closeable; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import static java.util.Objects.requireNonNull; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder.OAK_INDEXER_SORTED_FILE_PATH; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.DEFAULT_OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDED_PATHS; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.DEFAULT_OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDE_ENTRIES_REGEX; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.DEFAULT_OAK_INDEXER_PIPELINED_MONGO_REGEX_PATH_FILTERING; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDED_PATHS; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.OAK_INDEXER_PIPELINED_MONGO_CUSTOM_EXCLUDE_ENTRIES_REGEX; +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.PipelinedMongoDownloadTask.OAK_INDEXER_PIPELINED_MONGO_REGEX_PATH_FILTERING; +import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME; +import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; public abstract class DocumentStoreIndexerBase implements Closeable { public static final String INDEXER_METRICS_PREFIX = "oak_indexer_"; diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java index c7dee659b51..1d85447ac8a 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java @@ -19,20 +19,8 @@ package org.apache.jackrabbit.oak.index.indexer.document.flatfile; -import static java.util.Collections.unmodifiableSet; -import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState; -import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_LZ4; -import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_ZIP; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoDatabase; import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.commons.Compression; @@ -63,8 +51,22 @@ import org.apache.jackrabbit.oak.stats.StatisticsProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.mongodb.ConnectionString; -import com.mongodb.client.MongoDatabase; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import static java.util.Collections.unmodifiableSet; +import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState; +import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_LZ4; +import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_ZIP; /** * This class is where the strategy being selected for building FlatFileStore. diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTask.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTask.java index 03016b762e4..10e61148af2 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTask.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTask.java @@ -18,27 +18,20 @@ */ package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined; -import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; -import java.time.Duration; -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; +import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings; +import com.mongodb.MongoException; +import com.mongodb.MongoIncompatibleDriverException; +import com.mongodb.MongoInterruptedException; +import com.mongodb.ReadPreference; +import com.mongodb.client.FindIterable; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoCursor; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.Sorts; import org.apache.jackrabbit.guava.common.base.Preconditions; import org.apache.jackrabbit.guava.common.base.Stopwatch; import org.apache.jackrabbit.guava.common.util.concurrent.ThreadFactoryBuilder; @@ -61,20 +54,29 @@ import org.bson.conversions.Bson; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.mongodb.ConnectionString; -import com.mongodb.MongoClientSettings; -import com.mongodb.MongoException; -import com.mongodb.MongoIncompatibleDriverException; -import com.mongodb.MongoInterruptedException; -import com.mongodb.ReadPreference; -import com.mongodb.client.FindIterable; -import com.mongodb.client.MongoClient; -import com.mongodb.client.MongoClients; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoCursor; -import com.mongodb.client.MongoDatabase; -import com.mongodb.client.model.Filters; -import com.mongodb.client.model.Sorts; + +import java.time.Duration; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorCompletionService; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; + +import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; public class PipelinedMongoDownloadTask implements Callable { private static final Logger LOG = LoggerFactory.getLogger(PipelinedMongoDownloadTask.class); diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedStrategy.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedStrategy.java index 238fbd9102e..b212ca1f7cf 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedStrategy.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedStrategy.java @@ -18,27 +18,7 @@ */ package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined; -import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCountBin; -import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.function.Predicate; +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; @@ -53,14 +33,36 @@ import org.apache.jackrabbit.oak.plugins.document.RevisionVector; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; import org.apache.jackrabbit.oak.plugins.index.FormattingUtils; -import org.apache.jackrabbit.oak.plugins.index.IndexingReporter; import org.apache.jackrabbit.oak.plugins.index.MetricsFormatter; +import org.apache.jackrabbit.oak.plugins.index.IndexingReporter; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.filter.PathFilter; import org.apache.jackrabbit.oak.stats.StatisticsProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.mongodb.ConnectionString; + +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorCompletionService; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; + +import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCountBin; +import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; /** * Downloads the contents of the MongoDB repository dividing the tasks in a pipeline with the following stages: diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedTreeStoreStrategy.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedTreeStoreStrategy.java index 2291d559994..642c50a41fe 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedTreeStoreStrategy.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedTreeStoreStrategy.java @@ -18,20 +18,7 @@ */ package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined; -import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.function.Predicate; +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; @@ -47,14 +34,29 @@ import org.apache.jackrabbit.oak.plugins.document.RevisionVector; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; import org.apache.jackrabbit.oak.plugins.index.FormattingUtils; -import org.apache.jackrabbit.oak.plugins.index.IndexingReporter; import org.apache.jackrabbit.oak.plugins.index.MetricsFormatter; +import org.apache.jackrabbit.oak.plugins.index.IndexingReporter; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.filter.PathFilter; import org.apache.jackrabbit.oak.stats.StatisticsProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.mongodb.ConnectionString; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorCompletionService; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; + +import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER; /** * Downloads the contents of the MongoDB repository dividing the tasks in a pipeline with the following stages: diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java index aa890fa4d71..a4f46e9dc36 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java @@ -18,15 +18,14 @@ */ package org.apache.jackrabbit.oak.run.cli; -import static java.util.Collections.emptyMap; -import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; -import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder.newRDBDocumentNodeStoreBuilder; -import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.getService; import java.io.IOException; + import javax.sql.DataSource; -import org.apache.commons.io.FileUtils; + +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoDatabase; import org.apache.jackrabbit.guava.common.io.Closer; +import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder; @@ -38,8 +37,12 @@ import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard; import org.apache.jackrabbit.oak.stats.StatisticsProvider; -import com.mongodb.ConnectionString; -import com.mongodb.client.MongoDatabase; + +import static java.util.Collections.emptyMap; +import static java.util.Objects.requireNonNull; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; +import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder.newRDBDocumentNodeStoreBuilder; +import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.getService; class DocumentFixtureProvider { static DocumentNodeStore configureDocumentMk(Options options, diff --git a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/MongoTestBackend.java b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/MongoTestBackend.java index 75f411c60be..a446a7617b6 100644 --- a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/MongoTestBackend.java +++ b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/MongoTestBackend.java @@ -18,12 +18,13 @@ */ package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined; -import java.io.Closeable; -import java.io.IOException; -import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; 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; + +import java.io.Closeable; +import java.io.IOException; class MongoTestBackend implements Closeable { final ConnectionString mongoClientURI; diff --git a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelineITUtil.java b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelineITUtil.java index 30099c01e80..020880f8b9e 100644 --- a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelineITUtil.java +++ b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelineITUtil.java @@ -18,13 +18,7 @@ */ package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined; -import static org.junit.Assert.assertEquals; -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; +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; @@ -46,7 +40,15 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.mongodb.ConnectionString; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertEquals; public class PipelineITUtil { private static final Logger LOG = LoggerFactory.getLogger(PipelineITUtil.class); diff --git a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTaskTest.java b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTaskTest.java index a6b655c0581..36b74d2e7f8 100644 --- a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTaskTest.java +++ b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTaskTest.java @@ -18,15 +18,8 @@ */ package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined; -import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.MongoDownloaderRegexUtils.LONG_PATH_ID_PATTERN; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import java.util.Arrays; -import java.util.List; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.IntStream; +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; import org.apache.jackrabbit.oak.spi.filter.PathFilter; @@ -36,8 +29,17 @@ import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.RestoreSystemProperties; -import com.mongodb.MongoClientSettings; -import com.mongodb.client.model.Filters; + +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.MongoDownloaderRegexUtils.LONG_PATH_ID_PATTERN; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; public class PipelinedMongoDownloadTaskTest { diff --git a/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DataStoreCheckCommand.java b/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DataStoreCheckCommand.java index facb06396c7..a6ddb3d32d2 100644 --- a/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DataStoreCheckCommand.java +++ b/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DataStoreCheckCommand.java @@ -50,9 +50,9 @@ import org.apache.jackrabbit.guava.common.io.Closeables; import org.apache.jackrabbit.guava.common.io.Closer; import org.apache.jackrabbit.guava.common.io.Files; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientURI; -import com.mongodb.MongoURI; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; import joptsimple.ArgumentAcceptingOptionSpec; import joptsimple.OptionParser; import joptsimple.OptionSet; @@ -185,9 +185,9 @@ static int checkDataStore(String... args) { NodeStore nodeStore = null; if (options.has(store)) { String source = options.valueOf(store); - if (source.startsWith(MongoURI.MONGODB_PREFIX)) { - MongoClientURI uri = new MongoClientURI(source); - MongoClient client = new MongoClient(uri); + if (source.startsWith("mongodb://")) { + ConnectionString uri = new ConnectionString(source); + MongoClient client = MongoClients.create(uri); DocumentNodeStore docNodeStore = newMongoDocumentNodeStoreBuilder().setMongoDB(client, uri.getDatabase()).build(); closer.register(Utils.asCloseable(docNodeStore)); diff --git a/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommand.java b/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommand.java index a266a84fd78..71766b23141 100644 --- a/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommand.java +++ b/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommand.java @@ -22,8 +22,7 @@ import javax.sql.DataSource; -import com.mongodb.MongoClientURI; - +import com.mongodb.ConnectionString; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder; import org.apache.jackrabbit.oak.run.commons.Command; @@ -38,7 +37,6 @@ import joptsimple.OptionSet; import joptsimple.OptionSpec; -import static com.mongodb.MongoURI.MONGODB_PREFIX; import static java.util.Arrays.asList; import static org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore.VERSION; @@ -74,12 +72,12 @@ public void execute(String... args) throws Exception { DocumentStore store = null; try { String uri = nonOptions.get(0); - if (uri.startsWith(MONGODB_PREFIX)) { - MongoClientURI clientURI = new MongoClientURI(uri); + if (uri.startsWith("mongodb://")) { + ConnectionString clientURI = new ConnectionString(uri); if (clientURI.getDatabase() == null) { - System.err.println("Database missing in MongoDB URI: " + clientURI.getURI()); + System.err.println("Database missing in MongoDB URI: " + clientURI); } else { - MongoConnection mongo = new MongoConnection(clientURI.getURI()); + MongoConnection mongo = new MongoConnection(uri); store = new MongoDocumentStore( mongo.getMongoClient(), mongo.getDatabase(), new MongoDocumentNodeStoreBuilder()); diff --git a/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Utils.java b/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Utils.java index f202486bc9e..284e36c42e6 100644 --- a/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Utils.java +++ b/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Utils.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.run; -import static com.mongodb.MongoURI.MONGODB_PREFIX; import static java.util.Arrays.asList; import static java.util.Objects.isNull; import static java.util.Optional.empty; @@ -67,12 +66,10 @@ import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore; import org.apache.jackrabbit.oak.spi.state.NodeStore; import org.jetbrains.annotations.Nullable; - +import com.mongodb.ConnectionString; import org.apache.jackrabbit.guava.common.collect.Maps; import org.apache.jackrabbit.guava.common.io.Closer; import org.apache.jackrabbit.guava.common.io.Files; -import com.mongodb.MongoClientURI; -import com.mongodb.MongoURI; import joptsimple.ArgumentAcceptingOptionSpec; import joptsimple.OptionParser; @@ -184,7 +181,7 @@ public static NodeStore bootstrapNodeStore(NodeStoreOptions options, Closer clos System.exit(1); } - if (src.startsWith(MongoURI.MONGODB_PREFIX) || src.startsWith("jdbc")) { + if (src.startsWith("mongodb://") || src.startsWith("jdbc")) { DocumentNodeStoreBuilder builder = createDocumentMKBuilder(options, closer); if (builder != null) { if (readOnlyMode) { @@ -218,7 +215,7 @@ static DocumentNodeStoreBuilder createDocumentMKBuilder(String[] args, Closer static Optional getMongoConnection(final NodeStoreOptions options, final Closer closer) { String src = options.getStoreArg(); - if (isNull(src) || !src.startsWith(MONGODB_PREFIX)) { + if (isNull(src) || !src.startsWith("mongodb://")) { return empty(); } @@ -235,7 +232,7 @@ static DocumentNodeStoreBuilder createDocumentMKBuilder(NodeStoreOptions opti System.exit(1); } DocumentNodeStoreBuilder builder; - if (src.startsWith(MONGODB_PREFIX)) { + if (src.startsWith("mongodb://")) { MongoConnection mongo = getMongoConnection(closer, src); builder = newMongoDocumentNodeStoreBuilder().setMongoDB(mongo.getMongoClient(), mongo.getDBName()); } else if (src.startsWith("jdbc")) { @@ -262,12 +259,12 @@ static DocumentNodeStoreBuilder createDocumentMKBuilder(NodeStoreOptions opti } private static MongoConnection getMongoConnection(Closer closer, String src) { - MongoClientURI uri = new MongoClientURI(src); + ConnectionString uri = new ConnectionString(src); if (uri.getDatabase() == null) { - System.err.println("Database missing in MongoDB URI: " + uri.getURI()); + System.err.println("Database missing in MongoDB URI: " + uri); System.exit(1); } - MongoConnection mongo = new MongoConnection(uri.getURI()); + MongoConnection mongo = new MongoConnection(src); closer.register(asCloseable(mongo)); return mongo; } diff --git a/oak-run/src/test/java/org/apache/jackrabbit/oak/index/DocumentStoreIndexerIT.java b/oak-run/src/test/java/org/apache/jackrabbit/oak/index/DocumentStoreIndexerIT.java index f0495190296..8fea020b2a3 100644 --- a/oak-run/src/test/java/org/apache/jackrabbit/oak/index/DocumentStoreIndexerIT.java +++ b/oak-run/src/test/java/org/apache/jackrabbit/oak/index/DocumentStoreIndexerIT.java @@ -19,42 +19,9 @@ package org.apache.jackrabbit.oak.index; -import static java.util.Collections.emptyMap; -import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE; -import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_LZ4; -import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_ZIP; -import static org.apache.jackrabbit.oak.plugins.document.TestUtils.childBuilder; -import static org.apache.jackrabbit.oak.plugins.document.TestUtils.createChild; -import static org.apache.jackrabbit.oak.plugins.document.TestUtils.merge; -import static org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler.BUNDLOR; -import static org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler.DOCUMENT_NODE_STORE; -import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeNotNull; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.SortedMap; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.function.Predicate; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.query.Query; -import javax.jcr.query.QueryManager; -import javax.jcr.query.QueryResult; -import javax.jcr.query.Row; +import com.codahale.metrics.Counter; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoDatabase; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.oak.InitialContent; import org.apache.jackrabbit.oak.api.CommitFailedException; @@ -78,9 +45,9 @@ import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; import org.apache.jackrabbit.oak.plugins.document.util.Utils; +import org.apache.jackrabbit.oak.plugins.index.importer.ClusterNodeStoreLock; import org.apache.jackrabbit.oak.plugins.index.ConsoleIndexingReporter; import org.apache.jackrabbit.oak.plugins.index.IndexingReporter; -import org.apache.jackrabbit.oak.plugins.index.importer.ClusterNodeStoreLock; import org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexRootDirectory; import org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexDir; import org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder; @@ -106,9 +73,44 @@ import org.junit.rules.TestRule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.codahale.metrics.Counter; -import com.mongodb.ConnectionString; -import com.mongodb.client.MongoDatabase; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.query.Query; +import javax.jcr.query.QueryManager; +import javax.jcr.query.QueryResult; +import javax.jcr.query.Row; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.SortedMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; + +import static java.util.Collections.emptyMap; +import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE; +import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_LZ4; +import static org.apache.jackrabbit.oak.index.indexer.document.indexstore.IndexStoreUtils.OAK_INDEXER_USE_ZIP; +import static org.apache.jackrabbit.oak.plugins.document.TestUtils.childBuilder; +import static org.apache.jackrabbit.oak.plugins.document.TestUtils.createChild; +import static org.apache.jackrabbit.oak.plugins.document.TestUtils.merge; +import static org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler.BUNDLOR; +import static org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler.DOCUMENT_NODE_STORE; +import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeNotNull; public class DocumentStoreIndexerIT extends LuceneAbstractIndexCommandTest { private final Logger LOG = LoggerFactory.getLogger(getClass()); diff --git a/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IncrementalStoreTest.java b/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IncrementalStoreTest.java index 7dbe79b31f5..2345cad292f 100644 --- a/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IncrementalStoreTest.java +++ b/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IncrementalStoreTest.java @@ -20,7 +20,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.mongodb.MongoClientURI; +import com.mongodb.ConnectionString; import com.mongodb.client.MongoDatabase; import org.apache.commons.collections4.set.ListOrderedSet; import org.apache.commons.io.IOUtils; @@ -723,13 +723,13 @@ private Backend createNodeStore(boolean readOnly) { static class Backend { - private final MongoClientURI mongoURI; + private final ConnectionString mongoURI; final MongoDocumentStore mongoDocumentStore; final DocumentNodeStore documentNodeStore; final MongoDatabase mongoDatabase; final BlobStore blobStore; - public Backend(MongoClientURI mongoURI, MongoDocumentStore mongoDocumentStore, DocumentNodeStore documentNodeStore, MongoDatabase mongoDatabase, BlobStore blobStore) { + public Backend(ConnectionString mongoURI, MongoDocumentStore mongoDocumentStore, DocumentNodeStore documentNodeStore, MongoDatabase mongoDatabase, BlobStore blobStore) { this.mongoURI = mongoURI; this.mongoDocumentStore = mongoDocumentStore; this.documentNodeStore = documentNodeStore; From 9840ccc518b84078780a3fe9b13c15474e7c371d Mon Sep 17 00:00:00 2001 From: raffaega Date: Sat, 5 Oct 2024 00:00:00 +0200 Subject: [PATCH 06/10] Reordered imports like original classes --- .../document/DocumentNodeStoreService.java | 226 +++++++++--------- .../document/mongo/MongoBlobStore.java | 17 +- .../document/mongo/MongoDBConnection.java | 52 ++-- .../MongoDocumentNodeStoreBuilderBase.java | 74 +++--- .../document/mongo/MongoDocumentStore.java | 58 ++--- .../document/mongo/MongoSessionFactory.java | 35 +-- .../plugins/document/mongo/MongoStatus.java | 78 +++--- .../document/mongo/MongoVersionGCSupport.java | 2 + .../document/mongo/ReplicaSetStatus.java | 60 ++--- .../plugins/document/mongo/RevisionEntry.java | 5 +- .../document/util/MongoConnection.java | 22 +- .../oak/fixture/DocumentMongoFixture.java | 23 +- .../document/AbstractMongoConnectionTest.java | 29 ++- .../plugins/document/BlobThroughPutTest.java | 11 +- .../document/CacheConsistencyTest.java | 11 +- .../oak/plugins/document/ClusterInfoTest.java | 3 + .../ConcurrentPrefetchAndUpdateIT.java | 15 +- .../document/DocumentMKBuilderTest.java | 10 +- .../DocumentNodeStoreServiceTest.java | 21 +- .../oak/plugins/document/MongoDbTest.java | 2 + .../document/VersionGCSupportTest.java | 39 +-- .../mongo/AcquireRecoveryLockTest.java | 15 +- .../document/mongo/ClusterConflictTest.java | 8 +- .../document/mongo/MongoConnectionTest.java | 16 +- .../document/mongo/MongoDBConfigTest.java | 19 +- 25 files changed, 475 insertions(+), 376 deletions(-) diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java index 44b794c09e8..1349fb8e17d 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java @@ -1,12 +1,19 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work - * for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations * under the License. */ package org.apache.jackrabbit.oak.plugins.document; @@ -23,6 +30,7 @@ import static org.apache.jackrabbit.oak.spi.blob.osgi.SplitBlobStoreService.ONLY_STANDALONE_TARGET; import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean; import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.scheduleWithFixedDelay; + import java.io.Closeable; import java.io.IOException; import java.text.ParseException; @@ -39,17 +47,30 @@ import java.util.concurrent.TimeUnit; import java.util.function.Predicate; import java.util.function.Supplier; + import javax.sql.DataSource; -import org.apache.commons.io.FilenameUtils; -import org.apache.jackrabbit.commons.SimpleValueFactory; + import org.apache.jackrabbit.guava.common.base.Strings; import org.apache.jackrabbit.guava.common.io.Closer; import org.apache.jackrabbit.guava.common.util.concurrent.UncheckedExecutionException; +import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings; + +import org.apache.commons.io.FilenameUtils; +import org.apache.jackrabbit.commons.SimpleValueFactory; import org.apache.jackrabbit.oak.api.Descriptors; import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean; import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean; import org.apache.jackrabbit.oak.api.jmx.PersistentCacheStatsMBean; import org.apache.jackrabbit.oak.cache.CacheStats; +import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats; +import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder; +import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; +import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStoreMetrics; +import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder; +import org.apache.jackrabbit.oak.plugins.document.spi.lease.LeaseFailureHandler; +import org.apache.jackrabbit.oak.plugins.document.util.Utils; +import org.apache.jackrabbit.oak.spi.commit.ObserverTracker; import org.apache.jackrabbit.oak.osgi.OsgiWhiteboard; import org.apache.jackrabbit.oak.plugins.blob.BlobGC; import org.apache.jackrabbit.oak.plugins.blob.BlobGCMBean; @@ -59,23 +80,14 @@ import org.apache.jackrabbit.oak.plugins.blob.SharedDataStore; import org.apache.jackrabbit.oak.plugins.blob.datastore.BlobIdTracker; import org.apache.jackrabbit.oak.plugins.blob.datastore.SharedDataStoreUtils; -import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStoreMetrics; import org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCacheStats; -import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder; -import org.apache.jackrabbit.oak.plugins.document.spi.lease.LeaseFailureHandler; import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; -import org.apache.jackrabbit.oak.plugins.document.util.Utils; +import org.apache.jackrabbit.oak.spi.cluster.ClusterRepositoryInfo; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.blob.BlobStoreWrapper; import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore; import org.apache.jackrabbit.oak.spi.blob.stats.BlobStoreStatsMBean; -import org.apache.jackrabbit.oak.spi.cluster.ClusterRepositoryInfo; import org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean; -import org.apache.jackrabbit.oak.spi.commit.ObserverTracker; -import org.apache.jackrabbit.oak.spi.descriptors.GenericDescriptors; import org.apache.jackrabbit.oak.spi.gc.DelegatingGCMonitor; import org.apache.jackrabbit.oak.spi.gc.GCMonitor; import org.apache.jackrabbit.oak.spi.gc.GCMonitorTracker; @@ -92,6 +104,7 @@ import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard; import org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardExecutor; import org.apache.jackrabbit.oak.stats.StatisticsProvider; +import org.apache.jackrabbit.oak.spi.descriptors.GenericDescriptors; import org.jetbrains.annotations.NotNull; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; @@ -109,8 +122,6 @@ import org.quartz.CronExpression; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.mongodb.ConnectionString; -import com.mongodb.MongoClientSettings; /** * The OSGi service to start/stop a DocumentNodeStore instance. @@ -136,11 +147,11 @@ public class DocumentNodeStoreService { static final boolean DEFAULT_CUSTOM_BLOB_STORE = false; public static final String CONTINUOUS_RGC_EXPR = "*/5 * * * * ?"; public static final String CLASSIC_RGC_EXPR = "0 0 2 * * ?"; - public static final long DEFAULT_RGC_TIME_LIMIT_SECS = 3 * 60 * 60; // default is 3 hours + public static final long DEFAULT_RGC_TIME_LIMIT_SECS = 3*60*60; // default is 3 hours public static final double DEFAULT_RGC_DELAY_FACTOR = 0; private static final String DESCRIPTION = "oak.nodestore.description"; - static final long DEFAULT_JOURNAL_GC_INTERVAL_MILLIS = 5 * 60 * 1000; // default is 5min - static final long DEFAULT_JOURNAL_GC_MAX_AGE_MILLIS = 24 * 60 * 60 * 1000; // default is 24hours + static final long DEFAULT_JOURNAL_GC_INTERVAL_MILLIS = 5*60*1000; // default is 5min + static final long DEFAULT_JOURNAL_GC_MAX_AGE_MILLIS = 24*60*60*1000; // default is 24hours static final boolean DEFAULT_PREFETCH_EXTERNAL_CHANGES = false; private static final String DEFAULT_PROP_HOME = "./repository"; static final long DEFAULT_MAX_REPLICATION_LAG = 6 * 60 * 60; @@ -150,7 +161,7 @@ public class DocumentNodeStoreService { /** * Revisions older than this time would be garbage collected */ - static final long DEFAULT_VER_GC_MAX_AGE = 24 * 60 * 60; // TimeUnit.DAYS.toSeconds(1); + static final long DEFAULT_VER_GC_MAX_AGE = 24 * 60 * 60; //TimeUnit.DAYS.toSeconds(1); /** @@ -195,8 +206,7 @@ public class DocumentNodeStoreService { public static final String PROP_DS_TYPE = "documentStoreType"; private enum DocumentStoreType { - MONGO, - RDB; + MONGO, RDB; static DocumentStoreType fromString(String type) { if (type == null) { @@ -343,15 +353,14 @@ private void registerNodeStore() throws IOException { log.info("Connected to database '{}'", db); } - if (!customBlobStore) { + if (!customBlobStore){ defaultBlobStore = mkBuilder.getBlobStore(); log.info("Registering the BlobStore with ServiceRegistry"); - blobStoreReg = context.getBundleContext() - .registerService(BlobStore.class.getName(), - defaultBlobStore, null); + blobStoreReg = context.getBundleContext().registerService(BlobStore.class.getName(), + defaultBlobStore , null); } - // Set wrapping blob store after setting the DB + //Set wrapping blob store after setting the DB if (isWrappingCustomBlobStore()) { ((BlobStoreWrapper) blobStore).setBlobStore(mkBuilder.getBlobStore()); mkBuilder.setBlobStore(blobStore); @@ -375,15 +384,14 @@ private void registerNodeStore() throws IOException { nodeStore = mkBuilder.build(); - // ensure a clusterId is initialized + // ensure a clusterId is initialized // and expose it as 'oak.clusterid' repository descriptor GenericDescriptors clusterIdDesc = new GenericDescriptors(); - clusterIdDesc.put(ClusterRepositoryInfo.OAK_CLUSTERID_REPOSITORY_DESCRIPTOR_KEY, + clusterIdDesc.put(ClusterRepositoryInfo.OAK_CLUSTERID_REPOSITORY_DESCRIPTOR_KEY, new SimpleValueFactory().createValue( - ClusterRepositoryInfo.getOrCreateId(nodeStore)), - true, false); + ClusterRepositoryInfo.getOrCreateId(nodeStore)), true, false); whiteboard.register(Descriptors.class, clusterIdDesc, Collections.emptyMap()); - + // If a shared data store register the repo id in the data store if (SharedDataStoreUtils.isShared(blobStore)) { String repoId = null; @@ -397,13 +405,12 @@ private void registerNodeStore() throws IOException { if (blobStore instanceof BlobTrackingStore) { BlobTrackingStore trackingStore = (BlobTrackingStore) blobStore; if (trackingStore.getTracker() != null) { - trackingStore.getTracker() - .close(); + trackingStore.getTracker().close(); } ((BlobTrackingStore) blobStore).addTracker( - BlobIdTracker.build(getRepositoryHome(), repoId, - config.blobTrackSnapshotIntervalInSecs(), - (SharedDataStore) blobStore)); + BlobIdTracker.build(getRepositoryHome(), repoId, + config.blobTrackSnapshotIntervalInSecs(), + (SharedDataStore) blobStore)); } } @@ -425,12 +432,12 @@ private void registerNodeStore() throws IOException { String[] serviceClasses; if (isNodeStoreProvider()) { registerNodeStoreProvider(nodeStore); - serviceClasses = new String[] { + serviceClasses = new String[]{ DocumentNodeStore.class.getName(), Clusterable.class.getName() }; } else { - serviceClasses = new String[] { + serviceClasses = new String[]{ NodeStore.class.getName(), DocumentNodeStore.class.getName(), Clusterable.class.getName() @@ -443,18 +450,16 @@ private void registerNodeStore() throws IOException { // OAK-2844: in order to allow DocumentDiscoveryLiteService to directly // require a service DocumentNodeStore (instead of having to do an 'instanceof') // the registration is now done for both NodeStore and DocumentNodeStore here. - nodeStoreReg = context.getBundleContext() - .registerService( - serviceClasses, - nodeStore, props); + nodeStoreReg = context.getBundleContext().registerService( + serviceClasses, + nodeStore, props); } private LeaseFailureHandler createDefaultLeaseFailureHandler() { return new LeaseFailureHandler() { @Override public void handleLeaseFailure() { - Bundle bundle = context.getBundleContext() - .getBundle(); + Bundle bundle = context.getBundleContext().getBundle(); String bundleName = bundle.getSymbolicName(); try { // plan A: try stopping oak-store-document @@ -549,7 +554,7 @@ public void handleLeaseFailure() { builder.setJournalCache(journalCache); } - // Set blobstore before setting the document store + //Set blobstore before setting the document store if (customBlobStore && !isWrappingCustomBlobStore()) { requireNonNull(blobStore, String.format("Use of custom BlobStore enabled via [%s] but blobStore reference not " + "initialized", CUSTOM_BLOB_STORE)); @@ -573,7 +578,7 @@ private Predicate createCachePredicate() { if (config.persistentCacheIncludes().length == 0) { return x -> true; } - if (Arrays.equals(config.persistentCacheIncludes(), new String[] {"/"})) { + if (Arrays.equals(config.persistentCacheIncludes(), new String[]{"/"})) { return x -> true; } @@ -629,11 +634,10 @@ private String getVersionGCExpression() { private void registerNodeStoreProvider(final NodeStore ns) { Dictionary props = new Hashtable<>(); props.put(NodeStoreProvider.ROLE, config.role()); - nodeStoreReg = context.getBundleContext() - .registerService( - NodeStoreProvider.class.getName(), - (NodeStoreProvider) () -> ns, - props); + nodeStoreReg = context.getBundleContext().registerService( + NodeStoreProvider.class.getName(), + (NodeStoreProvider) () -> ns, + props); log.info("Registered NodeStoreProvider backed by DocumentNodeStore"); } @@ -643,7 +647,7 @@ protected void deactivate() { observerTracker.stop(); } - if (journalPropertyHandlerFactory != null) { + if (journalPropertyHandlerFactory != null){ journalPropertyHandlerFactory.stop(); } @@ -673,10 +677,11 @@ protected void deactivate() { @Reference(name = "blobStore", cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC, - target = ONLY_STANDALONE_TARGET) + target = ONLY_STANDALONE_TARGET + ) @SuppressWarnings("UnusedDeclaration") protected void bindBlobStore(BlobStore blobStore) throws IOException { - if (defaultBlobStore == blobStore) { + if (defaultBlobStore == blobStore){ return; } log.info("Initializing DocumentNodeStore with BlobStore [{}]", blobStore); @@ -686,7 +691,7 @@ protected void bindBlobStore(BlobStore blobStore) throws IOException { @SuppressWarnings("UnusedDeclaration") protected void unbindBlobStore(BlobStore blobStore) { - if (defaultBlobStore == blobStore) { + if (defaultBlobStore == blobStore){ return; } this.blobStore = null; @@ -696,7 +701,8 @@ protected void unbindBlobStore(BlobStore blobStore) { @Reference(name = "dataSource", cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC, - target = "(datasource.name=oak)") + target = "(datasource.name=oak)" + ) @SuppressWarnings("UnusedDeclaration") protected void bindDataSource(DataSource dataSource) throws IOException { if (this.dataSource != null) { @@ -725,7 +731,8 @@ protected void unbindDataSource(DataSource dataSource) { @Reference(name = "blobDataSource", cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC, - target = "(datasource.name=oak)") + target = "(datasource.name=oak)" + ) @SuppressWarnings("UnusedDeclaration") protected void bindBlobDataSource(DataSource dataSource) throws IOException { if (this.blobDataSource != null) { @@ -751,18 +758,19 @@ protected void unbindBlobDataSource(DataSource dataSource) { @Reference(name = "nodeStateCache", cardinality = ReferenceCardinality.OPTIONAL, - policy = ReferencePolicy.DYNAMIC) + policy = ReferencePolicy.DYNAMIC + ) @SuppressWarnings("UnusedDeclaration") protected void bindNodeStateCache(DocumentNodeStateCache nodeStateCache) throws IOException { - if (nodeStore != null) { - log.info("Registered DocumentNodeStateCache [{}] with DocumentNodeStore", nodeStateCache); - nodeStore.setNodeStateCache(nodeStateCache); - } + if (nodeStore != null){ + log.info("Registered DocumentNodeStateCache [{}] with DocumentNodeStore", nodeStateCache); + nodeStore.setNodeStateCache(nodeStateCache); + } } @SuppressWarnings("UnusedDeclaration") protected void unbindNodeStateCache(DocumentNodeStateCache nodeStateCache) { - if (nodeStore != null) { + if (nodeStore != null){ nodeStore.setNodeStateCache(DocumentNodeStateCache.NOOP); } } @@ -777,11 +785,11 @@ private void unregisterNodeStore() { nodeStoreReg = null; } - // If we exposed our BlobStore then unregister it *after* - // NodeStore service. This ensures that if any other component - // like SecondaryStoreCache depends on this then it remains active - // untill DocumentNodeStore get deactivated - if (blobStoreReg != null) { + //If we exposed our BlobStore then unregister it *after* + //NodeStore service. This ensures that if any other component + //like SecondaryStoreCache depends on this then it remains active + //untill DocumentNodeStore get deactivated + if (blobStoreReg != null){ blobStoreReg.unregister(); blobStoreReg = null; } @@ -797,7 +805,8 @@ private void unregisterNodeStore() { } } - private void registerJMXBeans(final DocumentNodeStore store, DocumentNodeStoreBuilder mkBuilder) throws IOException { + private void registerJMXBeans(final DocumentNodeStore store, DocumentNodeStoreBuilder mkBuilder) throws + IOException { registerCacheStatsMBean(store.getNodeCacheStats()); registerCacheStatsMBean(store.getNodeChildrenCacheStats()); for (CacheStats cs : store.getDiffCacheStats()) { @@ -816,7 +825,8 @@ private void registerJMXBeans(final DocumentNodeStore store, DocumentNodeStoreBu CheckpointMBean.class, new DocumentCheckpointMBean(store), CheckpointMBean.TYPE, - "Document node store checkpoint management")); + "Document node store checkpoint management") + ); } addRegistration( @@ -824,7 +834,8 @@ private void registerJMXBeans(final DocumentNodeStore store, DocumentNodeStoreBu DocumentNodeStoreMBean.class, store.getMBean(), DocumentNodeStoreMBean.TYPE, - "Document node store management")); + "Document node store management") + ); if (mkBuilder.getBlobStoreCacheStats() != null) { registerCacheStatsMBean(mkBuilder.getBlobStoreCacheStats()); @@ -836,43 +847,42 @@ private void registerJMXBeans(final DocumentNodeStore store, DocumentNodeStoreBu DocumentStoreStatsMBean.class, (DocumentStoreStatsMBean) mkBuilder.getDocumentStoreStatsCollector(), DocumentStoreStatsMBean.TYPE, - "DocumentStore Statistics")); + "DocumentStore Statistics") + ); } // register persistent cache stats Map persistenceCacheStats = mkBuilder.getPersistenceCacheStats(); - for (PersistentCacheStats pcs : persistenceCacheStats.values()) { + for (PersistentCacheStats pcs: persistenceCacheStats.values()) { addRegistration( registerMBean(whiteboard, PersistentCacheStatsMBean.class, pcs, PersistentCacheStatsMBean.TYPE, - pcs.getName())); + pcs.getName()) + ); } final long versionGcMaxAgeInSecs = config.versionGcMaxAgeInSecs(); final long blobGcMaxAgeInSecs = config.blobGcMaxAgeInSecs(); if (store.getBlobStore() instanceof GarbageCollectableBlobStore) { - BlobGarbageCollector gc = store.createBlobGarbageCollector(blobGcMaxAgeInSecs, - ClusterRepositoryInfo.getOrCreateId(nodeStore), - whiteboard, statisticsProvider); + BlobGarbageCollector gc = store.createBlobGarbageCollector(blobGcMaxAgeInSecs, + ClusterRepositoryInfo.getOrCreateId(nodeStore), + whiteboard, statisticsProvider); addRegistration(registerMBean(whiteboard, BlobGCMBean.class, new BlobGC(gc, executor), BlobGCMBean.TYPE, "Document node store blob garbage collection")); } Runnable startGC = new RevisionGCJob(store, versionGcMaxAgeInSecs, 0, DEFAULT_RGC_DELAY_FACTOR); - Runnable cancelGC = () -> store.getVersionGarbageCollector() - .cancel(); - Supplier status = () -> store.getVersionGarbageCollector() - .getStatus(); + Runnable cancelGC = () -> store.getVersionGarbageCollector().cancel(); + Supplier status = () -> store.getVersionGarbageCollector().getStatus(); RevisionGC revisionGC = new RevisionGC(startGC, cancelGC, status, executor); addRegistration(registerMBean(whiteboard, RevisionGCMBean.class, revisionGC, RevisionGCMBean.TYPE, "Document node store revision garbage collection")); addRegistration(registerMBean(whiteboard, RevisionGCStatsMBean.class, - store.getVersionGarbageCollector() - .getRevisionGCStats(), + store.getVersionGarbageCollector().getRevisionGCStats(), RevisionGCStatsMBean.TYPE, "Document node store revision garbage collection statistics")); @@ -882,15 +892,13 @@ private void registerJMXBeans(final DocumentNodeStore store, DocumentNodeStoreBu BlobStoreStatsMBean.class, blobStoreStats, BlobStoreStatsMBean.TYPE, - ds.getClass() - .getSimpleName())); + ds.getClass().getSimpleName())); } - if (!mkBuilder.isBundlingDisabled()) { + if (!mkBuilder.isBundlingDisabled()){ addRegistration(registerMBean(whiteboard, BackgroundObserverMBean.class, - store.getBundlingConfigHandler() - .getMBean(), + store.getBundlingConfigHandler().getMBean(), BackgroundObserverMBean.TYPE, "BundlingConfigObserver")); } @@ -902,12 +910,11 @@ private void registerCacheStatsMBean(CacheStats cacheStats) { } private void registerLastRevRecoveryJob(final DocumentNodeStore nodeStore) { - long leaseTime = toLong(context.getProperties() - .get(PROP_REV_RECOVERY_INTERVAL), + long leaseTime = toLong(context.getProperties().get(PROP_REV_RECOVERY_INTERVAL), ClusterNodeInfo.DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS); addRegistration(scheduleWithFixedDelay(whiteboard, new LastRevRecoveryJob(nodeStore), TimeUnit.MILLISECONDS.toSeconds(leaseTime), - false/* runOnSingleClusterNode */, true /* use dedicated pool */)); + false/*runOnSingleClusterNode*/, true /*use dedicated pool*/)); } private void registerJournalGC(final DocumentNodeStore nodeStore) { @@ -915,7 +922,7 @@ private void registerJournalGC(final DocumentNodeStore nodeStore) { new JournalGCJob(nodeStore), jobPropertiesFor(JournalGCJob.class), TimeUnit.MILLISECONDS.toSeconds(config.journalGCInterval()), - true/* runOnSingleClusterNode */, true /* use dedicated pool */)); + true/*runOnSingleClusterNode*/, true /*use dedicated pool*/)); } private void registerVersionGCJob(final DocumentNodeStore nodeStore) { @@ -1016,9 +1023,9 @@ static final class RevisionGCJob implements Runnable, Supplier { private VersionGCStats stats; RevisionGCJob(DocumentNodeStore ns, - long versionGcMaxAgeInSecs, - long versionGCTimeLimitInSecs, - double versionGCDelayFactor) { + long versionGcMaxAgeInSecs, + long versionGCTimeLimitInSecs, + double versionGCDelayFactor) { this.nodeStore = ns; this.versionGCMaxAgeInSecs = versionGcMaxAgeInSecs; this.versionGCTimeLimitInSecs = versionGCTimeLimitInSecs; @@ -1029,9 +1036,7 @@ static final class RevisionGCJob implements Runnable, Supplier { @Override public void run() { VersionGarbageCollector gc = nodeStore.getVersionGarbageCollector(); - gc.setOptions(gc.getOptions() - .withMaxDuration(TimeUnit.SECONDS, versionGCTimeLimitInSecs) - .withDelayFactor(versionGCDelayFactor)); + gc.setOptions(gc.getOptions().withMaxDuration(TimeUnit.SECONDS, versionGCTimeLimitInSecs).withDelayFactor(versionGCDelayFactor)); try { VersionGCStats s = gc.gc(versionGCMaxAgeInSecs, TimeUnit.SECONDS); stats.addRun(s); @@ -1049,7 +1054,8 @@ public void run() { } /** - * Returns the result of the last revision GC run. This method throws an {@link UncheckedExecutionException} if the last run failed with an + * Returns the result of the last revision GC run. This method throws + * an {@link UncheckedExecutionException} if the last run failed with an * exception. * * @return result of the last revision GC run. @@ -1063,14 +1069,12 @@ public String get() throws UncheckedExecutionException { } private void resetStats() { - lastLogTime = nodeStore.getClock() - .getTime(); + lastLogTime = nodeStore.getClock().getTime(); stats = new VersionGCStats(); } private void maybeLogStats() { - if (nodeStore.getClock() - .getTime() > lastLogTime + LOG_INTERVAL) { + if (nodeStore.getClock().getTime() > lastLogTime + LOG_INTERVAL) { LOGGER.info("Garbage collector stats since {}: {}", Utils.timestampToString(lastLogTime), stats); resetStats(); @@ -1088,8 +1092,7 @@ private static final class JournalGCJob implements Runnable { @Override public void run() { - nodeStore.getJournalGarbageCollector() - .gc(); + nodeStore.getJournalGarbageCollector().gc(); } } @@ -1103,8 +1106,7 @@ private static final class LastRevRecoveryJob implements Runnable { @Override public void run() { - nodeStore.getLastRevRecoveryAgent() - .performRecoveryIfNeeded(); + nodeStore.getLastRevRecoveryAgent().performRecoveryIfNeeded(); } } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoBlobStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoBlobStore.java index 315bf939581..4b0b5e304f2 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoBlobStore.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoBlobStore.java @@ -16,16 +16,16 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import static com.mongodb.ReadPreference.primary; -import static org.bson.codecs.configuration.CodecRegistries.fromCodecs; -import static org.bson.codecs.configuration.CodecRegistries.fromRegistries; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.stream.StreamSupport; -import org.apache.jackrabbit.guava.common.collect.AbstractIterator; + +import com.mongodb.ReadPreference; +import com.mongodb.client.model.UpdateOptions; +import com.mongodb.client.result.UpdateResult; import org.apache.jackrabbit.oak.commons.StringUtils; import org.apache.jackrabbit.oak.plugins.blob.CachingBlobStore; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder; @@ -36,16 +36,19 @@ import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import org.apache.jackrabbit.guava.common.collect.AbstractIterator; import com.mongodb.BasicDBObject; import com.mongodb.MongoClientSettings; import com.mongodb.MongoException; -import com.mongodb.ReadPreference; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoCursor; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Filters; -import com.mongodb.client.model.UpdateOptions; -import com.mongodb.client.result.UpdateResult; + +import static com.mongodb.ReadPreference.primary; +import static org.bson.codecs.configuration.CodecRegistries.fromCodecs; +import static org.bson.codecs.configuration.CodecRegistries.fromRegistries; /** * Implementation of blob store for the MongoDB extending from diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConnection.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConnection.java index 117dd0cd667..6dfdda9f3d7 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConnection.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConnection.java @@ -1,23 +1,21 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work - * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - * under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.oak.plugins.document.util.MongoConnection.readConcernLevel; -import java.util.concurrent.TimeUnit; -import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.mongodb.BasicDBObject; import com.mongodb.ConnectionString; import com.mongodb.MongoClientSettings.Builder; @@ -28,6 +26,15 @@ import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; +import java.util.concurrent.TimeUnit; +import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static java.util.Objects.requireNonNull; +import static org.apache.jackrabbit.oak.plugins.document.util.MongoConnection.readConcernLevel; + /** * Simple struct that contains {@code MongoClient}, {@code MongoDatabase} and {@code MongoStatus}. */ @@ -42,9 +49,9 @@ final class MongoDBConnection { private final MongoSessionFactory sessionFactory; MongoDBConnection(@NotNull MongoClient client, - @NotNull MongoDatabase database, - @NotNull MongoStatus status, - @NotNull MongoClock clock) { + @NotNull MongoDatabase database, + @NotNull MongoStatus status, + @NotNull MongoClock clock) { this.client = requireNonNull(client); this.db = requireNonNull(database); this.status = requireNonNull(status); @@ -53,10 +60,10 @@ final class MongoDBConnection { } static MongoDBConnection newMongoDBConnection(@NotNull String uri, - @NotNull String name, - @NotNull MongoClock clock, - int socketTimeout, - boolean socketKeepAlive) { + @NotNull String name, + @NotNull MongoClock clock, + int socketTimeout, + boolean socketKeepAlive) { CompositeServerMonitorListener serverMonitorListener = new CompositeServerMonitorListener(); ConnectionString connectionString = new ConnectionString(uri); @@ -122,7 +129,8 @@ void close() { } /** - * Checks read and write concern on the {@code MongoDatabase} and logs warn messages when they differ from the recommended values. + * Checks read and write concern on the {@code MongoDatabase} and logs warn + * messages when they differ from the recommended values. */ void checkReadWriteConcern() { if (!MongoConnection.isSufficientWriteConcern(client, db.getWriteConcern())) { diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentNodeStoreBuilderBase.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentNodeStoreBuilderBase.java index 50d89b5980a..24ea29c3797 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentNodeStoreBuilderBase.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentNodeStoreBuilderBase.java @@ -1,19 +1,25 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work - * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - * under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import static org.apache.jackrabbit.guava.common.base.Suppliers.memoize; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConnection.newMongoDBConnection; import java.util.concurrent.TimeUnit; + +import com.mongodb.client.MongoClient; + import org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder; @@ -21,10 +27,13 @@ import org.apache.jackrabbit.oak.plugins.document.MissingLastRevSeeker; import org.apache.jackrabbit.oak.plugins.document.VersionGCSupport; import org.jetbrains.annotations.NotNull; -import com.mongodb.client.MongoClient; + +import static org.apache.jackrabbit.guava.common.base.Suppliers.memoize; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConnection.newMongoDBConnection; /** - * A base builder implementation for a {@link DocumentNodeStore} backed by MongoDB. + * A base builder implementation for a {@link DocumentNodeStore} backed by + * MongoDB. */ public abstract class MongoDocumentNodeStoreBuilderBase> extends DocumentNodeStoreBuilder { @@ -41,18 +50,22 @@ public abstract class MongoDocumentNodeStoreBuilderBase new MongoBlobStore(mongoDBConnection.getDatabase(), blobCacheSizeMB * 1024 * 1024L, - MongoDocumentNodeStoreBuilderBase.this)); + () -> new MongoBlobStore(mongoDBConnection.getDatabase(), blobCacheSizeMB * 1024 * 1024L, MongoDocumentNodeStoreBuilderBase.this)); } return thisBuilder(); diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java index 2dc68ae4f09..11bc8e83833 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java @@ -16,30 +16,6 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import static com.mongodb.client.model.Projections.include; -import static java.lang.Integer.MAX_VALUE; -import static java.util.Collections.emptyList; -import static java.util.Objects.isNull; -import static java.util.concurrent.TimeUnit.NANOSECONDS; -import static java.util.stream.Collectors.toList; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; -import static org.apache.jackrabbit.guava.common.collect.Maps.filterKeys; -import static org.apache.jackrabbit.guava.common.collect.Sets.difference; -import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; -import static org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.asDocumentStoreException; -import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.DELETED_ONCE; -import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS; -import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.NULL; -import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_MAX_REV_TIME_IN_SECS; -import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_TYPE; -import static org.apache.jackrabbit.oak.plugins.document.Throttler.NO_THROTTLING; -import static org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition.newEqualsCondition; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoThrottlerFactory.exponentialThrottler; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.createIndex; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.createPartialIndex; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.getDocumentStoreExceptionTypeFor; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.hasIndex; -import static org.apache.jackrabbit.oak.plugins.document.util.Utils.isThrottlingEnabled; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -52,10 +28,10 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.TreeMap; +import java.util.Objects; +import java.util.Optional; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -63,6 +39,7 @@ import java.util.concurrent.locks.Lock; import java.util.function.Consumer; import java.util.stream.StreamSupport; + import org.apache.jackrabbit.guava.common.base.Stopwatch; import org.apache.jackrabbit.guava.common.collect.ImmutableList; import org.apache.jackrabbit.guava.common.collect.ImmutableMap; @@ -75,7 +52,6 @@ import org.apache.jackrabbit.guava.common.util.concurrent.UncheckedExecutionException; import org.apache.jackrabbit.oak.cache.CacheStats; import org.apache.jackrabbit.oak.cache.CacheValue; -import org.apache.jackrabbit.oak.commons.PerfLogger; import org.apache.jackrabbit.oak.plugins.document.Collection; import org.apache.jackrabbit.oak.plugins.document.Document; import org.apache.jackrabbit.oak.plugins.document.DocumentStore; @@ -85,8 +61,8 @@ import org.apache.jackrabbit.oak.plugins.document.NodeDocument; import org.apache.jackrabbit.oak.plugins.document.Revision; import org.apache.jackrabbit.oak.plugins.document.StableRevisionComparator; -import org.apache.jackrabbit.oak.plugins.document.Throttler; import org.apache.jackrabbit.oak.plugins.document.UpdateOp; +import org.apache.jackrabbit.oak.plugins.document.Throttler; import org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition; import org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key; import org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation; @@ -99,6 +75,7 @@ import org.apache.jackrabbit.oak.plugins.document.locks.StripedNodeDocumentLocks; import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.apache.jackrabbit.oak.stats.Clock; +import org.apache.jackrabbit.oak.commons.PerfLogger; import org.bson.BSONException; import org.bson.BsonMaximumSizeExceededException; import org.bson.conversions.Bson; @@ -137,6 +114,31 @@ import com.mongodb.client.result.DeleteResult; import com.mongodb.client.result.UpdateResult; +import static java.util.Objects.isNull; +import static java.util.concurrent.TimeUnit.NANOSECONDS; +import static java.util.stream.Collectors.toList; +import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; +import static org.apache.jackrabbit.guava.common.collect.Maps.filterKeys; +import static org.apache.jackrabbit.guava.common.collect.Sets.difference; +import static com.mongodb.client.model.Projections.include; +import static java.lang.Integer.MAX_VALUE; +import static java.util.Collections.emptyList; +import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; +import static org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.asDocumentStoreException; +import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.DELETED_ONCE; +import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS; +import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.NULL; +import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_MAX_REV_TIME_IN_SECS; +import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_TYPE; +import static org.apache.jackrabbit.oak.plugins.document.Throttler.NO_THROTTLING; +import static org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition.newEqualsCondition; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoThrottlerFactory.exponentialThrottler; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.createIndex; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.createPartialIndex; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.getDocumentStoreExceptionTypeFor; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.hasIndex; +import static org.apache.jackrabbit.oak.plugins.document.util.Utils.isThrottlingEnabled; + /** * A document store that uses MongoDB as the backend. */ diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoSessionFactory.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoSessionFactory.java index 780e8f8f8d3..a9f5fe98713 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoSessionFactory.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoSessionFactory.java @@ -1,28 +1,34 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work - * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - * under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import org.bson.BsonDocument; -import org.bson.BsonTimestamp; -import org.jetbrains.annotations.NotNull; import com.mongodb.ClientSessionOptions; +import com.mongodb.client.MongoClient; import com.mongodb.ServerAddress; import com.mongodb.TransactionOptions; import com.mongodb.client.ClientSession; -import com.mongodb.client.MongoClient; import com.mongodb.client.TransactionBody; import com.mongodb.internal.TimeoutContext; import com.mongodb.session.ServerSession; +import org.bson.BsonDocument; +import org.bson.BsonTimestamp; +import org.jetbrains.annotations.NotNull; + /** * Factory for {@link ClientSession}s. */ @@ -39,12 +45,11 @@ class MongoSessionFactory { private BsonTimestamp operationTime; MongoSessionFactory(@NotNull MongoClient client, - @NotNull MongoClock clock) { + @NotNull MongoClock clock) { this.client = client; this.clock = clock; this.options = ClientSessionOptions.builder() - .causallyConsistent(true) - .build(); + .causallyConsistent(true).build(); } ClientSession createClientSession() { @@ -151,7 +156,7 @@ public T withTransaction(@NotNull TransactionBody transactionBody) { @NotNull @Override public T withTransaction(@NotNull TransactionBody transactionBody, - @NotNull TransactionOptions options) { + @NotNull TransactionOptions options) { return session.withTransaction(transactionBody, options); } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatus.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatus.java index ece3d0501e2..6d355bdc3d4 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatus.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatus.java @@ -1,32 +1,30 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work - * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - * under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Maps; -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.mongodb.BasicDBObject; import com.mongodb.ClientSessionOptions; +import com.mongodb.client.MongoClient; import com.mongodb.MongoClientException; import com.mongodb.MongoCommandException; import com.mongodb.MongoQueryException; import com.mongodb.ReadConcern; -import com.mongodb.client.MongoClient; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoCursor; import com.mongodb.event.ServerHeartbeatFailedEvent; @@ -35,11 +33,20 @@ import com.mongodb.event.ServerMonitorListener; import com.mongodb.session.ClientSession; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class MongoStatus implements ServerMonitorListener { private static final Logger LOG = LoggerFactory.getLogger(MongoStatus.class); - private static final ImmutableSet SERVER_DETAIL_FIELD_NAMES = ImmutableSet.builder() + private static final ImmutableSet SERVER_DETAIL_FIELD_NAMES + = ImmutableSet.builder() .add("host", "process", "connections", "repl", "storageEngine", "mem") .build(); @@ -62,7 +69,7 @@ public class MongoStatus implements ServerMonitorListener { private final ReplicaSetStatus replicaSetStatus = new ReplicaSetStatus(); public MongoStatus(@NotNull MongoClient client, - @NotNull String dbName) { + @NotNull String dbName) { this.client = client; this.dbName = dbName; } @@ -76,8 +83,9 @@ public void checkVersion() { } /** - * Check if the majority read concern is supported by this storage engine. The fact that read concern is supported doesn't it can be used - it - * also has to be enabled. + * Check if the majority read concern is supported by this storage engine. + * The fact that read concern is supported doesn't it can be used - it also + * has to be enabled. * * @return true if the majority read concern is supported */ @@ -113,8 +121,7 @@ public boolean isMajorityReadConcernEnabled() { .getCollection("emptyCollection-" + System.currentTimeMillis()); try (MongoCursor cursor = emptyCollection .withReadConcern(ReadConcern.MAJORITY) - .find(new BasicDBObject()) - .iterator()) { + .find(new BasicDBObject()).iterator()) { cursor.hasNext(); majorityReadConcernEnabled = true; } catch (MongoQueryException | IllegalArgumentException e) { @@ -152,8 +159,7 @@ public String getVersion() { boolean isVersion(int requiredMajor, int requiredMinor) { String v = getVersion(); - Matcher m = Pattern.compile("^(\\d+)\\.(\\d+)\\..*") - .matcher(v); + Matcher m = Pattern.compile("^(\\d+)\\.(\\d+)\\..*").matcher(v); if (!m.matches()) { throw new IllegalArgumentException("Malformed MongoDB version: " + v); } @@ -177,8 +183,7 @@ boolean isClientSessionSupported() { // must be at least 3.6 if (isVersion(3, 6)) { ClientSessionOptions options = ClientSessionOptions.builder() - .causallyConsistent(true) - .build(); + .causallyConsistent(true).build(); try (ClientSession ignored = client.startSession(options)) { clientSessionSupported = true; } catch (MongoClientException e) { @@ -192,10 +197,13 @@ boolean isClientSessionSupported() { } /** - * Returns an estimate of the replica-set lag in milliseconds. The returned value is not an accurate measurement of the replication lag and should - * only be used as a rough estimate to decide whether secondaries can be used for queries in general. + * Returns an estimate of the replica-set lag in milliseconds. The returned + * value is not an accurate measurement of the replication lag and should + * only be used as a rough estimate to decide whether secondaries can be + * used for queries in general. *

- * This method may return {@link ReplicaSetStatus#UNKNOWN_LAG} if the value is currently unknown. + * This method may return {@link ReplicaSetStatus#UNKNOWN_LAG} if the value + * is currently unknown. * * @return an estimate of the */ @@ -203,7 +211,7 @@ long getReplicaSetLagEstimate() { return replicaSetStatus.getLagEstimate(); } - // ------------------------< ServerMonitorListener >------------------------- + //------------------------< ServerMonitorListener >------------------------- @Override public void serverHearbeatStarted(ServerHeartbeatStartedEvent event) { @@ -225,14 +233,13 @@ public void serverHeartbeatFailed(ServerHeartbeatFailedEvent event) { replicaSetStatus.serverHeartbeatFailed(event); } - // -------------------------------< internal >------------------------------- + //-------------------------------< internal >------------------------------- private BasicDBObject getServerStatus() { if (serverStatus == null) { try { - serverStatus = client.getDatabase(dbName) - .runCommand( - new BasicDBObject("serverStatus", 1), BasicDBObject.class); + serverStatus = client.getDatabase(dbName).runCommand( + new BasicDBObject("serverStatus", 1), BasicDBObject.class); } catch (MongoCommandException e) { if (e.getErrorCode() == -1) { // OAK-7485: workaround when running on @@ -253,9 +260,8 @@ private BasicDBObject getServerStatus() { private BasicDBObject getBuildInfo() { if (buildInfo == null) { - buildInfo = client.getDatabase(dbName) - .runCommand( - new BasicDBObject("buildInfo", 1), BasicDBObject.class); + buildInfo = client.getDatabase(dbName).runCommand( + new BasicDBObject("buildInfo", 1), BasicDBObject.class); } return buildInfo; } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoVersionGCSupport.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoVersionGCSupport.java index 317a172f461..6dade2a0898 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoVersionGCSupport.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoVersionGCSupport.java @@ -42,6 +42,7 @@ import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType.DEFAULT_NO_BRANCH; import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.hasIndex; import static org.apache.jackrabbit.oak.plugins.document.util.CloseableIterable.wrap; + import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -68,6 +69,7 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import com.mongodb.BasicDBObject; import com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatus.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatus.java index 0f44e837030..452c6c059ff 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatus.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatus.java @@ -1,13 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work - * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - * under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.jackrabbit.oak.plugins.document.mongo; @@ -22,20 +27,25 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; + +import com.mongodb.ServerAddress; +import com.mongodb.event.ServerHeartbeatSucceededEvent; +import com.mongodb.event.ServerMonitorListener; + import org.bson.BsonArray; import org.bson.BsonDocument; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.mongodb.ServerAddress; -import com.mongodb.event.ServerHeartbeatSucceededEvent; -import com.mongodb.event.ServerMonitorListener; /** - * Keeps track of the status of a replica set based on information provided by heartbeat events. This status provides a replica set lag estimate, - * which can be used to decide whether secondaries are sufficiently up-to-date and read operations can be sent to a secondary. This is particularly - * useful when causal consistent client sessions are used with the MongoDB Java driver. Read operations shouldn't be sent to a secondary when it lags - * too much behind, otherwise the read operation will block until it was able to catch up. + * Keeps track of the status of a replica set based on information provided + * by heartbeat events. This status provides a replica set lag estimate, which + * can be used to decide whether secondaries are sufficiently up-to-date and + * read operations can be sent to a secondary. This is particularly useful when + * causal consistent client sessions are used with the MongoDB Java driver. Read + * operations shouldn't be sent to a secondary when it lags too much behind, + * otherwise the read operation will block until it was able to catch up. */ public class ReplicaSetStatus implements ServerMonitorListener { @@ -57,9 +67,7 @@ public class ReplicaSetStatus implements ServerMonitorListener { @Override public void serverHeartbeatSucceeded(ServerHeartbeatSucceededEvent event) { synchronized (heartbeats) { - ServerAddress address = event.getConnectionId() - .getServerId() - .getAddress(); + ServerAddress address = event.getConnectionId().getServerId().getAddress(); Heartbeat beat = new Heartbeat(event); heartbeats.put(address, beat); members.addAll(beat.getHosts()); @@ -74,8 +82,7 @@ public long getLagEstimate() { } private void updateLag() { - if (!heartbeats.keySet() - .containsAll(members)) { + if (!heartbeats.keySet().containsAll(members)) { lagEstimate = UNKNOWN_LAG; return; } @@ -110,7 +117,7 @@ private void updateLag() { // average estimates over up to number of members and remove old value long estimate = 0; int i = 0; - for (Iterator it = estimatesPerMember.iterator(); it.hasNext();) { + for (Iterator it = estimatesPerMember.iterator(); it.hasNext(); ) { long v = it.next(); if (i++ < members.size()) { estimate += v; @@ -152,18 +159,14 @@ Date getLastWrite() { } private static List hostsFrom(ServerHeartbeatSucceededEvent event) { - return event.getReply() - .getArray("hosts", new BsonArray()) - .stream() - .map(bsonValue -> new ServerAddress(bsonValue.asString() - .getValue())) + return event.getReply().getArray("hosts", new BsonArray()).stream() + .map(bsonValue -> new ServerAddress(bsonValue.asString().getValue())) .collect(Collectors.toList()); } private static Date localTimeFrom(ServerHeartbeatSucceededEvent event) { BsonDocument reply = event.getReply(); - return new Date(reply.getDateTime("localTime") - .getValue()); + return new Date(reply.getDateTime("localTime").getValue()); } private static Date lastWriteFrom(ServerHeartbeatSucceededEvent event) { @@ -172,7 +175,6 @@ private static Date lastWriteFrom(ServerHeartbeatSucceededEvent event) { return null; } return new Date(reply.getDocument("lastWrite") - .getDateTime("lastWriteDate") - .getValue()); + .getDateTime("lastWriteDate").getValue()); } } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/RevisionEntry.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/RevisionEntry.java index d2a8430b6aa..2c7d777d0a7 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/RevisionEntry.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/RevisionEntry.java @@ -16,17 +16,20 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import static java.util.Objects.requireNonNull; import java.util.Collections; import java.util.Map; import java.util.Set; + import org.apache.jackrabbit.oak.plugins.document.Revision; import org.bson.BSONObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; + import com.mongodb.BasicDBObject; import com.mongodb.DBObject; +import static java.util.Objects.requireNonNull; + /** * A light-weight implementation of a MongoDB DBObject for a single revision * based map entry. diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/MongoConnection.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/MongoConnection.java index 96aaac789b6..da145439da2 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/MongoConnection.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/MongoConnection.java @@ -16,12 +16,11 @@ */ package org.apache.jackrabbit.oak.plugins.document.util; -import static java.util.Objects.requireNonNull; import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; + import org.apache.jackrabbit.guava.common.base.MoreObjects; -import org.jetbrains.annotations.NotNull; import com.mongodb.ConnectionString; import com.mongodb.MongoClientSettings; import com.mongodb.MongoClientSettings.Builder; @@ -38,6 +37,10 @@ import com.mongodb.connection.ServerSettings; import com.mongodb.connection.SocketSettings; +import static java.util.Objects.requireNonNull; + +import org.jetbrains.annotations.NotNull; + /** * The {@code MongoConnection} abstracts connection to the {@code MongoDB}. */ @@ -54,7 +57,8 @@ public class MongoConnection { private final MongoClient mongo; /** - * Constructs a new connection using the specified MongoDB connection string. See also http://docs.mongodb.org/manual/reference/connection-string/ + * Constructs a new connection using the specified MongoDB connection string. + * See also http://docs.mongodb.org/manual/reference/connection-string/ * * @param uri the MongoDB URI * @throws MongoException if there are failures @@ -64,7 +68,8 @@ public MongoConnection(String uri) throws MongoException { } /** - * Constructs a new connection using the specified MongoDB connection String. The default client options are taken from the provided builder. + * Constructs a new connection using the specified MongoDB connection + * String. The default client options are taken from the provided builder. * * @param uri the connection URI. * @param builder the client option defaults. @@ -123,7 +128,8 @@ public MongoClient getMongoClient() { } /** - * Returns the {@link MongoDatabase} as passed in the URI of the constructor. + * Returns the {@link MongoDatabase} as passed in the URI of the + * constructor. * * @return the {@link MongoDatabase}. */ @@ -154,7 +160,7 @@ public void close() { mongo.close(); } - // --------------------------------------< Utility Methods > + //--------------------------------------< Utility Methods > /** * Constructs a builder with default options set. These can be overridden later @@ -193,9 +199,9 @@ public static String toString(MongoClientSettings settings) { /** * Returns {@code true} if the given {@code uri} has a write concern set. - * * @param uri the URI to check. - * @return {@code true} if the URI has a write concern set, {@code false} otherwise. + * @return {@code true} if the URI has a write concern set, {@code false} + * otherwise. */ public static boolean hasMongoDbDefaultWriteConcern(@NotNull String uri) { ConnectionString connectionString = new ConnectionString(requireNonNull(uri)); diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/fixture/DocumentMongoFixture.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/fixture/DocumentMongoFixture.java index 9fe3d24980a..9446666d86f 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/fixture/DocumentMongoFixture.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/fixture/DocumentMongoFixture.java @@ -1,12 +1,19 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work - * for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations * under the License. */ @@ -15,6 +22,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; + import org.apache.jackrabbit.oak.plugins.document.DocumentMK; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; import org.apache.jackrabbit.oak.plugins.document.MongoUtils; @@ -25,6 +33,7 @@ import org.junit.AssumptionViolatedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import com.mongodb.ConnectionString; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; @@ -64,7 +73,7 @@ public NodeStore createNodeStore() { } builder.setPersistentCache("target/persistentCache,time"); builder.setMongoDB(createClient(), getDBName(suffix)); - // do not reuse the whiteboard + //do not reuse the whiteboard setWhiteboard(new DefaultWhiteboard()); builder.setNoChildOrderCleanupFeature(Feature.newFeature("FT_NOCOCLEANUP_OAK-10660", getWhiteboard())); DocumentNodeStore ns = builder.getNodeStore(); diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java index e081d792839..6b360915b45 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java @@ -1,16 +1,22 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work - * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - * under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.jackrabbit.oak.plugins.document; +import com.mongodb.client.MongoClient; import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; import org.apache.jackrabbit.oak.stats.Clock; @@ -19,11 +25,11 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; -import com.mongodb.client.MongoClient; /** - * Base class for test cases that need a {@link MongoConnection} to a clean test database. Tests in subclasses are automatically skipped if the - * configured MongoDB connection can not be created. + * Base class for test cases that need a {@link MongoConnection} + * to a clean test database. Tests in subclasses are automatically + * skipped if the configured MongoDB connection can not be created. */ public abstract class AbstractMongoConnectionTest extends DocumentMKTestBase { @@ -57,8 +63,7 @@ protected void setClusterNodeInfoClock(Clock c) { } protected DocumentMK.Builder newBuilder(MongoClient client, String dbName) throws Exception { - return addToBuilder(new DocumentMK.Builder()).clock(getTestClock()) - .setMongoDB(client, dbName); + return addToBuilder(new DocumentMK.Builder()).clock(getTestClock()).setMongoDB(client, dbName); } protected DocumentMK.Builder addToBuilder(DocumentMK.Builder mk) { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BlobThroughPutTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BlobThroughPutTest.java index c5084c84de8..ff32f035e26 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BlobThroughPutTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BlobThroughPutTest.java @@ -16,8 +16,6 @@ */ package org.apache.jackrabbit.oak.plugins.document; -import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount; -import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; @@ -28,10 +26,9 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; + import org.apache.commons.collections4.bidimap.DualHashBidiMap; import org.apache.jackrabbit.guava.common.io.ByteStreams; -import org.junit.Ignore; -import org.junit.Test; import com.mongodb.BasicDBObject; import com.mongodb.ConnectionString; import com.mongodb.WriteConcern; @@ -41,6 +38,12 @@ import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Filters; +import org.junit.Ignore; +import org.junit.Test; + +import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount; +import static org.junit.Assert.assertNotNull; + public class BlobThroughPutTest { private static final int NO_OF_NODES = 100; private static final int BLOB_SIZE = 1024 * 1024 * 2; diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTest.java index d379cf803f0..04ed05d4974 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTest.java @@ -16,13 +16,10 @@ */ package org.apache.jackrabbit.oak.plugins.document; -import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import java.util.Map; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; -import org.apache.jackrabbit.guava.common.collect.Maps; + import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.apache.jackrabbit.oak.spi.state.NodeState; @@ -30,10 +27,16 @@ import org.jetbrains.annotations.Nullable; import org.junit.Before; import org.junit.Test; + +import org.apache.jackrabbit.guava.common.collect.Maps; import com.mongodb.DBObject; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoDatabase; +import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + /** * Test for OAK-1897 */ diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterInfoTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterInfoTest.java index ee8df05b346..3e2bbd11324 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterInfoTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterInfoTest.java @@ -22,12 +22,15 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; + import java.util.List; + import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfo.ClusterNodeState; import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore; import org.apache.jackrabbit.oak.stats.Clock; import org.junit.After; import org.junit.Test; + import com.mongodb.ReadPreference; import com.mongodb.WriteConcern; diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentPrefetchAndUpdateIT.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentPrefetchAndUpdateIT.java index 64ea514dfbc..19732901439 100755 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentPrefetchAndUpdateIT.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentPrefetchAndUpdateIT.java @@ -16,15 +16,17 @@ */ package org.apache.jackrabbit.oak.plugins.document; -import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; import java.util.concurrent.atomic.AtomicLong; + import org.apache.jackrabbit.guava.common.collect.Lists; +import com.mongodb.DBObject; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoDatabase; + import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.jetbrains.annotations.NotNull; @@ -32,9 +34,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import com.mongodb.DBObject; -import com.mongodb.client.MongoClient; -import com.mongodb.client.MongoDatabase; + +import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; public class ConcurrentPrefetchAndUpdateIT extends AbstractMongoConnectionTest { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java index 40d1213dab9..dc0b1a6402e 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java @@ -16,16 +16,18 @@ */ package org.apache.jackrabbit.oak.plugins.document; +import org.apache.jackrabbit.guava.common.collect.Iterables; +import com.mongodb.client.MongoClient; + +import org.apache.jackrabbit.oak.cache.CacheStats; +import org.junit.Test; + import static org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_CHILDREN_CACHE_PERCENTAGE; import static org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_DIFF_CACHE_PERCENTAGE; import static org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_NODE_CACHE_PERCENTAGE; import static org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_PREV_DOC_CACHE_PERCENTAGE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import org.apache.jackrabbit.guava.common.collect.Iterables; -import org.apache.jackrabbit.oak.cache.CacheStats; -import org.junit.Test; -import com.mongodb.client.MongoClient; public class DocumentMKBuilderTest extends AbstractMongoConnectionTest { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java index b9f060fb549..689c91c1b7c 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java @@ -16,21 +16,15 @@ */ package org.apache.jackrabbit.oak.plugins.document; -import static org.apache.jackrabbit.oak.plugins.document.Configuration.PID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; -import static org.mockito.Mockito.mock; import java.io.File; import java.lang.reflect.Field; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; -import org.apache.commons.io.FilenameUtils; + import org.apache.jackrabbit.guava.common.collect.Maps; + +import org.apache.commons.io.FilenameUtils; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; import org.apache.jackrabbit.oak.plugins.document.spi.JournalPropertyService; import org.apache.jackrabbit.oak.plugins.document.spi.lease.LeaseFailureHandler; @@ -45,6 +39,15 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; +import static org.apache.jackrabbit.oak.plugins.document.Configuration.PID; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; +import static org.mockito.Mockito.mock; + public class DocumentNodeStoreServiceTest { @Rule diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoDbTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoDbTest.java index a8dbbde41c0..a706b052380 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoDbTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoDbTest.java @@ -18,10 +18,12 @@ import java.util.ArrayList; import java.util.List; + import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; import org.bson.conversions.Bson; import org.junit.Ignore; import org.junit.Test; + import com.mongodb.BasicDBObject; import com.mongodb.ExplainVerbosity; import com.mongodb.client.FindIterable; diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCSupportTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCSupportTest.java index e4f188e2d27..73044b74d43 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCSupportTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCSupportTest.java @@ -18,6 +18,27 @@ */ package org.apache.jackrabbit.oak.plugins.document; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.stream.StreamSupport; + +import com.mongodb.ReadPreference; + +import org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture.RDBFixture; +import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; +import org.apache.jackrabbit.oak.plugins.document.mongo.MongoTestUtils; +import org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport; +import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore; +import org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions; +import org.apache.jackrabbit.oak.plugins.document.rdb.RDBVersionGCSupport; +import org.apache.jackrabbit.oak.plugins.document.util.Utils; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + import static java.lang.Long.MAX_VALUE; import static java.util.Comparator.comparing; import static java.util.List.of; @@ -38,24 +59,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.stream.StreamSupport; -import org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture.RDBFixture; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoTestUtils; -import org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport; -import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore; -import org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions; -import org.apache.jackrabbit.oak.plugins.document.rdb.RDBVersionGCSupport; -import org.apache.jackrabbit.oak.plugins.document.util.Utils; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import com.mongodb.ReadPreference; @RunWith(Parameterized.class) public class VersionGCSupportTest { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/AcquireRecoveryLockTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/AcquireRecoveryLockTest.java index 068631a8182..5b975e07d75 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/AcquireRecoveryLockTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/AcquireRecoveryLockTest.java @@ -16,12 +16,10 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeNotNull; import java.util.List; + +import com.mongodb.client.MongoClient; + import org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest; import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfo; import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfoDocument; @@ -32,7 +30,12 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import com.mongodb.client.MongoClient; + +import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeNotNull; public class AcquireRecoveryLockTest extends AbstractMongoConnectionTest { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ClusterConflictTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ClusterConflictTest.java index 131db01d21f..5fb6af32322 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ClusterConflictTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ClusterConflictTest.java @@ -17,8 +17,8 @@ package org.apache.jackrabbit.oak.plugins.document.mongo; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import com.mongodb.client.MongoClient; + import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest; @@ -34,7 +34,9 @@ import org.apache.jackrabbit.oak.spi.state.NodeStore; import org.jetbrains.annotations.NotNull; import org.junit.Test; -import com.mongodb.client.MongoClient; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class ClusterConflictTest extends AbstractMongoConnectionTest { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoConnectionTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoConnectionTest.java index 18523abd898..150c4cfe67c 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoConnectionTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoConnectionTest.java @@ -16,19 +16,21 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; -import org.junit.Test; import com.mongodb.ReadConcern; import com.mongodb.WriteConcern; import com.mongodb.client.MongoClient; import com.mongodb.connection.ClusterDescription; import com.mongodb.connection.ClusterType; +import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class MongoConnectionTest { @Test diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConfigTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConfigTest.java index 114bf607987..0b5ae991f08 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConfigTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBConfigTest.java @@ -16,20 +16,21 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.COLLECTION_COMPRESSION_TYPE; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.STORAGE_CONFIG; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.STORAGE_ENGINE; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.getCollectionStorageOptions; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import java.util.Collections; +import com.mongodb.BasicDBObject; +import com.mongodb.MongoClientSettings; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.CollectionCompressor; import org.bson.BsonDocument; import org.bson.conversions.Bson; import org.junit.Test; -import com.mongodb.BasicDBObject; -import com.mongodb.MongoClientSettings; +import java.util.Collections; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.COLLECTION_COMPRESSION_TYPE; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.STORAGE_CONFIG; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.STORAGE_ENGINE; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConfig.getCollectionStorageOptions; public class MongoDBConfigTest { From 10b1cfc354ca90eeb6ca8b8f3af084e493c4658b Mon Sep 17 00:00:00 2001 From: raffaega Date: Tue, 8 Oct 2024 08:37:44 +0200 Subject: [PATCH 07/10] Upgraded com.mongodb and org.bson versions in Import-Package --- oak-store-document/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oak-store-document/pom.xml b/oak-store-document/pom.xml index 2429759b01a..41686c0d3e4 100644 --- a/oak-store-document/pom.xml +++ b/oak-store-document/pom.xml @@ -43,8 +43,8 @@ - com.mongodb*;version="[3.8, 4)";resolution:=optional, - org.bson*;version="[3.8, 4)";resolution:=optional, + com.mongodb*;version="[5.0, 5.2)";resolution:=optional, + org.bson*;version="[5.0, 5.2)";resolution:=optional, * From bac8f9d40f2761dc72ff14640e450b3a1db130c5 Mon Sep 17 00:00:00 2001 From: raffaega Date: Tue, 8 Oct 2024 08:43:54 +0200 Subject: [PATCH 08/10] Restored original formatting --- .../oak/plugins/document/MongoUtils.java | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java index 1e3185a1b0b..757b629b8fc 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java @@ -1,13 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work - * for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - * under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.jackrabbit.oak.plugins.document; @@ -15,18 +20,21 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; + import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDockerRule; import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection; import org.junit.runner.Description; import org.junit.runners.model.Statement; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import com.mongodb.BasicDBObject; import com.mongodb.ConnectionString; import com.mongodb.client.MongoDatabase; /** - * A utility class to get a {@link MongoConnection} to a local mongo instance and clean a test database. + * A utility class to get a {@link MongoConnection} to a local mongo instance + * and clean a test database. */ public class MongoUtils { @@ -104,7 +112,6 @@ public static MongoConnection getConnection(String dbName) { } catch (IllegalArgumentException e) { return null; } - StringBuilder uri = new StringBuilder("mongodb://"); String separator = ""; for (String host : connectionString.getHosts()) { @@ -112,16 +119,14 @@ public static MongoConnection getConnection(String dbName) { separator = ","; uri.append(host); } - uri.append("/") - .append(dbName) - .append("?") - .append(OPTIONS); + uri.append("/").append(dbName).append("?").append(OPTIONS); return getConnectionByURL(uri.toString()); } /** - * Drop all user defined collections in the given database. System collections are not dropped. This method returns silently if MongoDB is not - * available. + * Drop all user defined collections in the given database. System + * collections are not dropped. This method returns silently if MongoDB is + * not available. * * @param dbName the database name. */ @@ -145,14 +150,14 @@ public static void dropCollections(String dbName) { public static void dropCollections(MongoDatabase db) { for (String name : db.listCollectionNames()) { if (!name.startsWith("system.")) { - db.getCollection(name) - .drop(); + db.getCollection(name).drop(); } } } /** - * Drops the database with the given name. This method returns silently if MongoDB is not available. + * Drops the database with the given name. This method returns silently if + * MongoDB is not available. * * @param dbName the name of the database to drop. */ @@ -162,8 +167,7 @@ public static void dropDatabase(String dbName) { return; } try { - c.getDatabase() - .drop(); + c.getDatabase().drop(); } finally { c.close(); } @@ -183,7 +187,7 @@ public static boolean isAvailable() { } } - // ----------------------------< internal >---------------------------------- + //----------------------------< internal >---------------------------------- /** * Get a connection if available. If not available, null is returned. @@ -198,8 +202,7 @@ private static MongoConnection getConnectionByURL(String url) { MongoConnection mongoConnection; try { mongoConnection = new MongoConnection(url); - mongoConnection.getDatabase() - .runCommand(new BasicDBObject("ping", 1)); + mongoConnection.getDatabase().runCommand(new BasicDBObject("ping", 1)); // dropCollections(mongoConnection.getDB()); } catch (Exception e) { exceptions.put(url, e); From 01c5b2d9a6b3458b36d1431b08d107088db51557 Mon Sep 17 00:00:00 2001 From: raffaega Date: Tue, 8 Oct 2024 08:50:44 +0200 Subject: [PATCH 09/10] Restored original import ordering --- .../jackrabbit/oak/upgrade/cli/node/MongoFactory.java | 7 +++++-- .../oak/upgrade/cli/container/MongoNodeStoreContainer.java | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/node/MongoFactory.java b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/node/MongoFactory.java index a838c155b9e..cd5ca42db3d 100644 --- a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/node/MongoFactory.java +++ b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/node/MongoFactory.java @@ -16,18 +16,21 @@ */ package org.apache.jackrabbit.oak.upgrade.cli.node; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; -import java.io.IOException; import org.apache.jackrabbit.guava.common.io.Closer; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoBlobStore; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.state.NodeStore; + import com.mongodb.ConnectionString; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; +import java.io.IOException; + +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; + public class MongoFactory extends DocumentFactory { private final ConnectionString uri; diff --git a/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/container/MongoNodeStoreContainer.java b/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/container/MongoNodeStoreContainer.java index 9a5b550efcc..f6fb1493714 100644 --- a/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/container/MongoNodeStoreContainer.java +++ b/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/container/MongoNodeStoreContainer.java @@ -19,12 +19,14 @@ import java.io.IOException; import java.util.Iterator; import java.util.concurrent.atomic.AtomicInteger; + import org.apache.jackrabbit.guava.common.io.Closer; import org.apache.jackrabbit.oak.spi.state.NodeStore; import org.apache.jackrabbit.oak.upgrade.cli.node.MongoFactory; import org.junit.Assume; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import com.mongodb.ConnectionString; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; From 59576cb38cfa8a42b04c6f2b017f049e9f11bbca Mon Sep 17 00:00:00 2001 From: raffaega Date: Tue, 8 Oct 2024 08:53:54 +0200 Subject: [PATCH 10/10] Restored original import ordering --- .../document/mongo/ReplicaSetStatusTest.java | 15 +++++++++------ .../oak/plugins/document/mongo/RetryReadIT.java | 15 +++++++++------ .../document/prefetch/CountingMongoDatabase.java | 2 ++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatusTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatusTest.java index dc3e80dc94c..41c89ea7263 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatusTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/ReplicaSetStatusTest.java @@ -16,21 +16,24 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; + +import com.mongodb.ServerAddress; +import com.mongodb.connection.ClusterId; +import com.mongodb.connection.ConnectionDescription; +import com.mongodb.connection.ServerId; +import com.mongodb.event.ServerHeartbeatSucceededEvent; + import org.bson.BsonArray; import org.bson.BsonDateTime; import org.bson.BsonDocument; import org.bson.BsonString; import org.bson.BsonValue; import org.junit.Test; -import com.mongodb.ServerAddress; -import com.mongodb.connection.ClusterId; -import com.mongodb.connection.ConnectionDescription; -import com.mongodb.connection.ServerId; -import com.mongodb.event.ServerHeartbeatSucceededEvent; + +import static org.junit.Assert.assertEquals; public class ReplicaSetStatusTest { diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/RetryReadIT.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/RetryReadIT.java index ccd6a790e84..029547d4aff 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/RetryReadIT.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/RetryReadIT.java @@ -16,13 +16,8 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; -import static org.hamcrest.collection.IsEmptyCollection.empty; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; import java.util.List; + import org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest; import org.apache.jackrabbit.oak.plugins.document.Collection; import org.apache.jackrabbit.oak.plugins.document.Document; @@ -34,10 +29,18 @@ import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.jetbrains.annotations.NotNull; import org.junit.Test; + import com.mongodb.MongoException; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoDatabase; +import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; +import static org.hamcrest.collection.IsEmptyCollection.empty; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + /** * Tests retry logic in MongoDocumentStore (OAK-1641). */ diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/prefetch/CountingMongoDatabase.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/prefetch/CountingMongoDatabase.java index 02dffea6fac..170934943cb 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/prefetch/CountingMongoDatabase.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/prefetch/CountingMongoDatabase.java @@ -21,9 +21,11 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; + import org.bson.Document; import org.bson.codecs.configuration.CodecRegistry; import org.bson.conversions.Bson; + import com.mongodb.ReadConcern; import com.mongodb.ReadPreference; import com.mongodb.WriteConcern;