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 #224: 14405 replicas
Date Wed, 16 May 2018 17:06:05 GMT
Github user aweisberg commented on a diff in the pull request:

    https://github.com/apache/cassandra/pull/224#discussion_r188081346
  
    --- Diff: src/java/org/apache/cassandra/locator/ReplicaSet.java ---
    @@ -0,0 +1,142 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.cassandra.locator;
    +
    +import java.util.HashSet;
    +import java.util.Iterator;
    +import java.util.LinkedHashSet;
    +import java.util.Objects;
    +import java.util.Set;
    +
    +import com.google.common.collect.ImmutableSet;
    +import com.google.common.collect.Iterables;
    +import com.google.common.collect.Sets;
    +
    +public class ReplicaSet extends Replicas
    +{
    +    static final ReplicaSet EMPTY = new ReplicaSet(ImmutableSet.of());
    +
    +    private final Set<Replica> replicaSet;
    +
    +    public ReplicaSet()
    +    {
    +        replicaSet = new HashSet<>();
    +    }
    +
    +    public ReplicaSet(int expectedSize)
    +    {
    +        replicaSet = Sets.newHashSetWithExpectedSize(expectedSize);
    +    }
    +
    +    public ReplicaSet(Replicas replicas)
    +    {
    +        replicaSet = Sets.newHashSetWithExpectedSize(replicas.size());
    +        Iterables.addAll(replicaSet, replicas);
    +    }
    +
    +    private ReplicaSet(Set<Replica> replicaSet)
    +    {
    +        this.replicaSet = replicaSet;
    +    }
    +
    +    public boolean equals(Object o)
    +    {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +        ReplicaSet that = (ReplicaSet) o;
    +        return Objects.equals(replicaSet, that.replicaSet);
    +    }
    +
    +    public int hashCode()
    +    {
    +        return Objects.hash(replicaSet);
    +    }
    +
    +    @Override
    +    public String toString()
    +    {
    +        return replicaSet.toString();
    +    }
    +
    +    @Override
    +    public boolean add(Replica replica)
    +    {
    +        return replicaSet.add(replica);
    +    }
    +
    +    @Override
    +    public void addAll(Iterable<Replica> replicas)
    +    {
    +        Iterables.addAll(replicaSet, replicas);
    +    }
    +
    +    @Override
    +    public void removeEndpoint(InetAddressAndPort endpoint)
    +    {
    +        replicaSet.removeIf(r -> r.getEndpoint().equals(endpoint));
    +    }
    +
    +    @Override
    +    public void removeReplica(Replica replica)
    +    {
    +        replicaSet.remove(replica);
    +    }
    +
    +    @Override
    +    public int size()
    +    {
    +        return replicaSet.size();
    +    }
    +
    +    @Override
    +    public Iterator<Replica> iterator()
    +    {
    +        return replicaSet.iterator();
    +    }
    +
    +    public ReplicaSet differenceOnEndpoint(Replicas differenceOn)
    +    {
    +        if (Iterables.all(this, Replica::isFull) && Iterables.all(differenceOn,
Replica::isFull))
    +        {
    +            Set<InetAddressAndPort> diffEndpoints = differenceOn.asEndpointSet();
    +            return new ReplicaSet(Replicas.filterOnEndpoints(this, e -> !diffEndpoints.contains(e)));
    +        }
    +        else
    +        {
    +            // FIXME: add support for transient replicas
    +            throw new UnsupportedOperationException("transient replicas are currently
unsupported");
    +        }
    +
    +    }
    +
    +    public static ReplicaSet immutableCopyOf(ReplicaSet from)
    +    {
    +        return new ReplicaSet(ImmutableSet.copyOf(from.replicaSet));
    +    }
    +
    +    public static ReplicaSet immutableCopyOf(Replicas from)
    +    {
    +        return new ReplicaSet(ImmutableSet.<Replica>builder().addAll(from).build());
    +    }
    +
    +    public static ReplicaSet ordered()
    --- End diff --
    
    I had to look this up to realize that ordered doesn't mean sorted. It's the correct name,
they are ordered just not according to their natural order. Maybe the right shade for the
bike shed here is order preserving?


---

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


Mime
View raw message