TT#69550 fix possible leftover redis acc records

We must distinguish between old-style acc records without an appended
branch ID (key ends in `:<ts>`) and broken new-stype acc records with an
empty branch ID (key ends in `:<ts>:`). Failure to do so results in
leftover entries in the DB that are never trashed and repeatedly
processed.

Change-Id: I61a4086359369e460cf23cacfd53854605a6a955
changes/61/34761/1
Richard Fuchs 7 years ago
parent b431c48a21
commit beb28bdaca

@ -826,21 +826,35 @@ static int medredis_cleanup_entries(med_entry_t *records, uint64_t count, const
if (!e->redis)
continue;
if (strlen(e->branch_id) == 0) {
// Old ACC record version: it doesn't have branch_id
snprintf(buffer, sizeof(buffer), "acc:entry::%s:%f", e->callid, e->unix_timestamp);
}
else {
snprintf(buffer, sizeof(buffer), "acc:entry::%s:%f:%s", e->callid, e->unix_timestamp, e->branch_id);
}
const char *branch_id = e->branch_id;
L_DEBUG("Cleaning up redis entry for %s\n", buffer);
if (medredis_remove_mappings(e->callid, buffer) != 0) {
goto err;
}
if (medredis_remove_entry(buffer) != 0) {
goto err;
// do this at most twice: once with an empty branch ID, and once without a branch ID at all
do {
if (branch_id == NULL) {
// Old ACC record version: it doesn't have branch_id
snprintf(buffer, sizeof(buffer), "acc:entry::%s:%f", e->callid, e->unix_timestamp);
}
else {
snprintf(buffer, sizeof(buffer), "acc:entry::%s:%f:%s", e->callid, e->unix_timestamp, branch_id);
}
L_DEBUG("Cleaning up redis entry for %s\n", buffer);
if (medredis_remove_mappings(e->callid, buffer) != 0) {
goto err;
}
if (medredis_remove_entry(buffer) != 0) {
goto err;
}
// exit condition: if the branch ID is non-NULL but an empty string, try again with
// a NULL branch ID.
// otherwise (branch ID is NULL or a non-empty string) we break.
if (branch_id == NULL || strlen(branch_id) != 0)
break;
branch_id = NULL;
}
while (1);
}
return 0;

Loading…
Cancel
Save