From beb28bdacaff89f625c0ede34bb2aab0c4ce993b Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 29 Oct 2019 11:19:47 -0400 Subject: [PATCH] TT#69550 fix possible leftover redis acc records We must distinguish between old-style acc records without an appended branch ID (key ends in `:`) and broken new-stype acc records with an empty branch ID (key ends in `::`). Failure to do so results in leftover entries in the DB that are never trashed and repeatedly processed. Change-Id: I61a4086359369e460cf23cacfd53854605a6a955 --- medredis.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/medredis.c b/medredis.c index 8c973b2..20303ea 100644 --- a/medredis.c +++ b/medredis.c @@ -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;