ifesdjeen commented on code in PR #4068:
URL: https://github.com/apache/cassandra/pull/4068#discussion_r2037308971


##########
src/java/org/apache/cassandra/service/accord/AccordKeyspace.java:
##########
@@ -546,60 +541,38 @@ private static ByteBuffer cellValue(Row row, 
ColumnMetadata column)
 
     public static class JournalColumns
     {
-        static final ClusteringComparator keyComparator = 
Journal.partitionKeyAsClusteringComparator();
-        static final CompositeType partitionKeyType = (CompositeType) 
Journal.partitionKeyType;
-        public static final ColumnMetadata store_id = getColumn(Journal, 
"store_id");
-        public static final ColumnMetadata type = getColumn(Journal, "type");
-        public static final ColumnMetadata id = getColumn(Journal, "id");
+        public static final ColumnMetadata key = getColumn(Journal, "key");
         public static final ColumnMetadata record = getColumn(Journal, 
"record");
         public static final ColumnMetadata user_version = getColumn(Journal, 
"user_version");
         public static final RegularAndStaticColumns regular = new 
RegularAndStaticColumns(Columns.NONE, Columns.from(Arrays.asList(record, 
user_version)));
 
         public static DecoratedKey decorate(JournalKey key)
         {
-            ByteBuffer id = 
ByteBuffer.allocate(CommandSerializers.txnId.serializedSize());
-            CommandSerializers.txnId.serialize(key.id, id);
-            id.flip();
-            ByteBuffer pk = keyComparator.make(key.commandStoreId, 
(byte)key.type.id, id).serializeAsPartitionKey();
-            Invariants.require(getTxnId(splitPartitionKey(pk)).equals(key.id));
+            int commandStoreIdBytes = 
VIntCoding.computeUnsignedVIntSize(key.commandStoreId);
+            int length = commandStoreIdBytes + 1;
+            if (key.type == JournalKey.Type.COMMAND_DIFF)
+                length += CommandSerializers.txnId.serializedSize(key.id);
+            ByteBuffer pk = ByteBuffer.allocate(length);
+            ByteBufferAccessor.instance.putUnsignedVInt32(pk, 0, 
key.commandStoreId);
+            pk.put(commandStoreIdBytes, (byte)key.type.id);
+            if (key.type == JournalKey.Type.COMMAND_DIFF)
+                CommandSerializers.txnId.serializeComparable(key.id, pk, 
ByteBufferAccessor.instance, commandStoreIdBytes + 1);
             return Journal.partitioner.decorateKey(pk);
         }
 
-        public static ByteBuffer[] splitPartitionKey(DecoratedKey key)
-        {
-            return JournalColumns.partitionKeyType.split(key.getKey());
-        }
-
-        public static ByteBuffer[] splitPartitionKey(ByteBuffer key)
-        {
-            return JournalColumns.partitionKeyType.split(key);
-        }
-
         public static int getStoreId(DecoratedKey pk)
         {
-            return getStoreId(splitPartitionKey(pk));
-        }
-
-        public static int getStoreId(ByteBuffer[] partitionKeyComponents)
-        {
-            return 
Int32Type.instance.compose(partitionKeyComponents[store_id.position()]);
-        }
-
-        public static JournalKey.Type getType(ByteBuffer[] 
partitionKeyComponents)
-        {
-            return 
JournalKey.Type.fromId(ByteType.instance.compose(partitionKeyComponents[type.position()]));
-        }
-
-        public static TxnId getTxnId(ByteBuffer[] partitionKeyComponents)
-        {
-            ByteBuffer buffer = partitionKeyComponents[id.position()];
-            return CommandSerializers.txnId.deserialize(buffer, 
buffer.position());
+            return VIntCoding.readUnsignedVInt32(pk.getKey(), 0);
         }
 
         public static JournalKey getJournalKey(DecoratedKey key)
         {
-            ByteBuffer[] parts = splitPartitionKey(key);
-            return new JournalKey(getTxnId(parts), getType(parts), 
getStoreId(parts));
+            ByteBuffer bb = key.getKey();
+            int storeId = ByteBufferAccessor.instance.getUnsignedVInt32(bb, 0);
+            int offset = VIntCoding.readLengthOfVInt(bb, 0);
+            JournalKey.Type type = JournalKey.Type.fromId(bb.get(offset));
+            TxnId txnId = type != JournalKey.Type.COMMAND_DIFF ? TxnId.NONE : 
CommandSerializers.txnId.deserializeComparable(bb, ByteBufferAccessor.instance, 
offset + 1);

Review Comment:
   Ah, sure: I did not mean to switch it to variable width; only that we might 
want to avoid de-serializing txn id there too just like here.



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

Reply via email to