You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/11/01 05:07:21 UTC

[GitHub] [shardingsphere] lanchengx opened a new pull request #13376: Add DistSQL to set Proxy props.

lanchengx opened a new pull request #13376:
URL: https://github.com/apache/shardingsphere/pull/13376


   For https://github.com/apache/shardingsphere/issues/13207
   
   Changes proposed in this pull request:
   - `set variable statement` supports configuration property
   - Add tests.
   - Improve documentation.
   


-- 
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-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] menghaoranss commented on pull request #13376: Add DistSQL to set Proxy props.

Posted by GitBox <gi...@apache.org>.
menghaoranss commented on pull request #13376:
URL: https://github.com/apache/shardingsphere/pull/13376#issuecomment-955999413


   @lanchengx CI build failed.
   


-- 
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-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] RaigorJiang commented on a change in pull request #13376: Add DistSQL to set Proxy props.

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on a change in pull request #13376:
URL: https://github.com/apache/shardingsphere/pull/13376#discussion_r740005729



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetVariableExecutor.java
##########
@@ -41,20 +51,57 @@
     
     @Override
     public ResponseHeader execute() {
-        SetVariableStatement setVariableStatement = sqlStatement;
-        VariableEnum variable = VariableEnum.getValueOf(setVariableStatement.getName());
+        Enum type = getType(sqlStatement.getName());
+        if (type instanceof ConfigurationPropertyKey) {
+            handleConfigurationProperty((ConfigurationPropertyKey) type, sqlStatement.getValue());
+        } else if (type instanceof VariableEnum) {
+            handleVariables(sqlStatement);
+        } else {
+            throw new UnsupportedVariableException(sqlStatement.getName());
+        }
+        return new UpdateResponseHeader(sqlStatement);
+    }
+    
+    private Enum getType(final String name) {
+        try {
+            return ConfigurationPropertyKey.valueOf(name.toUpperCase());
+        } catch (IllegalArgumentException e) {
+            return VariableEnum.getValueOf(name);
+        }
+    }
+    
+    private void handleConfigurationProperty(final ConfigurationPropertyKey propertyKey, final String value) {
+        MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
+        Optional<MetaDataPersistService> metaDataPersistService = metaDataContexts.getMetaDataPersistService();
+        Properties props = metaDataContexts.getProps().getProps();
+        props.put(propertyKey.getKey(), getValue(propertyKey, value));
+        if (metaDataPersistService.isPresent() && null != metaDataPersistService.get().getPropsService()) {
+            metaDataPersistService.get().getPropsService().persist(props, true);
+        }
+    }
+    
+    private Object getValue(final ConfigurationPropertyKey propertyKey, final String value) {
+        try {
+            TypedPropertyValue propertyValue = new TypedPropertyValue(propertyKey, value);
+            return propertyValue.getValue();
+        } catch (TypedPropertyValueException e) {
+            throw new InvalidValueException(value);
+        }
+    }
+    
+    private void handleVariables(final SetVariableStatement statement) {

Review comment:
       The variable name `statement` represents a lot of meaning, can it be more precise?




-- 
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-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] RaigorJiang commented on a change in pull request #13376: Add DistSQL to set Proxy props.

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on a change in pull request #13376:
URL: https://github.com/apache/shardingsphere/pull/13376#discussion_r740007836



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetVariableExecutor.java
##########
@@ -41,20 +51,57 @@
     
     @Override
     public ResponseHeader execute() {
-        SetVariableStatement setVariableStatement = sqlStatement;
-        VariableEnum variable = VariableEnum.getValueOf(setVariableStatement.getName());
+        Enum type = getType(sqlStatement.getName());
+        if (type instanceof ConfigurationPropertyKey) {
+            handleConfigurationProperty((ConfigurationPropertyKey) type, sqlStatement.getValue());
+        } else if (type instanceof VariableEnum) {
+            handleVariables(sqlStatement);
+        } else {
+            throw new UnsupportedVariableException(sqlStatement.getName());
+        }
+        return new UpdateResponseHeader(sqlStatement);
+    }
+    
+    private Enum getType(final String name) {
+        try {
+            return ConfigurationPropertyKey.valueOf(name.toUpperCase());
+        } catch (IllegalArgumentException e) {
+            return VariableEnum.getValueOf(name);
+        }
+    }
+    
+    private void handleConfigurationProperty(final ConfigurationPropertyKey propertyKey, final String value) {
+        MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
+        Optional<MetaDataPersistService> metaDataPersistService = metaDataContexts.getMetaDataPersistService();
+        Properties props = metaDataContexts.getProps().getProps();
+        props.put(propertyKey.getKey(), getValue(propertyKey, value));
+        if (metaDataPersistService.isPresent() && null != metaDataPersistService.get().getPropsService()) {
+            metaDataPersistService.get().getPropsService().persist(props, true);
+        }
+    }
+    
+    private Object getValue(final ConfigurationPropertyKey propertyKey, final String value) {
+        try {
+            TypedPropertyValue propertyValue = new TypedPropertyValue(propertyKey, value);
+            return propertyValue.getValue();
+        } catch (TypedPropertyValueException e) {

Review comment:
       ex is better.




-- 
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-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] RaigorJiang merged pull request #13376: Add DistSQL to set Proxy props.

Posted by GitBox <gi...@apache.org>.
RaigorJiang merged pull request #13376:
URL: https://github.com/apache/shardingsphere/pull/13376


   


-- 
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-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] lanchengx commented on a change in pull request #13376: Add DistSQL to set Proxy props.

