Skip to content

QRep mirror creation via SQL interface fails with duplicate key #3949

@lukejudd-lux

Description

@lukejudd-lux

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions