Skip to content

Commit

Permalink
In both perl clients, adjust the message format for errors issued by …
Browse files Browse the repository at this point in the history
…postgres. Split the message on 2 lines (as what has been done for php clients) so that the check_error_messages.pl tool can recognize them.
  • Loading branch information
beaud76 committed Mar 27, 2023
1 parent 4e76f4f commit 6cbef29
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 28 deletions.
28 changes: 14 additions & 14 deletions client/emajParallelRollback.pl
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,28 @@ sub check_opt_session {
for (my $i = 1 ; $i <= $nbSession; $i++) {
print (strftime('%d/%m/%Y - %H:%M:%S',localtime)." Open session #$i...\n") if ($verbose);
$dbh[$i] = DBI->connect('dbi:Pg:'.$conn_string,$username,$password,{AutoCommit => 1, RaiseError => 0, PrintError => 0})
or die("Opening the session #$i failed. $DBI::errstr\n");
or die("Opening the session #$i failed.\n$DBI::errstr\n");
}

# Set the application_name
for (my $i = 1 ; $i <= $nbSession; $i++) {
$dbh[$i]->do("SET application_name to '$APPNAME'")
or die("Setting the application_name for session #$i failed. $DBI::errstr\n");
or die("Setting the application_name for session #$i failed.\n$DBI::errstr\n");
}

# For each session, start a transaction
for (my $i = 1 ; $i <= $nbSession; $i++) {
print (strftime('%d/%m/%Y - %H:%M:%S',localtime)." Start transaction #$i...\n") if ($verbose);
$dbh[$i]->begin_work()
or die("Begin transaction #$i failed. $DBI::errstr\n");
or die("Begin transaction #$i failed.\n$DBI::errstr\n");
}

# Call _rlbk_init() on first session
# This checks the groups and mark, and prepares the parallel rollback by creating well balanced sessions
print (strftime('%d/%m/%Y - %H:%M:%S',localtime)." Call _rlbk_init() for groups $groups and mark $mark....\n") if ($verbose);
$stmt[1] = $dbh[1]->prepare("SELECT emaj._rlbk_init(array[$groups], " . $dbh[1]->quote($mark) . ", $isLogged, $nbSession, $multiGroup, $isAlterGroupAllowed)");
$stmt[1]->execute()
or die("Calling the _rlbk_init() function failed. $DBI::errstr\n");
or die("Calling the _rlbk_init() function failed.\n$DBI::errstr\n");
my $rlbkId = $stmt[1]->fetchrow_array();
$stmt[1]->finish;
print ("==> $msgRlbk to mark '$mark' is now in progress with $nbSession sessions...\n");
Expand All @@ -143,68 +143,68 @@ sub check_opt_session {
for (my $i = 1 ; $i <= $nbSession; $i++) {
print (strftime('%d/%m/%Y - %H:%M:%S',localtime)." Call _rlbk_session_lock() for session #$i -> lock tables...\n") if ($verbose);
$dbh[$i]->do("SELECT emaj._rlbk_session_lock($rlbkId, $i)")
or die("Calling the _rlbk_session_lock() function for #$i failed. $DBI::errstr\n");
or die("Calling the _rlbk_session_lock() function for #$i failed.\n$DBI::errstr\n");
}

# Call _rlbk_start_mark() on first session
# This sets a rollback start mark if logged rollback
print (strftime('%d/%m/%Y - %H:%M:%S',localtime)." Call _rlbk_start_mark() ...\n") if ($verbose);
$dbh[1]->do("SELECT emaj._rlbk_start_mark($rlbkId, $multiGroup)")
or die("Calling the _rlbk_start_mark() function failed. $DBI::errstr\n");
or die("Calling the _rlbk_start_mark() function failed.\n$DBI::errstr\n");

# For each session, asynchronously call _rlbk_exec() to start the planned steps execution
for (my $i = 1 ; $i <= $nbSession; $i++) {
print (strftime('%d/%m/%Y - %H:%M:%S',localtime)." Call _rlbk_session_exec() for session #$i -> rollback tables...\n") if ($verbose);
$dbh[$i]->do("SELECT emaj._rlbk_session_exec($rlbkId, $i)", {pg_async => PG_ASYNC})
or die("Calling the _rlbk_session_exec() function for #$i failed. $DBI::errstr\n");
or die("Calling the _rlbk_session_exec() function for #$i failed.\n$DBI::errstr\n");
}

# For each session, get the result of the previous call of _rlbk_exec()
for (my $i = 1 ; $i <= $nbSession; $i++) {
$dbh[$i]->pg_result()
or die("Getting the result of the _rlbk_session_exec() function call failed for #$i. $DBI::errstr\n");
or die("Getting the result of the _rlbk_session_exec() function call failed for #$i.\n$DBI::errstr\n");
print (strftime('%d/%m/%Y - %H:%M:%S',localtime)." get result of _rlbk_session_exec call for session #$i...\n") if ($verbose);
}

# Call emaj_rlbk_end() on first session to complete the rollback operation
print (strftime('%d/%m/%Y - %H:%M:%S',localtime)." Call _rlbk_end() -> complete rollback operation...\n") if ($verbose);
$stmt[1] = $dbh[1]->prepare("SELECT * FROM emaj._rlbk_end($rlbkId, $multiGroup)");
$stmt[1]->execute()
or die("Calling the _rlbk_end() function failed. $DBI::errstr\n");
or die("Calling the _rlbk_end() function failed.\n$DBI::errstr\n");
my $execReportRows = $stmt[1]->fetchall_arrayref();
$stmt[1]->finish;

if ($nbSession == 1) {
# If there is only 1 session, perform a usual COMMIT
print (strftime('%d/%m/%Y - %H:%M:%S',localtime)." Commit transaction #1...\n") if ($verbose);
$dbh[1]->commit
or die("Commit prepared #1 failed. $DBI::errstr\n");
or die("Commit prepared #1 failed.\n$DBI::errstr\n");
} else {
# else, COMMIT with 2PC to be sure that all sessions can either commit or rollback in a single transaction
# Phase 1 : Prepare transaction
for (my $i = 1 ; $i <= $nbSession; $i++) {
print (strftime('%d/%m/%Y - %H:%M:%S',localtime)." Prepare transaction #$i...\n") if ($verbose);
$dbh[$i]->do("PREPARE TRANSACTION 'emajtx$i'")
or die("Prepare transaction #$i failed. $DBI::errstr\n");
or die("Prepare transaction #$i failed.\n$DBI::errstr\n");
}
# Phase 2 : Commit
for (my $i = 1 ; $i <= $nbSession; $i++) {
print (strftime('%d/%m/%Y - %H:%M:%S',localtime)." Commit transaction #$i...\n") if ($verbose);
$dbh[$i]->do("COMMIT PREPARED 'emajtx$i'")
or die("Commit prepared #$i failed. $DBI::errstr\n");
or die("Commit prepared #$i failed.\n$DBI::errstr\n");
}
}

# Call the emaj_cleanup_rollback_state() function to set the rollback event as committed
print (strftime('%d/%m/%Y - %H:%M:%S',localtime)." Call emaj_cleanup_rollback_state() -> set the rollback event as committed...\n") if ($verbose);
$dbh[1]->do("SELECT emaj.emaj_cleanup_rollback_state()")
or die("Calling the emaj_cleanup_rollback_state() function failed. $DBI::errstr\n");
or die("Calling the emaj_cleanup_rollback_state() function failed.\n$DBI::errstr\n");

# Close the sessions
print (strftime('%d/%m/%Y - %H:%M:%S',localtime)." Close all sessions...\n") if ($verbose);
for (my $i = 1 ; $i <= $nbSession; $i++) {
$dbh[$i]->disconnect
or die("Disconnect for session #$i failed: $DBI::errstr\n");
or die("Disconnect for session #$i failed:\n$DBI::errstr\n");
}
#clean up on error
END {
Expand Down
8 changes: 4 additions & 4 deletions client/emajRollbackMonitor.pl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ sub check_opt_nbIter {

# Set the application_name
$dbh->do("SET application_name to '$APPNAME'")
or die("Setting the application_name failed. $DBI::errstr\n");
or die("Setting the application_name failed.\n$DBI::errstr\n");

# Perform the monitoring
for (my $i=1; $i<=$nbIter; $i++){
Expand All @@ -133,7 +133,7 @@ sub check_opt_nbIter {
ORDER BY rlbk_id DESC LIMIT $nbComplRlbk) AS t
ORDER BY rlbk_id ASC");
$stmt->execute()
or die("Accessing to the emaj_rlbk table failed. $DBI::errstr \n");
or die("Accessing to the emaj_rlbk table failed.\n$DBI::errstr \n");

# Display results
$dbh->{pg_expand_array} = 0;
Expand All @@ -156,7 +156,7 @@ sub check_opt_nbIter {
format('%s/%s', coalesce(rlbk_eff_nb_sequence::TEXT, '?'), rlbk_nb_sequence) AS rlbk_seq
FROM emaj.emaj_rollback_activity() ORDER BY rlbk_id");
$stmt->execute()
or die("Calling of emaj_rollback_activity() function failed. $DBI::errstr\n");
or die("Calling of emaj_rollback_activity() function failed.\n$DBI::errstr\n");

# Display results
while ( $row = $stmt->fetchrow_hashref()) {
Expand Down Expand Up @@ -184,7 +184,7 @@ sub check_opt_nbIter {

# Close the sessions
$dbh->disconnect
or die("Disconnect failed. $DBI::errstr\n");
or die("Disconnect failed.\n$DBI::errstr\n");

sub print_help {
print qq{$PROGRAM belongs to the E-Maj PostgreSQL extension (version $VERSION).
Expand Down
6 changes: 4 additions & 2 deletions test/11/expected/client.out
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ alter sequence mySchema2.mySeq1 restart 9999;
-- parallel rollback, but with disabled dblink connection
delete from emaj.emaj_param where param_key = 'dblink_user_password';
\! ${EMAJ_DIR}/client/emajParallelRollback.pl -h localhost -d regression -g "myGroup1,myGroup2" -m Multi-1 -s 3 -l
Calling the _rlbk_init() function failed. ERROR: _rlbk_init: Cannot use several sessions without dblink connection capability. (Status of the dblink connection attempt = -5 - see E-Maj documentation)
Calling the _rlbk_init() function failed.
ERROR: _rlbk_init: Cannot use several sessions without dblink connection capability. (Status of the dblink connection attempt = -5 - see E-Maj documentation)
CONTEXT: PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 52 at RAISE
E-Maj (version <devel>) - launching parallel rollbacks
-----------------------------------------------------------
Expand All @@ -114,7 +115,8 @@ select emaj.emaj_modify_table('myschema1', 'mytbl1', '{"priority": 1}'::jsonb);
(1 row)

\! ${EMAJ_DIR}/client/emajParallelRollback.pl -h localhost -d regression -g "myGroup1,myGroup2" -m Multi-1 -s 3 -l
Calling the _rlbk_init() function failed. ERROR: _rlbk_check: This rollback operation would cross some previous structure group change operations, which is not allowed by the current function parameters.
Calling the _rlbk_init() function failed.
ERROR: _rlbk_check: This rollback operation would cross some previous structure group change operations, which is not allowed by the current function parameters.
CONTEXT: PL/pgSQL function emaj._rlbk_check(text[],text,boolean,boolean) line 60 at RAISE
SQL statement "SELECT emaj._rlbk_check(p_groupNames, p_mark, p_isAlterGroupAllowed, FALSE)"
PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 23 at SQL statement
Expand Down
6 changes: 4 additions & 2 deletions test/12/expected/client.out
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ alter sequence mySchema2.mySeq1 restart 9999;
-- parallel rollback, but with disabled dblink connection
delete from emaj.emaj_param where param_key = 'dblink_user_password';
\! ${EMAJ_DIR}/client/emajParallelRollback.pl -h localhost -d regression -g "myGroup1,myGroup2" -m Multi-1 -s 3 -l
Calling the _rlbk_init() function failed. ERROR: _rlbk_init: Cannot use several sessions without dblink connection capability. (Status of the dblink connection attempt = -5 - see E-Maj documentation)
Calling the _rlbk_init() function failed.
ERROR: _rlbk_init: Cannot use several sessions without dblink connection capability. (Status of the dblink connection attempt = -5 - see E-Maj documentation)
CONTEXT: PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 52 at RAISE
E-Maj (version <devel>) - launching parallel rollbacks
-----------------------------------------------------------
Expand All @@ -114,7 +115,8 @@ select emaj.emaj_modify_table('myschema1', 'mytbl1', '{"priority": 1}'::jsonb);
(1 row)

\! ${EMAJ_DIR}/client/emajParallelRollback.pl -h localhost -d regression -g "myGroup1,myGroup2" -m Multi-1 -s 3 -l
Calling the _rlbk_init() function failed. ERROR: _rlbk_check: This rollback operation would cross some previous structure group change operations, which is not allowed by the current function parameters.
Calling the _rlbk_init() function failed.
ERROR: _rlbk_check: This rollback operation would cross some previous structure group change operations, which is not allowed by the current function parameters.
CONTEXT: PL/pgSQL function emaj._rlbk_check(text[],text,boolean,boolean) line 60 at RAISE
SQL statement "SELECT emaj._rlbk_check(p_groupNames, p_mark, p_isAlterGroupAllowed, FALSE)"
PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 23 at SQL statement
Expand Down
6 changes: 4 additions & 2 deletions test/13/expected/client.out
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ alter sequence mySchema2.mySeq1 restart 9999;
-- parallel rollback, but with disabled dblink connection
delete from emaj.emaj_param where param_key = 'dblink_user_password';
\! ${EMAJ_DIR}/client/emajParallelRollback.pl -h localhost -d regression -g "myGroup1,myGroup2" -m Multi-1 -s 3 -l
Calling the _rlbk_init() function failed. ERROR: _rlbk_init: Cannot use several sessions without dblink connection capability. (Status of the dblink connection attempt = -5 - see E-Maj documentation)
Calling the _rlbk_init() function failed.
ERROR: _rlbk_init: Cannot use several sessions without dblink connection capability. (Status of the dblink connection attempt = -5 - see E-Maj documentation)
CONTEXT: PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 52 at RAISE
E-Maj (version <devel>) - launching parallel rollbacks
-----------------------------------------------------------
Expand All @@ -114,7 +115,8 @@ select emaj.emaj_modify_table('myschema1', 'mytbl1', '{"priority": 1}'::jsonb);
(1 row)

\! ${EMAJ_DIR}/client/emajParallelRollback.pl -h localhost -d regression -g "myGroup1,myGroup2" -m Multi-1 -s 3 -l
Calling the _rlbk_init() function failed. ERROR: _rlbk_check: This rollback operation would cross some previous structure group change operations, which is not allowed by the current function parameters.
Calling the _rlbk_init() function failed.
ERROR: _rlbk_check: This rollback operation would cross some previous structure group change operations, which is not allowed by the current function parameters.
CONTEXT: PL/pgSQL function emaj._rlbk_check(text[],text,boolean,boolean) line 60 at RAISE
SQL statement "SELECT emaj._rlbk_check(p_groupNames, p_mark, p_isAlterGroupAllowed, FALSE)"
PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 23 at SQL statement
Expand Down
6 changes: 4 additions & 2 deletions test/14/expected/client.out
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ alter sequence mySchema2.mySeq1 restart 9999;
-- parallel rollback, but with disabled dblink connection
delete from emaj.emaj_param where param_key = 'dblink_user_password';
\! ${EMAJ_DIR}/client/emajParallelRollback.pl -h localhost -d regression -g "myGroup1,myGroup2" -m Multi-1 -s 3 -l
Calling the _rlbk_init() function failed. ERROR: _rlbk_init: Cannot use several sessions without dblink connection capability. (Status of the dblink connection attempt = -5 - see E-Maj documentation)
Calling the _rlbk_init() function failed.
ERROR: _rlbk_init: Cannot use several sessions without dblink connection capability. (Status of the dblink connection attempt = -5 - see E-Maj documentation)
CONTEXT: PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 52 at RAISE
E-Maj (version <devel>) - launching parallel rollbacks
-----------------------------------------------------------
Expand All @@ -114,7 +115,8 @@ select emaj.emaj_modify_table('myschema1', 'mytbl1', '{"priority": 1}'::jsonb);
(1 row)

\! ${EMAJ_DIR}/client/emajParallelRollback.pl -h localhost -d regression -g "myGroup1,myGroup2" -m Multi-1 -s 3 -l
Calling the _rlbk_init() function failed. ERROR: _rlbk_check: This rollback operation would cross some previous structure group change operations, which is not allowed by the current function parameters.
Calling the _rlbk_init() function failed.
ERROR: _rlbk_check: This rollback operation would cross some previous structure group change operations, which is not allowed by the current function parameters.
CONTEXT: PL/pgSQL function emaj._rlbk_check(text[],text,boolean,boolean) line 60 at RAISE
SQL statement "SELECT emaj._rlbk_check(p_groupNames, p_mark, p_isAlterGroupAllowed, FALSE)"
PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 23 at SQL statement
Expand Down
6 changes: 4 additions & 2 deletions test/15/expected/client.out
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ alter sequence mySchema2.mySeq1 restart 9999;
-- parallel rollback, but with disabled dblink connection
delete from emaj.emaj_param where param_key = 'dblink_user_password';
\! ${EMAJ_DIR}/client/emajParallelRollback.pl -h localhost -d regression -g "myGroup1,myGroup2" -m Multi-1 -s 3 -l
Calling the _rlbk_init() function failed. ERROR: _rlbk_init: Cannot use several sessions without dblink connection capability. (Status of the dblink connection attempt = -5 - see E-Maj documentation)
Calling the _rlbk_init() function failed.
ERROR: _rlbk_init: Cannot use several sessions without dblink connection capability. (Status of the dblink connection attempt = -5 - see E-Maj documentation)
CONTEXT: PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 52 at RAISE
E-Maj (version <devel>) - launching parallel rollbacks
-----------------------------------------------------------
Expand All @@ -114,7 +115,8 @@ select emaj.emaj_modify_table('myschema1', 'mytbl1', '{"priority": 1}'::jsonb);
(1 row)

\! ${EMAJ_DIR}/client/emajParallelRollback.pl -h localhost -d regression -g "myGroup1,myGroup2" -m Multi-1 -s 3 -l
Calling the _rlbk_init() function failed. ERROR: _rlbk_check: This rollback operation would cross some previous structure group change operations, which is not allowed by the current function parameters.
Calling the _rlbk_init() function failed.
ERROR: _rlbk_check: This rollback operation would cross some previous structure group change operations, which is not allowed by the current function parameters.
CONTEXT: PL/pgSQL function emaj._rlbk_check(text[],text,boolean,boolean) line 60 at RAISE
SQL statement "SELECT emaj._rlbk_check(p_groupNames, p_mark, p_isAlterGroupAllowed, FALSE)"
PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 23 at SQL statement
Expand Down

0 comments on commit 6cbef29

Please sign in to comment.