Problem: upsert_mac_address was using Repo.one() which crashes with Ecto.MultipleResultsError when duplicate MAC address records exist in the database. Root Cause: Race condition or historical data corruption created duplicate entries for the same (device_id, mac_address, vlan_id) tuple, violating the unique constraint. Fix: - Changed Repo.one() to Repo.all() to handle duplicates gracefully - When duplicates found: keep first entry, delete extras, log warning - Includes device_id, mac_address, vlan_id, and duplicate IDs in log - Auto-cleans corrupted data while maintaining service availability Example Log Output: Found 1 duplicate MAC address entries, cleaning up device_id=f3ff19d5-b519-4327-9f7d-dc416e494cfa mac_address=78:9a:18:52:b1:c6 vlan_id=nil duplicate_ids=[...] Impact: - Prevents polling crashes when duplicate MAC entries exist - Self-healing: automatically cleans up database corruption - Maintains data integrity while preserving service availability Related: Issue 2.9 from bugs analysis (ARP/MAC parsing issues) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| mix/tasks | ||
| snmpkit | ||
| towerops | ||
| towerops_web | ||
| snmp_lib.ex | ||
| snmp_mgr.ex | ||
| snmpkit.ex | ||
| towerops.ex | ||
| towerops_native.ex | ||
| towerops_web.ex | ||