Skip to content
Permalink
Browse files
OAK-9757 : used MongoStatus.isVersion api to check node name limit
  • Loading branch information
Rishabh Kumar committed May 23, 2022
1 parent bd599db commit 20803aae0b9aa1f28081de27fca2d15bce26da01
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 46 deletions.
@@ -267,7 +267,7 @@ public MongoDocumentStore(MongoClient connection, MongoDatabase db,
.put("version", status.getVersion())
.build();

this.nodeNameLimit = MongoUtils.getNodeNameLimit(status.getVersion());
this.nodeNameLimit = status.isVersion(4,2) ? Integer.MAX_VALUE : Utils.NODE_NAME_LIMIT;
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,11 +31,9 @@
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;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.bson.Document;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -194,15 +190,4 @@ static Type getDocumentStoreExceptionTypeFor(Throwable t) {
}
return type;
}

/**
* Util method to get node size limit for current mongo version
*
* @param version version of current mongo db
* @return size limit based on mongo db 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;
}
}
@@ -200,36 +200,6 @@ public void isCollectionEmpty() {
}
}

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

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

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

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

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

private static MongoCommandException newMongoCommandException(int code) {
return new MongoCommandException(response(code), new ServerAddress());
}

0 comments on commit 20803aa

Please sign in to comment.