src/java/org/apache/cassandra/service/StorageService.java
/**
     * Calculate pair of ranges to stream/fetch for given two range collections
     * (current ranges for table and ranges after move to new token)
     *
     * @param current collection of the ranges by current token
     * @param updated collection of the ranges after token is changed
     * @return pair of ranges to stream/fetch for given current and updated range collections
     */
Calculate pair of ranges to stream/fetch for given two range collections
(current ranges for table and ranges after move to new token)

@param current collection of the ranges by current token
@param updated collection of the ranges after token is changed
@return pair of ranges to stream/fetch for given current and updated range collections
Calculate pair of ranges to stream / fetch for given two range collections ( current ranges for table and ranges after move to new token ) @param current collection of the ranges by current token @param updated collection of the ranges after token is changed @return pair of ranges to stream / fetch for given current and updated range collections
private Pair<Set<Range<Token>>, Set<Range<Token>>> calculateStreamAndFetchRanges(Iterator<Range<Token>> current, Iterator<Range<Token>> updated)
    {
        Set<Range<Token>> toStream = new HashSet<Range<Token>>();
        Set<Range<Token>> toFetch  = new HashSet<Range<Token>>();
        while (current.hasNext() && updated.hasNext())
        {
            Range<Token> r1 = current.next();
            Range<Token> r2 = updated.next();
            if (r1.intersects(r2))
            {
                toFetch.addAll(r1.differenceToFetch(r2));
                if (!r2.contains(r1))
                {
                    if (r1.left.compareTo(r2.left) < 0) 
                    {
                        toStream.add(new Range<Token>(r1.left, r2.left)); 
                    }
                    if (r1.right.compareTo(r2.right) > 0) 
                    {
                        toStream.add(new Range<Token>(r2.right, r1.right)); 
                    }
                }
            }
            else 
            {
                toStream.add(r1); 
                toFetch.add(r2);
            }
        }
        return new Pair<Set<Range<Token>>, Set<Range<Token>>>(toStream, toFetch);
    }
private Pair < Set < Range < Token > > , Set < Range < Token > > > calculateStreamAndFetchRanges ( Iterator < Range < Token > > current , Iterator < Range < Token > > updated ) { Set < Range < Token > > toStream = new HashSet < Range < Token > > ( ) ; Set < Range < Token > > toFetch = new HashSet < Range < Token > > ( ) ; while ( current . hasNext ( ) && updated . hasNext ( ) ) { Range < Token > r1 = current . next ( ) ; Range < Token > r2 = updated . next ( ) ; if ( r1 . intersects ( r2 ) ) { toFetch . addAll ( r1 . differenceToFetch ( r2 ) ) ; if ( ! r2 . contains ( r1 ) ) { if ( r1 . left . compareTo ( r2 . left ) < 0 ) { toStream . add ( new Range < Token > ( r1 . left , r2 . left ) ) ; } if ( r1 . right . compareTo ( r2 . right ) > 0 ) { toStream . add ( new Range < Token > ( r2 . right , r1 . right ) ) ; } } } else { toStream . add ( r1 ) ; toFetch . add ( r2 ) ; } } return new Pair < Set < Range < Token > > , Set < Range < Token > > > ( toStream , toFetch ) ; }
Calculate pair of ranges to stream/fetch for given two range collections
 (current ranges for table and ranges after move to new token)
Calculate pair of ranges to stream / fetch for given two range collections ( current ranges for table and ranges after move to new token )
// if ranges intersect we need to fetch only missing part // adding difference ranges to fetch from a ring // if current range is a sub-range of a new range we don't need to seed // otherwise we need to seed parts of the current range // (A, B] & (C, D] // if A < C // seed (A, C] // if B > D // seed (D, B] // otherwise we need to fetch whole new range // should seed whole old range