You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "alanwang67 (via GitHub)" <gi...@apache.org> on 2026/03/18 21:34:42 UTC

[PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

alanwang67 opened a new pull request, #4684:
URL: https://github.com/apache/cassandra/pull/4684

   Use batch log for single token batches that span both Accord and non Accord tables to preserve all or nothing application. 
   
   patch by Alan Wang;
   
   reviewed by for [CASSANDRA-20588](https://issues.apache.org/jira/browse/CASSANDRA-20588)
   
   Co-authored-by: Name1
   Co-authored-by: Name2


-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

Posted by "alanwang67 (via GitHub)" <gi...@apache.org>.
alanwang67 commented on code in PR #4684:
URL: https://github.com/apache/cassandra/pull/4684#discussion_r2976919843


##########
test/distributed/org/apache/cassandra/distributed/test/accord/AccordSingleTokenBatchTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.SuperCall;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.db.Mutation;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.distributed.api.Feature;
+import org.apache.cassandra.distributed.api.SimpleQueryResult;
+import org.apache.cassandra.locator.ReplicaPlan;
+import org.apache.cassandra.service.StorageProxy;
+import org.apache.cassandra.transport.Dispatcher;
+import org.apache.cassandra.utils.Shared;
+import org.apache.cassandra.utils.TimeUUID;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
+
+public class AccordSingleTokenBatchTest extends AccordTestBase
+{
+    private static final Logger logger = LoggerFactory.getLogger(AccordSingleTokenBatchTest.class);
+
+    @Override
+    protected Logger logger()
+    {
+        return logger;
+    }
+
+    @BeforeClass
+    public static void setupClass() throws IOException
+    {
+        AccordTestBase.setupCluster(builder -> builder
+                                               .withoutVNodes()
+                                               .withInstanceInitializer(BBHelper::install)
+                                               .withConfig(config ->
+                                                           config
+                                                           .with(Feature.NETWORK, Feature.GOSSIP)), 6);
+    }
+
+    @Test
+    public void accordSinglePartitionKeyBatchTest() throws Throwable
+    {
+        List<String> ddls = Arrays.asList("DROP KEYSPACE IF EXISTS " + KEYSPACE + ';',
+                                          "CREATE KEYSPACE " + KEYSPACE + " WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 3}",
+                                          "CREATE TABLE " + qualifiedAccordTableName + " (k int PRIMARY KEY, v int) WITH transactional_mode='full'",
+                                          "CREATE TABLE " + qualifiedRegularTableName + " (k int PRIMARY KEY, v int)");
+        test(ddls, cluster -> {
+            cluster.coordinator(1).execute("BEGIN BATCH\n" +
+                                           "INSERT INTO " + qualifiedAccordTableName + " (k, v) VALUES (1, 2);\n" +
+                                           "INSERT INTO " + qualifiedRegularTableName + " (k, v) VALUES (1, 3);\n" +
+                                           "APPLY BATCH;", ConsistencyLevel.ONE); 
+
+            SimpleQueryResult r1 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedAccordTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+            SimpleQueryResult r2 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedRegularTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+
+            assert(r1.toObjectArrays().length == 1);
+            assert(r2.toObjectArrays().length == 1);
+
+            assert(State.batchLogPath.get());
+        });
+    }
+
+    @Shared
+    public static class State
+    {
+        public static AtomicBoolean batchLogPath = new AtomicBoolean(false);
+    }
+
+    public static class BBHelper

Review Comment:
   Got it, updated the test to instead inspect whether or not the batch log contains the mutation with the two partition updates that we want. 



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4684:
URL: https://github.com/apache/cassandra/pull/4684#discussion_r3149401563


##########
test/distributed/org/apache/cassandra/distributed/test/accord/AccordCQLTestBase.java:
##########
@@ -330,6 +338,79 @@ public void testPartitionMultiRowReturn() throws Exception
         });
     }
 
