josh-mckenzie commented on code in PR #1954:
URL: https://github.com/apache/cassandra/pull/1954#discussion_r1041248090


##########
src/java/org/apache/cassandra/db/Mutation.java:
##########
@@ -393,34 +411,115 @@ public static class MutationSerializer implements 
IVersionedSerializer<Mutation>
     {
         public void serialize(Mutation mutation, DataOutputPlus out, int 
version) throws IOException
         {
+            serialization(mutation, 
version).serialize(PartitionUpdate.serializer, mutation, out, version);
+        }
+
+        /**
+         * Called early during request processing to prevent that {@link 
#serialization(Mutation, int)} is
+         * called concurrently.
+         * See {@link 
org.apache.cassandra.service.StorageProxy#sendToHintedReplicas(Mutation, 
ReplicaPlan.ForWrite, AbstractWriteResponseHandler, String, Stage)}
+         */
+        @SuppressWarnings("JavadocReference")
+        public void prepareSerializedBuffer(Mutation mutation, int version)
+        {
+            serialization(mutation, version);
+        }
+
+        /**
+         * Retrieve the cached serialization of this mutation, or compute and 
cache said serialization if it doesn't
+         * exist yet. Note that this method is _not_ synchronized even though 
it may (and will often) be called
+         * concurrently. Concurrent calls are still safe however, the only 
risk is that the value is not cached yet,
+         * multiple concurrent calls may compute it multiple times instead of 
just once. This is ok as in practice
+         * as we make sure this doesn't happen in the hot path by forcing the 
initial caching in
+         * {@link 
org.apache.cassandra.service.StorageProxy#sendToHintedReplicas(Mutation, 
ReplicaPlan.ForWrite, AbstractWriteResponseHandler, String, Stage)}
+         * via {@link #prepareSerializedBuffer(Mutation)}, which is the only 
caller that passes
+         * {@code isPrepare==true}.
+         */
+        @SuppressWarnings("JavadocReference")
+        private Serialization serialization(Mutation mutation, int version)
+        {
+            int versionOrdinal = MessagingService.getVersionOrdinal(version);
+            // Retrieves the cached version, or build+cache it if it's not 
cached already.
+            Serialization serialization = 
mutation.cachedSerializations[versionOrdinal];
+            if (serialization == null)
+            {
+                serialization = new SizeOnlyCacheableSerialization();
+                long sertializedSize = 
serialization.serializedSize(PartitionUpdate.serializer, mutation, version);

Review Comment:
   nit: spelling. Should be "serializedSize"



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

Reply via email to