cassandra-pr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aweisberg <...@git.apache.org>
Subject [GitHub] cassandra pull request #271: 14726
Date Wed, 26 Sep 2018 16:29:48 GMT
Github user aweisberg commented on a diff in the pull request:

    https://github.com/apache/cassandra/pull/271#discussion_r220635308
  
    --- Diff: src/java/org/apache/cassandra/locator/EndpointsForRange.java ---
    @@ -57,95 +54,77 @@ private EndpointsForRange(Range<Token> range, List<Replica>
list, boolean isSnap
         }
     
         @Override
    -    public Mutable newMutable(int initialCapacity)
    +    public Builder newBuilder(int initialCapacity)
         {
    -        return new Mutable(range, initialCapacity);
    +        return new Builder(range, initialCapacity);
         }
     
         public EndpointsForToken forToken(Token token)
         {
             if (!range.contains(token))
                 throw new IllegalArgumentException(token + " is not contained within " +
range);
    -        return new EndpointsForToken(token, list, isSnapshot, byEndpoint);
    +        return new EndpointsForToken(token, list, byEndpoint);
         }
     
         @Override
    -    public EndpointsForRange self()
    +    public EndpointsForRange snapshot()
         {
             return this;
         }
     
         @Override
    -    protected EndpointsForRange snapshot(List<Replica> snapshot)
    +    EndpointsForRange snapshot(ReplicaList newList)
         {
    -        if (snapshot.isEmpty()) return empty(range);
    -        return new EndpointsForRange(range, snapshot, true);
    +        if (newList.isEmpty()) return empty(range);
    +        ReplicaMap<InetAddressAndPort> byEndpoint = null;
    +        if (this.byEndpoint != null && list.isSubList(newList))
    +            byEndpoint = this.byEndpoint.forSubList(newList);
    +        return new EndpointsForRange(range, newList, byEndpoint);
         }
     
    -    public static class Mutable extends EndpointsForRange implements ReplicaCollection.Mutable<EndpointsForRange>
    +    public static class Builder extends EndpointsForRange implements ReplicaCollection.Builder<EndpointsForRange>
         {
    -        boolean hasSnapshot;
    -        public Mutable(Range<Token> range) { this(range, 0); }
    -        public Mutable(Range<Token> range, int capacity) { super(range, new ArrayList<>(capacity),
false, new LinkedHashMap<>(capacity)); }
    +        boolean built;
    +        public Builder(Range<Token> range) { this(range, 0); }
    +        public Builder(Range<Token> range, int capacity) { this(range, new ReplicaList(capacity));
}
    +        private Builder(Range<Token> range, ReplicaList list) { super(range, list,
endpointMap(list)); }
     
    -        public void add(Replica replica, Conflict ignoreConflict)
    +        public EndpointsForRange.Builder add(Replica replica, Conflict ignoreConflict)
             {
    -            if (hasSnapshot) throw new IllegalStateException();
    +            if (built) throw new IllegalStateException();
                 Preconditions.checkNotNull(replica);
                 if (!replica.range().contains(super.range))
                     throw new IllegalArgumentException("Replica " + replica + " does not
contain " + super.range);
     
    -            Replica prev = super.byEndpoint.put(replica.endpoint(), replica);
    -            if (prev != null)
    +            if (!super.byEndpoint.internalPutIfAbsent(replica, list.size()))
                 {
    -                super.byEndpoint.put(replica.endpoint(), prev); // restore prev
                     switch (ignoreConflict)
                     {
                         case DUPLICATE:
    -                        if (prev.equals(replica))
    +                        if (byEndpoint().get(replica.endpoint()).equals(replica))
    --- End diff --
    
    Oh actually only if there are duplicates so not a big deal


---

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Mime
View raw message