From cf6b9b75c415cf26f697399d05c7687cb0112081 Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Mon, 12 Sep 2022 15:05:20 +0200 Subject: [PATCH] TT#190250 switch replication binlog_format IODKU statements can fail for master-master replication. switching to 'STATEMENT' binlog_format to mitigate. Change-Id: I5e7d2438c6338e6cc7b17bf9c51a8a4712f72454 --- rate-o-mat.pl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rate-o-mat.pl b/rate-o-mat.pl index afc975c..0803411 100755 --- a/rate-o-mat.pl +++ b/rate-o-mat.pl @@ -288,6 +288,7 @@ sub connect_billdbh { FATAL "Error connecting to db: ".$DBI::errstr unless defined($billdbh); $billdbh->do('SET time_zone = ?',undef,$connection_timezone) or FATAL 'error setting connection timezone' if $connection_timezone; + $billdbh->do("SET SESSION binlog_format = 'STATEMENT'") or FATAL 'error setting session binlog_format'; INFO "Successfully connected to billing db..."; } @@ -302,6 +303,7 @@ sub connect_acctdbh { FATAL "Error connecting to db: ".$DBI::errstr unless defined($acctdbh); $acctdbh->do('SET time_zone = ?',undef,$connection_timezone) or FATAL 'error setting connection timezone' if $connection_timezone; + $acctdbh->do("SET SESSION binlog_format = 'STATEMENT'") or FATAL 'error setting session binlog_format'; INFO "Successfully connected to accounting db..."; } @@ -322,6 +324,7 @@ sub connect_provdbh { FATAL "Error connecting to db: ".$DBI::errstr unless defined($provdbh); $provdbh->do('SET time_zone = ?',undef,$connection_timezone) or FATAL 'error setting connection timezone' if $connection_timezone; + $provdbh->do("SET SESSION binlog_format = 'STATEMENT'") or FATAL 'error setting session binlog_format'; INFO "Successfully connected to provisioning db..."; } @@ -342,6 +345,7 @@ sub connect_dupdbh { FATAL "Error connecting to db: ".$DBI::errstr unless defined($dupdbh); $dupdbh->do('SET time_zone = ?',undef,$connection_timezone) or FATAL 'error setting connection timezone' if $connection_timezone; + $dupdbh->do("SET SESSION binlog_format = 'STATEMENT'") or FATAL 'error setting session binlog_format'; INFO "Successfully connected to duplication db..."; } @@ -712,13 +716,13 @@ EOS ) or FATAL "Error preparing get contract balance statement: ".$billdbh->errstr; $sth_new_cbalance = $billdbh->prepare( - "INSERT INTO billing.contract_balances (". + "INSERT IGNORE INTO billing.contract_balances (". " contract_id, cash_balance, initial_cash_balance, cash_balance_interval, free_time_balance, initial_free_time_balance, free_time_balance_interval, underrun_profiles, underrun_lock, start, end". ") VALUES (?, ?, ?, ?, ?, ?, ?, IF(? = 0, NULL, FROM_UNIXTIME(?)), IF(? = 0, NULL, FROM_UNIXTIME(?)), FROM_UNIXTIME(?), FROM_UNIXTIME(?))" ) or FATAL "Error preparing create contract balance statement: ".$billdbh->errstr; $sth_new_cbalance_infinite_future = $billdbh->prepare( - "INSERT INTO billing.contract_balances (". + "INSERT IGNORE INTO billing.contract_balances (". " contract_id, cash_balance, initial_cash_balance, cash_balance_interval, free_time_balance, initial_free_time_balance, free_time_balance_interval, underrun_profiles, underrun_lock, start, end". ") VALUES (?, ?, ?, ?, ?, ?, ?, IF(? = 0, NULL, FROM_UNIXTIME(?)), IF(? = 0, NULL, FROM_UNIXTIME(?)), FROM_UNIXTIME(?), '9999-12-31 23:59:59')" ) or FATAL "Error preparing create contract balance statement: ".$billdbh->errstr; @@ -797,7 +801,7 @@ EOS "SELECT id,value FROM provisioning.voip_usr_preferences WHERE attribute_id = ? AND subscriber_id = ?" ) or FATAL "Error preparing get usr preference value statement: ".$provdbh->errstr; $sth_create_usr_preference_value = $provdbh->prepare( - "INSERT INTO provisioning.voip_usr_preferences (subscriber_id, attribute_id, value) VALUES (?, ?, ?)" + "INSERT IGNORE INTO provisioning.voip_usr_preferences (subscriber_id, attribute_id, value) VALUES (?, ?, ?)" ) or FATAL "Error preparing create usr preference value statement: ".$provdbh->errstr; $sth_update_usr_preference_value = $provdbh->prepare( "UPDATE provisioning.voip_usr_preferences SET value = ? WHERE id = ?" @@ -3672,7 +3676,7 @@ sub main { next CDR; } # required to avoid contract_balances duplications during catchup: - begin_transaction($billdbh,'READ COMMITTED'); + begin_transaction($billdbh); #,'READ COMMITTED'); # row locks are released upon commit/rollback and have to cover # the whole transaction. thus locking contract rows for preventing # concurrent catchups will be our very first SQL statement in the