private void takeHADBLock ( Connection conn ) throws SQLException , InternalLogException { if ( tc . isEntryEnabled ( ) ) Tr . entry ( tc , "takeHADBLock" , new java . lang . Object [ ] { conn , this } ) ; Statement lockingStmt = null ; ResultSet lockingRS = null ; try { lockingStmt = conn . createStatement ( ) ; String queryString = "SELECT SERVER_NAME" + " FROM " + _recoveryTableName + _logIdentifierString + _recoveryTableNameSuffix + " WHERE RU_ID=" + "-1 FOR UPDATE" ; if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Attempt to select the HA LOCKING ROW for UPDATE using - " + queryString ) ; lockingRS = lockingStmt . executeQuery ( queryString ) ; if ( lockingRS . next ( ) ) { // We found the HA Lock row String storedServerName = lockingRS . getString ( 1 ) ; if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Acquired lock on HA Lock row, stored server value is: " + storedServerName ) ; if ( _currentProcessServerName . equalsIgnoreCase ( storedServerName ) ) { if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "This server OWNS the HA lock row as expected" ) ; } else { if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "ANOTHER server OWNS the lock row - we need to mark the log as failed" ) ; Tr . audit ( tc , "WTRN0100E: " + "Another server owns the log cannot force SQL RecoveryLog " + _logName + " for server " + _serverName ) ; InternalLogException ile = new InternalLogException ( "Another server has locked the HA lock row" , null ) ; markFailed ( ile ) ; if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "takeHADBLock" , "InternalLogException" ) ; throw ile ; } } else { // We didn't find the HA Lock row in the table, mark the log as failed if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Could not find HA Lock row" ) ; InternalLogException ile = new InternalLogException ( "Could not find the HA lock row" , null ) ; Tr . audit ( tc , "WTRN0100E: " + "Could not find HA lock row when forcing SQL RecoveryLog " + _logName + " for server " + _serverName ) ; markFailed ( ile ) ; if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "takeHADBLock" , "InternalLogException" ) ; throw ile ; } } finally { if ( lockingRS != null && ! lockingRS . isClosed ( ) ) lockingRS . close ( ) ; if ( lockingStmt != null && ! lockingStmt . isClosed ( ) ) lockingStmt . close ( ) ; } if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "takeHADBLock" ) ; }
Takes a row lock against the database table that is being used for the recovery log . This fulfils the same role as the file locking scheme in conventional transaction logging to a filesystem . The intent is that only one server should be logging to a specific table at a time . 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 .