You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by jo...@apache.org on 2025/08/03 12:37:04 UTC
(jackrabbit-oak) branch OAK-11834 created (now 90f447f2ed)
This is an automated email from the ASF dual-hosted git repository.
joscorbe pushed a change to branch OAK-11834
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
at 90f447f2ed OAK-11834: Add delay to getDefaultWriteConcern to avoid UNKWOWN ClusterType
This branch includes the following new commits:
new 90f447f2ed OAK-11834: Add delay to getDefaultWriteConcern to avoid UNKWOWN ClusterType
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(jackrabbit-oak) 01/01: OAK-11834: Add delay to getDefaultWriteConcern to avoid UNKWOWN ClusterType
Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
joscorbe pushed a commit to branch OAK-11834
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit 90f447f2ed39b358082fcbdaade9b5c56661de2e
Author: Jose Cordero <co...@adobe.com>
AuthorDate: Sun Aug 3 14:36:50 2025 +0200
OAK-11834: Add delay to getDefaultWriteConcern to avoid UNKWOWN ClusterType
---
.../plugins/document/mongo/MongoDBConnection.java | 6 ++-
.../oak/plugins/document/util/MongoConnection.java | 55 +++++++++++++++++++---
2 files changed, 53 insertions(+), 8 deletions(-)
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 200c7f1716..a8bd2fa675 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
@@ -27,6 +27,7 @@ import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
+import com.mongodb.WriteConcern;
import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
import org.jetbrains.annotations.NotNull;
@@ -83,7 +84,10 @@ final class MongoDBConnection {
serverMonitorListener.addListener(status);
MongoDatabase db = client.getDatabase(name);
if (!MongoConnection.hasWriteConcern(uri)) {
- db = db.withWriteConcern(MongoConnection.getDefaultWriteConcern(client));
+ WriteConcern defaultWriteConcern = MongoConnection.getDefaultWriteConcern(client);
+ LOG.info("Setting default write concern: {} for cluster type: {}",
+ defaultWriteConcern, client.getClusterDescription().getType());
+ db = db.withWriteConcern(defaultWriteConcern);
}
if (status.isMajorityReadConcernSupported()
&& status.isMajorityReadConcernEnabled()
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 11e62c2e20..744b032477 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
@@ -41,11 +41,16 @@ import static java.util.Objects.requireNonNull;
import org.jetbrains.annotations.NotNull;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
/**
* The {@code MongoConnection} abstracts connection to the {@code MongoDB}.
*/
public class MongoConnection {
+ private static final Logger LOG = LoggerFactory.getLogger(MongoConnection.class);
+
public static final String MONGODB_PREFIX = "mongodb://";
private static final int DEFAULT_MAX_WAIT_TIME = (int) TimeUnit.MINUTES.toMillis(1);
@@ -54,6 +59,12 @@ public class MongoConnection {
private final ConnectionString mongoURI;
private final MongoClient mongo;
+ // MongoDB cluster description timeout configuration
+ private static final String PROP_CLUSTER_DESCRIPTION_TIMEOUT_MS = "oak.mongo.clusterDescriptionTimeoutMs";
+ private static final String PROP_CLUSTER_DESCRIPTION_INTERVAL_MS = "oak.mongo.clusterDescriptionIntervalMs";
+ private static final long DEFAULT_CLUSTER_DESCRIPTION_TIMEOUT_MS = 5000L;
+ private static final long DEFAULT_CLUSTER_DESCRIPTION_INTERVAL_MS = 100L;
+
/**
* Constructs a new connection using the specified MongoDB connection string.
* See also http://docs.mongodb.org/manual/reference/connection-string/
@@ -227,14 +238,44 @@ public class MongoConnection {
* @return the default write concern to use for Oak.
*/
public static WriteConcern getDefaultWriteConcern(@NotNull MongoClient client) {
- WriteConcern w;
- ClusterDescription clusterDescription = client.getClusterDescription();
- if (clusterDescription.getType() == ClusterType.REPLICA_SET) {
- w = WriteConcern.MAJORITY;
- } else {
- w = WriteConcern.ACKNOWLEDGED;
+ long timeoutMs = Long.getLong(PROP_CLUSTER_DESCRIPTION_TIMEOUT_MS, DEFAULT_CLUSTER_DESCRIPTION_TIMEOUT_MS);
+ long intervalMs = Long.getLong(PROP_CLUSTER_DESCRIPTION_INTERVAL_MS, DEFAULT_CLUSTER_DESCRIPTION_INTERVAL_MS);
+
+ // If timeout is 0, disable the retry functionality and use immediate detection
+ if (timeoutMs == 0) {
+ WriteConcern w;
+ ClusterDescription clusterDescription = client.getClusterDescription();
+ if (clusterDescription.getType() == ClusterType.REPLICA_SET) {
+ w = WriteConcern.MAJORITY;
+ } else {
+ w = WriteConcern.ACKNOWLEDGED;
+ }
+ return w;
+ }
+
+ long startTime = System.currentTimeMillis();
+ long endTime = startTime + timeoutMs;
+ int attempts = 0;
+
+ while (System.currentTimeMillis() < endTime) {
+ attempts++;
+ ClusterDescription clusterDescription = client.getClusterDescription();
+
+ if (clusterDescription.getType() == ClusterType.REPLICA_SET) {
+ return WriteConcern.MAJORITY;
+ } else if (clusterDescription.getType() == ClusterType.STANDALONE) {
+ return WriteConcern.ACKNOWLEDGED;
+ }
+
+ try {
+ Thread.sleep(intervalMs);
+ } catch (InterruptedException e) {}
}
- return w;
+
+ // In case of timeout, default to ACKNOWLEDGED
+ LOG.warn("Cluster description timeout after {}ms ({} attempts). Defaulting to ACKNOWLEDGED write concern.",
+ timeoutMs, attempts);
+ return WriteConcern.ACKNOWLEDGED;
}
/**