public CompletableFuture < Void > addNewEntriesIfAbsent ( String tableName , Map < String , byte [ ] > toAdd ) { List < TableEntry < byte [ ] , byte [ ] > > entries = toAdd . entrySet ( ) . stream ( ) . map ( x -> new TableEntryImpl <> ( new TableKeyImpl <> ( x . getKey ( ) . getBytes ( Charsets . UTF_8 ) , KeyVersion . NOT_EXISTS ) , x . getValue ( ) ) ) . collect ( Collectors . toList ( ) ) ; Supplier < String > errorMessage = ( ) -> String . format ( "addNewEntriesIfAbsent: table: %s" , tableName ) ; return expectingDataExists ( withRetries ( ( ) -> segmentHelper . updateTableEntries ( tableName , entries , authToken . get ( ) , RequestTag . NON_EXISTENT_ID ) , errorMessage ) . handle ( ( r , e ) -> { if ( e != null ) { Throwable unwrap = Exceptions . unwrap ( e ) ; if ( unwrap instanceof StoreException . WriteConflictException ) { throw StoreException . create ( StoreException . Type . DATA_EXISTS , errorMessage . get ( ) ) ; } else { log . debug ( "add new entries to {} threw exception {} {}" , tableName , unwrap . getClass ( ) , unwrap . getMessage ( ) ) ; throw new CompletionException ( e ) ; } } else { log . trace ( "entries added to table {}" , tableName ) ; return null ; } } ) , null ) ; }
Method to add a batch of entries if absent . Table implementation on segment store guarantees that either all or none of the entries are added . If segment store responds with success then it is guaranteed that all entries are added to the store . However it is important to note that the segment store could respond with Data Exists even if one of the entries exists . In such case this method will ignore data exist and respond with success for the entire batch . It does not verify if all entries existed or one of the entries existed . Callers should use this only if they are guaranteed to never create the requested entries outside of the requested batch .