private CompletableFuture < Void > commitTransactions ( String scope , String stream , List < Long > segments , List < UUID > transactionsToCommit ) { // Chain all transaction commit futures one after the other. This will ensure that order of commit // if honoured and is based on the order in the list. CompletableFuture < Void > future = CompletableFuture . completedFuture ( null ) ; for ( UUID txnId : transactionsToCommit ) { log . debug ( "Committing transaction {} on stream {}/{}" , txnId , scope , stream ) ; // commit transaction in segment store future = future // Note, we can use the same segments and transaction id as only // primary id is taken for creation of txn-segment name and secondary part is erased and replaced with // transaction's epoch. // And we are creating duplicates of txn epoch keeping the primary same. . thenCompose ( v -> streamMetadataTasks . notifyTxnCommit ( scope , stream , segments , txnId ) ) ; } return future ; }
This method loops over each transaction in the list and commits them in order At the end of this method s execution all transactions in the list would have committed into given list of segments .