ekaterinadimitrova2 commented on code in PR #2807:
URL: https://github.com/apache/cassandra/pull/2807#discussion_r1375092644


##########
src/java/org/apache/cassandra/schema/SchemaTransformation.java:
##########
@@ -17,20 +17,76 @@
  */
 package org.apache.cassandra.schema;
 
+import java.io.IOException;
 import java.util.Optional;
 
+import org.apache.cassandra.cql3.CQLStatement;
+import org.apache.cassandra.cql3.QueryProcessor;
+import org.apache.cassandra.db.TypeSizes;
+import org.apache.cassandra.io.util.DataInputPlus;
+import org.apache.cassandra.io.util.DataOutputPlus;
+import org.apache.cassandra.tcm.serialization.MetadataSerializer;
+import org.apache.cassandra.tcm.serialization.Version;
+import org.apache.cassandra.service.ClientState;
+import org.apache.cassandra.tcm.ClusterMetadata;
+
 public interface SchemaTransformation
 {
+    SchemaTransformationSerializer serializer = new 
SchemaTransformationSerializer();
+
     /**
      * Apply a statement transformation to a schema snapshot.
      * <p>
-     * Implementing methods should be side-effect free (outside of throwing 
exceptions if the transformation cannot
+     * Implementing methods should be side effect free (outside of throwing 
exceptions if the transformation cannot
      * be successfully applied to the provided schema).
      *
-     * @param schema Keyspaces to base the transformation on
+     * @param metadata Cluster metadata representing the current state, 
including the DistributedSchema with the
+     *                 Keyspaces to base the transformation on
      * @return Keyspaces transformed by the statement
      */
-    Keyspaces apply(Keyspaces schema);
+    Keyspaces apply(ClusterMetadata metadata);
+
+    default String cql()
+    {
+        return "null";
+    }
+
+    /**
+     * SchemaTransformation::apply should be side effect free, as it may be 
called repeatedly for any given
+     * transformation.
+     * <ul>
+     *   <li>On receiving a CQL DDL statement, the coordinator pre-emptively 
applies it using its own current cluster
+     *   metadata for validation. The result of this transformation is 
discarded and the coordinator submits to the CMS.
+     *   </li>
+     *   <li>A CMS member, receiving a Commit containing an AlterSchema, 
applies the enclosed SchemaTransformation before
+     *   committing to the metadata log. There may be multiple attempts to 
commit, and so multiple applications, if
+     *   there is contention on the metadata log.
+     *   </li>
+     *   <li>Following commit, all peers should receive the committed log 
entry and they will then execute the AlterSchema,
+     *   applying the SchemaTransformation locally. The result of this 
application then becomes the current published
+     *   cluster metadata for the peer.
+     *   </li>
+     * </ul>
+     * At the moment, not all SchemaTransformation are entirely free of side 
effects, because both client warnings and
+     * guardrails are tightly coupled to the ST implementations and they do 
produce side effects. Ideally, ClientWarn
+     * and Guardrails can be reworked to decouple them from ClientState and 
threadlocals. In the meantime, we can hint
+     * to them that SchemaTransformation::apply is being called in the context 
of AlterSchema::execute and so they
+     * should not produce their side effects. The default impl is a no-op, but 
AlterSchemaStatement which has access to
+     * a ClientState, is able to pause both warnings and guardrails.
+     * @see 
org.apache.cassandra.cql3.statements.schema.AlterSchemaStatement#enterExecution()

Review Comment:
   What are the side effects you mean here, except duplicate warnings?
   I saw the 
`org.apache.cassandra.cql3.statements.schema.AlterSchemaStatement#enterExecution()`
 method. 



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