belliottsmith commented on code in PR #4362:
URL: https://github.com/apache/cassandra/pull/4362#discussion_r2321486630
##########
src/java/org/apache/cassandra/service/accord/txn/TxnUpdate.java:
##########
@@ -77,13 +92,325 @@
public class TxnUpdate extends AccordUpdate
{
- private static final long EMPTY_SIZE = ObjectSizes.measure(new
TxnUpdate(TableMetadatas.none(), null, new ByteBuffer[0], null, null,
PreserveTimestamp.no));
+ static class ConditionalBlock
+ {
+ public static final UnversionedSerializer<ConditionalBlock> serializer
= new UnversionedSerializer<>()
+ {
+ @Override
+ public void serialize(ConditionalBlock t, DataOutputPlus out)
throws IOException
+ {
+ out.writeUnsignedVInt32(t.id);
+ if (t.condition != null)
+ {
+ writeWithVIntLength(t.condition.bytes(), out);
+ }
+ else
+ {
+ out.writeUnsignedVInt32(0);
+ }
+ serializeArrayUnsignedVInt(t.fragments, out);
+ }
+
+ @Override
+ public ConditionalBlock deserialize(DataInputPlus in) throws
IOException
+ {
+ int id = in.readUnsignedVInt32();
+ ByteBuffer conditionBytes = readWithVIntLength(in);
+ SerializedTxnCondition condition = conditionBytes.remaining()
> 0
+ ? new
SerializedTxnCondition(conditionBytes)
+ : null;
+
+ // Deserialize mutations
+ int[] mutations = deserializeArrayUnsignedVInt(in);
+ return new ConditionalBlock(id, condition, mutations);
+ }
+
+ @Override
+ public void skip(DataInputPlus in) throws IOException
+ {
+ in.readUnsignedVInt32();
+ skipWithVIntLength(in);
+ skipArrayUnsignedVInt(in);
+ }
+
+ @Override
+ public long serializedSize(ConditionalBlock t)
+ {
+ long size = TypeSizes.sizeofUnsignedVInt(t.id);
+ if (t.condition != null)
+ {
+ size += serializedSizeWithVIntLength(t.condition.bytes());
+ }
+ else
+ {
+ size += TypeSizes.sizeofUnsignedVInt(0);
+ }
+ size += serializedArrayUnsignedVIntSize(t.fragments);
+ return size;
+ }
+ };
+ final int id;
+ /**
+ * If null, this block always executes (ELSE / unconditional).
+ */
+ @Nullable
+ final SerializedTxnCondition condition;
+ final int[] fragments;
+
+ ConditionalBlock(int id, @Nullable SerializedTxnCondition condition,
int[] fragments)
+ {
+ this.id = id;
+ this.condition = condition;
+ this.fragments = fragments;
+ }
+
+ public long estimatedSizeOnHeap()
+ {
+ long size = 0; //TODO (correctness): EMPTY_SIZE
+ if (condition != null)
+ size += condition.estimatedSizeOnHeap();
+ size += ObjectSizes.sizeOfArray(fragments);
+ return size;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (o == null || getClass() != o.getClass()) return false;
+ ConditionalBlock that = (ConditionalBlock) o;
+ return id == that.id && Objects.equals(condition, that.condition)
&& Arrays.equals(fragments, that.fragments);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hash(id, condition, Arrays.hashCode(fragments));
Review Comment:
do we use this hashCode, or can we throw `UnsupportedOperationException`? If
not, can we just use `id`?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]