Change units are re-executed unnecessarily
rgruber1 opened this issue · comments
Description
A change unit is unique across ID + author
PRIORITY
NORMAL
Version and environment
Mongock
- Mongock version 5.4.0
- Modules involved(springboot 3.2.1, MongoDB 5.0.19, etc.)
- How Mongock is used(builder or annotation approach, etc.) Instrumented automatically via springboot/mongock.
Environment
- Framework and libraries versions. Especially those that affect directly to Mongock(Spring, Spring data, MongoDB driver, etc.)
- Infrastructure: Kubernetes, Docker, SO, etc.
Steps to Reproduce
- Define two change units with the same id, and different authors, e.g.
@ChangeUnit(id="my-change-unit", author="ruser1", order="001", systemVersion="1", transactional=false)
@ChangeUnit(id="my-change-unit", author="joebloggs", order="001", systemVersion="1", transactional=false) - Launch the app, both change units are executed
- Launch again, first change unit is executed again
- Launch again, second change unit is executed again
- Launch again, first change unit is executed again
- ad infinitum
Behaviour
Change unit is reexecuted
Expected behavior: [What you expect to happen]
Expected a change unit not to be re-executed if it has already been applied to the database
Actual behavior: [What actually happens]
Change unit is reexecuted
How often the bug happens: [What percentage of the time does it reproduce?]
Occurs consistently.
Link to repository using Mongock
[While not mandatory, accessing to the real code that uses Mongock, would help to solve the issue]
Additional context
[Any additional information, logs, screenshots, configuration or data that might be necessary to reproduce or understand the issue]
Hello @rgruber1 , thanks for raising the issue. We'll take a look to reproduce it and let you know.
However, even though the unique key is composed of the ChangeUnit id + author, the best practice (and the recommended one) is to have unique ChangeUnit ids.
In a future major version the way to go will be to have unique ids (the author will be optional and won't be part of the key).
As a workaround, can you refactor your ChangeUnits to prevent duplicated ids?
@rgruber1 can you update us on this, so we can close it and move it to an internal ticket to address it?
As a workaround, we simplified the annotation definitions and only specify the mandatory attributes (id + order), so that mongock uses the id and the default author for the uniqueness check across change units (this effectively makes change units unique based on id only as you know).
Thanks, we'll fix this in the next major release. This workaround should be fine for the time being.
Mongock change unit documentation could possibly mention this defect in https://docs.mongock.io/v5/migration/index.html
you are totally right! Will do!