+    @Test
+    public void testSinglePartitionKeyBatch() throws Throwable
+    {
+        List<String> ddls = Arrays.asList("DROP KEYSPACE IF EXISTS " + KEYSPACE + ';',
+                                          "CREATE KEYSPACE " + KEYSPACE + " WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 2}",
+                                          "CREATE TABLE " + qualifiedAccordTableName + " (k int PRIMARY KEY, v int) WITH " + transactionalMode.asCqlParam(),
+                                          "CREATE TABLE " + qualifiedRegularTableName + " (k int PRIMARY KEY, v int)");
+
+        test(ddls, cluster -> {
+            cluster.coordinator(1).execute("BEGIN BATCH\n" +
+                                           "INSERT INTO " + qualifiedAccordTableName + " (k, v) VALUES (1, 2);\n" +
+                                           "INSERT INTO " + qualifiedRegularTableName + " (k, v) VALUES (1, 3);\n" +
+                                           "APPLY BATCH;", ConsistencyLevel.ONE);
+
+            SimpleQueryResult r1 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedAccordTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+            SimpleQueryResult r2 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedRegularTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+
+            assertEquals(1, r1.toObjectArrays().length);
+            assertEquals(1, r2.toObjectArrays().length);
+        });
+    }
+
+    @Test
+    public void testSinglePartitionKeyBatchWrittenToBatchLog() throws Throwable
+    {
+        DatabaseDescriptor.daemonInitialization();
+        List<String> ddls = Arrays.asList("DROP KEYSPACE IF EXISTS " + KEYSPACE + ';',
+                                          "CREATE KEYSPACE " + KEYSPACE + " WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 2}",
+                                          "CREATE TABLE " + qualifiedAccordTableName + " (k int PRIMARY KEY, v int) WITH " + transactionalMode.asCqlParam(),
+                                          "CREATE TABLE " + qualifiedRegularTableName + " (k int PRIMARY KEY, v int)");
+
+        test(ddls, cluster -> {
+            pauseHints();
+            blockMutationAndPreAccept(cluster);
+            try
+            {
+                cluster.coordinator(1).execute("BEGIN BATCH\n" +
+                                               "INSERT INTO " + qualifiedAccordTableName + " (k, v) VALUES (1, 2);\n" +
+                                               "INSERT INTO " + qualifiedRegularTableName + " (k, v) VALUES (1, 3);\n" +
+                                               "APPLY BATCH;", ConsistencyLevel.ALL);
+                fail("Should have thrown WTE");
+            }
+            catch (Throwable t)
+            {
+                assertEquals(t.getClass().getName(), WriteTimeoutException.class.getName());
+            }
+
+            if (transactionalMode.nonSerialWritesThroughAccord)
+                cluster.get(1).runOnInstance(() -> {
+                    String query = String.format("SELECT id, mutations, version FROM %s.%s",
+                                                 SchemaConstants.SYSTEM_KEYSPACE_NAME,
+                                                 SystemKeyspace.BATCHES);
+
+                    Iterator<UntypedResultSet.Row> r = QueryProcessor.executeInternal(query).iterator();
+                    assert (r.hasNext());
+                    UntypedResultSet.Row row = r.next();
+
+                    int version = row.getInt("version");
+                    List<ByteBuffer> serializedMutations = row.getList("mutations", BytesType.instance);
+                    assertEquals(1, serializedMutations.size());
+
+                    try (DataInputBuffer in = new DataInputBuffer(serializedMutations.get(0), true))
+                    {
+                        assertEquals(2, org.apache.cassandra.db.Mutation.serializer.deserialize(in, version).getPartitionUpdates().size());
+                    }
+                    catch (Exception e)
+                    {
+                        logger.info("Deserialization failed");

Review Comment:
   you should fail the test; if this is happening the test passes but we have a bug?



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

Posted by "alanwang67 (via GitHub)" <gi...@apache.org>.
alanwang67 commented on code in PR #4684:
URL: https://github.com/apache/cassandra/pull/4684#discussion_r2977097965


##########
src/java/org/apache/cassandra/cql3/statements/BatchStatement.java:
##########
@@ -541,7 +543,11 @@ private void executeWithoutConditions(List<? extends IMutation> mutations, Consi
 
         updatePartitionsPerBatchMetrics(mutations.size());
 
-        boolean mutateAtomic = (isLogged() && mutations.size() > 1);
+        // We special case single token batch statements that span both Accord and non-Accord
+        // tables to go through the batch log in order to preserve all or nothing application
+        // see CASSANDRA-20588 for more details
+        boolean isSingleTokenBatchStatementSpanningAccordAndNonAccordTables = (mutations.size() == 1) && (containsAccordMutation(ClusterMetadata.current(), mutations.get(0)));

Review Comment:
   I'm assuming you mean `StorageProxy.mutateWithTriggers`, as `StorageProxy.mutateWithConditions` does not exist. So currently, there are two methods that we branch to depending on whether or not we go through the batch log path: `mutateAtomically` and `dispatchMutationsWithRetryOnDifferentSystem`. These two methods use different `SplitConsumer`'s on the list of Accord Mutations and the list of Normal Mutations after constructing them. This means that in order to reuse the values that we created, we will need to perform the creation of the `SplitConsumer` after we have determined which path we will go down. Doing so is a bit awkward since the two `SplitConsumer`'s don't return the same type. Therefore, we would need to perform this as a side effect. However, this is a bit messy since `SplitConsumer` captures some state that is only later created by `mutateAtomically` and also this means we would have to allocate this state regardless of which branch we went down which seems a bit wa
 steful. 
   
   Some other alternatives I've considered are just applying the `SplitConsumer` lazily after we have passed in the two values. However, this means that we will have to reiterate over the list of Mutations which doesn't seem too great to do since we will have to pay this price for every Batch and Modification Statement. 
   
   However from your above comments, I changed the check to do a single pass and not allocate the filtered mutations and also inlined it so we only pay this overhead in the batch statement for the single mutation case.
   
   Also glad to take any suggestions if there's a better way to do things or if the tradeoff is still worthwhile to do. 



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4684:
URL: https://github.com/apache/cassandra/pull/4684#discussion_r3149388336


##########
test/distributed/org/apache/cassandra/distributed/test/accord/AccordCQLTestBase.java:
##########
@@ -330,6 +338,79 @@ public void testPartitionMultiRowReturn() throws Exception
         });
     }
 
+    @Test
+    public void testSinglePartitionKeyBatch() throws Throwable
+    {
+        List<String> ddls = Arrays.asList("DROP KEYSPACE IF EXISTS " + KEYSPACE + ';',
+                                          "CREATE KEYSPACE " + KEYSPACE + " WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 2}",
+                                          "CREATE TABLE " + qualifiedAccordTableName + " (k int PRIMARY KEY, v int) WITH " + transactionalMode.asCqlParam(),
+                                          "CREATE TABLE " + qualifiedRegularTableName + " (k int PRIMARY KEY, v int)");
+
+        test(ddls, cluster -> {
+            cluster.coordinator(1).execute("BEGIN BATCH\n" +
+                                           "INSERT INTO " + qualifiedAccordTableName + " (k, v) VALUES (1, 2);\n" +
+                                           "INSERT INTO " + qualifiedRegularTableName + " (k, v) VALUES (1, 3);\n" +
+                                           "APPLY BATCH;", ConsistencyLevel.ONE);
+
+            SimpleQueryResult r1 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedAccordTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+            SimpleQueryResult r2 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedRegularTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+
+            assertEquals(1, r1.toObjectArrays().length);
+            assertEquals(1, r2.toObjectArrays().length);

Review Comment:
   this tests that we get data, but this test passes today without the patch right?  We don't validate we actually did anything?



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4684:
URL: https://github.com/apache/cassandra/pull/4684#discussion_r3140580159


##########
src/java/org/apache/cassandra/service/consensus/migration/ConsensusMigrationMutationHelper.java:
##########
@@ -204,6 +204,29 @@ public static <T extends IMutation> void splitMutationsIntoAccordAndNormal(Clust
         }
     }
 
+    public static <T extends IMutation> boolean isSingleTokenStatementSpanningAccordAndNonAccordTables(ClusterMetadata cm, T mutation)
+    {
+        if (mutation.potentialTxnConflicts().allowed || mutation.getTableIds().size() == 1)
+            return false;
+
+        Token token = mutation.key().getToken();
+
+        boolean containsAccordMutation = false;
+        boolean containsNormalMutation = false;
+
+        for (TableId tableId : mutation.getTableIds())
+        {
+            boolean test = tokenShouldBeWrittenThroughAccord(cm, tableId, token, TransactionalMode::nonSerialWritesThroughAccord, TransactionalMigrationFromMode::nonSerialWritesThroughAccord);
+            containsAccordMutation = containsAccordMutation || test;

Review Comment:
   ```suggestion
               containsAccordMutation |= test;
   ```



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

Posted by "alanwang67 (via GitHub)" <gi...@apache.org>.
alanwang67 commented on code in PR #4684:
URL: https://github.com/apache/cassandra/pull/4684#discussion_r2968084135


##########
doc/modules/cassandra/pages/architecture/cql-on-accord.adoc:
##########
@@ -549,11 +549,11 @@ replay only makes a single attempt to replay before converting the batch
 contents to hints. If part of the batch was routed to Accord then there
 is no node to hint so there is a fake node that a hint is written to and
 when that hint is dispatched it will be split and then executed
-appropriately. In https://issues.apache.org/jira/browse/CASSANDRA-20588[CASSANDRA-20588] this needs to be simplified to writing the
-entire batch through Accord if any part of it should be written through
-Accord because it also addresses an atomicity issue with single token
-batches which can be torn when part is applied through Accord and part
-is applied through Cassandra.
+appropriately. Single token batches that involve both an Accord and non-Accord

Review Comment:
   Got it will update the comment. 



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4684:
URL: https://github.com/apache/cassandra/pull/4684#discussion_r3149398103


##########
test/distributed/org/apache/cassandra/distributed/test/accord/AccordCQLTestBase.java:
##########
@@ -330,6 +338,79 @@ public void testPartitionMultiRowReturn() throws Exception
         });
     }
 
+    @Test
+    public void testSinglePartitionKeyBatch() throws Throwable
+    {
+        List<String> ddls = Arrays.asList("DROP KEYSPACE IF EXISTS " + KEYSPACE + ';',
+                                          "CREATE KEYSPACE " + KEYSPACE + " WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 2}",
+                                          "CREATE TABLE " + qualifiedAccordTableName + " (k int PRIMARY KEY, v int) WITH " + transactionalMode.asCqlParam(),
+                                          "CREATE TABLE " + qualifiedRegularTableName + " (k int PRIMARY KEY, v int)");
+
+        test(ddls, cluster -> {
+            cluster.coordinator(1).execute("BEGIN BATCH\n" +
+                                           "INSERT INTO " + qualifiedAccordTableName + " (k, v) VALUES (1, 2);\n" +
+                                           "INSERT INTO " + qualifiedRegularTableName + " (k, v) VALUES (1, 3);\n" +
+                                           "APPLY BATCH;", ConsistencyLevel.ONE);
+
+            SimpleQueryResult r1 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedAccordTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+            SimpleQueryResult r2 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedRegularTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+
+            assertEquals(1, r1.toObjectArrays().length);
+            assertEquals(1, r2.toObjectArrays().length);
+        });
+    }
+
+    @Test
+    public void testSinglePartitionKeyBatchWrittenToBatchLog() throws Throwable
+    {
+        DatabaseDescriptor.daemonInitialization();
+        List<String> ddls = Arrays.asList("DROP KEYSPACE IF EXISTS " + KEYSPACE + ';',
+                                          "CREATE KEYSPACE " + KEYSPACE + " WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 2}",
+                                          "CREATE TABLE " + qualifiedAccordTableName + " (k int PRIMARY KEY, v int) WITH " + transactionalMode.asCqlParam(),
+                                          "CREATE TABLE " + qualifiedRegularTableName + " (k int PRIMARY KEY, v int)");
+
+        test(ddls, cluster -> {
+            pauseHints();
+            blockMutationAndPreAccept(cluster);
+            try
+            {
+                cluster.coordinator(1).execute("BEGIN BATCH\n" +
+                                               "INSERT INTO " + qualifiedAccordTableName + " (k, v) VALUES (1, 2);\n" +
+                                               "INSERT INTO " + qualifiedRegularTableName + " (k, v) VALUES (1, 3);\n" +
+                                               "APPLY BATCH;", ConsistencyLevel.ALL);
+                fail("Should have thrown WTE");
+            }
+            catch (Throwable t)
+            {
+                assertEquals(t.getClass().getName(), WriteTimeoutException.class.getName());
+            }
+
+            if (transactionalMode.nonSerialWritesThroughAccord)
+                cluster.get(1).runOnInstance(() -> {
+                    String query = String.format("SELECT id, mutations, version FROM %s.%s",
+                                                 SchemaConstants.SYSTEM_KEYSPACE_NAME,
+                                                 SystemKeyspace.BATCHES);
+
+                    Iterator<UntypedResultSet.Row> r = QueryProcessor.executeInternal(query).iterator();
+                    assert (r.hasNext());

Review Comment:
   nit: use junit assert.  `-ea` should be set by java, but its always best to be explicit; you don't want to actually have a conditionally run assert here, you want to run 100% of the time?



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4684:
URL: https://github.com/apache/cassandra/pull/4684#discussion_r3149384880


##########
test/distributed/org/apache/cassandra/distributed/test/accord/AccordCQLTestBase.java:
##########
@@ -330,6 +338,79 @@ public void testPartitionMultiRowReturn() throws Exception
         });
     }
 
+    @Test
+    public void testSinglePartitionKeyBatch() throws Throwable
+    {
+        List<String> ddls = Arrays.asList("DROP KEYSPACE IF EXISTS " + KEYSPACE + ';',
+                                          "CREATE KEYSPACE " + KEYSPACE + " WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 2}",
+                                          "CREATE TABLE " + qualifiedAccordTableName + " (k int PRIMARY KEY, v int) WITH " + transactionalMode.asCqlParam(),
+                                          "CREATE TABLE " + qualifiedRegularTableName + " (k int PRIMARY KEY, v int)");
+
+        test(ddls, cluster -> {
+            cluster.coordinator(1).execute("BEGIN BATCH\n" +
+                                           "INSERT INTO " + qualifiedAccordTableName + " (k, v) VALUES (1, 2);\n" +
+                                           "INSERT INTO " + qualifiedRegularTableName + " (k, v) VALUES (1, 3);\n" +
+                                           "APPLY BATCH;", ConsistencyLevel.ONE);
+
+            SimpleQueryResult r1 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedAccordTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+            SimpleQueryResult r2 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedRegularTableName + " WHERE k = 1", ConsistencyLevel.ONE);

Review Comment:
   so the batch is async right?  so this logic feels racy?  can't it return 0 rows some times due to races?



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

Posted by "aweisberg (via GitHub)" <gi...@apache.org>.
aweisberg commented on code in PR #4684:
URL: https://github.com/apache/cassandra/pull/4684#discussion_r2977193613


##########
test/distributed/org/apache/cassandra/distributed/test/accord/AccordCQLTestBase.java:
##########
@@ -330,6 +338,79 @@ public void testPartitionMultiRowReturn() throws Exception
         });
     }
 
+    @Test
+    public void testSinglePartitionKeyBatch() throws Throwable
+    {
+        List<String> ddls = Arrays.asList("DROP KEYSPACE IF EXISTS " + KEYSPACE + ';',
+                                          "CREATE KEYSPACE " + KEYSPACE + " WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 3}",
+                                          "CREATE TABLE " + qualifiedAccordTableName + " (k int PRIMARY KEY, v int) WITH transactional_mode='full'",
+                                          "CREATE TABLE " + qualifiedRegularTableName + " (k int PRIMARY KEY, v int)");
+
+        test(ddls, cluster -> {
+            cluster.coordinator(1).execute("BEGIN BATCH\n" +
+                                           "INSERT INTO " + qualifiedAccordTableName + " (k, v) VALUES (1, 2);\n" +
+                                           "INSERT INTO " + qualifiedRegularTableName + " (k, v) VALUES (1, 3);\n" +
+                                           "APPLY BATCH;", ConsistencyLevel.ONE);
+
+            SimpleQueryResult r1 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedAccordTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+            SimpleQueryResult r2 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedRegularTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+
+            assertEquals(1, r1.toObjectArrays().length);
+            assertEquals(1, r2.toObjectArrays().length);
+        });
+    }
+
+    @Test
+    public void testSinglePartitionKeyBatchWrittenToBatchLog() throws Throwable
+    {
+        DatabaseDescriptor.daemonInitialization();
+        List<String> ddls = Arrays.asList("DROP KEYSPACE IF EXISTS " + KEYSPACE + ';',
+                                          "CREATE KEYSPACE " + KEYSPACE + " WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 3}",
+                                          "CREATE TABLE " + qualifiedAccordTableName + " (k int PRIMARY KEY, v int) WITH transactional_mode='full'",

Review Comment:
   Same use the transactional mode from the derived test.



##########
test/distributed/org/apache/cassandra/distributed/test/accord/AccordCQLTestBase.java:
##########
@@ -330,6 +338,79 @@ public void testPartitionMultiRowReturn() throws Exception
         });
     }
 
+    @Test
+    public void testSinglePartitionKeyBatch() throws Throwable
+    {
+        List<String> ddls = Arrays.asList("DROP KEYSPACE IF EXISTS " + KEYSPACE + ';',
+                                          "CREATE KEYSPACE " + KEYSPACE + " WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 3}",
+                                          "CREATE TABLE " + qualifiedAccordTableName + " (k int PRIMARY KEY, v int) WITH transactional_mode='full'",

Review Comment:
   It would be good to use the transactional mode from whatever derived class this test is currently using



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

Posted by "aweisberg (via GitHub)" <gi...@apache.org>.
aweisberg commented on code in PR #4684:
URL: https://github.com/apache/cassandra/pull/4684#discussion_r2968007212


##########
test/distributed/org/apache/cassandra/distributed/test/accord/AccordSingleTokenBatchTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.SuperCall;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.db.Mutation;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.distributed.api.Feature;
+import org.apache.cassandra.distributed.api.SimpleQueryResult;
+import org.apache.cassandra.locator.ReplicaPlan;
+import org.apache.cassandra.service.StorageProxy;
+import org.apache.cassandra.transport.Dispatcher;
+import org.apache.cassandra.utils.Shared;
+import org.apache.cassandra.utils.TimeUUID;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
+
+public class AccordSingleTokenBatchTest extends AccordTestBase
+{
+    private static final Logger logger = LoggerFactory.getLogger(AccordSingleTokenBatchTest.class);
+
+    @Override
+    protected Logger logger()
+    {
+        return logger;
+    }
+
+    @BeforeClass
+    public static void setupClass() throws IOException
+    {
+        AccordTestBase.setupCluster(builder -> builder
+                                               .withoutVNodes()
+                                               .withInstanceInitializer(BBHelper::install)
+                                               .withConfig(config ->
+                                                           config
+                                                           .with(Feature.NETWORK, Feature.GOSSIP)), 6);
+    }
+
+    @Test
+    public void accordSinglePartitionKeyBatchTest() throws Throwable
+    {
+        List<String> ddls = Arrays.asList("DROP KEYSPACE IF EXISTS " + KEYSPACE + ';',
+                                          "CREATE KEYSPACE " + KEYSPACE + " WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 3}",
+                                          "CREATE TABLE " + qualifiedAccordTableName + " (k int PRIMARY KEY, v int) WITH transactional_mode='full'",
+                                          "CREATE TABLE " + qualifiedRegularTableName + " (k int PRIMARY KEY, v int)");
+        test(ddls, cluster -> {
+            cluster.coordinator(1).execute("BEGIN BATCH\n" +
+                                           "INSERT INTO " + qualifiedAccordTableName + " (k, v) VALUES (1, 2);\n" +
+                                           "INSERT INTO " + qualifiedRegularTableName + " (k, v) VALUES (1, 3);\n" +
+                                           "APPLY BATCH;", ConsistencyLevel.ONE); 
+
+            SimpleQueryResult r1 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedAccordTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+            SimpleQueryResult r2 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedRegularTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+
+            assert(r1.toObjectArrays().length == 1);
+            assert(r2.toObjectArrays().length == 1);
+
+            assert(State.batchLogPath.get());
+        });
+    }
+
+    @Shared
+    public static class State
+    {
+        public static AtomicBoolean batchLogPath = new AtomicBoolean(false);
+    }
+
+    public static class BBHelper

Review Comment:
   ByteBuddy is kind of a maintenance headache because it quickly fails to match the methods it is supposed to be updating if the name or signature changes as there is no static compile time check.
   
   I almost always try to find some way to use a metric instead. In this instance I don't see a metric in `mutateAtomically` so you can inspect the batch log table itself. You might need to pause batch log delivery to make sure the entry in the batch log table isn't deleted.



##########
doc/modules/cassandra/pages/architecture/cql-on-accord.adoc:
##########
@@ -549,11 +549,11 @@ replay only makes a single attempt to replay before converting the batch
 contents to hints. If part of the batch was routed to Accord then there
 is no node to hint so there is a fake node that a hint is written to and
 when that hint is dispatched it will be split and then executed
-appropriately. In https://issues.apache.org/jira/browse/CASSANDRA-20588[CASSANDRA-20588] this needs to be simplified to writing the
-entire batch through Accord if any part of it should be written through
-Accord because it also addresses an atomicity issue with single token
-batches which can be torn when part is applied through Accord and part
-is applied through Cassandra.
+appropriately. Single token batches that involve both an Accord and non-Accord

Review Comment:
   It's non-obvious what is going on here because many readers won't know what normally happens.
   
   Remove the last sentence and then update the first sentence to say that single token batch that span both Accord and non-Accord tables are written to the batch log to preserve all or nothing application. This incurs an additional performance cost because normally these single token batches would not be written to the batch log.



##########
test/distributed/org/apache/cassandra/distributed/test/accord/AccordSingleTokenBatchTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.SuperCall;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.db.Mutation;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.distributed.api.Feature;
+import org.apache.cassandra.distributed.api.SimpleQueryResult;
+import org.apache.cassandra.locator.ReplicaPlan;
+import org.apache.cassandra.service.StorageProxy;
+import org.apache.cassandra.transport.Dispatcher;
+import org.apache.cassandra.utils.Shared;
+import org.apache.cassandra.utils.TimeUUID;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
+
+public class AccordSingleTokenBatchTest extends AccordTestBase

Review Comment:
   It's not worth a whole new class and setting up a cluster. Can you add this to AccordCQLTestBase?



##########
src/java/org/apache/cassandra/cql3/statements/BatchStatement.java:
##########
@@ -541,7 +543,11 @@ private void executeWithoutConditions(List<? extends IMutation> mutations, Consi
 
         updatePartitionsPerBatchMetrics(mutations.size());
 
-        boolean mutateAtomic = (isLogged() && mutations.size() > 1);
+        // We special case single token batch statements that span both Accord and non-Accord
+        // tables to go through the batch log in order to preserve all or nothing application
+        // see CASSANDRA-20588 for more details
+        boolean isSingleTokenBatchStatementSpanningAccordAndNonAccordTables = (mutations.size() == 1) && (containsAccordMutation(ClusterMetadata.current(), mutations.get(0)));

Review Comment:
   I think this is being done in the wrong file. Update `StorageProxy.mutateWithConditions` to split the mutations and then use the result of the split to decide what is happening. A helper function can iterate the split mutation and look for the pattern we want to specially route to the batch log path. You can pass the already split mutations into the atomic and non-atomic mutation methods to re-use that work.
   
   The pattern to look for is split across Accord and non-Accord with more than one table present. You don't even need to have a set for tracking table UUID just remember the first one you see and if you see a different one in the other set of tables then you know it needs to go down the batch log route.
   
   I don't love asking for this because it's gong to be messy, but every mutation has to pass through here so avoiding repeating map lookups and constructing filtered mutations seems worth it.



##########
test/distributed/org/apache/cassandra/distributed/test/accord/AccordSingleTokenBatchTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.SuperCall;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.db.Mutation;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.distributed.api.Feature;
+import org.apache.cassandra.distributed.api.SimpleQueryResult;
+import org.apache.cassandra.locator.ReplicaPlan;
+import org.apache.cassandra.service.StorageProxy;
+import org.apache.cassandra.transport.Dispatcher;
+import org.apache.cassandra.utils.Shared;
+import org.apache.cassandra.utils.TimeUUID;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
+
+public class AccordSingleTokenBatchTest extends AccordTestBase
+{
+    private static final Logger logger = LoggerFactory.getLogger(AccordSingleTokenBatchTest.class);
+
+    @Override
+    protected Logger logger()
+    {
+        return logger;
+    }
+
+    @BeforeClass
+    public static void setupClass() throws IOException
+    {
+        AccordTestBase.setupCluster(builder -> builder
+                                               .withoutVNodes()
+                                               .withInstanceInitializer(BBHelper::install)
+                                               .withConfig(config ->
+                                                           config
+                                                           .with(Feature.NETWORK, Feature.GOSSIP)), 6);
+    }
+
+    @Test
+    public void accordSinglePartitionKeyBatchTest() throws Throwable
+    {
+        List<String> ddls = Arrays.asList("DROP KEYSPACE IF EXISTS " + KEYSPACE + ';',
+                                          "CREATE KEYSPACE " + KEYSPACE + " WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 3}",
+                                          "CREATE TABLE " + qualifiedAccordTableName + " (k int PRIMARY KEY, v int) WITH transactional_mode='full'",
+                                          "CREATE TABLE " + qualifiedRegularTableName + " (k int PRIMARY KEY, v int)");
+        test(ddls, cluster -> {
+            cluster.coordinator(1).execute("BEGIN BATCH\n" +
+                                           "INSERT INTO " + qualifiedAccordTableName + " (k, v) VALUES (1, 2);\n" +
+                                           "INSERT INTO " + qualifiedRegularTableName + " (k, v) VALUES (1, 3);\n" +
+                                           "APPLY BATCH;", ConsistencyLevel.ONE); 
+
+            SimpleQueryResult r1 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedAccordTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+            SimpleQueryResult r2 = cluster.coordinator(1).executeWithResult("SELECT * FROM " + qualifiedRegularTableName + " WHERE k = 1", ConsistencyLevel.ONE);
+
+            assert(r1.toObjectArrays().length == 1);

Review Comment:
   Use `assertTrue` not `assert` because `assert` can be disabled. Except everyone always runs C* and tests with assertions enabled anyways because running without assertions enabled even in production is pretty risky. When a check can be disabled it's still not an assert because there then you should add a property in CassandraRelevantProperties documenting the expensive assertion.
   
   So basically... `assert` is kind of dead and we don't use it anymore.
   
   I think junit also classifies errors from assert differently. They are errors not test condition failures which are different categories.



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

Posted by "alanwang67 (via GitHub)" <gi...@apache.org>.
alanwang67 closed pull request #4684: CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches
URL: https://github.com/apache/cassandra/pull/4684


-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4684:
URL: https://github.com/apache/cassandra/pull/4684#discussion_r3140580867


##########
src/java/org/apache/cassandra/service/consensus/migration/ConsensusMigrationMutationHelper.java:
##########
@@ -204,6 +204,29 @@ public static <T extends IMutation> void splitMutationsIntoAccordAndNormal(Clust
         }
     }
 
+    public static <T extends IMutation> boolean isSingleTokenStatementSpanningAccordAndNonAccordTables(ClusterMetadata cm, T mutation)
+    {
+        if (mutation.potentialTxnConflicts().allowed || mutation.getTableIds().size() == 1)
+            return false;
+
+        Token token = mutation.key().getToken();
+
+        boolean containsAccordMutation = false;
+        boolean containsNormalMutation = false;
+
+        for (TableId tableId : mutation.getTableIds())
+        {
+            boolean test = tokenShouldBeWrittenThroughAccord(cm, tableId, token, TransactionalMode::nonSerialWritesThroughAccord, TransactionalMigrationFromMode::nonSerialWritesThroughAccord);
+            containsAccordMutation = containsAccordMutation || test;
+            containsNormalMutation = containsNormalMutation || !test;

Review Comment:
   ```suggestion
               containsNormalMutation |= !test;
   ```



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] CASSANDRA-20588 Fix single token batch atomicity with Accord/non-Accord batches [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4684:
URL: https://github.com/apache/cassandra/pull/4684#discussion_r3140580867


##########
src/java/org/apache/cassandra/service/consensus/migration/ConsensusMigrationMutationHelper.java:
##########
@@ -204,6 +204,29 @@ public static <T extends IMutation> void splitMutationsIntoAccordAndNormal(Clust
         }
     }
 
+    public static <T extends IMutation> boolean isSingleTokenStatementSpanningAccordAndNonAccordTables(ClusterMetadata cm, T mutation)
+    {
+        if (mutation.potentialTxnConflicts().allowed || mutation.getTableIds().size() == 1)
+            return false;
+
+        Token token = mutation.key().getToken();
+
+        boolean containsAccordMutation = false;
+        boolean containsNormalMutation = false;
+
+        for (TableId tableId : mutation.getTableIds())
+        {
+            boolean test = tokenShouldBeWrittenThroughAccord(cm, tableId, token, TransactionalMode::nonSerialWritesThroughAccord, TransactionalMigrationFromMode::nonSerialWritesThroughAccord);
+            containsAccordMutation = containsAccordMutation || test;
+            containsNormalMutation = containsNormalMutation || !test;

Review Comment:
   ```suggestion
               containsNormalMutation != !test;
   ```



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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