private boolean executeWrites ( List < Write > toExecute ) { log . debug ( "{}: Executing {} writes." , this . traceObjectId , toExecute . size ( ) ) ; for ( int i = 0 ; i < toExecute . size ( ) ; i ++ ) { Write w = toExecute . get ( i ) ; try { // Record the beginning of a new attempt. int attemptCount = w . beginAttempt ( ) ; if ( attemptCount > this . config . getMaxWriteAttempts ( ) ) { // Retried too many times. throw new RetriesExhaustedException ( w . getFailureCause ( ) ) ; } // Invoke the BookKeeper write. w . getWriteLedger ( ) . ledger . asyncAddEntry ( w . data . array ( ) , w . data . arrayOffset ( ) , w . data . getLength ( ) , this :: addCallback , w ) ; } catch ( Throwable ex ) { // Synchronous failure (or RetriesExhausted). Fail current write. boolean isFinal = ! isRetryable ( ex ) ; w . fail ( ex , isFinal ) ; // And fail all remaining writes as well. for ( int j = i + 1 ; j < toExecute . size ( ) ; j ++ ) { toExecute . get ( j ) . fail ( new DurableDataLogException ( "Previous write failed." , ex ) , isFinal ) ; } return false ; } } // Success. return true ; }
Executes the given Writes to BookKeeper .