From 101adede9d9511ea99951aacf483354e8ace7fd2 Mon Sep 17 00:00:00 2001 From: sundarvenkata-ebi Date: Sat, 4 Nov 2023 06:25:36 +0000 Subject: [PATCH] Few small changes to enforce concerns regardless of the Spring context --- .../ac/ebi/eva/groovy/commons/EVADatabaseEnvironment.groovy | 4 ++++ .../ac/ebi/eva/groovy/commons/RetryableBatchingCursor.groovy | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/uk/ac/ebi/eva/groovy/commons/EVADatabaseEnvironment.groovy b/src/main/groovy/uk/ac/ebi/eva/groovy/commons/EVADatabaseEnvironment.groovy index 926412d..d461856 100644 --- a/src/main/groovy/uk/ac/ebi/eva/groovy/commons/EVADatabaseEnvironment.groovy +++ b/src/main/groovy/uk/ac/ebi/eva/groovy/commons/EVADatabaseEnvironment.groovy @@ -16,6 +16,8 @@ package uk.ac.ebi.eva.groovy.commons import com.mongodb.MongoBulkWriteException +import com.mongodb.ReadPreference +import com.mongodb.WriteConcern import com.mongodb.bulk.BulkWriteResult import com.mongodb.MongoClient import org.slf4j.LoggerFactory @@ -88,6 +90,8 @@ class EVADatabaseEnvironment { def mc = context.getBean(MongoClient.class) def mt = context.getBean(MongoTemplate.class) + mt.setReadPreference(ReadPreference.primary()) + mt.setWriteConcern(WriteConcern.MAJORITY) def (sva, cva) = [null, null] try { sva = context.getBean(SubmittedVariantAccessioningService.class) diff --git a/src/main/groovy/uk/ac/ebi/eva/groovy/commons/RetryableBatchingCursor.groovy b/src/main/groovy/uk/ac/ebi/eva/groovy/commons/RetryableBatchingCursor.groovy index 2c560d9..d0b27f4 100644 --- a/src/main/groovy/uk/ac/ebi/eva/groovy/commons/RetryableBatchingCursor.groovy +++ b/src/main/groovy/uk/ac/ebi/eva/groovy/commons/RetryableBatchingCursor.groovy @@ -65,7 +65,7 @@ class RetryableBatchingCursor implements Iterable { .causallyConsistent(true).build() ClientSession session = null try { - this.mongoTemplate.mongoDbFactory.getSession(sessionOptions) + session = this.mongoTemplate.mongoDbFactory.getSession(sessionOptions) this.hasSessionSupport = true } catch (MongoClientException ex) { // Handle stand-alone instances that don't have session support