private void commitMutations ( DBTransaction dbTran , long timestamp ) { Map < ByteBuffer , Map < String , List < Mutation > > > colMutMap = CassandraTransaction . getUpdateMap ( dbTran , timestamp ) ; if ( colMutMap . size ( ) == 0 ) { return ; } m_logger . debug ( "Committing {} mutations" , CassandraTransaction . totalColumnMutations ( dbTran ) ) ; // The batch_mutate will be retried up to MAX_COMMIT_RETRIES times. boolean bSuccess = false ; for ( int attempts = 1 ; ! bSuccess ; attempts ++ ) { try { // Attempt to commit all updates in the the current mutation map. Date startDate = new Date ( ) ; m_client . batch_mutate ( colMutMap , ConsistencyLevel . ONE ) ; timing ( "commitMutations" , startDate ) ; if ( attempts > 1 ) { // Since we had a failure and warned about it, confirm which attempt succeeded. m_logger . info ( "batch_mutate() succeeded on attempt #{}" , attempts ) ; } bSuccess = true ; } catch ( InvalidRequestException ex ) { // No point in retrying this one. m_bFailed = true ; m_logger . error ( "batch_mutate() failed" , ex ) ; throw new RuntimeException ( "batch_mutate() failed" , ex ) ; } catch ( Exception ex ) { // If we've reached the retry limit, we fail this commit. if ( attempts >= m_max_commit_attempts ) { m_bFailed = true ; m_logger . error ( "All retries exceeded; abandoning batch_mutate()" , ex ) ; throw new RuntimeException ( "All retries exceeded; abandoning batch_mutate()" , ex ) ; } // Report retry as a warning. m_logger . warn ( "batch_mutate() attempt #{} failed: {}" , attempts , ex ) ; try { // We wait more with each failure. Thread . sleep ( attempts * m_retry_wait_millis ) ; } catch ( InterruptedException e1 ) { // ignore } // Experience suggests that even for timeout exceptions, the connection // may be bad, so we attempt to reconnect. If this fails, it will throw // an DBNotAvailableException, which we pass to the caller. reconnect ( ex ) ; } } }
configured maximum number of retries .