dcapwell commented on code in PR #3426: URL: https://github.com/apache/cassandra/pull/3426#discussion_r1702245490
########## 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: nit... rf=2 can't have a single down node... so your message isn't correct in that case (it doesn't "already" have too many stale nodes; it just would not be in quorum if we made this change) ########## src/java/org/apache/cassandra/service/accord/StaleReplicas.java: ########## @@ -0,0 +1,111 @@ +/* + * 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.service.accord; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import javax.annotation.concurrent.Immutable; + +import com.google.common.collect.ImmutableSet; + +import accord.local.Node; +import org.apache.cassandra.io.util.DataInputPlus; +import org.apache.cassandra.io.util.DataOutputPlus; +import org.apache.cassandra.service.accord.serializers.TopologySerializers; +import org.apache.cassandra.tcm.Epoch; +import org.apache.cassandra.tcm.MetadataValue; +import org.apache.cassandra.tcm.serialization.MetadataSerializer; +import org.apache.cassandra.tcm.serialization.Version; +import org.apache.cassandra.utils.CollectionSerializers; + +@Immutable +public class StaleReplicas implements MetadataValue<StaleReplicas> +{ + public static final StaleReplicas EMPTY = new StaleReplicas(ImmutableSet.of(), Epoch.EMPTY); + + private final Set<Node.Id> nodeIds; + private final Epoch lastModified; + + StaleReplicas(Set<Node.Id> nodeIds, Epoch lastModified) + { + this.nodeIds = nodeIds; + this.lastModified = lastModified; + } + + @Override + public StaleReplicas withLastModified(Epoch epoch) + { + return new StaleReplicas(nodeIds, epoch); + } + + @Override + public Epoch lastModified() + { + return lastModified; + } + + public StaleReplicas withNodeId(Node.Id nodeId) + { + Set<Node.Id> copy = new HashSet<>(nodeIds); Review Comment: nit, can we make this `ImmutableSet` to avoid having shared objects that have mutable state? ########## test/distributed/org/apache/cassandra/distributed/test/accord/AccordMarkStaleTest.java: ########## @@ -0,0 +1,45 @@ +/* + * 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.distributed.test.accord; + +import org.junit.Test; + +import accord.local.Node; +import org.apache.cassandra.tcm.ClusterMetadata; +import org.apache.cassandra.distributed.Cluster; +import org.apache.cassandra.distributed.api.Feature; +import org.apache.cassandra.distributed.test.TestBaseImpl; + +import static org.junit.Assert.assertTrue; + +public class AccordMarkStaleTest extends TestBaseImpl Review Comment: can you expand the test to do 2 nodes at once. your APIs allow but not covering ########## src/java/org/apache/cassandra/tcm/CMSOperations.java: ########## @@ -243,4 +244,16 @@ public void unregisterLeftNodes(List<String> nodeIdStrings) cms.commit(new Unregister(nodeId, EnumSet.of(NodeState.LEFT))); } } + + @Override + public void accordMarkStale(List<String> nodeIdStrings) Review Comment: to be clear on intent, this is to "append" and not "override" the current set right? Append I think is the common case, not sure if we want to have a "YOLO I KNOW WHAT I AM DOING; OVERRIDE!" ########## src/java/org/apache/cassandra/tools/nodetool/AccordAdmin.java: ########## @@ -0,0 +1,42 @@ +/* + * 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.tools.nodetool; + +import java.util.List; + +import io.airlift.airline.Arguments; +import io.airlift.airline.Command; +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool; + +public abstract class AccordAdmin extends NodeTool.NodeToolCmd +{ + @Command(name = "mark_stale", description = "Mark a replica as being stale and no longer able to participate in durability status coordination") + public static class MarkStaleCmd extends AccordAdmin + { + @Arguments(required = true, description = "One or more nodeIds to mark stale", usage = "<nodeId>+") + public List<String> nodeIds; + + @Override + protected void execute(NodeProbe probe) + { + probe.getCMSOperationsProxy().accordMarkStale(nodeIds); + } + } Review Comment: asked in slack... if a node is *alive* then should we allow it to be `stale`? what about on reboot, do we take ourselves out of `stale`? ########## test/distributed/org/apache/cassandra/distributed/test/accord/AccordMarkStaleTest.java: ########## @@ -0,0 +1,45 @@ +/* + * 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.distributed.test.accord; + +import org.junit.Test; + +import accord.local.Node; +import org.apache.cassandra.tcm.ClusterMetadata; +import org.apache.cassandra.distributed.Cluster; +import org.apache.cassandra.distributed.api.Feature; +import org.apache.cassandra.distributed.test.TestBaseImpl; + +import static org.junit.Assert.assertTrue; + +public class AccordMarkStaleTest extends TestBaseImpl Review Comment: what happens if you try to mark a non-existing node as stale? -- 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]

