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 e0d143ec3b)
mr8.5.2
Rene Krenn 6 years ago
parent ddd55680ad
commit c1f4672c12

@ -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
}

Loading…
Cancel
Save