Loading sharding-proxy/src/main/resources/conf/config.yaml +68 −68 Original line number Diff line number Diff line Loading @@ -9,71 +9,71 @@ # The example of Sharding rule. #dataSources: # ds_0: # url: jdbc:mysql://127.0.0.1:3306/ds_0?serverTimezone=UTC&useSSL=false # username: root # password: # autoCommit: true # connectionTimeout: 30000 # idleTimeout: 60000 # maxLifetime: 1800000 # maximumPoolSize: 65 # ds_1: # url: jdbc:mysql://127.0.0.1:3306/ds_1?serverTimezone=UTC&useSSL=false # username: root # password: # autoCommit: true # connectionTimeout: 30000 # idleTimeout: 60000 # maxLifetime: 1800000 # maximumPoolSize: 65 # #shardingRule: # tables: # t_order: # actualDataNodes: ds_${0..1}.t_order_${0..1} # tableStrategy: # inline: # shardingColumn: order_id # algorithmExpression: t_order_${order_id % 2} # keyGeneratorColumnName: order_id # t_order_item: # actualDataNodes: ds_${0..1}.t_order_item_${0..1} # tableStrategy: # inline: # shardingColumn: order_id # algorithmExpression: t_order_item_${order_id % 2} # bindingTables: # - t_order,t_order_item # defaultDatabaseStrategy: # inline: # shardingColumn: user_id # algorithmExpression: ds_${user_id % 2} # defaultTableStrategy: # none: # defaultKeyGeneratorClassName: io.shardingsphere.core.keygen.DefaultKeyGenerator # # props: # # MEMORY_STRICTLY: Proxy holds as many connections as the count of actual tables routed in a database. # # The benefit of this approach is saving memory for Proxy by Stream ResultSet. # # # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet. # # Meanwhile, the cost of the memory will be increased. # connection.mode: MEMORY_STRICTLY # acceptor.size: 16 # The default value is available processors count * 2. # executor.size: 16 # Infinite by default. # proxy.transaction.mode: XA # sql.show: false # #orchestration: # name: orchestration_ds # type: SHARDING # overwrite: true # zookeeper: # namespace: orchestration # serverLists: localhost:2181 # #proxyAuthority: # username: root # password: root dataSources: ds_0: url: jdbc:mysql://127.0.0.1:3306/ds_0?serverTimezone=UTC&useSSL=false username: root password: autoCommit: true connectionTimeout: 30000 idleTimeout: 60000 maxLifetime: 1800000 maximumPoolSize: 65 ds_1: url: jdbc:mysql://127.0.0.1:3306/ds_1?serverTimezone=UTC&useSSL=false username: root password: autoCommit: true connectionTimeout: 30000 idleTimeout: 60000 maxLifetime: 1800000 maximumPoolSize: 65 shardingRule: tables: t_order: actualDataNodes: ds_${0..1}.t_order_${0..1} tableStrategy: inline: shardingColumn: order_id algorithmExpression: t_order_${order_id % 2} keyGeneratorColumnName: order_id t_order_item: actualDataNodes: ds_${0..1}.t_order_item_${0..1} tableStrategy: inline: shardingColumn: order_id algorithmExpression: t_order_item_${order_id % 2} bindingTables: - t_order,t_order_item defaultDatabaseStrategy: inline: shardingColumn: user_id algorithmExpression: ds_${user_id % 2} defaultTableStrategy: none: defaultKeyGeneratorClassName: io.shardingsphere.core.keygen.DefaultKeyGenerator props: # MEMORY_STRICTLY: Proxy holds as many connections as the count of actual tables routed in a database. # The benefit of this approach is saving memory for Proxy by Stream ResultSet. # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet. # Meanwhile, the cost of the memory will be increased. connection.mode: MEMORY_STRICTLY acceptor.size: 16 # The default value is available processors count * 2. executor.size: 16 # Infinite by default. proxy.transaction.mode: XA sql.show: false orchestration: name: orchestration_ds type: SHARDING overwrite: true zookeeper: namespace: orchestration serverLists: localhost:2181 proxyAuthority: username: root password: root sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/ShardingTransactionListenerAdapter.java +2 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,8 @@ public abstract class ShardingTransactionListenerAdapter<T extends TransactionEv EventBusInstance.getInstance().register(this); } protected final void doTransaction(final ShardingTransactionManager shardingTransactionManager, final TransactionEvent transactionEvent) throws SQLException { @SuppressWarnings("unchecked") protected final void doTransaction(final ShardingTransactionManager shardingTransactionManager, final T transactionEvent) throws SQLException { switch (transactionEvent.getTclType()) { case BEGIN: shardingTransactionManager.begin(transactionEvent); Loading sharding-transaction/src/main/java/io/shardingsphere/transaction/manager/ShardingTransactionManager.java +6 −4 Original line number Diff line number Diff line Loading @@ -25,8 +25,10 @@ import java.sql.SQLException; * * @author zhaojun * @author zhangliang * * @param <T> transaction event type */ public interface ShardingTransactionManager { public interface ShardingTransactionManager<T extends TransactionEvent> { /** * Begin transaction. Loading @@ -34,7 +36,7 @@ public interface ShardingTransactionManager { * @param transactionEvent transaction event * @throws SQLException SQL exception */ void begin(TransactionEvent transactionEvent) throws SQLException; void begin(T transactionEvent) throws SQLException; /** * Commit transaction. Loading @@ -42,7 +44,7 @@ public interface ShardingTransactionManager { * @param transactionEvent transaction event * @throws SQLException SQL exception */ void commit(TransactionEvent transactionEvent) throws SQLException; void commit(T transactionEvent) throws SQLException; /** * Rollback transaction. Loading @@ -50,7 +52,7 @@ public interface ShardingTransactionManager { * @param transactionEvent transaction event * @throws SQLException SQL exception */ void rollback(TransactionEvent transactionEvent) throws SQLException; void rollback(T transactionEvent) throws SQLException; /** * Obtain the status of the transaction associated with the current thread. Loading sharding-transaction/src/main/java/io/shardingsphere/transaction/manager/local/LocalTransactionManager.java +9 −13 Original line number Diff line number Diff line Loading @@ -17,9 +17,8 @@ package io.shardingsphere.transaction.manager.local; import io.shardingsphere.transaction.manager.ShardingTransactionManager; import io.shardingsphere.transaction.event.TransactionEvent; import io.shardingsphere.transaction.event.LocalTransactionEvent; import io.shardingsphere.transaction.manager.ShardingTransactionManager; import javax.transaction.Status; import java.sql.Connection; Loading @@ -32,15 +31,14 @@ import java.util.LinkedList; * * @author zhaojun */ public final class LocalTransactionManager implements ShardingTransactionManager { public final class LocalTransactionManager implements ShardingTransactionManager<LocalTransactionEvent> { @Override public void begin(final TransactionEvent transactionEvent) throws SQLException { LocalTransactionEvent localTransactionEvent = (LocalTransactionEvent) transactionEvent; public void begin(final LocalTransactionEvent event) throws SQLException { Collection<SQLException> exceptions = new LinkedList<>(); for (Connection each : localTransactionEvent.getCachedConnections()) { for (Connection each : event.getCachedConnections()) { try { each.setAutoCommit(localTransactionEvent.isAutoCommit()); each.setAutoCommit(event.isAutoCommit()); } catch (final SQLException ex) { exceptions.add(ex); } Loading @@ -49,10 +47,9 @@ public final class LocalTransactionManager implements ShardingTransactionManager } @Override public void commit(final TransactionEvent transactionEvent) throws SQLException { LocalTransactionEvent localTransactionEvent = (LocalTransactionEvent) transactionEvent; public void commit(final LocalTransactionEvent event) throws SQLException { Collection<SQLException> exceptions = new LinkedList<>(); for (Connection each : localTransactionEvent.getCachedConnections()) { for (Connection each : event.getCachedConnections()) { try { each.commit(); } catch (final SQLException ex) { Loading @@ -63,10 +60,9 @@ public final class LocalTransactionManager implements ShardingTransactionManager } @Override public void rollback(final TransactionEvent transactionEvent) throws SQLException { LocalTransactionEvent localTransactionEvent = (LocalTransactionEvent) transactionEvent; public void rollback(final LocalTransactionEvent event) throws SQLException { Collection<SQLException> exceptions = new LinkedList<>(); for (Connection each : localTransactionEvent.getCachedConnections()) { for (Connection each : event.getCachedConnections()) { try { each.rollback(); } catch (final SQLException ex) { Loading sharding-transaction/src/main/java/io/shardingsphere/transaction/manager/xa/XATransactionManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package io.shardingsphere.transaction.manager.xa; import io.shardingsphere.transaction.event.XATransactionEvent; import io.shardingsphere.transaction.manager.ShardingTransactionManager; /** Loading @@ -24,5 +25,5 @@ import io.shardingsphere.transaction.manager.ShardingTransactionManager; * * @author zhangliang */ public interface XATransactionManager extends ShardingTransactionManager { public interface XATransactionManager extends ShardingTransactionManager<XATransactionEvent> { } Loading
sharding-proxy/src/main/resources/conf/config.yaml +68 −68 Original line number Diff line number Diff line Loading @@ -9,71 +9,71 @@ # The example of Sharding rule. #dataSources: # ds_0: # url: jdbc:mysql://127.0.0.1:3306/ds_0?serverTimezone=UTC&useSSL=false # username: root # password: # autoCommit: true # connectionTimeout: 30000 # idleTimeout: 60000 # maxLifetime: 1800000 # maximumPoolSize: 65 # ds_1: # url: jdbc:mysql://127.0.0.1:3306/ds_1?serverTimezone=UTC&useSSL=false # username: root # password: # autoCommit: true # connectionTimeout: 30000 # idleTimeout: 60000 # maxLifetime: 1800000 # maximumPoolSize: 65 # #shardingRule: # tables: # t_order: # actualDataNodes: ds_${0..1}.t_order_${0..1} # tableStrategy: # inline: # shardingColumn: order_id # algorithmExpression: t_order_${order_id % 2} # keyGeneratorColumnName: order_id # t_order_item: # actualDataNodes: ds_${0..1}.t_order_item_${0..1} # tableStrategy: # inline: # shardingColumn: order_id # algorithmExpression: t_order_item_${order_id % 2} # bindingTables: # - t_order,t_order_item # defaultDatabaseStrategy: # inline: # shardingColumn: user_id # algorithmExpression: ds_${user_id % 2} # defaultTableStrategy: # none: # defaultKeyGeneratorClassName: io.shardingsphere.core.keygen.DefaultKeyGenerator # # props: # # MEMORY_STRICTLY: Proxy holds as many connections as the count of actual tables routed in a database. # # The benefit of this approach is saving memory for Proxy by Stream ResultSet. # # # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet. # # Meanwhile, the cost of the memory will be increased. # connection.mode: MEMORY_STRICTLY # acceptor.size: 16 # The default value is available processors count * 2. # executor.size: 16 # Infinite by default. # proxy.transaction.mode: XA # sql.show: false # #orchestration: # name: orchestration_ds # type: SHARDING # overwrite: true # zookeeper: # namespace: orchestration # serverLists: localhost:2181 # #proxyAuthority: # username: root # password: root dataSources: ds_0: url: jdbc:mysql://127.0.0.1:3306/ds_0?serverTimezone=UTC&useSSL=false username: root password: autoCommit: true connectionTimeout: 30000 idleTimeout: 60000 maxLifetime: 1800000 maximumPoolSize: 65 ds_1: url: jdbc:mysql://127.0.0.1:3306/ds_1?serverTimezone=UTC&useSSL=false username: root password: autoCommit: true connectionTimeout: 30000 idleTimeout: 60000 maxLifetime: 1800000 maximumPoolSize: 65 shardingRule: tables: t_order: actualDataNodes: ds_${0..1}.t_order_${0..1} tableStrategy: inline: shardingColumn: order_id algorithmExpression: t_order_${order_id % 2} keyGeneratorColumnName: order_id t_order_item: actualDataNodes: ds_${0..1}.t_order_item_${0..1} tableStrategy: inline: shardingColumn: order_id algorithmExpression: t_order_item_${order_id % 2} bindingTables: - t_order,t_order_item defaultDatabaseStrategy: inline: shardingColumn: user_id algorithmExpression: ds_${user_id % 2} defaultTableStrategy: none: defaultKeyGeneratorClassName: io.shardingsphere.core.keygen.DefaultKeyGenerator props: # MEMORY_STRICTLY: Proxy holds as many connections as the count of actual tables routed in a database. # The benefit of this approach is saving memory for Proxy by Stream ResultSet. # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet. # Meanwhile, the cost of the memory will be increased. connection.mode: MEMORY_STRICTLY acceptor.size: 16 # The default value is available processors count * 2. executor.size: 16 # Infinite by default. proxy.transaction.mode: XA sql.show: false orchestration: name: orchestration_ds type: SHARDING overwrite: true zookeeper: namespace: orchestration serverLists: localhost:2181 proxyAuthority: username: root password: root
sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/ShardingTransactionListenerAdapter.java +2 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,8 @@ public abstract class ShardingTransactionListenerAdapter<T extends TransactionEv EventBusInstance.getInstance().register(this); } protected final void doTransaction(final ShardingTransactionManager shardingTransactionManager, final TransactionEvent transactionEvent) throws SQLException { @SuppressWarnings("unchecked") protected final void doTransaction(final ShardingTransactionManager shardingTransactionManager, final T transactionEvent) throws SQLException { switch (transactionEvent.getTclType()) { case BEGIN: shardingTransactionManager.begin(transactionEvent); Loading
sharding-transaction/src/main/java/io/shardingsphere/transaction/manager/ShardingTransactionManager.java +6 −4 Original line number Diff line number Diff line Loading @@ -25,8 +25,10 @@ import java.sql.SQLException; * * @author zhaojun * @author zhangliang * * @param <T> transaction event type */ public interface ShardingTransactionManager { public interface ShardingTransactionManager<T extends TransactionEvent> { /** * Begin transaction. Loading @@ -34,7 +36,7 @@ public interface ShardingTransactionManager { * @param transactionEvent transaction event * @throws SQLException SQL exception */ void begin(TransactionEvent transactionEvent) throws SQLException; void begin(T transactionEvent) throws SQLException; /** * Commit transaction. Loading @@ -42,7 +44,7 @@ public interface ShardingTransactionManager { * @param transactionEvent transaction event * @throws SQLException SQL exception */ void commit(TransactionEvent transactionEvent) throws SQLException; void commit(T transactionEvent) throws SQLException; /** * Rollback transaction. Loading @@ -50,7 +52,7 @@ public interface ShardingTransactionManager { * @param transactionEvent transaction event * @throws SQLException SQL exception */ void rollback(TransactionEvent transactionEvent) throws SQLException; void rollback(T transactionEvent) throws SQLException; /** * Obtain the status of the transaction associated with the current thread. Loading
sharding-transaction/src/main/java/io/shardingsphere/transaction/manager/local/LocalTransactionManager.java +9 −13 Original line number Diff line number Diff line Loading @@ -17,9 +17,8 @@ package io.shardingsphere.transaction.manager.local; import io.shardingsphere.transaction.manager.ShardingTransactionManager; import io.shardingsphere.transaction.event.TransactionEvent; import io.shardingsphere.transaction.event.LocalTransactionEvent; import io.shardingsphere.transaction.manager.ShardingTransactionManager; import javax.transaction.Status; import java.sql.Connection; Loading @@ -32,15 +31,14 @@ import java.util.LinkedList; * * @author zhaojun */ public final class LocalTransactionManager implements ShardingTransactionManager { public final class LocalTransactionManager implements ShardingTransactionManager<LocalTransactionEvent> { @Override public void begin(final TransactionEvent transactionEvent) throws SQLException { LocalTransactionEvent localTransactionEvent = (LocalTransactionEvent) transactionEvent; public void begin(final LocalTransactionEvent event) throws SQLException { Collection<SQLException> exceptions = new LinkedList<>(); for (Connection each : localTransactionEvent.getCachedConnections()) { for (Connection each : event.getCachedConnections()) { try { each.setAutoCommit(localTransactionEvent.isAutoCommit()); each.setAutoCommit(event.isAutoCommit()); } catch (final SQLException ex) { exceptions.add(ex); } Loading @@ -49,10 +47,9 @@ public final class LocalTransactionManager implements ShardingTransactionManager } @Override public void commit(final TransactionEvent transactionEvent) throws SQLException { LocalTransactionEvent localTransactionEvent = (LocalTransactionEvent) transactionEvent; public void commit(final LocalTransactionEvent event) throws SQLException { Collection<SQLException> exceptions = new LinkedList<>(); for (Connection each : localTransactionEvent.getCachedConnections()) { for (Connection each : event.getCachedConnections()) { try { each.commit(); } catch (final SQLException ex) { Loading @@ -63,10 +60,9 @@ public final class LocalTransactionManager implements ShardingTransactionManager } @Override public void rollback(final TransactionEvent transactionEvent) throws SQLException { LocalTransactionEvent localTransactionEvent = (LocalTransactionEvent) transactionEvent; public void rollback(final LocalTransactionEvent event) throws SQLException { Collection<SQLException> exceptions = new LinkedList<>(); for (Connection each : localTransactionEvent.getCachedConnections()) { for (Connection each : event.getCachedConnections()) { try { each.rollback(); } catch (final SQLException ex) { Loading
sharding-transaction/src/main/java/io/shardingsphere/transaction/manager/xa/XATransactionManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package io.shardingsphere.transaction.manager.xa; import io.shardingsphere.transaction.event.XATransactionEvent; import io.shardingsphere.transaction.manager.ShardingTransactionManager; /** Loading @@ -24,5 +25,5 @@ import io.shardingsphere.transaction.manager.ShardingTransactionManager; * * @author zhangliang */ public interface XATransactionManager extends ShardingTransactionManager { public interface XATransactionManager extends ShardingTransactionManager<XATransactionEvent> { }