System migrations don't respect transaction settings
mcveat opened this issue · comments
Piotr Adamski commented
Description
Running migrations with mongock (with transactions disabled on driver and runner level) against a database that migrations haven't been run before fails with error
ERROR starting session. If Mongock is connected to a MongoDB cluster which doesn't support transactions, you must to disable transactions
PRIORITY
CRITICAL
Version and environment
Mongock
- Mongock version : 5.2.2
- Modules involved(springboot, standalone, MongoDB, DynamoDB, etc.) : standalone
- How Mongock is used(builder or annotation approach, etc.) : builder
Environment
- mongo-java-driver: 3.8.2
- mongo 5.0.7
Steps to Reproduce
- Take the example standalone runner project and disable transactions (
driver.disableTransaction()
andMongockStandalone.builder().setTransactionEnabled(false).setTransactionStrategy(TransactionStrategy.EXECUTION)
) - Run migrations against the database using mongo client or mongo server instance that does not allow transactions
Behaviour
Expected behavior:
Migrations run successfuly
Actual behavior:
Execution fails with error
ERROR starting session. If Mongock is connected to a MongoDB cluster which doesn't support transactions, you must to disable transactions
How often the bug happens:
Every time
Additional context
I believe it is happening because:
- system change unit is transactional (default value of the annotation) https://github.com/mongock/mongock/blob/develop/mongock-core/mongock-runner/mongock-runner-core/src/main/java/io/mongock/runner/core/executor/system/changes/SystemChangeUnit00001.java#L19
- system update executor ignores configuration and uses fixed value of the transaction strategy https://github.com/mongock/mongock/blob/develop/mongock-core/mongock-runner/mongock-runner-core/src/main/java/io/mongock/runner/core/executor/system/SystemUpdateExecutor.java#L48
- routine that prepares session for the transactions is executed because
isStrategyPerChangeUnit() && changeLog.isTransactional()
evaluates totrue
because of the above https://github.com/mongock/mongock/blob/develop/mongock-core/mongock-runner/mongock-runner-core/src/main/java/io/mongock/runner/core/executor/ChangeExecutorBase.java#L116
Antonio Perez Diepa commented
Oliver Santana commented
Hello @mcveat , we've just released Mongock's version 5.2.4, which fixes this issue. Please could you try it and let us know? Thanks.
Piotr Adamski commented
Thanks @osantana85 , I hope to find time to try it sometime this or next week, will let you know