`SetGeneration` fails if a repository rename was only partially applied
SetGeneration
fails if a repository rename was only partially applied to a repository. This became a problem now that Praefect now that the records are joined via repository id. Previously, a failed rename like the one below would leave an orphaned replica record in storage_repositories
with the old path and create a new replica at the new path. This causes problems now that we have a new unique index on (repository_id, storage)
. The mismatch in the relative path doesn't trigger the ON CONFLICT
clause in SetGeneration
and thus fails with a unique violation. As the jobs scheduled from the reconciler would contain the new relative path and would replicate into the new path, this can be fixed by changing the ON CONFLICT
to check against the new index and to update the relative path if it mismatches. This behavior can be dropped once the migration to repository IDs is complete and the (virtual_storage, relative_path)
columns dropped from storage_repositories
Logs: https://nonprod-log.gitlab.net/goto/e8aaa0ebdaa0a3aab7d41599a0d61b58
State captured from staging:
praefect_production=> select * from repositories where repository_id = '233074';
virtual_storage | relative_path | generation | primary | repository_id | replica_path
-----------------+---------------------------------------------------------------------------------------------------------+------------+---------+---------------+---------------------------------------------------------------------------------------------------------
nfs-file22 | @hashed/02/15/02155680c3a0867e72dd5c9db8bc23d0e2eb6f6a6a9d6389917c17aefce732f6.wiki+6436496+deleted.git | 1 | file-05 | 233074 | @hashed/02/15/02155680c3a0867e72dd5c9db8bc23d0e2eb6f6a6a9d6389917c17aefce732f6.wiki+6436496+deleted.git
(1 row)
praefect_production=> select * from storage_repositories where repository_id = '233074';
virtual_storage | relative_path | storage | generation | repository_id
-----------------+---------------------------------------------------------------------------------------------------------+---------+------------+---------------
nfs-file22 | @hashed/02/15/02155680c3a0867e72dd5c9db8bc23d0e2eb6f6a6a9d6389917c17aefce732f6.wiki.git | file-03 | 0 | 233074
nfs-file22 | @hashed/02/15/02155680c3a0867e72dd5c9db8bc23d0e2eb6f6a6a9d6389917c17aefce732f6.wiki+6436496+deleted.git | file-04 | 1 | 233074
nfs-file22 | @hashed/02/15/02155680c3a0867e72dd5c9db8bc23d0e2eb6f6a6a9d6389917c17aefce732f6.wiki+6436496+deleted.git | file-05 | 1 | 233074
(3 rows)
praefect_production=> select * from replication_queue where (job->>'repository_id')::BigInt = 233074;
-[ RECORD 1 ]------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
id | 27026499
state | ready
created_at | 2021-10-26 08:35:35.222306
updated_at |
attempt | 3
lock_id | nfs-file22|file-03|@hashed/02/15/02155680c3a0867e72dd5c9db8bc23d0e2eb6f6a6a9d6389917c17aefce732f6.wiki+6436496+deleted.git
job | {"change": "update", "relative_path": "@hashed/02/15/02155680c3a0867e72dd5c9db8bc23d0e2eb6f6a6a9d6389917c17aefce732f6.wiki+6436496+deleted.git", "repository_id": 233074, "virtual_storage": "nfs-file22", "source_node_storage": "file-05", "target_node_storage": "file-03"}
meta | {"correlation_id": "MC4yODM2NjI2MDM3MDIzOTYxNQ=="}
/cc @steveazz