From 32ef9fe3746111d5f3f45851071efd18366c1a85 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 14 Oct 2022 09:55:12 -0400 Subject: [PATCH] MT#55628 track individual CDRs Use a queue to keep track of the position of each CDR entry as it is added into the SQL string. This allows us to inspect each entry individually if the insert goes wrong. Change-Id: I2f95e35030c3f55f8ccd3efb3ef20684f301af2e (cherry picked from commit 8a3226759f9c9fbbaa45e0436d68d3aa60a6ebb8) --- medmysql.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/medmysql.c b/medmysql.c index 45202fe..cb25c49 100644 --- a/medmysql.c +++ b/medmysql.c @@ -60,6 +60,11 @@ typedef struct _cdr_tag_record { unsigned long long cdr_id; char *sql_record; } cdr_tag_record; +typedef struct { + const char *begin; + const char *end; + unsigned long cdr_id; +} single_cdr; typedef struct _medmysql_batch_definition { const char *sql_init_string, @@ -1110,6 +1115,12 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, uint64_t count, struct medmysql_b const char *end_ptr = batch->cdrs.str + batch->cdrs.len; L_DEBUG("CDR entry to be written: %.*s", (int) (end_ptr - begin_ptr), begin_ptr); + single_cdr *single = g_slice_alloc(sizeof(*single)); + single->begin = begin_ptr; + single->end = end_ptr; + single->cdr_id = batch->num_cdrs; + g_queue_push_tail(&batch->cdrs.q, single); + if (medmysql_tag_cdr(batch, medmysql_tag_provider_customer, medmysql_tag_direction_destination, "furnished_charging_info", e->furnished_charging_info, e)) return -1; @@ -1578,6 +1589,10 @@ static int medmysql_flush_cdr_batch(struct medmysql_cdr_batch *batch) { return -1; } + single_cdr *single; + while ((single = g_queue_pop_head(&batch->cdrs.q))) + g_slice_free1(sizeof(*single), single); + if (medmysql_write_cdr_tags(batch, auto_id)) return -1; if (medmysql_flush_med_str(&batch->tags))