Skip to content

mactrack: fail the rebuild when the drained source cannot be dropped - #424

Merged
TheWitness merged 1 commit into
developfrom
fix/mactrack-agg-rebuild-drop-retry
Nov 12, 2026
Merged

TheWitness merged 1 commit into
developfrom
fix/mactrack-agg-rebuild-drop-retry

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

Follow-up to #423 (merged). The Copilot review of #423 posted one more comment after it was merged: if the aggregated-ports rebuild's final DROP TABLE on the drained work table failed, the rebuild still set mt_aggregated_ports_rebuilt = on and reported success.

That left a stuck state: the leftover mac_track_aggregated_ports_upgrade table keeps the poller paused and the web hook launching upgrades, but every retry takes the rebuilt-flag early return and never attempts the drop again.

Fix

mactrack_rebuild_aggregated_ports() now checks the DROP TABLE IF EXISTS result and returns false (logging) before setting the completion flag. The flag stays off, so the next relaunch runs the full path again — the source is already drained, so it goes straight to the COUNT guard and retries the drop — instead of taking the early return. Cleanup stays retryable.

Testing

  • Unit suite: all green (AggregatedPortsRebuildTest adds testRebuildRetriesWhenDroppingTheDrainedSourceFails).
  • 100% patch coverage of the changed lines; PHPStan level 6 clean.

Copilot third pass: if DROP TABLE on the drained mac_track_aggregated_ports_upgrade
failed, the rebuild still set mt_aggregated_ports_rebuilt=on and returned
success. The leftover table then kept the poller paused and the web hook
launching, but every retry took the rebuilt-flag early return and never
attempted the drop again. Check the DROP result and return false before
recording completion so cleanup stays retryable.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 20:20
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change that keeps aggregated-ports cleanup retryable after a failed table drop.

No open issues 🎉

What changed in this PR

Keeps cleanup retryable in MacTrack’s background database upgrade when dropping the drained aggregated-ports source table fails.

Changes:

  • Logs the failed drop and returns false before setting the rebuild completion flag.
  • Adds a regression test confirming that drop failure reports failure and leaves completion unset.
File Description
tests/​Unit/​AggregatedPortsRebuildTest.php Tests failure handling when the drained source cannot be dropped.
includes/​database.php Checks the drop result before marking the rebuild complete.

Review effort: Balanced

@TheWitness
TheWitness merged commit 0fe7995 into develop Nov 12, 2026
10 checks passed
@TheWitness
TheWitness deleted the fix/mactrack-agg-rebuild-drop-retry branch November 12, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants