ifesdjeen commented on code in PR #4015: URL: https://github.com/apache/cassandra/pull/4015#discussion_r2018030373
########## test/distributed/org/apache/cassandra/distributed/upgrade/MixedModePaxosTest.java: ########## @@ -0,0 +1,226 @@ +/* + * 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.upgrade; + +import java.nio.ByteBuffer; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.cassandra.db.SimpleBuilders; +import org.apache.cassandra.db.marshal.Int32Type; +import org.apache.cassandra.db.partitions.PartitionUpdate; +import org.apache.cassandra.db.rows.Row; +import org.apache.cassandra.dht.Murmur3Partitioner; +import org.apache.cassandra.distributed.api.ConsistencyLevel; +import org.apache.cassandra.distributed.api.Feature; +import org.apache.cassandra.distributed.api.ICoordinator; +import org.apache.cassandra.net.MessagingService; +import org.apache.cassandra.schema.TableId; +import org.apache.cassandra.schema.TableMetadata; +import org.apache.cassandra.service.paxos.Ballot; +import org.apache.cassandra.utils.ByteBufferUtil; + +import static java.lang.String.format; + +public class MixedModePaxosTest extends UpgradeTestBase +{ + private static final Logger logger = LoggerFactory.getLogger(MixedModePaxosTest.class); + + + /** + * Tests the mixed mode loop bug in CASSANDRA-20493 + * + * Paxos uses a 'zero' ballot in place of null when it doesn't find a ballot in system.paxos. CEP-14 changed the lsb + * of the zero ballot uuid from -9187201950435737472 to 0. It also removed the check added in CASSANDRA-12043, since + * the way it read and filtered ttld paxos data had been improved. However, this means that 4.1 and higher paxos + * coordinators, the prepare phase will always interpret the most recent commits from 4.0 and lower nodes as being + * less than its own and will update them with its slightly higher zero ballot and empty partition update. In cases + * where this is the first paxos operation on a key, or the previously ttl'd paxos data on disk had been purged, this + * would just add a retry step as it updated the 4.0 and lower hosts with it's zero ballot. On nodes where there was + * ttl'd paxos data though, the ttl'd data on disk would shadow this update and the conflicting 'zero' value would + * cause the prepare phase to get into an infinite loop. + */ + @Test + public void upgradeAwareTtldPaxosStateTest() throws Throwable + { + String keyspace = KEYSPACE; + String table = "tbl"; + int gcGrace = 10; // 1 day + new TestCase() + .withConfig(c -> c.with(Feature.GOSSIP, Feature.NETWORK)) + .nodes(2) + .nodesToUpgrade(1) + // all upgrades from v30 up, excluding v30->v3X and from v40 + .singleUpgrade(v40) + .setup(cluster -> { + cluster.schemaChange(format("CREATE TABLE %s.%s (k int primary key, v int) " + + "WITH gc_grace_seconds=%s", keyspace, table, gcGrace)); + }) + .runAfterClusterUpgrade(cluster -> { + // disable compaction to prevent paxos state from being purged + cluster.forEach(instance -> instance.nodetool("disableautocompaction")); + + // insert a ttl'd committed paxos state + long ballotMicros = TimeUnit.NANOSECONDS.toMicros(System.currentTimeMillis()); + FakePaxosHelper helper = FakePaxosHelper.create(cluster.coordinator(1), keyspace, table, gcGrace, ballotMicros); + + // confirm none of the nodes have paxos state + for (int i=1; i<=cluster.size(); i++) + Assert.assertEquals(0, cluster.coordinator(i).execute("SELECT * FROM system.paxos", ConsistencyLevel.ONE).length); + + + // save commit to both nodes + helper.saveCommit(cluster.coordinator(1)); + helper.saveCommit(cluster.coordinator(2)); + + // wait for the paxos state to expire + Thread.sleep(TimeUnit.SECONDS.toMillis(gcGrace * 2)); Review Comment: Pardon me: of course it is 10 seconds; glanced at it too quickly. -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org