Skip to content
Permalink
Browse files
OAK-9757: increased node name limit for mongo 4.2 version
Use MongoStatus.isVersion() to decide on node name limit
  • Loading branch information
mreutegg committed May 23, 2022
1 parent 8ffdc12 commit fe7d993910204f81eaf39109fb5d16921224beec
Showing 3 changed files with 27 additions and 15 deletions.
@@ -267,7 +267,7 @@ public MongoDocumentStore(MongoClient connection, MongoDatabase db,
.put("version", status.getVersion())
.build();

this.nodeNameLimit = MongoUtils.getNodeNameLimit(status.getVersion());
this.nodeNameLimit = MongoUtils.getNodeNameLimit(status);
this.connection = new MongoDBConnection(connection, db, status, builder.getMongoClock());
this.clusterNodesConnection = getOrCreateClusterNodesConnection(builder);
stats = builder.getDocumentStoreStatsCollector();
@@ -16,9 +16,7 @@
*/
package org.apache.jackrabbit.oak.plugins.document.mongo;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

import com.google.common.collect.Sets;
import com.mongodb.BasicDBObject;
@@ -33,7 +31,6 @@
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.IndexOptions;
import com.mongodb.connection.ServerVersion;
import com.mongodb.internal.connection.MongoWriteConcernWithResponseException;

import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.Type;
@@ -196,13 +193,13 @@ static Type getDocumentStoreExceptionTypeFor(Throwable t) {
}

/**
* Util method to get node size limit for current mongo version
* Util method to get node size limit for MongoDB server version from the
* MongoDB status.
*
* @param version version of current mongo db
* @return size limit based on mongo db version
* @param status the MongoDB status
* @return size limit based on MongoDB version.
*/
static int getNodeNameLimit(final String version) {
final ServerVersion sv = new ServerVersion(Arrays.stream(version.split("\\.")).map(Integer::new).collect(Collectors.toList()));
return sv.compareTo(new ServerVersion(4,2)) >= 0 ? Integer.MAX_VALUE : Utils.NODE_NAME_LIMIT;
static int getNodeNameLimit(final @NotNull MongoStatus status) {
return status.isVersion(4, 2) ? Integer.MAX_VALUE : Utils.NODE_NAME_LIMIT;
}
}
@@ -22,6 +22,7 @@

import com.mongodb.BasicDBObject;
import com.mongodb.DuplicateKeyException;
import com.mongodb.MongoClient;
import com.mongodb.MongoCommandException;
import com.mongodb.MongoException;
import com.mongodb.MongoSocketException;
@@ -50,6 +51,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.mockito.Mockito.mock;

public class MongoUtilsTest {

@@ -202,31 +204,37 @@ public void isCollectionEmpty() {

@Test
public void getSizeLimitForMongo4() {
int sizeLimit = MongoUtils.getNodeNameLimit("4.0.0");
int sizeLimit = MongoUtils.getNodeNameLimit(serverVersion("4.0.0"));
assertEquals(150, sizeLimit);
}

@Test
public void getSizeLimitForMongo4_1_27() {
int sizeLimit = MongoUtils.getNodeNameLimit("4.1.27");
int sizeLimit = MongoUtils.getNodeNameLimit(serverVersion("4.1.27"));
assertEquals(150, sizeLimit);
}

@Test
public void getSizeLimitForMongo3_5() {
int sizeLimit = MongoUtils.getNodeNameLimit("3.5.0");
int sizeLimit = MongoUtils.getNodeNameLimit(serverVersion("3.5.0"));
assertEquals(150, sizeLimit);
}

@Test
public void getSizeLimitForMongo4_2() {
int sizeLimit = MongoUtils.getNodeNameLimit("4.2.0");
int sizeLimit = MongoUtils.getNodeNameLimit(serverVersion("4.2.0"));
assertEquals(Integer.MAX_VALUE, sizeLimit);
}

@Test
public void getSizeLimitForMongo4_2_1() {
int sizeLimit = MongoUtils.getNodeNameLimit("4.2.1");
int sizeLimit = MongoUtils.getNodeNameLimit(serverVersion("4.2.1"));
assertEquals(Integer.MAX_VALUE, sizeLimit);
}

@Test
public void getSizeLimitForMongo5_0_0rc() {
int sizeLimit = MongoUtils.getNodeNameLimit(serverVersion("5.0.0-rc0"));
assertEquals(Integer.MAX_VALUE, sizeLimit);
}

@@ -244,4 +252,11 @@ private static BsonDocument response(int code) {
response.put("errmsg", new BsonString("message"));
return response;
}

private static MongoStatus serverVersion(String version) {
MongoClient client = mock(MongoClient.class);
MongoStatus status = new MongoStatus(client, "db");
status.setVersion(version);
return status;
}
}

0 comments on commit fe7d993

Please sign in to comment.