Pace2Car commented on code in PR #24441:
URL: https://github.com/apache/shardingsphere/pull/24441#discussion_r1126039097


##########
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/impl/ReadOnlyProxyState.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.shardingsphere.proxy.backend.state.impl;
+
+import org.apache.shardingsphere.proxy.backend.exception.ReadOnlyException;
+import org.apache.shardingsphere.proxy.backend.state.spi.ProxyClusterState;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ShowStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowDatabasesStatement;
+
+/**
+ * ReadOnly proxy state.
+ */
+public final class ReadOnlyProxyState implements ProxyClusterState {
+    
+    @Override
+    public void check(final SQLStatement sqlStatement) {
+        if (isWriteStatement(sqlStatement)) {
+            throw new ReadOnlyException();
+        }
+    }
+    
+    private boolean isWriteStatement(final SQLStatement sqlStatement) {
+        return !(sqlStatement instanceof SelectStatement) && !(sqlStatement 
instanceof ShowStatement) && !(sqlStatement instanceof 
MySQLShowDatabasesStatement);

Review Comment:
   Thanks for point out, I have fixed.



##########
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/impl/UnavailableProxyState.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.shardingsphere.proxy.backend.state.impl;
+
+import org.apache.shardingsphere.distsql.parser.statement.ral.RALStatement;
+import org.apache.shardingsphere.proxy.backend.exception.UnavailableException;
+import org.apache.shardingsphere.proxy.backend.state.spi.ProxyClusterState;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DDLStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement;
+
+/**
+ * Unavailable proxy state.
+ */
+public final class UnavailableProxyState implements ProxyClusterState {
+    
+    @Override
+    public void check(final SQLStatement sqlStatement) {
+        if (isUnsupportedStatement(sqlStatement)) {
+            throw new UnavailableException();
+        }
+    }
+    
+    private boolean isUnsupportedStatement(final SQLStatement sqlStatement) {
+        return sqlStatement instanceof DMLStatement || sqlStatement instanceof 
DDLStatement || sqlStatement instanceof RALStatement;

Review Comment:
   Thanks for point out, I have fixed.



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

Reply via email to