-
Notifications
You must be signed in to change notification settings - Fork 174
Description
When creating a QRep mirror through the SQL interface (Nexus), both Nexus and the Flow service attempt to INSERT into the flows table, causing a unique constraint violation.
Steps to reproduce:
Connect to PeerDB SQL interface (Nexus) via psql
Run any CREATE MIRROR ... FOR $$...$$ QRep mirror statement
Observe: ERROR: duplicate key value violates unique constraint "flows_name_unique"
Root cause:
Two INSERTs happen for the same flow name:
Nexus calls catalog.create_qrep_flow_job_entry() which inserts into flows with NULL workflow_id (nexus/catalog/src/lib.rs)
Nexus then calls run_qrep_mirror() -> Flow service CreateQRepFlow -> createQRepJobEntry() which also inserts into flows with a workflow_id (flow/cmd/handler.go:125-132)
The second INSERT fails because the name already exists from step 1.
The CDC path doesn't have this issue because createCdcJobEntry in handler.go:90-97 has an idempotent parameter that silently ignores UniqueViolation errors. The QRep path (createQRepJobEntry) has no such handling.