You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "bdeggleston (via GitHub)" <gi...@apache.org> on 2025/08/22 17:26:37 UTC

[PR] Implement unified log reconciliation [cassandra]

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

   patch by Aleksey Yeschenko; reviewed by Blake Eggleston for CASSANDRA-20729
   
   Thanks for sending a pull request! Here are some tips if you're new here:
    
    * Ensure you have added or run the [appropriate tests](https://cassandra.apache.org/_/development/testing.html) for your PR.
    * Be sure to keep the PR description updated to reflect all changes.
    * Write your PR title to summarize what this PR proposes.
    * If possible, provide a concise example to reproduce the issue for a faster review.
    * Read our [contributor guidelines](https://cassandra.apache.org/_/development/index.html)
    * If you're making a documentation change, see our [guide to documentation contribution](https://cassandra.apache.org/_/development/documentation.html)
    
   Commit messages should follow the following format:
   
   ```
   <One sentence description, usually Jira title or CHANGES.txt summary>
   
   <Optional lengthier description (context on patch)>
   
   patch by <Authors>; reviewed by <Reviewers> for CASSANDRA-#####
   
   Co-authored-by: Name1 <email1>
   Co-authored-by: Name2 <email2>
   
   ```
   
   The [Cassandra Jira](https://issues.apache.org/jira/projects/CASSANDRA/issues/)
   
   


-- 
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] Implement unified log reconciliation [cassandra]

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


##########
src/java/org/apache/cassandra/replication/OutgoingMutations.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.replication;
+
+import org.agrona.collections.IntHashSet;
+import org.apache.cassandra.db.Mutation;
+import org.apache.cassandra.exceptions.RequestFailureReason;
+import org.apache.cassandra.locator.InetAddressAndPort;
+import org.jctools.maps.NonBlockingHashMapLong;
+
+/**
+ * Keep track of outgoing mutations so that we don't double-send any mutations
+ * when read reconciliation writes race with regular writes and/or each other.
+ * </p>
+ * Regular writes have a callback and need to be retried;
+ * Reconciliation writes have no callback, and only need to be retried if the writing node owns the log.
+ * </p>
+ * Note: this could live inside {@link CoordinatorLog}, since we cannot ever send a mutation
+ * that we don't have an instance of {@link CoordinatorLog} for, but for symmetry with
+ * {@link IncomingMutations} we put this inside {@link MutationTrackingService}.
+ */
+class OutgoingMutations

Review Comment:
   Incoming dedup is implemented, but outgoing dedup is wip. Let's punt to a follow-up JIRA - it's less important than incoming dedup is.



##########
src/java/org/apache/cassandra/replication/OutgoingMutations.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.replication;
+
+import org.agrona.collections.IntHashSet;
+import org.apache.cassandra.db.Mutation;
+import org.apache.cassandra.exceptions.RequestFailureReason;
+import org.apache.cassandra.locator.InetAddressAndPort;
+import org.jctools.maps.NonBlockingHashMapLong;
+
+/**
+ * Keep track of outgoing mutations so that we don't double-send any mutations
+ * when read reconciliation writes race with regular writes and/or each other.
+ * </p>
+ * Regular writes have a callback and need to be retried;
+ * Reconciliation writes have no callback, and only need to be retried if the writing node owns the log.
+ * </p>
+ * Note: this could live inside {@link CoordinatorLog}, since we cannot ever send a mutation
+ * that we don't have an instance of {@link CoordinatorLog} for, but for symmetry with
+ * {@link IncomingMutations} we put this inside {@link MutationTrackingService}.
+ */
+class OutgoingMutations
+{
+    private final NonBlockingHashMapLong<LogOutgoingMutations> log2MutationsMap = new NonBlockingHashMapLong<>();
+
+    void sentWriteRequest(Mutation mutation, IntHashSet toHostIds)
+    {
+        getOrCreate(mutation.id()).sentWriteRequest(mutation, toHostIds);
+    }
+
+    void receivedWriteResponse(ShortMutationId mutationId, int fromHostId)
+    {
+        getOrCreate(mutationId).receivedWriteResponse(mutationId, fromHostId);
+    }
+
+    void writeFailed(ShortMutationId mutationId, RequestFailureReason reason, InetAddressAndPort onHost)
+    {
+        getOrCreate(mutationId).writeFailed(mutationId, reason, onHost);
+    }
+
+    private LogOutgoingMutations getOrCreate(ShortMutationId mutationId)
+    {
+        LogOutgoingMutations mutations = log2MutationsMap.get(mutationId.logId());
+        if (mutations == null)
+            mutations = log2MutationsMap.computeIfAbsent(mutationId.logId(), ignore -> new LogOutgoingMutations());
+        return mutations;
+    }
+
+    private static class LogOutgoingMutations
+    {
+        // {host, offset} -> per-participant mutation state map
+        private final NonBlockingHashMapLong<OutgoingState> states = new NonBlockingHashMapLong<>();
+
+        void sentWriteRequest(Mutation mutation, IntHashSet toHostIds)
+        {
+            IntHashSet.IntIterator iterator = toHostIds.iterator();
+            while (iterator.hasNext())
+            {
+                OutgoingState state = getOrCreateState(iterator.nextValue(), mutation.id().offset());
+                state.setInFlight();
+            }
+        }
+
+        void receivedWriteResponse(ShortMutationId mutationId, int fromHostId)
+        {
+            OutgoingState state = remove(fromHostId, mutationId.offset());
+            if (state != null)
+                state.receivedWriteResponse();
+        }
+
+        void writeFailed(ShortMutationId mutationId, RequestFailureReason reason, InetAddressAndPort onHost)
+        {
+            // TODO check if need to implement this
+        }
+
+        // TODO FIXME: proper implementation
+        OutgoingState getOrCreateState(int hostId, int offset)
+        {
+            long key = key(hostId, offset);
+            OutgoingState state = states.get(key);
+            if (state != null)
+                return state;
+            return states.putIfAbsent(key, new OutgoingState());

Review Comment:
   But might as well fix it again here so that it doesn't resurface when `OutogingMutations` dedup is plugged-in again.



##########
src/java/org/apache/cassandra/replication/CoordinatorLog.java:
##########
@@ -160,13 +160,21 @@ void finishWriting(Mutation mutation)
 
     private boolean othersWitnessed(int offset, int exceptHostId)
     {
-        for (int i = 0; i < participants.size(); ++i)
+        lock.readLock().lock();

Review Comment:
   Was this really fixing a bug? All the calls to it, transitively, already must grab the write lock?



-- 
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] Implement unified log reconciliation [cassandra]

Posted by "iamaleksey (via GitHub)" <gi...@apache.org>.
iamaleksey commented on PR #4330:
URL: https://github.com/apache/cassandra/pull/4330#issuecomment-3229439192

   Merged manually.


-- 
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] Implement unified log reconciliation [cassandra]

Posted by "iamaleksey (via GitHub)" <gi...@apache.org>.
iamaleksey closed pull request #4330: Implement unified log reconciliation
URL: https://github.com/apache/cassandra/pull/4330


-- 
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] Implement unified log reconciliation [cassandra]

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


##########
src/java/org/apache/cassandra/replication/OutgoingMutations.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.replication;
+
+import org.agrona.collections.IntHashSet;
+import org.apache.cassandra.db.Mutation;
+import org.apache.cassandra.exceptions.RequestFailureReason;
+import org.apache.cassandra.locator.InetAddressAndPort;
+import org.jctools.maps.NonBlockingHashMapLong;
+
+/**
+ * Keep track of outgoing mutations so that we don't double-send any mutations
+ * when read reconciliation writes race with regular writes and/or each other.
+ * </p>
+ * Regular writes have a callback and need to be retried;
+ * Reconciliation writes have no callback, and only need to be retried if the writing node owns the log.
+ * </p>
+ * Note: this could live inside {@link CoordinatorLog}, since we cannot ever send a mutation
+ * that we don't have an instance of {@link CoordinatorLog} for, but for symmetry with
+ * {@link IncomingMutations} we put this inside {@link MutationTrackingService}.
+ */
+class OutgoingMutations
+{
+    private final NonBlockingHashMapLong<LogOutgoingMutations> log2MutationsMap = new NonBlockingHashMapLong<>();
+
+    void sentWriteRequest(Mutation mutation, IntHashSet toHostIds)
+    {
+        getOrCreate(mutation.id()).sentWriteRequest(mutation, toHostIds);
+    }
+
+    void receivedWriteResponse(ShortMutationId mutationId, int fromHostId)
+    {
+        getOrCreate(mutationId).receivedWriteResponse(mutationId, fromHostId);
+    }
+
+    void writeFailed(ShortMutationId mutationId, RequestFailureReason reason, InetAddressAndPort onHost)
+    {
+        getOrCreate(mutationId).writeFailed(mutationId, reason, onHost);
+    }
+
+    private LogOutgoingMutations getOrCreate(ShortMutationId mutationId)
+    {
+        LogOutgoingMutations mutations = log2MutationsMap.get(mutationId.logId());
+        if (mutations == null)
+            mutations = log2MutationsMap.computeIfAbsent(mutationId.logId(), ignore -> new LogOutgoingMutations());
+        return mutations;
+    }
+
+    private static class LogOutgoingMutations
+    {
+        // {host, offset} -> per-participant mutation state map
+        private final NonBlockingHashMapLong<OutgoingState> states = new NonBlockingHashMapLong<>();
+
+        void sentWriteRequest(Mutation mutation, IntHashSet toHostIds)
+        {
+            IntHashSet.IntIterator iterator = toHostIds.iterator();
+            while (iterator.hasNext())
+            {
+                OutgoingState state = getOrCreateState(iterator.nextValue(), mutation.id().offset());
+                state.setInFlight();
+            }
+        }
+
+        void receivedWriteResponse(ShortMutationId mutationId, int fromHostId)
+        {
+            OutgoingState state = remove(fromHostId, mutationId.offset());
+            if (state != null)
+                state.receivedWriteResponse();
+        }
+
+        void writeFailed(ShortMutationId mutationId, RequestFailureReason reason, InetAddressAndPort onHost)
+        {
+            // TODO check if need to implement this
+        }
+
+        // TODO FIXME: proper implementation
+        OutgoingState getOrCreateState(int hostId, int offset)
+        {
+            long key = key(hostId, offset);
+            OutgoingState state = states.get(key);
+            if (state != null)
+                return state;
+            return states.putIfAbsent(key, new OutgoingState());

Review Comment:
   I think we want computeIfAbsent here. putIfAbsent will return null if there isn't an entry associated with this key



##########
src/java/org/apache/cassandra/replication/OutgoingMutations.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.replication;
+
+import org.agrona.collections.IntHashSet;
+import org.apache.cassandra.db.Mutation;
+import org.apache.cassandra.exceptions.RequestFailureReason;
+import org.apache.cassandra.locator.InetAddressAndPort;
+import org.jctools.maps.NonBlockingHashMapLong;
+
+/**
+ * Keep track of outgoing mutations so that we don't double-send any mutations
+ * when read reconciliation writes race with regular writes and/or each other.
+ * </p>
+ * Regular writes have a callback and need to be retried;
+ * Reconciliation writes have no callback, and only need to be retried if the writing node owns the log.
+ * </p>
+ * Note: this could live inside {@link CoordinatorLog}, since we cannot ever send a mutation
+ * that we don't have an instance of {@link CoordinatorLog} for, but for symmetry with
+ * {@link IncomingMutations} we put this inside {@link MutationTrackingService}.
+ */
+class OutgoingMutations

Review Comment:
   AFAICT this is incomplete, isn't used anywhere, and deduping isn't implemented anywhere else



-- 
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] Implement unified log reconciliation [cassandra]

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


##########
src/java/org/apache/cassandra/replication/OutgoingMutations.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.replication;
+
+import org.agrona.collections.IntHashSet;
+import org.apache.cassandra.db.Mutation;
+import org.apache.cassandra.exceptions.RequestFailureReason;
+import org.apache.cassandra.locator.InetAddressAndPort;
+import org.jctools.maps.NonBlockingHashMapLong;
+
+/**
+ * Keep track of outgoing mutations so that we don't double-send any mutations
+ * when read reconciliation writes race with regular writes and/or each other.
+ * </p>
+ * Regular writes have a callback and need to be retried;
+ * Reconciliation writes have no callback, and only need to be retried if the writing node owns the log.
+ * </p>
+ * Note: this could live inside {@link CoordinatorLog}, since we cannot ever send a mutation
+ * that we don't have an instance of {@link CoordinatorLog} for, but for symmetry with
+ * {@link IncomingMutations} we put this inside {@link MutationTrackingService}.
+ */
+class OutgoingMutations
+{
+    private final NonBlockingHashMapLong<LogOutgoingMutations> log2MutationsMap = new NonBlockingHashMapLong<>();
+
+    void sentWriteRequest(Mutation mutation, IntHashSet toHostIds)
+    {
+        getOrCreate(mutation.id()).sentWriteRequest(mutation, toHostIds);
+    }
+
+    void receivedWriteResponse(ShortMutationId mutationId, int fromHostId)
+    {
+        getOrCreate(mutationId).receivedWriteResponse(mutationId, fromHostId);
+    }
+
+    void writeFailed(ShortMutationId mutationId, RequestFailureReason reason, InetAddressAndPort onHost)
+    {
+        getOrCreate(mutationId).writeFailed(mutationId, reason, onHost);
+    }
+
+    private LogOutgoingMutations getOrCreate(ShortMutationId mutationId)
+    {
+        LogOutgoingMutations mutations = log2MutationsMap.get(mutationId.logId());
+        if (mutations == null)
+            mutations = log2MutationsMap.computeIfAbsent(mutationId.logId(), ignore -> new LogOutgoingMutations());
+        return mutations;
+    }
+
+    private static class LogOutgoingMutations
+    {
+        // {host, offset} -> per-participant mutation state map
+        private final NonBlockingHashMapLong<OutgoingState> states = new NonBlockingHashMapLong<>();
+
+        void sentWriteRequest(Mutation mutation, IntHashSet toHostIds)
+        {
+            IntHashSet.IntIterator iterator = toHostIds.iterator();
+            while (iterator.hasNext())
+            {
+                OutgoingState state = getOrCreateState(iterator.nextValue(), mutation.id().offset());
+                state.setInFlight();
+            }
+        }
+
+        void receivedWriteResponse(ShortMutationId mutationId, int fromHostId)
+        {
+            OutgoingState state = remove(fromHostId, mutationId.offset());
+            if (state != null)
+                state.receivedWriteResponse();
+        }
+
+        void writeFailed(ShortMutationId mutationId, RequestFailureReason reason, InetAddressAndPort onHost)
+        {
+            // TODO check if need to implement this
+        }
+
+        // TODO FIXME: proper implementation
+        OutgoingState getOrCreateState(int hostId, int offset)
+        {
+            long key = key(hostId, offset);
+            OutgoingState state = states.get(key);
+            if (state != null)
+                return state;
+            return states.putIfAbsent(key, new OutgoingState());

Review Comment:
   Yes, you are correct. I had it fixed elsewhere, but then ended up just getting the incomplete `OutgoingMutations` out of the way for now and lost the fix.



-- 
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