funky-eyes commented on code in PR #7215:
URL: https://github.com/apache/incubator-seata/pull/7215#discussion_r1992504223


##########
server/src/main/java/org/apache/seata/server/filter/RaftLeaderWriteFilter.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.seata.server.filter;
+
+import org.apache.seata.common.store.SessionMode;
+import org.apache.seata.core.exception.TransactionException;
+import org.apache.seata.core.exception.TransactionExceptionCode;
+import org.apache.seata.server.cluster.listener.ClusterChangeEvent;
+import org.apache.seata.server.cluster.raft.context.SeataClusterContext;
+import org.apache.seata.server.console.exception.ConsoleException;
+import org.apache.seata.server.store.StoreConfig;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Raft Leader Write Filter
+ */
+@Component
+@Conditional(RaftCondition.class)
+public class RaftLeaderWriteFilter implements Filter, 
ApplicationListener<ClusterChangeEvent> {
+
+    private static final Map<String, Boolean> GROUP_PREVENT = new 
ConcurrentHashMap<>();
+
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException {}
+
+    @Override
+    public void doFilter(ServletRequest servletRequest, ServletResponse 
servletResponse,
+                         FilterChain filterChain) throws IOException, 
ServletException {
+        HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
+        String method = httpRequest.getMethod();
+        if (!"GET".equalsIgnoreCase(method)) {

Review Comment:
   ```suggestion
           if (!HttpMethod.GET.name().equalsIgnoreCase(method)) {
   ```



##########
server/src/main/java/org/apache/seata/server/filter/RaftLeaderWriteFilter.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.seata.server.filter;
+
+import org.apache.seata.common.store.SessionMode;
+import org.apache.seata.core.exception.TransactionException;
+import org.apache.seata.core.exception.TransactionExceptionCode;
+import org.apache.seata.server.cluster.listener.ClusterChangeEvent;
+import org.apache.seata.server.cluster.raft.context.SeataClusterContext;
+import org.apache.seata.server.console.exception.ConsoleException;
+import org.apache.seata.server.store.StoreConfig;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Raft Leader Write Filter
+ */
+@Component
+@Conditional(RaftCondition.class)
+public class RaftLeaderWriteFilter implements Filter, 
ApplicationListener<ClusterChangeEvent> {
+
+    private static final Map<String, Boolean> GROUP_PREVENT = new 
ConcurrentHashMap<>();
+
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException {}
+
+    @Override
+    public void doFilter(ServletRequest servletRequest, ServletResponse 
servletResponse,
+                         FilterChain filterChain) throws IOException, 
ServletException {
+        HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
+        String method = httpRequest.getMethod();
+        if (!"GET".equalsIgnoreCase(method)) {
+            String group = SeataClusterContext.bindGroup();
+            if (!isPass(group)) {
+                throw new ConsoleException(new 
TransactionException(TransactionExceptionCode.NotRaftLeader,

Review Comment:
   为什么是抛出异常,而不是响应某种result+状态码让namingserver能感知?
   Why throw an exception instead of responding with a result and status code 
so that the naming server can be aware?



-- 
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: notifications-unsubscr...@seata.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org
For additional commands, e-mail: notifications-h...@seata.apache.org

Reply via email to