Posted by GitBox <gi...@apache.org>.
lanchengx commented on a change in pull request #13376:
URL: https://github.com/apache/shardingsphere/pull/13376#discussion_r739983465



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/executor/SetVariableExecutorTest.java
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.text.distsql.ral.common.set.executor;
+
+import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetVariableStatement;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.TransactionStatus;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.enums.VariableEnum;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetVariableExecutor;
+import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class SetVariableExecutorTest {
+    
+    @Test
+    public void assertExecuteWithTransactionType() {
+        SetVariableStatement statement = new SetVariableStatement("transaction_type", "local");
+        BackendConnection connection = mock(BackendConnection.class);
+        when(connection.getTransactionStatus()).thenReturn(new TransactionStatus(TransactionType.XA));
+        new SetVariableExecutor(statement, connection).execute();
+        Assert.assertEquals(TransactionType.LOCAL.name(), connection.getTransactionStatus().getTransactionType().name());

Review comment:
       thanks, I have corrected it




-- 
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-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] lanchengx commented on pull request #13376: Add DistSQL to set Proxy props.

Posted by GitBox <gi...@apache.org>.
lanchengx commented on pull request #13376:
URL: https://github.com/apache/shardingsphere/pull/13376#issuecomment-956002686


   > @lanchengx CI build failed.
   
   I have corrected it


-- 
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-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] TeslaCN commented on a change in pull request #13376: Add DistSQL to set Proxy props.

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on a change in pull request #13376:
URL: https://github.com/apache/shardingsphere/pull/13376#discussion_r739969418



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/executor/SetVariableExecutorTest.java
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.text.distsql.ral.common.set.executor;
+
+import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetVariableStatement;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.TransactionStatus;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.enums.VariableEnum;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetVariableExecutor;
+import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class SetVariableExecutorTest {
+    
+    @Test
+    public void assertExecuteWithTransactionType() {
+        SetVariableStatement statement = new SetVariableStatement("transaction_type", "local");
+        BackendConnection connection = mock(BackendConnection.class);
+        when(connection.getTransactionStatus()).thenReturn(new TransactionStatus(TransactionType.XA));
+        new SetVariableExecutor(statement, connection).execute();
+        Assert.assertEquals(TransactionType.LOCAL.name(), connection.getTransactionStatus().getTransactionType().name());

Review comment:
       Consider using `assertThat` here and below.




-- 
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-unsubscribe@shardingsphere.apache.org

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