maedhroz commented on code in PR #3426: URL: https://github.com/apache/cassandra/pull/3426#discussion_r1705921464
########## src/java/org/apache/cassandra/tcm/transformations/AccordMarkStale.java: ########## @@ -0,0 +1,119 @@ +/* + * 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.tcm.transformations; + +import java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import accord.local.Node; +import accord.topology.Shard; +import org.apache.cassandra.io.util.DataInputPlus; +import org.apache.cassandra.io.util.DataOutputPlus; +import org.apache.cassandra.schema.KeyspaceMetadata; +import org.apache.cassandra.schema.SchemaConstants; +import org.apache.cassandra.service.accord.AccordTopology; +import org.apache.cassandra.tcm.ClusterMetadata; +import org.apache.cassandra.tcm.Transformation; +import org.apache.cassandra.tcm.membership.NodeId; +import org.apache.cassandra.tcm.sequences.LockedRanges; +import org.apache.cassandra.tcm.serialization.AsymmetricMetadataSerializer; +import org.apache.cassandra.tcm.serialization.Version; + +import static org.apache.cassandra.exceptions.ExceptionCode.INVALID; + +public class AccordMarkStale implements Transformation +{ + + private final NodeId tcmId; + + public AccordMarkStale(NodeId tcmId) + { + this.tcmId = tcmId; + } + + @Override + public Kind kind() + { + return Kind.ACCORD_MARK_STALE; + } + + @Override + public Result execute(ClusterMetadata prev) + { + if (!prev.directory.peerIds().contains(tcmId)) + return new Rejected(INVALID, String.format("Can not mark %s stale it is not present in the directory.", tcmId)); + + Node.Id staleAccordId = AccordTopology.tcmIdToAccord(tcmId); + + if (prev.staleReplicas.contains(staleAccordId)) + return new Rejected(INVALID, String.format("Can not mark %s stale as it already is.", tcmId)); + + for (KeyspaceMetadata keyspace : prev.schema.getKeyspaces().without(SchemaConstants.REPLICATED_SYSTEM_KEYSPACE_NAMES)) + { + List<AccordTopology.KeyspaceShard> shards = AccordTopology.KeyspaceShard.forKeyspace(keyspace, prev.placements, prev.directory); + + for (AccordTopology.KeyspaceShard shard : shards) + { + // We're trying to mark a node in this shard stale... + if (shard.nodes().contains(staleAccordId)) + { + int quorumSize = Shard.slowPathQuorumSize(shard.nodes().size()); + Set<Node.Id> nonStaleNodes = new HashSet<>(shard.nodes()); + nonStaleNodes.remove(staleAccordId); + nonStaleNodes.removeAll(prev.staleReplicas.ids()); + + // ...but reject the transformation if this would bring us below quorum. + if (nonStaleNodes.size() < quorumSize) + return new Rejected(INVALID, String.format("Can not mark %s stale as there are already too many stale nodes for range %s in keyspace '%s'.", Review Comment: Yeah, the message needs to be corrected to indicate marking will *produce* a bad state. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

