From 1c79b48fd9383f77cc551b1db0df84f19bfd4e04 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Sun, 29 Jul 2018 18:01:21 +0800
Subject: [PATCH 001/198] remove transaction event holder.
---
.../spi/TransactionEventHolder.java | 48 -------------------
.../transaction/spi/TransactionManager.java | 2 +-
2 files changed, 1 insertion(+), 49 deletions(-)
delete mode 100644 sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionEventHolder.java
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionEventHolder.java b/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionEventHolder.java
deleted file mode 100644
index 098d89812a029..0000000000000
--- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionEventHolder.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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 io.shardingsphere.core.transaction.spi;
-
-import io.shardingsphere.core.transaction.event.TransactionEvent;
-
-/**
- * Hold transaction event for current thread.
- *
- * @author zhaojun
- */
-public class TransactionEventHolder {
-
- private static Class extends TransactionEvent> transactionEvent;
-
- /**
- * Set transactionEvent.
- *
- * @param clazz class type of TransactionEvent
- */
- public static synchronized void set(final Class extends TransactionEvent> clazz) {
- transactionEvent = clazz;
- }
-
- /**
- * Get transactionEvent class type.
- *
- * @return transactionEvent class type
- */
- public static Class extends TransactionEvent> get() {
- return transactionEvent;
- }
-}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java b/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java
index f47639a4fd800..ef2db799a9462 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java
@@ -55,7 +55,7 @@ public interface TransactionManager {
/**
* Obtain the status of the transaction associated with the current thread.
*
- * @return The transaction status.
+ * @return The transaction status.
*
* If no transaction is associated with the current thread, this method returns the Status.NoTransaction value
*
From bf8b53cc8ea5cfd3c7ea49be431111eedb3fb0ca Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 11:47:02 +0800
Subject: [PATCH 002/198] refactor AtomikosUserTransaction to hungry mode.
---
.../transaction/xa/AtomikosUserTransaction.java | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java
index bd05b40e2ee29..117f8671f8918 100644
--- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java
+++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java
@@ -18,30 +18,25 @@
package io.shardingsphere.transaction.xa;
import com.atomikos.icatch.jta.UserTransactionManager;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
/**
* Hold singleton atomikos userTransaction.
*
* @author zhaojun
*/
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class AtomikosUserTransaction {
- // TODO why not new here?
- private static volatile UserTransactionManager transactionManager;
+ private static final UserTransactionManager TRANSACTION_MANAGER = new UserTransactionManager();
/**
- * Get singleton {@code UserTransactionManager} lazily.
+ * Get singleton of {@code UserTransactionManager}.
*
* @return {@code UserTransactionManager}
*/
public static UserTransactionManager getInstance() {
- if (null == transactionManager) {
- synchronized (AtomikosUserTransaction.class) {
- if (null == transactionManager) {
- transactionManager = new UserTransactionManager();
- }
- }
- }
- return transactionManager;
+ return TRANSACTION_MANAGER;
}
}
From 80c4b659bd9ecb9245ace2d519a1e78fdaaed54e Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 12:55:17 +0800
Subject: [PATCH 003/198] add sharding-event and sharding-transaction module.
---
pom.xml | 2 ++
sharding-event/pom.xml | 40 +++++++++++++++++++++++++++++++++++
sharding-transaction/pom.xml | 41 ++++++++++++++++++++++++++++++++++++
3 files changed, 83 insertions(+)
create mode 100644 sharding-event/pom.xml
create mode 100644 sharding-transaction/pom.xml
diff --git a/pom.xml b/pom.xml
index 10858af2be5c5..0dbf47ff58782 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,6 +16,8 @@
sharding-opentracing
sharding-proxy
sharding-sql-test
+ sharding-transaction
+ sharding-event
diff --git a/sharding-event/pom.xml b/sharding-event/pom.xml
new file mode 100644
index 0000000000000..cb414ad1d518f
--- /dev/null
+++ b/sharding-event/pom.xml
@@ -0,0 +1,40 @@
+
+
+ 4.0.0
+
+ sharding-sphere
+ io.shardingsphere
+ 3.0.0.M2-SNAPSHOT
+
+ sharding-event
+ ${project.artifactId}
+
+
+
+ com.google.guava
+ guava
+
+
+ org.projectlombok
+ lombok
+
+
+ org.slf4j
+ slf4j-api
+
+
+ ch.qos.logback
+ logback-classic
+
+
+ junit
+ junit
+
+
+ org.mockito
+ mockito-core
+
+
+
\ No newline at end of file
diff --git a/sharding-transaction/pom.xml b/sharding-transaction/pom.xml
new file mode 100644
index 0000000000000..44b3245248fd0
--- /dev/null
+++ b/sharding-transaction/pom.xml
@@ -0,0 +1,41 @@
+
+
+ 4.0.0
+
+ sharding-sphere
+ io.shardingsphere
+ 3.0.0.M2-SNAPSHOT
+
+
+ sharding-transaction
+ ${project.artifactId}
+
+
+
+ com.google.guava
+ guava
+
+
+ org.projectlombok
+ lombok
+
+
+ org.slf4j
+ slf4j-api
+
+
+ ch.qos.logback
+ logback-classic
+
+
+ junit
+ junit
+
+
+ org.mockito
+ mockito-core
+
+
+
\ No newline at end of file
From a4fe245c45334219b2b7dbefb4aec60e9f09a9e0 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 12:58:54 +0800
Subject: [PATCH 004/198] remove sharding-event module, event module can't been
common now.
---
pom.xml | 1 -
sharding-event/pom.xml | 40 ----------------------------------------
2 files changed, 41 deletions(-)
delete mode 100644 sharding-event/pom.xml
diff --git a/pom.xml b/pom.xml
index 0dbf47ff58782..d243c91a22ccb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,7 +17,6 @@
sharding-proxy
sharding-sql-test
sharding-transaction
- sharding-event
diff --git a/sharding-event/pom.xml b/sharding-event/pom.xml
deleted file mode 100644
index cb414ad1d518f..0000000000000
--- a/sharding-event/pom.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-
-
- 4.0.0
-
- sharding-sphere
- io.shardingsphere
- 3.0.0.M2-SNAPSHOT
-
- sharding-event
- ${project.artifactId}
-
-
-
- com.google.guava
- guava
-
-
- org.projectlombok
- lombok
-
-
- org.slf4j
- slf4j-api
-
-
- ch.qos.logback
- logback-classic
-
-
- junit
- junit
-
-
- org.mockito
- mockito-core
-
-
-
\ No newline at end of file
From e00e0192a2bc25668289cdb1c62f6b679c7e89c9 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 14:10:45 +0800
Subject: [PATCH 005/198] move xa transaction to transaction module.
---
sharding-transaction/pom.xml | 23 ++++++++++
.../TransactionEventBusInstance.java | 42 +++++++++++++++++++
.../transaction/TransactionLoader.java | 5 +--
.../transaction/WeakXaTransactionManager.java | 2 +-
.../xa/AtomikosTransactionManager.java | 0
.../xa/AtomikosUserTransaction.java | 0
6 files changed, 68 insertions(+), 4 deletions(-)
create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java
rename {sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core => sharding-transaction/src/main/java/io/shardingsphere}/transaction/TransactionLoader.java (92%)
rename {sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core => sharding-transaction/src/main/java/io/shardingsphere}/transaction/WeakXaTransactionManager.java (98%)
rename {sharding-jdbc-transaction-parent/sharding-jdbc-transaction => sharding-transaction}/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java (100%)
rename {sharding-jdbc-transaction-parent/sharding-jdbc-transaction => sharding-transaction}/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java (100%)
diff --git a/sharding-transaction/pom.xml b/sharding-transaction/pom.xml
index 44b3245248fd0..425710ba68a5a 100644
--- a/sharding-transaction/pom.xml
+++ b/sharding-transaction/pom.xml
@@ -37,5 +37,28 @@
org.mockito
mockito-core
+
+
+ io.shardingsphere
+ sharding-core
+ ${project.parent.version}
+
+
+
+ com.atomikos
+ transactions
+
+
+ com.atomikos
+ transactions-jta
+
+
+ com.atomikos
+ transactions-jdbc
+
+
+ javax.transaction
+ jta
+
\ No newline at end of file
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java
new file mode 100644
index 0000000000000..c703d9867573b
--- /dev/null
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed 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 io.shardingsphere.transaction;
+
+import com.google.common.eventbus.EventBus;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Event bus for singleton instance.
+ *
+ * @author zhangliang
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TransactionEventBusInstance {
+
+ private static final EventBus INSTANCE = new EventBus();
+
+ /**
+ * Get event bus instance.
+ *
+ * @return event bus instance
+ */
+ public static EventBus getInstance() {
+ return INSTANCE;
+ }
+}
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/TransactionLoader.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java
similarity index 92%
rename from sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/TransactionLoader.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java
index c5e0d89beef52..24d706058d60d 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/TransactionLoader.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.core.jdbc.core.transaction;
+package io.shardingsphere.transaction;
import io.shardingsphere.core.constant.TransactionType;
import io.shardingsphere.core.transaction.TransactionContext;
@@ -24,7 +24,6 @@
import io.shardingsphere.core.transaction.event.XaTransactionEvent;
import io.shardingsphere.core.transaction.listener.TransactionListener;
import io.shardingsphere.core.transaction.spi.TransactionManager;
-import io.shardingsphere.core.util.EventBusInstance;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -53,7 +52,7 @@ public static void load() {
break;
default:
}
- EventBusInstance.getInstance().register(TransactionListener.getInstance());
+ TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance());
}
private static void doXaTransactionConfiguration() {
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/WeakXaTransactionManager.java
similarity index 98%
rename from sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/WeakXaTransactionManager.java
index 52bde5e99f3a9..1d9de86da573d 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/WeakXaTransactionManager.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.core.jdbc.core.transaction;
+package io.shardingsphere.transaction;
import io.shardingsphere.core.transaction.event.TransactionEvent;
import io.shardingsphere.core.transaction.event.WeakXaTransactionEvent;
diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java
similarity index 100%
rename from sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java
diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java
similarity index 100%
rename from sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java
From 5f7ac5b6c2681fdac5c3363cee31bac6ffac3b3e Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 15:03:39 +0800
Subject: [PATCH 006/198] using sharding-transaction, refactor proxy and jdbc.
---
sharding-jdbc/pom.xml | 5 +++++
.../jdbc/adapter/AbstractConnectionAdapter.java | 6 +++---
.../jdbc/adapter/AbstractDataSourceAdapter.java | 2 +-
sharding-proxy/pom.xml | 2 +-
.../jdbc/transaction/XaTransactionEngine.java | 6 +++---
.../shardingsphere/proxy/config/RuleRegistry.java | 4 ++--
...phere.transaction.common.spi.TransactionManager} | 0
.../transaction}/ProxyTransactionLoader.java | 9 ++++-----
.../transaction/TransactionLoader.java | 13 +++++++------
.../transaction/common}/TransactionContext.java | 8 ++++----
.../common}/TransactionContextHolder.java | 2 +-
.../transaction/common}/event/TransactionEvent.java | 2 +-
.../common}/event/TransactionEventFactory.java | 4 ++--
.../common}/event/WeakXaTransactionEvent.java | 2 +-
.../common}/event/XaTransactionEvent.java | 2 +-
.../common}/listener/TransactionListener.java | 8 ++++----
.../transaction/common}/spi/TransactionManager.java | 5 ++---
.../{ => weakxa}/WeakXaTransactionManager.java | 8 ++++----
.../transaction/xa/AtomikosTransactionManager.java | 4 ++--
19 files changed, 48 insertions(+), 44 deletions(-)
rename sharding-proxy/src/main/resources/META-INF/services/{io.shardingsphere.core.transaction.spi.TransactionManager => io.shardingsphere.transaction.common.spi.TransactionManager} (100%)
rename {sharding-proxy/src/main/java/io/shardingsphere/proxy/util => sharding-transaction/src/main/java/io/shardingsphere/transaction}/ProxyTransactionLoader.java (85%)
rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/TransactionContext.java (84%)
rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/TransactionContextHolder.java (96%)
rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/event/TransactionEvent.java (96%)
rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/event/TransactionEventFactory.java (92%)
rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/event/WeakXaTransactionEvent.java (96%)
rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/event/XaTransactionEvent.java (96%)
rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/listener/TransactionListener.java (88%)
rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/spi/TransactionManager.java (93%)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => weakxa}/WeakXaTransactionManager.java (91%)
diff --git a/sharding-jdbc/pom.xml b/sharding-jdbc/pom.xml
index 12be6706e4c23..6d36058f3a317 100644
--- a/sharding-jdbc/pom.xml
+++ b/sharding-jdbc/pom.xml
@@ -14,6 +14,11 @@
sharding-core
${project.version}
+
+ io.shardingsphere
+ sharding-transaction
+ ${project.version}
+
org.projectlombok
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
index 458200532d65d..674a8c02e74b9 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
@@ -22,9 +22,9 @@
import io.shardingsphere.core.hint.HintManagerHolder;
import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationConnection;
import io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager;
-import io.shardingsphere.core.transaction.event.TransactionEvent;
-import io.shardingsphere.core.transaction.event.TransactionEventFactory;
-import io.shardingsphere.core.transaction.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.common.event.TransactionEvent;
+import io.shardingsphere.transaction.common.event.TransactionEventFactory;
+import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
import io.shardingsphere.core.util.EventBusInstance;
import javax.sql.DataSource;
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java
index a078f0912180d..6614587377c8f 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java
@@ -19,8 +19,8 @@
import com.google.common.base.Preconditions;
import io.shardingsphere.core.constant.DatabaseType;
-import io.shardingsphere.core.jdbc.core.transaction.TransactionLoader;
import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationDataSource;
+import io.shardingsphere.transaction.TransactionLoader;
import lombok.Getter;
import javax.sql.DataSource;
diff --git a/sharding-proxy/pom.xml b/sharding-proxy/pom.xml
index 40e7e9ec6a9a4..aa01e36a67b46 100644
--- a/sharding-proxy/pom.xml
+++ b/sharding-proxy/pom.xml
@@ -24,7 +24,7 @@
io.shardingsphere
- sharding-jdbc-transaction
+ sharding-transaction
${project.version}
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
index eabcdd9d6aebf..4d9f5b8ce1cc6 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
@@ -19,9 +19,9 @@
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TCLType;
-import io.shardingsphere.core.transaction.TransactionContext;
-import io.shardingsphere.core.transaction.TransactionContextHolder;
-import io.shardingsphere.core.transaction.event.XaTransactionEvent;
+import io.shardingsphere.transaction.common.TransactionContext;
+import io.shardingsphere.transaction.common.TransactionContextHolder;
+import io.shardingsphere.transaction.common.event.XaTransactionEvent;
import io.shardingsphere.core.util.EventBusInstance;
import io.shardingsphere.proxy.config.RuleRegistry;
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
index 61c3e7b2b7e1a..8d88692a1f977 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
@@ -30,13 +30,13 @@
import io.shardingsphere.core.rule.MasterSlaveRule;
import io.shardingsphere.core.rule.ProxyAuthority;
import io.shardingsphere.core.rule.ShardingRule;
-import io.shardingsphere.core.transaction.spi.TransactionManager;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
import io.shardingsphere.jdbc.orchestration.internal.OrchestrationProxyConfiguration;
import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent;
import io.shardingsphere.proxy.backend.constant.ProxyMode;
import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource;
import io.shardingsphere.proxy.metadata.ProxyShardingMetaData;
-import io.shardingsphere.proxy.util.ProxyTransactionLoader;
+import io.shardingsphere.transaction.ProxyTransactionLoader;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
diff --git a/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.core.transaction.spi.TransactionManager b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.common.spi.TransactionManager
similarity index 100%
rename from sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.core.transaction.spi.TransactionManager
rename to sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.common.spi.TransactionManager
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/ProxyTransactionLoader.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.java
similarity index 85%
rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/util/ProxyTransactionLoader.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.java
index b38904c0dc790..a4f277808ed8b 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/ProxyTransactionLoader.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.java
@@ -15,12 +15,11 @@
*
*/
-package io.shardingsphere.proxy.util;
+package io.shardingsphere.transaction;
import io.shardingsphere.core.constant.TransactionType;
-import io.shardingsphere.core.transaction.listener.TransactionListener;
-import io.shardingsphere.core.transaction.spi.TransactionManager;
-import io.shardingsphere.core.util.EventBusInstance;
+import io.shardingsphere.transaction.common.listener.TransactionListener;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -51,7 +50,7 @@ public static TransactionManager load(final TransactionType transactionType) {
break;
default:
}
- EventBusInstance.getInstance().register(TransactionListener.getInstance());
+ TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance());
return result;
}
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java
index 24d706058d60d..1aa818c10f5d3 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java
@@ -18,12 +18,13 @@
package io.shardingsphere.transaction;
import io.shardingsphere.core.constant.TransactionType;
-import io.shardingsphere.core.transaction.TransactionContext;
-import io.shardingsphere.core.transaction.TransactionContextHolder;
-import io.shardingsphere.core.transaction.event.WeakXaTransactionEvent;
-import io.shardingsphere.core.transaction.event.XaTransactionEvent;
-import io.shardingsphere.core.transaction.listener.TransactionListener;
-import io.shardingsphere.core.transaction.spi.TransactionManager;
+import io.shardingsphere.transaction.common.TransactionContext;
+import io.shardingsphere.transaction.common.TransactionContextHolder;
+import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.common.event.XaTransactionEvent;
+import io.shardingsphere.transaction.common.listener.TransactionListener;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
+import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
similarity index 84%
rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/TransactionContext.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
index 1581ce6c831d3..6dff8a5832162 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/TransactionContext.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
@@ -15,12 +15,12 @@
*
*/
-package io.shardingsphere.core.transaction;
+package io.shardingsphere.transaction.common;
import io.shardingsphere.core.constant.TransactionType;
-import io.shardingsphere.core.transaction.event.TransactionEvent;
-import io.shardingsphere.core.transaction.event.WeakXaTransactionEvent;
-import io.shardingsphere.core.transaction.spi.TransactionManager;
+import io.shardingsphere.transaction.common.event.TransactionEvent;
+import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
import lombok.Getter;
/**
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/TransactionContextHolder.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java
similarity index 96%
rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/TransactionContextHolder.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java
index bbbf6acffc99c..676869ce12e4d 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/TransactionContextHolder.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.core.transaction;
+package io.shardingsphere.transaction.common;
/**
* Hold transaction context for current thread.
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/TransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java
similarity index 96%
rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/event/TransactionEvent.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java
index dce58732d9554..5c02c1b41c74a 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/TransactionEvent.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.core.transaction.event;
+package io.shardingsphere.transaction.common.event;
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TCLType;
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/TransactionEventFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java
similarity index 92%
rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/event/TransactionEventFactory.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java
index 530b3587e3543..133914168c293 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/TransactionEventFactory.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java
@@ -15,10 +15,10 @@
*
*/
-package io.shardingsphere.core.transaction.event;
+package io.shardingsphere.transaction.common.event;
import io.shardingsphere.core.constant.TCLType;
-import io.shardingsphere.core.transaction.TransactionContextHolder;
+import io.shardingsphere.transaction.common.TransactionContextHolder;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java
similarity index 96%
rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java
index e002128cc9df9..f1bb7bcec60c4 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.core.transaction.event;
+package io.shardingsphere.transaction.common.event;
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TCLType;
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/XaTransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java
similarity index 96%
rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/event/XaTransactionEvent.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java
index 1791d557a47b4..67c9dd5ecd15c 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/XaTransactionEvent.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.core.transaction.event;
+package io.shardingsphere.transaction.common.event;
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TCLType;
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/listener/TransactionListener.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java
similarity index 88%
rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/listener/TransactionListener.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java
index eae664f4c0b99..5e131b22bc517 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/listener/TransactionListener.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java
@@ -15,13 +15,13 @@
*
*/
-package io.shardingsphere.core.transaction.listener;
+package io.shardingsphere.transaction.common.listener;
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
-import io.shardingsphere.core.transaction.TransactionContextHolder;
-import io.shardingsphere.core.transaction.event.TransactionEvent;
-import io.shardingsphere.core.transaction.spi.TransactionManager;
+import io.shardingsphere.transaction.common.TransactionContextHolder;
+import io.shardingsphere.transaction.common.event.TransactionEvent;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java
similarity index 93%
rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java
index ef2db799a9462..6c06cd29f172a 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java
@@ -15,10 +15,9 @@
*
*/
-package io.shardingsphere.core.transaction.spi;
-
-import io.shardingsphere.core.transaction.event.TransactionEvent;
+package io.shardingsphere.transaction.common.spi;
+import io.shardingsphere.transaction.common.event.TransactionEvent;
import java.sql.SQLException;
/**
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/weakxa/WeakXaTransactionManager.java
similarity index 91%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/WeakXaTransactionManager.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/weakxa/WeakXaTransactionManager.java
index 1d9de86da573d..3c8de3438a966 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/WeakXaTransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/weakxa/WeakXaTransactionManager.java
@@ -15,11 +15,11 @@
*
*/
-package io.shardingsphere.transaction;
+package io.shardingsphere.transaction.weakxa;
-import io.shardingsphere.core.transaction.event.TransactionEvent;
-import io.shardingsphere.core.transaction.event.WeakXaTransactionEvent;
-import io.shardingsphere.core.transaction.spi.TransactionManager;
+import io.shardingsphere.transaction.common.event.TransactionEvent;
+import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
import java.sql.Connection;
import java.sql.SQLException;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java
index 12d5ab2cf0333..290552baf7211 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java
@@ -18,8 +18,8 @@
package io.shardingsphere.transaction.xa;
import com.atomikos.icatch.jta.UserTransactionManager;
-import io.shardingsphere.core.transaction.event.TransactionEvent;
-import io.shardingsphere.core.transaction.spi.TransactionManager;
+import io.shardingsphere.transaction.common.event.TransactionEvent;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
From 4e256c2f958d97691cc7b4b74597aa42bd21a49f Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 16:33:00 +0800
Subject: [PATCH 007/198] add transaction configuration interface.
---
.../config/JDBCTransactionConfiguration.java | 54 +++++++++++++++++++
.../config/TransactionConfiguration.java | 41 ++++++++++++++
.../TransactionConfigurationAdapter.java | 44 +++++++++++++++
3 files changed, 139 insertions(+)
create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java
create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
new file mode 100644
index 0000000000000..8c72b52dc3c3d
--- /dev/null
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed 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 io.shardingsphere.transaction.common.config;
+
+import com.google.common.base.Optional;
+import io.shardingsphere.core.constant.TransactionType;
+import io.shardingsphere.transaction.common.TransactionContext;
+import io.shardingsphere.transaction.common.TransactionContextHolder;
+import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.common.event.XaTransactionEvent;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
+import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager;
+
+/**
+ * JDBC transaction configuration.
+ *
+ * @author zhaojun
+ */
+public class JDBCTransactionConfiguration extends TransactionConfigurationAdapter {
+
+ @Override
+ public void configTransactionContext(final TransactionType transactionType) {
+ switch (transactionType) {
+ case XA:
+ doXaTransactionConfiguration();
+ break;
+ case BASE:
+ break;
+ default:
+ }
+ }
+
+ private void doXaTransactionConfiguration() {
+ Optional transactionManager = doSPIConfiguration();
+ TransactionContext transactionContext = transactionManager.isPresent() ? new TransactionContext(transactionManager.get(), TransactionType.XA, XaTransactionEvent.class)
+ : new TransactionContext(new WeakXaTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class);
+ TransactionContextHolder.set(transactionContext);
+ }
+}
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java
new file mode 100644
index 0000000000000..867b3da9d5d0b
--- /dev/null
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed 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 io.shardingsphere.transaction.common.config;
+
+import io.shardingsphere.core.constant.TransactionType;
+
+/**
+ * Execute transaction manager configuration.
+ *
+ * @author zhaojun
+ */
+public interface TransactionConfiguration {
+
+ /**
+ * Config transaction context, then binding to current thread.
+ *
+ * @param transactionType transaction type
+ */
+ void configTransactionContext(TransactionType transactionType);
+
+ /**
+ * Subscribe transaction event using listener, register into event bus.
+ */
+ void registerListener();
+
+}
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
new file mode 100644
index 0000000000000..7ffa67dbc61e1
--- /dev/null
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed 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 io.shardingsphere.transaction.common.config;
+
+import com.google.common.base.Optional;
+import io.shardingsphere.transaction.TransactionEventBusInstance;
+import io.shardingsphere.transaction.common.listener.TransactionListener;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
+
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+/**
+ * Abstract transaction manager configuration.
+ *
+ * @author zhaojun
+ */
+public abstract class TransactionConfigurationAdapter implements TransactionConfiguration {
+
+ @Override
+ public void registerListener() {
+ TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance());
+ }
+
+ protected Optional doSPIConfiguration() {
+ Iterator iterator = ServiceLoader.load(TransactionManager.class).iterator();
+ return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.absent();
+ }
+}
From 6c4dfd1ca493b43d543de60fb598f721330fba5c Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 16:48:18 +0800
Subject: [PATCH 008/198] refactor AbstractDataSource Adapter using
JDBCTransactionConfiguration.
---
.../jdbc/adapter/AbstractDataSourceAdapter.java | 6 ++++--
.../config/JDBCTransactionConfiguration.java | 14 ++++++++++++++
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java
index 6614587377c8f..b7c6fb7aee224 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java
@@ -20,7 +20,8 @@
import com.google.common.base.Preconditions;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationDataSource;
-import io.shardingsphere.transaction.TransactionLoader;
+import io.shardingsphere.transaction.common.TransactionContextHolder;
+import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration;
import lombok.Getter;
import javax.sql.DataSource;
@@ -38,7 +39,8 @@
public abstract class AbstractDataSourceAdapter extends AbstractUnsupportedOperationDataSource {
static {
- TransactionLoader.load();
+ JDBCTransactionConfiguration.getInstance().configTransactionContext(TransactionContextHolder.get().getTransactionType());
+ JDBCTransactionConfiguration.getInstance().registerListener();
}
@Getter
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
index 8c72b52dc3c3d..bac5eff38abed 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
@@ -25,14 +25,28 @@
import io.shardingsphere.transaction.common.event.XaTransactionEvent;
import io.shardingsphere.transaction.common.spi.TransactionManager;
import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
/**
* JDBC transaction configuration.
*
* @author zhaojun
*/
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class JDBCTransactionConfiguration extends TransactionConfigurationAdapter {
+ private static final JDBCTransactionConfiguration CONFIGURATION = new JDBCTransactionConfiguration();
+
+ /**
+ * Get singleton instance of {@code JDBCTransactionConfiguration}.
+ *
+ * @return JDBC transaction configuration
+ */
+ public static JDBCTransactionConfiguration getInstance() {
+ return CONFIGURATION;
+ }
+
@Override
public void configTransactionContext(final TransactionType transactionType) {
switch (transactionType) {
From 1bc352d73a2ac5906c768bfb8fb5c308f87c283b Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 16:57:13 +0800
Subject: [PATCH 009/198] create transaction context using factory.
---
.../common/TransactionContextFactory.java | 54 +++++++++++++++++++
.../config/JDBCTransactionConfiguration.java | 8 ++-
2 files changed, 57 insertions(+), 5 deletions(-)
create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
new file mode 100644
index 0000000000000..4e7083b620c48
--- /dev/null
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed 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 io.shardingsphere.transaction.common;
+
+import io.shardingsphere.core.constant.TransactionType;
+import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.common.event.XaTransactionEvent;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
+import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Transaction context factory.
+ *
+ * @author zhaojun
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class TransactionContextFactory {
+
+ /**
+ * Create transaction context of XA.
+ *
+ * @param transactionManager transaction manager
+ * @return XA transaction context
+ */
+ public static TransactionContext newXAContext(final TransactionManager transactionManager) {
+ return new TransactionContext(transactionManager, TransactionType.XA, XaTransactionEvent.class);
+ }
+
+ /**
+ * Create transaction context of weak XA.
+ *
+ * @return weak XA transaction context
+ */
+ public static TransactionContext newWeakXAContext() {
+ return new TransactionContext(new WeakXaTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class);
+ }
+}
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
index bac5eff38abed..da3e5194793a9 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
@@ -20,11 +20,9 @@
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TransactionType;
import io.shardingsphere.transaction.common.TransactionContext;
+import io.shardingsphere.transaction.common.TransactionContextFactory;
import io.shardingsphere.transaction.common.TransactionContextHolder;
-import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
-import io.shardingsphere.transaction.common.event.XaTransactionEvent;
import io.shardingsphere.transaction.common.spi.TransactionManager;
-import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -61,8 +59,8 @@ public void configTransactionContext(final TransactionType transactionType) {
private void doXaTransactionConfiguration() {
Optional transactionManager = doSPIConfiguration();
- TransactionContext transactionContext = transactionManager.isPresent() ? new TransactionContext(transactionManager.get(), TransactionType.XA, XaTransactionEvent.class)
- : new TransactionContext(new WeakXaTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class);
+ TransactionContext transactionContext = transactionManager.isPresent()
+ ? TransactionContextFactory.newXAContext(transactionManager.get()) : TransactionContextFactory.newWeakXAContext();
TransactionContextHolder.set(transactionContext);
}
}
From 159b1d79b2ffd28f90a41e1035d98231daa617f9 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 17:02:27 +0800
Subject: [PATCH 010/198] move configTransactionContext to
TransactionConfigurationAdapter.
---
.../config/JDBCTransactionConfiguration.java | 14 +-------------
.../config/TransactionConfigurationAdapter.java | 15 +++++++++++++++
2 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
index da3e5194793a9..1dd88adf7f7f9 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
@@ -18,7 +18,6 @@
package io.shardingsphere.transaction.common.config;
import com.google.common.base.Optional;
-import io.shardingsphere.core.constant.TransactionType;
import io.shardingsphere.transaction.common.TransactionContext;
import io.shardingsphere.transaction.common.TransactionContextFactory;
import io.shardingsphere.transaction.common.TransactionContextHolder;
@@ -46,18 +45,7 @@ public static JDBCTransactionConfiguration getInstance() {
}
@Override
- public void configTransactionContext(final TransactionType transactionType) {
- switch (transactionType) {
- case XA:
- doXaTransactionConfiguration();
- break;
- case BASE:
- break;
- default:
- }
- }
-
- private void doXaTransactionConfiguration() {
+ protected void doXaTransactionConfiguration() {
Optional transactionManager = doSPIConfiguration();
TransactionContext transactionContext = transactionManager.isPresent()
? TransactionContextFactory.newXAContext(transactionManager.get()) : TransactionContextFactory.newWeakXAContext();
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
index 7ffa67dbc61e1..ed20f114206e8 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
@@ -18,6 +18,7 @@
package io.shardingsphere.transaction.common.config;
import com.google.common.base.Optional;
+import io.shardingsphere.core.constant.TransactionType;
import io.shardingsphere.transaction.TransactionEventBusInstance;
import io.shardingsphere.transaction.common.listener.TransactionListener;
import io.shardingsphere.transaction.common.spi.TransactionManager;
@@ -32,11 +33,25 @@
*/
public abstract class TransactionConfigurationAdapter implements TransactionConfiguration {
+ @Override
+ public void configTransactionContext(final TransactionType transactionType) {
+ switch (transactionType) {
+ case XA:
+ doXaTransactionConfiguration();
+ break;
+ case BASE:
+ break;
+ default:
+ }
+ }
+
@Override
public void registerListener() {
TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance());
}
+ protected abstract void doXaTransactionConfiguration();
+
protected Optional doSPIConfiguration() {
Iterator iterator = ServiceLoader.load(TransactionManager.class).iterator();
return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.absent();
From 9902b61e07a7617fb2699b0ae7fcbe33add2f310 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 17:20:42 +0800
Subject: [PATCH 011/198] add proxy transaction configuration.
---
.../config/JDBCTransactionConfiguration.java | 4 +-
.../config/ProxyTransactionConfiguration.java | 53 +++++++++++++++++++
2 files changed, 55 insertions(+), 2 deletions(-)
create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
index 1dd88adf7f7f9..52f9b92366584 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
@@ -33,7 +33,7 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class JDBCTransactionConfiguration extends TransactionConfigurationAdapter {
- private static final JDBCTransactionConfiguration CONFIGURATION = new JDBCTransactionConfiguration();
+ private static final JDBCTransactionConfiguration CONFIG = new JDBCTransactionConfiguration();
/**
* Get singleton instance of {@code JDBCTransactionConfiguration}.
@@ -41,7 +41,7 @@ public class JDBCTransactionConfiguration extends TransactionConfigurationAdapte
* @return JDBC transaction configuration
*/
public static JDBCTransactionConfiguration getInstance() {
- return CONFIGURATION;
+ return CONFIG;
}
@Override
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java
new file mode 100644
index 0000000000000..a911a84355d9b
--- /dev/null
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed 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 io.shardingsphere.transaction.common.config;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import io.shardingsphere.transaction.common.TransactionContextFactory;
+import io.shardingsphere.transaction.common.TransactionContextHolder;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Sharding proxy transaction configuration.
+ *
+ * @author zhaojun
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class ProxyTransactionConfiguration extends TransactionConfigurationAdapter {
+
+ private static final ProxyTransactionConfiguration CONFIG = new ProxyTransactionConfiguration();
+
+ /**
+ * Get singleton instance of {@code ProxyTransactionConfiguration}.
+ *
+ * @return proxy transaction configuration
+ */
+ public static ProxyTransactionConfiguration getInstance() {
+ return CONFIG;
+ }
+
+ @Override
+ protected void doXaTransactionConfiguration() {
+ Optional transactionManager = doSPIConfiguration();
+ Preconditions.checkState(transactionManager.isPresent(), "there is no XA transaction manager existing, please prepare exactly one(Atomikos or Narayana) using SPI.");
+ TransactionContextHolder.set(TransactionContextFactory.newXAContext(transactionManager.get()));
+ }
+}
From fd03ce41238125e4128f53389de8d1f31cfce11d Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 17:30:00 +0800
Subject: [PATCH 012/198] add transaction manager result for
TransactionConfiguration.
---
.../common/config/JDBCTransactionConfiguration.java | 3 ++-
.../common/config/ProxyTransactionConfiguration.java | 3 ++-
.../common/config/TransactionConfiguration.java | 4 +++-
.../common/config/TransactionConfigurationAdapter.java | 8 +++++---
4 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
index 52f9b92366584..27e5b53fbcba4 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
@@ -45,10 +45,11 @@ public static JDBCTransactionConfiguration getInstance() {
}
@Override
- protected void doXaTransactionConfiguration() {
+ protected TransactionManager doXaTransactionConfiguration() {
Optional transactionManager = doSPIConfiguration();
TransactionContext transactionContext = transactionManager.isPresent()
? TransactionContextFactory.newXAContext(transactionManager.get()) : TransactionContextFactory.newWeakXAContext();
TransactionContextHolder.set(transactionContext);
+ return transactionContext.getTransactionManager();
}
}
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java
index a911a84355d9b..fd4bce1f46a49 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java
@@ -45,9 +45,10 @@ public static ProxyTransactionConfiguration getInstance() {
}
@Override
- protected void doXaTransactionConfiguration() {
+ protected TransactionManager doXaTransactionConfiguration() {
Optional transactionManager = doSPIConfiguration();
Preconditions.checkState(transactionManager.isPresent(), "there is no XA transaction manager existing, please prepare exactly one(Atomikos or Narayana) using SPI.");
TransactionContextHolder.set(TransactionContextFactory.newXAContext(transactionManager.get()));
+ return transactionManager.get();
}
}
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java
index 867b3da9d5d0b..3a8b276fc3808 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java
@@ -18,6 +18,7 @@
package io.shardingsphere.transaction.common.config;
import io.shardingsphere.core.constant.TransactionType;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
/**
* Execute transaction manager configuration.
@@ -30,8 +31,9 @@ public interface TransactionConfiguration {
* Config transaction context, then binding to current thread.
*
* @param transactionType transaction type
+ * @return transaction manager
*/
- void configTransactionContext(TransactionType transactionType);
+ TransactionManager configTransactionContext(TransactionType transactionType);
/**
* Subscribe transaction event using listener, register into event bus.
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
index ed20f114206e8..7093de5c1f817 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
@@ -34,15 +34,17 @@
public abstract class TransactionConfigurationAdapter implements TransactionConfiguration {
@Override
- public void configTransactionContext(final TransactionType transactionType) {
+ public TransactionManager configTransactionContext(final TransactionType transactionType) {
+ TransactionManager result = null;
switch (transactionType) {
case XA:
- doXaTransactionConfiguration();
+ result = doXaTransactionConfiguration();
break;
case BASE:
break;
default:
}
+ return result;
}
@Override
@@ -50,7 +52,7 @@ public void registerListener() {
TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance());
}
- protected abstract void doXaTransactionConfiguration();
+ protected abstract TransactionManager doXaTransactionConfiguration();
protected Optional doSPIConfiguration() {
Iterator iterator = ServiceLoader.load(TransactionManager.class).iterator();
From 140c20e3e409e39a0cfae461b4a3921e04870dc9 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 17:31:18 +0800
Subject: [PATCH 013/198] refactor RuleRegister using
ProxyTransactionConfiguration.
---
.../java/io/shardingsphere/proxy/config/RuleRegistry.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
index 8d88692a1f977..927e4065f9cf9 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
@@ -30,13 +30,13 @@
import io.shardingsphere.core.rule.MasterSlaveRule;
import io.shardingsphere.core.rule.ProxyAuthority;
import io.shardingsphere.core.rule.ShardingRule;
-import io.shardingsphere.transaction.common.spi.TransactionManager;
import io.shardingsphere.jdbc.orchestration.internal.OrchestrationProxyConfiguration;
import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent;
import io.shardingsphere.proxy.backend.constant.ProxyMode;
import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource;
import io.shardingsphere.proxy.metadata.ProxyShardingMetaData;
-import io.shardingsphere.transaction.ProxyTransactionLoader;
+import io.shardingsphere.transaction.common.config.ProxyTransactionConfiguration;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -112,7 +112,8 @@ public synchronized void init(final OrchestrationProxyConfiguration config) {
showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW);
proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE));
transactionType = TransactionType.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_TRANSACTION_MODE));
- transactionManager = ProxyTransactionLoader.load(transactionType);
+ transactionManager = ProxyTransactionConfiguration.getInstance().configTransactionContext(transactionType);
+ ProxyTransactionConfiguration.getInstance().registerListener();
maxWorkingThreads = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MAX_WORKING_THREADS);
proxyBackendUseNio = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_BACKEND_USE_NIO);
proxyBackendSimpleDbConnections = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_BACKEND_SIMPLE_DB_CONNECTIONS);
From b674da61a49129dc6b8d408e204db450f88438e7 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 17:38:33 +0800
Subject: [PATCH 014/198] refactor XaTransactionEngine using
ProxyTransactionConfiguration.
---
.../backend/jdbc/transaction/XaTransactionEngine.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
index 4d9f5b8ce1cc6..7b1af949a348b 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
@@ -19,11 +19,11 @@
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TCLType;
-import io.shardingsphere.transaction.common.TransactionContext;
+import io.shardingsphere.proxy.config.RuleRegistry;
+import io.shardingsphere.transaction.TransactionEventBusInstance;
+import io.shardingsphere.transaction.common.TransactionContextFactory;
import io.shardingsphere.transaction.common.TransactionContextHolder;
import io.shardingsphere.transaction.common.event.XaTransactionEvent;
-import io.shardingsphere.core.util.EventBusInstance;
-import io.shardingsphere.proxy.config.RuleRegistry;
import javax.transaction.Status;
import java.sql.SQLException;
@@ -45,8 +45,8 @@ public XaTransactionEngine(final String sql) {
public boolean execute() throws SQLException {
Optional tclType = parseSQL();
if (tclType.isPresent() && isInTransaction(tclType.get())) {
- TransactionContextHolder.set(new TransactionContext(RULE_REGISTRY.getTransactionManager(), RULE_REGISTRY.getTransactionType(), XaTransactionEvent.class));
- EventBusInstance.getInstance().post(new XaTransactionEvent(tclType.get(), getSql()));
+ TransactionContextHolder.set(TransactionContextFactory.newXAContext(RULE_REGISTRY.getTransactionManager()));
+ TransactionEventBusInstance.getInstance().post(new XaTransactionEvent(tclType.get(), getSql()));
return true;
}
return false;
From 61d0f83257487f7cebc49c4669cf2c4a8f98b51e Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 17:43:43 +0800
Subject: [PATCH 015/198] move EventBus to sharding-core for common using.
---
.../core/util/EventBusInstance.java | 0
.../jdbc/transaction/XaTransactionEngine.java | 4 +-
.../TransactionEventBusInstance.java | 42 -------------------
.../TransactionConfigurationAdapter.java | 4 +-
4 files changed, 4 insertions(+), 46 deletions(-)
rename {sharding-jdbc => sharding-core}/src/main/java/io/shardingsphere/core/util/EventBusInstance.java (100%)
delete mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/util/EventBusInstance.java b/sharding-core/src/main/java/io/shardingsphere/core/util/EventBusInstance.java
similarity index 100%
rename from sharding-jdbc/src/main/java/io/shardingsphere/core/util/EventBusInstance.java
rename to sharding-core/src/main/java/io/shardingsphere/core/util/EventBusInstance.java
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
index 7b1af949a348b..3dae64ee20f36 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
@@ -19,8 +19,8 @@
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TCLType;
+import io.shardingsphere.core.util.EventBusInstance;
import io.shardingsphere.proxy.config.RuleRegistry;
-import io.shardingsphere.transaction.TransactionEventBusInstance;
import io.shardingsphere.transaction.common.TransactionContextFactory;
import io.shardingsphere.transaction.common.TransactionContextHolder;
import io.shardingsphere.transaction.common.event.XaTransactionEvent;
@@ -46,7 +46,7 @@ public boolean execute() throws SQLException {
Optional tclType = parseSQL();
if (tclType.isPresent() && isInTransaction(tclType.get())) {
TransactionContextHolder.set(TransactionContextFactory.newXAContext(RULE_REGISTRY.getTransactionManager()));
- TransactionEventBusInstance.getInstance().post(new XaTransactionEvent(tclType.get(), getSql()));
+ EventBusInstance.getInstance().post(new XaTransactionEvent(tclType.get(), getSql()));
return true;
}
return false;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java
deleted file mode 100644
index c703d9867573b..0000000000000
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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 io.shardingsphere.transaction;
-
-import com.google.common.eventbus.EventBus;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-/**
- * Event bus for singleton instance.
- *
- * @author zhangliang
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class TransactionEventBusInstance {
-
- private static final EventBus INSTANCE = new EventBus();
-
- /**
- * Get event bus instance.
- *
- * @return event bus instance
- */
- public static EventBus getInstance() {
- return INSTANCE;
- }
-}
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
index 7093de5c1f817..525b2a7396ed6 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
@@ -19,7 +19,7 @@
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TransactionType;
-import io.shardingsphere.transaction.TransactionEventBusInstance;
+import io.shardingsphere.core.util.EventBusInstance;
import io.shardingsphere.transaction.common.listener.TransactionListener;
import io.shardingsphere.transaction.common.spi.TransactionManager;
@@ -49,7 +49,7 @@ public TransactionManager configTransactionContext(final TransactionType transac
@Override
public void registerListener() {
- TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance());
+ EventBusInstance.getInstance().register(TransactionListener.getInstance());
}
protected abstract TransactionManager doXaTransactionConfiguration();
From 6c6e9634ea95c17c27645fd6ad428c8c0a191ab6 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 18:05:54 +0800
Subject: [PATCH 016/198] add log for transactionConfiguration when existing
more than one SPI implement.
---
.../config/TransactionConfigurationAdapter.java | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
index 525b2a7396ed6..ffdb2258d317e 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
@@ -18,12 +18,14 @@
package io.shardingsphere.transaction.common.config;
import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
import io.shardingsphere.core.constant.TransactionType;
import io.shardingsphere.core.util.EventBusInstance;
import io.shardingsphere.transaction.common.listener.TransactionListener;
import io.shardingsphere.transaction.common.spi.TransactionManager;
+import lombok.extern.slf4j.Slf4j;
-import java.util.Iterator;
+import java.util.List;
import java.util.ServiceLoader;
/**
@@ -31,6 +33,7 @@
*
* @author zhaojun
*/
+@Slf4j
public abstract class TransactionConfigurationAdapter implements TransactionConfiguration {
@Override
@@ -55,7 +58,10 @@ public void registerListener() {
protected abstract TransactionManager doXaTransactionConfiguration();
protected Optional doSPIConfiguration() {
- Iterator iterator = ServiceLoader.load(TransactionManager.class).iterator();
- return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.absent();
+ List transactionManagerList = Lists.newArrayList(ServiceLoader.load(TransactionManager.class).iterator());
+ if (transactionManagerList.size() > 1) {
+ log.info("there is more than one transaction manger existing, chosen first one default.");
+ }
+ return transactionManagerList.isEmpty() ? Optional.absent() : Optional.of(transactionManagerList.get(0));
}
}
From 72d99b1181780bea65e7c39a3a8237aeb3fbf9bf Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 18:15:21 +0800
Subject: [PATCH 017/198] add transaction context for jdbc connection adapter.
---
.../core/jdbc/adapter/AbstractConnectionAdapter.java | 6 +++++-
.../transaction/common/TransactionContextHolder.java | 7 +++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
index 674a8c02e74b9..d5fa32626b918 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
@@ -22,10 +22,12 @@
import io.shardingsphere.core.hint.HintManagerHolder;
import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationConnection;
import io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager;
+import io.shardingsphere.core.util.EventBusInstance;
+import io.shardingsphere.transaction.common.TransactionContextHolder;
+import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration;
import io.shardingsphere.transaction.common.event.TransactionEvent;
import io.shardingsphere.transaction.common.event.TransactionEventFactory;
import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
-import io.shardingsphere.core.util.EventBusInstance;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -62,6 +64,7 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera
* @throws SQLException SQL exception
*/
public final Connection getConnection(final String dataSourceName) throws SQLException {
+ JDBCTransactionConfiguration.getInstance().configTransactionContext(TransactionContextHolder.get().getTransactionType());
if (cachedConnections.containsKey(dataSourceName)) {
return cachedConnections.get(dataSourceName);
}
@@ -106,6 +109,7 @@ public void close() throws SQLException {
closed = true;
HintManagerHolder.clear();
MasterVisitedManager.clear();
+ TransactionContextHolder.clear();
Collection exceptions = new LinkedList<>();
for (Connection each : cachedConnections.values()) {
try {
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java
index 676869ce12e4d..802892695294f 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java
@@ -48,4 +48,11 @@ public static TransactionContext get() {
public static void set(final TransactionContext context) {
CONTEXT.set(context);
}
+
+ /**
+ * Clear transaction context for current thread.
+ */
+ public static void clear() {
+ CONTEXT.remove();
+ }
}
From 0c8e9494348e1aa3905186de3b01907a0c9b1643 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 18:34:10 +0800
Subject: [PATCH 018/198] add local cache for transaction configuration
adapter.
---
.../TransactionConfigurationAdapter.java | 25 +++++++++++++------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
index ffdb2258d317e..399134254388d 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
@@ -25,7 +25,9 @@
import io.shardingsphere.transaction.common.spi.TransactionManager;
import lombok.extern.slf4j.Slf4j;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.ServiceLoader;
/**
@@ -36,12 +38,14 @@
@Slf4j
public abstract class TransactionConfigurationAdapter implements TransactionConfiguration {
+ private static final Map> SPI_RESOURCE = new HashMap<>();
+
@Override
public TransactionManager configTransactionContext(final TransactionType transactionType) {
TransactionManager result = null;
switch (transactionType) {
case XA:
- result = doXaTransactionConfiguration();
+ result = doXaTransactionConfiguration(transactionType);
break;
case BASE:
break;
@@ -55,13 +59,20 @@ public void registerListener() {
EventBusInstance.getInstance().register(TransactionListener.getInstance());
}
- protected abstract TransactionManager doXaTransactionConfiguration();
+ protected abstract TransactionManager doXaTransactionConfiguration(TransactionType transactionType);
- protected Optional doSPIConfiguration() {
- List transactionManagerList = Lists.newArrayList(ServiceLoader.load(TransactionManager.class).iterator());
- if (transactionManagerList.size() > 1) {
- log.info("there is more than one transaction manger existing, chosen first one default.");
+ protected Optional doSPIConfiguration(final TransactionType transactionType) {
+ if (SPI_RESOURCE.containsKey(transactionType)) {
+ return SPI_RESOURCE.get(transactionType);
+ }
+ synchronized (SPI_RESOURCE) {
+ List transactionManagerList = Lists.newArrayList(ServiceLoader.load(TransactionManager.class).iterator());
+ if (transactionManagerList.size() > 1) {
+ log.info("there is more than one transaction manger existing, chosen first one default.");
+ }
+ Optional transactionManager = transactionManagerList.isEmpty() ? Optional.absent() : Optional.of(transactionManagerList.get(0));
+ SPI_RESOURCE.put(transactionType, transactionManager);
+ return transactionManager;
}
- return transactionManagerList.isEmpty() ? Optional.absent() : Optional.of(transactionManagerList.get(0));
}
}
From 3b66870f1a5d61456136cf462d6d51b08a9e4d91 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 18:36:53 +0800
Subject: [PATCH 019/198] resolve compile error for JDBC and Proxy transaction
configuration.
---
.../common/config/JDBCTransactionConfiguration.java | 5 +++--
.../common/config/ProxyTransactionConfiguration.java | 5 +++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
index 27e5b53fbcba4..f29a8581901e8 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
@@ -18,6 +18,7 @@
package io.shardingsphere.transaction.common.config;
import com.google.common.base.Optional;
+import io.shardingsphere.core.constant.TransactionType;
import io.shardingsphere.transaction.common.TransactionContext;
import io.shardingsphere.transaction.common.TransactionContextFactory;
import io.shardingsphere.transaction.common.TransactionContextHolder;
@@ -45,8 +46,8 @@ public static JDBCTransactionConfiguration getInstance() {
}
@Override
- protected TransactionManager doXaTransactionConfiguration() {
- Optional transactionManager = doSPIConfiguration();
+ protected TransactionManager doXaTransactionConfiguration(final TransactionType transactionType) {
+ Optional transactionManager = doSPIConfiguration(transactionType);
TransactionContext transactionContext = transactionManager.isPresent()
? TransactionContextFactory.newXAContext(transactionManager.get()) : TransactionContextFactory.newWeakXAContext();
TransactionContextHolder.set(transactionContext);
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java
index fd4bce1f46a49..e30d7b17b07e0 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java
@@ -19,6 +19,7 @@
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import io.shardingsphere.core.constant.TransactionType;
import io.shardingsphere.transaction.common.TransactionContextFactory;
import io.shardingsphere.transaction.common.TransactionContextHolder;
import io.shardingsphere.transaction.common.spi.TransactionManager;
@@ -45,8 +46,8 @@ public static ProxyTransactionConfiguration getInstance() {
}
@Override
- protected TransactionManager doXaTransactionConfiguration() {
- Optional transactionManager = doSPIConfiguration();
+ protected TransactionManager doXaTransactionConfiguration(final TransactionType transactionType) {
+ Optional transactionManager = doSPIConfiguration(transactionType);
Preconditions.checkState(transactionManager.isPresent(), "there is no XA transaction manager existing, please prepare exactly one(Atomikos or Narayana) using SPI.");
TransactionContextHolder.set(TransactionContextFactory.newXAContext(transactionManager.get()));
return transactionManager.get();
From 8d0e0761f1df0cf567dbc45667d0bd8c25e90136 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 18:59:22 +0800
Subject: [PATCH 020/198] remove unused class.
---
.../transaction/ProxyTransactionLoader.java | 62 -----------------
.../transaction/TransactionLoader.java | 69 -------------------
2 files changed, 131 deletions(-)
delete mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.java
delete mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.java
deleted file mode 100644
index a4f277808ed8b..0000000000000
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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 io.shardingsphere.transaction;
-
-import io.shardingsphere.core.constant.TransactionType;
-import io.shardingsphere.transaction.common.listener.TransactionListener;
-import io.shardingsphere.transaction.common.spi.TransactionManager;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.util.Iterator;
-import java.util.ServiceLoader;
-
-/**
- * Transaction manager loader via SPI.
- *
- * @author zhaojun
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ProxyTransactionLoader {
-
- /**
- * Create transaction manager via SPI.
- *
- * @param transactionType transaction type
- * @return transaction manager
- */
- public static TransactionManager load(final TransactionType transactionType) {
- TransactionManager result = null;
- switch (transactionType) {
- case XA:
- result = doXaTransactionConfiguration();
- break;
- case BASE:
- break;
- default:
- }
- TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance());
- return result;
- }
-
- // TODO if read more transaction manager, log chosen one, if no transaction manager, throw exception
- private static TransactionManager doXaTransactionConfiguration() {
- Iterator iterator = ServiceLoader.load(TransactionManager.class).iterator();
- return iterator.hasNext() ? iterator.next() : null;
- }
-}
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java
deleted file mode 100644
index 1aa818c10f5d3..0000000000000
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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 io.shardingsphere.transaction;
-
-import io.shardingsphere.core.constant.TransactionType;
-import io.shardingsphere.transaction.common.TransactionContext;
-import io.shardingsphere.transaction.common.TransactionContextHolder;
-import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
-import io.shardingsphere.transaction.common.event.XaTransactionEvent;
-import io.shardingsphere.transaction.common.listener.TransactionListener;
-import io.shardingsphere.transaction.common.spi.TransactionManager;
-import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.util.Iterator;
-import java.util.ServiceLoader;
-
-/**
- * Loader Transaction spi with ServiceLoader.
- *
- * @author zhaojun
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class TransactionLoader {
-
- /**
- * Using ServiceLoader to dynamic load spi transaction.
- *
- */
- public static void load() {
- TransactionContext transactionContext = TransactionContextHolder.get();
- switch (transactionContext.getTransactionType()) {
- case XA:
- doXaTransactionConfiguration();
- break;
- case BASE:
- break;
- default:
- }
- TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance());
- }
-
- private static void doXaTransactionConfiguration() {
- Iterator iterator = ServiceLoader.load(TransactionManager.class).iterator();
- TransactionContext transactionContext;
- if (iterator.hasNext()) {
- transactionContext = new TransactionContext(iterator.next(), TransactionType.XA, XaTransactionEvent.class);
- } else {
- transactionContext = new TransactionContext(new WeakXaTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class);
- }
- TransactionContextHolder.set(transactionContext);
- }
-}
From cbbd4f6de564fdffa8971d18245788b5a220b3f3 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 19:16:39 +0800
Subject: [PATCH 021/198] Merge branch 'dev' of
https://github.com/sharding-sphere/sharding-sphere into
sharding-proxy-xa-transaction
# Conflicts:
# sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
# sharding-proxy/src/main/java/io/shardingsphere/proxy/util/ProxyTransactionLoader.java
---
.../io/shardingsphere/proxy/config/RuleRegistry.java | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
index 18fc685979014..26c21eb5ceaa7 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
@@ -24,19 +24,19 @@
import io.shardingsphere.core.constant.ShardingProperties;
import io.shardingsphere.core.constant.ShardingPropertiesConstant;
import io.shardingsphere.core.constant.TransactionType;
-import io.shardingsphere.core.metadata.table.ShardingTableMetaData;
import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData;
+import io.shardingsphere.core.metadata.table.ShardingTableMetaData;
import io.shardingsphere.core.rule.DataSourceParameter;
import io.shardingsphere.core.rule.MasterSlaveRule;
import io.shardingsphere.core.rule.ProxyAuthority;
import io.shardingsphere.core.rule.ShardingRule;
-import io.shardingsphere.core.transaction.spi.TransactionManager;
import io.shardingsphere.jdbc.orchestration.internal.OrchestrationProxyConfiguration;
import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent;
import io.shardingsphere.proxy.backend.constant.ProxyMode;
import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource;
import io.shardingsphere.proxy.metadata.ProxyShardingTableMetaData;
-import io.shardingsphere.proxy.util.ProxyTransactionLoader;
+import io.shardingsphere.transaction.common.config.ProxyTransactionConfiguration;
+import io.shardingsphere.transaction.common.spi.TransactionManager;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -112,7 +112,8 @@ public synchronized void init(final OrchestrationProxyConfiguration config) {
showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW);
proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE));
transactionType = TransactionType.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_TRANSACTION_MODE));
- transactionManager = ProxyTransactionLoader.load(transactionType);
+ transactionManager = ProxyTransactionConfiguration.getInstance().configTransactionContext(transactionType);
+ ProxyTransactionConfiguration.getInstance().registerListener();
maxWorkingThreads = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MAX_WORKING_THREADS);
proxyBackendUseNio = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_BACKEND_USE_NIO);
proxyBackendSimpleDbConnections = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_BACKEND_SIMPLE_DB_CONNECTIONS);
From f2330692202c1f4e32abdf19c38c562544c829b8 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Mon, 30 Jul 2018 19:18:03 +0800
Subject: [PATCH 022/198] config file revert.
---
.../src/main/resources/conf/config.yaml | 199 ++++++------------
sharding-proxy/src/main/resources/logback.xml | 4 +-
2 files changed, 69 insertions(+), 134 deletions(-)
diff --git a/sharding-proxy/src/main/resources/conf/config.yaml b/sharding-proxy/src/main/resources/conf/config.yaml
index 723ddb7048472..9bb12cfdd3c72 100644
--- a/sharding-proxy/src/main/resources/conf/config.yaml
+++ b/sharding-proxy/src/main/resources/conf/config.yaml
@@ -1,142 +1,77 @@
################## ##################
# Here you can configure the rules for the proxy.
#
-# We provide two kinds of configurations for example. The one is the configuration of Sharding rule,
-# and the other is the configuration of master-slave rule.
-# If you want to use Sharding, please refer to the first one, and if you only want to use master-slave,
-# please refer to the second one.
+# We provide two kinds of configurations for example. This one is the configuration of Sharding rule,
+# If you want to use Sharding, please refer to the this one, and if you only want to use master-slave,
+# please refer to config_master_slave.yaml.
#
################## ##################
-
# The example of Sharding rule.
-dataSources:
- ds_0:
- url: jdbc:mysql://127.0.0.1:3306/ds_trans_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_trans_1?serverTimezone=UTC&useSSL=false
- username: root
- password:
- autoCommit: true
- connectionTimeout: 30000
- idleTimeout: 60000
- maxLifetime: 1800000
- maximumPoolSize: 65
- ds_2:
- url: jdbc:mysql://127.0.0.1:3306/ds_trans_2?serverTimezone=UTC&useSSL=false
- username: root
- password:
- autoCommit: true
- connectionTimeout: 30000
- idleTimeout: 60000
- maxLifetime: 1800000
- maximumPoolSize: 65
- ds_3:
- url: jdbc:mysql://127.0.0.1:3306/ds_trans_3?serverTimezone=UTC&useSSL=false
- username: root
- password:
- autoCommit: true
- connectionTimeout: 30000
- idleTimeout: 60000
- maxLifetime: 1800000
- maximumPoolSize: 65
- ds_4:
- url: jdbc:mysql://127.0.0.1:3306/ds_trans_4?serverTimezone=UTC&useSSL=false
- username: root
- password:
- autoCommit: true
- connectionTimeout: 30000
- idleTimeout: 60000
- maxLifetime: 1800000
- maximumPoolSize: 65
- ds_5:
- url: jdbc:mysql://127.0.0.1:3306/ds_trans_5?serverTimezone=UTC&useSSL=false
- username: root
- password:
- autoCommit: true
- connectionTimeout: 30000
- idleTimeout: 60000
- maxLifetime: 1800000
- maximumPoolSize: 65
- ds_6:
- url: jdbc:mysql://127.0.0.1:3306/ds_trans_6?serverTimezone=UTC&useSSL=false
- username: root
- password:
- autoCommit: true
- connectionTimeout: 30000
- idleTimeout: 60000
- maxLifetime: 1800000
- maximumPoolSize: 65
- ds_7:
- url: jdbc:mysql://127.0.0.1:3306/ds_trans_7?serverTimezone=UTC&useSSL=false
- username: root
- password:
- autoCommit: true
- connectionTimeout: 30000
- idleTimeout: 60000
- maxLifetime: 1800000
- maximumPoolSize: 65
- ds_8:
- url: jdbc:mysql://127.0.0.1:3306/ds_trans_8?serverTimezone=UTC&useSSL=false
- username: root
- password:
- autoCommit: true
- connectionTimeout: 30000
- idleTimeout: 60000
- maxLifetime: 1800000
- maximumPoolSize: 65
- ds_9:
- url: jdbc:mysql://127.0.0.1:3306/ds_trans_9?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
+#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.
+# proxy.mode: MEMORY_STRICTLY
+# proxy.transaction.mode: NONE
+# proxy.max.working.threads: 16
+# sql.show: false
- 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.
- proxy.mode: CONNECTION_STRICTLY
- proxy.transaction.mode: NONE
- proxy.max.working.threads: 16
- sql.show: false
+#orchestration:
+# name: orchestration_ds
+# type: SHARDING
+# overwrite: true
+# zookeeper:
+# namespace: orchestration
+# serverLists: localhost:2181
-proxyAuthority:
- username: root
- password: root
\ No newline at end of file
+#proxyAuthority:
+# username: root
+# password: root
\ No newline at end of file
diff --git a/sharding-proxy/src/main/resources/logback.xml b/sharding-proxy/src/main/resources/logback.xml
index 733a52031a8c7..35eedd49dc958 100644
--- a/sharding-proxy/src/main/resources/logback.xml
+++ b/sharding-proxy/src/main/resources/logback.xml
@@ -9,9 +9,9 @@
-
+
-
+
From b9e2ff16fa0e934164bdf43c74f28d5aad18034a Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Tue, 31 Jul 2018 10:28:12 +0800
Subject: [PATCH 023/198] adjust weakXATransaction manager package.
---
.../transaction/common/TransactionContextFactory.java | 2 +-
.../transaction/{weakxa => xa}/WeakXaTransactionManager.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{weakxa => xa}/WeakXaTransactionManager.java (98%)
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
index 4e7083b620c48..5330433b4f6c8 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
@@ -21,7 +21,7 @@
import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
import io.shardingsphere.transaction.common.event.XaTransactionEvent;
import io.shardingsphere.transaction.common.spi.TransactionManager;
-import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager;
+import io.shardingsphere.transaction.xa.WeakXaTransactionManager;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/weakxa/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java
similarity index 98%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/weakxa/WeakXaTransactionManager.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java
index 3c8de3438a966..412d10eea3a0b 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/weakxa/WeakXaTransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.transaction.weakxa;
+package io.shardingsphere.transaction.xa;
import io.shardingsphere.transaction.common.event.TransactionEvent;
import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
From 91f1de4e22ef23c08a59d3f1c533d2611dcb5f04 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Tue, 31 Jul 2018 10:33:43 +0800
Subject: [PATCH 024/198] adjust transaction event package.
---
.../core/jdbc/adapter/AbstractConnectionAdapter.java | 6 +++---
.../proxy/backend/jdbc/transaction/XaTransactionEngine.java | 2 +-
.../transaction/common/TransactionContext.java | 4 ++--
.../transaction/common/TransactionContextFactory.java | 4 ++--
.../transaction/common/listener/TransactionListener.java | 2 +-
.../transaction/common/spi/TransactionManager.java | 2 +-
.../transaction/{common => }/event/TransactionEvent.java | 2 +-
.../{common => }/event/TransactionEventFactory.java | 2 +-
.../{common => }/event/WeakXaTransactionEvent.java | 2 +-
.../transaction/{common => }/event/XaTransactionEvent.java | 2 +-
.../transaction/xa/AtomikosTransactionManager.java | 2 +-
.../transaction/xa/WeakXaTransactionManager.java | 4 ++--
12 files changed, 17 insertions(+), 17 deletions(-)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{common => }/event/TransactionEvent.java (96%)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{common => }/event/TransactionEventFactory.java (96%)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{common => }/event/WeakXaTransactionEvent.java (96%)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{common => }/event/XaTransactionEvent.java (96%)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
index d5fa32626b918..d49b06288aaf3 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
@@ -25,9 +25,9 @@
import io.shardingsphere.core.util.EventBusInstance;
import io.shardingsphere.transaction.common.TransactionContextHolder;
import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration;
-import io.shardingsphere.transaction.common.event.TransactionEvent;
-import io.shardingsphere.transaction.common.event.TransactionEventFactory;
-import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.event.TransactionEvent;
+import io.shardingsphere.transaction.event.TransactionEventFactory;
+import io.shardingsphere.transaction.event.WeakXaTransactionEvent;
import javax.sql.DataSource;
import java.sql.Connection;
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
index 3dae64ee20f36..dfe74505d9b35 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
@@ -23,7 +23,7 @@
import io.shardingsphere.proxy.config.RuleRegistry;
import io.shardingsphere.transaction.common.TransactionContextFactory;
import io.shardingsphere.transaction.common.TransactionContextHolder;
-import io.shardingsphere.transaction.common.event.XaTransactionEvent;
+import io.shardingsphere.transaction.event.XaTransactionEvent;
import javax.transaction.Status;
import java.sql.SQLException;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
index 6dff8a5832162..bcf80b4a98aec 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
@@ -18,8 +18,8 @@
package io.shardingsphere.transaction.common;
import io.shardingsphere.core.constant.TransactionType;
-import io.shardingsphere.transaction.common.event.TransactionEvent;
-import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.event.TransactionEvent;
+import io.shardingsphere.transaction.event.WeakXaTransactionEvent;
import io.shardingsphere.transaction.common.spi.TransactionManager;
import lombok.Getter;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
index 5330433b4f6c8..4801dab71c81d 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
@@ -18,8 +18,8 @@
package io.shardingsphere.transaction.common;
import io.shardingsphere.core.constant.TransactionType;
-import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
-import io.shardingsphere.transaction.common.event.XaTransactionEvent;
+import io.shardingsphere.transaction.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.event.XaTransactionEvent;
import io.shardingsphere.transaction.common.spi.TransactionManager;
import io.shardingsphere.transaction.xa.WeakXaTransactionManager;
import lombok.AccessLevel;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java
index 5e131b22bc517..837e5aac1d74d 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java
@@ -20,7 +20,7 @@
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import io.shardingsphere.transaction.common.TransactionContextHolder;
-import io.shardingsphere.transaction.common.event.TransactionEvent;
+import io.shardingsphere.transaction.event.TransactionEvent;
import io.shardingsphere.transaction.common.spi.TransactionManager;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java
index 6c06cd29f172a..98dd54bd3696f 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java
@@ -17,7 +17,7 @@
package io.shardingsphere.transaction.common.spi;
-import io.shardingsphere.transaction.common.event.TransactionEvent;
+import io.shardingsphere.transaction.event.TransactionEvent;
import java.sql.SQLException;
/**
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEvent.java
similarity index 96%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEvent.java
index 5c02c1b41c74a..c0b1321420bcf 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEvent.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.transaction.common.event;
+package io.shardingsphere.transaction.event;
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TCLType;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEventFactory.java
similarity index 96%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEventFactory.java
index 133914168c293..0148059ff18b4 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEventFactory.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.transaction.common.event;
+package io.shardingsphere.transaction.event;
import io.shardingsphere.core.constant.TCLType;
import io.shardingsphere.transaction.common.TransactionContextHolder;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/WeakXaTransactionEvent.java
similarity index 96%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/event/WeakXaTransactionEvent.java
index f1bb7bcec60c4..006875de72479 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/WeakXaTransactionEvent.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.transaction.common.event;
+package io.shardingsphere.transaction.event;
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TCLType;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/XaTransactionEvent.java
similarity index 96%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/event/XaTransactionEvent.java
index 67c9dd5ecd15c..202ed83b8e07b 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/XaTransactionEvent.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.transaction.common.event;
+package io.shardingsphere.transaction.event;
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TCLType;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java
index 290552baf7211..dd79210cbf1c8 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java
@@ -18,7 +18,7 @@
package io.shardingsphere.transaction.xa;
import com.atomikos.icatch.jta.UserTransactionManager;
-import io.shardingsphere.transaction.common.event.TransactionEvent;
+import io.shardingsphere.transaction.event.TransactionEvent;
import io.shardingsphere.transaction.common.spi.TransactionManager;
import javax.transaction.HeuristicMixedException;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java
index 412d10eea3a0b..5162d80904e46 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java
@@ -17,8 +17,8 @@
package io.shardingsphere.transaction.xa;
-import io.shardingsphere.transaction.common.event.TransactionEvent;
-import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.event.TransactionEvent;
+import io.shardingsphere.transaction.event.WeakXaTransactionEvent;
import io.shardingsphere.transaction.common.spi.TransactionManager;
import java.sql.Connection;
From 1305d45baa9f15ce9a8024849ff32fccd6604264 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Tue, 31 Jul 2018 10:55:06 +0800
Subject: [PATCH 025/198] move xa and base transaction to api package.
---
.../java/io/shardingsphere/proxy/config/RuleRegistry.java | 2 +-
.../io.shardingsphere.transaction.api.TransactionManager | 1 +
...o.shardingsphere.transaction.common.spi.TransactionManager | 1 -
.../transaction/{common/spi => api}/TransactionManager.java | 2 +-
.../transaction/{ => api}/xa/AtomikosTransactionManager.java | 4 ++--
.../transaction/{ => api}/xa/AtomikosUserTransaction.java | 2 +-
.../transaction/{ => api}/xa/WeakXaTransactionManager.java | 4 ++--
.../shardingsphere/transaction/common/TransactionContext.java | 2 +-
.../transaction/common/TransactionContextFactory.java | 4 ++--
.../common/config/JDBCTransactionConfiguration.java | 2 +-
.../common/config/ProxyTransactionConfiguration.java | 2 +-
.../transaction/common/config/TransactionConfiguration.java | 2 +-
.../common/config/TransactionConfigurationAdapter.java | 4 ++--
.../{common => }/listener/TransactionListener.java | 4 ++--
14 files changed, 18 insertions(+), 18 deletions(-)
create mode 100644 sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager
delete mode 100644 sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.common.spi.TransactionManager
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{common/spi => api}/TransactionManager.java (97%)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => api}/xa/AtomikosTransactionManager.java (95%)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => api}/xa/AtomikosUserTransaction.java (96%)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => api}/xa/WeakXaTransactionManager.java (96%)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{common => }/listener/TransactionListener.java (94%)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
index 26c21eb5ceaa7..17adc18de1fa7 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
@@ -35,8 +35,8 @@
import io.shardingsphere.proxy.backend.constant.ProxyMode;
import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource;
import io.shardingsphere.proxy.metadata.ProxyShardingTableMetaData;
+import io.shardingsphere.transaction.api.TransactionManager;
import io.shardingsphere.transaction.common.config.ProxyTransactionConfiguration;
-import io.shardingsphere.transaction.common.spi.TransactionManager;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
diff --git a/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager
new file mode 100644
index 0000000000000..c41e2fba94e9e
--- /dev/null
+++ b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager
@@ -0,0 +1 @@
+io.shardingsphere.transaction.api.xa.AtomikosTransactionManager
\ No newline at end of file
diff --git a/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.common.spi.TransactionManager b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.common.spi.TransactionManager
deleted file mode 100644
index bfa7798479eba..0000000000000
--- a/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.common.spi.TransactionManager
+++ /dev/null
@@ -1 +0,0 @@
-io.shardingsphere.transaction.xa.AtomikosTransactionManager
\ No newline at end of file
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java
similarity index 97%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java
index 98dd54bd3696f..645e8d0277fab 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.transaction.common.spi;
+package io.shardingsphere.transaction.api;
import io.shardingsphere.transaction.event.TransactionEvent;
import java.sql.SQLException;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java
similarity index 95%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java
index dd79210cbf1c8..47162618d7a61 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java
@@ -15,11 +15,11 @@
*
*/
-package io.shardingsphere.transaction.xa;
+package io.shardingsphere.transaction.api.xa;
import com.atomikos.icatch.jta.UserTransactionManager;
+import io.shardingsphere.transaction.api.TransactionManager;
import io.shardingsphere.transaction.event.TransactionEvent;
-import io.shardingsphere.transaction.common.spi.TransactionManager;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosUserTransaction.java
similarity index 96%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosUserTransaction.java
index 117f8671f8918..137c89ad32787 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosUserTransaction.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.transaction.xa;
+package io.shardingsphere.transaction.api.xa;
import com.atomikos.icatch.jta.UserTransactionManager;
import lombok.AccessLevel;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java
similarity index 96%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java
index 5162d80904e46..5ad04464918ef 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java
@@ -15,11 +15,11 @@
*
*/
-package io.shardingsphere.transaction.xa;
+package io.shardingsphere.transaction.api.xa;
+import io.shardingsphere.transaction.api.TransactionManager;
import io.shardingsphere.transaction.event.TransactionEvent;
import io.shardingsphere.transaction.event.WeakXaTransactionEvent;
-import io.shardingsphere.transaction.common.spi.TransactionManager;
import java.sql.Connection;
import java.sql.SQLException;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
index bcf80b4a98aec..3779ad40b353c 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
@@ -18,9 +18,9 @@
package io.shardingsphere.transaction.common;
import io.shardingsphere.core.constant.TransactionType;
+import io.shardingsphere.transaction.api.TransactionManager;
import io.shardingsphere.transaction.event.TransactionEvent;
import io.shardingsphere.transaction.event.WeakXaTransactionEvent;
-import io.shardingsphere.transaction.common.spi.TransactionManager;
import lombok.Getter;
/**
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
index 4801dab71c81d..c562bcb857c38 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
@@ -18,10 +18,10 @@
package io.shardingsphere.transaction.common;
import io.shardingsphere.core.constant.TransactionType;
+import io.shardingsphere.transaction.api.TransactionManager;
import io.shardingsphere.transaction.event.WeakXaTransactionEvent;
import io.shardingsphere.transaction.event.XaTransactionEvent;
-import io.shardingsphere.transaction.common.spi.TransactionManager;
-import io.shardingsphere.transaction.xa.WeakXaTransactionManager;
+import io.shardingsphere.transaction.api.xa.WeakXaTransactionManager;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
index f29a8581901e8..486b7a6823e88 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java
@@ -19,10 +19,10 @@
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TransactionType;
+import io.shardingsphere.transaction.api.TransactionManager;
import io.shardingsphere.transaction.common.TransactionContext;
import io.shardingsphere.transaction.common.TransactionContextFactory;
import io.shardingsphere.transaction.common.TransactionContextHolder;
-import io.shardingsphere.transaction.common.spi.TransactionManager;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java
index e30d7b17b07e0..e63ef806d52bf 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java
@@ -20,9 +20,9 @@
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import io.shardingsphere.core.constant.TransactionType;
+import io.shardingsphere.transaction.api.TransactionManager;
import io.shardingsphere.transaction.common.TransactionContextFactory;
import io.shardingsphere.transaction.common.TransactionContextHolder;
-import io.shardingsphere.transaction.common.spi.TransactionManager;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java
index 3a8b276fc3808..76533870eba55 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java
@@ -18,7 +18,7 @@
package io.shardingsphere.transaction.common.config;
import io.shardingsphere.core.constant.TransactionType;
-import io.shardingsphere.transaction.common.spi.TransactionManager;
+import io.shardingsphere.transaction.api.TransactionManager;
/**
* Execute transaction manager configuration.
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
index 399134254388d..9d0bddc090ca3 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
@@ -21,8 +21,8 @@
import com.google.common.collect.Lists;
import io.shardingsphere.core.constant.TransactionType;
import io.shardingsphere.core.util.EventBusInstance;
-import io.shardingsphere.transaction.common.listener.TransactionListener;
-import io.shardingsphere.transaction.common.spi.TransactionManager;
+import io.shardingsphere.transaction.api.TransactionManager;
+import io.shardingsphere.transaction.listener.TransactionListener;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/TransactionListener.java
similarity index 94%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/TransactionListener.java
index 837e5aac1d74d..08530020d9e14 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/TransactionListener.java
@@ -15,13 +15,13 @@
*
*/
-package io.shardingsphere.transaction.common.listener;
+package io.shardingsphere.transaction.listener;
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
+import io.shardingsphere.transaction.api.TransactionManager;
import io.shardingsphere.transaction.common.TransactionContextHolder;
import io.shardingsphere.transaction.event.TransactionEvent;
-import io.shardingsphere.transaction.common.spi.TransactionManager;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
From bed9514cec4cfeff7e0db4b6c2e9b386cad007fb Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Tue, 31 Jul 2018 11:05:11 +0800
Subject: [PATCH 026/198] adjust transaction common package.
---
.../core/jdbc/adapter/AbstractConnectionAdapter.java | 6 +++---
.../proxy/backend/jdbc/transaction/XaTransactionEngine.java | 2 +-
.../shardingsphere/transaction/api/TransactionManager.java | 2 +-
.../transaction/api/xa/AtomikosTransactionManager.java | 2 +-
.../transaction/api/xa/WeakXaTransactionManager.java | 4 ++--
.../transaction/common/TransactionContext.java | 4 ++--
.../transaction/common/TransactionContextFactory.java | 4 ++--
.../common/config/TransactionConfigurationAdapter.java | 2 +-
.../transaction/{ => common}/event/TransactionEvent.java | 2 +-
.../{ => common}/event/TransactionEventFactory.java | 2 +-
.../{ => common}/event/WeakXaTransactionEvent.java | 2 +-
.../transaction/{ => common}/event/XaTransactionEvent.java | 2 +-
.../{ => common}/listener/TransactionListener.java | 4 ++--
13 files changed, 19 insertions(+), 19 deletions(-)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => common}/event/TransactionEvent.java (96%)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => common}/event/TransactionEventFactory.java (96%)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => common}/event/WeakXaTransactionEvent.java (96%)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => common}/event/XaTransactionEvent.java (96%)
rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => common}/listener/TransactionListener.java (94%)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
index d49b06288aaf3..d5fa32626b918 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
@@ -25,9 +25,9 @@
import io.shardingsphere.core.util.EventBusInstance;
import io.shardingsphere.transaction.common.TransactionContextHolder;
import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration;
-import io.shardingsphere.transaction.event.TransactionEvent;
-import io.shardingsphere.transaction.event.TransactionEventFactory;
-import io.shardingsphere.transaction.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.common.event.TransactionEvent;
+import io.shardingsphere.transaction.common.event.TransactionEventFactory;
+import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
import javax.sql.DataSource;
import java.sql.Connection;
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
index dfe74505d9b35..3dae64ee20f36 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
@@ -23,7 +23,7 @@
import io.shardingsphere.proxy.config.RuleRegistry;
import io.shardingsphere.transaction.common.TransactionContextFactory;
import io.shardingsphere.transaction.common.TransactionContextHolder;
-import io.shardingsphere.transaction.event.XaTransactionEvent;
+import io.shardingsphere.transaction.common.event.XaTransactionEvent;
import javax.transaction.Status;
import java.sql.SQLException;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java
index 645e8d0277fab..8dc49da1ea869 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java
@@ -17,7 +17,7 @@
package io.shardingsphere.transaction.api;
-import io.shardingsphere.transaction.event.TransactionEvent;
+import io.shardingsphere.transaction.common.event.TransactionEvent;
import java.sql.SQLException;
/**
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java
index 47162618d7a61..bde3f3fa4e16c 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java
@@ -19,7 +19,7 @@
import com.atomikos.icatch.jta.UserTransactionManager;
import io.shardingsphere.transaction.api.TransactionManager;
-import io.shardingsphere.transaction.event.TransactionEvent;
+import io.shardingsphere.transaction.common.event.TransactionEvent;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java
index 5ad04464918ef..6025dba35b4e1 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java
@@ -18,8 +18,8 @@
package io.shardingsphere.transaction.api.xa;
import io.shardingsphere.transaction.api.TransactionManager;
-import io.shardingsphere.transaction.event.TransactionEvent;
-import io.shardingsphere.transaction.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.common.event.TransactionEvent;
+import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
import java.sql.Connection;
import java.sql.SQLException;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
index 3779ad40b353c..58941d29bd2ac 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
@@ -19,8 +19,8 @@
import io.shardingsphere.core.constant.TransactionType;
import io.shardingsphere.transaction.api.TransactionManager;
-import io.shardingsphere.transaction.event.TransactionEvent;
-import io.shardingsphere.transaction.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.common.event.TransactionEvent;
+import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
import lombok.Getter;
/**
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
index c562bcb857c38..15aa2f4ec5be9 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
@@ -19,8 +19,8 @@
import io.shardingsphere.core.constant.TransactionType;
import io.shardingsphere.transaction.api.TransactionManager;
-import io.shardingsphere.transaction.event.WeakXaTransactionEvent;
-import io.shardingsphere.transaction.event.XaTransactionEvent;
+import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
+import io.shardingsphere.transaction.common.event.XaTransactionEvent;
import io.shardingsphere.transaction.api.xa.WeakXaTransactionManager;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
index 9d0bddc090ca3..8f661a53fffe8 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java
@@ -22,7 +22,7 @@
import io.shardingsphere.core.constant.TransactionType;
import io.shardingsphere.core.util.EventBusInstance;
import io.shardingsphere.transaction.api.TransactionManager;
-import io.shardingsphere.transaction.listener.TransactionListener;
+import io.shardingsphere.transaction.common.listener.TransactionListener;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java
similarity index 96%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEvent.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java
index c0b1321420bcf..5c02c1b41c74a 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEvent.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.transaction.event;
+package io.shardingsphere.transaction.common.event;
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TCLType;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEventFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java
similarity index 96%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEventFactory.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java
index 0148059ff18b4..133914168c293 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEventFactory.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.transaction.event;
+package io.shardingsphere.transaction.common.event;
import io.shardingsphere.core.constant.TCLType;
import io.shardingsphere.transaction.common.TransactionContextHolder;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/WeakXaTransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java
similarity index 96%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/event/WeakXaTransactionEvent.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java
index 006875de72479..f1bb7bcec60c4 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/WeakXaTransactionEvent.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.transaction.event;
+package io.shardingsphere.transaction.common.event;
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TCLType;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/XaTransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java
similarity index 96%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/event/XaTransactionEvent.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java
index 202ed83b8e07b..67c9dd5ecd15c 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/XaTransactionEvent.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.transaction.event;
+package io.shardingsphere.transaction.common.event;
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.TCLType;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/TransactionListener.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java
similarity index 94%
rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/TransactionListener.java
rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java
index 08530020d9e14..2c19bbd9b9ad3 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/TransactionListener.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java
@@ -15,13 +15,13 @@
*
*/
-package io.shardingsphere.transaction.listener;
+package io.shardingsphere.transaction.common.listener;
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import io.shardingsphere.transaction.api.TransactionManager;
import io.shardingsphere.transaction.common.TransactionContextHolder;
-import io.shardingsphere.transaction.event.TransactionEvent;
+import io.shardingsphere.transaction.common.event.TransactionEvent;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
From d6d5137d58b6f37b69cab38d73be7ae50467c92e Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Tue, 31 Jul 2018 11:10:04 +0800
Subject: [PATCH 027/198] add saga transaction manager for package placeholder.
---
.../api/base/SagaTransactionManager.java | 51 +++++++++++++++++++
1 file changed, 51 insertions(+)
create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java
new file mode 100644
index 0000000000000..396d8695b70ef
--- /dev/null
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed 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 io.shardingsphere.transaction.api.base;
+
+import io.shardingsphere.transaction.api.TransactionManager;
+import io.shardingsphere.transaction.common.event.TransactionEvent;
+
+import java.sql.SQLException;
+
+/**
+ * Saga transaction manager for sharding-sphere.
+ *
+ * @author zhaojun
+ */
+public class SagaTransactionManager implements TransactionManager {
+
+ @Override
+ public void begin(final TransactionEvent transactionEvent) throws SQLException {
+
+ }
+
+ @Override
+ public void commit(final TransactionEvent transactionEvent) throws SQLException {
+
+ }
+
+ @Override
+ public void rollback(final TransactionEvent transactionEvent) throws SQLException {
+
+ }
+
+ @Override
+ public int getStatus() throws SQLException {
+ return 0;
+ }
+}
From c266830346316c77e4bd7b4e6b7b2315443b2ce6 Mon Sep 17 00:00:00 2001
From: cherrylzhao
Date: Tue, 31 Jul 2018 11:16:28 +0800
Subject: [PATCH 028/198] make WeakXaTransactionManager is singleton.
---
.../api/xa/WeakXaTransactionManager.java | 14 ++++++++++++++
.../common/TransactionContextFactory.java | 2 +-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java
index 6025dba35b4e1..bdc90c2bc5aeb 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java
@@ -20,6 +20,8 @@
import io.shardingsphere.transaction.api.TransactionManager;
import io.shardingsphere.transaction.common.event.TransactionEvent;
import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import java.sql.Connection;
import java.sql.SQLException;
@@ -31,8 +33,20 @@
*
* @author zhaojun
*/
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class WeakXaTransactionManager implements TransactionManager {
+ private static final WeakXaTransactionManager TRANSACTION_MANAGER = new WeakXaTransactionManager();
+
+ /**
+ * Get singleton instance of {@code WeakXaTransactionManager}.
+ *
+ * @return weak XA transaction manager
+ */
+ public static WeakXaTransactionManager getInstance() {
+ return TRANSACTION_MANAGER;
+ }
+
@Override
public void begin(final TransactionEvent transactionEvent) throws SQLException {
WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) transactionEvent;
diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
index 15aa2f4ec5be9..90a7a3baba612 100644
--- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
+++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java
@@ -49,6 +49,6 @@ public static TransactionContext newXAContext(final TransactionManager transacti
* @return weak XA transaction context
*/
public static TransactionContext newWeakXAContext() {
- return new TransactionContext(new WeakXaTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class);
+ return new TransactionContext(WeakXaTransactionManager.getInstance(), TransactionType.XA, WeakXaTransactionEvent.class);
}
}
From a6b6a7bb1585380b0b3d4cac22e0cc76e4bd28d5 Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Fri, 3 Aug 2018 17:54:15 +0800
Subject: [PATCH 029/198] move it to core module.
---
.../main/java/io/shardingsphere/core}/constant/ProxyMode.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
rename {sharding-proxy/src/main/java/io/shardingsphere/proxy/backend => sharding-core/src/main/java/io/shardingsphere/core}/constant/ProxyMode.java (94%)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/constant/ProxyMode.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/ProxyMode.java
similarity index 94%
rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/constant/ProxyMode.java
rename to sharding-core/src/main/java/io/shardingsphere/core/constant/ProxyMode.java
index 975b318f81289..b09a4797acd90 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/constant/ProxyMode.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/constant/ProxyMode.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.proxy.backend.constant;
+package io.shardingsphere.core.constant;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
From 40465bcc40c0d344a579bed7e175029b539d5ee1 Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Fri, 3 Aug 2018 17:55:01 +0800
Subject: [PATCH 030/198] change import position.
---
.../proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java | 2 +-
.../main/java/io/shardingsphere/proxy/config/RuleRegistry.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java
index ea523d354959c..b99fe86658050 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java
@@ -17,7 +17,7 @@
package io.shardingsphere.proxy.backend.jdbc.execute;
-import io.shardingsphere.proxy.backend.constant.ProxyMode;
+import io.shardingsphere.core.constant.ProxyMode;
import io.shardingsphere.proxy.backend.jdbc.connection.BackendConnection;
import io.shardingsphere.proxy.backend.jdbc.execute.memory.ConnectionStrictlyExecuteEngine;
import io.shardingsphere.proxy.backend.jdbc.execute.stream.MemoryStrictlyExecuteEngine;
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
index a64c2594e9496..6b2b41c1eb28b 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
@@ -35,7 +35,7 @@
import io.shardingsphere.core.transaction.spi.TransactionManager;
import io.shardingsphere.jdbc.orchestration.internal.OrchestrationProxyConfiguration;
import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent;
-import io.shardingsphere.proxy.backend.constant.ProxyMode;
+import io.shardingsphere.core.constant.ProxyMode;
import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource;
import io.shardingsphere.proxy.util.ProxyTransactionLoader;
import lombok.AccessLevel;
From d1b93fb050be404612e3633356d17645e337b4bb Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Sun, 5 Aug 2018 19:43:44 +0800
Subject: [PATCH 031/198] change ProxyMode usagek
---
.../core/jdbc/core/datasource/ShardingDataSource.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java
index 8c535618ff91a..ca7ca8f0fb95b 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java
@@ -20,6 +20,7 @@
import io.shardingsphere.core.api.ConfigMapContext;
import io.shardingsphere.core.api.config.MasterSlaveRuleConfiguration;
import io.shardingsphere.core.api.config.ShardingRuleConfiguration;
+import io.shardingsphere.core.constant.ProxyMode;
import io.shardingsphere.core.constant.ShardingProperties;
import io.shardingsphere.core.constant.ShardingPropertiesConstant;
import io.shardingsphere.core.executor.ExecutorEngine;
@@ -72,6 +73,7 @@ public ShardingDataSource(final Map dataSourceMap, final Sha
ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData(
new TableMetaDataInitializer(executorEngine.getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(dataSourceMap)).load(shardingRule));
boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW);
+ ProxyMode proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE));
shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingTableMetaData, showSQL);
}
From f87cd914437686aeb09b3cff2a26e8f8cef18731 Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Sun, 5 Aug 2018 21:16:49 +0800
Subject: [PATCH 032/198] add ExecutorEngineFactory.java
---
.../core/executor/ExecutorEngineFactory.java | 44 +++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngineFactory.java
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngineFactory.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngineFactory.java
new file mode 100644
index 0000000000000..96f6f3c81933c
--- /dev/null
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngineFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed 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 io.shardingsphere.core.executor;
+
+import io.shardingsphere.core.constant.ProxyMode;
+import io.shardingsphere.core.executor.type.connection.ConnectionStrictlyExecutorEngine;
+import io.shardingsphere.core.executor.type.memory.MemoryStrictlyExecutorEngine;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * JDBC execute engine factory.
+ *
+ * @author panjuan
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ExecutorEngineFactory {
+
+ /**
+ * Create instance for execute engine.
+ *
+ * @param proxyMode proxy mode
+ * @param executorSize executor size
+ * @return instance for text protocol
+ */
+ public static ExecutorEngine createTextProtocolInstance(final ProxyMode proxyMode, final int executorSize) {
+ return ProxyMode.MEMORY_STRICTLY == proxyMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize);
+ }
+}
From 210b6d75fec21cb2a8dbe118a9fdbdef3d86426f Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Sun, 5 Aug 2018 21:16:59 +0800
Subject: [PATCH 033/198] add MemoryQueryResult.java
---
.../type/connection/MemoryQueryResult.java | 133 ++++++++++++++++++
1 file changed, 133 insertions(+)
create mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/MemoryQueryResult.java
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/MemoryQueryResult.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/MemoryQueryResult.java
new file mode 100644
index 0000000000000..8ca08596fe603
--- /dev/null
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/MemoryQueryResult.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed 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 io.shardingsphere.core.executor.type.connection;
+
+import io.shardingsphere.core.merger.QueryResult;
+
+import java.io.InputStream;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * Query result for memory loading.
+ *
+ * @author zhangliang
+ */
+public final class MemoryQueryResult implements QueryResult {
+
+ private final Map columnLabelAndIndexMap;
+
+ private final Iterator> resultData;
+
+ private List currentRow;
+
+ public MemoryQueryResult(final ResultSet resultSet) throws SQLException {
+ columnLabelAndIndexMap = getMetaData(resultSet.getMetaData());
+ resultData = getResultData(resultSet);
+ }
+
+ private Map getMetaData(final ResultSetMetaData resultSetMetaData) throws SQLException {
+ Map result = new HashMap<>();
+ for (int columnIndex = 1; columnIndex <= resultSetMetaData.getColumnCount(); columnIndex++) {
+ result.put(resultSetMetaData.getColumnLabel(columnIndex), columnIndex);
+ }
+ return result;
+ }
+
+ private Iterator> getResultData(final ResultSet resultSet) throws SQLException {
+ Collection> result = new LinkedList<>();
+ while (resultSet.next()) {
+ List row = new ArrayList<>(columnLabelAndIndexMap.size());
+ for (int columnIndex = 1; columnIndex <= resultSet.getMetaData().getColumnCount(); columnIndex++) {
+ row.add(resultSet.getObject(columnIndex));
+ }
+ result.add(row);
+ }
+ return result.iterator();
+ }
+
+ @Override
+ public boolean next() {
+ if (resultData.hasNext()) {
+ currentRow = resultData.next();
+ return true;
+ }
+ currentRow = null;
+ return false;
+ }
+
+ @Override
+ public Object getValue(final int columnIndex, final Class> type) {
+ return currentRow.get(columnIndex - 1);
+ }
+
+ @Override
+ public Object getValue(final String columnLabel, final Class> type) {
+ return currentRow.get(columnLabelAndIndexMap.get(columnLabel));
+ }
+
+ @Override
+ public Object getCalendarValue(final int columnIndex, final Class> type, final Calendar calendar) {
+ return currentRow.get(columnIndex - 1);
+ }
+
+ @Override
+ public Object getCalendarValue(final String columnLabel, final Class> type, final Calendar calendar) {
+ return currentRow.get(columnLabelAndIndexMap.get(columnLabel));
+ }
+
+ @Override
+ public InputStream getInputStream(final int columnIndex, final String type) {
+ return (InputStream) currentRow.get(columnIndex - 1);
+ }
+
+ @Override
+ public InputStream getInputStream(final String columnLabel, final String type) {
+ return (InputStream) currentRow.get(columnLabelAndIndexMap.get(columnLabel));
+ }
+
+ @Override
+ public boolean wasNull() {
+ return null == currentRow;
+ }
+
+ @Override
+ public int getColumnCount() {
+ return columnLabelAndIndexMap.size();
+ }
+
+ @Override
+ public String getColumnLabel(final int columnIndex) throws SQLException {
+ for (Entry entry : columnLabelAndIndexMap.entrySet()) {
+ if (columnIndex == entry.getValue()) {
+ return entry.getKey();
+ }
+ }
+ throw new SQLException("Column index out of range", "9999");
+ }
+}
From 28314e87fba9667f3d364d6ee77c2c64c9e488aa Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Sun, 5 Aug 2018 21:17:11 +0800
Subject: [PATCH 034/198] modify ExecutorEngine
---
.../core/executor/ExecutorEngine.java | 45 ++-----------------
1 file changed, 4 insertions(+), 41 deletions(-)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java
index 2e066f42257e4..257adf89dbec1 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java
@@ -17,8 +17,6 @@
package io.shardingsphere.core.executor;
-import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -35,15 +33,11 @@
import lombok.extern.slf4j.Slf4j;
import java.sql.SQLException;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@@ -57,7 +51,7 @@
* @author panjuan
*/
@Slf4j
-public final class ExecutorEngine implements AutoCloseable {
+public abstract class ExecutorEngine implements AutoCloseable {
private static final ThreadPoolExecutor SHUTDOWN_EXECUTOR = new ThreadPoolExecutor(
0, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(10), new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Sharding-JDBC-ExecutorEngineCloseTimer").build());
@@ -88,11 +82,8 @@ public List execute(
}
OverallExecutionEvent event = new OverallExecutionEvent(sqlType, baseStatementUnits.size());
EventBusInstance.getInstance().post(event);
- Iterator extends BaseStatementUnit> iterator = baseStatementUnits.iterator();
try {
- T firstOutput = syncExecute(sqlType, iterator.next(), executeCallback);
- List> restFutures = asyncExecute(sqlType, Lists.newArrayList(iterator), executeCallback);
- List result = buildResultList(firstOutput, restFutures);
+ List result = getExecuteResults(sqlType, baseStatementUnits, executeCallback);
event.setEventExecutionType(EventExecutionType.EXECUTE_SUCCESS);
EventBusInstance.getInstance().post(event);
return result;
@@ -107,28 +98,9 @@ public List execute(
}
}
- private List> asyncExecute(
- final SQLType sqlType, final Collection baseStatementUnits, final ExecuteCallback executeCallback) {
- List> result = new ArrayList<>(baseStatementUnits.size());
- final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
- final Map dataMap = ExecutorDataMap.getDataMap();
- for (final BaseStatementUnit each : baseStatementUnits) {
- result.add(executorService.submit(new Callable() {
-
- @Override
- public T call() throws Exception {
- return executeInternal(sqlType, each, executeCallback, isExceptionThrown, dataMap);
- }
- }));
- }
- return result;
- }
-
- private T syncExecute(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback) throws Exception {
- return executeInternal(sqlType, baseStatementUnit, executeCallback, ExecutorExceptionHandler.isExceptionThrown(), ExecutorDataMap.getDataMap());
- }
+ protected abstract List getExecuteResults(SQLType sqlType, Collection extends BaseStatementUnit> baseStatementUnits, ExecuteCallback executeCallback) throws Exception;
- private T executeInternal(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback,
+ protected T executeInternal(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback,
final boolean isExceptionThrown, final Map dataMap) throws Exception {
synchronized (baseStatementUnit.getStatement().getConnection()) {
T result;
@@ -160,15 +132,6 @@ private T executeInternal(final SQLType sqlType, final BaseStatementUnit bas
}
}
- private List buildResultList(final T firstOutput, final List> restResultFutures) throws ExecutionException, InterruptedException {
- List result = new LinkedList<>();
- result.add(firstOutput);
- for (ListenableFuture each : restResultFutures) {
- result.add(each.get());
- }
- return result;
- }
-
private AbstractExecutionEvent getExecutionEvent(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final List parameters) {
AbstractExecutionEvent result;
if (SQLType.DQL == sqlType) {
From c68e81542949f9215b1d040bcc68ce848df5cdcc Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Sun, 5 Aug 2018 21:17:50 +0800
Subject: [PATCH 035/198] add MemoryStrictlyExecutorEngine.java
---
.../memory/MemoryStrictlyExecutorEngine.java | 86 +++++++++++++++++++
1 file changed, 86 insertions(+)
create mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java
new file mode 100644
index 0000000000000..901cf10a8c130
--- /dev/null
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed 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 io.shardingsphere.core.executor.type.memory;
+
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.ListenableFuture;
+import io.shardingsphere.core.constant.SQLType;
+import io.shardingsphere.core.executor.BaseStatementUnit;
+import io.shardingsphere.core.executor.ExecuteCallback;
+import io.shardingsphere.core.executor.ExecutorEngine;
+import io.shardingsphere.core.executor.threadlocal.ExecutorDataMap;
+import io.shardingsphere.core.executor.threadlocal.ExecutorExceptionHandler;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+
+/**
+ * Memory strictly execute engine.
+ *
+ * @author panjuan
+ */
+public final class MemoryStrictlyExecutorEngine extends ExecutorEngine {
+
+ public MemoryStrictlyExecutorEngine(final int executorSize) {
+ super(executorSize);
+ }
+
+ @Override
+ protected List getExecuteResults(final SQLType sqlType, final Collection extends BaseStatementUnit> baseStatementUnits, final ExecuteCallback executeCallback) throws Exception {
+ Iterator extends BaseStatementUnit> iterator = baseStatementUnits.iterator();
+ T firstOutput = syncExecute(sqlType, iterator.next(), executeCallback);
+ List> restFutures = asyncExecute(sqlType, Lists.newArrayList(iterator), executeCallback);
+ return buildResultList(firstOutput, restFutures);
+ }
+
+ private List> asyncExecute(
+ final SQLType sqlType, final Collection baseStatementUnits, final ExecuteCallback executeCallback) {
+ List> result = new ArrayList<>(baseStatementUnits.size());
+ final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
+ final Map dataMap = ExecutorDataMap.getDataMap();
+ for (final BaseStatementUnit each : baseStatementUnits) {
+ result.add(getExecutorService().submit(new Callable() {
+
+ @Override
+ public T call() throws Exception {
+ return executeInternal(sqlType, each, executeCallback, isExceptionThrown, dataMap);
+ }
+ }));
+ }
+ return result;
+ }
+
+ private T syncExecute(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback) throws Exception {
+ return executeInternal(sqlType, baseStatementUnit, executeCallback, ExecutorExceptionHandler.isExceptionThrown(), ExecutorDataMap.getDataMap());
+ }
+
+ private List buildResultList(final T firstOutput, final List> restResultFutures) throws ExecutionException, InterruptedException {
+ List result = new LinkedList<>();
+ result.add(firstOutput);
+ for (ListenableFuture each : restResultFutures) {
+ result.add(each.get());
+ }
+ return result;
+ }
+}
From 0de63304add597540968ee0c81543f53aaa87898 Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Sun, 5 Aug 2018 21:18:01 +0800
Subject: [PATCH 036/198] add StreamQueryResult.java
---
.../type/memory/StreamQueryResult.java | 216 ++++++++++++++++++
1 file changed, 216 insertions(+)
create mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java
new file mode 100644
index 0000000000000..56ec8ef4df0cb
--- /dev/null
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java
@@ -0,0 +1,216 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed 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 io.shardingsphere.core.executor.type.memory;
+
+import io.shardingsphere.core.merger.QueryResult;
+import lombok.RequiredArgsConstructor;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLXML;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+
+/**
+ * Query result for stream loading.
+ *
+ * @author zhangliang
+ */
+@RequiredArgsConstructor
+public final class StreamQueryResult implements QueryResult {
+
+ private final ResultSet resultSet;
+
+ @Override
+ public boolean next() throws SQLException {
+ return resultSet.next();
+ }
+
+ @Override
+ public Object getValue(final int columnIndex, final Class> type) throws SQLException {
+ Object result;
+ if (Object.class == type) {
+ result = resultSet.getObject(columnIndex);
+ } else if (boolean.class == type) {
+ result = resultSet.getBoolean(columnIndex);
+ } else if (byte.class == type) {
+ result = resultSet.getByte(columnIndex);
+ } else if (short.class == type) {
+ result = resultSet.getShort(columnIndex);
+ } else if (int.class == type) {
+ result = resultSet.getInt(columnIndex);
+ } else if (long.class == type) {
+ result = resultSet.getLong(columnIndex);
+ } else if (float.class == type) {
+ result = resultSet.getFloat(columnIndex);
+ } else if (double.class == type) {
+ result = resultSet.getDouble(columnIndex);
+ } else if (String.class == type) {
+ result = resultSet.getString(columnIndex);
+ } else if (BigDecimal.class == type) {
+ result = resultSet.getBigDecimal(columnIndex);
+ } else if (byte[].class == type) {
+ result = resultSet.getBytes(columnIndex);
+ } else if (Date.class == type) {
+ result = resultSet.getDate(columnIndex);
+ } else if (Time.class == type) {
+ result = resultSet.getTime(columnIndex);
+ } else if (Timestamp.class == type) {
+ result = resultSet.getTimestamp(columnIndex);
+ } else if (URL.class == type) {
+ result = resultSet.getURL(columnIndex);
+ } else if (Blob.class == type) {
+ result = resultSet.getBlob(columnIndex);
+ } else if (Clob.class == type) {
+ result = resultSet.getClob(columnIndex);
+ } else if (SQLXML.class == type) {
+ result = resultSet.getSQLXML(columnIndex);
+ } else if (Reader.class == type) {
+ result = resultSet.getCharacterStream(columnIndex);
+ } else {
+ result = resultSet.getObject(columnIndex);
+ }
+ return result;
+ }
+
+ @Override
+ public Object getValue(final String columnLabel, final Class> type) throws SQLException {
+ Object result;
+ if (Object.class == type) {
+ result = resultSet.getObject(columnLabel);
+ } else if (boolean.class == type) {
+ result = resultSet.getBoolean(columnLabel);
+ } else if (byte.class == type) {
+ result = resultSet.getByte(columnLabel);
+ } else if (short.class == type) {
+ result = resultSet.getShort(columnLabel);
+ } else if (int.class == type) {
+ result = resultSet.getInt(columnLabel);
+ } else if (long.class == type) {
+ result = resultSet.getLong(columnLabel);
+ } else if (float.class == type) {
+ result = resultSet.getFloat(columnLabel);
+ } else if (double.class == type) {
+ result = resultSet.getDouble(columnLabel);
+ } else if (String.class == type) {
+ result = resultSet.getString(columnLabel);
+ } else if (BigDecimal.class == type) {
+ result = resultSet.getBigDecimal(columnLabel);
+ } else if (byte[].class == type) {
+ result = resultSet.getBytes(columnLabel);
+ } else if (Date.class == type) {
+ result = resultSet.getDate(columnLabel);
+ } else if (Time.class == type) {
+ result = resultSet.getTime(columnLabel);
+ } else if (Timestamp.class == type) {
+ result = resultSet.getTimestamp(columnLabel);
+ } else if (URL.class == type) {
+ result = resultSet.getURL(columnLabel);
+ } else if (Blob.class == type) {
+ result = resultSet.getBlob(columnLabel);
+ } else if (Clob.class == type) {
+ result = resultSet.getClob(columnLabel);
+ } else if (SQLXML.class == type) {
+ result = resultSet.getSQLXML(columnLabel);
+ } else if (Reader.class == type) {
+ result = resultSet.getCharacterStream(columnLabel);
+ } else {
+ result = resultSet.getObject(columnLabel);
+ }
+ return result;
+ }
+
+ @Override
+ public Object getCalendarValue(final int columnIndex, final Class> type, final Calendar calendar) throws SQLException {
+ if (Date.class == type) {
+ return resultSet.getDate(columnIndex, calendar);
+ }
+ if (Time.class == type) {
+ return resultSet.getTime(columnIndex, calendar);
+ }
+ if (Timestamp.class == type) {
+ return resultSet.getTimestamp(columnIndex, calendar);
+ }
+ throw new SQLException(String.format("Unsupported type: %s", type));
+ }
+
+ @Override
+ public Object getCalendarValue(final String columnLabel, final Class> type, final Calendar calendar) throws SQLException {
+ if (Date.class == type) {
+ return resultSet.getDate(columnLabel, calendar);
+ }
+ if (Time.class == type) {
+ return resultSet.getTime(columnLabel, calendar);
+ }
+ if (Timestamp.class == type) {
+ return resultSet.getTimestamp(columnLabel, calendar);
+ }
+ throw new SQLException(String.format("Unsupported type: %s", type));
+ }
+
+ @Override
+ public InputStream getInputStream(final int columnIndex, final String type) throws SQLException {
+ switch (type) {
+ case "Ascii":
+ return resultSet.getAsciiStream(columnIndex);
+ case "Unicode":
+ return resultSet.getUnicodeStream(columnIndex);
+ case "Binary":
+ return resultSet.getBinaryStream(columnIndex);
+ default:
+ throw new SQLException(String.format("Unsupported type: %s", type));
+ }
+ }
+
+ @Override
+ public InputStream getInputStream(final String columnLabel, final String type) throws SQLException {
+ switch (type) {
+ case "Ascii":
+ return resultSet.getAsciiStream(columnLabel);
+ case "Unicode":
+ return resultSet.getUnicodeStream(columnLabel);
+ case "Binary":
+ return resultSet.getBinaryStream(columnLabel);
+ default:
+ throw new SQLException(String.format("Unsupported type: %s", type));
+ }
+ }
+
+ @Override
+ public boolean wasNull() throws SQLException {
+ return resultSet.wasNull();
+ }
+
+ @Override
+ public int getColumnCount() throws SQLException {
+ return resultSet.getMetaData().getColumnCount();
+ }
+
+ @Override
+ public String getColumnLabel(final int columnIndex) throws SQLException {
+ return resultSet.getMetaData().getColumnLabel(columnIndex);
+ }
+}
From cc57f6c64f799cec7b29c6ab2ce4b505ded7d78c Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Mon, 6 Aug 2018 06:03:34 +0800
Subject: [PATCH 037/198] change function name to getResultList
---
.../executor/type/memory/MemoryStrictlyExecutorEngine.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java
index 901cf10a8c130..4430e4f417e12 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java
@@ -51,7 +51,7 @@ protected List getExecuteResults(final SQLType sqlType, final Collection<
Iterator extends BaseStatementUnit> iterator = baseStatementUnits.iterator();
T firstOutput = syncExecute(sqlType, iterator.next(), executeCallback);
List> restFutures = asyncExecute(sqlType, Lists.newArrayList(iterator), executeCallback);
- return buildResultList(firstOutput, restFutures);
+ return getResultList(firstOutput, restFutures);
}
private List> asyncExecute(
@@ -75,7 +75,7 @@ private T syncExecute(final SQLType sqlType, final BaseStatementUnit baseSta
return executeInternal(sqlType, baseStatementUnit, executeCallback, ExecutorExceptionHandler.isExceptionThrown(), ExecutorDataMap.getDataMap());
}
- private List buildResultList(final T firstOutput, final List> restResultFutures) throws ExecutionException, InterruptedException {
+ private List getResultList(final T firstOutput, final List> restResultFutures) throws ExecutionException, InterruptedException {
List result = new LinkedList<>();
result.add(firstOutput);
for (ListenableFuture each : restResultFutures) {
From 46a92f3be0add0faa8e5a043c3a6d7c8dfaa78c7 Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Mon, 6 Aug 2018 12:01:58 +0800
Subject: [PATCH 038/198] modify cachedConnections
---
.../adapter/AbstractConnectionAdapter.java | 21 ++++++++-----------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
index 458200532d65d..67cc0548ee685 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
@@ -33,9 +33,9 @@
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.util.Collection;
-import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
/**
* Adapter for {@code Connection}.
@@ -44,7 +44,7 @@
*/
public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOperationConnection {
- private final Map cachedConnections = new HashMap<>();
+ private final Collection cachedConnections = new CopyOnWriteArrayList<>();
private boolean autoCommit = true;
@@ -62,13 +62,10 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera
* @throws SQLException SQL exception
*/
public final Connection getConnection(final String dataSourceName) throws SQLException {
- if (cachedConnections.containsKey(dataSourceName)) {
- return cachedConnections.get(dataSourceName);
- }
DataSource dataSource = getDataSourceMap().get(dataSourceName);
Preconditions.checkState(null != dataSource, "Missing the data source name: '%s'", dataSourceName);
Connection result = dataSource.getConnection();
- cachedConnections.put(dataSourceName, result);
+ cachedConnections.add(result);
replayMethodsInvocation(result);
return result;
}
@@ -76,7 +73,7 @@ public final Connection getConnection(final String dataSourceName) throws SQLExc
protected abstract Map getDataSourceMap();
protected void removeCache(final Connection connection) {
- cachedConnections.values().remove(connection);
+ cachedConnections.remove(connection);
}
@Override
@@ -107,7 +104,7 @@ public void close() throws SQLException {
HintManagerHolder.clear();
MasterVisitedManager.clear();
Collection exceptions = new LinkedList<>();
- for (Connection each : cachedConnections.values()) {
+ for (Connection each : cachedConnections) {
try {
each.close();
} catch (final SQLException ex) {
@@ -131,24 +128,24 @@ public final boolean isReadOnly() {
public final void setReadOnly(final boolean readOnly) throws SQLException {
this.readOnly = readOnly;
recordMethodInvocation(Connection.class, "setReadOnly", new Class[] {boolean.class}, new Object[] {readOnly});
- for (Connection each : cachedConnections.values()) {
+ for (Connection each : cachedConnections) {
each.setReadOnly(readOnly);
}
}
@Override
public final int getTransactionIsolation() throws SQLException {
- if (cachedConnections.values().isEmpty()) {
+ if (cachedConnections.isEmpty()) {
return transactionIsolation;
}
- return cachedConnections.values().iterator().next().getTransactionIsolation();
+ return cachedConnections.iterator().next().getTransactionIsolation();
}
@Override
public final void setTransactionIsolation(final int level) throws SQLException {
transactionIsolation = level;
recordMethodInvocation(Connection.class, "setTransactionIsolation", new Class[] {int.class}, new Object[] {level});
- for (Connection each : cachedConnections.values()) {
+ for (Connection each : cachedConnections) {
each.setTransactionIsolation(level);
}
}
From 354535d070f3ea4d8978218ea8e3b519fd5b341d Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Mon, 6 Aug 2018 12:02:09 +0800
Subject: [PATCH 039/198] reuse cachedConnections
---
.../core/transaction/event/WeakXaTransactionEvent.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java b/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java
index e002128cc9df9..220d2ea91ac63 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java
@@ -24,7 +24,7 @@
import lombok.Setter;
import java.sql.Connection;
-import java.util.Map;
+import java.util.Collection;
/**
* Weak XA transaction event.
@@ -35,7 +35,7 @@
@Setter
public final class WeakXaTransactionEvent extends TransactionEvent {
- private Map cachedConnections;
+ private Collection cachedConnections;
private boolean autoCommit = true;
From 2b9edced94a96f2c934b754de03bdc296d87e3c3 Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Mon, 6 Aug 2018 12:02:15 +0800
Subject: [PATCH 040/198] modify cachedConnections
---
.../jdbc/core/transaction/WeakXaTransactionManager.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java
index 52bde5e99f3a9..02c71260275fc 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java
@@ -36,7 +36,7 @@ public final class WeakXaTransactionManager implements TransactionManager {
@Override
public void begin(final TransactionEvent transactionEvent) throws SQLException {
WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) transactionEvent;
- for (Connection each : weakXaTransactionEvent.getCachedConnections().values()) {
+ for (Connection each : weakXaTransactionEvent.getCachedConnections()) {
each.setAutoCommit(weakXaTransactionEvent.isAutoCommit());
}
}
@@ -45,7 +45,7 @@ public void begin(final TransactionEvent transactionEvent) throws SQLException {
public void commit(final TransactionEvent transactionEvent) throws SQLException {
WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) transactionEvent;
Collection exceptions = new LinkedList<>();
- for (Connection each : weakXaTransactionEvent.getCachedConnections().values()) {
+ for (Connection each : weakXaTransactionEvent.getCachedConnections()) {
try {
each.commit();
} catch (final SQLException ex) {
@@ -59,7 +59,7 @@ public void commit(final TransactionEvent transactionEvent) throws SQLException
public void rollback(final TransactionEvent transactionEvent) throws SQLException {
WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) transactionEvent;
Collection exceptions = new LinkedList<>();
- for (Connection each : weakXaTransactionEvent.getCachedConnections().values()) {
+ for (Connection each : weakXaTransactionEvent.getCachedConnections()) {
try {
each.rollback();
} catch (final SQLException ex) {
From ca59be50ea5c4010d6285bdc857b7c4e0c02d8bb Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Mon, 6 Aug 2018 12:17:10 +0800
Subject: [PATCH 041/198] renew proxy mode
---
.../core/jdbc/core/datasource/ShardingDataSource.java | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java
index ca7ca8f0fb95b..5cac8709ae3c3 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java
@@ -24,6 +24,8 @@
import io.shardingsphere.core.constant.ShardingProperties;
import io.shardingsphere.core.constant.ShardingPropertiesConstant;
import io.shardingsphere.core.executor.ExecutorEngine;
+import io.shardingsphere.core.executor.type.connection.ConnectionStrictlyExecutorEngine;
+import io.shardingsphere.core.executor.type.memory.MemoryStrictlyExecutorEngine;
import io.shardingsphere.core.jdbc.adapter.AbstractDataSourceAdapter;
import io.shardingsphere.core.jdbc.core.ShardingContext;
import io.shardingsphere.core.jdbc.core.connection.ShardingConnection;
@@ -48,6 +50,7 @@
*
* @author zhangliang
* @author zhaojun
+ * @author panjuan
*/
public class ShardingDataSource extends AbstractDataSourceAdapter implements AutoCloseable {
@@ -69,11 +72,11 @@ public ShardingDataSource(final Map dataSourceMap, final Sha
}
shardingProperties = new ShardingProperties(null == props ? new Properties() : props);
int executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE);
- executorEngine = new ExecutorEngine(executorSize);
ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData(
new TableMetaDataInitializer(executorEngine.getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(dataSourceMap)).load(shardingRule));
boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW);
ProxyMode proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE));
+ executorEngine = ProxyMode.MEMORY_STRICTLY == proxyMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize);
shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingTableMetaData, showSQL);
}
@@ -88,9 +91,11 @@ public void renew(final Map newDataSourceMap, final Sharding
ShardingProperties newShardingProperties = new ShardingProperties(null == newProps ? new Properties() : newProps);
int originalExecutorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE);
int newExecutorSize = newShardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE);
- if (originalExecutorSize != newExecutorSize) {
+ ProxyMode originalProxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE));
+ ProxyMode newProxyMode = ProxyMode.valueOf(newShardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE));
+ if (originalExecutorSize != newExecutorSize || originalProxyMode != newProxyMode) {
ExecutorEngine originalExecutorEngine = executorEngine;
- executorEngine = new ExecutorEngine(newExecutorSize);
+ executorEngine = ProxyMode.MEMORY_STRICTLY == newProxyMode ? new MemoryStrictlyExecutorEngine(newExecutorSize) : new ConnectionStrictlyExecutorEngine(newExecutorSize);
originalExecutorEngine.close();
}
boolean newShowSQL = newShardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW);
From b28c9fb674449a4306f3462ef18e669c519f02fc Mon Sep 17 00:00:00 2001
From: terrymanu
Date: Mon, 6 Aug 2018 12:25:39 +0800
Subject: [PATCH 042/198] MySQLResultCache => FutureRegistry
---
.../backend/netty/NettyBackendHandler.java | 20 +-
.../netty/future/FutureRegistry.java} | 155 +++++++-------
.../netty/future}/SynchronizedFuture.java | 194 +++++++++---------
.../netty/mysql/MySQLBackendHandler.java | 6 +-
4 files changed, 188 insertions(+), 187 deletions(-)
rename sharding-proxy/src/main/java/io/shardingsphere/proxy/{util/MySQLResultCache.java => backend/netty/future/FutureRegistry.java} (58%)
rename sharding-proxy/src/main/java/io/shardingsphere/proxy/{util => backend/netty/future}/SynchronizedFuture.java (94%)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java
index 026792c74fbea..f5fec55c2c25c 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java
@@ -33,7 +33,9 @@
import io.shardingsphere.core.routing.StatementRoutingEngine;
import io.shardingsphere.core.routing.router.masterslave.MasterSlaveRouter;
import io.shardingsphere.proxy.backend.AbstractBackendHandler;
+import io.shardingsphere.proxy.backend.BackendExecutorContext;
import io.shardingsphere.proxy.backend.ResultPacket;
+import io.shardingsphere.proxy.backend.netty.future.FutureRegistry;
import io.shardingsphere.proxy.backend.netty.mysql.MySQLQueryResult;
import io.shardingsphere.proxy.config.ProxyTableMetaDataConnectionManager;
import io.shardingsphere.proxy.config.RuleRegistry;
@@ -44,9 +46,7 @@
import io.shardingsphere.proxy.transport.mysql.packet.command.query.text.query.ComQueryPacket;
import io.shardingsphere.proxy.transport.mysql.packet.generic.ErrPacket;
import io.shardingsphere.proxy.transport.mysql.packet.generic.OKPacket;
-import io.shardingsphere.proxy.backend.BackendExecutorContext;
-import io.shardingsphere.proxy.util.MySQLResultCache;
-import io.shardingsphere.proxy.util.SynchronizedFuture;
+import io.shardingsphere.proxy.backend.netty.future.SynchronizedFuture;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -101,10 +101,10 @@ protected CommandResponsePackets execute0() throws InterruptedException, Executi
private CommandResponsePackets executeForMasterSlave() throws InterruptedException, ExecutionException, TimeoutException {
String dataSourceName = new MasterSlaveRouter(RULE_REGISTRY.getMasterSlaveRule(), RULE_REGISTRY.isShowSQL()).route(sql).iterator().next();
synchronizedFuture = new SynchronizedFuture(1);
- MySQLResultCache.getInstance().putFuture(connectionId, synchronizedFuture);
- executeCommand(dataSourceName, sql);
+ FutureRegistry.getInstance().put(connectionId, synchronizedFuture);
+ executeSQL(dataSourceName, sql);
List queryResults = synchronizedFuture.get(RULE_REGISTRY.getBackendNIOConfig().getConnectionTimeoutSeconds(), TimeUnit.SECONDS);
- MySQLResultCache.getInstance().deleteFuture(connectionId);
+ FutureRegistry.getInstance().delete(connectionId);
List packets = new LinkedList<>();
for (QueryResult each : queryResults) {
packets.add(((MySQLQueryResult) each).getCommandResponsePackets());
@@ -120,12 +120,12 @@ private CommandResponsePackets executeForSharding() throws InterruptedException,
return new CommandResponsePackets(new OKPacket(1));
}
synchronizedFuture = new SynchronizedFuture(routeResult.getExecutionUnits().size());
- MySQLResultCache.getInstance().putFuture(connectionId, synchronizedFuture);
+ FutureRegistry.getInstance().put(connectionId, synchronizedFuture);
for (SQLExecutionUnit each : routeResult.getExecutionUnits()) {
- executeCommand(each.getDataSource(), each.getSqlUnit().getSql());
+ executeSQL(each.getDataSource(), each.getSqlUnit().getSql());
}
List queryResults = synchronizedFuture.get(RULE_REGISTRY.getBackendNIOConfig().getConnectionTimeoutSeconds(), TimeUnit.SECONDS);
- MySQLResultCache.getInstance().deleteFuture(connectionId);
+ FutureRegistry.getInstance().delete(connectionId);
List packets = Lists.newArrayListWithCapacity(queryResults.size());
for (QueryResult each : queryResults) {
@@ -149,7 +149,7 @@ private CommandResponsePackets executeForSharding() throws InterruptedException,
return result;
}
- private void executeCommand(final String dataSourceName, final String sql) throws InterruptedException, ExecutionException, TimeoutException {
+ private void executeSQL(final String dataSourceName, final String sql) throws InterruptedException, ExecutionException, TimeoutException {
if (!channelMap.containsKey(dataSourceName)) {
channelMap.put(dataSourceName, new ArrayList());
}
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/MySQLResultCache.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/FutureRegistry.java
similarity index 58%
rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/util/MySQLResultCache.java
rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/FutureRegistry.java
index a37e276e0d5b2..68d411662fde8 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/MySQLResultCache.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/FutureRegistry.java
@@ -1,77 +1,78 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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 io.shardingsphere.proxy.util;
-
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * Cache for synchronized future.
- *
- * @author wangkai
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class MySQLResultCache {
-
- private static final MySQLResultCache INSTANCE = new MySQLResultCache();
-
- //TODO expire time should be set.
- private final Cache resultCache = CacheBuilder.newBuilder().expireAfterWrite(60, TimeUnit.SECONDS).build();
-
- /**
- * Get instance of MySQL result cache.
- *
- * @return instance of MySQL result cache
- */
- public static MySQLResultCache getInstance() {
- return INSTANCE;
- }
-
- /**
- * Put synchronized future by connection id.
- *
- * @param connectionId MySQL connection id
- * @param synchronizedFuture multiple result set
- */
- public void putFuture(final int connectionId, final SynchronizedFuture synchronizedFuture) {
- resultCache.put(connectionId, synchronizedFuture);
- }
-
- /**
- * Get synchronized future by connection id.
- *
- * @param connectionId MySQL connection id
- * @return multiple result set
- */
- public SynchronizedFuture getFuture(final int connectionId) {
- return resultCache.getIfPresent(connectionId);
- }
-
- /**
- * Delete synchronized future by connection id.
- *
- * @param connectionId MySQL connection id
- */
- public void deleteFuture(final int connectionId) {
- resultCache.invalidate(connectionId);
- }
-}
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed 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 io.shardingsphere.proxy.backend.netty.future;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Future registry.
+ *
+ * @author wangkai
+ * @author zhangliang
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class FutureRegistry {
+
+ private static final FutureRegistry INSTANCE = new FutureRegistry();
+
+ //TODO expire time should be set.
+ private final Cache resultCache = CacheBuilder.newBuilder().expireAfterWrite(60, TimeUnit.SECONDS).build();
+
+ /**
+ * Get instance of future registry.
+ *
+ * @return instance of future registry
+ */
+ public static FutureRegistry getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Put synchronized future by connection ID.
+ *
+ * @param connectionId database connection ID
+ * @param synchronizedFuture synchronized future
+ */
+ public void put(final int connectionId, final SynchronizedFuture synchronizedFuture) {
+ resultCache.put(connectionId, synchronizedFuture);
+ }
+
+ /**
+ * Get synchronized future by connection ID.
+ *
+ * @param connectionId database connection ID
+ * @return synchronized future
+ */
+ public SynchronizedFuture get(final int connectionId) {
+ return resultCache.getIfPresent(connectionId);
+ }
+
+ /**
+ * Delete synchronized future by connection ID.
+ *
+ * @param connectionId database connection ID
+ */
+ public void delete(final int connectionId) {
+ resultCache.invalidate(connectionId);
+ }
+}
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/SynchronizedFuture.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java
similarity index 94%
rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/util/SynchronizedFuture.java
rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java
index c5921b6abf09d..0baff8fe1a3a1 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/SynchronizedFuture.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java
@@ -1,97 +1,97 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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 io.shardingsphere.proxy.util;
-
-import com.google.common.collect.Lists;
-import io.shardingsphere.core.merger.QueryResult;
-import lombok.extern.slf4j.Slf4j;
-
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Synchronized future for get multiple netty returns.
- *
- * @author wangkai
- * @author linjiaqi
- */
-@Slf4j
-public class SynchronizedFuture implements Future> {
-
- private final CountDownLatch latch;
-
- private final List responses;
-
- private boolean isDone;
-
- public SynchronizedFuture(final int resultSize) {
- latch = new CountDownLatch(resultSize);
- responses = Lists.newArrayListWithCapacity(resultSize);
- }
-
- @Override
- public boolean cancel(final boolean mayInterruptIfRunning) {
- return false;
- }
-
- @Override
- public boolean isCancelled() {
- return false;
- }
-
- @Override
- public boolean isDone() {
- return isDone;
- }
-
- @Override
- public List get() throws InterruptedException {
- latch.await();
- return responses;
- }
-
- /**
- * Get responses for waiting time.
- *
- * @param timeout wait timeout
- * @param unit time unit
- * @return responses
- */
- @Override
- public List get(final long timeout, final TimeUnit unit) {
- try {
- latch.await(timeout, unit);
- isDone = true;
- } catch (final InterruptedException ex) {
- log.error(ex.getMessage(), ex);
- }
- return responses;
- }
-
- /**
- * Set response and count down.
- *
- * @param response SQL command result
- */
- public void setResponse(final QueryResult response) {
- responses.add(response);
- latch.countDown();
- }
-}
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed 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 io.shardingsphere.proxy.backend.netty.future;
+
+import com.google.common.collect.Lists;
+import io.shardingsphere.core.merger.QueryResult;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Synchronized future for get multiple netty returns.
+ *
+ * @author wangkai
+ * @author linjiaqi
+ */
+@Slf4j
+public class SynchronizedFuture implements Future> {
+
+ private final CountDownLatch latch;
+
+ private final List responses;
+
+ private boolean isDone;
+
+ public SynchronizedFuture(final int resultSize) {
+ latch = new CountDownLatch(resultSize);
+ responses = Lists.newArrayListWithCapacity(resultSize);
+ }
+
+ @Override
+ public boolean cancel(final boolean mayInterruptIfRunning) {
+ return false;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return false;
+ }
+
+ @Override
+ public boolean isDone() {
+ return isDone;
+ }
+
+ @Override
+ public List get() throws InterruptedException {
+ latch.await();
+ return responses;
+ }
+
+ /**
+ * Get responses for waiting time.
+ *
+ * @param timeout wait timeout
+ * @param unit time unit
+ * @return responses
+ */
+ @Override
+ public List get(final long timeout, final TimeUnit unit) {
+ try {
+ latch.await(timeout, unit);
+ isDone = true;
+ } catch (final InterruptedException ex) {
+ log.error(ex.getMessage(), ex);
+ }
+ return responses;
+ }
+
+ /**
+ * Set response and count down.
+ *
+ * @param response SQL command result
+ */
+ public void setResponse(final QueryResult response) {
+ responses.add(response);
+ latch.countDown();
+ }
+}
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLBackendHandler.java
index c94403c0b052c..77cfa0c037eb6 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLBackendHandler.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLBackendHandler.java
@@ -35,7 +35,7 @@
import io.shardingsphere.proxy.transport.mysql.packet.generic.OKPacket;
import io.shardingsphere.proxy.transport.mysql.packet.handshake.HandshakePacket;
import io.shardingsphere.proxy.transport.mysql.packet.handshake.HandshakeResponse41Packet;
-import io.shardingsphere.proxy.util.MySQLResultCache;
+import io.shardingsphere.proxy.backend.netty.future.FutureRegistry;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -190,8 +190,8 @@ private byte[] securePasswordAuthentication(final byte[] password, final byte[]
private void setResponse(final ChannelHandlerContext context) {
int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText());
- if (MySQLResultCache.getInstance().getFuture(connectionId) != null) {
- MySQLResultCache.getInstance().getFuture(connectionId).setResponse(resultMap.get(connectionId));
+ if (FutureRegistry.getInstance().get(connectionId) != null) {
+ FutureRegistry.getInstance().get(connectionId).setResponse(resultMap.get(connectionId));
}
}
}
From a84ce0b27a9147bd517ebe6152a9ef8297a4645c Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Mon, 6 Aug 2018 12:31:13 +0800
Subject: [PATCH 043/198] use Map> baseStatementUnitGroups
---
.../shardingsphere/core/executor/ExecutorEngine.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java
index 257adf89dbec1..940aadfda1715 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java
@@ -69,21 +69,21 @@ public ExecutorEngine(final int executorSize) {
* Execute.
*
* @param sqlType SQL type
- * @param baseStatementUnits statement execute unitS
+ * @param baseStatementUnitGroups statement execute unitS
* @param executeCallback prepared statement execute callback
* @param class type of return value
* @return execute result
* @throws SQLException SQL exception
*/
public List execute(
- final SQLType sqlType, final Collection extends BaseStatementUnit> baseStatementUnits, final ExecuteCallback executeCallback) throws SQLException {
- if (baseStatementUnits.isEmpty()) {
+ final SQLType sqlType, final Map> baseStatementUnitGroups, final ExecuteCallback executeCallback) throws SQLException {
+ if (baseStatementUnitGroups.isEmpty()) {
return Collections.emptyList();
}
- OverallExecutionEvent event = new OverallExecutionEvent(sqlType, baseStatementUnits.size());
+ OverallExecutionEvent event = new OverallExecutionEvent(sqlType, baseStatementUnitGroups.size());
EventBusInstance.getInstance().post(event);
try {
- List result = getExecuteResults(sqlType, baseStatementUnits, executeCallback);
+ List result = getExecuteResults(sqlType, baseStatementUnitGroups, executeCallback);
event.setEventExecutionType(EventExecutionType.EXECUTE_SUCCESS);
EventBusInstance.getInstance().post(event);
return result;
@@ -98,7 +98,7 @@ public List execute(
}
}
- protected abstract List getExecuteResults(SQLType sqlType, Collection extends BaseStatementUnit> baseStatementUnits, ExecuteCallback executeCallback) throws Exception;
+ protected abstract List getExecuteResults(SQLType sqlType, Map> baseStatementUnitGroups, ExecuteCallback executeCallback) throws Exception;
protected T executeInternal(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback,
final boolean isExceptionThrown, final Map dataMap) throws Exception {
From 9ea1afba01947b3e2fffd4200b4ee92a3c8a5ecc Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Mon, 6 Aug 2018 12:35:03 +0800
Subject: [PATCH 044/198] reverse
---
.../core/executor/ExecutorEngine.java | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java
index 940aadfda1715..4b0c08da66b18 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java
@@ -35,6 +35,7 @@
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -69,21 +70,22 @@ public ExecutorEngine(final int executorSize) {
* Execute.
*
* @param sqlType SQL type
- * @param baseStatementUnitGroups statement execute unitS
+ * @param baseStatementUnits statement execute unitS
* @param executeCallback prepared statement execute callback
* @param class type of return value
* @return execute result
* @throws SQLException SQL exception
*/
public List execute(
- final SQLType sqlType, final Map> baseStatementUnitGroups, final ExecuteCallback executeCallback) throws SQLException {
- if (baseStatementUnitGroups.isEmpty()) {
+ final SQLType sqlType, final Collection extends BaseStatementUnit> baseStatementUnits, final ExecuteCallback executeCallback) throws SQLException {
+ if (baseStatementUnits.isEmpty()) {
return Collections.emptyList();
}
- OverallExecutionEvent event = new OverallExecutionEvent(sqlType, baseStatementUnitGroups.size());
+ OverallExecutionEvent event = new OverallExecutionEvent(sqlType, baseStatementUnits.size());
EventBusInstance.getInstance().post(event);
+ Iterator extends BaseStatementUnit> iterator = baseStatementUnits.iterator();
try {
- List result = getExecuteResults(sqlType, baseStatementUnitGroups, executeCallback);
+ List result = getExecuteResults(sqlType, baseStatementUnits, executeCallback);
event.setEventExecutionType(EventExecutionType.EXECUTE_SUCCESS);
EventBusInstance.getInstance().post(event);
return result;
@@ -98,9 +100,9 @@ public List execute(
}
}
- protected abstract List getExecuteResults(SQLType sqlType, Map> baseStatementUnitGroups, ExecuteCallback executeCallback) throws Exception;
+ protected abstract List getExecuteResults(SQLType sqlType, Collection extends BaseStatementUnit> baseStatementUnits, ExecuteCallback executeCallback);
- protected T executeInternal(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback,
+ protected T executeInternal(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback,
final boolean isExceptionThrown, final Map dataMap) throws Exception {
synchronized (baseStatementUnit.getStatement().getConnection()) {
T result;
From b3971b6ffa213dd0d4d888b898c4514e565768fe Mon Sep 17 00:00:00 2001
From: tuohai666
Date: Mon, 6 Aug 2018 12:35:15 +0800
Subject: [PATCH 045/198] #1099, change FrontendExecutorContext to
UserGroupContext
---
.../proxy/frontend/ShardingProxy.java | 8 ++++---
...utorContext.java => UserGroupContext.java} | 22 +++++++++----------
.../common/executor/ExecutorGroup.java | 4 ++--
3 files changed, 17 insertions(+), 17 deletions(-)
rename sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/{FrontendExecutorContext.java => UserGroupContext.java} (53%)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java
index 588fb65d752f4..99629d5fe463d 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java
@@ -48,14 +48,14 @@ public final class ShardingProxy {
private static final RuleRegistry RULE_REGISTRY = RuleRegistry.getInstance();
- private final FrontendExecutorContext frontendExecutorContext = FrontendExecutorContext.getInstance();
-
private final BackendExecutorContext backendExecutorContext = BackendExecutorContext.getInstance();
private EventLoopGroup bossGroup;
private EventLoopGroup workerGroup;
+ private final UserGroupContext userGroupContext = UserGroupContext.getInstance();
+
public ShardingProxy() {
RULE_REGISTRY.initShardingMetaData(backendExecutorContext.getExecutorService());
}
@@ -84,7 +84,7 @@ public void start(final int port) throws InterruptedException, MalformedURLExcep
} finally {
workerGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
- frontendExecutorContext.getExecutorService().shutdown();
+ userGroupContext.getUserGroup().shutdownGracefully();
backendExecutorContext.getExecutorService().shutdown();
if (RULE_REGISTRY.getBackendNIOConfig().isUseNIO()) {
ShardingProxyClient.getInstance().stop();
@@ -102,6 +102,7 @@ private EventLoopGroup createEventLoopGroup() {
private void groupsEpoll(final ServerBootstrap bootstrap) {
workerGroup = new EpollEventLoopGroup(RULE_REGISTRY.getExecutorSize());
+ userGroupContext.setUserGroup(new EpollEventLoopGroup(RULE_REGISTRY.getExecutorSize()));
bootstrap.group(bossGroup, workerGroup)
.channel(EpollServerSocketChannel.class)
.option(EpollChannelOption.SO_BACKLOG, 128)
@@ -114,6 +115,7 @@ private void groupsEpoll(final ServerBootstrap bootstrap) {
private void groupsNio(final ServerBootstrap bootstrap) {
workerGroup = new NioEventLoopGroup(RULE_REGISTRY.getExecutorSize());
+ userGroupContext.setUserGroup(new NioEventLoopGroup(RULE_REGISTRY.getExecutorSize()));
bootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 128)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/FrontendExecutorContext.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/UserGroupContext.java
similarity index 53%
rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/FrontendExecutorContext.java
rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/UserGroupContext.java
index 2eb7e842101ff..9557d9272c63c 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/FrontendExecutorContext.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/UserGroupContext.java
@@ -17,31 +17,29 @@
package io.shardingsphere.proxy.frontend;
-import com.google.common.util.concurrent.ListeningExecutorService;
-import com.google.common.util.concurrent.MoreExecutors;
-import io.shardingsphere.proxy.config.RuleRegistry;
+import io.netty.channel.EventLoopGroup;
import lombok.Getter;
-
-import java.util.concurrent.Executors;
+import lombok.Setter;
/**
- * Frontend executor context.
+ * User group context.
*
* @author zhangyonglun
*/
-public final class FrontendExecutorContext {
+public final class UserGroupContext {
- private static final FrontendExecutorContext INSTANCE = new FrontendExecutorContext();
+ private static final UserGroupContext INSTANCE = new UserGroupContext();
@Getter
- private final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(RuleRegistry.getInstance().getExecutorSize()));
+ @Setter
+ private EventLoopGroup userGroup;
/**
- * Get frontend executor context instance.
+ * Get user group context instance.
*
- * @return instance of frontend executor context
+ * @return instance of user group context
*/
- public static FrontendExecutorContext getInstance() {
+ public static UserGroupContext getInstance() {
return INSTANCE;
}
}
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/executor/ExecutorGroup.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/executor/ExecutorGroup.java
index 109c9c6e9d155..8d02443af3682 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/executor/ExecutorGroup.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/executor/ExecutorGroup.java
@@ -20,7 +20,7 @@
import io.netty.channel.ChannelId;
import io.shardingsphere.core.constant.TransactionType;
import io.shardingsphere.proxy.config.RuleRegistry;
-import io.shardingsphere.proxy.frontend.FrontendExecutorContext;
+import io.shardingsphere.proxy.frontend.UserGroupContext;
import lombok.RequiredArgsConstructor;
import java.util.concurrent.ExecutorService;
@@ -44,6 +44,6 @@ public final class ExecutorGroup {
*/
public ExecutorService getExecutorService() {
return TransactionType.XA.equals(RULE_REGISTRY.getTransactionType()) ? ChannelThreadExecutorGroup.getInstance().get(channelId)
- : FrontendExecutorContext.getInstance().getExecutorService();
+ : UserGroupContext.getInstance().getUserGroup();
}
}
From 4cc45d3f708078453a8275d965879d80725b4b64 Mon Sep 17 00:00:00 2001
From: terrymanu
Date: Mon, 6 Aug 2018 12:40:09 +0800
Subject: [PATCH 046/198] refactor NettyBackendHandler
---
.../backend/netty/NettyBackendHandler.java | 22 ++++++++++---------
.../netty/future/SynchronizedFuture.java | 6 ++---
.../backend/netty/mysql/MySQLQueryResult.java | 1 +
3 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java
index f5fec55c2c25c..9cbd33b27ea14 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java
@@ -17,7 +17,6 @@
package io.shardingsphere.proxy.backend.netty;
-import com.google.common.collect.Lists;
import io.netty.channel.Channel;
import io.netty.channel.pool.SimpleChannelPool;
import io.shardingsphere.core.constant.DatabaseType;
@@ -36,6 +35,7 @@
import io.shardingsphere.proxy.backend.BackendExecutorContext;
import io.shardingsphere.proxy.backend.ResultPacket;
import io.shardingsphere.proxy.backend.netty.future.FutureRegistry;
+import io.shardingsphere.proxy.backend.netty.future.SynchronizedFuture;
import io.shardingsphere.proxy.backend.netty.mysql.MySQLQueryResult;
import io.shardingsphere.proxy.config.ProxyTableMetaDataConnectionManager;
import io.shardingsphere.proxy.config.RuleRegistry;
@@ -46,7 +46,6 @@
import io.shardingsphere.proxy.transport.mysql.packet.command.query.text.query.ComQueryPacket;
import io.shardingsphere.proxy.transport.mysql.packet.generic.ErrPacket;
import io.shardingsphere.proxy.transport.mysql.packet.generic.OKPacket;
-import io.shardingsphere.proxy.backend.netty.future.SynchronizedFuture;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -126,8 +125,7 @@ private CommandResponsePackets executeForSharding() throws InterruptedException,
}
List queryResults = synchronizedFuture.get(RULE_REGISTRY.getBackendNIOConfig().getConnectionTimeoutSeconds(), TimeUnit.SECONDS);
FutureRegistry.getInstance().delete(connectionId);
-
- List packets = Lists.newArrayListWithCapacity(queryResults.size());
+ List packets = new ArrayList<>(queryResults.size());
for (QueryResult each : queryResults) {
MySQLQueryResult queryResult = (MySQLQueryResult) each;
if (0 == currentSequenceId) {
@@ -138,13 +136,10 @@ private CommandResponsePackets executeForSharding() throws InterruptedException,
}
packets.add(queryResult.getCommandResponsePackets());
}
- CommandResponsePackets result = merge(routeResult.getSqlStatement(), packets, queryResults);
SQLStatement sqlStatement = routeResult.getSqlStatement();
- if (!RULE_REGISTRY.isMasterSlaveOnly() && SQLType.DDL == sqlStatement.getType() && !sqlStatement.getTables().isEmpty()) {
- String logicTableName = sqlStatement.getTables().getSingleTableName();
- TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader(
- BackendExecutorContext.getInstance().getExecutorService(), new ProxyTableMetaDataConnectionManager(RULE_REGISTRY.getBackendDataSource()));
- RULE_REGISTRY.getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, RULE_REGISTRY.getShardingRule()));
+ CommandResponsePackets result = merge(sqlStatement, packets, queryResults);
+ if (SQLType.DDL == sqlStatement.getType() && !sqlStatement.getTables().isEmpty()) {
+ refreshTableMetaData(sqlStatement.getTables().getSingleTableName());
}
return result;
}
@@ -201,6 +196,13 @@ private CommandResponsePackets mergeDQLorDAL(final SQLStatement sqlStatement, fi
return packets.get(0);
}
+ // TODO :jiaqi use sql packet to refresh meta data
+ private void refreshTableMetaData(final String logicTableName) {
+ TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader(
+ BackendExecutorContext.getInstance().getExecutorService(), new ProxyTableMetaDataConnectionManager(RULE_REGISTRY.getBackendDataSource()));
+ RULE_REGISTRY.getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, RULE_REGISTRY.getShardingRule()));
+ }
+
@Override
public boolean next() throws SQLException {
if (null == mergedResult || !mergedResult.next()) {
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java
index 0baff8fe1a3a1..477b359cd7028 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java
@@ -17,10 +17,10 @@
package io.shardingsphere.proxy.backend.netty.future;
-import com.google.common.collect.Lists;
import io.shardingsphere.core.merger.QueryResult;
import lombok.extern.slf4j.Slf4j;
+import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
@@ -33,7 +33,7 @@
* @author linjiaqi
*/
@Slf4j
-public class SynchronizedFuture implements Future> {
+public final class SynchronizedFuture implements Future> {
private final CountDownLatch latch;
@@ -43,7 +43,7 @@ public class SynchronizedFuture implements Future> {
public SynchronizedFuture(final int resultSize) {
latch = new CountDownLatch(resultSize);
- responses = Lists.newArrayListWithCapacity(resultSize);
+ responses = new ArrayList<>(resultSize);
}
@Override
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLQueryResult.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLQueryResult.java
index a36c6e5160b59..285d28b5127d6 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLQueryResult.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLQueryResult.java
@@ -45,6 +45,7 @@
*/
@Slf4j
public final class MySQLQueryResult implements QueryResult {
+
@Getter
private final CommandResponsePackets commandResponsePackets;
From 157ccc18014fd31a21f47a0c150d01fc9e7847cc Mon Sep 17 00:00:00 2001
From: tuohai666
Date: Mon, 6 Aug 2018 12:52:08 +0800
Subject: [PATCH 047/198] #1099, worker group and user group share the
acceptor.size configuration
---
.../core/constant/ShardingPropertiesConstant.java | 11 +++++++++++
.../io/shardingsphere/proxy/config/RuleRegistry.java | 3 +++
.../shardingsphere/proxy/frontend/ShardingProxy.java | 8 ++++----
sharding-proxy/src/main/resources/conf/config.yaml | 1 +
.../src/main/resources/conf/config_master_slave.yaml | 1 +
sharding-proxy/src/test/resources/conf/config.yaml | 1 +
6 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java
index d421c3593643e..fc2a8cd3b0aef 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java
@@ -42,6 +42,17 @@ public enum ShardingPropertiesConstant {
*/
SQL_SHOW("sql.show", Boolean.FALSE.toString(), boolean.class),
+ /**
+ * Worker group or user group thread max size.
+ *
+ *
+ * Worker group accept tcp connection.
+ * User group accept MySQL command.
+ * Default: CPU cores * 2.
+ *
+ */
+ ACCEPTOR_SIZE("acceptor.size", String.valueOf(Runtime.getRuntime().availableProcessors() * 2), int.class),
+
/**
* Worker thread max size.
*
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
index 9962a74e13256..cd64f2e14ae7f 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
@@ -75,6 +75,8 @@ public final class RuleRegistry {
private ConnectionMode connectionMode;
+ private int acceptorSize;
+
private int executorSize;
private BackendNIOConfiguration backendNIOConfig;
@@ -108,6 +110,7 @@ public synchronized void init(final OrchestrationProxyConfiguration config) {
connectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE));
transactionType = TransactionType.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_TRANSACTION_MODE));
transactionManager = ProxyTransactionLoader.load(transactionType);
+ acceptorSize = shardingProperties.getValue(ShardingPropertiesConstant.ACCEPTOR_SIZE);
executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE);
// TODO :jiaqi force off use NIO for backend, this feature is not complete yet
boolean useNIO = false;
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java
index 99629d5fe463d..88553689c9a70 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java
@@ -101,8 +101,8 @@ private EventLoopGroup createEventLoopGroup() {
}
private void groupsEpoll(final ServerBootstrap bootstrap) {
- workerGroup = new EpollEventLoopGroup(RULE_REGISTRY.getExecutorSize());
- userGroupContext.setUserGroup(new EpollEventLoopGroup(RULE_REGISTRY.getExecutorSize()));
+ workerGroup = new EpollEventLoopGroup(RULE_REGISTRY.getAcceptorSize());
+ userGroupContext.setUserGroup(new EpollEventLoopGroup(RULE_REGISTRY.getAcceptorSize()));
bootstrap.group(bossGroup, workerGroup)
.channel(EpollServerSocketChannel.class)
.option(EpollChannelOption.SO_BACKLOG, 128)
@@ -114,8 +114,8 @@ private void groupsEpoll(final ServerBootstrap bootstrap) {
}
private void groupsNio(final ServerBootstrap bootstrap) {
- workerGroup = new NioEventLoopGroup(RULE_REGISTRY.getExecutorSize());
- userGroupContext.setUserGroup(new NioEventLoopGroup(RULE_REGISTRY.getExecutorSize()));
+ workerGroup = new NioEventLoopGroup(RULE_REGISTRY.getAcceptorSize());
+ userGroupContext.setUserGroup(new NioEventLoopGroup(RULE_REGISTRY.getAcceptorSize()));
bootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 128)
diff --git a/sharding-proxy/src/main/resources/conf/config.yaml b/sharding-proxy/src/main/resources/conf/config.yaml
index 4c0f1905bee9c..7400815a5048d 100644
--- a/sharding-proxy/src/main/resources/conf/config.yaml
+++ b/sharding-proxy/src/main/resources/conf/config.yaml
@@ -61,6 +61,7 @@
# # 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 # The default value is available processors count.
# sql.show: false
#
diff --git a/sharding-proxy/src/main/resources/conf/config_master_slave.yaml b/sharding-proxy/src/main/resources/conf/config_master_slave.yaml
index 8a2be1004bc8c..e005afaeb829a 100644
--- a/sharding-proxy/src/main/resources/conf/config_master_slave.yaml
+++ b/sharding-proxy/src/main/resources/conf/config_master_slave.yaml
@@ -40,6 +40,7 @@
# # 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 # The default value is available processors count.
# sql.show: false
diff --git a/sharding-proxy/src/test/resources/conf/config.yaml b/sharding-proxy/src/test/resources/conf/config.yaml
index 86ff83e56a32c..1196350abf6fc 100644
--- a/sharding-proxy/src/test/resources/conf/config.yaml
+++ b/sharding-proxy/src/test/resources/conf/config.yaml
@@ -45,6 +45,7 @@ shardingRule:
props:
connection.mode: MEMORY_STRICTLY
+ acceptor.size: 16
executor.size: 16
sql.show: false
From 7f74a9e4a662d9cd2e1dc096de15e4c71d5fd3ac Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Mon, 6 Aug 2018 12:55:41 +0800
Subject: [PATCH 048/198] add ProxyMode proxyMode.
---
.../io/shardingsphere/core/jdbc/core/ShardingContext.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java
index cf7c16191e7e8..1ec523da155f1 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java
@@ -18,6 +18,7 @@
package io.shardingsphere.core.jdbc.core;
import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.constant.ProxyMode;
import io.shardingsphere.core.exception.ShardingException;
import io.shardingsphere.core.executor.ExecutorEngine;
import io.shardingsphere.core.metadata.ShardingMetaData;
@@ -54,15 +55,18 @@ public final class ShardingContext {
private final boolean showSQL;
+ private final ProxyMode proxyMode;
+
private final ShardingMetaData metaData;
public ShardingContext(final Map dataSourceMap, final ShardingRule shardingRule,
- final DatabaseType databaseType, final ExecutorEngine executorEngine, final ShardingTableMetaData shardingTableMetaData, final boolean showSQL) {
+ final DatabaseType databaseType, final ExecutorEngine executorEngine, final ShardingTableMetaData shardingTableMetaData, final boolean showSQL, final ProxyMode proxyMode) {
this.dataSourceMap = dataSourceMap;
this.shardingRule = shardingRule;
this.databaseType = databaseType;
this.executorEngine = executorEngine;
this.showSQL = showSQL;
+ this.proxyMode = proxyMode;
metaData = new ShardingMetaData(new ShardingDataSourceMetaData(getDataSourceURLs(dataSourceMap), shardingRule, databaseType), shardingTableMetaData);
}
From 8c475fc1a9d10ed258278048590995c72ce92f4a Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Mon, 6 Aug 2018 12:56:39 +0800
Subject: [PATCH 049/198] new ShardingContext
---
.../core/jdbc/core/datasource/ShardingDataSource.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java
index 5cac8709ae3c3..15d0273327e76 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java
@@ -77,7 +77,7 @@ public ShardingDataSource(final Map dataSourceMap, final Sha
boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW);
ProxyMode proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE));
executorEngine = ProxyMode.MEMORY_STRICTLY == proxyMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize);
- shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingTableMetaData, showSQL);
+ shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingTableMetaData, showSQL, proxyMode);
}
/**
@@ -102,7 +102,7 @@ public void renew(final Map newDataSourceMap, final Sharding
ShardingTableMetaData shardingMetaData = new ShardingTableMetaData(
new TableMetaDataInitializer(executorEngine.getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(newDataSourceMap)).load(newShardingRule));
shardingProperties = newShardingProperties;
- shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, shardingMetaData, newShowSQL);
+ shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, shardingMetaData, newShowSQL, newProxyMode);
}
@Override
From 3ea817aea89217e6a19ca4107b1c9f1e91858957 Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Mon, 6 Aug 2018 12:59:44 +0800
Subject: [PATCH 050/198] add getStatementUnitsForMemoryStrictly()
---
.../core/statement/ShardingStatement.java | 36 ++++++++++++++++---
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java
index b24c45ff2891a..99ba311049a9c 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java
@@ -18,6 +18,7 @@
package io.shardingsphere.core.jdbc.core.statement;
import com.google.common.base.Optional;
+import io.shardingsphere.core.constant.ProxyMode;
import io.shardingsphere.core.constant.SQLType;
import io.shardingsphere.core.executor.type.statement.StatementExecutor;
import io.shardingsphere.core.executor.type.statement.StatementUnit;
@@ -49,13 +50,16 @@
import lombok.AccessLevel;
import lombok.Getter;
+import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
/**
* Statement that support sharding.
@@ -209,14 +213,38 @@ public boolean execute(final String sql, final String[] columnNames) throws SQLE
private StatementExecutor generateExecutor(final String sql) throws SQLException {
clearPrevious();
sqlRoute(sql);
- Collection statementUnits = new LinkedList<>();
+ if (ProxyMode.MEMORY_STRICTLY == connection.getShardingContext().getProxyMode()) {
+ return new StatementExecutor(connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), getStatementUnitsForMemoryStrictly());
+ }
+ return new StatementExecutor(connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), getStatementUnitsForConnectionStrictly());
+ }
+
+ private Collection getStatementUnitsForConnectionStrictly() throws SQLException {
+ Collection result = new LinkedList<>();
+ Map connectionMap = new LinkedHashMap<>();
+ for (SQLExecutionUnit each : routeResult.getExecutionUnits()) {
+ String dataSourceName = each.getDataSource();
+ if (null == connectionMap.get(dataSourceName)) {
+ connectionMap.put(dataSourceName, connection.getConnection(each.getDataSource()));
+ }
+ Statement statement = connectionMap.get(dataSourceName).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
+ replayMethodsInvocation(statement);
+ result.add(new StatementUnit(each, statement));
+ routedStatements.add(statement);
+ }
+ return result;
+ }
+
+ private Collection getStatementUnitsForMemoryStrictly() throws SQLException {
+ Collection result = new LinkedList<>();
for (SQLExecutionUnit each : routeResult.getExecutionUnits()) {
- Statement statement = connection.getConnection(each.getDataSource()).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
+ String dataSourceName = each.getDataSource();
+ Statement statement = connection.getConnection(dataSourceName).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
replayMethodsInvocation(statement);
- statementUnits.add(new StatementUnit(each, statement));
+ result.add(new StatementUnit(each, statement));
routedStatements.add(statement);
}
- return new StatementExecutor(connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), statementUnits);
+ return result;
}
private void clearPrevious() throws SQLException {
From ecbfa6f68bc8a7d0903bca52d5f1bdd5f96ff440 Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Mon, 6 Aug 2018 13:41:29 +0800
Subject: [PATCH 051/198] add getPreparedStatementUnitsForMemoryStrictly()
---
.../statement/ShardingPreparedStatement.java | 40 +++++++++++++++----
1 file changed, 33 insertions(+), 7 deletions(-)
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java
index e179de57181e9..00fb01076b462 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java
@@ -20,6 +20,7 @@
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
+import io.shardingsphere.core.constant.ProxyMode;
import io.shardingsphere.core.constant.SQLType;
import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementExecutor;
import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementUnit;
@@ -60,8 +61,10 @@
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
/**
@@ -177,10 +180,33 @@ public boolean execute() throws SQLException {
}
private Collection route() throws SQLException {
- Collection result = new LinkedList<>();
sqlRoute();
+ if (ProxyMode.MEMORY_STRICTLY == connection.getShardingContext().getProxyMode()) {
+ return getPreparedStatementUnitsForMemoryStrictly();
+ }
+ return getPreparedStatementUnitsForConnectionStrictly();
+ }
+
+ private Collection