use of com.mongodb.ReadConcernLevel in project jackrabbit-oak by apache.
the class MongoDocumentNodeStoreBuilderBase method setMongoDB.
private T setMongoDB(@Nonnull MongoClient client, @Nonnull MongoDatabase db, MongoStatus status, int blobCacheSizeMB) {
if (!MongoConnection.isSufficientWriteConcern(client, db.getWriteConcern())) {
LOG.warn("Insufficient write concern: " + db.getWriteConcern() + " At least " + MongoConnection.getDefaultWriteConcern(client) + " is recommended.");
}
if (status.isMajorityReadConcernSupported() && !status.isMajorityReadConcernEnabled()) {
LOG.warn("The read concern should be enabled on mongod using --enableMajorityReadConcern");
} else if (status.isMajorityReadConcernSupported() && !MongoConnection.isSufficientReadConcern(client, db.getReadConcern())) {
ReadConcernLevel currentLevel = readConcernLevel(db.getReadConcern());
ReadConcernLevel recommendedLevel = readConcernLevel(MongoConnection.getDefaultReadConcern(client, db));
if (currentLevel == null) {
LOG.warn("Read concern hasn't been set. At least " + recommendedLevel + " is recommended.");
} else {
LOG.warn("Insufficient read concern: " + currentLevel + ". At least " + recommendedLevel + " is recommended.");
}
}
this.mongoStatus = status;
this.documentStoreSupplier = memoize(() -> new MongoDocumentStore(client, db.getName(), MongoDocumentNodeStoreBuilderBase.this));
if (this.blobStore == null) {
GarbageCollectableBlobStore s = new MongoBlobStore(db, blobCacheSizeMB * 1024 * 1024L);
setGCBlobStore(s);
}
return thisBuilder();
}
use of com.mongodb.ReadConcernLevel in project mongo-java-driver by mongodb.
the class ReadConcernHelper method getReadConcernDocument.
public static BsonDocument getReadConcernDocument(final SessionContext sessionContext, final int maxWireVersion) {
notNull("sessionContext", sessionContext);
BsonDocument readConcernDocument = new BsonDocument();
ReadConcernLevel level = sessionContext.getReadConcern().getLevel();
if (level != null) {
readConcernDocument.append("level", new BsonString(level.getValue()));
}
assertFalse(sessionContext.isSnapshot() && sessionContext.isCausallyConsistent());
if (sessionContext.isSnapshot() && maxWireVersion < FIVE_DOT_ZERO_WIRE_VERSION) {
throw new MongoClientException("Snapshot reads require MongoDB 5.0 or later");
}
if (shouldAddAfterClusterTime(sessionContext)) {
readConcernDocument.append("afterClusterTime", sessionContext.getOperationTime());
} else if (shouldAddAtClusterTime(sessionContext)) {
readConcernDocument.append("atClusterTime", sessionContext.getSnapshotTimestamp());
}
return readConcernDocument;
}
use of com.mongodb.ReadConcernLevel in project mongo-java-driver by mongodb.
the class Entities method initClient.
private void initClient(final BsonDocument entity, final String id, final Function<MongoClientSettings, MongoClient> mongoClientSupplier, final boolean waitForPoolAsyncWorkManagerStart) {
if (!SUPPORTED_CLIENT_ENTITY_OPTIONS.containsAll(entity.keySet())) {
throw new UnsupportedOperationException("Client entity contains unsupported options: " + entity.keySet() + ". Supported options are " + SUPPORTED_CLIENT_ENTITY_OPTIONS);
}
MongoClientSettings.Builder clientSettingsBuilder;
if (entity.getBoolean("useMultipleMongoses", BsonBoolean.FALSE).getValue() && (isSharded() || isLoadBalanced())) {
assumeTrue("Multiple mongos connection string not available for sharded cluster", !isSharded() || getMultiMongosConnectionString() != null);
assumeTrue("Multiple mongos connection string not available for load-balanced cluster", !isLoadBalanced() || getMultiMongosConnectionString() != null);
clientSettingsBuilder = getMultiMongosMongoClientSettingsBuilder();
} else {
clientSettingsBuilder = getMongoClientSettingsBuilder();
}
if (entity.containsKey("observeEvents")) {
List<String> ignoreCommandMonitoringEvents = entity.getArray("ignoreCommandMonitoringEvents", new BsonArray()).stream().map(type -> type.asString().getValue()).collect(Collectors.toList());
ignoreCommandMonitoringEvents.add("configureFailPoint");
TestCommandListener testCommandListener = new TestCommandListener(entity.getArray("observeEvents").stream().map(type -> type.asString().getValue()).collect(Collectors.toList()), ignoreCommandMonitoringEvents, entity.getBoolean("observeSensitiveCommands", BsonBoolean.FALSE).getValue());
clientSettingsBuilder.addCommandListener(testCommandListener);
putEntity(id + "-command-listener", testCommandListener, clientCommandListeners);
TestConnectionPoolListener testConnectionPoolListener = new TestConnectionPoolListener(entity.getArray("observeEvents").stream().map(type -> type.asString().getValue()).collect(Collectors.toList()));
clientSettingsBuilder.applyToConnectionPoolSettings(builder -> builder.addConnectionPoolListener(testConnectionPoolListener));
putEntity(id + "-connection-pool-listener", testConnectionPoolListener, clientConnectionPoolListeners);
} else {
// Regardless of whether events are observed, we still need to track some info about the pool in order to implement
// the assertNumberConnectionsCheckedOut operation
TestConnectionPoolListener testConnectionPoolListener = new TestConnectionPoolListener();
clientSettingsBuilder.applyToConnectionPoolSettings(builder -> builder.addConnectionPoolListener(testConnectionPoolListener));
putEntity(id + "-connection-pool-listener", testConnectionPoolListener, clientConnectionPoolListeners);
}
if (entity.containsKey("storeEventsAsEntities")) {
BsonArray storeEventsAsEntitiesArray = entity.getArray("storeEventsAsEntities");
for (BsonValue eventValue : storeEventsAsEntitiesArray) {
BsonDocument eventDocument = eventValue.asDocument();
String key = eventDocument.getString("id").getValue();
BsonArray eventList = eventDocument.getArray("events");
List<BsonDocument> eventDocumentList = synchronizedList(new ArrayList<>());
putEntity(key, eventDocumentList, eventsMap);
if (eventList.stream().map(value -> value.asString().getValue()).anyMatch(value -> value.startsWith("Command"))) {
clientSettingsBuilder.addCommandListener(new EntityCommandListener(eventList.stream().map(value -> value.asString().getValue()).collect(Collectors.toSet()), eventDocumentList));
}
if (eventList.stream().map(value -> value.asString().getValue()).anyMatch(value -> value.startsWith("Pool") || value.startsWith("Connection"))) {
clientSettingsBuilder.applyToConnectionPoolSettings(builder -> builder.addConnectionPoolListener(new EntityConnectionPoolListener(eventList.stream().map(value -> value.asString().getValue()).collect(Collectors.toSet()), eventDocumentList)));
}
}
}
clientSettingsBuilder.applyToServerSettings(builder -> {
builder.heartbeatFrequency(50, TimeUnit.MILLISECONDS);
builder.minHeartbeatFrequency(50, TimeUnit.MILLISECONDS);
});
if (entity.containsKey("uriOptions")) {
entity.getDocument("uriOptions").forEach((key, value) -> {
switch(key) {
case "retryReads":
clientSettingsBuilder.retryReads(value.asBoolean().getValue());
break;
case "retryWrites":
clientSettingsBuilder.retryWrites(value.asBoolean().getValue());
break;
case "readConcernLevel":
clientSettingsBuilder.readConcern(new ReadConcern(ReadConcernLevel.fromString(value.asString().getValue())));
break;
case "w":
clientSettingsBuilder.writeConcern(new WriteConcern(value.asInt32().intValue()));
break;
case "maxPoolSize":
clientSettingsBuilder.applyToConnectionPoolSettings(builder -> builder.maxSize(value.asNumber().intValue()));
break;
case "waitQueueTimeoutMS":
clientSettingsBuilder.applyToConnectionPoolSettings(builder -> builder.maxWaitTime(value.asNumber().longValue(), TimeUnit.MILLISECONDS));
break;
case "loadBalanced":
if (value.asBoolean().getValue()) {
clientSettingsBuilder.applyToClusterSettings(builder -> builder.mode(ClusterConnectionMode.LOAD_BALANCED));
}
break;
case "appname":
clientSettingsBuilder.applicationName(value.asString().getValue());
break;
default:
throw new UnsupportedOperationException("Unsupported uri option: " + key);
}
});
}
if (entity.containsKey("serverApi")) {
BsonDocument serverApiDocument = entity.getDocument("serverApi");
String apiVersion = serverApiDocument.getString("version").getValue();
ServerApi.Builder serverApiBuilder = ServerApi.builder().version(ServerApiVersion.findByValue(apiVersion));
if (serverApiDocument.containsKey("deprecationErrors")) {
serverApiBuilder.deprecationErrors(serverApiDocument.getBoolean("deprecationErrors").getValue());
}
if (serverApiDocument.containsKey("strict")) {
serverApiBuilder.strict(serverApiDocument.getBoolean("strict").getValue());
}
clientSettingsBuilder.serverApi(serverApiBuilder.build());
}
putEntity(id, mongoClientSupplier.apply(clientSettingsBuilder.build()), clients);
if (waitForPoolAsyncWorkManagerStart) {
waitForPoolAsyncWorkManagerStart();
}
}
Aggregations