未验证 提交 738972ba 编写于 作者: ShardingSphere's avatar ShardingSphere 提交者: GitHub

Merge pull request #820 from tuohai666/dev

Robustness for sharding-proxy
......@@ -10,16 +10,12 @@
</parent>
<artifactId>sharding-proxy</artifactId>
<name>${project.artifactId}</name>
<properties>
<sharding-jdbc.version>2.1.0-SNAPSHOT</sharding-jdbc.version>
</properties>
<dependencies>
<dependency>
<groupId>io.shardingsphere</groupId>
<artifactId>sharding-jdbc-orchestration</artifactId>
<version>${sharding-jdbc.version}</version>
<artifactId>sharding-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
......
......@@ -17,6 +17,7 @@
package io.shardingsphere.proxy;
import io.shardingsphere.proxy.config.RuleRegistry;
import io.shardingsphere.proxy.frontend.ShardingProxy;
/**
......@@ -35,6 +36,7 @@ public final class Bootstrap {
* @throws InterruptedException interrupted exception
*/
public static void main(final String[] args) throws InterruptedException {
initializeRuleRegistry();
new ShardingProxy().start(getPort(args));
}
......@@ -48,4 +50,8 @@ public final class Bootstrap {
return DEFAULT_PORT;
}
}
private static void initializeRuleRegistry() {
RuleRegistry.getInstance();
}
}
......@@ -19,6 +19,7 @@ package io.shardingsphere.proxy.backend.common;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.constant.SQLType;
import io.shardingsphere.core.exception.ShardingException;
import io.shardingsphere.core.merger.MergeEngineFactory;
import io.shardingsphere.core.merger.MergedResult;
import io.shardingsphere.core.merger.QueryResult;
......@@ -96,7 +97,15 @@ public final class SQLExecuteBackendHandler implements BackendHandler {
@Override
public CommandResponsePackets execute() {
return RuleRegistry.getInstance().isOnlyMasterSlave() ? executeForMasterSlave() : executeForSharding();
try {
if (RuleRegistry.getInstance().isOnlyMasterSlave()) {
return executeForMasterSlave();
} else {
return executeForSharding();
}
} catch (final ShardingException ex) {
return new CommandResponsePackets(new ErrPacket(1, 0, "", "", ex.getMessage()));
}
}
private CommandResponsePackets executeForMasterSlave() {
......
......@@ -19,6 +19,7 @@ package io.shardingsphere.proxy.backend.common;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.constant.SQLType;
import io.shardingsphere.core.exception.ShardingException;
import io.shardingsphere.core.merger.MergeEngineFactory;
import io.shardingsphere.core.merger.MergedResult;
import io.shardingsphere.core.merger.QueryResult;
......@@ -104,7 +105,15 @@ public final class StatementExecuteBackendHandler implements BackendHandler {
@Override
public CommandResponsePackets execute() {
return RuleRegistry.getInstance().isOnlyMasterSlave() ? executeForMasterSlave() : executeForSharding();
try {
if (RuleRegistry.getInstance().isOnlyMasterSlave()) {
return executeForMasterSlave();
} else {
return executeForSharding();
}
} catch (final ShardingException ex) {
return new CommandResponsePackets(new ErrPacket(1, 0, "", "", ex.getMessage()));
}
}
private CommandResponsePackets executeForMasterSlave() {
......
......@@ -24,7 +24,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
RandomGeneratorTest.class,
RandomGeneratorTest.class,
})
public class AllTests {
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册