on 2021 Jul 21 5:28 AM
I'm trying to change the default action code from 3000 to 1000, and I used the example from the documentation like below, but it doesn't work. Once MLSRV17 encounters an error then it tries it 10 times and then stop with (synchronization failed).
call ml_add_connection_script(
'ver1',
'handle_error',
'call MyLog({ml s.action_code})'
);
create or replace procedure MyLog(inout @action_code int)
begin
set @action_code = 1000;
end;
Locking is a special case in which the handle_error event is not called because the ML Server will (when possible) detect that locking has occured and retry, based on the same values you specified for deadlocks when using the -r and -rd switches on the ML Server start line.
Your solution for an SP with an exception handler is one way to handle this from the database, but it will execute a number of times, since the ML Server will retry. Another alternative to capture information using the MobiLink Server would be to implement a Java log listener looking for the -10021 error that the MobiLink Server posts to the log after all attempts to retry have been exhausted. Within the Java code for the log listener, make another connection to the database, and then execute and capture the output from the sa_locks() call. The java code for your very simple log listener might look something like :
import com.sap.ml.script.*; import java.sql.*; import java.util.*; public class Example { Connection _log_connection; class MyLogListener implements LogListener { public void messageLogged( ServerContext sc, LogMessage msg ) { String user; if( msg.getText().indexOf("[-10021]") != -1 ) { try { PreparedStatement ps_log = _log_connection.prepareStatement( "insert into track_locks select ?,CURRENT TIMESTAMP,* from sa_locks()" ); user = msg.getUser(); if( user == null ) { user = "UserIsNULL"; } ps_log.setString( 1, user ); ps_log.executeUpdate(); ps_log.close(); _log_connection.commit(); } catch( Exception e ) { // print some error output to the Mobilink log e.printStackTrace(); } } } } public Example( ServerContext sc ) throws SQLException { _log_connection = sc.makeConnection(); sc.addErrorListener( new MyLogListener() ); } }
Next, you just need to add -sl java to the ML Server start line.
-sl java(-DMLStartClasses=Example -cp c:\\path\\to\\dir\\where\\Example\\dot\\class\\exists)"
Reg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Reg: Why does MobiLink say "deadlock" when SQLCODE -210 is a simple block?
W. 2021-07-20 16:28:06. <1> [10050] ODBC: [SAP][ODBC Driver] [SQL Anywhere]User 'User1' has the row in 'TABLE1' locked (ODBC State = 40001, Native error code = -210) I. 2021-07-20 16:28:06. <1> ROLLBACK Transaction: Upload W. 2021-07-20 16:28:22. <1> [10045] Retrying the upload after deadlock in the consolidated database
The Help says this: "Deadlock - When an upload is being applied to the consolidated database, it may encounter deadlock due to concurrency with other transactions. These transactions might be upload transactions from other MobiLink server database connections, or transactions from other applications using the consolidated database. When an upload transaction is deadlocked, it is rolled back and the MobiLink server automatically starts applying the upload again, from the beginning."
Sadly, that is a description of a block, not a deadlock. SQL Anywhere resolves true deadlocks instantly by picking one of the two deadlocked connections and giving one of them an exception.
User | Count |
---|---|
69 | |
11 | |
10 | |
10 | |
9 | |
9 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.