project-pegaprox icon indicating copy to clipboard operation
project-pegaprox copied to clipboard

[Bug] Cross-cluster replication does not automatically create xcrepl-job ownership tag

Open Br00dkast opened this issue 2 months ago • 5 comments

Hey there! 👋 Thanks for taking the time to report this bug — we appreciate it!

Please keep in mind: PegaProx is developed and maintained entirely by volunteers in our free time. We do our best, but we can't work magic 🪄 — please be patient, we'll get to your issue as soon as we can.

Want to help keep PegaProx alive?

  • ⭐ [Star the project](https://github.com/PegaProx/project-pegaprox) — it's free and helps a lot!
  • 💖 [Become a Sponsor](https://pegaprox.com/#sponsor) — helps us dedicate more time to development
  • 🤝 Contributing code or docs is always welcome too!

Describe the bug

Cross-cluster replication successfully creates the target VM, but the job-specific replication ownership tag is not automatically added to the target VM.

The initial replication completes successfully and the target VM is created. However, the expected tag is missing:

xcrepl-job-<job-id>

Because the tag is missing, the next scheduled replication run refuses to overwrite the existing target VM:

Target VM 100 on node bewst02pv02n001 is not tagged as a replica of this job
(xcrepl-job-21374341 tag missing).

Refusing to overwrite to prevent data loss.
If this is a stranded replica from a previous run or manual clone,
tag it with `xcrepl-job-21374341` and re-run.
If it is an unrelated VM, pick a different target VMID for the job.

I deleted the target VM and recreated the replication job to rule out stale state from a previous replication.

The newly created job showed the same behavior.

The new replication job ID was:

a302ff3b

The replicated VM was created correctly and its description was set to:

Cross-cluster replication a302ff3b

but the expected ownership tag was not added:

xcrepl-job-a302ff3b

If I manually add the expected xcrepl-job-<job-id> tag to the target VM, the replication job works correctly on subsequent runs.

This suggests that the cross-cluster replication itself and the replica ownership validation are working, but the automatic post-replication tag creation is failing or being skipped.

Steps to Reproduce

  1. Create a cross-cluster replication job for a VM.
  2. Run the replication job.
  3. Wait for the initial replication to complete successfully.
  4. Check the target VM and observe that the xcrepl-job-<job-id> tag is missing.
  5. Run the replication job again, or wait for the next scheduled run.
  6. Observe that PegaProx refuses to overwrite the target VM because the ownership tag is missing.
  7. Manually add the expected xcrepl-job-<job-id> tag to the target VM.
  8. Run the replication job again.
  9. Observe that replication now works correctly.

Expected behavior

After the first successful cross-cluster replication, PegaProx should automatically add the expected replication ownership tags to the target VM, for example:

pegaprox-replica
xcrepl-job-a302ff3b

Subsequent replication runs should then recognize the existing target VM as belonging to that replication job and update it normally.

If creating the ownership tag fails, the replication job should ideally not be reported as fully successful, because the next scheduled run will fail.

Environment

  • PegaProx Version:
  • Installation Method: Docker
  • OS:
  • Browser: Chrome
  • Behind Reverse Proxy?
  • UI?

Logs

Initial replication completes successfully:

mtunnel started
received command 'version'
received command 'bwlimit'
received command 'disk-import'
ready

received command 'ticket'
received command 'query-disk-import'
disk-import: Importing image: 100% complete...done.

received command 'query-disk-import'
disk-import: successfully imported 'ceph:vm-100-disk-0'

received command 'config'
update VM 100: -balloon 0 -boot order=scsi0 -cipassword <hidden> -ciuser root -cores 1 -cpu host -description Cross-cluster replication a302ff3b -ide0 none,media=cdrom -ide2 none,media=cdrom -memory 1024 -name xcrepl-100-tmp -net0 virtio=BC:24:11:31:97:40,bridge=vmbr1,firewall=1,tag=21 -numa 0 -onboot 1 -ostype l26 -scsi0 ceph:vm-100-disk-0,iothread=1,size=10G -scsihw virtio-scsi-single -smbios1 uuid=912658a0-d400-41ec-a4b3-d15b80a7814b -sockets 1
received command 'unlock'
received command 'quit'
switching to exit-mode, waiting for client to disconnect
mtunnel exited
TASK OK

On the next replication run:

Target VM 100 on node bewst02pv02n001 is not tagged as a replica of this job
(xcrepl-job-21374341 tag missing).

Refusing to overwrite to prevent data loss.
If this is a stranded replica from a previous run or manual clone,
tag it with `xcrepl-job-21374341` and re-run.
If it is an unrelated VM, pick a different target VMID for the job.

After manually adding the correct xcrepl-job-<job-id> tag to the target VM, subsequent replication runs succeed.

Screenshots

Checklist

  • [ ] I have searched existing issues to make sure this is not a duplicate
  • [ ] I am using the latest version of PegaProx

Br00dkast avatar Sep 10 '26 10:09 Br00dkast

Hi @Br00dkast,

can you send the Proxmox side logs please? Our own log only tells us half the story here. What we need from the target node around the time the job ran:

  • the task log for the remote migration (/var/log/pve/tasks/, or the task in the PVE UI)
  • pvesh get /nodes/<node>/qemu/100/config right after a replication run — mainly whether there is a lock: line on it
  • /var/log/pve/access.log around that timestamp, the config PUT should show up there with its status

And if you can, grep your PegaProx log for XCREPL for job a302ff3b too. We tag the replica right after the migration finishes, and if the PUT gets rejected we log what PVE answered — that line would point straight at it. If nothing shows up at all then it failed a step earlier, which is also useful to know.

MrMasterbay avatar Sep 10 '26 10:09 MrMasterbay

I deleted the replication job and all snapshots it had created, then recreated the same cross-cluster replication job.

After recreating it, the replica now appears to be tagged correctly.

So this may have been related to stale state from the previous replication job or snapshots rather than the tagging logic itself.

Br00dkast avatar Sep 10 '26 12:09 Br00dkast

Good to hear it tags now. I would still keep this open though, because the part that bothers me is not that it failed once — it is that you never got told.

The tag write is best-effort all the way down: if the config read fails we return silently, and if the PUT is rejected we only log a warning. Then the next scheduled run hits a hard stop because the tag is missing. So whatever went wrong in your first job, it reported success and only surfaced a week later as a refusal to overwrite. That pairing is the actual bug, stale state or not.

Leaving it open on that basis rather than closing it as "works now".

Marcus

mkellermann97 avatar Sep 10 '26 13:09 mkellermann97

Fixed on Testing.

To close the loop on what I said earlier: the tag write was best-effort in every direction — a failed config read returned silently, a rejected write only logged a warning — while the check that reads that same tag on the next run aborts the job outright. So the run that actually broke the pairing reported success, and you met the problem a day later as a message about a tag nobody had told you we failed to write. That asymmetry is what your report exposed, whatever the original trigger was.

Three changes:

  • The tag is read back after writing it. A 200 from PVE is not proof: it queues the config write behind the guest lock the migration has only just released, and the next run's check reads the config, not our status code. So it is confirmed the same way the check will confirm it.
  • Two retries with a short backoff before giving up. If the guest lock is the cause — which fits your case self-resolving after a recreate — it clears on its own and this becomes a non-event.
  • If it genuinely cannot be written, the run reports error with the tag to apply, the VMID and node, and the reason. On the run that failed, not the one after.

Both cross-cluster paths, full and incremental, do this now. The in-cluster path stays non-fatal on purpose: an untagged replica there only costs the cleanup pass its handle on the old copies, so they pile up rather than the job refusing to run.

Ships in the next release. If it ever does fail on you again you should get a specific reason instead of silence, which is the part I actually wanted out of this.

mkellermann97 avatar Sep 10 '26 15:09 mkellermann97

Shipped in 1.2.0.

To close the loop on what bothered me more than the original symptom: the tag write was best-effort in every direction while the check that reads it aborts the next run outright. So the run that broke the pairing reported success and you met the problem a day later. It now confirms the tag actually stuck and says so when it didn't.

Marcus

— if it's worth something to you: https://opencollective.com/pegaprox

mkellermann97 avatar Sep 21 '26 07:09 mkellermann97