This is an automated email from the ASF dual-hosted git repository.

bdeggleston pushed a commit to branch cep-15-accord
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/cep-15-accord by this push:
     new 01ac50bcbf ninja: fix CFK serializer
01ac50bcbf is described below

commit 01ac50bcbfb2e9b0a9d18a76d0db5c256b997b60
Author: Benedict Elliott Smith <bened...@apache.org>
AuthorDate: Mon Sep 30 23:52:34 2024 +0100

    ninja: fix CFK serializer
---
 modules/accord                                       |  2 +-
 .../accord/serializers/CommandsForKeySerializer.java | 20 +++++++++++---------
 .../serializers/CommandsForKeySerializerTest.java    |  5 +++--
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/modules/accord b/modules/accord
index b0ad8e8cfb..e2e72287a7 160000
--- a/modules/accord
+++ b/modules/accord
@@ -1 +1 @@
-Subproject commit b0ad8e8cfbcc35fc8152850760cd1f34f06836e7
+Subproject commit e2e72287a70bfff4cf6a5639d4a60a0c9e8086b4
diff --git 
a/src/java/org/apache/cassandra/service/accord/serializers/CommandsForKeySerializer.java
 
b/src/java/org/apache/cassandra/service/accord/serializers/CommandsForKeySerializer.java
index a12b17098e..c5ce8054f7 100644
--- 
a/src/java/org/apache/cassandra/service/accord/serializers/CommandsForKeySerializer.java
+++ 
b/src/java/org/apache/cassandra/service/accord/serializers/CommandsForKeySerializer.java
@@ -137,7 +137,7 @@ public class CommandsForKeySerializer
                 {
                     if (nodeIdCount + 3 >= nodeIds.length)
                     {
-                        nodeIdCount = compact(nodeIds);
+                        nodeIdCount = compact(nodeIds, nodeIdCount);
                         if (nodeIdCount > nodeIds.length/2 || nodeIdCount + 2 
>= nodeIds.length)
                             nodeIds = cachedInts().resize(nodeIds, 
nodeIds.length, nodeIds.length * 2);
                     }
@@ -169,7 +169,7 @@ public class CommandsForKeySerializer
                         }
                     }
                 }
-                nodeIdCount = compact(nodeIds);
+                nodeIdCount = compact(nodeIds, nodeIdCount);
                 Invariants.checkState(nodeIdCount > 0);
             }
 
@@ -679,11 +679,10 @@ public class CommandsForKeySerializer
         RedundantBefore.Entry boundsInfo = NO_BOUNDS_INFO.withEpochs(minEpoch, 
maxEpoch);
         long prevEpoch = minEpoch + VIntCoding.readVInt(in);
         long prevHlc = VIntCoding.readUnsignedVInt(in);
-        TxnId redundantBefore;
         {
             int flags = VIntCoding.readUnsignedVInt32(in);
             Node.Id node = nodeIds[VIntCoding.readUnsignedVInt32(in)];
-            redundantBefore = TxnId.fromValues(prevEpoch, prevHlc, flags, 
node);
+            boundsInfo = 
boundsInfo.withGcBeforeBeforeAtLeast(TxnId.fromValues(prevEpoch, prevHlc, 
flags, node));
         }
         int prunedBeforeIndex = VIntCoding.readUnsignedVInt32(in) - 1;
 
@@ -938,7 +937,7 @@ public class CommandsForKeySerializer
         }
         cachedTxnIds().forceDiscard(txnIds, commandCount);
 
-        return CommandsForKey.SerializerSupport.create(key, txns, unmanageds, 
redundantBefore, prunedBeforeIndex == -1 ? TxnId.NONE : 
txns[prunedBeforeIndex]);
+        return CommandsForKey.SerializerSupport.create(key, txns, unmanageds, 
prunedBeforeIndex == -1 ? TxnId.NONE : txns[prunedBeforeIndex], boundsInfo);
     }
 
     private static TxnInfo create(RedundantBefore.Entry boundsInfo, @Nonnull 
TxnId txnId, InternalStatus status, int statusOverrides, @Nonnull Timestamp 
executeAt, @Nonnull TxnId[] missing, @Nonnull Ballot ballot)
@@ -984,16 +983,16 @@ public class CommandsForKeySerializer
         return flagsLookup;
     }
 
