Skip to content

Commit

Permalink
Merge pull request #6 from sharding-sphere/dev
Browse files Browse the repository at this point in the history
Synchronize origin dev branch
  • Loading branch information
KomachiSion authored Oct 10, 2018
2 parents 9e39a5e + 5ff6f9f commit 110f799
Show file tree
Hide file tree
Showing 65 changed files with 986 additions and 534 deletions.
50 changes: 27 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ Aiming at reasonably making full use of the computation and storage capacity of
As the cornerstone of many enterprises, relational database still takes a huge market share.
Therefore, at current stage, we prefer to focus on its increment instead of a total overturn.

![Sharding-Sphere Scope](http://ovfotjrsi.bkt.clouddn.com/sharding-sphere-scope_en.png)
![Sharding-Sphere Scope](http://ovfotjrsi.bkt.clouddn.com/sharding-sphere-scope_en_v2.png)

### Sharding-JDBC

[![Maven Status](https://maven-badges.herokuapp.com/maven-central/io.shardingsphere/sharding-jdbc/badge.svg)](https://mvnrepository.com/artifact/io.shardingsphere/sharding-jdbc)

Sharding-JDBC is positioned as a lightweight Java framework that provides Sharding service in the JDBC layer.
It directly connects to databases to provide services in the form of jar, with no additional deployment and dependencies, and it can be understood as an enhanced version of the JDBC driver, fully compliant with JDBC and various ORM frameworks.
Sharding-JDBC defines itself as a lightweight Java framework that provides extra service at Java JDBC layer.
With client end connecting directly to the database, it provides service in the form of jar and requires no extra deployment and dependence.
It can be considered as an enhanced JDBC driver, which is fully compatible with JDBC and all kinds of ORM frameworks.

* It is compliant with any Java-based ORM framework, such as JPA, Hibernate, Mybatis and Spring JDBC Template; or you can use JDBC directly.
* It is suitable for connection-pool based on any third party, such as DBCP, C3P0, BoneCP, Druid, HikariCP and so on.
* It supports databases implementing JDBC specification. Supporting MySQL, Oracle, SQLServer and PostgreSQL right now.
* Applicable in any ORM framework based on Java, such as JPA, Hibernate, Mybatis, Spring JDBC Template or direct use of JDBC.
* Based on any third-party database connection pool, such as DBCP, C3P0, BoneCP, Druid, HikariCP.
* Support any kind of database that conforms to JDBC standard: MySQL,Oracle,SQLServer and PostgreSQL for now.

![Sharding-JDBC Architecture](http://ovfotjrsi.bkt.clouddn.com/sharding-jdbc-brief.png)

Expand All @@ -48,32 +49,35 @@ It directly connects to databases to provide services in the form of jar, with n
[![Download](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/sharding-sphere/sharding-sphere-doc/raw/master/dist/sharding-proxy-3.0.0.M4.tar.gz)
[![Docker Pulls](https://img.shields.io/docker/pulls/shardingsphere/sharding-proxy.svg)](https://store.docker.com/community/images/shardingsphere/sharding-proxy)

Sharding-Proxy is positioned as a transparent database proxy, providing a database server that encapsulates database binary protocol to support heterogeneous languages.
At present, we provide Sharding-Proxy for MySQL, and you can use any clients compatible with MySQL protocol (such as MySQL Command Client, MySQL Workbench, etc.) to manipulate data.
Sharding-Proxy defines itself as a transparent database proxy, providing a database server that encapsulates database binary protocol to support heterogeneous languages.
Friendlier to DBA, the MySQL version provided now can use any kind of client access (such as MySQL Command Client, MySQL Workbench, etc.) that is compatible of MySQL protocol to operate data.

* It is transparent to application, which can be used as MySQL.
* It is suitable for any clients compatible with MySQL protocol.
* Totally transparent to applications, it can be used directly as MySQL.
* Applicable to any kind of compatible of client end that is compatible of MySQL protocol.

![Sharding-Proxy Architecture](http://ovfotjrsi.bkt.clouddn.com/sharding-proxy-brief_v2.png)

### Sharding-Sidecar(TBD)

It is positioned as cloud native database agent of Kubernetes or Mesos environment, in charge of all database access in the form of DaemonSet.
Through a centre-less and zero-cost solution, it provides mesh layer interacting with database. We call it `Database Mesh`.
Sharding-Sidecar (TBD) defines itself as a cloud native database agent of Kubernetes or Mesos environment, in charge of all the access to database in the form of DaemonSet.
Through a decentralized and zero-cost solution, it provides a mesh layer interacting with database, i.e., Database Mesh, also referred to as database grid.

Database Mesh emphasizes how to connect distributed data-access-layer with databases. It pays more attention to interaction, which means the messy interaction between applications and databases will be effectively orchestrated.
By using Database Mesh, applications and databases will form a large grid system, where they just need to be put into the right position accordingly. They are all governed by mesh layer.
Database Mesh emphasizes on how to connect distributed database access application with the database.
Focusing on interaction, it effectively organizes the interaction between messy applications and database.
The application and database that use Database Mesh to visit database will form a large grid system, where they just need to be put into the right position accordingly.
They are all governed by mesh layer.

![Sharding-Sidecar Architecture](http://ovfotjrsi.bkt.clouddn.com/sharding-sidecar-brief_v2.png)

| | *Sharding-JDBC* | *Sharding-Proxy* | *Sharding-Sidecar* |
| ---------------------- | --------------- | ---------------- | ------------------ |
| Database | Any | MySQL | MySQL |
| Connections Cost | More | Less | More |
| Heterogeneous Language | Java Only | Any | Any |
| Performance | Low loss | High loss | Low loss |
| Centre-less | Yes | No | No |
| Static Entry | No | Yes | No |
| | *Sharding-JDBC* | *Sharding-Proxy* | *Sharding-Sidecar* |
| ----------------------- | --------------- | -------------------- | ------------------ |
| Database | Any | MySQL | MySQL |
| Connections Cost Number | High | Low | High |
| Heterogeneous Language | Java Only | Any | Any |
| Performance | Low loss | Relatively High loss | Low loss |
| Decentralization | Yes | No | No |
| Static Entry | No | Yes | No |


## Features

Expand All @@ -98,4 +102,4 @@ By using Database Mesh, applications and databases will form a large grid system

## Roadmap

![Roadmap](http://ovfotjrsi.bkt.clouddn.com/roadmap_en_v2.png)
![Roadmap](http://ovfotjrsi.bkt.clouddn.com/roadmap_en_v3.png)
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ShardingConditions optimize() {
}
String expression;
Number currentGeneratedKey = generatedKeys.next();
if (0 == parameters.size()) {
if (parameters.isEmpty()) {
if (DefaultKeyword.VALUES.equals(insertValue.getType())) {
expression = insertValue.getExpression().substring(0, insertValue.getExpression().lastIndexOf(")")) + ", " + currentGeneratedKey.toString() + ")";
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import lombok.Setter;

/**
* Proxy authority.
* Authentication.
*
* @author panjuan
*/
@NoArgsConstructor
@Getter
@Setter
public final class ProxyAuthority {
public final class Authentication {

private String username;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package io.shardingsphere.core.yaml.other;

import io.shardingsphere.core.rule.ProxyAuthority;
import io.shardingsphere.core.rule.Authentication;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -32,7 +32,7 @@
@Setter
public final class YamlServerConfiguration {

private ProxyAuthority proxyAuthority = new ProxyAuthority();
private Authentication authentication = new Authentication();

private Properties props = new Properties();
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public MasterSlaveStatement(final MasterSlaveConnection connection, final int re

@Override
public ResultSet executeQuery(final String sql) throws SQLException {
clearPrevious();
Collection<String> dataSourceNames = masterSlaveRouter.route(sql);
Preconditions.checkState(1 == dataSourceNames.size(), "Cannot support executeQuery for DML or DDL");
Statement statement = connection.getConnection(dataSourceNames.iterator().next()).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
Expand All @@ -80,6 +81,7 @@ public ResultSet executeQuery(final String sql) throws SQLException {

@Override
public int executeUpdate(final String sql) throws SQLException {
clearPrevious();
int result = 0;
for (String each : masterSlaveRouter.route(sql)) {
Statement statement = connection.getConnection(each).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
Expand All @@ -91,6 +93,7 @@ public int executeUpdate(final String sql) throws SQLException {

@Override
public int executeUpdate(final String sql, final int autoGeneratedKeys) throws SQLException {
clearPrevious();
int result = 0;
for (String each : masterSlaveRouter.route(sql)) {
Statement statement = connection.getConnection(each).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
Expand All @@ -102,6 +105,7 @@ public int executeUpdate(final String sql, final int autoGeneratedKeys) throws S

@Override
public int executeUpdate(final String sql, final int[] columnIndexes) throws SQLException {
clearPrevious();
int result = 0;
for (String each : masterSlaveRouter.route(sql)) {
Statement statement = connection.getConnection(each).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
Expand All @@ -113,6 +117,7 @@ public int executeUpdate(final String sql, final int[] columnIndexes) throws SQL

@Override
public int executeUpdate(final String sql, final String[] columnNames) throws SQLException {
clearPrevious();
int result = 0;
for (String each : masterSlaveRouter.route(sql)) {
Statement statement = connection.getConnection(each).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
Expand All @@ -124,6 +129,7 @@ public int executeUpdate(final String sql, final String[] columnNames) throws SQ

@Override
public boolean execute(final String sql) throws SQLException {
clearPrevious();
boolean result = false;
for (String each : masterSlaveRouter.route(sql)) {
Statement statement = connection.getConnection(each).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
Expand All @@ -135,6 +141,7 @@ public boolean execute(final String sql) throws SQLException {

@Override
public boolean execute(final String sql, final int autoGeneratedKeys) throws SQLException {
clearPrevious();
boolean result = false;
for (String each : masterSlaveRouter.route(sql)) {
Statement statement = connection.getConnection(each).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
Expand All @@ -146,6 +153,7 @@ public boolean execute(final String sql, final int autoGeneratedKeys) throws SQL

@Override
public boolean execute(final String sql, final int[] columnIndexes) throws SQLException {
clearPrevious();
boolean result = false;
for (String each : masterSlaveRouter.route(sql)) {
Statement statement = connection.getConnection(each).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
Expand All @@ -157,6 +165,7 @@ public boolean execute(final String sql, final int[] columnIndexes) throws SQLEx

@Override
public boolean execute(final String sql, final String[] columnNames) throws SQLException {
clearPrevious();
boolean result = false;
for (String each : masterSlaveRouter.route(sql)) {
Statement statement = connection.getConnection(each).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
Expand All @@ -177,4 +186,11 @@ public ResultSet getResultSet() throws SQLException {
Preconditions.checkState(1 == routedStatements.size());
return routedStatements.iterator().next().getResultSet();
}

private void clearPrevious() throws SQLException {
for (Statement each : routedStatements) {
each.close();
}
routedStatements.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ private void setSQLType(final SQLType sqlType) {
field.set(actual, sqlType);
}


private void setExecuteGroups(final List<PreparedStatement> preparedStatements) {
Collection<ShardingExecuteGroup<StatementExecuteUnit>> executeGroups = new LinkedList<>();
List<StatementExecuteUnit> preparedStatementExecuteUnits = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void assertNoStatement() throws SQLException {
}

@Test
public void assertExecuteQueryForSinglePreparedStatementSuccess() throws SQLException{
public void assertExecuteQueryForSinglePreparedStatementSuccess() throws SQLException {
PreparedStatement preparedStatement = getPreparedStatement();
ResultSet resultSet = mock(ResultSet.class);
when(resultSet.getInt(1)).thenReturn(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<assertion expected-data-file="insert_for_order_1_2.xml" />
</dml-test-case>

<dml-test-case sql-case-id="insert_on_duplicate_key_update">
<assertion parameters="1000:int, 10:int, update:String" expected-data-file="update.xml" />
</dml-test-case>

<!-- TODO fixme -->
<!--<dml-test-case sql-case-id="insert_with_all_placeholders_for_table_identifier">-->
<!--<assertion parameters="1:int, 1:int, insert:String" expected-data-file="insert_for_order_1.xml" />-->
Expand Down Expand Up @@ -70,14 +74,13 @@
<!--<assertion parameters="1:int, 1:int" expected-data-file="insert_with_generate_key_column.xml" />-->
</dml-test-case>

<!-- TODO parse generator context for insert set -->
<!--<dml-test-case sql-case-id="insert_without_generate_key_column">-->
<!--<assertion parameters="1:int, 1:int" expected-data-file="insert_without_generate_key_column.xml" />-->
<!--</dml-test-case>-->
<!---->
<!--<dml-test-case sql-case-id="insert_set_without_generate_key_column">-->
<!--<assertion parameters="1:int, 1:int" expected-data-file="insert_without_generate_key_column.xml" />-->
<!--</dml-test-case>-->
<dml-test-case sql-case-id="insert_without_generate_key_column">
<assertion parameters="1:int, 1:int" expected-data-file="insert_without_generate_key_column.xml" />
</dml-test-case>

<dml-test-case sql-case-id="insert_set_without_generate_key_column">
<assertion parameters="1:int, 1:int" expected-data-file="insert_without_generate_key_column.xml" />
</dml-test-case>

<dml-test-case sql-case-id="insert_with_batch">
<assertion parameters="1:int, 1:int, insert:String, 2:int, 2:int, insert:String" expected-data-file="batch_insert_for_order.xml" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public Map<String, YamlRuleConfiguration> loadProxyConfiguration() {
public YamlServerConfiguration loadYamlServerConfiguration() {
try {
YamlServerConfiguration result = ProxyConfigurationConverter.proxyServerConfigFromYaml(regCenter.getDirectly(configNode.getFullPath(ConfigurationNode.PROXY_SERVER_CONFIG_NODE_PATH)));
Preconditions.checkState(!Strings.isNullOrEmpty(result.getProxyAuthority().getUsername()), "Authority configuration is invalid.");
Preconditions.checkState(!Strings.isNullOrEmpty(result.getAuthentication().getUsername()), "Authority configuration is invalid.");
return result;
// CHECKSTYLE:OFF
} catch (final Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package io.shardingsphere.orchestration.internal.yaml.converter;

import io.shardingsphere.core.rule.DataSourceParameter;
import io.shardingsphere.orchestration.internal.yaml.representer.DefaultConfigurationRepresenter;
import io.shardingsphere.orchestration.internal.yaml.representer.DataSourceParameterRepresenter;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.yaml.snakeyaml.Yaml;
Expand All @@ -33,7 +33,7 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DataSourceParameterConverter {

private static final Yaml YAML = new Yaml(new DefaultConfigurationRepresenter());
private static final Yaml YAML = new Yaml(new DataSourceParameterRepresenter());

/**
* Convert schema data source parameter map to Yaml string.
Expand Down
Loading

0 comments on commit 110f799

Please sign in to comment.