You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now follow the same steps as for the first reproduction: apply the first migration, generate load, apply the second migration. The second migration will likely fail with the same error as in the first reproduction.
Notes
In the first reproduction, the operation fails because there is a race between the movies_name_unique index being marked valid after it is created (concurrently) on operation Start:
There is a race condition when adding a
unique
constraint to a column.The race can cause the operation to fail, particularly when the target database is under high load at the time of the migration.
Reproduction 1
Create a pair of migrations:
01_create_table.json
02_set_unique.json
Apply the first migration:
In the target database, generate some load on the system:
While the above
INSERT
operation is running, apply the second migration:The second migration is likely to fail with the following error:
Reproduction 2
The same problem also exists when a column with a
UNIQUE
constraint is duplicated, for example to change the nullability of the column. To reproduce:Create a pair of migrations:
01_create_table.json
02_set_notnull.json
Now follow the same steps as for the first reproduction: apply the first migration, generate load, apply the second migration. The second migration will likely fail with the same error as in the first reproduction.
Notes
In the first reproduction, the operation fails because there is a race between the
movies_name_unique
index being marked valid after it is created (concurrently) on operationStart
:pgroll/pkg/migrations/op_set_unique.go
Lines 74 to 84 in 6d48386
and when the unique constraint is added using the index on operation
Complete
:pgroll/pkg/migrations/op_set_unique.go
Lines 35 to 47 in 6d48386
In the second reproduction, the race is between the concurrent index creation performed by the column duplicator:
pgroll/pkg/migrations/duplicate.go
Lines 170 to 186 in 6d48386
And when the unique constraint is created using the index when the column is renamed on operation complete:
pgroll/pkg/migrations/rename.go
Lines 123 to 159 in 6d48386
In both cases the correct behaviour is to wait for the concurrently created index to be marked as valid before returning.
The text was updated successfully, but these errors were encountered: