From a577b8cd8f1b5f3befcc3e5dee0a341b4c7d201f Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Thu, 23 Jul 2020 10:54:06 +0200 Subject: [PATCH] TT#75901 cdr_status_data UPSERT should return 0 if already exported CDR export jobs such as ama exporter or cdr-exporter must never execute on both active/passive node. because the output folder resides on a glusterfs filesystem, this will cause merged or duplicate files, and calls charged twice to customers subsequentially. for .ama, the 2-phase commit steps for exporting CDRs were separated already: (a) rename .tmp file to final output file name (b) commit db transaction: - cdrexportstatus of all cdrs of that file - file sequence number increment The implemented 2PC flow will prevent (a) properly, if (b) fails. This is now leveraged (by escalating the UPSERT not changing anything) to abandon a whole file, if a single CDR shows an exportstatus other than "unexported". Such CDRs indicate there is a race condition with another exporter (which was quicker here). the same thechnique also has to be added to cdr-exporter, which unfortunately has no 2PC flow impl yet. Change-Id: Ice40fa79d2b263018ee7825e314d63c9abe888ce (cherry picked from commit e0d143ec3b99d26f6ef064c2bac62cc3c6b05873) --- .../Dao/Trunk/accounting/cdr_export_status_data.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/NGCP/BulkProcessor/Dao/Trunk/accounting/cdr_export_status_data.pm b/lib/NGCP/BulkProcessor/Dao/Trunk/accounting/cdr_export_status_data.pm index 522f452..312df98 100644 --- a/lib/NGCP/BulkProcessor/Dao/Trunk/accounting/cdr_export_status_data.pm +++ b/lib/NGCP/BulkProcessor/Dao/Trunk/accounting/cdr_export_status_data.pm @@ -146,7 +146,8 @@ sub upsert_row { cdr_start_time /}; - if ($xa_db->db_do('INSERT INTO ' . $db->tableidentifier($tablename) . ' (' . + my $result; + if ($result = $xa_db->db_do('INSERT INTO ' . $db->tableidentifier($tablename) . ' (' . $db->columnidentifier('cdr_id') . ', ' . $db->columnidentifier('status_id') . ', ' . $db->columnidentifier('export_status') . ', ' . @@ -156,7 +157,9 @@ sub upsert_row { '?, ' . '?, ' . 'NOW(), ' . - '?) ON DUPLICATE KEY UPDATE export_status = ?, exported_at = NOW()', + '?) ON DUPLICATE KEY UPDATE ' . + 'export_status = ?, ' . + 'exported_at = IF(export_status = "' . $UNEXPORTED . '",NOW(),exported_at)', $cdr_id, $status_id, $export_status, @@ -164,10 +167,9 @@ sub upsert_row { $export_status, )) { rowupserted($db,$tablename,getlogger(__PACKAGE__)); - return 1; } - return undef; + return $result; # 0 .. no change, 1 .. inserted, 2 .. updated }