-    private static int compact(int[] buffer)
+    private static int compact(int[] buffer, int usedSize)
     {
-        Arrays.sort(buffer);
+        Arrays.sort(buffer, 0, usedSize);
         int count = 0;
         int j = 0;
-        while (j < buffer.length)
+        while (j < usedSize)
         {
             int prev;
             buffer[count++] = prev = buffer[j];
-            while (++j < buffer.length && buffer[j] == prev) {}
+            while (++j < usedSize && buffer[j] == prev) {}
         }
         return count;
     }
@@ -1015,6 +1014,9 @@ public class CommandsForKeySerializer
 
         long read(int readCount, ByteBuffer in)
         {
+            if (readCount == 64 && bitCount == 0)
+                return in.getLong();
+
             long result = bitBuffer >>> (64 - readCount);
             int remaining = bitCount - readCount;
             if (remaining >= 0)
diff --git 
a/test/unit/org/apache/cassandra/service/accord/serializers/CommandsForKeySerializerTest.java
 
b/test/unit/org/apache/cassandra/service/accord/serializers/CommandsForKeySerializerTest.java
index 6f41f00830..ae11f3fa59 100644
--- 
a/test/unit/org/apache/cassandra/service/accord/serializers/CommandsForKeySerializerTest.java
+++ 
b/test/unit/org/apache/cassandra/service/accord/serializers/CommandsForKeySerializerTest.java
@@ -81,6 +81,7 @@ import org.apache.cassandra.simulator.RandomSource.Choices;
 import org.apache.cassandra.utils.AccordGenerators;
 import org.apache.cassandra.utils.CassandraGenerators;
 
+import static accord.local.cfk.CommandsForKey.NO_BOUNDS_INFO;
 import static accord.primitives.Status.Durability.NotDurable;
 import static accord.primitives.Known.KnownExecuteAt.ExecuteAtErased;
 import static accord.primitives.Known.KnownExecuteAt.ExecuteAtUnknown;
@@ -540,7 +541,7 @@ public class CommandsForKeySerializerTest
             }
             else unmanaged = CommandsForKey.NO_PENDING_UNMANAGED;
 
-            CommandsForKey expected = 
CommandsForKey.SerializerSupport.create(pk, info, unmanaged, TxnId.NONE, 
TxnId.NONE);
+            CommandsForKey expected = 
CommandsForKey.SerializerSupport.create(pk, info, unmanaged, TxnId.NONE, 
NO_BOUNDS_INFO);
 
             ByteBuffer buffer = 
CommandsForKeySerializer.toBytesWithoutKey(expected);
             CommandsForKey roundTrip = CommandsForKeySerializer.fromBytes(pk, 
buffer);
@@ -557,7 +558,7 @@ public class CommandsForKeySerializerTest
         TxnId txnId = TxnId.fromValues(11,34052499,2,1);
         CommandsForKey expected = CommandsForKey.SerializerSupport.create(pk,
                                                      new TxnInfo[] { 
TxnInfo.create(txnId, InternalStatus.PREACCEPTED_OR_ACCEPTED_INVALIDATE, true, 
txnId, TxnId.NO_TXNIDS, Ballot.ZERO) },
-                                                                          
CommandsForKey.NO_PENDING_UNMANAGED, TxnId.NONE, TxnId.NONE);
+                                                                          
CommandsForKey.NO_PENDING_UNMANAGED, TxnId.NONE, NO_BOUNDS_INFO);
 
         ByteBuffer buffer = 
CommandsForKeySerializer.toBytesWithoutKey(expected);
         CommandsForKey roundTrip = CommandsForKeySerializer.fromBytes(pk, 
buffer);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to