szetszwo commented on code in PR #10013:
URL: https://github.com/apache/ozone/pull/10013#discussion_r3033572180


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMHAInvocationHandler.java:
##########
@@ -86,10 +88,8 @@ private Object invokeLocal(Method method, Object[] args)
       LOG.trace("Invoking method {} on target {} with arguments {}",
           method, localHandler, args);
     }
+    Preconditions.assertNull(invoker, "invoker");

Review Comment:
   The `invoker` field is always null.  We should remove it.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/invoker/DeletedBlockLogStateManagerInvoker.java:
##########
@@ -49,6 +53,76 @@ public DeletedBlockLogStateManager getImpl() {
     return impl;
   }
 
+  @Override
+  protected Class<?>[] getParameterTypes(String methodName) {

Review Comment:
   Let's add an enum instead:
   ```java
     enum ReplicateMethod implements NameAndParameterTypes {
       addTransactionsToDB(new Class<?>[] {ArrayList.class, 
DeletedBlocksTransactionSummary.class}),
       removeTransactionsFromDB(new Class<?>[] {ArrayList.class, 
DeletedBlocksTransactionSummary.class}),
       ;
   
       private final Class<?>[][] parameterTypes;
   
       ReplicateMethod(Class<?>[] parameterTypes) {
         final Class<?>[][] types = new Class<?>[parameterTypes.length + 1][];
         for(int i = 0; i <= parameterTypes.length; ++i) {
           types[i] = Arrays.copyOf(parameterTypes, i);
         }
         this.parameterTypes = types;
       }
   
       @Override
       public String getName() {
         return name();
       }
   
       @Override
       public Class<?>[] getParameterTypes(int numArgs) {
         return parameterTypes[numArgs];
       }
     }
   ```



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMRatisServer.java:
##########
@@ -82,6 +83,9 @@ default <T> T getProxyHandler(ScmInvoker<T> invoker) {
   default <T> T getProxyHandler(RequestType type, Class<T> intf, T impl, 
ScmInvoker<T> invoker) {
     final SCMHAInvocationHandler invocationHandler =
         new SCMHAInvocationHandler(type, impl, invoker, this);
+    if (invoker != null) {
+      return invoker.getProxy();
+    }

Review Comment:
   We don't need the common method anymore.
   ```java
     default <T> T getProxyHandler(ScmInvoker<T> invoker) {
       registerStateMachineHandler(invoker.getType(), invoker.getImpl());
       return invoker.getProxy();
     }
   
     default <T> T getProxyHandler(RequestType type, Class<T> intf, T impl) {
       final SCMHAInvocationHandler invocationHandler =
           new SCMHAInvocationHandler(type, impl, this);
       return intf.cast(Proxy.newProxyInstance(getClass().getClassLoader(),
           new Class<?>[] {intf}, invocationHandler));
     }
   ```



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/invoker/ScmInvoker.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdds.scm.ha.invoker;
+
+import static 
org.apache.hadoop.hdds.scm.ha.SCMHAInvocationHandler.translateException;
+
+import org.apache.hadoop.hdds.protocol.proto.SCMRatisProtocol.RequestType;
+import org.apache.hadoop.hdds.scm.exceptions.SCMException;
+import org.apache.hadoop.hdds.scm.ha.SCMRatisRequest;
+import org.apache.hadoop.hdds.scm.ha.SCMRatisResponse;
+import org.apache.hadoop.hdds.scm.ha.SCMRatisServer;
+
+/**
+ * Invokes methods without using reflection.
+ */
+public abstract class ScmInvoker<T> {
+  static final Object[] NO_ARGS = {};
+
+  private final SCMRatisServer ratisHandler;
+
+  ScmInvoker(SCMRatisServer ratisHandler) {
+    this.ratisHandler = ratisHandler;
+  }
+
+  public abstract RequestType getType();
+
+  public abstract Class<T> getApi();
+
+  public abstract T getImpl();
+
+  public abstract T getProxy();
+
+  abstract Class<?>[] getParameterTypes(String methodName);
+
+  abstract Object invokeLocal(String methodName, Object[] args) throws 
Exception;
+
+  Object invokeRatisServer(String methodName, Class<?>[] paramTypes,
+          Object[] args) throws SCMException {

Review Comment:
   Let's add an interface:
   ```java
     interface NameAndParameterTypes {
       String getName();
   
       Class<?>[] getParameterTypes(int numArgs);
     }
   ```
   ```java
     Object invokeRatisServer(NameAndParameterTypes method, Object[] args) 
throws SCMException {
       try {
         final SCMRatisRequest request = SCMRatisRequest.of(
             getType(), method.getName(), 
method.getParameterTypes(args.length), args);
   ```
   



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