CSNAPC-8087: Stale entries are getting piled up in nsm db leading to primary retention failure
Issue
SCSQL Retention frequently fails during the RemoveBackupToSnapshotInfo function, which leads to subsequent issues with dropped MySQL connections and ensuing constraint errors (stemming from the MySQL connection being dropped after running the query for a while).
The following errors will be seen:
SnapManagerWeb_1234 PID=[123] TID=[28] Error deleting BackupToSnapshot records for backup id 273132. Error: An incomplete response was received from the server
SnapManagerWeb_1234 PID=[123] TID=[28] Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
---> MySqlConnector.MySqlException (0x80004005): Cannot delete or update a parent row: a foreign key constraint fails (`nsm`.`nsm_backuptoobjects_map`, CONSTRAINT `FK_nsm_BackupMetadata_map_nsm_Backup` FOREIGN KEY (`nsm_Backup_Id`) REFERENCES `nsm_backup` (`nsm_Backup_Id`))
2024-10-16T14:48:05.0971064+02:00 DEBUG SnapManagerWeb_1234 PID=[123] TID=[28] Cannot delete or update a parent row: a foreign key constraint fails (`nsm`.`nsm_backuptoobjects_map`, CONSTRAINT `FK_nsm_BackupMetadata_map_nsm_Backup` FOREIGN KEY (`nsm_Backup_Id`) REFERENCES `nsm_backup`
(`nsm_Backup_Id`))
SnapManagerWeb_1234 PID=[123] TID=[38] RemoveBackupToSnapshotInfo - Enter 2024-10-30T06:08:01.9784409+01:00 ERROR SnapManagerWeb_1234 PID=[123] TID=[38] Error deleting BackupToSnapshot records for backup id 273201. Error: An incomplete response was received from the server
SnapManagerWeb_1234 PID=[123] TID=[38] RemoveBackupToSnapshotInfo - Exit
OR:
SnapManagerWeb_425169 PID=[124] TID=[16] RemoveBackupToSnapshotInfo - Enter
SnapManagerWeb_425169 PID=[124] TID=[16] Error deleting BackupToSnapshot records for backup id 273138. Error: An existing connection was forcibly closed by the remote host.
SnapManagerWeb_425169 PID=[124] TID=[16] RemoveBackupToSnapshotInfo - Exit