private void updateHADBLock ( Connection conn , Statement lockingStmt , ResultSet lockingRS ) throws SQLException { if ( tc . isEntryEnabled ( ) ) Tr . entry ( tc , "updateHADBLock" , new java . lang . Object [ ] { conn , lockingStmt , lockingRS , this } ) ; if ( lockingRS . next ( ) ) { // We found the HA Lock row if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Acquired lock on HA Lock row" ) ; String storedServerName = lockingRS . getString ( 1 ) ; if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Stored server value is: " + storedServerName ) ; if ( _currentProcessServerName . equalsIgnoreCase ( storedServerName ) ) { if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "This server ALREADY OWNS the HA lock row" ) ; } else { String updateString = "UPDATE " + _recoveryTableName + _logIdentifierString + _recoveryTableNameSuffix + " SET SERVER_NAME = '" + _currentProcessServerName + "' WHERE RU_ID = -1" ; if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "ANOTHER server OWNS the lock, lets update it using - " + updateString ) ; int ret = lockingStmt . executeUpdate ( updateString ) ; if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Have updated HA Lock row with return: " + ret ) ; } } else { // Is this entirely necessary? We didn't find the HA Lock row in the table, perhaps we should barf short serviceId = ( short ) 1 ; String insertString = "INSERT INTO " + _recoveryTableName + _logIdentifierString + _recoveryTableNameSuffix + " (SERVER_NAME, SERVICE_ID, RU_ID, RUSECTION_ID, RUSECTION_DATA_INDEX, DATA)" + " VALUES (?,?,?,?,?,?)" ; PreparedStatement specStatement = null ; try { if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Need to setup HA Lock row using - " + insertString ) ; specStatement = conn . prepareStatement ( insertString ) ; specStatement . setString ( 1 , _currentProcessServerName ) ; specStatement . setShort ( 2 , serviceId ) ; specStatement . setLong ( 3 , - 1 ) ; // NOTE RU_ID SET TO -1 specStatement . setLong ( 4 , 1 ) ; specStatement . setShort ( 5 , ( short ) 1 ) ; byte buf [ ] = new byte [ 2 ] ; specStatement . setBytes ( 6 , buf ) ; int ret = specStatement . executeUpdate ( ) ; if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Have inserted HA Lock row with return: " + ret ) ; } finally { if ( specStatement != null && ! specStatement . isClosed ( ) ) specStatement . close ( ) ; } } if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "updateHADBLock" ) ; }
Acquires ownership of the special row used in the HA locking scheme . There is sometimes a lag in peer recovery where an old server is closing down while a new server is opening the same log for peer recovery .