You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by se...@apache.org on 2018/01/11 07:20:16 UTC
[incubator-servicecomb-saga] 03/13: SCB-212 removed parent tx id
from omega context, since it's not necessary
This is an automated email from the ASF dual-hosted git repository.
seanyinx pushed a commit to branch SCB-212_tx_timeout
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-saga.git
commit 814c39aaf14823edd38516df937dab459d5fafe8
Author: seanyinx <se...@huawei.com>
AuthorDate: Wed Jan 10 15:56:53 2018 +0800
SCB-212 removed parent tx id from omega context, since it's not necessary
Signed-off-by: seanyinx <se...@huawei.com>
---
.../saga/omega/context/OmegaContext.java | 11 -----------
.../saga/omega/context/OmegaContextTest.java | 18 ------------------
.../transaction/spring/ExecutorFieldCallback.java | 13 ++++---------
.../saga/omega/transaction/TransactionAspect.java | 21 +++++++++------------
.../SagaStartAnnotationProcessorTest.java | 2 --
.../saga/omega/transaction/SagaStartAspectTest.java | 3 ---
.../omega/transaction/TransactionAspectTest.java | 3 ---
.../TransactionHandlerInterceptorTest.java | 2 --
8 files changed, 13 insertions(+), 60 deletions(-)
diff --git a/omega/omega-context/src/main/java/org/apache/servicecomb/saga/omega/context/OmegaContext.java b/omega/omega-context/src/main/java/org/apache/servicecomb/saga/omega/context/OmegaContext.java
index 43bf0b4..daa8e7c 100644
--- a/omega/omega-context/src/main/java/org/apache/servicecomb/saga/omega/context/OmegaContext.java
+++ b/omega/omega-context/src/main/java/org/apache/servicecomb/saga/omega/context/OmegaContext.java
@@ -23,7 +23,6 @@ public class OmegaContext {
private final ThreadLocal<String> globalTxId = new InheritableThreadLocal<>();
private final ThreadLocal<String> localTxId = new InheritableThreadLocal<>();
- private final ThreadLocal<String> parentTxId = new InheritableThreadLocal<>();
private final IdGenerator<String> idGenerator;
public OmegaContext(IdGenerator<String> idGenerator) {
@@ -58,18 +57,9 @@ public class OmegaContext {
return localTxId.get();
}
- public String parentTxId() {
- return parentTxId.get();
- }
-
- public void setParentTxId(String parentTxId) {
- this.parentTxId.set(parentTxId);
- }
-
public void clear() {
globalTxId.remove();
localTxId.remove();
- parentTxId.remove();
}
@Override
@@ -77,7 +67,6 @@ public class OmegaContext {
return "OmegaContext{" +
"globalTxId=" + globalTxId.get() +
", localTxId=" + localTxId.get() +
- ", parentTxId=" + parentTxId.get() +
'}';
}
}
diff --git a/omega/omega-context/src/test/java/org/apache/servicecomb/saga/omega/context/OmegaContextTest.java b/omega/omega-context/src/test/java/org/apache/servicecomb/saga/omega/context/OmegaContextTest.java
index 3f844d3..b741e88 100644
--- a/omega/omega-context/src/test/java/org/apache/servicecomb/saga/omega/context/OmegaContextTest.java
+++ b/omega/omega-context/src/test/java/org/apache/servicecomb/saga/omega/context/OmegaContextTest.java
@@ -67,24 +67,6 @@ public class OmegaContextTest {
CompletableFuture.allOf(future1, future2).join();
}
- @Test
- public void eachThreadGetsDifferentParentTxId() throws Exception {
- CyclicBarrier barrier = new CyclicBarrier(2);
-
- Runnable runnable = exceptionalRunnable(() -> {
- String parentId = UUID.randomUUID().toString();
- omegaContext.setParentTxId(parentId);
- barrier.await();
-
- assertThat(omegaContext.parentTxId(), is(parentId));
- });
-
- CompletableFuture<Void> future1 = CompletableFuture.runAsync(runnable);
- CompletableFuture<Void> future2 = CompletableFuture.runAsync(runnable);
-
- CompletableFuture.allOf(future1, future2).join();
- }
-
private Runnable exceptionalRunnable(ExceptionalRunnable runnable) {
return () -> {
try {
diff --git a/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/ExecutorFieldCallback.java b/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/ExecutorFieldCallback.java
index 5ae949d..e07356c 100644
--- a/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/ExecutorFieldCallback.java
+++ b/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/ExecutorFieldCallback.java
@@ -68,7 +68,6 @@ class ExecutorFieldCallback implements FieldCallback {
private final String globalTxId;
private final String localTxId;
- private final String parentTxId;
private final Object runnable;
private final OmegaContext omegaContext;
@@ -84,29 +83,25 @@ class ExecutorFieldCallback implements FieldCallback {
this.omegaContext = omegaContext;
this.globalTxId = omegaContext.globalTxId();
this.localTxId = omegaContext.localTxId();
- this.parentTxId = omegaContext.parentTxId();
this.runnable = runnable;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
- LOG.debug("Setting OmegaContext with globalTxId [{}], localTxId [{}], & parentTxId [{}]",
+ LOG.debug("Setting OmegaContext with globalTxId [{}] & localTxId [{}]",
globalTxId,
- localTxId,
- parentTxId);
+ localTxId);
omegaContext.setGlobalTxId(globalTxId);
omegaContext.setLocalTxId(localTxId);
- omegaContext.setParentTxId(parentTxId);
return method.invoke(runnable, args);
} finally {
omegaContext.clear();
- LOG.debug("Cleared OmegaContext with globalTxId [{}], localTxId [{}], & parentTxId [{}]",
+ LOG.debug("Cleared OmegaContext with globalTxId [{}] & localTxId [{}]",
globalTxId,
- localTxId,
- parentTxId);
+ localTxId);
}
}
}
diff --git a/omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/TransactionAspect.java b/omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/TransactionAspect.java
index f62b92e..b5c6859 100644
--- a/omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/TransactionAspect.java
+++ b/omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/TransactionAspect.java
@@ -53,23 +53,20 @@ public class TransactionAspect {
String signature = compensationMethodSignature(joinPoint, compensable, method);
String localTxId = context.localTxId();
- String parentTxId = context.parentTxId();
- context.setParentTxId(localTxId);
- preIntercept(joinPoint, signature);
+ preIntercept(joinPoint, signature, localTxId);
LOG.debug("Updated context {} for compensable method {} ", context, method.toString());
try {
Object result = joinPoint.proceed();
- postIntercept(signature);
+ postIntercept(signature, localTxId);
return result;
} catch (Throwable throwable) {
- interceptException(signature, throwable);
+ interceptException(signature, throwable, localTxId);
throw throwable;
} finally {
context.setLocalTxId(localTxId);
- context.setParentTxId(parentTxId);
LOG.debug("Restored context back to {}", context);
}
}
@@ -83,28 +80,28 @@ public class TransactionAspect {
.toString();
}
- private void preIntercept(ProceedingJoinPoint joinPoint, String signature) {
+ private void preIntercept(ProceedingJoinPoint joinPoint, String signature, String parentTxId) {
preTransactionInterceptor.intercept(
context.globalTxId(),
context.newLocalTxId(),
- context.parentTxId(),
+ parentTxId,
signature,
joinPoint.getArgs());
}
- private void postIntercept(String signature) {
+ private void postIntercept(String signature, String parentTxId) {
postTransactionInterceptor.intercept(
context.globalTxId(),
context.localTxId(),
- context.parentTxId(),
+ parentTxId,
signature);
}
- private void interceptException(String signature, Throwable throwable) {
+ private void interceptException(String signature, Throwable throwable, String parentTxId) {
failedTransactionInterceptor.intercept(
context.globalTxId(),
context.localTxId(),
- context.parentTxId(),
+ parentTxId,
signature,
throwable);
}
diff --git a/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/SagaStartAnnotationProcessorTest.java b/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/SagaStartAnnotationProcessorTest.java
index fba7826..0dadebe 100644
--- a/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/SagaStartAnnotationProcessorTest.java
+++ b/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/SagaStartAnnotationProcessorTest.java
@@ -57,7 +57,6 @@ public class SagaStartAnnotationProcessorTest {
assertThat(context.globalTxId(), is(globalTxId));
assertThat(context.localTxId(), is(globalTxId));
- assertThat(context.parentTxId(), is(nullValue()));
TxEvent event = messages.get(0);
@@ -87,6 +86,5 @@ public class SagaStartAnnotationProcessorTest {
assertThat(context.globalTxId(), is(nullValue()));
assertThat(context.localTxId(), is(nullValue()));
- assertThat(context.parentTxId(), is(nullValue()));
}
}
\ No newline at end of file
diff --git a/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/SagaStartAspectTest.java b/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/SagaStartAspectTest.java
index cfaa7b6..432b3ad 100644
--- a/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/SagaStartAspectTest.java
+++ b/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/SagaStartAspectTest.java
@@ -63,7 +63,6 @@ public class SagaStartAspectTest {
omegaContext.setGlobalTxId(globalTxId);
omegaContext.setLocalTxId(localTxId);
- omegaContext.setParentTxId(parentTxId);
}
@Test
@@ -89,7 +88,6 @@ public class SagaStartAspectTest {
assertThat(omegaContext.globalTxId(), is(nullValue()));
assertThat(omegaContext.localTxId(), is(nullValue()));
- assertThat(omegaContext.parentTxId(), is(nullValue()));
}
@Test
@@ -115,7 +113,6 @@ public class SagaStartAspectTest {
assertThat(omegaContext.globalTxId(), is(nullValue()));
assertThat(omegaContext.localTxId(), is(nullValue()));
- assertThat(omegaContext.parentTxId(), is(nullValue()));
}
private String doNothing() {
diff --git a/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/TransactionAspectTest.java b/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/TransactionAspectTest.java
index bd8829c..65f23a7 100644
--- a/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/TransactionAspectTest.java
+++ b/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/TransactionAspectTest.java
@@ -64,7 +64,6 @@ public class TransactionAspectTest {
omegaContext.setGlobalTxId(globalTxId);
omegaContext.setLocalTxId(localTxId);
- omegaContext.setParentTxId(parentTxId);
}
@Test
@@ -89,7 +88,6 @@ public class TransactionAspectTest {
assertThat(omegaContext.globalTxId(), is(globalTxId));
assertThat(omegaContext.localTxId(), is(localTxId));
- assertThat(omegaContext.parentTxId(), is(parentTxId));
}
@Test
@@ -115,7 +113,6 @@ public class TransactionAspectTest {
assertThat(omegaContext.globalTxId(), is(globalTxId));
assertThat(omegaContext.localTxId(), is(localTxId));
- assertThat(omegaContext.parentTxId(), is(parentTxId));
}
private String doNothing() {
diff --git a/omega/omega-transport/omega-transport-resttemplate/src/test/java/org/apache/servicecomb/saga/omega/transport/resttemplate/TransactionHandlerInterceptorTest.java b/omega/omega-transport/omega-transport-resttemplate/src/test/java/org/apache/servicecomb/saga/omega/transport/resttemplate/TransactionHandlerInterceptorTest.java
index 03f278f..7b41540 100644
--- a/omega/omega-transport/omega-transport-resttemplate/src/test/java/org/apache/servicecomb/saga/omega/transport/resttemplate/TransactionHandlerInterceptorTest.java
+++ b/omega/omega-transport/omega-transport-resttemplate/src/test/java/org/apache/servicecomb/saga/omega/transport/resttemplate/TransactionHandlerInterceptorTest.java
@@ -63,7 +63,6 @@ public class TransactionHandlerInterceptorTest {
assertThat(omegaContext.globalTxId(), is(globalTxId));
assertThat(omegaContext.localTxId(), is(localTxId));
- assertThat(omegaContext.parentTxId(), is(nullValue()));
}
@Test
@@ -74,7 +73,6 @@ public class TransactionHandlerInterceptorTest {
requestInterceptor.preHandle(request, response, null);
assertThat(omegaContext.globalTxId(), is(nullValue()));
- assertThat(omegaContext.parentTxId(), is(nullValue()));
assertThat(omegaContext.localTxId(), is(nullValue()));
}
}
--
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.