private boolean taskClaimedByUs ( Tenant tenant , String claimID ) { waitForClaim ( ) ; Iterator < DColumn > colIter = DBService . instance ( tenant ) . getAllColumns ( TaskManagerService . TASKS_STORE_NAME , claimID ) . iterator ( ) ; if ( colIter == null ) { m_logger . warn ( "Claim record disappeared: {}" , claimID ) ; return false ; } String claimingHost = m_hostClaimID ; long earliestClaim = Long . MAX_VALUE ; while ( colIter . hasNext ( ) ) { DColumn col = colIter . next ( ) ; try { long claimStamp = Long . parseLong ( col . getValue ( ) ) ; // otarakanov: sometimes, the task writes a claim but does not start. The claim remains the lowest // and makes future tries to write new claims but not start. // we disregard claims older that ten minutes. long secondsSinceClaim = ( System . currentTimeMillis ( ) - claimStamp ) / 1000 ; if ( secondsSinceClaim > 600 ) continue ; String claimHost = col . getName ( ) ; if ( claimStamp < earliestClaim ) { claimingHost = claimHost ; earliestClaim = claimStamp ; } else if ( claimStamp == earliestClaim ) { // Two nodes chose the same claim stamp. Lower node name wins. if ( claimHost . compareTo ( claimingHost ) < 0 ) { claimingHost = claimHost ; } } } catch ( NumberFormatException e ) { // Ignore this column } } return claimingHost . equals ( m_hostClaimID ) && ! m_bShutdown ; }
Indicate if we won the claim to run the given task .