Unable to specify/override ReadConcern for transactional ChangeUnits
thorstenvogel opened this issue · comments
Description
Unable to create indices in ChangeUnit's @execution methods.
The error message listed below says that the command createIndexes does not support this transaction's readConcern
.
The mongo documentation specifies that "To use
createIndexes
in a transaction, the transaction must use read concern "local". If you specify a read concern level other than "local", the transaction fails."
The MongoTransactionManager has been setup with ReadConcern local
but this is somehow not considered.
@Bean
MongoTransactionManager transactionManager(MongoTemplate mongoTemplate) {
TransactionOptions transactionOptions = TransactionOptions.builder()
.readConcern(ReadConcern.LOCAL)
.writeConcern(WriteConcern.ACKNOWLEDGED)
.build();
return new MongoTransactionManager(mongoTemplate.getMongoDatabaseFactory(), transactionOptions);
}
@Bean
ConnectionDriver connectionDriver(MongoTemplate mongoTemplate) {
SpringDataMongoV4Driver springDataMongoV4Driver = SpringDataMongoV4Driver.withDefaultLock(mongoTemplate);
springDataMongoV4Driver.enableTransaction();
return springDataMongoV4Driver;
}
@Bean
MongockApplicationRunner mongockApplicationRunner(ConnectionDriver driver, ApplicationContext applicationContext) {
return MongockSpringboot.builder()
.setDriver(driver)
.setSpringContext(applicationContext)
...
.addMigrationScanPackages(MIGRATION_PACKAGES)
.setTransactionEnabled(true)
.buildApplicationRunner();
}
I was thinking that the TransactionManager is picked up automatically from the Spring context, as i cannot find any setter method for the transactionmanager.
PRIORITY
[CRITICAL]
Version and environment
Mongock
- 5.3.4
- Mockock-SpringBootBuilder
Environment
- Spring Boot 3.1.3, , MongoDB 5.0.14
- Infrastructure: Docker
Steps to Reproduce
-
Setup Mongock to use transactions, i.e. declare MongoTransactionManager und enable transactions in Driver and MongockSpringboot.builder().
-
Create a ChangeUnit that tries to create an Index
Behaviour
Expected behavior: The specified index is created.
Actual behavior: Error message from Mongo-Driver:
com.mongodb.MongoCommandException: Command failed with error 72 (InvalidOptions): 'Command createIndexes does not support this transaction's { readConcern: { level: "majority", provenance: "clientSupplied" } } :: caused by :: read concern not supported' on server mft-kafka-t0011.deutschepost.dpwn.com:27017. The full response is {"ok": 0.0, "errmsg": "Command createIndexes does not support this transaction's { readConcern: { level: \"majority\", provenance: \"clientSupplied\" } } :: caused by :: read concern not supported", "code": 72, "codeName": "InvalidOptions", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1694598946, "i": 3}}, "signature": {"hash": {"$binary": {"base64": "APP1ec+sC3Qs1BmcFVZVsD/vRdE=", "subType": "00"}}, "keyId": 7232103882782932993}}, "operationTime": {"$timestamp": {"t": 1694598946, "i": 3}}}
How often the bug happens: 100%
Hello @thorstenvogel , we'll take a look and let you know.
As a workaround you can include index creation within @BeforeExecution
method, which is executed with no transactional context (only @Execution
method is executed within transaction).
Please take a look to the ChangeUnit's methods documentation here.
Thanks