private Map < Address , IntSet > backupOwnersOfSegments ( ConsistentHash ch , IntSet segments ) { Map < Address , IntSet > map = new HashMap <> ( ch . getMembers ( ) . size ( ) ) ; if ( ch . isReplicated ( ) ) { for ( Address member : ch . getMembers ( ) ) { map . put ( member , segments ) ; } map . remove ( rpcManager . getAddress ( ) ) ; } else { int numSegments = ch . getNumSegments ( ) ; for ( PrimitiveIterator . OfInt iter = segments . iterator ( ) ; iter . hasNext ( ) ; ) { int segment = iter . nextInt ( ) ; List < Address > owners = ch . locateOwnersForSegment ( segment ) ; for ( int i = 1 ; i < owners . size ( ) ; ++ i ) { map . computeIfAbsent ( owners . get ( i ) , o -> IntSets . mutableEmptySet ( numSegments ) ) . set ( segment ) ; } } } return map ; }
we re assuming that this function is ran on primary owner of given segments