diff --git a/.gitignore b/.gitignore index 81f47f78431..e4c325744c2 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ server/.root.* Thumbs.db *.orig *.class +data* diff --git a/README.md b/README.md index db34b58a2cd..d6fd9a62047 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ - + # Seata: Simple Extensible Autonomous Transaction Architecture [![Build Status](https://travis-ci.org/seata/seata.svg?branch=develop)](https://travis-ci.org/seata/seata) [![codecov](https://codecov.io/gh/seata/seata/branch/develop/graph/badge.svg)](https://codecov.io/gh/seata/seata) -![license](https://img.shields.io/github/license/seata/seata.svg) -![maven](https://img.shields.io/maven-central/v/com.alibaba.fescar/fescar-all.svg) +[![license](https://img.shields.io/github/license/seata/seata.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) +[![maven](https://img.shields.io/maven-central/v/io.seata/seata-parent.svg)](https://search.maven.org/search?q=io.seata) ## What is Seata? @@ -136,16 +136,15 @@ Contributors are welcomed to join the FEATS project. Please check [CONTRIBUTING] ## Seata ecosystem * [Seata Ecosystem Entry](https://github.com/seata) - A GitHub group `seata` to gather all Seata relevant projects -* [Seata Samples](https://github.com/fescar-group/fescar-samples) - Samples for Seata -* [Seata Docker](https://github.com/fescar-group/fescar-docker) - Seata integration with docker -* [Seata K8s](https://github.com/fescar-group/fescar-k8s) - Seata integration with k8s -* [Awesome Seata](https://github.com/fescar-group/awesome-fescar) - Description of Seata related projects -* [Seata Website](https://github.com/fescar-group/fescar.io) - Seata official website (***In the process of design***) +* [Seata Samples](https://github.com/seata/seata-samples) - Samples for Seata +* [Seata Docker](https://github.com/seata/seata-docker) - Seata integration with docker +* [Seata K8s](https://github.com/seata/seata-k8s) - Seata integration with k8s +* [Awesome Seata](https://github.com/seata/awesome-seata) - Description of Seata related projects +* [Seata Website](https://github.com/seata/seata.github.io) - Seata official website (***In the process of design***) ## Contributors -This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. - +This project exists thanks to all the people who contribute. [[Contributors](https://github.com/seata/seata/graphs/contributors)]. ## License diff --git a/common/src/main/java/io/seata/common/Constants.java b/common/src/main/java/io/seata/common/Constants.java index 038b0d4ca5f..a76bacb155d 100644 --- a/common/src/main/java/io/seata/common/Constants.java +++ b/common/src/main/java/io/seata/common/Constants.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common; /** diff --git a/common/src/main/java/io/seata/common/XID.java b/common/src/main/java/io/seata/common/XID.java index 07ae0c6d570..7cb6ac8dd0c 100644 --- a/common/src/main/java/io/seata/common/XID.java +++ b/common/src/main/java/io/seata/common/XID.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common; /** diff --git a/common/src/main/java/io/seata/common/exception/EurekaRegistryException.java b/common/src/main/java/io/seata/common/exception/EurekaRegistryException.java index f385c9aa882..12c037708d5 100644 --- a/common/src/main/java/io/seata/common/exception/EurekaRegistryException.java +++ b/common/src/main/java/io/seata/common/exception/EurekaRegistryException.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/common/src/main/java/io/seata/common/exception/FrameworkErrorCode.java b/common/src/main/java/io/seata/common/exception/FrameworkErrorCode.java index 46eda8697b0..f78ecfca064 100644 --- a/common/src/main/java/io/seata/common/exception/FrameworkErrorCode.java +++ b/common/src/main/java/io/seata/common/exception/FrameworkErrorCode.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.exception; /** @@ -101,15 +100,15 @@ public enum FrameworkErrorCode { /** * The Err code. */ - public String errCode; + private String errCode; /** * The Err message. */ - public String errMessage; + private String errMessage; /** * The Err dispose. */ - public String errDispose; + private String errDispose; FrameworkErrorCode(String errCode, String errMessage, String errDispose) { this.errCode = errCode; @@ -117,6 +116,18 @@ public enum FrameworkErrorCode { this.errDispose = errDispose; } + public String getErrCode() { + return errCode; + } + + public String getErrMessage() { + return errMessage; + } + + public String getErrDispose() { + return errDispose; + } + @Override public String toString() { return String.format("[%s] [%s] [%s]", errCode, errMessage, errDispose); diff --git a/common/src/main/java/io/seata/common/exception/FrameworkException.java b/common/src/main/java/io/seata/common/exception/FrameworkException.java index 79674b6b4c2..cd867fd88aa 100644 --- a/common/src/main/java/io/seata/common/exception/FrameworkException.java +++ b/common/src/main/java/io/seata/common/exception/FrameworkException.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.exception; import java.sql.SQLException; @@ -47,7 +46,7 @@ public FrameworkException() { * @param err the err */ public FrameworkException(FrameworkErrorCode err) { - this(err.errMessage, err); + this(err.getErrMessage(), err); } /** diff --git a/common/src/main/java/io/seata/common/exception/NotSupportYetException.java b/common/src/main/java/io/seata/common/exception/NotSupportYetException.java index 54c92ba0ae5..b32faa44c55 100644 --- a/common/src/main/java/io/seata/common/exception/NotSupportYetException.java +++ b/common/src/main/java/io/seata/common/exception/NotSupportYetException.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.exception; /** diff --git a/common/src/main/java/io/seata/common/exception/ShouldNeverHappenException.java b/common/src/main/java/io/seata/common/exception/ShouldNeverHappenException.java index aefaa5e8472..baefd3f5f23 100644 --- a/common/src/main/java/io/seata/common/exception/ShouldNeverHappenException.java +++ b/common/src/main/java/io/seata/common/exception/ShouldNeverHappenException.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.exception; /** diff --git a/common/src/main/java/io/seata/common/exception/StoreException.java b/common/src/main/java/io/seata/common/exception/StoreException.java index c59dfdbbc63..70622471ad5 100644 --- a/common/src/main/java/io/seata/common/exception/StoreException.java +++ b/common/src/main/java/io/seata/common/exception/StoreException.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/common/src/main/java/io/seata/common/executor/Callback.java b/common/src/main/java/io/seata/common/executor/Callback.java index 287bb85111b..2fb54d4b792 100644 --- a/common/src/main/java/io/seata/common/executor/Callback.java +++ b/common/src/main/java/io/seata/common/executor/Callback.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.executor; /** diff --git a/common/src/main/java/io/seata/common/executor/Initialize.java b/common/src/main/java/io/seata/common/executor/Initialize.java index 7555ab44fcb..2d711551df9 100644 --- a/common/src/main/java/io/seata/common/executor/Initialize.java +++ b/common/src/main/java/io/seata/common/executor/Initialize.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.executor; /** diff --git a/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java b/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java index 69b4e53bbb8..d10d95999bc 100644 --- a/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java +++ b/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.loader; import java.io.BufferedReader; diff --git a/common/src/main/java/io/seata/common/loader/EnhancedServiceNotFoundException.java b/common/src/main/java/io/seata/common/loader/EnhancedServiceNotFoundException.java index ad56a04c968..9fbf355919a 100644 --- a/common/src/main/java/io/seata/common/loader/EnhancedServiceNotFoundException.java +++ b/common/src/main/java/io/seata/common/loader/EnhancedServiceNotFoundException.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.loader; import org.apache.commons.lang.exception.NestableRuntimeException; diff --git a/common/src/main/java/io/seata/common/loader/LoadLevel.java b/common/src/main/java/io/seata/common/loader/LoadLevel.java index b4adff0fbee..b01ebf76c74 100644 --- a/common/src/main/java/io/seata/common/loader/LoadLevel.java +++ b/common/src/main/java/io/seata/common/loader/LoadLevel.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.loader; import java.lang.annotation.Documented; diff --git a/common/src/main/java/io/seata/common/thread/NamedThreadFactory.java b/common/src/main/java/io/seata/common/thread/NamedThreadFactory.java index 8e3c98b00fc..e53b531765d 100644 --- a/common/src/main/java/io/seata/common/thread/NamedThreadFactory.java +++ b/common/src/main/java/io/seata/common/thread/NamedThreadFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.thread; import java.util.concurrent.ThreadFactory; diff --git a/common/src/main/java/io/seata/common/thread/RejectedPolicies.java b/common/src/main/java/io/seata/common/thread/RejectedPolicies.java index f0e1e4c2ab7..9a131fd54a2 100644 --- a/common/src/main/java/io/seata/common/thread/RejectedPolicies.java +++ b/common/src/main/java/io/seata/common/thread/RejectedPolicies.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.thread; import java.util.concurrent.BlockingQueue; diff --git a/common/src/main/java/io/seata/common/util/BlobUtils.java b/common/src/main/java/io/seata/common/util/BlobUtils.java index e850e2cc007..3eb62aa0c28 100644 --- a/common/src/main/java/io/seata/common/util/BlobUtils.java +++ b/common/src/main/java/io/seata/common/util/BlobUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.util; import java.io.ByteArrayOutputStream; diff --git a/common/src/main/java/io/seata/common/util/CollectionUtils.java b/common/src/main/java/io/seata/common/util/CollectionUtils.java index b5d177a7813..1ad659d8b9e 100644 --- a/common/src/main/java/io/seata/common/util/CollectionUtils.java +++ b/common/src/main/java/io/seata/common/util/CollectionUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.util; import java.util.Collection; diff --git a/common/src/main/java/io/seata/common/util/CompressUtil.java b/common/src/main/java/io/seata/common/util/CompressUtil.java index 48043fa058b..5236b1846e7 100644 --- a/common/src/main/java/io/seata/common/util/CompressUtil.java +++ b/common/src/main/java/io/seata/common/util/CompressUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -87,9 +87,7 @@ public static byte[] uncompress(final byte[] src) throws IOException { public static boolean isCompressData(byte[] bytes) { if (bytes != null && bytes.length > 2) { int header = ((bytes[0] & 0xff)) | (bytes[1] & 0xff) << 8; - if (GZIPInputStream.GZIP_MAGIC == header) { - return true; - } + return GZIPInputStream.GZIP_MAGIC == header; } return false; } diff --git a/common/src/main/java/io/seata/common/util/NetUtil.java b/common/src/main/java/io/seata/common/util/NetUtil.java index 66ce2796c3e..5ffe7a4be73 100644 --- a/common/src/main/java/io/seata/common/util/NetUtil.java +++ b/common/src/main/java/io/seata/common/util/NetUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.util; import java.net.InetAddress; diff --git a/common/src/main/java/io/seata/common/util/ReflectionUtil.java b/common/src/main/java/io/seata/common/util/ReflectionUtil.java index 0a0c0912b22..a9753ddc2a1 100644 --- a/common/src/main/java/io/seata/common/util/ReflectionUtil.java +++ b/common/src/main/java/io/seata/common/util/ReflectionUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.util; import java.lang.reflect.Field; @@ -33,7 +32,7 @@ public class ReflectionUtil { /** * The constant MAX_NEST_DEPTH. */ - public static int MAX_NEST_DEPTH = 20; + public static final int MAX_NEST_DEPTH = 20; /** * Gets class by name. @@ -177,7 +176,7 @@ public static Method getMethod(Class classType, String methodName, Class[] */ public static Set> getInterfaces(Class clazz){ if (clazz.isInterface() ) { - return Collections.>singleton(clazz); + return Collections.singleton(clazz); } Set> interfaces = new LinkedHashSet>(); while (clazz != null) { diff --git a/common/src/main/java/io/seata/common/util/StringUtils.java b/common/src/main/java/io/seata/common/util/StringUtils.java index b25b5910f53..db98e470ac3 100644 --- a/common/src/main/java/io/seata/common/util/StringUtils.java +++ b/common/src/main/java/io/seata/common/util/StringUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.util; import java.io.ByteArrayOutputStream; diff --git a/common/src/test/java/io/seata/common/XIDTest.java b/common/src/test/java/io/seata/common/XIDTest.java index a02e9ab8efe..04f55842288 100644 --- a/common/src/test/java/io/seata/common/XIDTest.java +++ b/common/src/test/java/io/seata/common/XIDTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common; import java.util.Random; diff --git a/common/src/test/java/io/seata/common/exception/FrameworkExceptionTest.java b/common/src/test/java/io/seata/common/exception/FrameworkExceptionTest.java index 354f8515e8d..9e9e9c3cc75 100644 --- a/common/src/test/java/io/seata/common/exception/FrameworkExceptionTest.java +++ b/common/src/test/java/io/seata/common/exception/FrameworkExceptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.exception; import java.sql.SQLException; @@ -41,7 +40,7 @@ public void testGetErrcode() { message.print4(); } catch (FrameworkException e) { assertThat(e).isInstanceOf(FrameworkException.class).hasMessage( - FrameworkErrorCode.UnknownAppError.errMessage); + FrameworkErrorCode.UnknownAppError.getErrMessage()); assertThat(e.getErrcode()).isEqualTo(FrameworkErrorCode.UnknownAppError); } } @@ -103,7 +102,7 @@ public void testNestedException5() { message.print5(); } catch (Exception e) { assertThat(e).isInstanceOf(FrameworkException.class).hasMessage( - FrameworkErrorCode.ExceptionCaught.errMessage); + FrameworkErrorCode.ExceptionCaught.getErrMessage()); } } diff --git a/common/src/test/java/io/seata/common/exception/Message.java b/common/src/test/java/io/seata/common/exception/Message.java index 14d1fba0e81..c41c9a8292a 100644 --- a/common/src/test/java/io/seata/common/exception/Message.java +++ b/common/src/test/java/io/seata/common/exception/Message.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.exception; import java.sql.SQLException; diff --git a/common/src/test/java/io/seata/common/loader/ChineseHello.java b/common/src/test/java/io/seata/common/loader/ChineseHello.java index ae81108f972..57d696ea061 100644 --- a/common/src/test/java/io/seata/common/loader/ChineseHello.java +++ b/common/src/test/java/io/seata/common/loader/ChineseHello.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.loader; /** diff --git a/common/src/test/java/io/seata/common/loader/EnglishHello.java b/common/src/test/java/io/seata/common/loader/EnglishHello.java index 887333725aa..6e3f1b64fdc 100644 --- a/common/src/test/java/io/seata/common/loader/EnglishHello.java +++ b/common/src/test/java/io/seata/common/loader/EnglishHello.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.loader; /** diff --git a/common/src/test/java/io/seata/common/loader/EnhancedServiceLoaderTest.java b/common/src/test/java/io/seata/common/loader/EnhancedServiceLoaderTest.java index d82a9ff42ca..a3761da5f3f 100644 --- a/common/src/test/java/io/seata/common/loader/EnhancedServiceLoaderTest.java +++ b/common/src/test/java/io/seata/common/loader/EnhancedServiceLoaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.loader; import java.util.List; diff --git a/common/src/test/java/io/seata/common/loader/FrenchHello.java b/common/src/test/java/io/seata/common/loader/FrenchHello.java index 19680738776..144c7860da6 100644 --- a/common/src/test/java/io/seata/common/loader/FrenchHello.java +++ b/common/src/test/java/io/seata/common/loader/FrenchHello.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.loader; /** diff --git a/common/src/test/java/io/seata/common/loader/Hello.java b/common/src/test/java/io/seata/common/loader/Hello.java index e2b8fbd6bf0..dee66c05c71 100644 --- a/common/src/test/java/io/seata/common/loader/Hello.java +++ b/common/src/test/java/io/seata/common/loader/Hello.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.loader; /** diff --git a/common/src/test/java/io/seata/common/thread/NamedThreadFactoryTest.java b/common/src/test/java/io/seata/common/thread/NamedThreadFactoryTest.java index 71d23a0f8d2..046a2492c24 100644 --- a/common/src/test/java/io/seata/common/thread/NamedThreadFactoryTest.java +++ b/common/src/test/java/io/seata/common/thread/NamedThreadFactoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/common/src/test/java/io/seata/common/thread/RejectedPoliciesTest.java b/common/src/test/java/io/seata/common/thread/RejectedPoliciesTest.java index 0a89f569be1..f84e7a6ba47 100644 --- a/common/src/test/java/io/seata/common/thread/RejectedPoliciesTest.java +++ b/common/src/test/java/io/seata/common/thread/RejectedPoliciesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.thread; import java.util.concurrent.CountDownLatch; diff --git a/common/src/test/java/io/seata/common/util/BlobUtilsTest.java b/common/src/test/java/io/seata/common/util/BlobUtilsTest.java index 56854a3d519..e65d917e760 100644 --- a/common/src/test/java/io/seata/common/util/BlobUtilsTest.java +++ b/common/src/test/java/io/seata/common/util/BlobUtilsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/common/src/test/java/io/seata/common/util/NetUtilTest.java b/common/src/test/java/io/seata/common/util/NetUtilTest.java index ad52e3b676c..8ac10950cb9 100644 --- a/common/src/test/java/io/seata/common/util/NetUtilTest.java +++ b/common/src/test/java/io/seata/common/util/NetUtilTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/common/src/test/java/io/seata/common/util/StringUtilsTest.java b/common/src/test/java/io/seata/common/util/StringUtilsTest.java index 6202d02d1fc..a6f2e04de15 100644 --- a/common/src/test/java/io/seata/common/util/StringUtilsTest.java +++ b/common/src/test/java/io/seata/common/util/StringUtilsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.util; import java.io.IOException; diff --git a/config/seata-config-apollo/src/main/java/io/seata/config/apollo/ApolloConfiguration.java b/config/seata-config-apollo/src/main/java/io/seata/config/apollo/ApolloConfiguration.java index 19eeeb68add..561caef4842 100644 --- a/config/seata-config-apollo/src/main/java/io/seata/config/apollo/ApolloConfiguration.java +++ b/config/seata-config-apollo/src/main/java/io/seata/config/apollo/ApolloConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.config.apollo; import java.util.List; diff --git a/config/seata-config-apollo/src/main/java/io/seata/config/apollo/ApolloConfigurationProvider.java b/config/seata-config-apollo/src/main/java/io/seata/config/apollo/ApolloConfigurationProvider.java index ebff7a19547..f3756e06e37 100644 --- a/config/seata-config-apollo/src/main/java/io/seata/config/apollo/ApolloConfigurationProvider.java +++ b/config/seata-config-apollo/src/main/java/io/seata/config/apollo/ApolloConfigurationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/config/seata-config-core/src/main/java/io/seata/config/AbstractConfiguration.java b/config/seata-config-core/src/main/java/io/seata/config/AbstractConfiguration.java index 9cd7fe9f4dd..7cd509eccdd 100644 --- a/config/seata-config-core/src/main/java/io/seata/config/AbstractConfiguration.java +++ b/config/seata-config-core/src/main/java/io/seata/config/AbstractConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.config; /** diff --git a/config/seata-config-core/src/main/java/io/seata/config/ConfigChangeListener.java b/config/seata-config-core/src/main/java/io/seata/config/ConfigChangeListener.java index 6ae503db352..8cca750f4d4 100644 --- a/config/seata-config-core/src/main/java/io/seata/config/ConfigChangeListener.java +++ b/config/seata-config-core/src/main/java/io/seata/config/ConfigChangeListener.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.config; import java.util.concurrent.ExecutorService; diff --git a/config/seata-config-core/src/main/java/io/seata/config/ConfigFuture.java b/config/seata-config-core/src/main/java/io/seata/config/ConfigFuture.java index 148a0c6d5dc..c1f4eae6779 100644 --- a/config/seata-config-core/src/main/java/io/seata/config/ConfigFuture.java +++ b/config/seata-config-core/src/main/java/io/seata/config/ConfigFuture.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.config; import java.util.concurrent.CountDownLatch; @@ -205,6 +204,6 @@ public enum ConfigOperation { /** * Remove config operation. */ - REMOVE; + REMOVE } } diff --git a/config/seata-config-core/src/main/java/io/seata/config/ConfigType.java b/config/seata-config-core/src/main/java/io/seata/config/ConfigType.java index ee0425fdbf8..8f4ced0b101 100644 --- a/config/seata-config-core/src/main/java/io/seata/config/ConfigType.java +++ b/config/seata-config-core/src/main/java/io/seata/config/ConfigType.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.config; /** diff --git a/config/seata-config-core/src/main/java/io/seata/config/Configuration.java b/config/seata-config-core/src/main/java/io/seata/config/Configuration.java index 72a18196269..bb3e1a7c18c 100644 --- a/config/seata-config-core/src/main/java/io/seata/config/Configuration.java +++ b/config/seata-config-core/src/main/java/io/seata/config/Configuration.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.config; import java.util.List; diff --git a/config/seata-config-core/src/main/java/io/seata/config/ConfigurationFactory.java b/config/seata-config-core/src/main/java/io/seata/config/ConfigurationFactory.java index 9b2b373ee0f..0b802b3d344 100644 --- a/config/seata-config-core/src/main/java/io/seata/config/ConfigurationFactory.java +++ b/config/seata-config-core/src/main/java/io/seata/config/ConfigurationFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.config; import io.seata.common.exception.NotSupportYetException; diff --git a/config/seata-config-core/src/main/java/io/seata/config/ConfigurationKeys.java b/config/seata-config-core/src/main/java/io/seata/config/ConfigurationKeys.java index 66d33cb9325..2a520d9047f 100644 --- a/config/seata-config-core/src/main/java/io/seata/config/ConfigurationKeys.java +++ b/config/seata-config-core/src/main/java/io/seata/config/ConfigurationKeys.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.config; /** diff --git a/config/seata-config-core/src/main/java/io/seata/config/ConfigurationProvider.java b/config/seata-config-core/src/main/java/io/seata/config/ConfigurationProvider.java index 3cd85321a34..2d2772654f2 100644 --- a/config/seata-config-core/src/main/java/io/seata/config/ConfigurationProvider.java +++ b/config/seata-config-core/src/main/java/io/seata/config/ConfigurationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/config/seata-config-core/src/main/java/io/seata/config/FileConfiguration.java b/config/seata-config-core/src/main/java/io/seata/config/FileConfiguration.java index 3f3606fdea9..1ef77b9d5a0 100644 --- a/config/seata-config-core/src/main/java/io/seata/config/FileConfiguration.java +++ b/config/seata-config-core/src/main/java/io/seata/config/FileConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.config; import java.util.ArrayList; diff --git a/config/seata-config-core/src/main/resources/file.conf b/config/seata-config-core/src/main/resources/file.conf index 9cd05c0ec5f..30801f29901 100644 --- a/config/seata-config-core/src/main/resources/file.conf +++ b/config/seata-config-core/src/main/resources/file.conf @@ -20,16 +20,37 @@ transport { worker-thread-size = 8 } } +## transaction log store store { - # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions - max-branch-session-size = 16384 - # globe session size , if exceeded throws exceptions - max-global-session-size = 512 - # file buffer size , if exceeded allocate new buffer - file-write-buffer-cache-size = 16384 - # when recover batch read size - session.reload.read_size = 100 + ## store mode: file、db + mode = "file" + + ## file store + file { + dir = "sessionStore" + + # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions + max-branch-session-size = 16384 + # globe session size , if exceeded throws exceptions + max-global-session-size = 512 + # file buffer size , if exceeded allocate new buffer + file-write-buffer-cache-size = 16384 + # when recover batch read size + session.reload.read_size = 100 + # async, sync + flush-disk-mode = async + } + + ## database store + db { + driver_class = "" + url = "" + user = "" + password = "" + } + } + service { #vgroup->rgroup vgroup_mapping.my_test_tx_group = "default" diff --git a/config/seata-config-core/src/main/resources/registry.conf b/config/seata-config-core/src/main/resources/registry.conf index 1aa9dfa5a6f..15677236a89 100644 --- a/config/seata-config-core/src/main/resources/registry.conf +++ b/config/seata-config-core/src/main/resources/registry.conf @@ -1,5 +1,5 @@ registry { - # file 、nacos 、eureka、redis、zk、consul + # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa type = "file" nacos { @@ -26,6 +26,19 @@ registry { cluster = "default" serverAddr = "127.0.0.1:8500" } + etcd3 { + cluster = "default" + serverAddr = "http://localhost:2379" + } + sofa { + serverAddr = "127.0.0.1:9603" + application = "default" + region = "DEFAULT_ZONE" + datacenter = "DefaultDataCenter" + cluster = "default" + group = "SEATA_GROUP" + addressWaitTime = "3000" + } file { name = "file.conf" } diff --git a/config/seata-config-nacos/src/main/java/io/seata/config/nacos/NacosConfiguration.java b/config/seata-config-nacos/src/main/java/io/seata/config/nacos/NacosConfiguration.java index 294280868b9..f38f0eedcad 100644 --- a/config/seata-config-nacos/src/main/java/io/seata/config/nacos/NacosConfiguration.java +++ b/config/seata-config-nacos/src/main/java/io/seata/config/nacos/NacosConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.config.nacos; import java.util.List; diff --git a/config/seata-config-nacos/src/main/java/io/seata/config/nacos/NacosConfigurationProvider.java b/config/seata-config-nacos/src/main/java/io/seata/config/nacos/NacosConfigurationProvider.java index dd0c4f943d6..2bab83bb086 100644 --- a/config/seata-config-nacos/src/main/java/io/seata/config/nacos/NacosConfigurationProvider.java +++ b/config/seata-config-nacos/src/main/java/io/seata/config/nacos/NacosConfigurationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/config/seata-config-zk/src/main/java/io/seata/config/zk/ZookeeperConfiguration.java b/config/seata-config-zk/src/main/java/io/seata/config/zk/ZookeeperConfiguration.java index 13f5c9fc28f..c5f4e332dd8 100644 --- a/config/seata-config-zk/src/main/java/io/seata/config/zk/ZookeeperConfiguration.java +++ b/config/seata-config-zk/src/main/java/io/seata/config/zk/ZookeeperConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.config.zk; import java.util.List; diff --git a/config/seata-config-zk/src/main/java/io/seata/config/zk/ZookeeperConfigurationProvider.java b/config/seata-config-zk/src/main/java/io/seata/config/zk/ZookeeperConfigurationProvider.java index b51f8f5144b..9cddf37f80c 100644 --- a/config/seata-config-zk/src/main/java/io/seata/config/zk/ZookeeperConfigurationProvider.java +++ b/config/seata-config-zk/src/main/java/io/seata/config/zk/ZookeeperConfigurationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/main/java/io/seata/core/constants/ConfigurationKeys.java b/core/src/main/java/io/seata/core/constants/ConfigurationKeys.java index 3036a4414d3..4df7b3f11c6 100644 --- a/core/src/main/java/io/seata/core/constants/ConfigurationKeys.java +++ b/core/src/main/java/io/seata/core/constants/ConfigurationKeys.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.constants; /** diff --git a/core/src/main/java/io/seata/core/context/ContextCore.java b/core/src/main/java/io/seata/core/context/ContextCore.java index 55305571f2b..022c786a0f8 100644 --- a/core/src/main/java/io/seata/core/context/ContextCore.java +++ b/core/src/main/java/io/seata/core/context/ContextCore.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.context; /** diff --git a/core/src/main/java/io/seata/core/context/ContextCoreLoader.java b/core/src/main/java/io/seata/core/context/ContextCoreLoader.java index afa39cc02d2..2000bd5b942 100644 --- a/core/src/main/java/io/seata/core/context/ContextCoreLoader.java +++ b/core/src/main/java/io/seata/core/context/ContextCoreLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.context; import io.seata.common.loader.EnhancedServiceLoader; diff --git a/core/src/main/java/io/seata/core/context/RootContext.java b/core/src/main/java/io/seata/core/context/RootContext.java index 46fe17b5b64..f7946f44a28 100644 --- a/core/src/main/java/io/seata/core/context/RootContext.java +++ b/core/src/main/java/io/seata/core/context/RootContext.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.context; import io.seata.common.exception.ShouldNeverHappenException; diff --git a/core/src/main/java/io/seata/core/context/ThreadLocalContextCore.java b/core/src/main/java/io/seata/core/context/ThreadLocalContextCore.java index 65833d1517a..7e94b9bf081 100644 --- a/core/src/main/java/io/seata/core/context/ThreadLocalContextCore.java +++ b/core/src/main/java/io/seata/core/context/ThreadLocalContextCore.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.context; import java.util.HashMap; diff --git a/core/src/main/java/io/seata/core/exception/AbstractExceptionHandler.java b/core/src/main/java/io/seata/core/exception/AbstractExceptionHandler.java index e2c4efeab40..abe610e4392 100644 --- a/core/src/main/java/io/seata/core/exception/AbstractExceptionHandler.java +++ b/core/src/main/java/io/seata/core/exception/AbstractExceptionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.exception; import io.seata.core.protocol.ResultCode; diff --git a/core/src/main/java/io/seata/core/exception/TransactionException.java b/core/src/main/java/io/seata/core/exception/TransactionException.java index 8bcea098879..d0940864deb 100644 --- a/core/src/main/java/io/seata/core/exception/TransactionException.java +++ b/core/src/main/java/io/seata/core/exception/TransactionException.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.exception; /** diff --git a/core/src/main/java/io/seata/core/exception/TransactionExceptionCode.java b/core/src/main/java/io/seata/core/exception/TransactionExceptionCode.java index c91b04285e2..2dc1f710430 100644 --- a/core/src/main/java/io/seata/core/exception/TransactionExceptionCode.java +++ b/core/src/main/java/io/seata/core/exception/TransactionExceptionCode.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.exception; import java.util.HashMap; @@ -115,7 +114,15 @@ public enum TransactionExceptionCode { */ // FailedToAddBranch, + /** + * Failed to lock global transaction exception code. + */ + FailedLockGlobalTranscation, + /** + * FailedWriteSession + */ + FailedWriteSession, ; private static final Map MAP = new HashMap<>(values().length); diff --git a/core/src/main/java/io/seata/core/model/BranchStatus.java b/core/src/main/java/io/seata/core/model/BranchStatus.java index 836ccfbb376..65be5e68317 100644 --- a/core/src/main/java/io/seata/core/model/BranchStatus.java +++ b/core/src/main/java/io/seata/core/model/BranchStatus.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.model; import java.util.HashMap; diff --git a/core/src/main/java/io/seata/core/model/BranchType.java b/core/src/main/java/io/seata/core/model/BranchType.java index d07d275c997..267ee241145 100644 --- a/core/src/main/java/io/seata/core/model/BranchType.java +++ b/core/src/main/java/io/seata/core/model/BranchType.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.model; /** diff --git a/core/src/main/java/io/seata/core/model/GlobalStatus.java b/core/src/main/java/io/seata/core/model/GlobalStatus.java index 63554f5a50e..d8e813d17b5 100644 --- a/core/src/main/java/io/seata/core/model/GlobalStatus.java +++ b/core/src/main/java/io/seata/core/model/GlobalStatus.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.model; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; /** * Status of global transaction. @@ -128,6 +129,7 @@ public enum GlobalStatus { this.code = code; } + /** * Gets code. * @@ -137,6 +139,8 @@ public int getCode() { return code; } + + private static final Map MAP = new HashMap<>(values().length); static { diff --git a/core/src/main/java/io/seata/core/model/Resource.java b/core/src/main/java/io/seata/core/model/Resource.java index 2de8b277dea..5b6c94d84a7 100644 --- a/core/src/main/java/io/seata/core/model/Resource.java +++ b/core/src/main/java/io/seata/core/model/Resource.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.model; /** diff --git a/core/src/main/java/io/seata/core/model/ResourceManager.java b/core/src/main/java/io/seata/core/model/ResourceManager.java index 03242debdbf..21fd5ea2710 100644 --- a/core/src/main/java/io/seata/core/model/ResourceManager.java +++ b/core/src/main/java/io/seata/core/model/ResourceManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.model; import java.util.Map; diff --git a/core/src/main/java/io/seata/core/model/ResourceManagerInbound.java b/core/src/main/java/io/seata/core/model/ResourceManagerInbound.java index 24d93c29c93..e841b39f0c4 100644 --- a/core/src/main/java/io/seata/core/model/ResourceManagerInbound.java +++ b/core/src/main/java/io/seata/core/model/ResourceManagerInbound.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.model; import io.seata.core.exception.TransactionException; diff --git a/core/src/main/java/io/seata/core/model/ResourceManagerOutbound.java b/core/src/main/java/io/seata/core/model/ResourceManagerOutbound.java index 85952672a09..5e25206b85e 100644 --- a/core/src/main/java/io/seata/core/model/ResourceManagerOutbound.java +++ b/core/src/main/java/io/seata/core/model/ResourceManagerOutbound.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.model; import io.seata.core.exception.TransactionException; diff --git a/core/src/main/java/io/seata/core/model/TransactionManager.java b/core/src/main/java/io/seata/core/model/TransactionManager.java index e31b9fc39b2..0770d6bba32 100644 --- a/core/src/main/java/io/seata/core/model/TransactionManager.java +++ b/core/src/main/java/io/seata/core/model/TransactionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.model; import io.seata.core.exception.TransactionException; diff --git a/core/src/main/java/io/seata/core/protocol/AbstractIdentifyRequest.java b/core/src/main/java/io/seata/core/protocol/AbstractIdentifyRequest.java index 07569f79348..688cada84e2 100644 --- a/core/src/main/java/io/seata/core/protocol/AbstractIdentifyRequest.java +++ b/core/src/main/java/io/seata/core/protocol/AbstractIdentifyRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/AbstractIdentifyResponse.java b/core/src/main/java/io/seata/core/protocol/AbstractIdentifyResponse.java index e914087fba8..75ec8ac00ef 100644 --- a/core/src/main/java/io/seata/core/protocol/AbstractIdentifyResponse.java +++ b/core/src/main/java/io/seata/core/protocol/AbstractIdentifyResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import io.netty.buffer.ByteBuf; @@ -26,7 +25,6 @@ public abstract class AbstractIdentifyResponse extends AbstractResultMessage { private String version = Version.CURRENT; - ; private String extraData; @@ -129,19 +127,19 @@ public boolean decode(ByteBuf in) { public String toString() { StringBuilder result = new StringBuilder(); result.append("version="); - result.append(String.valueOf(version)); + result.append(version); result.append(","); result.append("extraData="); - result.append(String.valueOf(extraData)); + result.append(extraData); result.append(","); result.append("identified="); - result.append(String.valueOf(identified)); + result.append(identified); result.append(","); result.append("resultCode="); - result.append(String.valueOf(getResultCode())); + result.append(getResultCode()); result.append(","); result.append("msg="); - result.append(String.valueOf(getMsg())); + result.append(getMsg()); return result.toString(); } diff --git a/core/src/main/java/io/seata/core/protocol/AbstractMessage.java b/core/src/main/java/io/seata/core/protocol/AbstractMessage.java index 1c7a2f2f7fc..e6f3dd07e09 100644 --- a/core/src/main/java/io/seata/core/protocol/AbstractMessage.java +++ b/core/src/main/java/io/seata/core/protocol/AbstractMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import java.io.Serializable; @@ -40,24 +39,6 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; -import io.seata.core.protocol.transaction.BranchCommitRequest; -import io.seata.core.protocol.transaction.BranchCommitResponse; -import io.seata.core.protocol.transaction.BranchRegisterRequest; -import io.seata.core.protocol.transaction.BranchRegisterResponse; -import io.seata.core.protocol.transaction.BranchReportRequest; -import io.seata.core.protocol.transaction.BranchReportResponse; -import io.seata.core.protocol.transaction.BranchRollbackRequest; -import io.seata.core.protocol.transaction.BranchRollbackResponse; -import io.seata.core.protocol.transaction.GlobalBeginRequest; -import io.seata.core.protocol.transaction.GlobalBeginResponse; -import io.seata.core.protocol.transaction.GlobalCommitRequest; -import io.seata.core.protocol.transaction.GlobalCommitResponse; -import io.seata.core.protocol.transaction.GlobalLockQueryRequest; -import io.seata.core.protocol.transaction.GlobalLockQueryResponse; -import io.seata.core.protocol.transaction.GlobalRollbackRequest; -import io.seata.core.protocol.transaction.GlobalRollbackResponse; -import io.seata.core.protocol.transaction.GlobalStatusRequest; -import io.seata.core.protocol.transaction.GlobalStatusResponse; /** * The type Abstract message. diff --git a/core/src/main/java/io/seata/core/protocol/AbstractResultMessage.java b/core/src/main/java/io/seata/core/protocol/AbstractResultMessage.java index 6b9ca01318c..df1e2bb1e63 100644 --- a/core/src/main/java/io/seata/core/protocol/AbstractResultMessage.java +++ b/core/src/main/java/io/seata/core/protocol/AbstractResultMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/HeartbeatMessage.java b/core/src/main/java/io/seata/core/protocol/HeartbeatMessage.java index 72a0db9d60c..e25e34b1485 100644 --- a/core/src/main/java/io/seata/core/protocol/HeartbeatMessage.java +++ b/core/src/main/java/io/seata/core/protocol/HeartbeatMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import java.io.Serializable; diff --git a/core/src/main/java/io/seata/core/protocol/IncompatibleVersionException.java b/core/src/main/java/io/seata/core/protocol/IncompatibleVersionException.java index bc44509045f..3fb55396dcd 100644 --- a/core/src/main/java/io/seata/core/protocol/IncompatibleVersionException.java +++ b/core/src/main/java/io/seata/core/protocol/IncompatibleVersionException.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; /** diff --git a/core/src/main/java/io/seata/core/protocol/MergeMessage.java b/core/src/main/java/io/seata/core/protocol/MergeMessage.java index b543fe5b3a6..7be16a69dfe 100644 --- a/core/src/main/java/io/seata/core/protocol/MergeMessage.java +++ b/core/src/main/java/io/seata/core/protocol/MergeMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; /** diff --git a/core/src/main/java/io/seata/core/protocol/MergeResultMessage.java b/core/src/main/java/io/seata/core/protocol/MergeResultMessage.java index 96cc2dd610c..6f8a7232707 100644 --- a/core/src/main/java/io/seata/core/protocol/MergeResultMessage.java +++ b/core/src/main/java/io/seata/core/protocol/MergeResultMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import java.nio.ByteBuffer; @@ -117,6 +116,9 @@ public void decode(ByteBuffer byteBuffer) { @Override public String toString() { StringBuilder sb = new StringBuilder("MergeResultMessage "); + if (msgs == null) { + return sb.toString(); + } for (AbstractMessage msg : msgs) { sb.append(msg.toString()).append("\n"); } return sb.toString(); } diff --git a/core/src/main/java/io/seata/core/protocol/MergedMessage.java b/core/src/main/java/io/seata/core/protocol/MergedMessage.java index 24ff58563d2..c8273ad5848 100644 --- a/core/src/main/java/io/seata/core/protocol/MergedMessage.java +++ b/core/src/main/java/io/seata/core/protocol/MergedMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/MergedWarpMessage.java b/core/src/main/java/io/seata/core/protocol/MergedWarpMessage.java index 8119b87bc80..27e946b35ad 100644 --- a/core/src/main/java/io/seata/core/protocol/MergedWarpMessage.java +++ b/core/src/main/java/io/seata/core/protocol/MergedWarpMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import java.io.Serializable; diff --git a/core/src/main/java/io/seata/core/protocol/MessageCodec.java b/core/src/main/java/io/seata/core/protocol/MessageCodec.java index 87a0c3e89de..8a77602fc3a 100644 --- a/core/src/main/java/io/seata/core/protocol/MessageCodec.java +++ b/core/src/main/java/io/seata/core/protocol/MessageCodec.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import io.netty.buffer.ByteBuf; diff --git a/core/src/main/java/io/seata/core/protocol/MessageFuture.java b/core/src/main/java/io/seata/core/protocol/MessageFuture.java index f6521f7b191..bf97a88a7cf 100644 --- a/core/src/main/java/io/seata/core/protocol/MessageFuture.java +++ b/core/src/main/java/io/seata/core/protocol/MessageFuture.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; -import java.util.concurrent.CountDownLatch; +import io.seata.common.exception.ShouldNeverHappenException; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -30,9 +32,8 @@ public class MessageFuture { private RpcMessage requestMessage; private long timeout; private long start = System.currentTimeMillis(); - private volatile Object resultMessage; private static final Object NULL = new Object(); - private final CountDownLatch latch = new CountDownLatch(1); + private transient CompletableFuture origin = new CompletableFuture(); /** * Is timeout boolean. @@ -54,18 +55,22 @@ public boolean isTimeout() { */ public Object get(long timeout, TimeUnit unit) throws TimeoutException, InterruptedException { - boolean success = latch.await(timeout, unit); - if (!success) { + Object result = null; + try { + result = origin.get(timeout, unit); + } catch (ExecutionException e) { + throw new ShouldNeverHappenException("Should not get results in a multi-threaded environment", e); + } catch (TimeoutException e) { throw new TimeoutException("cost " + (System.currentTimeMillis() - start) + " ms"); } - if (resultMessage instanceof RuntimeException) { - throw (RuntimeException)resultMessage; - } else if (resultMessage instanceof Throwable) { - throw new RuntimeException((Throwable)resultMessage); + if (result instanceof RuntimeException) { + throw (RuntimeException)result; + } else if (result instanceof Throwable) { + throw new RuntimeException((Throwable)result); } - return resultMessage; + return result; } /** @@ -74,8 +79,7 @@ public Object get(long timeout, TimeUnit unit) throws TimeoutException, * @param obj the obj */ public void setResultMessage(Object obj) { - this.resultMessage = (obj == null ? NULL : obj); - latch.countDown(); + origin.complete(obj); } /** diff --git a/core/src/main/java/io/seata/core/protocol/RegisterRMRequest.java b/core/src/main/java/io/seata/core/protocol/RegisterRMRequest.java index 50556f0dda8..f1914bd8a17 100644 --- a/core/src/main/java/io/seata/core/protocol/RegisterRMRequest.java +++ b/core/src/main/java/io/seata/core/protocol/RegisterRMRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import java.io.Serializable; @@ -93,6 +92,7 @@ public boolean decode(ByteBuf in) { } short len = in.readShort(); + i -= 2; if (len > 0) { if (i < len) { return false; @@ -105,6 +105,7 @@ public boolean decode(ByteBuf in) { } len = in.readShort(); + i -= 2; if (len > 0) { if (i < len) { return false; @@ -117,6 +118,7 @@ public boolean decode(ByteBuf in) { } len = in.readShort(); + i -= 2; if (len > 0) { if (i < len) { return false; @@ -129,6 +131,7 @@ public boolean decode(ByteBuf in) { } len = in.readShort(); + i -= 2; if (len > 0) { if (i < len) { return false; @@ -141,6 +144,7 @@ public boolean decode(ByteBuf in) { } int iLen = in.readInt(); + i -= 4; if (iLen > 0) { if (i < iLen) { return false; diff --git a/core/src/main/java/io/seata/core/protocol/RegisterRMResponse.java b/core/src/main/java/io/seata/core/protocol/RegisterRMResponse.java index caaa22a62ff..7082e7543e6 100644 --- a/core/src/main/java/io/seata/core/protocol/RegisterRMResponse.java +++ b/core/src/main/java/io/seata/core/protocol/RegisterRMResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import java.io.Serializable; diff --git a/core/src/main/java/io/seata/core/protocol/RegisterTMRequest.java b/core/src/main/java/io/seata/core/protocol/RegisterTMRequest.java index 860ca07835c..11676425330 100644 --- a/core/src/main/java/io/seata/core/protocol/RegisterTMRequest.java +++ b/core/src/main/java/io/seata/core/protocol/RegisterTMRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import java.io.Serializable; diff --git a/core/src/main/java/io/seata/core/protocol/RegisterTMResponse.java b/core/src/main/java/io/seata/core/protocol/RegisterTMResponse.java index 7c6182b91ae..50c32edc002 100644 --- a/core/src/main/java/io/seata/core/protocol/RegisterTMResponse.java +++ b/core/src/main/java/io/seata/core/protocol/RegisterTMResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import java.io.Serializable; diff --git a/core/src/main/java/io/seata/core/protocol/ResultCode.java b/core/src/main/java/io/seata/core/protocol/ResultCode.java index bed89a4554c..215632f3179 100644 --- a/core/src/main/java/io/seata/core/protocol/ResultCode.java +++ b/core/src/main/java/io/seata/core/protocol/ResultCode.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; /** diff --git a/core/src/main/java/io/seata/core/protocol/RpcMessage.java b/core/src/main/java/io/seata/core/protocol/RpcMessage.java index 6fdd2833335..b4dc0aa9a50 100644 --- a/core/src/main/java/io/seata/core/protocol/RpcMessage.java +++ b/core/src/main/java/io/seata/core/protocol/RpcMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import java.util.concurrent.atomic.AtomicLong; diff --git a/core/src/main/java/io/seata/core/protocol/Version.java b/core/src/main/java/io/seata/core/protocol/Version.java index f8ab837dd48..b6239d739c7 100644 --- a/core/src/main/java/io/seata/core/protocol/Version.java +++ b/core/src/main/java/io/seata/core/protocol/Version.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import io.seata.common.util.NetUtil; - import io.netty.channel.Channel; +import io.seata.common.util.NetUtil; /** * The type Version. @@ -33,7 +31,7 @@ public class Version { /** * The constant CURRENT. */ - public static final String CURRENT = "0.5.0"; + public static final String CURRENT = "0.5.1"; /** * The constant VERSION_MAP. diff --git a/core/src/main/java/io/seata/core/protocol/transaction/AbstractBranchEndRequest.java b/core/src/main/java/io/seata/core/protocol/transaction/AbstractBranchEndRequest.java index a48e9c9973f..4bd5963acdf 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/AbstractBranchEndRequest.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/AbstractBranchEndRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,14 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.nio.ByteBuffer; -import io.seata.core.model.BranchType; - import io.netty.buffer.ByteBuf; +import io.seata.core.model.BranchType; /** * The type Abstract branch end request. @@ -202,6 +200,7 @@ public boolean decode(ByteBuf in) { int leftLen = in.readableBytes(); int read = 0; int xidLen = in.readShort(); + leftLen -= 2; if (xidLen > 0) { if (leftLen < xidLen) { return false; @@ -217,6 +216,7 @@ public boolean decode(ByteBuf in) { leftLen--; int resourceIdLen = in.readShort(); + leftLen -= 2; if (resourceIdLen > 0) { if (leftLen < resourceIdLen) { return false; @@ -228,6 +228,7 @@ public boolean decode(ByteBuf in) { } int applicationDataLen = in.readInt(); + leftLen -= 4; if (applicationDataLen > 0) { if (leftLen < applicationDataLen) { return false; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/AbstractBranchEndResponse.java b/core/src/main/java/io/seata/core/protocol/transaction/AbstractBranchEndResponse.java index 2bb5c0d0dc6..74524041486 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/AbstractBranchEndResponse.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/AbstractBranchEndResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/AbstractGlobalEndRequest.java b/core/src/main/java/io/seata/core/protocol/transaction/AbstractGlobalEndRequest.java index 2e50271f306..b77a111e501 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/AbstractGlobalEndRequest.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/AbstractGlobalEndRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/AbstractGlobalEndResponse.java b/core/src/main/java/io/seata/core/protocol/transaction/AbstractGlobalEndResponse.java index 89082e35e8c..f3e0825b1e4 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/AbstractGlobalEndResponse.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/AbstractGlobalEndResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionRequest.java b/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionRequest.java index a85d1823c1d..3452467bfa0 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionRequest.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionRequestToRM.java b/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionRequestToRM.java index aa1d070ee50..b22b3b28d00 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionRequestToRM.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionRequestToRM.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionRequestToTC.java b/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionRequestToTC.java index 8e7576f922a..b24abfa0ac9 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionRequestToTC.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionRequestToTC.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionResponse.java b/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionResponse.java index b6c5623e185..46aa783a202 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionResponse.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/AbstractTransactionResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/BranchCommitRequest.java b/core/src/main/java/io/seata/core/protocol/transaction/BranchCommitRequest.java index 4ded27fef0b..dae191733da 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/BranchCommitRequest.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/BranchCommitRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import io.seata.core.protocol.AbstractMessage; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/BranchCommitResponse.java b/core/src/main/java/io/seata/core/protocol/transaction/BranchCommitResponse.java index 5302724dbff..a4e4be291bd 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/BranchCommitResponse.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/BranchCommitResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import io.seata.core.protocol.AbstractMessage; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/BranchRegisterRequest.java b/core/src/main/java/io/seata/core/protocol/transaction/BranchRegisterRequest.java index 487f5ab6276..5be09408dfc 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/BranchRegisterRequest.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/BranchRegisterRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/BranchRegisterResponse.java b/core/src/main/java/io/seata/core/protocol/transaction/BranchRegisterResponse.java index 459d17bfa9c..e5f2734c92f 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/BranchRegisterResponse.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/BranchRegisterResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.io.Serializable; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/BranchReportRequest.java b/core/src/main/java/io/seata/core/protocol/transaction/BranchReportRequest.java index bba0fafac88..b21f6350b05 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/BranchReportRequest.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/BranchReportRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/BranchReportResponse.java b/core/src/main/java/io/seata/core/protocol/transaction/BranchReportResponse.java index a7a9c902eeb..d2a744d0205 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/BranchReportResponse.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/BranchReportResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; /** diff --git a/core/src/main/java/io/seata/core/protocol/transaction/BranchRollbackRequest.java b/core/src/main/java/io/seata/core/protocol/transaction/BranchRollbackRequest.java index 1488774d663..c18722b2745 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/BranchRollbackRequest.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/BranchRollbackRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import io.seata.core.rpc.RpcContext; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/BranchRollbackResponse.java b/core/src/main/java/io/seata/core/protocol/transaction/BranchRollbackResponse.java index b163124c95a..c9289a0a0d2 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/BranchRollbackResponse.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/BranchRollbackResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import io.seata.core.protocol.AbstractMessage; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/GlobalBeginRequest.java b/core/src/main/java/io/seata/core/protocol/transaction/GlobalBeginRequest.java index 4b50d446fc8..ca8a4eb879d 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/GlobalBeginRequest.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/GlobalBeginRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/GlobalBeginResponse.java b/core/src/main/java/io/seata/core/protocol/transaction/GlobalBeginResponse.java index 777e21ee6ce..f92823c334e 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/GlobalBeginResponse.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/GlobalBeginResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/GlobalCommitRequest.java b/core/src/main/java/io/seata/core/protocol/transaction/GlobalCommitRequest.java index ff33145a4fe..aacca8ef163 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/GlobalCommitRequest.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/GlobalCommitRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import io.seata.core.rpc.RpcContext; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/GlobalCommitResponse.java b/core/src/main/java/io/seata/core/protocol/transaction/GlobalCommitResponse.java index 8b395b5f1ba..e18084863f7 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/GlobalCommitResponse.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/GlobalCommitResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; /** diff --git a/core/src/main/java/io/seata/core/protocol/transaction/GlobalLockQueryRequest.java b/core/src/main/java/io/seata/core/protocol/transaction/GlobalLockQueryRequest.java index e5057be00b5..42fc69bc42b 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/GlobalLockQueryRequest.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/GlobalLockQueryRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import io.seata.core.protocol.MergedMessage; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/GlobalLockQueryResponse.java b/core/src/main/java/io/seata/core/protocol/transaction/GlobalLockQueryResponse.java index 6c66be99bb7..ff8a4e9d827 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/GlobalLockQueryResponse.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/GlobalLockQueryResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/GlobalRollbackRequest.java b/core/src/main/java/io/seata/core/protocol/transaction/GlobalRollbackRequest.java index 95fca47a16b..757a615c080 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/GlobalRollbackRequest.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/GlobalRollbackRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import io.seata.core.rpc.RpcContext; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/GlobalRollbackResponse.java b/core/src/main/java/io/seata/core/protocol/transaction/GlobalRollbackResponse.java index 8b46ef437d6..7ab13fe3d4e 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/GlobalRollbackResponse.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/GlobalRollbackResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; /** diff --git a/core/src/main/java/io/seata/core/protocol/transaction/GlobalStatusRequest.java b/core/src/main/java/io/seata/core/protocol/transaction/GlobalStatusRequest.java index 2be21ea3ef1..4b67fd8b936 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/GlobalStatusRequest.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/GlobalStatusRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import io.seata.core.rpc.RpcContext; diff --git a/core/src/main/java/io/seata/core/protocol/transaction/GlobalStatusResponse.java b/core/src/main/java/io/seata/core/protocol/transaction/GlobalStatusResponse.java index 8d3d3bd9b48..a8e730a87cf 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/GlobalStatusResponse.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/GlobalStatusResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; /** diff --git a/core/src/main/java/io/seata/core/protocol/transaction/RMInboundHandler.java b/core/src/main/java/io/seata/core/protocol/transaction/RMInboundHandler.java index 0b04cd6f857..99a568f8378 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/RMInboundHandler.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/RMInboundHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; /** diff --git a/core/src/main/java/io/seata/core/protocol/transaction/TCInboundHandler.java b/core/src/main/java/io/seata/core/protocol/transaction/TCInboundHandler.java index aab89a5d85d..5b1b2ecfe09 100644 --- a/core/src/main/java/io/seata/core/protocol/transaction/TCInboundHandler.java +++ b/core/src/main/java/io/seata/core/protocol/transaction/TCInboundHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol.transaction; import io.seata.core.rpc.RpcContext; diff --git a/core/src/main/java/io/seata/core/rpc/ChannelManager.java b/core/src/main/java/io/seata/core/rpc/ChannelManager.java index 7faa0c14096..d63086ea251 100644 --- a/core/src/main/java/io/seata/core/rpc/ChannelManager.java +++ b/core/src/main/java/io/seata/core/rpc/ChannelManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc; import java.net.SocketAddress; diff --git a/core/src/main/java/io/seata/core/rpc/ClientMessageListener.java b/core/src/main/java/io/seata/core/rpc/ClientMessageListener.java index 29aa2a76997..0a34a71ee3c 100644 --- a/core/src/main/java/io/seata/core/rpc/ClientMessageListener.java +++ b/core/src/main/java/io/seata/core/rpc/ClientMessageListener.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc; /** diff --git a/core/src/main/java/io/seata/core/rpc/ClientMessageSender.java b/core/src/main/java/io/seata/core/rpc/ClientMessageSender.java index 864425f6a3c..8cfbf488b61 100644 --- a/core/src/main/java/io/seata/core/rpc/ClientMessageSender.java +++ b/core/src/main/java/io/seata/core/rpc/ClientMessageSender.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc; import java.util.concurrent.TimeoutException; diff --git a/core/src/main/java/io/seata/core/rpc/ClientType.java b/core/src/main/java/io/seata/core/rpc/ClientType.java index b6967c943a7..bee506c7d21 100644 --- a/core/src/main/java/io/seata/core/rpc/ClientType.java +++ b/core/src/main/java/io/seata/core/rpc/ClientType.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc; /** diff --git a/core/src/main/java/io/seata/core/rpc/DefaultServerMessageListenerImpl.java b/core/src/main/java/io/seata/core/rpc/DefaultServerMessageListenerImpl.java index 41ee6fb2b0e..aca924d21a7 100644 --- a/core/src/main/java/io/seata/core/rpc/DefaultServerMessageListenerImpl.java +++ b/core/src/main/java/io/seata/core/rpc/DefaultServerMessageListenerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc; import java.util.concurrent.BlockingQueue; diff --git a/core/src/main/java/io/seata/core/rpc/Disposable.java b/core/src/main/java/io/seata/core/rpc/Disposable.java index 6c29ea25b38..30272c36582 100644 --- a/core/src/main/java/io/seata/core/rpc/Disposable.java +++ b/core/src/main/java/io/seata/core/rpc/Disposable.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/main/java/io/seata/core/rpc/RemotingServer.java b/core/src/main/java/io/seata/core/rpc/RemotingServer.java index 633cffb0870..8e72417dd95 100644 --- a/core/src/main/java/io/seata/core/rpc/RemotingServer.java +++ b/core/src/main/java/io/seata/core/rpc/RemotingServer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc; /** diff --git a/core/src/main/java/io/seata/core/rpc/RemotingService.java b/core/src/main/java/io/seata/core/rpc/RemotingService.java index 95fc6395f2b..f8cfb972c8e 100644 --- a/core/src/main/java/io/seata/core/rpc/RemotingService.java +++ b/core/src/main/java/io/seata/core/rpc/RemotingService.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc; /** diff --git a/core/src/main/java/io/seata/core/rpc/RpcContext.java b/core/src/main/java/io/seata/core/rpc/RpcContext.java index f1dafa3cdd5..b605b72d067 100644 --- a/core/src/main/java/io/seata/core/rpc/RpcContext.java +++ b/core/src/main/java/io/seata/core/rpc/RpcContext.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc; import java.net.SocketAddress; diff --git a/core/src/main/java/io/seata/core/rpc/ServerMessageListener.java b/core/src/main/java/io/seata/core/rpc/ServerMessageListener.java index edd1ca377ce..a6994df462e 100644 --- a/core/src/main/java/io/seata/core/rpc/ServerMessageListener.java +++ b/core/src/main/java/io/seata/core/rpc/ServerMessageListener.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc; import io.seata.core.protocol.RegisterRMRequest; diff --git a/core/src/main/java/io/seata/core/rpc/ServerMessageSender.java b/core/src/main/java/io/seata/core/rpc/ServerMessageSender.java index 837af2b81f5..217499cc15f 100644 --- a/core/src/main/java/io/seata/core/rpc/ServerMessageSender.java +++ b/core/src/main/java/io/seata/core/rpc/ServerMessageSender.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc; import java.io.IOException; diff --git a/core/src/main/java/io/seata/core/rpc/TransactionMessageHandler.java b/core/src/main/java/io/seata/core/rpc/TransactionMessageHandler.java index b9efd36fdce..d7877f86bb2 100644 --- a/core/src/main/java/io/seata/core/rpc/TransactionMessageHandler.java +++ b/core/src/main/java/io/seata/core/rpc/TransactionMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc; import io.seata.core.protocol.AbstractMessage; diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractRpcRemoting.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractRpcRemoting.java index 6e9295862d2..44c33d31fdf 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractRpcRemoting.java +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractRpcRemoting.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import java.io.IOException; @@ -123,9 +122,6 @@ public AbstractRpcRemoting(ThreadPoolExecutor messageExecutor) { * Init. */ public void init() { - //register shutdownHook - ShutdownHook.getInstance().addDisposable(this); - timerExecutor.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -364,12 +360,12 @@ public void run() { try { dispatch(rpcMessage.getId(), ctx, rpcMessage.getBody()); } catch (Throwable th) { - LOGGER.error(FrameworkErrorCode.NetDispatch.errCode, th.getMessage(), th); + LOGGER.error(FrameworkErrorCode.NetDispatch.getErrCode(), th.getMessage(), th); } } }); } catch (RejectedExecutionException e) { - LOGGER.error(FrameworkErrorCode.ThreadPoolFull.errCode, + LOGGER.error(FrameworkErrorCode.ThreadPoolFull.getErrCode(), "thread pool is full, current max pool size is " + messageExecutor.getActiveCount()); if (allowDumpStack) { String name = ManagementFactory.getRuntimeMXBean().getName(); @@ -400,12 +396,12 @@ public void run() { try { dispatch(rpcMessage.getId(), ctx, rpcMessage.getBody()); } catch (Throwable th) { - LOGGER.error(FrameworkErrorCode.NetDispatch.errCode, th.getMessage(), th); + LOGGER.error(FrameworkErrorCode.NetDispatch.getErrCode(), th.getMessage(), th); } } }); } catch (RejectedExecutionException e) { - LOGGER.error(FrameworkErrorCode.ThreadPoolFull.errCode, + LOGGER.error(FrameworkErrorCode.ThreadPoolFull.getErrCode(), "thread pool is full, current max pool size is " + messageExecutor.getActiveCount()); } } @@ -415,7 +411,7 @@ public void run() { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - LOGGER.error(FrameworkErrorCode.ExceptionCaught.errCode, + LOGGER.error(FrameworkErrorCode.ExceptionCaught.getErrCode(), ctx.channel() + " connect exception. " + cause.getMessage(), cause); try { diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractRpcRemotingClient.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractRpcRemotingClient.java index 051c06437d6..342c0d5015f 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractRpcRemotingClient.java +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractRpcRemotingClient.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import java.net.InetSocketAddress; @@ -349,7 +348,7 @@ protected void reconnect(String transactionServiceGroup) { try { connect(serverAddress); } catch (Exception e) { - LOGGER.error(FrameworkErrorCode.NetConnect.errCode, + LOGGER.error(FrameworkErrorCode.NetConnect.getErrCode(), "can not connect to " + serverAddress + " cause:" + e.getMessage(), e); } } diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractRpcRemotingServer.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractRpcRemotingServer.java index f5b46509dbd..707d039bc72 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractRpcRemotingServer.java +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractRpcRemotingServer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import java.net.InetSocketAddress; diff --git a/core/src/main/java/io/seata/core/rpc/netty/ChannelAuthHealthChecker.java b/core/src/main/java/io/seata/core/rpc/netty/ChannelAuthHealthChecker.java index 40f5e6d56fe..c635ff3dfcb 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/ChannelAuthHealthChecker.java +++ b/core/src/main/java/io/seata/core/rpc/netty/ChannelAuthHealthChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import io.netty.channel.Channel; diff --git a/core/src/main/java/io/seata/core/rpc/netty/ChannelEventListener.java b/core/src/main/java/io/seata/core/rpc/netty/ChannelEventListener.java index 7d6a74ebe0f..077ebb8a094 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/ChannelEventListener.java +++ b/core/src/main/java/io/seata/core/rpc/netty/ChannelEventListener.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import io.netty.channel.Channel; diff --git a/core/src/main/java/io/seata/core/rpc/netty/DefaultChannelPoolHandler.java b/core/src/main/java/io/seata/core/rpc/netty/DefaultChannelPoolHandler.java index 94edc1de7e8..5753e004d9c 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/DefaultChannelPoolHandler.java +++ b/core/src/main/java/io/seata/core/rpc/netty/DefaultChannelPoolHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import io.netty.channel.Channel; diff --git a/core/src/main/java/io/seata/core/rpc/netty/MessageCodecHandler.java b/core/src/main/java/io/seata/core/rpc/netty/MessageCodecHandler.java index 115295590c2..32a56449e0e 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/MessageCodecHandler.java +++ b/core/src/main/java/io/seata/core/rpc/netty/MessageCodecHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import java.nio.ByteBuffer; diff --git a/core/src/main/java/io/seata/core/rpc/netty/NettyBaseConfig.java b/core/src/main/java/io/seata/core/rpc/netty/NettyBaseConfig.java index 8ea3025baff..580b678492a 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/NettyBaseConfig.java +++ b/core/src/main/java/io/seata/core/rpc/netty/NettyBaseConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,13 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; -import io.seata.common.exception.ShouldNeverHappenException; -import io.seata.config.Configuration; -import io.seata.config.ConfigurationFactory; - import io.netty.channel.Channel; import io.netty.channel.ServerChannel; import io.netty.channel.epoll.EpollDomainSocketChannel; @@ -34,6 +29,8 @@ import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.util.NettyRuntime; import io.netty.util.internal.PlatformDependent; +import io.seata.config.Configuration; +import io.seata.config.ConfigurationFactory; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -111,7 +108,7 @@ public class NettyBaseConfig { protected static final int MAX_ALL_IDLE_SECONDS = 0; static { - TRANSPORT_PROTOCOL_TYPE = TransportProtocolType.valueOf(CONFIG.getConfig("transport.type")); + TRANSPORT_PROTOCOL_TYPE = TransportProtocolType.valueOf(CONFIG.getConfig("transport.type",TransportProtocolType.TCP.name())); String workerThreadSize = CONFIG.getConfig("transport.thread-factory.worker-thread-size"); if (StringUtils.isNotBlank(workerThreadSize) && StringUtils.isNumeric(workerThreadSize)) { WORKER_THREAD_SIZE = Integer.parseInt(workerThreadSize); @@ -120,7 +117,7 @@ public class NettyBaseConfig { } else { WORKER_THREAD_SIZE = WorkThreadMode.Default.getValue(); } - TRANSPORT_SERVER_TYPE = TransportServerType.valueOf(CONFIG.getConfig("transport.server")); + TRANSPORT_SERVER_TYPE = TransportServerType.valueOf(CONFIG.getConfig("transport.server",TransportServerType.NIO.name())); switch (TRANSPORT_SERVER_TYPE) { case NIO: if (TRANSPORT_PROTOCOL_TYPE == TransportProtocolType.TCP) { @@ -233,7 +230,7 @@ public static WorkThreadMode getModeByName(String name) { } else if (Default.name().equalsIgnoreCase(name)) { return Default; } else { - throw new ShouldNeverHappenException("incorrect workThreadMode."); + return null; } } diff --git a/core/src/main/java/io/seata/core/rpc/netty/NettyClientConfig.java b/core/src/main/java/io/seata/core/rpc/netty/NettyClientConfig.java index 5bdbd4e8d40..2ae97ced878 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/NettyClientConfig.java +++ b/core/src/main/java/io/seata/core/rpc/netty/NettyClientConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import io.seata.core.rpc.netty.NettyPoolKey.TransactionRole; diff --git a/core/src/main/java/io/seata/core/rpc/netty/NettyPoolKey.java b/core/src/main/java/io/seata/core/rpc/netty/NettyPoolKey.java index fc21c57a022..91ac738dfa0 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/NettyPoolKey.java +++ b/core/src/main/java/io/seata/core/rpc/netty/NettyPoolKey.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import io.seata.core.protocol.AbstractMessage; diff --git a/core/src/main/java/io/seata/core/rpc/netty/NettyPoolableFactory.java b/core/src/main/java/io/seata/core/rpc/netty/NettyPoolableFactory.java index 632c48cf212..db29b780465 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/NettyPoolableFactory.java +++ b/core/src/main/java/io/seata/core/rpc/netty/NettyPoolableFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import java.net.InetSocketAddress; @@ -94,16 +93,12 @@ private boolean isResponseSuccess(Object response, NettyPoolKey.TransactionRole if (!(response instanceof RegisterTMResponse)) { return false; } - if (((RegisterTMResponse)response).isIdentified()) { - return true; - } + return ((RegisterTMResponse) response).isIdentified(); } else if (transactionRole.equals(NettyPoolKey.TransactionRole.RMROLE)) { if (!(response instanceof RegisterRMResponse)) { return false; } - if (((RegisterRMResponse)response).isIdentified()) { - return true; - } + return ((RegisterRMResponse) response).isIdentified(); } return false; } diff --git a/core/src/main/java/io/seata/core/rpc/netty/NettyServerConfig.java b/core/src/main/java/io/seata/core/rpc/netty/NettyServerConfig.java index d4cd514d7e1..37cdf06ae45 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/NettyServerConfig.java +++ b/core/src/main/java/io/seata/core/rpc/netty/NettyServerConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import io.netty.buffer.PooledByteBufAllocator; diff --git a/core/src/main/java/io/seata/core/rpc/netty/RegisterCheckAuthHandler.java b/core/src/main/java/io/seata/core/rpc/netty/RegisterCheckAuthHandler.java index dcf5af40d41..d078a4df0da 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/RegisterCheckAuthHandler.java +++ b/core/src/main/java/io/seata/core/rpc/netty/RegisterCheckAuthHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import io.seata.core.protocol.RegisterRMRequest; diff --git a/core/src/main/java/io/seata/core/rpc/netty/RegisterMsgListener.java b/core/src/main/java/io/seata/core/rpc/netty/RegisterMsgListener.java index 197e5a0800a..42a9eedbac5 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/RegisterMsgListener.java +++ b/core/src/main/java/io/seata/core/rpc/netty/RegisterMsgListener.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import io.seata.core.protocol.AbstractMessage; diff --git a/core/src/main/java/io/seata/core/rpc/netty/RmMessageListener.java b/core/src/main/java/io/seata/core/rpc/netty/RmMessageListener.java index d6b309e10b6..e6f92688d05 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/RmMessageListener.java +++ b/core/src/main/java/io/seata/core/rpc/netty/RmMessageListener.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import io.seata.common.exception.FrameworkErrorCode; @@ -95,7 +94,10 @@ private void handleBranchCommit(long msgId, String serverAddress, resultMessage = (BranchCommitResponse)handler.onRequest(branchCommitRequest, null); sender.sendResponse(msgId, serverAddress, resultMessage); } catch (Exception e) { - LOGGER.error(FrameworkErrorCode.NetOnMessage.errCode, e.getMessage(), e); + LOGGER.error(FrameworkErrorCode.NetOnMessage.getErrCode(), e.getMessage(), e); + if(resultMessage == null){ + resultMessage = new BranchCommitResponse(); + } resultMessage.setResultCode(ResultCode.Failed); resultMessage.setMsg(e.getMessage()); sender.sendResponse(msgId, serverAddress, resultMessage); diff --git a/core/src/main/java/io/seata/core/rpc/netty/RmRpcClient.java b/core/src/main/java/io/seata/core/rpc/netty/RmRpcClient.java index 31a72d4b2e7..c2e4928a2ef 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/RmRpcClient.java +++ b/core/src/main/java/io/seata/core/rpc/netty/RmRpcClient.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import java.util.Map; @@ -222,7 +221,8 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { LOGGER.info("RmRpcClient channel" + ctx.channel() + " idle."); } try { - nettyClientKeyPool.invalidateObject(poolKeyMap.get(ctx.channel().remoteAddress()), ctx.channel()); + String serverAddress = NetUtil.toStringAddress(ctx.channel().remoteAddress()); + nettyClientKeyPool.invalidateObject(poolKeyMap.get(serverAddress), ctx.channel()); } catch (Exception exx) { LOGGER.error(exx.getMessage()); } finally { @@ -313,7 +313,7 @@ private Channel doConnect(String serverAddress) { } channelFromPool = nettyClientKeyPool.borrowObject(poolKeyMap.get(serverAddress)); } catch (Exception exx) { - LOGGER.error(FrameworkErrorCode.RegistRM.errCode, "register RM failed.", exx); + LOGGER.error(FrameworkErrorCode.RegistRM.getErrCode(), "register RM failed.", exx); throw new FrameworkException("can not register RM,err:" + exx.getMessage()); } return channelFromPool; @@ -346,7 +346,7 @@ private Channel getExistAliveChannel(Channel rmChannel, String serverAddress) { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - LOGGER.error(FrameworkErrorCode.ExceptionCaught.errCode, + LOGGER.error(FrameworkErrorCode.ExceptionCaught.getErrCode(), NetUtil.toStringAddress(ctx.channel().remoteAddress()) + "connect exception. " + cause.getMessage(), cause); releaseChannel(ctx.channel(), getAddressFromChannel(ctx.channel())); diff --git a/core/src/main/java/io/seata/core/rpc/netty/RpcClientHandler.java b/core/src/main/java/io/seata/core/rpc/netty/RpcClientHandler.java index 4457cb0c37e..d09514f72b8 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/RpcClientHandler.java +++ b/core/src/main/java/io/seata/core/rpc/netty/RpcClientHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import io.netty.channel.Channel; diff --git a/core/src/main/java/io/seata/core/rpc/netty/RpcEventLoopGroup.java b/core/src/main/java/io/seata/core/rpc/netty/RpcEventLoopGroup.java index 4658ae7a06e..8b1ddaaee6b 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/RpcEventLoopGroup.java +++ b/core/src/main/java/io/seata/core/rpc/netty/RpcEventLoopGroup.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import java.util.concurrent.ThreadFactory; diff --git a/core/src/main/java/io/seata/core/rpc/netty/RpcServer.java b/core/src/main/java/io/seata/core/rpc/netty/RpcServer.java index 62b6103d155..6f8de79c546 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/RpcServer.java +++ b/core/src/main/java/io/seata/core/rpc/netty/RpcServer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import java.util.concurrent.ThreadPoolExecutor; diff --git a/core/src/main/java/io/seata/core/rpc/netty/RpcServerHandler.java b/core/src/main/java/io/seata/core/rpc/netty/RpcServerHandler.java index 73890f29f2b..2070285297b 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/RpcServerHandler.java +++ b/core/src/main/java/io/seata/core/rpc/netty/RpcServerHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import io.netty.channel.ChannelHandler.Sharable; diff --git a/core/src/main/java/io/seata/core/rpc/netty/ShutdownHook.java b/core/src/main/java/io/seata/core/rpc/netty/ShutdownHook.java index b9e10d1a0df..6a860159772 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/ShutdownHook.java +++ b/core/src/main/java/io/seata/core/rpc/netty/ShutdownHook.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import io.seata.common.util.CollectionUtils; diff --git a/core/src/main/java/io/seata/core/rpc/netty/TmRpcClient.java b/core/src/main/java/io/seata/core/rpc/netty/TmRpcClient.java index 4139872d0bb..662e7178700 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/TmRpcClient.java +++ b/core/src/main/java/io/seata/core/rpc/netty/TmRpcClient.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import java.util.concurrent.ConcurrentHashMap; @@ -194,7 +193,8 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { LOGGER.info("channel" + ctx.channel() + " read idle."); } try { - nettyClientKeyPool.invalidateObject(poolKeyMap.get(ctx.channel().remoteAddress()), ctx.channel()); + String serverAddress = NetUtil.toStringAddress(ctx.channel().remoteAddress()); + nettyClientKeyPool.invalidateObject(poolKeyMap.get(serverAddress), ctx.channel()); } catch (Exception exx) { LOGGER.error(exx.getMessage()); } finally { @@ -370,7 +370,7 @@ public void sendResponse(long msgId, String serverAddress, Object msg) { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - LOGGER.error(FrameworkErrorCode.ExceptionCaught.errCode, + LOGGER.error(FrameworkErrorCode.ExceptionCaught.getErrCode(), NetUtil.toStringAddress(ctx.channel().remoteAddress()) + "connect exception. " + cause.getMessage(), cause); releaseChannel(ctx.channel(), getAddressFromChannel(ctx.channel())); if (LOGGER.isInfoEnabled()) { diff --git a/core/src/main/java/io/seata/core/rpc/netty/TransportProtocolType.java b/core/src/main/java/io/seata/core/rpc/netty/TransportProtocolType.java index e6c5d415b50..817002a0409 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/TransportProtocolType.java +++ b/core/src/main/java/io/seata/core/rpc/netty/TransportProtocolType.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; /** diff --git a/core/src/main/java/io/seata/core/rpc/netty/TransportServerType.java b/core/src/main/java/io/seata/core/rpc/netty/TransportServerType.java index dc0ae98e538..c8e9fe5aa99 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/TransportServerType.java +++ b/core/src/main/java/io/seata/core/rpc/netty/TransportServerType.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; /** diff --git a/core/src/main/java/io/seata/core/store/StoreMode.java b/core/src/main/java/io/seata/core/store/StoreMode.java index 0c36bea504f..f6553ab3a98 100644 --- a/core/src/main/java/io/seata/core/store/StoreMode.java +++ b/core/src/main/java/io/seata/core/store/StoreMode.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/main/log4j.properties b/core/src/main/log4j.properties index 39f8a02c4f6..05ba0e365a1 100644 --- a/core/src/main/log4j.properties +++ b/core/src/main/log4j.properties @@ -1,5 +1,5 @@ # -# Copyright 1999-2018 Alibaba Group Holding Ltd. +# Copyright 1999-2019 Seata.io Group. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/core/src/main/resources/META-INF/services/io.seata.core.context.ContextCore b/core/src/main/resources/META-INF/services/io.seata.core.context.ContextCore index 861fa75ed90..04e8ed55dd8 100644 --- a/core/src/main/resources/META-INF/services/io.seata.core.context.ContextCore +++ b/core/src/main/resources/META-INF/services/io.seata.core.context.ContextCore @@ -1,35 +1 @@ -# -# Copyright 1999-2018 Alibaba Group Holding Ltd. -# -# 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. -# - -# -# -# Copyright 1999-2018 Alibaba Group Holding Ltd. -# -# 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. -# -# - io.seata.core.context.ThreadLocalContextCore \ No newline at end of file diff --git a/core/src/test/java/io/seata/core/context/ContextCoreTest.java b/core/src/test/java/io/seata/core/context/ContextCoreTest.java index afd1e1a47f1..724d02dd2e9 100644 --- a/core/src/test/java/io/seata/core/context/ContextCoreTest.java +++ b/core/src/test/java/io/seata/core/context/ContextCoreTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/test/java/io/seata/core/context/RootContextTest.java b/core/src/test/java/io/seata/core/context/RootContextTest.java index 110e47808f0..aebe5eb96cf 100644 --- a/core/src/test/java/io/seata/core/context/RootContextTest.java +++ b/core/src/test/java/io/seata/core/context/RootContextTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/test/java/io/seata/core/message/BranchCommitRequestTest.java b/core/src/test/java/io/seata/core/message/BranchCommitRequestTest.java index a87dcaaeeb3..6c8e48c6627 100644 --- a/core/src/test/java/io/seata/core/message/BranchCommitRequestTest.java +++ b/core/src/test/java/io/seata/core/message/BranchCommitRequestTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/test/java/io/seata/core/message/BranchCommitResponseTest.java b/core/src/test/java/io/seata/core/message/BranchCommitResponseTest.java index c00ce8ecf02..2fb414ad85d 100644 --- a/core/src/test/java/io/seata/core/message/BranchCommitResponseTest.java +++ b/core/src/test/java/io/seata/core/message/BranchCommitResponseTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/test/java/io/seata/core/message/BranchRegisterRequestTest.java b/core/src/test/java/io/seata/core/message/BranchRegisterRequestTest.java index df372000b64..0b06c0be6d5 100644 --- a/core/src/test/java/io/seata/core/message/BranchRegisterRequestTest.java +++ b/core/src/test/java/io/seata/core/message/BranchRegisterRequestTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.message; import java.nio.ByteBuffer; diff --git a/core/src/test/java/io/seata/core/message/BranchRegisterResponseTest.java b/core/src/test/java/io/seata/core/message/BranchRegisterResponseTest.java index ec8396672ce..ee9a8083594 100644 --- a/core/src/test/java/io/seata/core/message/BranchRegisterResponseTest.java +++ b/core/src/test/java/io/seata/core/message/BranchRegisterResponseTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/test/java/io/seata/core/message/BranchReportRequestTest.java b/core/src/test/java/io/seata/core/message/BranchReportRequestTest.java index 695e71aea1e..6061b55a989 100644 --- a/core/src/test/java/io/seata/core/message/BranchReportRequestTest.java +++ b/core/src/test/java/io/seata/core/message/BranchReportRequestTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/test/java/io/seata/core/message/CodecTest.java b/core/src/test/java/io/seata/core/message/CodecTest.java index f275c2a8b2b..929d2601a28 100644 --- a/core/src/test/java/io/seata/core/message/CodecTest.java +++ b/core/src/test/java/io/seata/core/message/CodecTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.message; import java.nio.ByteBuffer; diff --git a/core/src/test/java/io/seata/core/message/GlobalBeginRequestTest.java b/core/src/test/java/io/seata/core/message/GlobalBeginRequestTest.java index f4eccf5c126..3d879a7f4c1 100644 --- a/core/src/test/java/io/seata/core/message/GlobalBeginRequestTest.java +++ b/core/src/test/java/io/seata/core/message/GlobalBeginRequestTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/test/java/io/seata/core/message/GlobalCommitResponseTest.java b/core/src/test/java/io/seata/core/message/GlobalCommitResponseTest.java index 7c6bbda33fb..fa81c21756b 100644 --- a/core/src/test/java/io/seata/core/message/GlobalCommitResponseTest.java +++ b/core/src/test/java/io/seata/core/message/GlobalCommitResponseTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/test/java/io/seata/core/message/GlobalRollbackRequestTest.java b/core/src/test/java/io/seata/core/message/GlobalRollbackRequestTest.java index 816a36adef7..c2e6da1bab5 100644 --- a/core/src/test/java/io/seata/core/message/GlobalRollbackRequestTest.java +++ b/core/src/test/java/io/seata/core/message/GlobalRollbackRequestTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/test/java/io/seata/core/message/RegisterTMResponseTest.java b/core/src/test/java/io/seata/core/message/RegisterTMResponseTest.java index 49204414814..39c6c50fd34 100644 --- a/core/src/test/java/io/seata/core/message/RegisterTMResponseTest.java +++ b/core/src/test/java/io/seata/core/message/RegisterTMResponseTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/test/java/io/seata/core/model/BranchStatusTest.java b/core/src/test/java/io/seata/core/model/BranchStatusTest.java index 9f757597462..9840d94f320 100644 --- a/core/src/test/java/io/seata/core/model/BranchStatusTest.java +++ b/core/src/test/java/io/seata/core/model/BranchStatusTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.model; import io.seata.common.exception.ShouldNeverHappenException; diff --git a/core/src/test/java/io/seata/core/model/BranchTypeTest.java b/core/src/test/java/io/seata/core/model/BranchTypeTest.java index f511cd8851c..f2dfa744d05 100644 --- a/core/src/test/java/io/seata/core/model/BranchTypeTest.java +++ b/core/src/test/java/io/seata/core/model/BranchTypeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.model; import org.junit.Assert; diff --git a/core/src/test/java/io/seata/core/model/GlobalStatusTest.java b/core/src/test/java/io/seata/core/model/GlobalStatusTest.java index 87804c31b96..ec8e103b87f 100644 --- a/core/src/test/java/io/seata/core/model/GlobalStatusTest.java +++ b/core/src/test/java/io/seata/core/model/GlobalStatusTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.model; import org.junit.Assert; diff --git a/core/src/test/java/io/seata/core/protocol/MergeResultMessageTest.java b/core/src/test/java/io/seata/core/protocol/MergeResultMessageTest.java index 08024fa6e13..33782fa80b0 100644 --- a/core/src/test/java/io/seata/core/protocol/MergeResultMessageTest.java +++ b/core/src/test/java/io/seata/core/protocol/MergeResultMessageTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import io.netty.buffer.ByteBuf; diff --git a/core/src/test/java/io/seata/core/protocol/MergedWarpMessageTest.java b/core/src/test/java/io/seata/core/protocol/MergedWarpMessageTest.java index ec51d86407a..5a5f3d03124 100644 --- a/core/src/test/java/io/seata/core/protocol/MergedWarpMessageTest.java +++ b/core/src/test/java/io/seata/core/protocol/MergedWarpMessageTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import io.netty.buffer.ByteBuf; diff --git a/core/src/test/java/io/seata/core/protocol/MessageFutureTest.java b/core/src/test/java/io/seata/core/protocol/MessageFutureTest.java index 6402664febe..80b228f3878 100644 --- a/core/src/test/java/io/seata/core/protocol/MessageFutureTest.java +++ b/core/src/test/java/io/seata/core/protocol/MessageFutureTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/test/java/io/seata/core/protocol/RegisterRMRequestTest.java b/core/src/test/java/io/seata/core/protocol/RegisterRMRequestTest.java index 809711b2e0e..d0eb6dee0d5 100644 --- a/core/src/test/java/io/seata/core/protocol/RegisterRMRequestTest.java +++ b/core/src/test/java/io/seata/core/protocol/RegisterRMRequestTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.protocol; import io.netty.buffer.ByteBuf; diff --git a/core/src/test/java/io/seata/core/protocol/RpcMessageTest.java b/core/src/test/java/io/seata/core/protocol/RpcMessageTest.java index 691c05fef09..7c8081effc8 100644 --- a/core/src/test/java/io/seata/core/protocol/RpcMessageTest.java +++ b/core/src/test/java/io/seata/core/protocol/RpcMessageTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/test/java/io/seata/core/protocol/transaction/BranchRollbackRequestTest.java b/core/src/test/java/io/seata/core/protocol/transaction/BranchRollbackRequestTest.java index c96170ec00e..b46fcec16d7 100644 --- a/core/src/test/java/io/seata/core/protocol/transaction/BranchRollbackRequestTest.java +++ b/core/src/test/java/io/seata/core/protocol/transaction/BranchRollbackRequestTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * 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.seata.core.protocol.transaction; diff --git a/core/src/test/java/io/seata/core/protocol/transaction/BranchRollbackResponseTest.java b/core/src/test/java/io/seata/core/protocol/transaction/BranchRollbackResponseTest.java index 6f172a73683..410b20a5d27 100644 --- a/core/src/test/java/io/seata/core/protocol/transaction/BranchRollbackResponseTest.java +++ b/core/src/test/java/io/seata/core/protocol/transaction/BranchRollbackResponseTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * 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.seata.core.protocol.transaction; diff --git a/core/src/test/java/io/seata/core/protocol/transaction/GlobalBeginResponseTest.java b/core/src/test/java/io/seata/core/protocol/transaction/GlobalBeginResponseTest.java index d4de3a6902d..36a26a6df21 100644 --- a/core/src/test/java/io/seata/core/protocol/transaction/GlobalBeginResponseTest.java +++ b/core/src/test/java/io/seata/core/protocol/transaction/GlobalBeginResponseTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/test/java/io/seata/core/rpc/netty/NettyBaseConfigTest.java b/core/src/test/java/io/seata/core/rpc/netty/NettyBaseConfigTest.java index 27486e52fc1..758715293c2 100644 --- a/core/src/test/java/io/seata/core/rpc/netty/NettyBaseConfigTest.java +++ b/core/src/test/java/io/seata/core/rpc/netty/NettyBaseConfigTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import org.junit.Test; diff --git a/core/src/test/java/io/seata/core/rpc/netty/NettyPoolKeyTest.java b/core/src/test/java/io/seata/core/rpc/netty/NettyPoolKeyTest.java index de4b4a1235f..570fbfb5432 100644 --- a/core/src/test/java/io/seata/core/rpc/netty/NettyPoolKeyTest.java +++ b/core/src/test/java/io/seata/core/rpc/netty/NettyPoolKeyTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.core.rpc.netty; import io.seata.core.protocol.RegisterRMRequest; diff --git a/core/src/test/java/io/seata/core/rpc/netty/TmRpcClientTest.java b/core/src/test/java/io/seata/core/rpc/netty/TmRpcClientTest.java index 8a5f7b30a96..2fdb4721c6e 100644 --- a/core/src/test/java/io/seata/core/rpc/netty/TmRpcClientTest.java +++ b/core/src/test/java/io/seata/core/rpc/netty/TmRpcClientTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import java.lang.reflect.Field; diff --git a/discovery/pom.xml b/discovery/pom.xml index 8ab8a9df2de..af586b5ec50 100644 --- a/discovery/pom.xml +++ b/discovery/pom.xml @@ -35,6 +35,8 @@ seata-discovery-zk seata-discovery-redis seata-discovery-nacos + seata-discovery-etcd3 + seata-discovery-sofa diff --git a/discovery/seata-discovery-all/pom.xml b/discovery/seata-discovery-all/pom.xml index 0f12dab5574..598649d8273 100644 --- a/discovery/seata-discovery-all/pom.xml +++ b/discovery/seata-discovery-all/pom.xml @@ -46,5 +46,13 @@ ${project.groupId} seata-discovery-nacos + + ${project.groupId} + seata-discovery-etcd3 + + + ${project.groupId} + seata-discovery-sofa + diff --git a/discovery/seata-discovery-consul/src/main/java/io/seata/discovery/registry/consul/ConsulListener.java b/discovery/seata-discovery-consul/src/main/java/io/seata/discovery/registry/consul/ConsulListener.java index 76e07f84a49..dcc3370fcb8 100644 --- a/discovery/seata-discovery-consul/src/main/java/io/seata/discovery/registry/consul/ConsulListener.java +++ b/discovery/seata-discovery-consul/src/main/java/io/seata/discovery/registry/consul/ConsulListener.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/discovery/seata-discovery-consul/src/main/java/io/seata/discovery/registry/consul/ConsulRegistryProvider.java b/discovery/seata-discovery-consul/src/main/java/io/seata/discovery/registry/consul/ConsulRegistryProvider.java index 7414ba7f0d9..77f8f262068 100644 --- a/discovery/seata-discovery-consul/src/main/java/io/seata/discovery/registry/consul/ConsulRegistryProvider.java +++ b/discovery/seata-discovery-consul/src/main/java/io/seata/discovery/registry/consul/ConsulRegistryProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/discovery/seata-discovery-consul/src/main/java/io/seata/discovery/registry/consul/ConsulRegistryServiceImpl.java b/discovery/seata-discovery-consul/src/main/java/io/seata/discovery/registry/consul/ConsulRegistryServiceImpl.java index af696fc0151..b0fc0847b65 100644 --- a/discovery/seata-discovery-consul/src/main/java/io/seata/discovery/registry/consul/ConsulRegistryServiceImpl.java +++ b/discovery/seata-discovery-consul/src/main/java/io/seata/discovery/registry/consul/ConsulRegistryServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.registry.consul; import io.seata.common.thread.NamedThreadFactory; diff --git a/discovery/seata-discovery-consul/src/test/java/io/seata/discovery/registry/consul/ConsulRegistryServiceImplTest.java b/discovery/seata-discovery-consul/src/test/java/io/seata/discovery/registry/consul/ConsulRegistryServiceImplTest.java index 09fa1c6278f..f1e09145263 100644 --- a/discovery/seata-discovery-consul/src/test/java/io/seata/discovery/registry/consul/ConsulRegistryServiceImplTest.java +++ b/discovery/seata-discovery-consul/src/test/java/io/seata/discovery/registry/consul/ConsulRegistryServiceImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.registry.consul; import io.seata.discovery.registry.RegistryService; diff --git a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/AbstractLoadBalance.java b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/AbstractLoadBalance.java index 86b7a310c03..e0ce85ae801 100644 --- a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/AbstractLoadBalance.java +++ b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/AbstractLoadBalance.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.loadbalance; import java.util.List; diff --git a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/LoadBalance.java b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/LoadBalance.java index e92369bcaf5..5a6932a4dd5 100644 --- a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/LoadBalance.java +++ b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/LoadBalance.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.loadbalance; import java.util.List; diff --git a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/LoadBalanceFactory.java b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/LoadBalanceFactory.java index 2c2d6fb2cfa..a275843cf81 100644 --- a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/LoadBalanceFactory.java +++ b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/LoadBalanceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.loadbalance; import io.seata.common.loader.EnhancedServiceLoader; diff --git a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/RandomLoadBalance.java b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/RandomLoadBalance.java index 3feef0a3d7e..a8d530b1d46 100644 --- a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/RandomLoadBalance.java +++ b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/RandomLoadBalance.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.loadbalance; import java.util.List; diff --git a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/RoundRobinLoadBalance.java b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/RoundRobinLoadBalance.java index bcab9c90532..2ceaea10d36 100644 --- a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/RoundRobinLoadBalance.java +++ b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/loadbalance/RoundRobinLoadBalance.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.loadbalance; import java.util.List; diff --git a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/FileRegistryServiceImpl.java b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/FileRegistryServiceImpl.java index cb08d6c5beb..48bff75f999 100644 --- a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/FileRegistryServiceImpl.java +++ b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/FileRegistryServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.registry; diff --git a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryFactory.java b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryFactory.java index a866f10eeea..114914af27f 100644 --- a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryFactory.java +++ b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.registry; import io.seata.common.exception.NotSupportYetException; diff --git a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryProvider.java b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryProvider.java index 6333367a74b..105b6d0e41e 100644 --- a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryProvider.java +++ b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryService.java b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryService.java index 147cb91c390..f59974c1bb9 100644 --- a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryService.java +++ b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryService.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.registry; import java.net.InetSocketAddress; diff --git a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryType.java b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryType.java index 5b408e40067..e83510c4ed6 100644 --- a/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryType.java +++ b/discovery/seata-discovery-core/src/main/java/io/seata/discovery/registry/RegistryType.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.registry; import io.seata.common.exception.NotSupportYetException; @@ -48,7 +47,15 @@ public enum RegistryType { /** * Consul registry type */ - Consul; + Consul, + /** + * Etcd3 registry type + */ + Etcd3, + /** + * Sofa registry type + */ + Sofa; /** * Gets type. @@ -69,6 +76,10 @@ public static RegistryType getType(String name) { return ZK; } else if (Consul.name().equalsIgnoreCase(name)) { return Consul; + } else if (Etcd3.name().equalsIgnoreCase(name)) { + return Etcd3; + } else if (Sofa.name().equalsIgnoreCase(name)) { + return Sofa; } else { throw new NotSupportYetException("unsupported type:" + name); } diff --git a/discovery/seata-discovery-core/src/test/java/io/seata/discovery/loadbalance/LoadBalanceFactoryTest.java b/discovery/seata-discovery-core/src/test/java/io/seata/discovery/loadbalance/LoadBalanceFactoryTest.java index 424bdd8ca09..e73d91406cb 100644 --- a/discovery/seata-discovery-core/src/test/java/io/seata/discovery/loadbalance/LoadBalanceFactoryTest.java +++ b/discovery/seata-discovery-core/src/test/java/io/seata/discovery/loadbalance/LoadBalanceFactoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.loadbalance; import java.net.InetSocketAddress; diff --git a/discovery/seata-discovery-core/src/test/java/io/seata/discovery/loadbalance/LoadBalanceTest.java b/discovery/seata-discovery-core/src/test/java/io/seata/discovery/loadbalance/LoadBalanceTest.java index 7959820b283..b4b6ebd0dba 100644 --- a/discovery/seata-discovery-core/src/test/java/io/seata/discovery/loadbalance/LoadBalanceTest.java +++ b/discovery/seata-discovery-core/src/test/java/io/seata/discovery/loadbalance/LoadBalanceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.loadbalance; import java.net.InetSocketAddress; diff --git a/discovery/seata-discovery-core/src/test/java/resources/apollo.properties b/discovery/seata-discovery-core/src/test/java/resources/apollo.properties index fc8fc882dd9..51c0cb8718d 100644 --- a/discovery/seata-discovery-core/src/test/java/resources/apollo.properties +++ b/discovery/seata-discovery-core/src/test/java/resources/apollo.properties @@ -1,3 +1,19 @@ +# +# Copyright 1999-2019 Seata.io Group. +# +# 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. +# + #apollo config registry.redis.serverAddr = 192.168.1.204:6379 registry.redis.db = 6 diff --git a/discovery/seata-discovery-etcd3/pom.xml b/discovery/seata-discovery-etcd3/pom.xml new file mode 100644 index 00000000000..014c5258480 --- /dev/null +++ b/discovery/seata-discovery-etcd3/pom.xml @@ -0,0 +1,60 @@ + + + + + io.seata + seata-discovery + ${revision} + + 4.0.0 + seata-discovery-etcd3 + seata-discovery-etcd3 ${project.version} + + + + io.seata + seata-discovery-core + ${project.parent.version} + + + io.etcd + jetcd-core + + + com.google.guava + guava + + + + + com.google.guava + guava + + + + io.etcd + jetcd-launcher + test + + + org.testcontainers + testcontainers + test + + + diff --git a/discovery/seata-discovery-etcd3/src/main/java/io/seata/discovery/registery/etcd/EtcdRegistryProvider.java b/discovery/seata-discovery-etcd3/src/main/java/io/seata/discovery/registery/etcd/EtcdRegistryProvider.java new file mode 100644 index 00000000000..9f0a3957184 --- /dev/null +++ b/discovery/seata-discovery-etcd3/src/main/java/io/seata/discovery/registery/etcd/EtcdRegistryProvider.java @@ -0,0 +1,32 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.discovery.registery.etcd; + +import io.seata.common.loader.LoadLevel; +import io.seata.discovery.registry.RegistryProvider; +import io.seata.discovery.registry.RegistryService; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/04/18 + */ +@LoadLevel(name = "Etcd3", order = 1) +public class EtcdRegistryProvider implements RegistryProvider { + @Override + public RegistryService provide() { + return EtcdRegistryServiceImpl.getInstance(); + } +} diff --git a/discovery/seata-discovery-etcd3/src/main/java/io/seata/discovery/registery/etcd/EtcdRegistryServiceImpl.java b/discovery/seata-discovery-etcd3/src/main/java/io/seata/discovery/registery/etcd/EtcdRegistryServiceImpl.java new file mode 100644 index 00000000000..0afaec08f50 --- /dev/null +++ b/discovery/seata-discovery-etcd3/src/main/java/io/seata/discovery/registery/etcd/EtcdRegistryServiceImpl.java @@ -0,0 +1,412 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.discovery.registery.etcd; + + +import io.etcd.jetcd.ByteSequence; +import io.etcd.jetcd.Client; +import io.etcd.jetcd.Lease; +import io.etcd.jetcd.Watch; +import io.etcd.jetcd.kv.GetResponse; +import io.etcd.jetcd.lease.LeaseTimeToLiveResponse; +import io.etcd.jetcd.options.GetOption; +import io.etcd.jetcd.options.LeaseOption; +import io.etcd.jetcd.options.PutOption; +import io.etcd.jetcd.options.WatchOption; +import io.etcd.jetcd.watch.WatchResponse; +import io.seata.common.exception.ShouldNeverHappenException; +import io.seata.common.thread.NamedThreadFactory; +import io.seata.common.util.NetUtil; +import io.seata.common.util.StringUtils; +import io.seata.config.Configuration; +import io.seata.config.ConfigurationFactory; +import io.seata.discovery.registry.RegistryService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.InetSocketAddress; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +import static io.netty.util.CharsetUtil.UTF_8; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/04/18 + */ +public class EtcdRegistryServiceImpl implements RegistryService { + private static final Logger LOGGER = LoggerFactory.getLogger(EtcdRegistryServiceImpl.class); + private static final Configuration FILE_CONFIG = ConfigurationFactory.FILE_INSTANCE; + private static final String FILE_ROOT_REGISTRY = "registry"; + private static final String FILE_CONFIG_SPLIT_CHAR = "."; + private static final String REGISTRY_TYPE = "etcd3"; + private static final String SERVER_ADDR_KEY = "serverAddr"; + private static final String REGISTRY_CLUSTER = "cluster"; + private static final String DEFAULT_CLUSTER_NAME = "default"; + private static final String REGISTRY_KEY_PREFIX = "registry-seata-"; + private static final String FILE_CONFIG_KEY_PREFIX = FILE_ROOT_REGISTRY + FILE_CONFIG_SPLIT_CHAR + REGISTRY_TYPE + FILE_CONFIG_SPLIT_CHAR; + private static final int MAP_INITIAL_CAPACITY = 8; + private static final int THREAD_POOL_SIZE = 2; + private final static ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(THREAD_POOL_SIZE, THREAD_POOL_SIZE, + Integer.MAX_VALUE, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("registry-etcd3", THREAD_POOL_SIZE)); + /** + * TTL for lease + */ + private static final long TTL = 10; + /** + * interval for life keep + */ + private final static long LIFE_KEEP_INTERVAL = 5; + /** + * critical value for life keep + */ + private final static long LIFE_KEEP_CRITICAL = 6; + private static volatile EtcdRegistryServiceImpl instance; + private static volatile Client client; + private static ConcurrentMap> clusterAddressMap = null; + private static ConcurrentMap> listenerMap = null; + private static ConcurrentMap watcherMap = null; + private static long leaseId = 0; + private EtcdLifeKeeper lifeKeeper = null; + private Future lifeKeeperFuture = null; + /** + * a endpoint for unit testing + */ + public static final String TEST_ENDPONT = "etcd-test-lancher-endpoint"; + + + private EtcdRegistryServiceImpl() { + } + + /** + * get etcd registry service instance + * + * @return instance + */ + static EtcdRegistryServiceImpl getInstance() { + if (null == instance) { + synchronized (EtcdRegistryServiceImpl.class) { + if (null == instance) { + clusterAddressMap = new ConcurrentHashMap<>(MAP_INITIAL_CAPACITY); + listenerMap = new ConcurrentHashMap<>(MAP_INITIAL_CAPACITY); + watcherMap = new ConcurrentHashMap<>(MAP_INITIAL_CAPACITY); + instance = new EtcdRegistryServiceImpl(); + } + } + } + return instance; + } + + + @Override + public void register(InetSocketAddress address) throws Exception { + NetUtil.validAddress(address); + doRegister(address); + } + + /** + * do registry + * + * @param address + */ + private void doRegister(InetSocketAddress address) throws Exception { + PutOption putOption = PutOption.newBuilder().withLeaseId(getLeaseId()).build(); + getClient().getKVClient().put(buildRegestryKey(address), buildRegistryValue(address), putOption).get(); + } + + + @Override + public void unregister(InetSocketAddress address) throws Exception { + NetUtil.validAddress(address); + doUnregister(address); + } + + /** + * do unregister + * + * @param address + * @throws Exception + */ + private void doUnregister(InetSocketAddress address) throws Exception { + getClient().getKVClient().delete(buildRegestryKey(address)).get(); + } + + @Override + public void subscribe(String cluster, Watch.Listener listener) throws Exception { + listenerMap.putIfAbsent(cluster, new HashSet<>()); + listenerMap.get(cluster).add(listener); + EtcdWatcher watcher = watcherMap.computeIfAbsent(cluster, w -> new EtcdWatcher(listener)); + EXECUTOR_SERVICE.submit(watcher); + } + + @Override + public void unsubscribe(String cluster, Watch.Listener listener) throws Exception { + Set subscribeSet = listenerMap.get(cluster); + if (null != subscribeSet) { + Set newSubscribeSet = new HashSet<>(); + for (Watch.Listener eventListener : subscribeSet) { + if (!eventListener.equals(listener)) { + newSubscribeSet.add(eventListener); + } + } + listenerMap.put(cluster, newSubscribeSet); + } + watcherMap.remove(cluster).stop(); + + + } + + @Override + public List lookup(String key) throws Exception { + final String cluster = getServiceGroup(key); + if (null == cluster) { + return null; + } + if (!listenerMap.containsKey(cluster)) { + //1.refresh + refreshCluster(cluster); + //2.subscribe + subscribe(cluster, new Watch.Listener() { + @Override + public void onNext(WatchResponse response) { + try { + refreshCluster(cluster); + } catch (Exception e) { + LOGGER.error("etcd watch listener", e); + throw new RuntimeException(e.getMessage()); + } + } + + @Override + public void onError(Throwable throwable) { + + } + + @Override + public void onCompleted() { + + } + }); + + } + return clusterAddressMap.get(cluster); + } + + @Override + public void close() throws Exception { + if (null != lifeKeeper) { + lifeKeeper.stop(); + if (null != lifeKeeperFuture) { + lifeKeeperFuture.get(3, TimeUnit.SECONDS); + } + } + + } + + /** + * refresh cluster + * + * @param cluster + * @throws Exception + */ + private void refreshCluster(String cluster) throws Exception { + if (null == cluster) { + return; + } + //1.get all available registries + GetOption getOption = GetOption.newBuilder().withPrefix(buildRegestryKeyPrefix()).build(); + GetResponse getResponse = getClient().getKVClient().get(buildRegestryKeyPrefix(), getOption).get(); + //2.add to list + List instanceList = getResponse.getKvs().stream().map(keyValue -> { + String[] instanceInfo = keyValue.getValue().toString(UTF_8).split(":"); + return new InetSocketAddress(instanceInfo[0], Integer.parseInt(instanceInfo[1])); + }).collect(Collectors.toList()); + clusterAddressMap.put(cluster, instanceList); + } + + /** + * get client + * + * @return client + */ + private Client getClient() { + if (null == client) { + synchronized (EtcdRegistryServiceImpl.class) { + if (null == client) { + String testEndpoint = System.getProperty(TEST_ENDPONT); + if (StringUtils.isNotBlank(testEndpoint)) { + client = Client.builder().endpoints(testEndpoint).build(); + } else { + client = Client.builder().endpoints(FILE_CONFIG.getConfig(FILE_CONFIG_KEY_PREFIX + SERVER_ADDR_KEY)).build(); + } + } + } + } + return client; + } + + /** + * get service group + * + * @param key + * @return clusterNameKey + */ + private String getServiceGroup(String key) { + String clusterNameKey = PREFIX_SERVICE_ROOT + CONFIG_SPLIT_CHAR + PREFIX_SERVICE_MAPPING + key; + return ConfigurationFactory.getInstance().getConfig(clusterNameKey); + } + + /** + * get cluster name + * + * @return + */ + private String getClusterName() { + String clusterConfigName = FILE_ROOT_REGISTRY + FILE_CONFIG_SPLIT_CHAR + REGISTRY_TYPE + FILE_CONFIG_SPLIT_CHAR + + REGISTRY_CLUSTER; + return FILE_CONFIG.getConfig(clusterConfigName, DEFAULT_CLUSTER_NAME); + } + + /** + * create a new lease id or return a existing lease id + */ + private long getLeaseId() throws Exception { + if (0 == leaseId) { + //create a new lease + leaseId = getClient().getLeaseClient().grant(TTL).get().getID(); + lifeKeeper = new EtcdLifeKeeper(leaseId); + lifeKeeperFuture = EXECUTOR_SERVICE.submit(lifeKeeper); + } + return leaseId; + } + + /** + * build registry key + * + * @return registry key + */ + private ByteSequence buildRegestryKey(InetSocketAddress address) { + return ByteSequence.from(REGISTRY_KEY_PREFIX + getClusterName() + "-" + NetUtil.toStringAddress(address), UTF_8); + } + + /** + * build registry key prefix + * + * @return registry key prefix + */ + private ByteSequence buildRegestryKeyPrefix() { + return ByteSequence.from(REGISTRY_KEY_PREFIX + getClusterName(), UTF_8); + } + + /** + * build registry value + * + * @param address + * @return registry value + */ + private ByteSequence buildRegistryValue(InetSocketAddress address) { + return ByteSequence.from(NetUtil.toStringAddress(address), UTF_8); + } + + /** + * the type etcd life keeper + */ + private class EtcdLifeKeeper implements Callable { + private final long leaseId; + private final Lease leaseClient; + private boolean running; + + + public EtcdLifeKeeper(long leaseId) { + this.leaseClient = getClient().getLeaseClient(); + this.leaseId = leaseId; + this.running = true; + + } + + /** + * process + */ + private void process() { + for (; ; ) { + try { + //1.get TTL + LeaseTimeToLiveResponse leaseTimeToLiveResponse = this.leaseClient.timeToLive(this.leaseId, LeaseOption.DEFAULT).get(); + final long tTl = leaseTimeToLiveResponse.getTTl(); + if (tTl <= LIFE_KEEP_CRITICAL) { + //2.refresh the TTL + this.leaseClient.keepAliveOnce(this.leaseId).get(); + } + TimeUnit.SECONDS.sleep(LIFE_KEEP_INTERVAL); + } catch (Exception e) { + LOGGER.error("EtcdLifeKeeper", e); + throw new ShouldNeverHappenException("failed to renewal the lease."); + } + } + } + + /** + * stop this task + */ + public void stop() { + this.running = false; + } + + @Override + public Boolean call() { + if (this.running) { + process(); + } + return this.running; + } + } + + /** + * the type etcd watcher + */ + private class EtcdWatcher implements Runnable { + private final Watch.Listener listener; + private Watch.Watcher watcher; + + public EtcdWatcher(Watch.Listener listener) { + this.listener = listener; + } + + @Override + public void run() { + Watch watchClient = getClient().getWatchClient(); + WatchOption watchOption = WatchOption.newBuilder().withPrefix(buildRegestryKeyPrefix()).build(); + this.watcher = watchClient.watch(buildRegestryKeyPrefix(), watchOption, this.listener); + } + + /** + * stop this task + */ + public void stop() { + this.watcher.close(); + } + } +} diff --git a/discovery/seata-discovery-etcd3/src/main/resources/META-INF/services/io.seata.discovery.registry.RegistryProvider b/discovery/seata-discovery-etcd3/src/main/resources/META-INF/services/io.seata.discovery.registry.RegistryProvider new file mode 100644 index 00000000000..7d9b88d77ec --- /dev/null +++ b/discovery/seata-discovery-etcd3/src/main/resources/META-INF/services/io.seata.discovery.registry.RegistryProvider @@ -0,0 +1 @@ +io.seata.discovery.registery.etcd.EtcdRegistryProvider \ No newline at end of file diff --git a/discovery/seata-discovery-etcd3/src/test/java/io/seata/discovery/registry/etcd/EtcdRegistryProviderTest.java b/discovery/seata-discovery-etcd3/src/test/java/io/seata/discovery/registry/etcd/EtcdRegistryProviderTest.java new file mode 100644 index 00000000000..da6813dc486 --- /dev/null +++ b/discovery/seata-discovery-etcd3/src/test/java/io/seata/discovery/registry/etcd/EtcdRegistryProviderTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.discovery.registry.etcd; + +import io.seata.discovery.registery.etcd.EtcdRegistryProvider; +import io.seata.discovery.registery.etcd.EtcdRegistryServiceImpl; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/04/26 + * the type etcd registry provider test + */ +public class EtcdRegistryProviderTest { + /** + * test provide + */ + @Test + public void testProvide() { + assertThat(new EtcdRegistryProvider().provide()).isInstanceOf(EtcdRegistryServiceImpl.class); + } +} diff --git a/discovery/seata-discovery-etcd3/src/test/java/io/seata/discovery/registry/etcd/EtcdRegistryServiceImplTest.java b/discovery/seata-discovery-etcd3/src/test/java/io/seata/discovery/registry/etcd/EtcdRegistryServiceImplTest.java new file mode 100644 index 00000000000..d126319febd --- /dev/null +++ b/discovery/seata-discovery-etcd3/src/test/java/io/seata/discovery/registry/etcd/EtcdRegistryServiceImplTest.java @@ -0,0 +1,200 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.discovery.registry.etcd; + +import io.etcd.jetcd.ByteSequence; +import io.etcd.jetcd.Client; +import io.etcd.jetcd.Watch; +import io.etcd.jetcd.launcher.junit.EtcdClusterResource; +import io.etcd.jetcd.options.DeleteOption; +import io.etcd.jetcd.options.GetOption; +import io.etcd.jetcd.watch.WatchResponse; +import io.seata.discovery.registery.etcd.EtcdRegistryProvider; +import io.seata.discovery.registery.etcd.EtcdRegistryServiceImpl; +import io.seata.discovery.registry.RegistryService; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; + +import java.net.InetSocketAddress; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static io.netty.util.CharsetUtil.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/04/26 + */ +public class EtcdRegistryServiceImplTest { + private static final String REGISTRY_KEY_PREFIX = "registry-seata-"; + private static final String CLUSTER_NAME = "default"; + @Rule + private final EtcdClusterResource etcd = new EtcdClusterResource(CLUSTER_NAME, 1); + + private final Client client = Client.builder().endpoints(etcd.cluster().getClientEndpoints()).build(); + private final static String HOST = "127.0.0.1"; + private final static int PORT = 8091; + + @BeforeClass + public void beforeClass() throws Exception { + System.setProperty(EtcdRegistryServiceImpl.TEST_ENDPONT, etcd.cluster().getClientEndpoints().get(0).toString()); + } + + @AfterClass + public void afterClass() throws Exception { + System.setProperty(EtcdRegistryServiceImpl.TEST_ENDPONT, ""); + } + + @Test + public void testRegister() throws Exception { + RegistryService registryService = new EtcdRegistryProvider().provide(); + InetSocketAddress inetSocketAddress = new InetSocketAddress(HOST, PORT); + //1.register + registryService.register(inetSocketAddress); + //2.get instance information + GetOption getOption = GetOption.newBuilder().withPrefix(buildRegistryKeyPrefix()).build(); + long count = client.getKVClient().get(buildRegistryKeyPrefix(), getOption).get().getKvs().stream().filter(keyValue -> { + String[] instanceInfo = keyValue.getValue().toString(UTF_8).split(":"); + return HOST.equals(instanceInfo[0]) && PORT == Integer.parseInt(instanceInfo[1]); + }).count(); + assertThat(count).isEqualTo(1); + } + + + @Test + public void testUnregister() throws Exception { + RegistryService registryService = new EtcdRegistryProvider().provide(); + InetSocketAddress inetSocketAddress = new InetSocketAddress(HOST, PORT); + //1.register + registryService.register(inetSocketAddress); + //2.get instance information + GetOption getOption = GetOption.newBuilder().withPrefix(buildRegistryKeyPrefix()).build(); + long count = client.getKVClient().get(buildRegistryKeyPrefix(), getOption).get().getKvs().stream().filter(keyValue -> { + String[] instanceInfo = keyValue.getValue().toString(UTF_8).split(":"); + return HOST.equals(instanceInfo[0]) && PORT == Integer.parseInt(instanceInfo[1]); + }).count(); + assertThat(count).isEqualTo(1); + //3.unregister + registryService.unregister(inetSocketAddress); + //4.again get instance information + getOption = GetOption.newBuilder().withPrefix(buildRegistryKeyPrefix()).build(); + count = client.getKVClient().get(buildRegistryKeyPrefix(), getOption).get().getKvs().stream().filter(keyValue -> { + String[] instanceInfo = keyValue.getValue().toString(UTF_8).split(":"); + return HOST.equals(instanceInfo[0]) && PORT == Integer.parseInt(instanceInfo[1]); + }).count(); + assertThat(count).isEqualTo(0); + + + } + + @Test + public void testSubscribe() throws Exception { + RegistryService registryService = new EtcdRegistryProvider().provide(); + InetSocketAddress inetSocketAddress = new InetSocketAddress(HOST, PORT); + //1.register + registryService.register(inetSocketAddress); + //2.subscribe + EtcdListener etcdListener = new EtcdListener(); + registryService.subscribe(CLUSTER_NAME, etcdListener); + //3.delete instance,see if the listener can be notified + DeleteOption deleteOption = DeleteOption.newBuilder().withPrefix(buildRegistryKeyPrefix()).build(); + client.getKVClient().delete(buildRegistryKeyPrefix(), deleteOption).get(); + assertThat(etcdListener.isNotified()).isTrue(); + } + + @Test + public void testUnsubscribe() throws Exception { + RegistryService registryService = new EtcdRegistryProvider().provide(); + InetSocketAddress inetSocketAddress = new InetSocketAddress(HOST, PORT); + //1.register + registryService.register(inetSocketAddress); + //2.subscribe + EtcdListener etcdListener = new EtcdListener(); + registryService.subscribe(CLUSTER_NAME, etcdListener); + //3.delete instance,see if the listener can be notified + DeleteOption deleteOption = DeleteOption.newBuilder().withPrefix(buildRegistryKeyPrefix()).build(); + client.getKVClient().delete(buildRegistryKeyPrefix(), deleteOption).get(); + assertThat(etcdListener.isNotified()).isTrue(); + //4.unsubscribe + registryService.unsubscribe(CLUSTER_NAME, etcdListener); + //5.reset + etcdListener.reset(); + //6.put instance,the listener should not be notified + client.getKVClient().put(buildRegistryKeyPrefix(), ByteSequence.from("test", UTF_8)).get(); + assertThat(etcdListener.isNotified()).isFalse(); + } + + @Test + public void testLookup() throws Exception { + RegistryService registryService = new EtcdRegistryProvider().provide(); + InetSocketAddress inetSocketAddress = new InetSocketAddress(HOST, PORT); + //1.register + registryService.register(inetSocketAddress); + //2.lookup + List inetSocketAddresses = registryService.lookup("my_test_tx_group"); + assertThat(inetSocketAddresses).size().isEqualTo(1); + } + + /** + * build registry key prefix + * + * @return + */ + private ByteSequence buildRegistryKeyPrefix() { + return ByteSequence.from(REGISTRY_KEY_PREFIX, UTF_8); + } + + /** + * etcd listener + */ + private class EtcdListener implements Watch.Listener { + private boolean notified = false; + + @Override + public void onNext(WatchResponse response) { + notified = true; + + } + + @Override + public void onError(Throwable throwable) { + + } + + @Override + public void onCompleted() { + + } + + /** + * @return + */ + public boolean isNotified() throws InterruptedException { + TimeUnit.SECONDS.sleep(3); + return notified; + } + + /** + * reset + */ + private void reset() { + this.notified = false; + } + } +} diff --git a/discovery/seata-discovery-eureka/src/main/java/io/seata/discovery/registry/eureka/CustomEurekaInstanceConfig.java b/discovery/seata-discovery-eureka/src/main/java/io/seata/discovery/registry/eureka/CustomEurekaInstanceConfig.java index 356bc41810f..c9d68492153 100644 --- a/discovery/seata-discovery-eureka/src/main/java/io/seata/discovery/registry/eureka/CustomEurekaInstanceConfig.java +++ b/discovery/seata-discovery-eureka/src/main/java/io/seata/discovery/registry/eureka/CustomEurekaInstanceConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/discovery/seata-discovery-eureka/src/main/java/io/seata/discovery/registry/eureka/EurekaRegistryProvider.java b/discovery/seata-discovery-eureka/src/main/java/io/seata/discovery/registry/eureka/EurekaRegistryProvider.java index b86f9affbe3..8687246b90f 100644 --- a/discovery/seata-discovery-eureka/src/main/java/io/seata/discovery/registry/eureka/EurekaRegistryProvider.java +++ b/discovery/seata-discovery-eureka/src/main/java/io/seata/discovery/registry/eureka/EurekaRegistryProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/discovery/seata-discovery-eureka/src/main/java/io/seata/discovery/registry/eureka/EurekaRegistryServiceImpl.java b/discovery/seata-discovery-eureka/src/main/java/io/seata/discovery/registry/eureka/EurekaRegistryServiceImpl.java index f7f192d810c..b07c9dcf0e1 100644 --- a/discovery/seata-discovery-eureka/src/main/java/io/seata/discovery/registry/eureka/EurekaRegistryServiceImpl.java +++ b/discovery/seata-discovery-eureka/src/main/java/io/seata/discovery/registry/eureka/EurekaRegistryServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/discovery/seata-discovery-nacos/src/main/java/io/seata/discovery/registry/nacos/NacosRegistryProvider.java b/discovery/seata-discovery-nacos/src/main/java/io/seata/discovery/registry/nacos/NacosRegistryProvider.java index 76e576349dc..1acd0db7f7e 100644 --- a/discovery/seata-discovery-nacos/src/main/java/io/seata/discovery/registry/nacos/NacosRegistryProvider.java +++ b/discovery/seata-discovery-nacos/src/main/java/io/seata/discovery/registry/nacos/NacosRegistryProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/discovery/seata-discovery-nacos/src/main/java/io/seata/discovery/registry/nacos/NacosRegistryServiceImpl.java b/discovery/seata-discovery-nacos/src/main/java/io/seata/discovery/registry/nacos/NacosRegistryServiceImpl.java index 0dea8b36ca3..ff0e066e7bd 100644 --- a/discovery/seata-discovery-nacos/src/main/java/io/seata/discovery/registry/nacos/NacosRegistryServiceImpl.java +++ b/discovery/seata-discovery-nacos/src/main/java/io/seata/discovery/registry/nacos/NacosRegistryServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.registry.nacos; import java.net.InetSocketAddress; diff --git a/discovery/seata-discovery-redis/src/main/java/io/seata/discovery/registry/redis/RedisListener.java b/discovery/seata-discovery-redis/src/main/java/io/seata/discovery/registry/redis/RedisListener.java index f96e65712da..cd9e989afee 100644 --- a/discovery/seata-discovery-redis/src/main/java/io/seata/discovery/registry/redis/RedisListener.java +++ b/discovery/seata-discovery-redis/src/main/java/io/seata/discovery/registry/redis/RedisListener.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.registry.redis; /** diff --git a/discovery/seata-discovery-redis/src/main/java/io/seata/discovery/registry/redis/RedisRegistryProvider.java b/discovery/seata-discovery-redis/src/main/java/io/seata/discovery/registry/redis/RedisRegistryProvider.java index f892edba6f4..4585a45b092 100644 --- a/discovery/seata-discovery-redis/src/main/java/io/seata/discovery/registry/redis/RedisRegistryProvider.java +++ b/discovery/seata-discovery-redis/src/main/java/io/seata/discovery/registry/redis/RedisRegistryProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/discovery/seata-discovery-redis/src/main/java/io/seata/discovery/registry/redis/RedisRegistryServiceImpl.java b/discovery/seata-discovery-redis/src/main/java/io/seata/discovery/registry/redis/RedisRegistryServiceImpl.java index bad577d16d8..9c1d87a8810 100644 --- a/discovery/seata-discovery-redis/src/main/java/io/seata/discovery/registry/redis/RedisRegistryServiceImpl.java +++ b/discovery/seata-discovery-redis/src/main/java/io/seata/discovery/registry/redis/RedisRegistryServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.registry.redis; import java.lang.management.ManagementFactory; @@ -75,7 +74,7 @@ private RedisRegistryServiceImpl() { String serverAddr = seataConfig.getConfig(getRedisAddrFileKey()); String[] serverArr = serverAddr.split(":"); String host = serverArr[0]; - int port = Integer.valueOf(serverArr[1]); + int port = Integer.parseInt(serverArr[1]); int db = seataConfig.getInt(getRedisDbFileKey()); GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig(); redisConfig.setTestOnBorrow(seataConfig.getBoolean(REDIS_FILEKEY_PREFIX + "test.on.borrow", true)); diff --git a/discovery/seata-discovery-sofa/pom.xml b/discovery/seata-discovery-sofa/pom.xml new file mode 100644 index 00000000000..dcd620e1602 --- /dev/null +++ b/discovery/seata-discovery-sofa/pom.xml @@ -0,0 +1,69 @@ + + + + + io.seata + seata-discovery + ${revision} + + 4.0.0 + seata-discovery-sofa + seata-discovery-sofa ${project.version} + + + + io.seata + seata-discovery-core + ${project.parent.version} + + + com.alipay.sofa + registry-client-all + + + junit + junit + test + + + + com.alipay.sofa + registry-test + ${sofa.registry.version} + test + + + log4j-over-slf4j + org.slf4j + + + log4j-jcl + org.apache.logging.log4j + + + log4j-core + org.apache.logging.log4j + + + log4j-api + org.apache.logging.log4j + + + + + diff --git a/discovery/seata-discovery-sofa/src/main/java/io/seata/discovery/registry/sofa/SofaRegistryProvider.java b/discovery/seata-discovery-sofa/src/main/java/io/seata/discovery/registry/sofa/SofaRegistryProvider.java new file mode 100644 index 00000000000..83574898ff0 --- /dev/null +++ b/discovery/seata-discovery-sofa/src/main/java/io/seata/discovery/registry/sofa/SofaRegistryProvider.java @@ -0,0 +1,33 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.discovery.registry.sofa; + + +import io.seata.common.loader.LoadLevel; +import io.seata.discovery.registry.RegistryProvider; +import io.seata.discovery.registry.RegistryService; + +/** + * @author leizhiyuan + * @date 2019/04/15 + */ +@LoadLevel(name = "Sofa", order = 1) +public class SofaRegistryProvider implements RegistryProvider { + @Override + public RegistryService provide() { + return SofaRegistryServiceImpl.getInstance(); + } +} diff --git a/discovery/seata-discovery-sofa/src/main/java/io/seata/discovery/registry/sofa/SofaRegistryServiceImpl.java b/discovery/seata-discovery-sofa/src/main/java/io/seata/discovery/registry/sofa/SofaRegistryServiceImpl.java new file mode 100644 index 00000000000..c1371e7b2d7 --- /dev/null +++ b/discovery/seata-discovery-sofa/src/main/java/io/seata/discovery/registry/sofa/SofaRegistryServiceImpl.java @@ -0,0 +1,322 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.discovery.registry.sofa; + +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import com.alipay.sofa.registry.client.api.RegistryClient; +import com.alipay.sofa.registry.client.api.RegistryClientConfig; +import com.alipay.sofa.registry.client.api.SubscriberDataObserver; +import com.alipay.sofa.registry.client.api.model.RegistryType; +import com.alipay.sofa.registry.client.api.model.UserData; +import com.alipay.sofa.registry.client.api.registration.PublisherRegistration; +import com.alipay.sofa.registry.client.api.registration.SubscriberRegistration; +import com.alipay.sofa.registry.client.provider.DefaultRegistryClient; +import com.alipay.sofa.registry.client.provider.DefaultRegistryClientConfigBuilder; +import com.alipay.sofa.registry.core.model.ScopeEnum; +import io.seata.common.util.NetUtil; +import io.seata.config.Configuration; +import io.seata.config.ConfigurationFactory; +import io.seata.discovery.registry.RegistryService; +import org.apache.commons.lang.StringUtils; + +import static io.seata.config.ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR; +import static io.seata.config.ConfigurationKeys.FILE_ROOT_REGISTRY; + +/** + * The type SOFARegistry registry service. + * + * @author leizhiyuan + * @date 2019 /4/15 + */ +public class SofaRegistryServiceImpl implements RegistryService { + + private static final String SOFA_FILEKEY_PREFIX = "registry.sofa."; + + private static final String PRO_SERVER_ADDR_KEY = "serverAddr"; + private static final String PRO_REGION_KEY = "region"; + private static final String PRO_DATACENTER_KEY = "datacenter"; + private static final String PRO_GROUP_KEY = "group"; + private static final String PRO_APPLICATION_KEY = "application"; + private static final String PRO_CLUSTER_KEY = "cluster"; + private static final String PRO_ADDRESS_WAIT_TIME_KEY = "addressWaitTime"; + + private static final String DEFAULT_LOCAL_DATACENTER = "DefaultDataCenter"; + private static final String DEFAULT_LOCAL_REGION = "DEFAULT_ZONE"; + private static final String DEFAULT_GROUP = "SEATA_GROUP"; + private static final String DEFAULT_APPLICATION = "default"; + private static final String DEFAULT_CLUSTER = "default"; + private static final String DEFAULT_ADDRESS_WAIT_TIME = "3000"; + + private static final Configuration FILE_CONFIG = ConfigurationFactory.FILE_INSTANCE; + + private static final String HOST_SEPERATOR = ":"; + private static final String REGISTRY_TYPE = "sofa"; + + private static final ConcurrentMap> LISTENER_SERVICE_MAP + = new ConcurrentHashMap<>(); + private static final ConcurrentMap> CLUSTER_ADDRESS_MAP = new ConcurrentHashMap<>(); + private static Properties registryProps; + private static volatile RegistryClient registryClient; + + private static volatile SofaRegistryServiceImpl instance; + + private SofaRegistryServiceImpl() { + } + + /** + * Gets instance. + * + * @return the instance + */ + static SofaRegistryServiceImpl getInstance() { + if (null == instance) { + synchronized (SofaRegistryServiceImpl.class) { + if (null == instance) { + registryProps = getNamingProperties(); + instance = new SofaRegistryServiceImpl(); + } + } + } + return instance; + } + + @Override + public void register(InetSocketAddress address) throws Exception { + NetUtil.validAddress(address); + String clusterName = registryProps.getProperty(PRO_CLUSTER_KEY); + PublisherRegistration publisherRegistration = new PublisherRegistration(clusterName); + publisherRegistration.setGroup(registryProps.getProperty(PRO_GROUP_KEY)); + String serviceData = address.getAddress().getHostAddress() + HOST_SEPERATOR + address.getPort(); + getRegistryInstance().register(publisherRegistration, serviceData); + } + + @Override + public void unregister(InetSocketAddress address) throws Exception { + NetUtil.validAddress(address); + String clusterName = registryProps.getProperty(PRO_CLUSTER_KEY); + getRegistryInstance().unregister(clusterName, registryProps.getProperty(PRO_GROUP_KEY), RegistryType.PUBLISHER); + } + + private RegistryClient getRegistryInstance() { + if (null == registryClient) { + synchronized (SofaRegistryServiceImpl.class) { + if (null == registryClient) { + String address = registryProps.getProperty(PRO_SERVER_ADDR_KEY); + final String portStr = StringUtils.substringAfter(address, HOST_SEPERATOR); + + RegistryClientConfig config = DefaultRegistryClientConfigBuilder.start() + .setAppName(getApplicationName()) + .setDataCenter(registryProps.getProperty(PRO_DATACENTER_KEY)) + .setZone(registryProps.getProperty(PRO_REGION_KEY)) + .setRegistryEndpoint(StringUtils.substringBefore(address, HOST_SEPERATOR)) + .setRegistryEndpointPort(Integer.parseInt(portStr)).build(); + + registryClient = new DefaultRegistryClient(config); + ((DefaultRegistryClient)registryClient).init(); + } + } + } + return registryClient; + } + + @Override + public void subscribe(String cluster, SubscriberDataObserver listener) throws Exception { + SubscriberRegistration subscriberRegistration = new SubscriberRegistration(cluster, listener); + subscriberRegistration.setScopeEnum(ScopeEnum.global); + subscriberRegistration.setGroup(registryProps.getProperty(PRO_GROUP_KEY)); + + LISTENER_SERVICE_MAP.putIfAbsent(cluster, new ArrayList<>()); + LISTENER_SERVICE_MAP.get(cluster).add(listener); + getRegistryInstance().register(subscriberRegistration); + } + + @Override + public void unsubscribe(String cluster, SubscriberDataObserver listener) throws Exception { + getRegistryInstance().unregister(cluster, registryProps.getProperty(PRO_GROUP_KEY), RegistryType.SUBSCRIBER); + } + + @Override + public List lookup(String key) throws Exception { + Configuration config = ConfigurationFactory.getInstance(); + String clusterName = config.getConfig(PREFIX_SERVICE_ROOT + CONFIG_SPLIT_CHAR + PREFIX_SERVICE_MAPPING + key); + if (null == clusterName) { + return null; + } + if (!LISTENER_SERVICE_MAP.containsKey(clusterName)) { + CountDownLatch respondRegistries = new CountDownLatch(1); + subscribe(clusterName, new SubscriberDataObserver() { + @Override + public void handleData(String dataId, UserData data) { + Map> instances = data.getZoneData(); + if (null == instances && null != CLUSTER_ADDRESS_MAP.get(clusterName)) { + CLUSTER_ADDRESS_MAP.remove(clusterName); + } else { + List tranformData = flatData(instances); + List newAddressList = new ArrayList<>(); + newAddressList.addAll(tranformData); + CLUSTER_ADDRESS_MAP.put(clusterName, newAddressList); + } + respondRegistries.countDown(); + } + }); + + //wait max for first lookup + final String property = registryProps.getProperty(PRO_ADDRESS_WAIT_TIME_KEY); + respondRegistries.await(Integer.parseInt(property), TimeUnit.MILLISECONDS); + + } + return CLUSTER_ADDRESS_MAP.get(clusterName); + } + + private List flatData(Map> instances) { + List result = new ArrayList(); + + for (Map.Entry> entry : instances.entrySet()) { + for (String str : entry.getValue()) { + String ip = StringUtils.substringBefore(str, HOST_SEPERATOR); + String port = StringUtils.substringAfter(str, HOST_SEPERATOR); + InetSocketAddress inetSocketAddress = new InetSocketAddress(ip, Integer.parseInt(port)); + result.add(inetSocketAddress); + } + } + return result; + } + + @Override + public void close() throws Exception { + } + + private static Properties getNamingProperties() { + Properties properties = new Properties(); + if (null != System.getProperty(SOFA_FILEKEY_PREFIX + PRO_SERVER_ADDR_KEY)) { + properties.setProperty(PRO_SERVER_ADDR_KEY, System.getProperty(PRO_SERVER_ADDR_KEY)); + } else { + String address = FILE_CONFIG.getConfig(getSofaAddrFileKey()); + if (null != address) { + properties.setProperty(PRO_SERVER_ADDR_KEY, address); + } + } + if (null != System.getProperty(SOFA_FILEKEY_PREFIX + PRO_REGION_KEY)) { + properties.setProperty(PRO_REGION_KEY, System.getProperty(PRO_REGION_KEY)); + } else { + String region = FILE_CONFIG.getConfig(getSofaRegionFileKey()); + if (null == region) { + region = DEFAULT_LOCAL_REGION; + } + properties.setProperty(PRO_REGION_KEY, region); + } + + if (null != System.getProperty(SOFA_FILEKEY_PREFIX + PRO_DATACENTER_KEY)) { + properties.setProperty(PRO_DATACENTER_KEY, System.getProperty(PRO_DATACENTER_KEY)); + } else { + String datacenter = FILE_CONFIG.getConfig(getSofaDataCenterFileKey()); + if (null == datacenter) { + datacenter = DEFAULT_LOCAL_DATACENTER; + } + properties.setProperty(PRO_DATACENTER_KEY, datacenter); + } + + if (null != System.getProperty(SOFA_FILEKEY_PREFIX + PRO_GROUP_KEY)) { + properties.setProperty(PRO_GROUP_KEY, System.getProperty(PRO_GROUP_KEY)); + } else { + String group = FILE_CONFIG.getConfig(getSofaGroupFileKey()); + if (null == group) { + group = DEFAULT_GROUP; + } + properties.setProperty(PRO_GROUP_KEY, group); + } + + if (null != System.getProperty(SOFA_FILEKEY_PREFIX + PRO_CLUSTER_KEY)) { + properties.setProperty(PRO_CLUSTER_KEY, System.getProperty(PRO_CLUSTER_KEY)); + } else { + String cluster = FILE_CONFIG.getConfig(getSofaClusterFileKey()); + if (null == cluster) { + cluster = DEFAULT_CLUSTER; + } + properties.setProperty(PRO_CLUSTER_KEY, cluster); + } + + if (null != System.getProperty(SOFA_FILEKEY_PREFIX + PRO_ADDRESS_WAIT_TIME_KEY)) { + properties.setProperty(PRO_ADDRESS_WAIT_TIME_KEY, System.getProperty(PRO_ADDRESS_WAIT_TIME_KEY)); + } else { + String group = FILE_CONFIG.getConfig(getSofaAddressWaitTimeFileKey()); + if (null == group) { + group = DEFAULT_ADDRESS_WAIT_TIME; + } + properties.setProperty(PRO_ADDRESS_WAIT_TIME_KEY, group); + } + + return properties; + } + + private static String getSofaClusterFileKey() { + return FILE_ROOT_REGISTRY + FILE_CONFIG_SPLIT_CHAR + REGISTRY_TYPE + + FILE_CONFIG_SPLIT_CHAR + + PRO_CLUSTER_KEY; + } + + private static String getSofaAddressWaitTimeFileKey() { + return FILE_ROOT_REGISTRY + FILE_CONFIG_SPLIT_CHAR + REGISTRY_TYPE + + FILE_CONFIG_SPLIT_CHAR + + PRO_ADDRESS_WAIT_TIME_KEY; + } + + private static String getSofaAddrFileKey() { + return FILE_ROOT_REGISTRY + FILE_CONFIG_SPLIT_CHAR + REGISTRY_TYPE + + FILE_CONFIG_SPLIT_CHAR + + PRO_SERVER_ADDR_KEY; + } + + private static String getSofaRegionFileKey() { + return FILE_ROOT_REGISTRY + FILE_CONFIG_SPLIT_CHAR + REGISTRY_TYPE + + FILE_CONFIG_SPLIT_CHAR + + PRO_REGION_KEY; + } + + private static String getSofaDataCenterFileKey() { + return FILE_ROOT_REGISTRY + FILE_CONFIG_SPLIT_CHAR + REGISTRY_TYPE + + FILE_CONFIG_SPLIT_CHAR + + PRO_DATACENTER_KEY; + } + + private static String getSofaGroupFileKey() { + return FILE_ROOT_REGISTRY + FILE_CONFIG_SPLIT_CHAR + REGISTRY_TYPE + + FILE_CONFIG_SPLIT_CHAR + + PRO_GROUP_KEY; + } + + private String getApplicationFileKey() { + return FILE_ROOT_REGISTRY + FILE_CONFIG_SPLIT_CHAR + REGISTRY_TYPE + FILE_CONFIG_SPLIT_CHAR + + PRO_APPLICATION_KEY; + } + + private String getApplicationName() { + String application = FILE_CONFIG.getConfig(getApplicationFileKey()); + if (null == application) { + application = DEFAULT_APPLICATION; + } + return application; + } +} diff --git a/discovery/seata-discovery-sofa/src/main/resources/META-INF/services/io.seata.discovery.registry.RegistryProvider b/discovery/seata-discovery-sofa/src/main/resources/META-INF/services/io.seata.discovery.registry.RegistryProvider new file mode 100644 index 00000000000..a5afd865039 --- /dev/null +++ b/discovery/seata-discovery-sofa/src/main/resources/META-INF/services/io.seata.discovery.registry.RegistryProvider @@ -0,0 +1 @@ +io.seata.discovery.registry.sofa.SofaRegistryProvider \ No newline at end of file diff --git a/discovery/seata-discovery-sofa/src/test/io/seata/discovery/registry/sofa/SofaRegistryServiceImplTest.java b/discovery/seata-discovery-sofa/src/test/io/seata/discovery/registry/sofa/SofaRegistryServiceImplTest.java new file mode 100644 index 00000000000..4a5e1b6a691 --- /dev/null +++ b/discovery/seata-discovery-sofa/src/test/io/seata/discovery/registry/sofa/SofaRegistryServiceImplTest.java @@ -0,0 +1,112 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.discovery.registry.sofa; + +import com.alipay.sofa.registry.server.test.TestRegistryMain; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; +/** + * The type SofaRegistryServiceImpl test. + * + * @author leizhiyuan + */ +public class SofaRegistryServiceImplTest { + + private static TestRegistryMain registryMain; + + @BeforeClass + public static void beforeClass() { + System.setProperty("serverAddr", "127.0.0.1:9603"); + System.setProperty("addressWaitTime", "10000"); + registryMain = new TestRegistryMain(); + try { + registryMain.startRegistry(); + } catch (Exception e) { + Assert.fail("start sofaregistry fail"); + } + } + + @Test + public void testSofaRegistry() { + final InetSocketAddress address = new InetSocketAddress(1234); + + final SofaRegistryServiceImpl instance = SofaRegistryServiceImpl.getInstance(); + try { + instance.register(address); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + + //need sofa registry to sync data + try { + TimeUnit.SECONDS.sleep(10); + } catch (InterruptedException e) { + } + + List result = new ArrayList<>(); + try { + result = instance.lookup("my_test_tx_group"); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + + Assert.assertTrue(result.size() > 0); + Assert.assertEquals(address, result.get(0)); + + + try { + instance.unregister(address); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + + try { + TimeUnit.SECONDS.sleep(3); + } catch (InterruptedException ignore) { + } + + try { + result = instance.lookup("my_test_tx_group"); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + + Assert.assertEquals(0, result.size()); + + } + + + @AfterClass + public static void afterClass() { + System.setProperty("serverAddr", ""); + System.setProperty("addressWaitTime", "0"); + + + try { + registryMain.stopRegistry(); + } catch (Exception ignore) { + //ignore + } + } + +} \ No newline at end of file diff --git a/discovery/seata-discovery-zk/pom.xml b/discovery/seata-discovery-zk/pom.xml index cca2470daa3..635cdd1d5ac 100644 --- a/discovery/seata-discovery-zk/pom.xml +++ b/discovery/seata-discovery-zk/pom.xml @@ -41,5 +41,12 @@ + + + org.apache.curator + curator-test + 2.9.1 + test + diff --git a/discovery/seata-discovery-zk/src/main/java/io/seata/discovery/registry/zk/ZookeeperRegisterServiceImpl.java b/discovery/seata-discovery-zk/src/main/java/io/seata/discovery/registry/zk/ZookeeperRegisterServiceImpl.java index fb3a1a13c97..41af1611c1c 100644 --- a/discovery/seata-discovery-zk/src/main/java/io/seata/discovery/registry/zk/ZookeeperRegisterServiceImpl.java +++ b/discovery/seata-discovery-zk/src/main/java/io/seata/discovery/registry/zk/ZookeeperRegisterServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.registry.zk; import io.seata.common.util.CollectionUtils; @@ -99,12 +98,22 @@ private boolean doRegister(String path) { if (checkExists(path)) { return false; } + createParentIfNotPresent(path); getClientInstance().createEphemeral(path, true); REGISTERED_PATH_SET.add(path); return true; } - + private void createParentIfNotPresent(String path) { + int i = path.lastIndexOf('/'); + if (i > 0) { + String parent = path.substring(0, i); + if (!checkExists(parent)) { + getClientInstance().createPersistent(parent); + } + } + } + private boolean checkExists(String path) { return getClientInstance().exists(path); } @@ -125,11 +134,12 @@ public void subscribe(String cluster, IZkChildListener listener) throws Exceptio } String path = ROOT_PATH + cluster; - if (getClientInstance().exists(path)) { - getClientInstance().subscribeChildChanges(path, listener); - LISTENER_SERVICE_MAP.putIfAbsent(cluster, new ArrayList<>()); - LISTENER_SERVICE_MAP.get(cluster).add(listener); + if (!getClientInstance().exists(path)) { + getClientInstance().createPersistent(path); } + getClientInstance().subscribeChildChanges(path, listener); + LISTENER_SERVICE_MAP.putIfAbsent(cluster, new ArrayList<>()); + LISTENER_SERVICE_MAP.get(cluster).add(listener); } @Override @@ -168,7 +178,12 @@ public List lookup(String key) throws Exception { return null; } - Boolean exist = getClientInstance().exists(ROOT_PATH + clusterName); + return doLookup(clusterName); + } + + // visible for test. + List doLookup(String clusterName) throws Exception { + boolean exist = getClientInstance().exists(ROOT_PATH + clusterName); if (!exist) { return null; } @@ -189,30 +204,40 @@ public void close() throws Exception { private ZkClient getClientInstance() { if (zkClient == null) { - zkClient = new ZkClient(FILE_CONFIG.getConfig(FILE_CONFIG_KEY_PREFIX + SERVER_ADDR_KEY), - FILE_CONFIG.getInt(FILE_CONFIG_KEY_PREFIX + SESSION_TIME_OUT_KEY), - FILE_CONFIG.getInt(FILE_CONFIG_KEY_PREFIX + CONNECT_TIME_OUT_KEY)); - if (!zkClient.exists(ROOT_PATH_WITHOUT_SUFFIX)) { - zkClient.createPersistent(ROOT_PATH_WITHOUT_SUFFIX, true); + synchronized (ZookeeperRegisterServiceImpl.class) { + if (null == zkClient) { + zkClient = buildZkClient(FILE_CONFIG.getConfig(FILE_CONFIG_KEY_PREFIX + SERVER_ADDR_KEY), + FILE_CONFIG.getInt(FILE_CONFIG_KEY_PREFIX + SESSION_TIME_OUT_KEY), + FILE_CONFIG.getInt(FILE_CONFIG_KEY_PREFIX + CONNECT_TIME_OUT_KEY)); + } } - zkClient.subscribeStateChanges(new IZkStateListener() { + } + return zkClient; + } + + // visible for test. + ZkClient buildZkClient(String address, int sessionTimeout, int connectTimeout) { + ZkClient zkClient = new ZkClient(address, sessionTimeout,connectTimeout); + if (!zkClient.exists(ROOT_PATH_WITHOUT_SUFFIX)) { + zkClient.createPersistent(ROOT_PATH_WITHOUT_SUFFIX, true); + } + zkClient.subscribeStateChanges(new IZkStateListener() { - @Override - public void handleStateChanged(Watcher.Event.KeeperState keeperState) throws Exception { - //ignore - } + @Override + public void handleStateChanged(Watcher.Event.KeeperState keeperState) throws Exception { + //ignore + } - @Override - public void handleNewSession() throws Exception { - recover(); - } + @Override + public void handleNewSession() throws Exception { + recover(); + } - @Override - public void handleSessionEstablishmentError(Throwable throwable) throws Exception { - //ignore - } - }); - } + @Override + public void handleSessionEstablishmentError(Throwable throwable) throws Exception { + //ignore + } + }); return zkClient; } diff --git a/discovery/seata-discovery-zk/src/main/java/io/seata/discovery/registry/zk/ZookeeperRegistryProvider.java b/discovery/seata-discovery-zk/src/main/java/io/seata/discovery/registry/zk/ZookeeperRegistryProvider.java index f1837d330fa..f97e7199341 100644 --- a/discovery/seata-discovery-zk/src/main/java/io/seata/discovery/registry/zk/ZookeeperRegistryProvider.java +++ b/discovery/seata-discovery-zk/src/main/java/io/seata/discovery/registry/zk/ZookeeperRegistryProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.discovery.registry.zk; import io.seata.common.loader.LoadLevel; diff --git a/discovery/seata-discovery-zk/src/test/java/io/seata/discovery/registry/zk/ZookeeperRegisterServiceImplTest.java b/discovery/seata-discovery-zk/src/test/java/io/seata/discovery/registry/zk/ZookeeperRegisterServiceImplTest.java new file mode 100644 index 00000000000..3788e0cfe92 --- /dev/null +++ b/discovery/seata-discovery-zk/src/test/java/io/seata/discovery/registry/zk/ZookeeperRegisterServiceImplTest.java @@ -0,0 +1,98 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.discovery.registry.zk; + +import io.seata.common.util.NetUtil; +import org.I0Itec.zkclient.IZkChildListener; +import org.I0Itec.zkclient.ZkClient; +import org.apache.curator.test.TestingServer; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * @author Geng Zhang + */ +public class ZookeeperRegisterServiceImplTest { + protected static TestingServer server = null; + @BeforeClass + public static void adBeforeClass() throws Exception { + server = new TestingServer(2181, true); + server.start(); + } + + @AfterClass + public static void adAfterClass() throws Exception { + if (server != null) { + server.stop(); + } + } + + ZookeeperRegisterServiceImpl service = (ZookeeperRegisterServiceImpl) new ZookeeperRegistryProvider().provide(); + + @Test + public void getInstance() { + ZookeeperRegisterServiceImpl service1 = ZookeeperRegisterServiceImpl.getInstance(); + Assert.assertEquals(service1, service); + } + + @Test + public void buildZkTest() { + ZkClient client = service.buildZkClient("127.0.0.1:2181", 5000, 5000); + Assert.assertTrue(client.exists("/zookeeper")); + } + + @Test + public void testAll() throws Exception { + service.register(new InetSocketAddress(NetUtil.getLocalAddress(), 33333)); + + Assert.assertNull(service.lookup("xxx")); + List lookup2 = service.doLookup("default"); + Assert.assertTrue(lookup2.size() == 1); + + final List data = new ArrayList<>(); + final CountDownLatch latch = new CountDownLatch(1); + IZkChildListener listener = (s, list) -> { + data.clear(); + data.addAll(list); + latch.countDown(); + }; + service.subscribe("default", listener); + final CountDownLatch latch2 = new CountDownLatch(1); + final List data2 = new ArrayList<>(); + IZkChildListener listener2 = (s, list) -> { + data2.clear(); + data2.addAll(list); + latch2.countDown(); + }; + service.subscribe("default", listener2); + + service.unregister(new InetSocketAddress(NetUtil.getLocalAddress(), 33333)); + latch2.await(1000, TimeUnit.MILLISECONDS); + Assert.assertTrue(data2.size() == 0); + + service.unsubscribe("default", listener); + service.unsubscribe("default", listener2); + } + +} \ No newline at end of file diff --git a/discovery/seata-discovery-zk/src/test/java/io/seata/discovery/registry/zk/ZookeeperRegistryProviderTest.java b/discovery/seata-discovery-zk/src/test/java/io/seata/discovery/registry/zk/ZookeeperRegistryProviderTest.java new file mode 100644 index 00000000000..6cf299cfd10 --- /dev/null +++ b/discovery/seata-discovery-zk/src/test/java/io/seata/discovery/registry/zk/ZookeeperRegistryProviderTest.java @@ -0,0 +1,32 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.discovery.registry.zk; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Geng Zhang + */ +public class ZookeeperRegistryProviderTest { + + @Test + public void provide() { + ZookeeperRegistryProvider provider = new ZookeeperRegistryProvider(); + Assert.assertTrue(provider.provide() instanceof ZookeeperRegisterServiceImpl); + } + +} \ No newline at end of file diff --git a/dubbo-alibaba/src/main/resources/META-INF/services/com.alibaba.dubbo.rpc.Filter b/dubbo-alibaba/src/main/resources/META-INF/services/com.alibaba.dubbo.rpc.Filter deleted file mode 100644 index 11c09e91703..00000000000 --- a/dubbo-alibaba/src/main/resources/META-INF/services/com.alibaba.dubbo.rpc.Filter +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright 1999-2018 Alibaba Group Holding Ltd. -# -# 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. -# - -io.seata.dubbo.alibaba.TransactionPropagationFilter \ No newline at end of file diff --git a/dubbo/src/main/resources/META-INF/services/org.apache.dubbo.rpc.Filter b/dubbo/src/main/resources/META-INF/services/org.apache.dubbo.rpc.Filter deleted file mode 100644 index 4e5c0d46373..00000000000 --- a/dubbo/src/main/resources/META-INF/services/org.apache.dubbo.rpc.Filter +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright 1999-2018 Alibaba Group Holding Ltd. -# -# 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. -# - -io.seata.dubbo.TransactionPropagationFilter \ No newline at end of file diff --git a/dubbo-alibaba/pom.xml b/integration/dubbo-alibaba/pom.xml similarity index 96% rename from dubbo-alibaba/pom.xml rename to integration/dubbo-alibaba/pom.xml index dc9a6a162da..fd8959c0b3b 100644 --- a/dubbo-alibaba/pom.xml +++ b/integration/dubbo-alibaba/pom.xml @@ -22,6 +22,7 @@ io.seata seata-parent ${revision} + ../../pom.xml 4.0.0 @@ -39,5 +40,4 @@ 2.6.5 - diff --git a/dubbo-alibaba/src/main/java/io/seata/dubbo/alibaba/TransactionPropagationFilter.java b/integration/dubbo-alibaba/src/main/java/io/seata/integration/dubbo/alibaba/TransactionPropagationFilter.java similarity index 97% rename from dubbo-alibaba/src/main/java/io/seata/dubbo/alibaba/TransactionPropagationFilter.java rename to integration/dubbo-alibaba/src/main/java/io/seata/integration/dubbo/alibaba/TransactionPropagationFilter.java index 48d9a77b2a5..ccd1dc41d5e 100644 --- a/dubbo-alibaba/src/main/java/io/seata/dubbo/alibaba/TransactionPropagationFilter.java +++ b/integration/dubbo-alibaba/src/main/java/io/seata/integration/dubbo/alibaba/TransactionPropagationFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,8 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -package io.seata.dubbo.alibaba; +package io.seata.integration.dubbo.alibaba; import com.alibaba.dubbo.common.Constants; import com.alibaba.dubbo.common.extension.Activate; diff --git a/integration/dubbo-alibaba/src/main/resources/META-INF/services/com.alibaba.dubbo.rpc.Filter b/integration/dubbo-alibaba/src/main/resources/META-INF/services/com.alibaba.dubbo.rpc.Filter new file mode 100644 index 00000000000..411c528b5a1 --- /dev/null +++ b/integration/dubbo-alibaba/src/main/resources/META-INF/services/com.alibaba.dubbo.rpc.Filter @@ -0,0 +1 @@ +io.seata.integration.dubbo.alibaba.TransactionPropagationFilter \ No newline at end of file diff --git a/dubbo/pom.xml b/integration/dubbo/pom.xml similarity index 96% rename from dubbo/pom.xml rename to integration/dubbo/pom.xml index 2978e5c8ea2..85e3d81e99b 100644 --- a/dubbo/pom.xml +++ b/integration/dubbo/pom.xml @@ -21,6 +21,7 @@ io.seata seata-parent ${revision} + ../../pom.xml 4.0.0 seata-dubbo diff --git a/dubbo/src/main/java/io/seata/dubbo/TransactionPropagationFilter.java b/integration/dubbo/src/main/java/io/seata/integration/dubbo/TransactionPropagationFilter.java similarity index 97% rename from dubbo/src/main/java/io/seata/dubbo/TransactionPropagationFilter.java rename to integration/dubbo/src/main/java/io/seata/integration/dubbo/TransactionPropagationFilter.java index 478f50b027c..76de6a5cb95 100644 --- a/dubbo/src/main/java/io/seata/dubbo/TransactionPropagationFilter.java +++ b/integration/dubbo/src/main/java/io/seata/integration/dubbo/TransactionPropagationFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -package io.seata.dubbo; +package io.seata.integration.dubbo; import io.seata.core.context.RootContext; - import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.rpc.Filter; diff --git a/integration/dubbo/src/main/resources/META-INF/services/org.apache.dubbo.rpc.Filter b/integration/dubbo/src/main/resources/META-INF/services/org.apache.dubbo.rpc.Filter new file mode 100644 index 00000000000..6e43e2b995e --- /dev/null +++ b/integration/dubbo/src/main/resources/META-INF/services/org.apache.dubbo.rpc.Filter @@ -0,0 +1 @@ +io.seata.integration.dubbo.TransactionPropagationFilter \ No newline at end of file diff --git a/pom.xml b/pom.xml index f75e7054e05..d40c2248302 100644 --- a/pom.xml +++ b/pom.xml @@ -23,24 +23,24 @@ seata-parent ${revision} - config common - server - distribution + config core + discovery + distribution + integration/dubbo + integration/dubbo-alibaba + rm rm-datasource - tm + server spring - dubbo - discovery - test - dubbo-alibaba tcc - rm + test + tm pom - Seata ${project.version} + Seata Parent POM ${project.version} http://seata.io top seata project pom.xml file @@ -79,7 +79,7 @@ - 0.5.0 + 0.5.1 UTF-8 UTF-8 @@ -112,14 +112,20 @@ 1.9.5 1.4.2 0.9.1 + 0.3.0 + 1.11.2 + 27.0.1-jre 1 0.7.6 + 5.2.0 1.1.0 3.6.0 1.3.6 3.8 3.0.0 2.2.1 + 3.0 + 3.0.0 @@ -213,11 +219,21 @@ seata-discovery-redis ${project.version} + + ${project.groupId} + seata-discovery-sofa + ${project.version} + ${project.groupId} seata-discovery-nacos ${project.version} + + ${project.groupId} + seata-discovery-etcd3 + ${project.version} + ${project.groupId} seata-config-core @@ -333,6 +349,11 @@ zkclient ${zkclient.version} + + com.alipay.sofa + registry-client-all + ${sofa.registry.version} + com.alibaba.spring spring-context-support @@ -363,6 +384,26 @@ consul-api ${consul-clients.version} + + io.etcd + jetcd-core + ${etcd-client-v3.version} + + + io.etcd + jetcd-launcher + ${etcd-client-v3.version} + + + org.testcontainers + testcontainers + ${testcontainers.version} + + + com.google.guava + guava + ${guava.version} + javax.inject javax.inject @@ -559,6 +600,53 @@ + + com.mycila + license-maven-plugin + ${license-maven-plugin.version} + + + generate-sources + + remove + format + + + + + true +
${user.dir}/style/copyright
+ + **/src/main/java/** + **/src/test/java/** + + true + + SLASHSTAR_STYLE + +
+
+ + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + + + validate + validate + + ${user.dir}/style/feats_checkstyle.xml + UTF-8 + true + false + false + + + check + + + + diff --git a/rm-datasource/src/main/java/io/seata/rm/GlobalLockTemplate.java b/rm-datasource/src/main/java/io/seata/rm/GlobalLockTemplate.java index 2e36376c878..658c5b415ae 100644 --- a/rm-datasource/src/main/java/io/seata/rm/GlobalLockTemplate.java +++ b/rm-datasource/src/main/java/io/seata/rm/GlobalLockTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm; import java.util.concurrent.Callable; diff --git a/rm-datasource/src/main/java/io/seata/rm/RMHandlerAT.java b/rm-datasource/src/main/java/io/seata/rm/RMHandlerAT.java index 29dbed559b1..17fa33dd1be 100644 --- a/rm-datasource/src/main/java/io/seata/rm/RMHandlerAT.java +++ b/rm-datasource/src/main/java/io/seata/rm/RMHandlerAT.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm; import io.seata.core.model.BranchType; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractConnectionProxy.java b/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractConnectionProxy.java index af71a8c2ad1..c97149ff3aa 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractConnectionProxy.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractConnectionProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource; import io.seata.core.context.RootContext; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractDataSourceProxy.java b/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractDataSourceProxy.java index 1b2aba6e4d8..af296ea5ca9 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractDataSourceProxy.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractDataSourceProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource; import javax.sql.DataSource; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractPreparedStatementProxy.java b/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractPreparedStatementProxy.java index 39c8fc0d362..b835dc354ab 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractPreparedStatementProxy.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractPreparedStatementProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource; import java.io.InputStream; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractStatementProxy.java b/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractStatementProxy.java index f4299d3ec2b..01233ad9539 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractStatementProxy.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/AbstractStatementProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource; import java.sql.Connection; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/AsyncWorker.java b/rm-datasource/src/main/java/io/seata/rm/datasource/AsyncWorker.java index 4859c0feb71..f1400f49aa0 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/AsyncWorker.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/AsyncWorker.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource; import io.seata.common.exception.NotSupportYetException; import io.seata.common.exception.ShouldNeverHappenException; import io.seata.common.thread.NamedThreadFactory; +import io.seata.common.util.CollectionUtils; import io.seata.config.ConfigurationFactory; import io.seata.core.exception.TransactionException; import io.seata.core.model.BranchStatus; @@ -26,18 +26,20 @@ import io.seata.core.model.ResourceManagerInbound; import io.seata.rm.DefaultResourceManager; import io.seata.rm.datasource.undo.UndoLogManager; -import io.seata.rm.datasource.undo.UndoLogManager; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -55,6 +57,8 @@ public class AsyncWorker implements ResourceManagerInbound { private static final int DEFAULT_RESOURCE_SIZE = 16; + private static final int UNDOLOG_DELETE_LIMIT_SIZE = 1000; + private static class Phase2Context { /** @@ -97,19 +101,17 @@ public Phase2Context(BranchType branchType, String xid, long branchId, String re BranchType branchType; } - private static final List ASYNC_COMMIT_BUFFER = Collections.synchronizedList( - new ArrayList()); - private static int ASYNC_COMMIT_BUFFER_LIMIT = ConfigurationFactory.getInstance().getInt( CLIENT_ASYNC_COMMIT_BUFFER_LIMIT, 10000); + private static final BlockingQueue ASYNC_COMMIT_BUFFER = new LinkedBlockingQueue<>(ASYNC_COMMIT_BUFFER_LIMIT); + + private static ScheduledExecutorService timerExecutor; @Override public BranchStatus branchCommit(BranchType branchType, String xid, long branchId, String resourceId, String applicationData) throws TransactionException { - if (ASYNC_COMMIT_BUFFER.size() < ASYNC_COMMIT_BUFFER_LIMIT) { - ASYNC_COMMIT_BUFFER.add(new Phase2Context(branchType, xid, branchId, resourceId, applicationData)); - } else { + if (!ASYNC_COMMIT_BUFFER.offer(new Phase2Context(branchType, xid, branchId, resourceId, applicationData))) { LOGGER.warn("Async commit buffer is FULL. Rejected branch [" + branchId + "/" + xid + "] will be handled by housekeeping later."); } return BranchStatus.PhaseTwo_Committed; @@ -141,10 +143,10 @@ private void doBranchCommits() { if (ASYNC_COMMIT_BUFFER.size() == 0) { return; } + Map> mappedContexts = new HashMap<>(DEFAULT_RESOURCE_SIZE); - Iterator iterator = ASYNC_COMMIT_BUFFER.iterator(); - while (iterator.hasNext()) { - Phase2Context commitContext = iterator.next(); + while (!ASYNC_COMMIT_BUFFER.isEmpty()) { + Phase2Context commitContext = ASYNC_COMMIT_BUFFER.poll(); List contextsGroupedByResourceId = mappedContexts.get(commitContext.resourceId); if (contextsGroupedByResourceId == null) { contextsGroupedByResourceId = new ArrayList<>(); @@ -152,8 +154,6 @@ private void doBranchCommits() { } contextsGroupedByResourceId.add(commitContext); - iterator.remove(); - } for (Map.Entry> entry : mappedContexts.entrySet()) { @@ -171,15 +171,33 @@ private void doBranchCommits() { continue; } List contextsGroupedByResourceId = entry.getValue(); + Set xids = new LinkedHashSet<>(UNDOLOG_DELETE_LIMIT_SIZE); + Set branchIds = new LinkedHashSet<>(UNDOLOG_DELETE_LIMIT_SIZE); for (Phase2Context commitContext : contextsGroupedByResourceId) { - try { - UndoLogManager.deleteUndoLog(commitContext.xid, commitContext.branchId, conn); - } catch (Exception ex) { - LOGGER.warn( - "Failed to delete undo log [" + commitContext.branchId + "/" + commitContext.xid + "]", ex); + xids.add(commitContext.xid); + branchIds.add(commitContext.branchId); + int maxSize = xids.size() > branchIds.size() ? xids.size() : branchIds.size(); + if(maxSize == UNDOLOG_DELETE_LIMIT_SIZE){ + try { + UndoLogManager.batchDeleteUndoLog(xids, branchIds, UNDOLOG_DELETE_LIMIT_SIZE, conn); + } catch (Exception ex) { + LOGGER.warn("Failed to batch delete undo log [" + branchIds + "/" + xids + "]", ex); + } + xids.clear(); + branchIds.clear(); } } + if (CollectionUtils.isEmpty(xids) || CollectionUtils.isEmpty(branchIds)) { + return; + } + + try { + UndoLogManager.batchDeleteUndoLog(xids, branchIds, UNDOLOG_DELETE_LIMIT_SIZE, conn); + }catch (Exception ex) { + LOGGER.warn("Failed to batch delete undo log [" + branchIds + "/" + xids + "]", ex); + } + } finally { if (conn != null) { try { diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/ConnectionContext.java b/rm-datasource/src/main/java/io/seata/rm/datasource/ConnectionContext.java index 8738de7b105..06addce1b0e 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/ConnectionContext.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/ConnectionContext.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource; import java.util.ArrayList; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/ConnectionProxy.java b/rm-datasource/src/main/java/io/seata/rm/datasource/ConnectionProxy.java index 696c0d45802..3ebfdb86388 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/ConnectionProxy.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/ConnectionProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource; import io.seata.config.ConfigurationFactory; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/DataSourceManager.java b/rm-datasource/src/main/java/io/seata/rm/datasource/DataSourceManager.java index c9718e1a806..0c17a1b272f 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/DataSourceManager.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/DataSourceManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource; import java.net.InetSocketAddress; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/DataSourceProxy.java b/rm-datasource/src/main/java/io/seata/rm/datasource/DataSourceProxy.java index 85d292b6278..79f534dab65 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/DataSourceProxy.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/DataSourceProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource; import com.alibaba.druid.util.JdbcUtils; @@ -40,8 +39,6 @@ public class DataSourceProxy extends AbstractDataSourceProxy implements Resource private String dbType; - private boolean managed = false; - /** * Instantiates a new Data source proxy. * @@ -70,13 +67,7 @@ private void init(DataSource dataSource, String resourceGroupId) { } catch (SQLException e) { throw new IllegalStateException(String.format("can not init dataSource :%s", e.getSQLState())); } - } - - private void assertManaged() { - if (!managed) { - DefaultResourceManager.get().registerResource(this); - managed = true; - } + DefaultResourceManager.get().registerResource(this); } /** @@ -100,14 +91,12 @@ public String getDbType() { @Override public ConnectionProxy getConnection() throws SQLException { - assertManaged(); Connection targetConnection = targetDataSource.getConnection(); return new ConnectionProxy(this, targetConnection); } @Override public ConnectionProxy getConnection(String username, String password) throws SQLException { - assertManaged(); Connection targetConnection = targetDataSource.getConnection(username, password); return new ConnectionProxy(this, targetConnection); } diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/ParametersHolder.java b/rm-datasource/src/main/java/io/seata/rm/datasource/ParametersHolder.java index 00e30921fc3..8a5c45f7c1c 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/ParametersHolder.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/ParametersHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource; import java.util.ArrayList; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/PreparedStatementProxy.java b/rm-datasource/src/main/java/io/seata/rm/datasource/PreparedStatementProxy.java index 302ab60f38c..5279ad772d7 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/PreparedStatementProxy.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/PreparedStatementProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource; import java.sql.PreparedStatement; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/StatementProxy.java b/rm-datasource/src/main/java/io/seata/rm/datasource/StatementProxy.java index 665bbb267d2..e0b1eb7ab68 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/StatementProxy.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/StatementProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource; import java.sql.ResultSet; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/AbstractDMLBaseExecutor.java b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/AbstractDMLBaseExecutor.java index 46af9c1d205..ccd5905dde7 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/AbstractDMLBaseExecutor.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/AbstractDMLBaseExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; import java.sql.SQLException; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/BaseTransactionalExecutor.java b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/BaseTransactionalExecutor.java index 945f11b5a51..6114746ea62 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/BaseTransactionalExecutor.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/BaseTransactionalExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; import java.sql.SQLException; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/DeleteExecutor.java b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/DeleteExecutor.java index 362b041cee0..6a3f3f848b5 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/DeleteExecutor.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/DeleteExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; import java.sql.PreparedStatement; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/ExecuteTemplate.java b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/ExecuteTemplate.java index bd9f7ddfaf7..715a38fed9d 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/ExecuteTemplate.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/ExecuteTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; import java.sql.SQLException; @@ -90,7 +89,7 @@ public static T execute(SQLRecognizer sqlRecognizer, executor = new DeleteExecutor(statementProxy, statementCallback, sqlRecognizer); break; case SELECT_FOR_UPDATE: - executor = new SelectForUpdateExecutor(statementProxy, statementCallback, sqlRecognizer); + executor = new SelectForUpdateExecutor(statementProxy, statementCallback, sqlRecognizer); break; default: executor = new PlainExecutor(statementProxy, statementCallback); @@ -100,7 +99,6 @@ public static T execute(SQLRecognizer sqlRecognizer, T rs = null; try { rs = executor.execute(args); - } catch (Throwable ex) { if (!(ex instanceof SQLException)) { // Turn other exception into SQLException diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/Executor.java b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/Executor.java index 44fcb067449..c4ef3bbb3a7 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/Executor.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/Executor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/InsertExecutor.java b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/InsertExecutor.java index 8c3bd438a90..9668fe62332 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/InsertExecutor.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/InsertExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; import io.seata.common.exception.NotSupportYetException; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/LockConflictException.java b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/LockConflictException.java index 935125625ed..40e983528f5 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/LockConflictException.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/LockConflictException.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; import java.sql.SQLException; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/LockRetryController.java b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/LockRetryController.java index 70fc63ffe49..99bc5c95082 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/LockRetryController.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/LockRetryController.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; import io.seata.config.ConfigurationFactory; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/LockWaitTimeoutException.java b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/LockWaitTimeoutException.java index 01c207eda15..a6e859231a2 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/LockWaitTimeoutException.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/LockWaitTimeoutException.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; import java.sql.SQLException; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/PlainExecutor.java b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/PlainExecutor.java index 30507af7cbd..c859f6f3031 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/PlainExecutor.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/PlainExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; import java.sql.Statement; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/SelectForUpdateExecutor.java b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/SelectForUpdateExecutor.java index 8d0916933d8..8e42aa7e4ff 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/SelectForUpdateExecutor.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/SelectForUpdateExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; import java.sql.Connection; @@ -38,7 +37,7 @@ * * @param the type parameter */ -public class SelectForUpdateExecutor extends BaseTransactionalExecutor { +public class SelectForUpdateExecutor extends BaseTransactionalExecutor { /** * Instantiates a new Select for update executor. @@ -47,17 +46,17 @@ public class SelectForUpdateExecutor extends BaseTransactio * @param statementCallback the statement callback * @param sqlRecognizer the sql recognizer */ - public SelectForUpdateExecutor(StatementProxy statementProxy, StatementCallback statementCallback, + public SelectForUpdateExecutor(StatementProxy statementProxy, StatementCallback statementCallback, SQLRecognizer sqlRecognizer) { super(statementProxy, statementCallback, sqlRecognizer); } @Override - public Object doExecute(Object... args) throws Throwable { + public T doExecute(Object... args) throws Throwable { SQLSelectRecognizer recognizer = (SQLSelectRecognizer)sqlRecognizer; Connection conn = statementProxy.getConnection(); - ResultSet rs = null; + T rs = null; Savepoint sp = null; LockRetryController lockRetryController = new LockRetryController(); boolean originalAutoCommit = conn.getAutoCommit(); @@ -83,6 +82,9 @@ public Object doExecute(Object... args) throws Throwable { conn.setAutoCommit(false); } sp = conn.setSavepoint(); + // #870 + // execute return Boolean + // executeQuery return ResultSet rs = statementCallback.execute(statementProxy.getTargetStatement(), args); while (true) { @@ -104,6 +106,9 @@ public Object doExecute(Object... args) throws Throwable { TableRecords selectPKRows = TableRecords.buildRecords(getTableMeta(), rsPK); String lockKeys = buildLockKey(selectPKRows); + if (StringUtils.isNullOrEmpty(lockKeys)) { + break; + } if (RootContext.inGlobalTransaction()) { //do as usual diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/StatementCallback.java b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/StatementCallback.java index d7e00ded0d8..208bf69ab20 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/StatementCallback.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/StatementCallback.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; import java.sql.SQLException; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/UpdateExecutor.java b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/UpdateExecutor.java index df532267281..068ede397b0 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/exec/UpdateExecutor.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/exec/UpdateExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; import java.sql.PreparedStatement; @@ -142,7 +141,7 @@ protected TableRecords afterImage(TableRecords beforeImage) throws SQLException } List pkRows = beforeImage.pkRows(); selectSQLAppender.append( - " FROM " + getFromTableInSQL() + " WHERE " + buildWhereConditionByPKs(pkRows) + " FOR UPDATE"); + " FROM " + getFromTableInSQL() + " WHERE " + buildWhereConditionByPKs(pkRows)); String selectSQL = selectSQLAppender.toString(); TableRecords afterImage = null; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLDeleteRecognizer.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLDeleteRecognizer.java index 51f620e3642..d4b2a2749cd 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLDeleteRecognizer.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLDeleteRecognizer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLInsertRecognizer.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLInsertRecognizer.java index c50a0b85f95..e1b6fe732ef 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLInsertRecognizer.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLInsertRecognizer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql; import java.util.List; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLParsingException.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLParsingException.java index 29342d6c0ae..e93dbadc8eb 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLParsingException.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLParsingException.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLRecognizer.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLRecognizer.java index f192a2d25e5..96da504d07f 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLRecognizer.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLRecognizer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLSelectRecognizer.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLSelectRecognizer.java index c99b8725b98..7e82c742013 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLSelectRecognizer.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLSelectRecognizer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLType.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLType.java index 5f247ec5655..4fdb9d35c9d 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLType.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLType.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLUpdateRecognizer.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLUpdateRecognizer.java index 21a1200195b..05b94765029 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLUpdateRecognizer.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLUpdateRecognizer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql; import java.util.List; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLVisitorFactory.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLVisitorFactory.java index 8dc9dfa5de9..097ae19a041 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLVisitorFactory.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/SQLVisitorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql; -import java.util.List; - import com.alibaba.druid.sql.SQLUtils; import com.alibaba.druid.sql.ast.SQLStatement; import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement; @@ -29,10 +26,8 @@ import io.seata.rm.datasource.sql.druid.MySQLInsertRecognizer; import io.seata.rm.datasource.sql.druid.MySQLSelectForUpdateRecognizer; import io.seata.rm.datasource.sql.druid.MySQLUpdateRecognizer; -import io.seata.rm.datasource.sql.druid.MySQLDeleteRecognizer; -import io.seata.rm.datasource.sql.druid.MySQLInsertRecognizer; -import io.seata.rm.datasource.sql.druid.MySQLSelectForUpdateRecognizer; -import io.seata.rm.datasource.sql.druid.MySQLUpdateRecognizer; + +import java.util.List; /** * The type Sql visitor factory. @@ -63,7 +58,7 @@ public static SQLRecognizer get(String sql, String dbType) { } else if (ast instanceof SQLDeleteStatement) { recognizer = new MySQLDeleteRecognizer(sql, ast); } else if (ast instanceof SQLSelectStatement) { - if (((SQLSelectStatement)ast).getSelect().getQueryBlock().isForUpdate()) { + if (((SQLSelectStatement) ast).getSelect().getFirstQueryBlock().isForUpdate()) { recognizer = new MySQLSelectForUpdateRecognizer(sql, ast); } } diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/WhereRecognizer.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/WhereRecognizer.java index f9e29338086..be6537bfe12 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/WhereRecognizer.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/WhereRecognizer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql; import java.util.ArrayList; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/BaseRecognizer.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/BaseRecognizer.java index 752d502c687..cab1399691f 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/BaseRecognizer.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/BaseRecognizer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.druid; import io.seata.rm.datasource.sql.SQLRecognizer; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLDeleteRecognizer.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLDeleteRecognizer.java index e1578dbcc1e..801e5683750 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLDeleteRecognizer.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLDeleteRecognizer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.druid; import java.util.ArrayList; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLInsertRecognizer.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLInsertRecognizer.java index 052f4a1bc23..f80d8331d91 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLInsertRecognizer.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLInsertRecognizer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.druid; import java.util.ArrayList; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLSelectForUpdateRecognizer.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLSelectForUpdateRecognizer.java index 8510605c00d..2adff88564f 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLSelectForUpdateRecognizer.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLSelectForUpdateRecognizer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.druid; import java.util.ArrayList; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLUpdateRecognizer.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLUpdateRecognizer.java index 9324c8c6d19..6d3a8c34ea9 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLUpdateRecognizer.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/druid/MySQLUpdateRecognizer.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.druid; import java.util.ArrayList; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/ColumnMeta.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/ColumnMeta.java index fcd017e117d..8da1e9d47b3 100755 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/ColumnMeta.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/ColumnMeta.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.struct; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/Field.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/Field.java index 810f92dbf2b..fa798d215f4 100755 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/Field.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/Field.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.struct; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/IndexMeta.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/IndexMeta.java index c73d9ac362e..83135582181 100755 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/IndexMeta.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/IndexMeta.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.struct; import java.util.ArrayList; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/IndexType.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/IndexType.java index 350e857c2a4..378aca21598 100755 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/IndexType.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/IndexType.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.struct; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/KeyType.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/KeyType.java index 1cc680027c2..530ba44185e 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/KeyType.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/KeyType.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.struct; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/Null.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/Null.java index 99ebe77cc23..8890dc2acb9 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/Null.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/Null.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.struct; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/Row.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/Row.java index b7afc40c3b3..33fbc256302 100755 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/Row.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/Row.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.struct; import java.util.ArrayList; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableMeta.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableMeta.java index 7050d647127..7f4d3d6be31 100755 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableMeta.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableMeta.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.struct; import java.util.ArrayList; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableMetaCache.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableMetaCache.java index 27f0b8d1a08..ff87d6c9ba6 100755 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableMetaCache.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableMetaCache.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.struct; import java.sql.Connection; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableRecords.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableRecords.java index c2ffc8d20ab..6bd17138240 100755 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableRecords.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableRecords.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.struct; import java.sql.ResultSet; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/AbstractUndoExecutor.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/AbstractUndoExecutor.java index ec6ad989c5e..a4a52b30012 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/AbstractUndoExecutor.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/AbstractUndoExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo; import java.sql.Connection; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/BranchUndoLog.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/BranchUndoLog.java index 9140a0fd3d1..aacfb19f302 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/BranchUndoLog.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/BranchUndoLog.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo; import java.util.List; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/JSONBasedUndoLogParser.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/JSONBasedUndoLogParser.java index 1e946c631c0..d4c3c5f3429 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/JSONBasedUndoLogParser.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/JSONBasedUndoLogParser.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo; import com.alibaba.fastjson.JSON; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/KeywordChecker.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/KeywordChecker.java index 371a6fd901f..a556a0b11f2 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/KeywordChecker.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/KeywordChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/KeywordCheckerFactory.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/KeywordCheckerFactory.java index 8fa6d2d277c..eec41816bc5 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/KeywordCheckerFactory.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/KeywordCheckerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo; import com.alibaba.druid.util.JdbcConstants; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/SQLUndoLog.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/SQLUndoLog.java index e2be4a75b81..3800bc7691a 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/SQLUndoLog.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/SQLUndoLog.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo; import io.seata.rm.datasource.sql.SQLType; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoExecutorFactory.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoExecutorFactory.java index 7ffa61d49ff..7bf2292c9c2 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoExecutorFactory.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoExecutorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo; import com.alibaba.druid.util.JdbcConstants; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogManager.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogManager.java index 489a90872cb..ab278f2e71f 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogManager.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,16 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo; -import java.sql.Blob; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.SQLIntegrityConstraintViolationException; - import com.alibaba.druid.util.JdbcConstants; import io.seata.common.exception.NotSupportYetException; import io.seata.common.util.BlobUtils; @@ -33,10 +25,17 @@ import io.seata.rm.datasource.DataSourceProxy; import io.seata.rm.datasource.sql.struct.TableMeta; import io.seata.rm.datasource.sql.struct.TableMetaCache; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.sql.Blob; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLIntegrityConstraintViolationException; +import java.util.Set; + import static io.seata.core.exception.TransactionExceptionCode.BranchRollbackFailed_Retriable; /** @@ -45,6 +44,7 @@ * @author sharajava */ public final class UndoLogManager { + private enum State { /** * This state can be properly rolled back by services @@ -74,6 +74,7 @@ public int getValue() { private static String INSERT_UNDO_LOG_SQL = "INSERT INTO " + UNDO_LOG_TABLE_NAME + "\n" + "\t(branch_id, xid, rollback_info, log_status, log_created, log_modified)\n" + "VALUES (?, ?, ?, ?, now(), now())"; + private static String DELETE_UNDO_LOG_SQL = "DELETE FROM " + UNDO_LOG_TABLE_NAME + "\n" + "\tWHERE branch_id = ? AND xid = ?"; @@ -228,6 +229,68 @@ public static void undo(DataSourceProxy dataSourceProxy, String xid, long branch } } + /** + * batch Delete undo log. + * + * @param xids + * @param branchIds + * @param limitSize + * @param conn + */ + public static void batchDeleteUndoLog(Set xids, Set branchIds, int limitSize, Connection conn) throws SQLException { + int xidSize = xids.size(); + int branchIdSize = branchIds.size(); + String batchDeleteSql = toBatchDeleteUndoLogSql(xidSize, branchIdSize,limitSize); + PreparedStatement deletePST = null; + try { + deletePST = conn.prepareStatement(batchDeleteSql); + int paramsIndex = 1; + for (Long branchId : branchIds) { + deletePST.setLong(paramsIndex++,branchId); + } + for (String xid: xids){ + deletePST.setString(paramsIndex++, xid); + } + int deleteRows = deletePST.executeUpdate(); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("batch delete undo log size " + deleteRows); + } + }catch (Exception e){ + if (!(e instanceof SQLException)) { + e = new SQLException(e); + } + throw (SQLException) e; + } finally { + if (deletePST != null) { + deletePST.close(); + } + } + + } + + protected static String toBatchDeleteUndoLogSql(int xidSize, int branchIdSize,int limitSize) { + StringBuilder sqlBuilder = new StringBuilder(); + sqlBuilder.append("DELETE FROM ") + .append(UNDO_LOG_TABLE_NAME) + .append(" WHERE branch_id IN "); + appendInParam(xidSize, sqlBuilder); + sqlBuilder.append(" AND xid IN "); + appendInParam(branchIdSize, sqlBuilder); + sqlBuilder.append(" LIMIT ").append(limitSize); + return sqlBuilder.toString(); + } + + protected static void appendInParam(int size, StringBuilder sqlBuilder) { + sqlBuilder.append(" ("); + for (int i = 0;i < size;i++) { + sqlBuilder.append("?"); + if (i < (size - 1)) { + sqlBuilder.append(","); + } + } + sqlBuilder.append(") "); + } + /** * Delete undo log. * @@ -237,10 +300,22 @@ public static void undo(DataSourceProxy dataSourceProxy, String xid, long branch * @throws SQLException the sql exception */ public static void deleteUndoLog(String xid, long branchId, Connection conn) throws SQLException { - PreparedStatement deletePST = conn.prepareStatement(DELETE_UNDO_LOG_SQL); - deletePST.setLong(1, branchId); - deletePST.setString(2, xid); - deletePST.executeUpdate(); + PreparedStatement deletePST = null; + try { + deletePST = conn.prepareStatement(DELETE_UNDO_LOG_SQL); + deletePST.setLong(1, branchId); + deletePST.setString(2, xid); + deletePST.executeUpdate(); + }catch (Exception e){ + if (!(e instanceof SQLException)) { + e = new SQLException(e); + } + throw (SQLException) e; + } finally { + if (deletePST != null) { + deletePST.close(); + } + } } private static void insertUndoLogWithNormal(String xid, long branchID, @@ -264,11 +339,10 @@ private static void insertUndoLog(String xid, long branchID, pst.setInt(4, state.getValue()); pst.executeUpdate(); } catch (Exception e) { - if (e instanceof SQLException) { - throw (SQLException)e; - } else { - throw new SQLException(e); + if (!(e instanceof SQLException)) { + e = new SQLException(e); } + throw (SQLException) e; } finally { if (pst != null) { pst.close(); diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogParser.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogParser.java index 406a29390dd..90ef9a6930c 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogParser.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogParser.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogParserFactory.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogParserFactory.java index 564ca210045..1a1c9d128c4 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogParserFactory.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogParserFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo; /** diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/MySQLUndoDeleteExecutor.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/MySQLUndoDeleteExecutor.java index 513a8cb0407..c13bbc52e33 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/MySQLUndoDeleteExecutor.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/MySQLUndoDeleteExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo.mysql; import java.util.List; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/MySQLUndoInsertExecutor.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/MySQLUndoInsertExecutor.java index c454ed99857..9975b137b24 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/MySQLUndoInsertExecutor.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/MySQLUndoInsertExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo.mysql; import java.sql.PreparedStatement; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/MySQLUndoUpdateExecutor.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/MySQLUndoUpdateExecutor.java index be29c32bef4..a7398fe9cec 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/MySQLUndoUpdateExecutor.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/MySQLUndoUpdateExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo.mysql; import java.util.List; diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/keyword/MySQLKeywordChecker.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/keyword/MySQLKeywordChecker.java index 27c3922e030..82f1de1820d 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/keyword/MySQLKeywordChecker.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/keyword/MySQLKeywordChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo.mysql.keyword; import io.seata.rm.datasource.undo.KeywordChecker; diff --git a/rm-datasource/src/test/java/io/seata/rm/GlobalLockLocalTransactionlTemplateTest.java b/rm-datasource/src/test/java/io/seata/rm/GlobalLockLocalTransactionlTemplateTest.java index 10c2335759d..d7fafa850a7 100644 --- a/rm-datasource/src/test/java/io/seata/rm/GlobalLockLocalTransactionlTemplateTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/GlobalLockLocalTransactionlTemplateTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm; import java.util.concurrent.Callable; diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/SQLVisitorFactoryTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/SQLVisitorFactoryTest.java index 5ceefd4e7ca..a9899938d20 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/SQLVisitorFactoryTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/SQLVisitorFactoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource; import com.alibaba.druid.util.JdbcConstants; diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/exec/BaseTransactionalExecutorTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/exec/BaseTransactionalExecutorTest.java index 9f7bc702fad..9c45bae1943 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/exec/BaseTransactionalExecutorTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/exec/BaseTransactionalExecutorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.exec; import java.sql.Statement; diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/exec/InsertExecutorTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/exec/InsertExecutorTest.java index 70bd5cc1497..fac24ca1784 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/exec/InsertExecutorTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/exec/InsertExecutorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/AbstractMySQLRecognizerTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/AbstractMySQLRecognizerTest.java index 97e2c3c9daa..1f429757564 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/AbstractMySQLRecognizerTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/AbstractMySQLRecognizerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.druid; import java.util.List; diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLDeleteRecognizerTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLDeleteRecognizerTest.java index 02710436725..606bcb8f4ca 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLDeleteRecognizerTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLDeleteRecognizerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.druid; import java.util.ArrayList; diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLInsertRecognizerTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLInsertRecognizerTest.java index 432e3b93781..dfbdc42bd7d 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLInsertRecognizerTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLInsertRecognizerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.druid; import java.util.Arrays; diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLSelectForUpdateRecognizerTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLSelectForUpdateRecognizerTest.java index 6f0d93fd094..58973e24ea5 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLSelectForUpdateRecognizerTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLSelectForUpdateRecognizerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.druid; import java.util.ArrayList; diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLUpdateRecognizerTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLUpdateRecognizerTest.java index 76d10e723a8..b73b1a3f72b 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLUpdateRecognizerTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/sql/druid/MySQLUpdateRecognizerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.druid; import java.util.ArrayList; diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/sql/struct/TableMetaTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/sql/struct/TableMetaTest.java index 319a859b08b..3353cfd2625 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/sql/struct/TableMetaTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/sql/struct/TableMetaTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.sql.struct; import java.sql.Connection; @@ -276,7 +275,7 @@ public boolean allTablesAreSelectable() throws SQLException { @Override public String getURL() throws SQLException { - return null; + return getUrl(); } @Override diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/undo/BranchUndoLogTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/undo/BranchUndoLogTest.java index 9044ad77e0c..3a26d32559e 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/undo/BranchUndoLogTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/undo/BranchUndoLogTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo; import java.sql.Types; diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoExecutorTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoExecutorTest.java index e9a08c3de5d..f026b467758 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoExecutorTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoExecutorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo; import java.io.InputStream; diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoLogManagerTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoLogManagerTest.java new file mode 100644 index 00000000000..8b06aaa158f --- /dev/null +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoLogManagerTest.java @@ -0,0 +1,91 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.rm.datasource.undo; + +import org.junit.Test; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * @author guoyao + * @date 2019/4/19 + */ +public class UndoLogManagerTest { + + + private static final int APPEND_IN_SIZE = 10; + + private static final int LIMIT_SIZE = 10; + + private static final String THE_APPEND_IN_SIZE_PARAM_String = " (?,?,?,?,?,?,?,?,?,?) "; + + @Test + public void testBatchDeleteUndoLog() throws Exception { + Set xids = new HashSet<>(); + for (int i = 0;i < APPEND_IN_SIZE;i++){ + xids.add(UUID.randomUUID().toString()); + } + Set branchIds = new HashSet<>(); + for (int i = 0;i < APPEND_IN_SIZE;i++){ + branchIds.add(Long.valueOf(i)); + } + Connection connection = mock(Connection.class); + PreparedStatement preparedStatement = mock(PreparedStatement.class); + when(connection.prepareStatement(anyString())).thenReturn(preparedStatement); + UndoLogManager.batchDeleteUndoLog(xids, branchIds, LIMIT_SIZE, connection); + + //verify + for (int i = 1;i <= APPEND_IN_SIZE;i++){ + verify(preparedStatement).setLong(eq(i),anyLong()); + } + for (int i = APPEND_IN_SIZE + 1;i <= APPEND_IN_SIZE * 2;i++){ + verify(preparedStatement).setString(eq(i),anyString()); + } + verify(preparedStatement).executeUpdate(); + } + + @Test + public void testToBatchDeleteUndoLogSql() { + String expectedSqlString="DELETE FROM undo_log WHERE branch_id IN " + + THE_APPEND_IN_SIZE_PARAM_String + + " AND xid IN " + + THE_APPEND_IN_SIZE_PARAM_String + + " LIMIT " + LIMIT_SIZE; + String batchDeleteUndoLogSql = UndoLogManager.toBatchDeleteUndoLogSql(APPEND_IN_SIZE, APPEND_IN_SIZE, LIMIT_SIZE); + System.out.println(batchDeleteUndoLogSql); + assertThat(batchDeleteUndoLogSql).isEqualTo(expectedSqlString); + } + + @Test + public void testAppendInParam() { + StringBuilder sqlBuilder = new StringBuilder(); + UndoLogManager.appendInParam(APPEND_IN_SIZE, sqlBuilder); + assertThat(sqlBuilder.toString()).isEqualTo(THE_APPEND_IN_SIZE_PARAM_String); + } + +} diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/undo/mysql/keyword/MySQLKeywordCheckerTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/undo/mysql/keyword/MySQLKeywordCheckerTest.java index e3ff5686a9a..df410d62c5a 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/undo/mysql/keyword/MySQLKeywordCheckerTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/undo/mysql/keyword/MySQLKeywordCheckerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.datasource.undo.mysql.keyword; import java.sql.Types; diff --git a/rm/src/main/java/io/seata/rm/AbstractRMHandler.java b/rm/src/main/java/io/seata/rm/AbstractRMHandler.java index 12af4d37586..fa7f929f53b 100644 --- a/rm/src/main/java/io/seata/rm/AbstractRMHandler.java +++ b/rm/src/main/java/io/seata/rm/AbstractRMHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm; import io.seata.common.exception.ShouldNeverHappenException; diff --git a/rm/src/main/java/io/seata/rm/AbstractResourceManager.java b/rm/src/main/java/io/seata/rm/AbstractResourceManager.java index 9fa9ac7ad8d..6ff5f048ad7 100644 --- a/rm/src/main/java/io/seata/rm/AbstractResourceManager.java +++ b/rm/src/main/java/io/seata/rm/AbstractResourceManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm; import java.util.concurrent.TimeoutException; diff --git a/rm/src/main/java/io/seata/rm/DefaultRMHandler.java b/rm/src/main/java/io/seata/rm/DefaultRMHandler.java index 6747edead33..133ef233ad0 100644 --- a/rm/src/main/java/io/seata/rm/DefaultRMHandler.java +++ b/rm/src/main/java/io/seata/rm/DefaultRMHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm; import io.seata.common.exception.FrameworkException; diff --git a/rm/src/main/java/io/seata/rm/DefaultResourceManager.java b/rm/src/main/java/io/seata/rm/DefaultResourceManager.java index 7621cdb3fd0..c09e79846c1 100644 --- a/rm/src/main/java/io/seata/rm/DefaultResourceManager.java +++ b/rm/src/main/java/io/seata/rm/DefaultResourceManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm; import java.util.HashMap; diff --git a/rm/src/main/java/io/seata/rm/RMClient.java b/rm/src/main/java/io/seata/rm/RMClient.java index e6216b9be68..71c2f6c53e0 100644 --- a/rm/src/main/java/io/seata/rm/RMClient.java +++ b/rm/src/main/java/io/seata/rm/RMClient.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm; import io.seata.core.rpc.netty.RmMessageListener; diff --git a/server/src/main/java/io/seata/server/AbstractTCInboundHandler.java b/server/src/main/java/io/seata/server/AbstractTCInboundHandler.java index 93949bc0ee0..7a1d9722928 100644 --- a/server/src/main/java/io/seata/server/AbstractTCInboundHandler.java +++ b/server/src/main/java/io/seata/server/AbstractTCInboundHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server; import io.seata.core.exception.AbstractExceptionHandler; diff --git a/server/src/main/java/io/seata/server/Server.java b/server/src/main/java/io/seata/server/Server.java index 2f02e099bf8..a636e84d348 100644 --- a/server/src/main/java/io/seata/server/Server.java +++ b/server/src/main/java/io/seata/server/Server.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server; import java.io.IOException; @@ -25,6 +24,7 @@ import io.seata.common.thread.NamedThreadFactory; import io.seata.common.util.NetUtil; import io.seata.core.rpc.netty.RpcServer; +import io.seata.core.rpc.netty.ShutdownHook; import io.seata.server.coordinator.DefaultCoordinator; import io.seata.server.session.SessionHolder; @@ -39,6 +39,7 @@ public class Server { private static final int MAX_SERVER_POOL_SIZE = 500; private static final int MAX_TASK_QUEUE_SIZE = 20000; private static final int KEEP_ALIVE_TIME = 500; + private static final int SERVER_DEFAULT_PORT = 8091; private static final ThreadPoolExecutor WORKING_THREADS = new ThreadPoolExecutor(MIN_SERVER_POOL_SIZE, MAX_SERVER_POOL_SIZE, KEEP_ALIVE_TIME, TimeUnit.SECONDS, new LinkedBlockingQueue(MAX_TASK_QUEUE_SIZE), @@ -53,10 +54,7 @@ public class Server { public static void main(String[] args) throws IOException { RpcServer rpcServer = new RpcServer(WORKING_THREADS); - int port = 8091; - if (args.length == 0) { - rpcServer.setListenPort(port); - } + int port = SERVER_DEFAULT_PORT; //server port if (args.length > 0) { try { @@ -65,8 +63,8 @@ public static void main(String[] args) throws IOException { System.err.println("Usage: sh services-server.sh $LISTEN_PORT $PATH_FOR_PERSISTENT_DATA"); System.exit(0); } - rpcServer.setListenPort(port); } + rpcServer.setListenPort(port); //log store mode : file、db String storeMode = null; @@ -77,7 +75,9 @@ public static void main(String[] args) throws IOException { DefaultCoordinator coordinator = new DefaultCoordinator(rpcServer); coordinator.init(); - rpcServer.setHandler(new DefaultCoordinator(rpcServer)); + rpcServer.setHandler(coordinator); + // register ShutdownHook + ShutdownHook.getInstance().addDisposable(coordinator); UUIDGenerator.init(1); diff --git a/server/src/main/java/io/seata/server/UUIDGenerator.java b/server/src/main/java/io/seata/server/UUIDGenerator.java index 22e52b168cc..becbe0e1f4e 100644 --- a/server/src/main/java/io/seata/server/UUIDGenerator.java +++ b/server/src/main/java/io/seata/server/UUIDGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server; import java.text.ParseException; diff --git a/server/src/main/java/io/seata/server/coordinator/Core.java b/server/src/main/java/io/seata/server/coordinator/Core.java index 1615856d004..7d34dfee101 100644 --- a/server/src/main/java/io/seata/server/coordinator/Core.java +++ b/server/src/main/java/io/seata/server/coordinator/Core.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.coordinator; import io.seata.core.exception.TransactionException; diff --git a/server/src/main/java/io/seata/server/coordinator/CoreFactory.java b/server/src/main/java/io/seata/server/coordinator/CoreFactory.java index 887688aa7c9..19e09f70eb7 100644 --- a/server/src/main/java/io/seata/server/coordinator/CoreFactory.java +++ b/server/src/main/java/io/seata/server/coordinator/CoreFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.coordinator; /** diff --git a/server/src/main/java/io/seata/server/coordinator/DefaultCoordinator.java b/server/src/main/java/io/seata/server/coordinator/DefaultCoordinator.java index 78839d3d0f9..d98388ea66b 100644 --- a/server/src/main/java/io/seata/server/coordinator/DefaultCoordinator.java +++ b/server/src/main/java/io/seata/server/coordinator/DefaultCoordinator.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.coordinator; import java.io.IOException; @@ -51,9 +50,11 @@ import io.seata.core.protocol.transaction.GlobalRollbackResponse; import io.seata.core.protocol.transaction.GlobalStatusRequest; import io.seata.core.protocol.transaction.GlobalStatusResponse; +import io.seata.core.rpc.Disposable; import io.seata.core.rpc.RpcContext; import io.seata.core.rpc.ServerMessageSender; import io.seata.core.rpc.TransactionMessageHandler; +import io.seata.core.rpc.netty.RpcServer; import io.seata.server.AbstractTCInboundHandler; import io.seata.server.session.BranchSession; import io.seata.server.session.GlobalSession; @@ -71,10 +72,12 @@ * @author sharajava */ public class DefaultCoordinator extends AbstractTCInboundHandler - implements TransactionMessageHandler, ResourceManagerInbound { + implements TransactionMessageHandler, ResourceManagerInbound, Disposable { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultCoordinator.class); + private static final int TIMED_TASK_SHUTDOWN_MAX_WAIT_MILLS = 5000; + private ServerMessageSender messageSender; private Core core = CoreFactory.get(); @@ -202,13 +205,17 @@ private void timeoutCheck() throws TransactionException { LOGGER.debug(globalSession.getTransactionId() + " " + globalSession.getStatus() + " " + globalSession.getBeginTime() + " " + globalSession.getTimeout()); } - - if (globalSession.getStatus() != GlobalStatus.Begin || !globalSession.isTimeout()) { + boolean shouldTimeout = globalSession.lockAndExcute(() -> { + if (globalSession.getStatus() != GlobalStatus.Begin || !globalSession.isTimeout()) { + return false; + } + globalSession.close(); + globalSession.changeStatus(GlobalStatus.TimeoutRollbacking); + return true; + }); + if (!shouldTimeout) { continue; } - - globalSession.close(); - globalSession.changeStatus(GlobalStatus.TimeoutRollbacking); LOGGER.info( "Global transaction[" + globalSession.getTransactionId() + "] is timeout and will be rolled back."); @@ -323,7 +330,6 @@ public void run() { } }, 0, 2, TimeUnit.MILLISECONDS); - } @Override @@ -344,4 +350,27 @@ public void onResponse(AbstractResultMessage response, RpcContext context) { } } + + @Override + public void destroy() { + // 1. first shutdown timed task + retryRollbacking.shutdown(); + retryCommitting.shutdown(); + asyncCommitting.shutdown(); + timeoutCheck.shutdown(); + try { + retryRollbacking.awaitTermination(TIMED_TASK_SHUTDOWN_MAX_WAIT_MILLS, TimeUnit.MILLISECONDS); + retryCommitting.awaitTermination(TIMED_TASK_SHUTDOWN_MAX_WAIT_MILLS, TimeUnit.MILLISECONDS); + asyncCommitting.awaitTermination(TIMED_TASK_SHUTDOWN_MAX_WAIT_MILLS, TimeUnit.MILLISECONDS); + timeoutCheck.awaitTermination(TIMED_TASK_SHUTDOWN_MAX_WAIT_MILLS, TimeUnit.MILLISECONDS); + } catch (InterruptedException ingore) { + + } + // 2. sencond close netty flow + if (messageSender instanceof RpcServer){ + ((RpcServer) messageSender).destroy(); + } + // 3. last destory SessionHolder + SessionHolder.destory(); + } } diff --git a/server/src/main/java/io/seata/server/coordinator/DefaultCore.java b/server/src/main/java/io/seata/server/coordinator/DefaultCore.java index 5a99b815993..1ba36763f1f 100644 --- a/server/src/main/java/io/seata/server/coordinator/DefaultCore.java +++ b/server/src/main/java/io/seata/server/coordinator/DefaultCore.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.coordinator; import io.seata.common.XID; @@ -29,7 +28,6 @@ import io.seata.server.session.GlobalSession; import io.seata.server.session.SessionHelper; import io.seata.server.session.SessionHolder; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,46 +58,42 @@ public void setResourceManagerInbound(ResourceManagerInbound resourceManagerInbo @Override public Long branchRegister(BranchType branchType, String resourceId, String clientId, String xid, String applicationData, String lockKeys) throws TransactionException { - GlobalSession globalSession = assertGlobalSession(XID.getTransactionId(xid), GlobalStatus.Begin); - - BranchSession branchSession = SessionHelper.newBranchByGlobal(globalSession, branchType, resourceId, - applicationData, lockKeys, clientId); - - if (!branchSession.lock()) { - throw new TransactionException(LockKeyConflict); - } - try { - globalSession.addBranch(branchSession); - } catch (RuntimeException ex) { - throw new TransactionException(FailedToAddBranch); - - } - return branchSession.getBranchId(); + GlobalSession globalSession = assertGlobalSessionNotNull(XID.getTransactionId(xid)); + return globalSession.lockAndExcute(() -> { + if (!globalSession.isActive()) { + throw new TransactionException(GlobalTransactionNotActive, "Current Status: " + globalSession.getStatus()); + } + if (globalSession.getStatus() != GlobalStatus.Begin) { + throw new TransactionException(GlobalTransactionStatusInvalid, + globalSession.getStatus() + " while expecting " + GlobalStatus.Begin); + } + BranchSession branchSession = SessionHelper.newBranchByGlobal(globalSession, branchType, resourceId, + applicationData, lockKeys, clientId); + if (!branchSession.lock()) { + throw new TransactionException(LockKeyConflict); + } + try { + globalSession.addBranch(branchSession); + } catch (RuntimeException ex) { + throw new TransactionException(FailedToAddBranch); + } + return branchSession.getBranchId(); + }); } - private GlobalSession assertGlobalSession(long transactionId, GlobalStatus status) throws TransactionException { + private GlobalSession assertGlobalSessionNotNull(long transactionId) throws TransactionException { GlobalSession globalSession = SessionHolder.findGlobalSession(transactionId); if (globalSession == null) { throw new TransactionException(TransactionExceptionCode.GlobalTransactionNotExist, "" + transactionId + ""); } - if (!globalSession.isActive()) { - throw new TransactionException(GlobalTransactionNotActive, "Current Status: " + globalSession.getStatus()); - } - if (globalSession.getStatus() != status) { - throw new TransactionException(GlobalTransactionStatusInvalid, - globalSession.getStatus() + " while expecting " + status); - } return globalSession; } + @Override public void branchReport(BranchType branchType, String xid, long branchId, BranchStatus status, String applicationData) throws TransactionException { - GlobalSession globalSession = SessionHolder.findGlobalSession(XID.getTransactionId(xid)); - if (globalSession == null) { - throw new TransactionException(TransactionExceptionCode.GlobalTransactionNotExist, - "" + XID.getTransactionId(xid) + ""); - } + GlobalSession globalSession = assertGlobalSessionNotNull(XID.getTransactionId(xid)); BranchSession branchSession = globalSession.getBranch(branchId); if (branchSession == null) { throw new TransactionException(BranchTransactionNotExist); @@ -136,18 +130,23 @@ public GlobalStatus commit(String xid) throws TransactionException { if (globalSession == null) { return GlobalStatus.Finished; } - GlobalStatus status = globalSession.getStatus(); - - globalSession.closeAndClean(); // Highlight: Firstly, close the session, then no more branch can be registered. - - if (status == GlobalStatus.Begin) { - globalSession.changeStatus(GlobalStatus.Committing); - if (globalSession.canBeCommittedAsync()) { - asyncCommit(globalSession); - } else { - doGlobalCommit(globalSession, false); + // just lock changeStatus + boolean shouldCommit = globalSession.lockAndExcute(() -> { + globalSession.closeAndClean(); // Highlight: Firstly, close the session, then no more branch can be registered. + if (globalSession.getStatus() == GlobalStatus.Begin) { + globalSession.changeStatus(GlobalStatus.Committing); + return true; } - + return false; + }); + if (!shouldCommit){ + return globalSession.getStatus(); + } + if (globalSession.canBeCommittedAsync()) { + asyncCommit(globalSession); + return GlobalStatus.Committed; + } else { + doGlobalCommit(globalSession, false); } return globalSession.getStatus(); } @@ -243,15 +242,20 @@ public GlobalStatus rollback(String xid) throws TransactionException { if (globalSession == null) { return GlobalStatus.Finished; } - GlobalStatus status = globalSession.getStatus(); - - globalSession.close(); // Highlight: Firstly, close the session, then no more branch can be registered. - - if (status == GlobalStatus.Begin) { - globalSession.changeStatus(GlobalStatus.Rollbacking); - doGlobalRollback(globalSession, false); - + // just lock changeStatus + boolean shouldRollBack = globalSession.lockAndExcute(() -> { + globalSession.close(); // Highlight: Firstly, close the session, then no more branch can be registered. + if (globalSession.getStatus() == GlobalStatus.Begin) { + globalSession.changeStatus(GlobalStatus.Rollbacking); + return true; + } + return false; + }); + if (!shouldRollBack){ + return globalSession.getStatus(); } + + doGlobalRollback(globalSession, false); return globalSession.getStatus(); } diff --git a/server/src/main/java/io/seata/server/lock/DefaultLockManagerImpl.java b/server/src/main/java/io/seata/server/lock/DefaultLockManagerImpl.java index 81bc9c53c7a..1807ff1ec32 100644 --- a/server/src/main/java/io/seata/server/lock/DefaultLockManagerImpl.java +++ b/server/src/main/java/io/seata/server/lock/DefaultLockManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,20 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.lock; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import io.netty.util.internal.ConcurrentSet; import io.seata.common.exception.ShouldNeverHappenException; import io.seata.common.util.StringUtils; import io.seata.core.exception.TransactionException; import io.seata.server.session.BranchSession; - -import io.netty.util.internal.ConcurrentSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -154,4 +154,31 @@ public boolean isLockable(long transactionId, String resourceId, String lockKey) public void cleanAllLocks() throws TransactionException { LOCK_MAP.clear(); } + + @Override + public boolean releaseLock(BranchSession branchSession) throws TransactionException { + ConcurrentHashMap, Set> lockHolder = branchSession.getLockHolder(); + if (lockHolder.size() == 0) { + return true; + } + Iterator, Set>> it = lockHolder.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry, Set> entry = it.next(); + Map bucket = entry.getKey(); + Set keys = entry.getValue(); + synchronized (bucket) { + for (String key : keys) { + Long v = bucket.get(key); + if (v == null) { + continue; + } + if (v.longValue() == branchSession.getTransactionId()) { + bucket.remove(key); + } + } + } + } + lockHolder.clear(); + return true; + } } diff --git a/server/src/main/java/io/seata/server/lock/LockManager.java b/server/src/main/java/io/seata/server/lock/LockManager.java index dd84c4aa58c..54bcef3c0b4 100644 --- a/server/src/main/java/io/seata/server/lock/LockManager.java +++ b/server/src/main/java/io/seata/server/lock/LockManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.lock; import io.seata.core.exception.TransactionException; @@ -52,4 +51,13 @@ public interface LockManager { * @throws TransactionException the transaction exception */ void cleanAllLocks() throws TransactionException; + + /** + * Release lock boolean. + * + * @param branchSession the branch session + * @return the boolean + * @throws TransactionException the transaction exception + */ + boolean releaseLock(BranchSession branchSession) throws TransactionException; } diff --git a/server/src/main/java/io/seata/server/lock/LockManagerFactory.java b/server/src/main/java/io/seata/server/lock/LockManagerFactory.java index 29f07b91639..3468cc89449 100644 --- a/server/src/main/java/io/seata/server/lock/LockManagerFactory.java +++ b/server/src/main/java/io/seata/server/lock/LockManagerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.lock; /** diff --git a/server/src/main/java/io/seata/server/session/AbstractSessionManager.java b/server/src/main/java/io/seata/server/session/AbstractSessionManager.java index 14632055f3b..f124b010254 100644 --- a/server/src/main/java/io/seata/server/session/AbstractSessionManager.java +++ b/server/src/main/java/io/seata/server/session/AbstractSessionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,24 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.session; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - import io.seata.core.exception.TransactionException; +import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.BranchStatus; import io.seata.core.model.GlobalStatus; +import io.seata.server.store.SessionStorable; import io.seata.server.store.TransactionStoreManager; import io.seata.server.store.TransactionStoreManager.LogOperation; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + /** * The type Abstract session manager. * @@ -72,11 +72,13 @@ public void addGlobalSession(GlobalSession session) throws TransactionException if (LOGGER.isDebugEnabled()) { LOGGER.debug("MANAGER[" + name + "] SESSION[" + session + "] " + LogOperation.GLOBAL_ADD); } - transactionStoreManager.writeSession(LogOperation.GLOBAL_ADD, session); + writeSession(LogOperation.GLOBAL_ADD, session); sessionMap.put(session.getTransactionId(), session); } + + @Override public GlobalSession findGlobalSession(Long transactionId) throws TransactionException { return sessionMap.get(transactionId); @@ -87,7 +89,7 @@ public void updateGlobalSessionStatus(GlobalSession session, GlobalStatus status if (LOGGER.isDebugEnabled()) { LOGGER.debug("MANAGER[" + name + "] SESSION[" + session + "] " + LogOperation.GLOBAL_UPDATE); } - transactionStoreManager.writeSession(LogOperation.GLOBAL_UPDATE, session); + writeSession(LogOperation.GLOBAL_UPDATE, session); } @Override @@ -95,7 +97,7 @@ public void removeGlobalSession(GlobalSession session) throws TransactionExcepti if (LOGGER.isDebugEnabled()) { LOGGER.debug("MANAGER[" + name + "] SESSION[" + session + "] " + LogOperation.GLOBAL_REMOVE); } - transactionStoreManager.writeSession(LogOperation.GLOBAL_REMOVE, session); + writeSession(LogOperation.GLOBAL_REMOVE, session); sessionMap.remove(session.getTransactionId()); } @@ -105,7 +107,7 @@ public void addBranchSession(GlobalSession session, BranchSession branchSession) if (LOGGER.isDebugEnabled()) { LOGGER.debug("MANAGER[" + name + "] SESSION[" + branchSession + "] " + LogOperation.BRANCH_ADD); } - transactionStoreManager.writeSession(LogOperation.BRANCH_ADD, branchSession); + writeSession(LogOperation.BRANCH_ADD, branchSession); } @Override @@ -114,8 +116,7 @@ public void updateBranchSessionStatus(BranchSession branchSession, BranchStatus if (LOGGER.isDebugEnabled()) { LOGGER.debug("MANAGER[" + name + "] SESSION[" + branchSession + "] " + LogOperation.GLOBAL_ADD); } - transactionStoreManager.writeSession(LogOperation.BRANCH_UPDATE, branchSession); - + writeSession(LogOperation.BRANCH_UPDATE, branchSession); } @Override @@ -124,7 +125,7 @@ public void removeBranchSession(GlobalSession globalSession, BranchSession branc if (LOGGER.isDebugEnabled()) { LOGGER.debug("MANAGER[" + name + "] SESSION[" + branchSession + "] " + LogOperation.GLOBAL_ADD); } - transactionStoreManager.writeSession(LogOperation.BRANCH_REMOVE, branchSession); + writeSession(LogOperation.BRANCH_REMOVE, branchSession); } @@ -137,11 +138,9 @@ public Collection allSessions() { public List findGlobalSessions(SessionCondition condition) { List found = new ArrayList<>(); for (GlobalSession globalSession : sessionMap.values()) { - if (globalSession.getStatus() == condition.getStatus()) { if (System.currentTimeMillis() - globalSession.getBeginTime() > condition.getOverTimeAliveMills()) { found.add(globalSession); } - } } return found; } @@ -183,4 +182,10 @@ public void onEnd(GlobalSession globalSession) throws TransactionException { removeGlobalSession(globalSession); } + + private void writeSession(LogOperation logOperation, SessionStorable sessionStorable) throws TransactionException{ + if (!transactionStoreManager.writeSession(logOperation, sessionStorable)) { + throw new TransactionException(TransactionExceptionCode.FailedWriteSession); + } + } } diff --git a/server/src/main/java/io/seata/server/session/BranchSession.java b/server/src/main/java/io/seata/server/session/BranchSession.java index 806f797d5e4..31e51961235 100644 --- a/server/src/main/java/io/seata/server/session/BranchSession.java +++ b/server/src/main/java/io/seata/server/session/BranchSession.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.session; import java.io.IOException; import java.nio.ByteBuffer; -import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -42,10 +40,10 @@ public class BranchSession implements Lockable, Comparable, Sessi private static final Logger LOGGER = LoggerFactory.getLogger(BranchSession.class); - private static final int MAX_BRANCH_SESSION_SIZE = StoreConfig.getMaxBranchSessionSize(); + private static final int MAX_BRANCH_SESSION_SIZE = StoreConfig.getMaxBranchSessionSize(); private static ThreadLocal byteBufferThreadLocal = ThreadLocal.withInitial(() -> ByteBuffer.allocate( - MAX_BRANCH_SESSION_SIZE)); + MAX_BRANCH_SESSION_SIZE)); private long transactionId; @@ -256,28 +254,7 @@ public boolean lock() throws TransactionException { @Override public boolean unlock() throws TransactionException { - if (lockHolder.size() == 0) { - return true; - } - Iterator, Set>> it = lockHolder.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry, Set> entry = it.next(); - Map bucket = entry.getKey(); - Set keys = entry.getValue(); - synchronized (bucket) { - for (String key : keys) { - Long v = bucket.get(key); - if (v == null) { - continue; - } - if (v.longValue() == getTransactionId()) { - bucket.remove(key); - } - } - } - } - lockHolder.clear(); - return true; + return LockManagerFactory.get().releaseLock(this); } @Override @@ -293,23 +270,25 @@ public byte[] encode() { int size = calBranchSessionSize(resourceIdBytes, lockKeyBytes, clientIdBytes, applicationDataBytes); - - if (size > MAX_BRANCH_SESSION_SIZE){ - if (lockKeyBytes == null){ - throw new RuntimeException("branch session size exceeded, size : " + size + " maxBranchSessionSize : " + MAX_BRANCH_SESSION_SIZE); + if (size > MAX_BRANCH_SESSION_SIZE) { + if (lockKeyBytes == null) { + throw new RuntimeException("branch session size exceeded, size : " + size + " maxBranchSessionSize : " + + MAX_BRANCH_SESSION_SIZE); } // try compress lockkey try { size -= lockKeyBytes.length; lockKeyBytes = CompressUtil.compress(lockKeyBytes); - }catch (IOException e){ + } catch (IOException e) { LOGGER.error("compress lockKey error", e); - }finally { + } finally { size += lockKeyBytes.length; } - if (size > MAX_BRANCH_SESSION_SIZE){ - throw new RuntimeException("compress branch session size exceeded, compressSize : " + size + " maxBranchSessionSize : " + MAX_BRANCH_SESSION_SIZE); + if (size > MAX_BRANCH_SESSION_SIZE) { + throw new RuntimeException( + "compress branch session size exceeded, compressSize : " + size + " maxBranchSessionSize : " + + MAX_BRANCH_SESSION_SIZE); } } @@ -317,7 +296,6 @@ public byte[] encode() { //recycle byteBuffer.clear(); - byteBuffer.putLong(transactionId); byteBuffer.putLong(branchId); @@ -359,16 +337,16 @@ public byte[] encode() { private int calBranchSessionSize(byte[] resourceIdBytes, byte[] lockKeyBytes, byte[] clientIdBytes, byte[] applicationDataBytes) { final int size = 8 // trascationId - + 8 // branchId - + 4 // resourceIdBytes.length - + 4 // lockKeyBytes.length - + 2 // clientIdBytes.length - + 4 // applicationDataBytes.length - + 1 // statusCode - + (resourceIdBytes == null ? 0 : resourceIdBytes.length) - + (lockKeyBytes == null ? 0 : lockKeyBytes.length) - + (clientIdBytes == null ? 0 : clientIdBytes.length) - + (applicationDataBytes == null ? 0 : applicationDataBytes.length); + + 8 // branchId + + 4 // resourceIdBytes.length + + 4 // lockKeyBytes.length + + 2 // clientIdBytes.length + + 4 // applicationDataBytes.length + + 1 // statusCode + + (resourceIdBytes == null ? 0 : resourceIdBytes.length) + + (lockKeyBytes == null ? 0 : lockKeyBytes.length) + + (clientIdBytes == null ? 0 : clientIdBytes.length) + + (applicationDataBytes == null ? 0 : applicationDataBytes.length); return size; } @@ -387,13 +365,13 @@ public void decode(byte[] a) { if (lockKeyLen > 0) { byte[] byLockKey = new byte[lockKeyLen]; byteBuffer.get(byLockKey); - if (CompressUtil.isCompressData(byLockKey)){ + if (CompressUtil.isCompressData(byLockKey)) { try { this.lockKey = new String(CompressUtil.uncompress(byLockKey)); - }catch (IOException e){ + } catch (IOException e) { throw new RuntimeException("uncompress lockKey error", e); } - }else { + } else { this.lockKey = new String(byLockKey); } diff --git a/server/src/main/java/io/seata/server/session/DefaultSessionManager.java b/server/src/main/java/io/seata/server/session/DefaultSessionManager.java index eea75466b0a..ff24f7f6bba 100644 --- a/server/src/main/java/io/seata/server/session/DefaultSessionManager.java +++ b/server/src/main/java/io/seata/server/session/DefaultSessionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.session; import java.util.List; @@ -39,7 +38,7 @@ public DefaultSessionManager(String name) { transactionStoreManager = new TransactionStoreManager() { @Override public boolean writeSession(LogOperation logOperation, SessionStorable session) { - return false; + return true; } @Override @@ -58,4 +57,9 @@ public boolean hasRemaining(boolean isHistory) { } }; } + + @Override + public void destroy() { + transactionStoreManager.shutdown(); + } } diff --git a/server/src/main/java/io/seata/server/session/FileBasedSessionManager.java b/server/src/main/java/io/seata/server/session/FileBasedSessionManager.java index 693bac311ee..1cf82df345a 100644 --- a/server/src/main/java/io/seata/server/session/FileBasedSessionManager.java +++ b/server/src/main/java/io/seata/server/session/FileBasedSessionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.session; import java.io.File; @@ -200,4 +199,9 @@ private void restore(List stores, Map branchSessions = new ArrayList<>(); + private GlobalSessionSpinLock globalSessionSpinLock = new GlobalSessionSpinLock(); + /** * Add boolean. * @@ -347,6 +351,7 @@ public long getBeginTime() { return beginTime; } + /** * Create global session global session. * @@ -420,15 +425,15 @@ public byte[] encode() { private int calGlobalSessionSize(byte[] byApplicationIdBytes, byte[] byServiceGroupBytes, byte[] byTxNameBytes) { final int size = 8 // trascationId - + 4 // timeout - + 2 // byApplicationIdBytes.length - + 2 // byServiceGroupBytes.length - + 2 // byTxNameBytes.length - + 8 // beginTime - + 1 // statusCode - + (byApplicationIdBytes == null ? 0 : byApplicationIdBytes.length) - + (byServiceGroupBytes == null ? 0 : byServiceGroupBytes.length) - + (byTxNameBytes == null ? 0 : byTxNameBytes.length); + + 4 // timeout + + 2 // byApplicationIdBytes.length + + 2 // byServiceGroupBytes.length + + 2 // byTxNameBytes.length + + 8 // beginTime + + 1 // statusCode + + (byApplicationIdBytes == null ? 0 : byApplicationIdBytes.length) + + (byServiceGroupBytes == null ? 0 : byServiceGroupBytes.length) + + (byTxNameBytes == null ? 0 : byTxNameBytes.length); return size; } @@ -467,4 +472,85 @@ public void decode(byte[] a) { public boolean hasBranch() { return branchSessions.size() > 0; } + + public void lock() throws TransactionException { + globalSessionSpinLock.lock(); + } + + public void unlock(){ + globalSessionSpinLock.unlock(); + } + + public void lockAndExcute(LockRunnable excuteRunnable) throws TransactionException{ + this.lock(); + try { + excuteRunnable.run(); + }finally { + this.unlock(); + } + } + + public T lockAndExcute(LockCallable lockCallable) throws TransactionException{ + this.lock(); + try { + return lockCallable.call(); + }finally { + this.unlock(); + } + } + /** + * globalsession is low race conditions, so use spinlock + */ + private class GlobalSessionSpinLock{ + /** + * true: Can lock, false : in lock. + */ + private AtomicBoolean globalSessionSpinLock = new AtomicBoolean(true); + + private static final int GLOBAL_SESSOION_LOCK_TIME_OUT_MILLS = 2 * 1000; + + private static final int PARK_TIMES_BASE = 10; + + private static final int PARK_TIMES_BASE_NANOS = 1 * 1000 * 1000; + + public void lock() throws TransactionException { + boolean flag; + int times = 0; + long beginTime = System.currentTimeMillis(); + long restTime = GLOBAL_SESSOION_LOCK_TIME_OUT_MILLS ; + do { + restTime -= (System.currentTimeMillis() - beginTime); + if (restTime <= 0){ + throw new TransactionException(TransactionExceptionCode.FailedLockGlobalTranscation); + } + // Pause every PARK_TIMES_BASE times,yield the CPU + if (times % PARK_TIMES_BASE == 0){ + // Exponential Backoff + long backOffTime = PARK_TIMES_BASE_NANOS << (times/PARK_TIMES_BASE); + long parkTime = backOffTime < restTime ? backOffTime : restTime; + LockSupport.parkNanos(parkTime); + } + flag = this.globalSessionSpinLock.compareAndSet(true, false); + times++; + } + while (!flag); + } + + + public void unlock() { + this.globalSessionSpinLock.compareAndSet(false, true); + } + + } + + @FunctionalInterface + public interface LockRunnable { + + void run() throws TransactionException; + } + @FunctionalInterface + public interface LockCallable { + + V call() throws TransactionException; + } } diff --git a/server/src/main/java/io/seata/server/session/Lockable.java b/server/src/main/java/io/seata/server/session/Lockable.java index 5e3ffb281cc..d023e632f85 100644 --- a/server/src/main/java/io/seata/server/session/Lockable.java +++ b/server/src/main/java/io/seata/server/session/Lockable.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.session; import io.seata.core.exception.TransactionException; diff --git a/server/src/main/java/io/seata/server/session/Reloadable.java b/server/src/main/java/io/seata/server/session/Reloadable.java index a34467ecd50..5701c69d6ae 100644 --- a/server/src/main/java/io/seata/server/session/Reloadable.java +++ b/server/src/main/java/io/seata/server/session/Reloadable.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.session; /** diff --git a/server/src/main/java/io/seata/server/session/SessionCondition.java b/server/src/main/java/io/seata/server/session/SessionCondition.java index 72d68ce4be3..6d04dd3616d 100644 --- a/server/src/main/java/io/seata/server/session/SessionCondition.java +++ b/server/src/main/java/io/seata/server/session/SessionCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.session; import io.seata.core.model.GlobalStatus; +import java.util.Set; + /** * The type Session condition. * @@ -25,37 +26,18 @@ * @date 2018 /12/13 */ public class SessionCondition { - private GlobalStatus status; + private long overTimeAliveMills; /** * Instantiates a new Session condition. * - * @param status the status * @param overTimeAliveMills the over time alive mills */ - public SessionCondition(GlobalStatus status, long overTimeAliveMills) { - this.status = status; + public SessionCondition( long overTimeAliveMills) { this.overTimeAliveMills = overTimeAliveMills; } - /** - * Gets status. - * - * @return the status - */ - public GlobalStatus getStatus() { - return status; - } - - /** - * Sets status. - * - * @param status the status - */ - public void setStatus(GlobalStatus status) { - this.status = status; - } /** * Gets over time alive mills. diff --git a/server/src/main/java/io/seata/server/session/SessionHelper.java b/server/src/main/java/io/seata/server/session/SessionHelper.java index f738d4d6db6..b3295d24e8f 100644 --- a/server/src/main/java/io/seata/server/session/SessionHelper.java +++ b/server/src/main/java/io/seata/server/session/SessionHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.session; import io.seata.core.exception.TransactionException; diff --git a/server/src/main/java/io/seata/server/session/SessionHolder.java b/server/src/main/java/io/seata/server/session/SessionHolder.java index a62662e423a..151512ffbce 100644 --- a/server/src/main/java/io/seata/server/session/SessionHolder.java +++ b/server/src/main/java/io/seata/server/session/SessionHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.session; import java.io.IOException; @@ -235,4 +234,11 @@ public static final SessionManager getRetryRollbackingSessionManager() { public static GlobalSession findGlobalSession(Long transactionId) throws TransactionException { return getRootSessionManager().findGlobalSession(transactionId); } + + public static void destory() { + ROOT_SESSION_MANAGER.destroy(); + ASYNC_COMMITTING_SESSION_MANAGER.destroy(); + RETRY_COMMITTING_SESSION_MANAGER.destroy(); + RETRY_ROLLBACKING_SESSION_MANAGER.destroy(); + } } diff --git a/server/src/main/java/io/seata/server/session/SessionLifecycle.java b/server/src/main/java/io/seata/server/session/SessionLifecycle.java index 22d82f366a2..9c46a2fd737 100644 --- a/server/src/main/java/io/seata/server/session/SessionLifecycle.java +++ b/server/src/main/java/io/seata/server/session/SessionLifecycle.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.session; import io.seata.core.exception.TransactionException; diff --git a/server/src/main/java/io/seata/server/session/SessionLifecycleListener.java b/server/src/main/java/io/seata/server/session/SessionLifecycleListener.java index d3a46032965..54c415e92e3 100644 --- a/server/src/main/java/io/seata/server/session/SessionLifecycleListener.java +++ b/server/src/main/java/io/seata/server/session/SessionLifecycleListener.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.session; import io.seata.core.exception.TransactionException; diff --git a/server/src/main/java/io/seata/server/session/SessionManager.java b/server/src/main/java/io/seata/server/session/SessionManager.java index b4ab08798ee..621b2011681 100644 --- a/server/src/main/java/io/seata/server/session/SessionManager.java +++ b/server/src/main/java/io/seata/server/session/SessionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.session; import java.util.Collection; @@ -22,13 +21,14 @@ import io.seata.core.exception.TransactionException; import io.seata.core.model.BranchStatus; import io.seata.core.model.GlobalStatus; +import io.seata.core.rpc.Disposable; /** * The interface Session manager. * * @author sharajava */ -public interface SessionManager extends SessionLifecycleListener { +public interface SessionManager extends SessionLifecycleListener, Disposable { /** * Add global session. diff --git a/server/src/main/java/io/seata/server/store/FileTransactionStoreManager.java b/server/src/main/java/io/seata/server/store/FileTransactionStoreManager.java index 8a8f7f5c797..6f9f0b286d1 100644 --- a/server/src/main/java/io/seata/server/store/FileTransactionStoreManager.java +++ b/server/src/main/java/io/seata/server/store/FileTransactionStoreManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.store; +import io.seata.common.thread.NamedThreadFactory; +import io.seata.common.util.CollectionUtils; +import io.seata.server.session.BranchSession; +import io.seata.server.session.GlobalSession; +import io.seata.server.session.SessionCondition; +import io.seata.server.session.SessionManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; @@ -25,22 +33,9 @@ import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicLong; - -import io.seata.common.thread.NamedThreadFactory; -import io.seata.core.model.GlobalStatus; -import io.seata.server.session.BranchSession; -import io.seata.server.session.GlobalSession; -import io.seata.server.session.SessionCondition; -import io.seata.server.session.SessionManager; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.concurrent.locks.ReentrantLock; /** * The type File transaction store manager. @@ -48,38 +43,73 @@ * @author jimin.jm @alibaba-inc.com */ public class FileTransactionStoreManager implements TransactionStoreManager { + private static final Logger LOGGER = LoggerFactory.getLogger(FileTransactionStoreManager.class); - private BlockingQueue transactionWriteFutureQueue - = new LinkedBlockingQueue(); - private static final long MAX_ENQUEUE_MILLS = 5 * 1000; + private static final int MAX_THREAD_WRITE = 1; + private ExecutorService fileWriteExecutor; + private volatile boolean stopping = false; + private static final int MAX_SHUTDOWN_RETRY = 3; + private static final int SHUTDOWN_CHECK_INTERNAL = 1 * 1000; + private static final int MAX_WRITE_RETRY = 5; + private static final String HIS_DATA_FILENAME_POSTFIX = ".1"; + private static final AtomicLong FILE_TRX_NUM = new AtomicLong(0); + private static final AtomicLong FILE_FLUSH_NUM = new AtomicLong(0); + private static final int MARK_SIZE = 4; - private static final int MAX_POOL_TIME_MILLS = 2 * 1000; + + private static final int MAX_WAIT_TIME_MILLS = 2 * 1000; + private static final int MAX_FLUSH_TIME_MILLS = 2 * 1000; + private static final int MAX_FLUSH_NUM = 10; + private static int PER_FILE_BLOCK_SIZE = 65535 * 8; + private static long MAX_TRX_TIMEOUT_MILLS = 30 * 60 * 1000; + private static volatile long trxStartTimeMills = System.currentTimeMillis(); - private static final boolean ENABLE_SCHEDULE_FLUSH = true; + private File currDataFile; + private RandomAccessFile currRaf; + private FileChannel currFileChannel; + private long recoverCurrOffset = 0; + private long recoverHisOffset = 0; + private SessionManager sessionManager; + private String currFullFileName; + private String hisFullFileName; + private WriteDataFileRunnable writeDataFileRunnable; + + private ReentrantLock writeSessionLock = new ReentrantLock(); + + private volatile long lastModifiedTime; + private static final int MAX_WRITE_BUFFER_SIZE = StoreConfig.getFileWriteBufferCacheSize(); + private final ByteBuffer writeBuffer = ByteBuffer.allocateDirect(MAX_WRITE_BUFFER_SIZE); + + private static final FlushDiskMode FLUSH_DISK_MODE = StoreConfig.getFlushDiskMode(); + + private static final int MAX_WAIT_FOR_FLUSH_TIME_MILLS = 2 * 1000; + + private static final int INT_BYTE_SIZE = 4; + /** * Instantiates a new File transaction store manager. * @@ -89,10 +119,12 @@ public class FileTransactionStoreManager implements TransactionStoreManager { */ public FileTransactionStoreManager(String fullFileName, SessionManager sessionManager) throws IOException { initFile(fullFileName); - fileWriteExecutor = new ThreadPoolExecutor(MAX_THREAD_WRITE, MAX_THREAD_WRITE, - Integer.MAX_VALUE, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), - new NamedThreadFactory("fileTransactionStore", MAX_THREAD_WRITE, true)); - fileWriteExecutor.submit(new WriteDataFileRunnable()); + fileWriteExecutor = + new ThreadPoolExecutor(MAX_THREAD_WRITE, MAX_THREAD_WRITE, Integer.MAX_VALUE, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue(), + new NamedThreadFactory("fileTransactionStore", MAX_THREAD_WRITE, true)); + writeDataFileRunnable = new WriteDataFileRunnable(); + fileWriteExecutor.submit(writeDataFileRunnable); this.sessionManager = sessionManager; } @@ -111,6 +143,7 @@ private void initFile(String fullFileName) throws IOException { } else { trxStartTimeMills = currDataFile.lastModified(); } + lastModifiedTime = System.currentTimeMillis(); currRaf = new RandomAccessFile(currDataFile, "rw"); currRaf.seek(currDataFile.length()); currFileChannel = currRaf.getChannel(); @@ -122,13 +155,94 @@ private void initFile(String fullFileName) throws IOException { @Override public boolean writeSession(LogOperation logOperation, SessionStorable session) { - TransactionWriteFuture writeFutureRequest = new TransactionWriteFuture(session, logOperation); + writeSessionLock.lock(); + long curFileTrxNum; + try { + if (!writeDataFile(new TransactionWriteStore(session, logOperation).encode())) { + return false; + } + lastModifiedTime = System.currentTimeMillis(); + curFileTrxNum = FILE_TRX_NUM.incrementAndGet(); + if (curFileTrxNum % PER_FILE_BLOCK_SIZE == 0 && + (System.currentTimeMillis() - trxStartTimeMills) > MAX_TRX_TIMEOUT_MILLS) { + return saveHistory(); + } + } catch (Exception exx) { + LOGGER.error("writeSession error," + exx.getMessage()); + return false; + } finally { + writeSessionLock.unlock(); + } + flushDisk(curFileTrxNum, currFileChannel); + return true; + } + + private void flushDisk(long curFileNum, FileChannel currFileChannel) { + + if (FLUSH_DISK_MODE == FlushDiskMode.SYNC_MODEL) { + SyncFlushRequest syncFlushRequest = new SyncFlushRequest(curFileNum, currFileChannel); + writeDataFileRunnable.putRequest(syncFlushRequest); + syncFlushRequest.waitForFlush(MAX_WAIT_FOR_FLUSH_TIME_MILLS); + } else { + writeDataFileRunnable.putRequest(new AsyncFlushRequest(curFileNum, currFileChannel)); + } + } + + /** + * get all overTimeSessionStorables + * merge write file + * + * @throws IOException + */ + private boolean saveHistory() throws IOException { + boolean result; try { - if (transactionWriteFutureQueue.offer(writeFutureRequest, MAX_ENQUEUE_MILLS, TimeUnit.MILLISECONDS)) { - return writeFutureRequest.get(); + result = findTimeoutAndSave(); + writeDataFileRunnable.putRequest(new CloseFileRequest(currFileChannel, currRaf)); + Files.move(currDataFile.toPath(), new File(hisFullFileName).toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException exx) { + LOGGER.error("save history data file error," + exx.getMessage()); + result = false; + } finally { + initFile(currFullFileName); + } + return result; + } + + private boolean findTimeoutAndSave() throws IOException { + List globalSessionsOverMaxTimeout = + sessionManager.findGlobalSessions(new SessionCondition(MAX_TRX_TIMEOUT_MILLS)); + if (CollectionUtils.isEmpty(globalSessionsOverMaxTimeout)) { + return true; + } + List listBytes = new ArrayList<>(); + int totalSize = 0; + // 1. find all data and merge + for (GlobalSession globalSession : globalSessionsOverMaxTimeout) { + TransactionWriteStore globalWriteStore = new TransactionWriteStore(globalSession, LogOperation.GLOBAL_ADD); + byte[] data = globalWriteStore.encode(); + listBytes.add(data); + totalSize += data.length + INT_BYTE_SIZE; + List branchSessIonsOverMaXTimeout = globalSession.getSortedBranches(); + if (null != branchSessIonsOverMaXTimeout) { + for (BranchSession branchSession : branchSessIonsOverMaXTimeout) { + TransactionWriteStore branchWriteStore = + new TransactionWriteStore(branchSession, LogOperation.BRANCH_ADD); + data = branchWriteStore.encode(); + listBytes.add(data); + totalSize += data.length + INT_BYTE_SIZE; + } } - } catch (InterruptedException exx) { - LOGGER.error("write data file error," + exx.getMessage()); + } + // 2. batch write + ByteBuffer byteBuffer = ByteBuffer.allocateDirect(totalSize); + for (byte[] bytes : listBytes) { + byteBuffer.putInt(bytes.length); + byteBuffer.put(bytes); + } + if (writeDataFileByBuffer(byteBuffer)) { + currFileChannel.force(false); + return true; } return false; } @@ -143,12 +257,19 @@ public void shutdown() { ++retry; try { Thread.sleep(SHUTDOWN_CHECK_INTERNAL); - } catch (InterruptedException exx) {} + } catch (InterruptedException exx) { + } } if (retry >= MAX_SHUTDOWN_RETRY) { fileWriteExecutor.shutdownNow(); } } + try { + currFileChannel.force(true); + } catch (IOException e) { + LOGGER.error("filechannel force error", e); + } + closeFile(currRaf); } @Override @@ -206,13 +327,17 @@ private List parseDataFile(File file, int readSize, long try { buffSize.clear(); int avilReadSize = fileChannel.read(buffSize); - if (avilReadSize != MARK_SIZE) { break; } + if (avilReadSize != MARK_SIZE) { + break; + } buffSize.flip(); int bodySize = buffSize.getInt(); byte[] byBody = new byte[bodySize]; ByteBuffer buffBody = ByteBuffer.wrap(byBody); avilReadSize = fileChannel.read(buffBody); - if (avilReadSize != bodySize) { break; } + if (avilReadSize != bodySize) { + break; + } TransactionWriteStore writeStore = new TransactionWriteStore(); writeStore.decode(byBody); transactionWriteStores.add(writeStore); @@ -261,132 +386,205 @@ private void closeFile(RandomAccessFile raf) { } } + private boolean writeDataFile(byte[] bs) { + if (bs == null) { + return false; + } + ByteBuffer byteBuffer = null; + + if (bs.length > MAX_WRITE_BUFFER_SIZE) { + //allocateNew + byteBuffer = ByteBuffer.allocateDirect(bs.length); + } else { + byteBuffer = writeBuffer; + //recycle + byteBuffer.clear(); + } + + byteBuffer.putInt(bs.length); + byteBuffer.put(bs); + return writeDataFileByBuffer(byteBuffer); + } + + private boolean writeDataFileByBuffer(ByteBuffer byteBuffer) { + for (int retry = 0; retry < MAX_WRITE_RETRY; retry++) { + try { + byteBuffer.flip(); + while (byteBuffer.hasRemaining()) { + currFileChannel.write(byteBuffer); + } + return true; + } catch (IOException exx) { + LOGGER.error("write data file error:" + exx.getMessage()); + } + } + LOGGER.error("write dataFile failed,retry more than :" + MAX_WRITE_RETRY); + return false; + } + + interface StoreRequest { + + } + abstract class AbstractFlushRequest implements StoreRequest{ + private final long curFileTrxNum; + + private final FileChannel curFileChannel; + + protected AbstractFlushRequest(long curFileTrxNum, FileChannel curFileChannel) { + this.curFileTrxNum = curFileTrxNum; + this.curFileChannel = curFileChannel; + } + public long getCurFileTrxNum() { + return curFileTrxNum; + } + + public FileChannel getCurFileChannel() { + return curFileChannel; + } + } + class SyncFlushRequest extends AbstractFlushRequest { + + private final CountDownLatch countDownLatch = new CountDownLatch(1); + + public SyncFlushRequest(long curFileTrxNum, FileChannel curFileChannel) { + super(curFileTrxNum, curFileChannel); + } + + + public void wakeupCustomer() { + this.countDownLatch.countDown(); + } + + public void waitForFlush(long timeout) { + try { + this.countDownLatch.await(timeout, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + LOGGER.error("Interrupted", e); + } + } + } + + class AsyncFlushRequest extends AbstractFlushRequest { + + public AsyncFlushRequest(long curFileTrxNum, FileChannel curFileChannel) { + super(curFileTrxNum, curFileChannel); + } + + } + + class CloseFileRequest implements StoreRequest { + + private FileChannel fileChannel; + + private RandomAccessFile file; + + public CloseFileRequest(FileChannel fileChannel, RandomAccessFile file) { + this.fileChannel = fileChannel; + this.file = file; + } + + public FileChannel getFileChannel() { + return fileChannel; + } + + public RandomAccessFile getFile() { + return file; + } + } + /** * The type Write data file runnable. */ class WriteDataFileRunnable implements Runnable { + private LinkedBlockingQueue storeRequests = new LinkedBlockingQueue<>(); + + + public void putRequest(final StoreRequest request) { + storeRequests.add(request); + } - ByteBuffer wireteBuffer = ByteBuffer.allocateDirect(MAX_WRITE_BUFFER_SIZE); @Override public void run() { while (!stopping) { - TransactionWriteFuture transactionWriteFuture = null; try { - transactionWriteFuture = transactionWriteFutureQueue.poll( - MAX_POOL_TIME_MILLS, - TimeUnit.MILLISECONDS); - if (null == transactionWriteFuture) { - flushOnCondition(); - continue; - } - if (transactionWriteFuture.isTimeout()) { - transactionWriteFuture.setResult(Boolean.FALSE); - continue; - } - if (writeDataFile(transactionWriteFuture.getWriteStore().encode())) { - transactionWriteFuture.setResult(Boolean.TRUE); - FILE_TRX_NUM.incrementAndGet(); - flushOnCondition(); - } else { - transactionWriteFuture.setResult(Boolean.FALSE); - } - if (FILE_TRX_NUM.get() % PER_FILE_BLOCK_SIZE == 0 - && (System.currentTimeMillis() - trxStartTimeMills) > MAX_TRX_TIMEOUT_MILLS) { - saveHistory(); - } - } catch (InterruptedException exx) { - stopping = true; + StoreRequest storeRequest = storeRequests.poll(MAX_WAIT_TIME_MILLS, TimeUnit.MILLISECONDS); + handleStoreRequest(storeRequest); } catch (Exception exx) { - LOGGER.error(exx.getMessage()); - if (transactionWriteFuture != null){ - // fast fail - transactionWriteFuture.setResult(Boolean.FALSE); - } + LOGGER.error("write file error", exx.getMessage()); } } + handleRestRequest(); + } + /** + * handle the rest requests when stopping is true + */ + private void handleRestRequest() { + int remainNums = storeRequests.size(); + for (int i = 0; i < remainNums; i++) { + handleStoreRequest(storeRequests.poll()); + } } - private boolean writeDataFile(byte[] bs) { - int retry = 0; - if (bs == null){ - return false; + private void handleStoreRequest(StoreRequest storeRequest) { + if (storeRequest == null){ + flushOnCondition(currFileChannel); } - ByteBuffer byteBuffer = null; - - if (bs.length > MAX_WRITE_BUFFER_SIZE){ - //allocateNew - byteBuffer = ByteBuffer.allocateDirect(bs.length); - }else { - byteBuffer = wireteBuffer; - //recycle - byteBuffer.clear(); + if (storeRequest instanceof SyncFlushRequest) { + syncFlush((SyncFlushRequest) storeRequest); + } else if (storeRequest instanceof AsyncFlushRequest) { + async((AsyncFlushRequest) storeRequest); + } else if (storeRequest instanceof CloseFileRequest) { + closeAndFlush((CloseFileRequest) storeRequest); } + } - byteBuffer.putInt(bs.length); - byteBuffer.put(bs); - for (; retry < MAX_WRITE_RETRY; retry++) { - try { - byteBuffer.flip(); - while (byteBuffer.hasRemaining()) { - currFileChannel.write(byteBuffer); - } - return true; - } catch (IOException exx) { - LOGGER.error("write data file error:" + exx.getMessage()); - } + private void closeAndFlush(CloseFileRequest req) { + long diff = FILE_TRX_NUM.get() - FILE_FLUSH_NUM.get(); + flush(req.getFileChannel()); + FILE_FLUSH_NUM.addAndGet(diff); + closeFile(currRaf); + } + + private void async(AsyncFlushRequest req) { + if (req.getCurFileTrxNum() < FILE_FLUSH_NUM.get()) { + flushOnCondition(req.getCurFileChannel()); } - LOGGER.error("write dataFile failed,retry more than :" + MAX_WRITE_RETRY); - return false; } - private void flushOnCondition() { - if (!ENABLE_SCHEDULE_FLUSH) { return; } + private void syncFlush(SyncFlushRequest req) { + if (req.getCurFileTrxNum() < FILE_FLUSH_NUM.get()) { + long diff = FILE_TRX_NUM.get() - FILE_FLUSH_NUM.get(); + flush(req.getCurFileChannel()); + FILE_FLUSH_NUM.addAndGet(diff); + } + // notify + req.wakeupCustomer(); + } + + private void flushOnCondition(FileChannel fileChannel) { + if (FLUSH_DISK_MODE == FlushDiskMode.SYNC_MODEL) { + return; + } long diff = FILE_TRX_NUM.get() - FILE_FLUSH_NUM.get(); - if (diff == 0) { return; } - if (diff % MAX_FLUSH_NUM == 0 - || System.currentTimeMillis() - currDataFile.lastModified() > MAX_FLUSH_TIME_MILLS) { - try { - currFileChannel.force(false); - } catch (IOException exx) { - LOGGER.error("flush error:" + exx.getMessage()); - } + if (diff == 0) { + return; + } + if (diff % MAX_FLUSH_NUM == 0 || + System.currentTimeMillis() - lastModifiedTime > MAX_FLUSH_TIME_MILLS) { + flush(fileChannel); FILE_FLUSH_NUM.addAndGet(diff); } } - private void saveHistory() throws IOException { + private void flush(FileChannel fileChannel) { try { - List globalSessionsOverMaxTimeout = sessionManager.findGlobalSessions( - new SessionCondition( - GlobalStatus.Begin, MAX_TRX_TIMEOUT_MILLS)); - if (null != globalSessionsOverMaxTimeout) { - for (GlobalSession globalSession : globalSessionsOverMaxTimeout) { - TransactionWriteStore globalWriteStore = new TransactionWriteStore(globalSession, - LogOperation.GLOBAL_ADD); - writeDataFile(globalWriteStore.encode()); - List branchSessIonsOverMaXTimeout = globalSession.getSortedBranches(); - if (null != branchSessIonsOverMaXTimeout) { - for (BranchSession branchSession : branchSessIonsOverMaXTimeout) { - TransactionWriteStore branchWriteStore = new TransactionWriteStore(branchSession, - LogOperation.BRANCH_ADD); - writeDataFile(branchWriteStore.encode()); - } - } - } - } - currFileChannel.force(true); - closeFile(currRaf); - Files.move(currDataFile.toPath(), new File(hisFullFileName).toPath(), - StandardCopyOption.REPLACE_EXISTING); + fileChannel.force(false); } catch (IOException exx) { - LOGGER.error("save history data file error," + exx.getMessage()); - } finally { - initFile(currFullFileName); + LOGGER.error("flush error:" + exx.getMessage()); } - } } } diff --git a/server/src/main/java/io/seata/server/store/FlushDiskMode.java b/server/src/main/java/io/seata/server/store/FlushDiskMode.java new file mode 100644 index 00000000000..34f9ba33132 --- /dev/null +++ b/server/src/main/java/io/seata/server/store/FlushDiskMode.java @@ -0,0 +1,44 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.server.store; + +/** + * + * @author lizhao + */ +public enum FlushDiskMode { + /** + * sync flush disk + */ + SYNC_MODEL("sync"), + /** + * async flush disk + */ + ASYNC_MODEL("async"); + + private String modeStr; + + FlushDiskMode(String modeStr) { + this.modeStr = modeStr; + } + + public static FlushDiskMode findDiskMode(String modeStr) { + if (SYNC_MODEL.modeStr.equals(modeStr)){ + return SYNC_MODEL; + } + return ASYNC_MODEL; + } +} diff --git a/server/src/main/java/io/seata/server/store/SessionStorable.java b/server/src/main/java/io/seata/server/store/SessionStorable.java index dcf2a69cdb4..23b5dce75ef 100644 --- a/server/src/main/java/io/seata/server/store/SessionStorable.java +++ b/server/src/main/java/io/seata/server/store/SessionStorable.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.store; /** diff --git a/server/src/main/java/io/seata/server/store/StoreConfig.java b/server/src/main/java/io/seata/server/store/StoreConfig.java index b6d3352da7a..ec257d2992c 100644 --- a/server/src/main/java/io/seata/server/store/StoreConfig.java +++ b/server/src/main/java/io/seata/server/store/StoreConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import io.seata.config.ConfigurationFactory; import static io.seata.core.constants.ConfigurationKeys.STORE_FILE_PREFIX; +import static io.seata.core.constants.ConfigurationKeys.STORE_PREFIX; /** @@ -33,10 +34,10 @@ public class StoreConfig { private static final int DEFAULT_MAX_BRANCH_SESSION_SIZE = 1024 * 16; // default 512b - public static final int DEFAULT_MAX_GLOBAL_SESSION_SIZE = 512; + private static final int DEFAULT_MAX_GLOBAL_SESSION_SIZE = 512; // default 16kb - public static final int DEFAULT_WRITE_BUFFER_SIZE = 1024 * 16; + private static final int DEFAULT_WRITE_BUFFER_SIZE = 1024 * 16; public static int getMaxBranchSessionSize() { return CONFIGURATION.getInt(STORE_FILE_PREFIX + "max-branch-session-size", DEFAULT_MAX_BRANCH_SESSION_SIZE); @@ -49,4 +50,8 @@ public static int getMaxGlobalSessionSize() { public static int getFileWriteBufferCacheSize() { return CONFIGURATION.getInt(STORE_FILE_PREFIX + "file-write-buffer-cache-size", DEFAULT_WRITE_BUFFER_SIZE); } + + public static FlushDiskMode getFlushDiskMode() { + return FlushDiskMode.findDiskMode(CONFIGURATION.getConfig(STORE_PREFIX + "flush-disk-mode")); + } } \ No newline at end of file diff --git a/server/src/main/java/io/seata/server/store/TransactionStoreManager.java b/server/src/main/java/io/seata/server/store/TransactionStoreManager.java index eb41a3e6aca..665a81e66be 100644 --- a/server/src/main/java/io/seata/server/store/TransactionStoreManager.java +++ b/server/src/main/java/io/seata/server/store/TransactionStoreManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.store; import java.util.List; diff --git a/server/src/main/java/io/seata/server/store/TransactionWriteFuture.java b/server/src/main/java/io/seata/server/store/TransactionWriteFuture.java deleted file mode 100644 index 3d45c471352..00000000000 --- a/server/src/main/java/io/seata/server/store/TransactionWriteFuture.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright 1999-2018 Alibaba Group Holding Ltd. - * - * 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.seata.server.store; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * The type Transaction write future. - * - * @author jimin.jm @alibaba-inc.com - * @date 2018 /12/10 - */ -public class TransactionWriteFuture { - private static final Logger LOGGER = LoggerFactory.getLogger(TransactionWriteFuture.class); - private static final long DEFAULT_WRITE_TIMEOUT = 5 * 1000; - private final long writeId; - private long timeoutMills; - private long start = System.currentTimeMillis(); - private volatile Object result; - private final TransactionWriteStore writeStore; - private final CountDownLatch latch = new CountDownLatch(1); - private static AtomicLong NEXT_WRITE_ID = new AtomicLong(0); - - /** - * Instantiates a new Transaction write future. - * - * @param sessionRequest the session request - * @param logOperation the log operation - */ - public TransactionWriteFuture(SessionStorable sessionRequest, TransactionStoreManager.LogOperation logOperation) { - this(sessionRequest, logOperation, DEFAULT_WRITE_TIMEOUT); - } - - /** - * Instantiates a new Transaction write future. - * - * @param sessionRequest the session request - * @param logOperation the log operation - * @param timeoutMills the timeout mills - */ - public TransactionWriteFuture(SessionStorable sessionRequest, TransactionStoreManager.LogOperation logOperation, long timeoutMills) { - this.writeId = NEXT_WRITE_ID.incrementAndGet(); - this.writeStore = new TransactionWriteStore(sessionRequest, logOperation); - this.timeoutMills = timeoutMills; - } - - /** - * Is timeout boolean. - * - * @return the boolean - */ - public boolean isTimeout() { - return System.currentTimeMillis() - start > timeoutMills; - } - - /** - * Get boolean. - * - * @return the boolean - * @throws InterruptedException the interrupted exception - */ - public boolean get() throws InterruptedException { - return get(timeoutMills, TimeUnit.MILLISECONDS); - } - - /** - * Get boolean. - * - * @param timeout the timeout - * @param unit the unit - * @return the boolean - * @throws InterruptedException the interrupted exception - */ - public boolean get(long timeout, TimeUnit unit) throws InterruptedException { - this.timeoutMills = unit.toMillis(timeout); - boolean success = latch.await(timeout, unit); - if (!success) { - LOGGER.error("write file timeout,cost" + (System.currentTimeMillis() - start) + " ms"); - return false; - } - if (result instanceof Exception) { - LOGGER.error("write file error,msg:" + ((Exception)result).getMessage()); - return false; - } - - return (result instanceof Boolean) ? ((Boolean)result).booleanValue() : false; - } - - /** - * Sets result. - * - * @param result the result - */ - public void setResult(Object result) { - if (null != result) { - this.result = result; - latch.countDown(); - } - } - - /** - * Gets timeout. - * - * @return the timeout - */ - public long getTimeoutMills() { - return timeoutMills; - } - - /** - * Sets timeout. - * - * @param timeout the timeout - */ - public void setTimeoutMills(long timeout) { - this.timeoutMills = timeout; - } - - /** - * Gets write id. - * - * @return the write id - */ - public long getWriteId() { - return writeId; - } - - /** - * Gets write store. - * - * @return the write store - */ - public TransactionWriteStore getWriteStore() { - return writeStore; - } -} diff --git a/server/src/main/java/io/seata/server/store/TransactionWriteStore.java b/server/src/main/java/io/seata/server/store/TransactionWriteStore.java index 195eaffbcfa..f7ab6c5424a 100644 --- a/server/src/main/java/io/seata/server/store/TransactionWriteStore.java +++ b/server/src/main/java/io/seata/server/store/TransactionWriteStore.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.store; import java.nio.ByteBuffer; diff --git a/server/src/main/resources/file.conf b/server/src/main/resources/file.conf index 087e15781cf..dc908a344ef 100644 --- a/server/src/main/resources/file.conf +++ b/server/src/main/resources/file.conf @@ -57,6 +57,8 @@ store { file-write-buffer-cache-size = 16384 # when recover batch read size session.reload.read_size = 100 + # async, sync + flush-disk-mode = async } ## database store diff --git a/server/src/main/resources/nacos-config.txt b/server/src/main/resources/nacos-config.txt index d9fcd2ff519..254a8db09d4 100644 --- a/server/src/main/resources/nacos-config.txt +++ b/server/src/main/resources/nacos-config.txt @@ -21,8 +21,9 @@ store.file.dir=file_store/data store.file.max-branch-session-size=16384 store.file.max-global-session-size=512 store.file.file-write-buffer-cache-size=16384 +store.file.flush-disk-mode=async store.file.session.reload.read_size=100 store.db.driver_class=com.mysql.jdbc.Driver -store.db.url=jdbc:mysql://localhost:3306/fescar_demo +store.db.url=jdbc:mysql://localhost:3306/seata_demo store.db.user=user store.db.password=password \ No newline at end of file diff --git a/server/src/main/resources/registry.conf b/server/src/main/resources/registry.conf index 1aa9dfa5a6f..15677236a89 100644 --- a/server/src/main/resources/registry.conf +++ b/server/src/main/resources/registry.conf @@ -1,5 +1,5 @@ registry { - # file 、nacos 、eureka、redis、zk、consul + # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa type = "file" nacos { @@ -26,6 +26,19 @@ registry { cluster = "default" serverAddr = "127.0.0.1:8500" } + etcd3 { + cluster = "default" + serverAddr = "http://localhost:2379" + } + sofa { + serverAddr = "127.0.0.1:9603" + application = "default" + region = "DEFAULT_ZONE" + datacenter = "DefaultDataCenter" + cluster = "default" + group = "SEATA_GROUP" + addressWaitTime = "3000" + } file { name = "file.conf" } diff --git a/server/src/test/java/ServerTest.java b/server/src/test/java/ServerTest.java index 95537d314ef..0e5812ff185 100644 --- a/server/src/test/java/ServerTest.java +++ b/server/src/test/java/ServerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import io.seata.common.XID; +import io.seata.common.util.NetUtil; +import io.seata.core.rpc.netty.RpcServer; +import io.seata.server.UUIDGenerator; +import io.seata.server.coordinator.DefaultCoordinator; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import io.seata.core.rpc.netty.RpcServer; -import io.seata.server.UUIDGenerator; -import io.seata.server.coordinator.DefaultCoordinator; - /** * The type Server test. * @@ -33,6 +34,7 @@ public class ServerTest { private static final ThreadPoolExecutor workingThreads = new ThreadPoolExecutor(100, 500, 500, TimeUnit.SECONDS, new LinkedBlockingQueue(20000), new ThreadPoolExecutor.CallerRunsPolicy()); + /** * The entry point of application. * @@ -43,8 +45,9 @@ public static void main(String[] args) { RpcServer rpcServer = new RpcServer(workingThreads); rpcServer.setHandler(new DefaultCoordinator(rpcServer)); UUIDGenerator.init(1); + XID.setIpAddress(NetUtil.getLocalIp()); + XID.setPort(rpcServer.getListenPort()); rpcServer.init(); - System.exit(0); } diff --git a/server/src/test/java/WriteStoreMultithreadTest.java b/server/src/test/java/WriteStoreMultithreadTest.java new file mode 100644 index 00000000000..f782bfae1e3 --- /dev/null +++ b/server/src/test/java/WriteStoreMultithreadTest.java @@ -0,0 +1,200 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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. + */ +import io.seata.core.exception.TransactionException; +import io.seata.core.model.BranchStatus; +import io.seata.core.model.GlobalStatus; +import io.seata.server.session.BranchSession; +import io.seata.server.session.GlobalSession; +import io.seata.server.session.SessionCondition; +import io.seata.server.session.SessionManager; +import io.seata.server.store.FileTransactionStoreManager; +import io.seata.server.store.TransactionStoreManager; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.CountDownLatch; + +/** + * The interface Session storable. + * + * @author lizhao + */ +public class WriteStoreMultithreadTest { + private static String vgroup = "vgroupMock"; + private static String appname = "appnameMock"; + private static String instname = "seataMock"; + private static int per_thread_trx_num = 65535; + private static int threadNum = 16; + private static CountDownLatch countDownLatch = new CountDownLatch(threadNum); + public static void main(String[] args) throws Exception { + TransactionStoreManager transactionStoreManager = new FileTransactionStoreManager( + "data", + new SessionManager() { + @Override + public void destroy() { + + } + + @Override + public void addGlobalSession(GlobalSession session) throws TransactionException { + + } + + @Override + public GlobalSession findGlobalSession(Long transactionId) throws TransactionException { + return null; + } + + @Override + public void updateGlobalSessionStatus(GlobalSession session, GlobalStatus status) + throws TransactionException { + + } + + @Override + public void removeGlobalSession(GlobalSession session) throws TransactionException { + + } + + @Override + public void addBranchSession(GlobalSession globalSession, BranchSession session) + throws TransactionException { + + } + + @Override + public void updateBranchSessionStatus(BranchSession session, BranchStatus status) + throws TransactionException { + + } + + @Override + public void removeBranchSession(GlobalSession globalSession, BranchSession session) + throws TransactionException { + + } + + @Override + public Collection allSessions() { + return null; + } + + @Override + public List findGlobalSessions(SessionCondition condition) { + List globalSessions = new ArrayList<>(); + int begin = 10000; + int num = 1000; + for (int i = begin; i < begin + num; i++) { + BranchSession branchSession1 = new BranchSession(); + branchSession1.setTransactionId(i); + branchSession1.setBranchId(begin + num + (i - begin) * 2); + branchSession1.setResourceId("mockDbkeY1"); + + BranchSession branchSession2 = new BranchSession(); + branchSession2.setTransactionId(i); + branchSession2.setBranchId(begin + num + (i - begin) * 2 + 1); + branchSession2.setResourceId("mockDbkeY2"); + + GlobalSession globalSession = new GlobalSession(appname, vgroup, instname, 60000); + try { + globalSession.add(branchSession1); + globalSession.add(branchSession2); + globalSessions.add(globalSession); + } catch (Exception exx) {} + } + return globalSessions; + + } + + @Override + public void onBegin(GlobalSession globalSession) throws TransactionException { + + } + + @Override + public void onStatusChange(GlobalSession globalSession, GlobalStatus status) + throws TransactionException { + + } + + @Override + public void onBranchStatusChange(GlobalSession globalSession, BranchSession branchSession, + BranchStatus status) throws TransactionException { + + } + + @Override + public void onAddBranch(GlobalSession globalSession, BranchSession branchSession) + throws TransactionException { + + } + + @Override + public void onRemoveBranch(GlobalSession globalSession, BranchSession branchSession) + throws TransactionException { + + } + + @Override + public void onClose(GlobalSession globalSession) throws TransactionException { + + } + + @Override + public void onEnd(GlobalSession globalSession) throws TransactionException { + + } + }); + long beginWriteMills = System.currentTimeMillis(); + for (int i = 0; i < threadNum; i++) { + final int threadNo = i; + Thread thread = new Thread(() -> {write(transactionStoreManager, threadNo);}); + thread.start(); + } + countDownLatch.await(); + long endWriteMills = System.currentTimeMillis(); + System.out.println("thread nums:" + threadNum + ", per_thread_trx_num:" + per_thread_trx_num +" ,cost" + (endWriteMills-beginWriteMills)); + } + + private static void write(TransactionStoreManager transactionStoreManager, int threadNo) { + int trx_begin = threadNo * per_thread_trx_num; + for (int i = trx_begin; i < trx_begin + per_thread_trx_num; i++) { + GlobalSession globalSession = new GlobalSession(appname, vgroup, instname, 60000); + transactionStoreManager.writeSession(TransactionStoreManager.LogOperation.GLOBAL_ADD, globalSession); + + BranchSession branchSession1 = new BranchSession(); + branchSession1.setTransactionId(globalSession.getTransactionId()); + branchSession1.setBranchId(trx_begin + per_thread_trx_num + (i - trx_begin) * 2); + branchSession1.setResourceId("mockDbkeY1"); + transactionStoreManager.writeSession(TransactionStoreManager.LogOperation.BRANCH_ADD, branchSession1); + transactionStoreManager.writeSession(TransactionStoreManager.LogOperation.BRANCH_UPDATE, branchSession1); + transactionStoreManager.writeSession(TransactionStoreManager.LogOperation.BRANCH_REMOVE, branchSession1); + + BranchSession branchSession2 = new BranchSession(); + branchSession2.setTransactionId(globalSession.getTransactionId()); + branchSession2.setBranchId(trx_begin + (i - trx_begin) + i * 2 + 1); + branchSession2.setResourceId("mockDbkeY2"); + transactionStoreManager.writeSession(TransactionStoreManager.LogOperation.BRANCH_ADD, branchSession2); + transactionStoreManager.writeSession(TransactionStoreManager.LogOperation.BRANCH_UPDATE, branchSession2); + transactionStoreManager.writeSession(TransactionStoreManager.LogOperation.BRANCH_REMOVE, branchSession2); + + transactionStoreManager.writeSession(TransactionStoreManager.LogOperation.GLOBAL_UPDATE, globalSession); + transactionStoreManager.writeSession(TransactionStoreManager.LogOperation.GLOBAL_REMOVE, globalSession); + } + countDownLatch.countDown(); + } +} diff --git a/server/src/test/java/WriteStoreTest.java b/server/src/test/java/WriteStoreTest.java index 522b9c19634..50cfcc19443 100644 --- a/server/src/test/java/WriteStoreTest.java +++ b/server/src/test/java/WriteStoreTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -61,6 +60,11 @@ public static void main(String[] args) throws InterruptedException, IOException TransactionStoreManager transactionStoreManager = new FileTransactionStoreManager( "~/Documents/test/data", new SessionManager() { + @Override + public void destroy() { + + } + @Override public void addGlobalSession(GlobalSession session) throws TransactionException { diff --git a/server/src/test/java/io/seata/server/UUIDGeneratorOverflowTest.java b/server/src/test/java/io/seata/server/UUIDGeneratorOverflowTest.java index c6ff4ee8972..ad16e61da79 100644 --- a/server/src/test/java/io/seata/server/UUIDGeneratorOverflowTest.java +++ b/server/src/test/java/io/seata/server/UUIDGeneratorOverflowTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server; import org.testng.annotations.Test; diff --git a/server/src/test/java/io/seata/server/coordinator/DefaultCoordinatorTest.java b/server/src/test/java/io/seata/server/coordinator/DefaultCoordinatorTest.java index 3a5f1b47774..2a335283ced 100644 --- a/server/src/test/java/io/seata/server/coordinator/DefaultCoordinatorTest.java +++ b/server/src/test/java/io/seata/server/coordinator/DefaultCoordinatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.coordinator; import io.seata.common.XID; diff --git a/server/src/test/java/io/seata/server/coordinator/DefaultCoreTest.java b/server/src/test/java/io/seata/server/coordinator/DefaultCoreTest.java index 478fde4bc03..760a3cef808 100644 --- a/server/src/test/java/io/seata/server/coordinator/DefaultCoreTest.java +++ b/server/src/test/java/io/seata/server/coordinator/DefaultCoreTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/server/src/test/java/io/seata/server/lock/DefaultLockManagerImplTest.java b/server/src/test/java/io/seata/server/lock/DefaultLockManagerImplTest.java index 67c012b5a6d..73207bdf6bc 100644 --- a/server/src/test/java/io/seata/server/lock/DefaultLockManagerImplTest.java +++ b/server/src/test/java/io/seata/server/lock/DefaultLockManagerImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/server/src/test/java/io/seata/server/lock/LockManagerTest.java b/server/src/test/java/io/seata/server/lock/LockManagerTest.java index 53addc2d721..9ebee0ef72e 100644 --- a/server/src/test/java/io/seata/server/lock/LockManagerTest.java +++ b/server/src/test/java/io/seata/server/lock/LockManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/server/src/test/java/io/seata/server/session/BranchSessionTest.java b/server/src/test/java/io/seata/server/session/BranchSessionTest.java index 5257743cdb9..231d6d588a4 100644 --- a/server/src/test/java/io/seata/server/session/BranchSessionTest.java +++ b/server/src/test/java/io/seata/server/session/BranchSessionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/server/src/test/java/io/seata/server/session/DefaultSessionManagerTest.java b/server/src/test/java/io/seata/server/session/DefaultSessionManagerTest.java index cfe7a9c8a6e..790db949015 100644 --- a/server/src/test/java/io/seata/server/session/DefaultSessionManagerTest.java +++ b/server/src/test/java/io/seata/server/session/DefaultSessionManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ import java.util.Arrays; import java.util.Collection; +import java.util.HashSet; import java.util.List; import io.seata.core.model.BranchStatus; @@ -178,7 +179,7 @@ public void findGlobalSessionsTest(List globalSessions) throws Ex for (GlobalSession globalSession : globalSessions) { sessionManager.addGlobalSession(globalSession); } - SessionCondition sessionCondition = new SessionCondition(GlobalStatus.Begin, 30 * 24 * 3600); + SessionCondition sessionCondition = new SessionCondition( 30 * 24 * 3600); Collection expectedGlobalSessions = sessionManager.findGlobalSessions(sessionCondition); Assert.assertNotNull(expectedGlobalSessions); Assert.assertEquals(2, expectedGlobalSessions.size()); diff --git a/server/src/test/java/io/seata/server/session/FileBasedSessionManagerTest.java b/server/src/test/java/io/seata/server/session/FileBasedSessionManagerTest.java index 76a7dcf4b03..54b00ce6e11 100644 --- a/server/src/test/java/io/seata/server/session/FileBasedSessionManagerTest.java +++ b/server/src/test/java/io/seata/server/session/FileBasedSessionManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -189,7 +189,7 @@ public void findGlobalSessionsTest(List globalSessions) throws Ex for (GlobalSession globalSession : globalSessions) { sessionManager.addGlobalSession(globalSession); } - SessionCondition sessionCondition = new SessionCondition(GlobalStatus.Begin, 30 * 24 * 3600); + SessionCondition sessionCondition = new SessionCondition( 30 * 24 * 3600); Collection expectedGlobalSessions = sessionManager.findGlobalSessions(sessionCondition); Assert.assertNotNull(expectedGlobalSessions); Assert.assertEquals(2, expectedGlobalSessions.size()); diff --git a/server/src/test/java/io/seata/server/session/GlobalSessionTest.java b/server/src/test/java/io/seata/server/session/GlobalSessionTest.java index eb765ef0627..33356716912 100644 --- a/server/src/test/java/io/seata/server/session/GlobalSessionTest.java +++ b/server/src/test/java/io/seata/server/session/GlobalSessionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/server/src/test/java/io/seata/server/session/SessionHolderTest.java b/server/src/test/java/io/seata/server/session/SessionHolderTest.java index 6cf663dc208..2e10bd31a46 100644 --- a/server/src/test/java/io/seata/server/session/SessionHolderTest.java +++ b/server/src/test/java/io/seata/server/session/SessionHolderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.session; import io.seata.core.constants.ConfigurationKeys; diff --git a/server/src/test/java/io/seata/server/store/SessionStoreTest.java b/server/src/test/java/io/seata/server/store/SessionStoreTest.java index 1508a3d3427..e5addccd523 100644 --- a/server/src/test/java/io/seata/server/store/SessionStoreTest.java +++ b/server/src/test/java/io/seata/server/store/SessionStoreTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.server.store; import java.io.File; diff --git a/spring/src/main/java/io/seata/spring/annotation/GlobalLock.java b/spring/src/main/java/io/seata/spring/annotation/GlobalLock.java index 10508a71e32..e4f80c674b2 100644 --- a/spring/src/main/java/io/seata/spring/annotation/GlobalLock.java +++ b/spring/src/main/java/io/seata/spring/annotation/GlobalLock.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.annotation; import java.lang.annotation.ElementType; diff --git a/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java b/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java index 06e09321bab..aa92dabbe31 100644 --- a/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java +++ b/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.annotation; import io.seata.common.util.StringUtils; @@ -189,9 +188,9 @@ private void registerSpringShutdownHook() { if (applicationContext instanceof ConfigurableApplicationContext) { ((ConfigurableApplicationContext) applicationContext).registerShutdownHook(); ShutdownHook.removeRuntimeShutdownHook(); - ShutdownHook.getInstance().addDisposable(TmRpcClient.getInstance(applicationId, txServiceGroup)); - ShutdownHook.getInstance().addDisposable(RmRpcClient.getInstance(applicationId, txServiceGroup)); } + ShutdownHook.getInstance().addDisposable(TmRpcClient.getInstance(applicationId, txServiceGroup)); + ShutdownHook.getInstance().addDisposable(RmRpcClient.getInstance(applicationId, txServiceGroup)); } @Override diff --git a/spring/src/main/java/io/seata/spring/annotation/GlobalTransactional.java b/spring/src/main/java/io/seata/spring/annotation/GlobalTransactional.java index edb5773a05f..2374b3a3314 100644 --- a/spring/src/main/java/io/seata/spring/annotation/GlobalTransactional.java +++ b/spring/src/main/java/io/seata/spring/annotation/GlobalTransactional.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.annotation; import io.seata.tm.api.transaction.TransactionInfo; diff --git a/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionalInterceptor.java b/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionalInterceptor.java index 81eb4d10392..bc88a5435a9 100644 --- a/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionalInterceptor.java +++ b/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionalInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.annotation; import io.seata.common.exception.ShouldNeverHappenException; diff --git a/spring/src/main/java/io/seata/spring/annotation/MethodDesc.java b/spring/src/main/java/io/seata/spring/annotation/MethodDesc.java index 4dbfda2d09d..defecc69a63 100644 --- a/spring/src/main/java/io/seata/spring/annotation/MethodDesc.java +++ b/spring/src/main/java/io/seata/spring/annotation/MethodDesc.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.annotation; import java.lang.reflect.Method; diff --git a/spring/src/main/java/io/seata/spring/tcc/TccActionInterceptor.java b/spring/src/main/java/io/seata/spring/tcc/TccActionInterceptor.java index c97d8b2602e..edbe7f7a047 100644 --- a/spring/src/main/java/io/seata/spring/tcc/TccActionInterceptor.java +++ b/spring/src/main/java/io/seata/spring/tcc/TccActionInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.tcc; import io.seata.common.Constants; diff --git a/spring/src/main/java/io/seata/spring/util/SpringProxyUtils.java b/spring/src/main/java/io/seata/spring/util/SpringProxyUtils.java index 8cfce6ee0b3..69b3681047a 100644 --- a/spring/src/main/java/io/seata/spring/util/SpringProxyUtils.java +++ b/spring/src/main/java/io/seata/spring/util/SpringProxyUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.util; import org.springframework.aop.TargetSource; @@ -113,11 +112,13 @@ public static boolean isProxy(Object bean){ if(bean == null){ return false; } - if (Proxy.class.isAssignableFrom(bean.getClass()) || AopUtils.isAopProxy(bean)) { + //check dubbo proxy ? + String proxyClassName = bean.getClass().getName(); + if(proxyClassName.startsWith("com.alibaba.dubbo.common.bytecode.proxy") + || proxyClassName.startsWith("org.apache.dubbo.common.bytecode.proxy") ){ return true; - }else{ - return false; } + return Proxy.class.isAssignableFrom(bean.getClass()) || AopUtils.isAopProxy(bean); } /** diff --git a/spring/src/main/java/io/seata/spring/util/TCCBeanParserUtils.java b/spring/src/main/java/io/seata/spring/util/TCCBeanParserUtils.java index 6cfa35d9cc7..0ba4d20d46c 100644 --- a/spring/src/main/java/io/seata/spring/util/TCCBeanParserUtils.java +++ b/spring/src/main/java/io/seata/spring/util/TCCBeanParserUtils.java @@ -1,3 +1,18 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.spring.util; import io.seata.rm.tcc.api.TwoPhaseBusinessAction; @@ -112,10 +127,7 @@ protected static boolean isTccProxyTargetBean(RemotingDesc remotingDesc){ return true; } // sofa:reference / dubbo:reference, AOP - if(remotingDesc.isReference()){ - return true; - } - return false; + return remotingDesc.isReference(); } /** diff --git a/spring/src/test/java/io/seata/spring/annotation/Business.java b/spring/src/test/java/io/seata/spring/annotation/Business.java index 04980af1a75..aaa351d03a3 100644 --- a/spring/src/test/java/io/seata/spring/annotation/Business.java +++ b/spring/src/test/java/io/seata/spring/annotation/Business.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.annotation; /** diff --git a/spring/src/test/java/io/seata/spring/annotation/BusinessImpl.java b/spring/src/test/java/io/seata/spring/annotation/BusinessImpl.java index e5008381a8c..2ac53976727 100644 --- a/spring/src/test/java/io/seata/spring/annotation/BusinessImpl.java +++ b/spring/src/test/java/io/seata/spring/annotation/BusinessImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.annotation; import org.slf4j.Logger; diff --git a/spring/src/test/java/io/seata/spring/annotation/BusinessProxy.java b/spring/src/test/java/io/seata/spring/annotation/BusinessProxy.java index 140b76bb59b..14e0043e06a 100644 --- a/spring/src/test/java/io/seata/spring/annotation/BusinessProxy.java +++ b/spring/src/test/java/io/seata/spring/annotation/BusinessProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.annotation; import java.lang.reflect.InvocationHandler; diff --git a/spring/src/test/java/io/seata/spring/annotation/GlobalTransactionScannerTest.java b/spring/src/test/java/io/seata/spring/annotation/GlobalTransactionScannerTest.java index f33d7aa3975..6999738008d 100644 --- a/spring/src/test/java/io/seata/spring/annotation/GlobalTransactionScannerTest.java +++ b/spring/src/test/java/io/seata/spring/annotation/GlobalTransactionScannerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.annotation; import io.seata.spring.tcc.LocalTccAction; diff --git a/spring/src/test/java/io/seata/spring/annotation/MethodDescTest.java b/spring/src/test/java/io/seata/spring/annotation/MethodDescTest.java index 6baef9eb2dd..f6cae98ef9e 100644 --- a/spring/src/test/java/io/seata/spring/annotation/MethodDescTest.java +++ b/spring/src/test/java/io/seata/spring/annotation/MethodDescTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.annotation; import java.lang.reflect.InvocationTargetException; diff --git a/spring/src/test/java/io/seata/spring/tcc/LocalTccAction.java b/spring/src/test/java/io/seata/spring/tcc/LocalTccAction.java index f7395b9b64e..4fdeb378a18 100644 --- a/spring/src/test/java/io/seata/spring/tcc/LocalTccAction.java +++ b/spring/src/test/java/io/seata/spring/tcc/LocalTccAction.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.tcc; import io.seata.rm.tcc.api.LocalTCC; diff --git a/spring/src/test/java/io/seata/spring/tcc/LocalTccActionImpl.java b/spring/src/test/java/io/seata/spring/tcc/LocalTccActionImpl.java index b2dae4c1dd7..e693c1e92cc 100644 --- a/spring/src/test/java/io/seata/spring/tcc/LocalTccActionImpl.java +++ b/spring/src/test/java/io/seata/spring/tcc/LocalTccActionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.tcc; /** diff --git a/spring/src/test/java/io/seata/spring/tcc/TccAction.java b/spring/src/test/java/io/seata/spring/tcc/TccAction.java index 1873b1d80ca..6eaedc1d640 100644 --- a/spring/src/test/java/io/seata/spring/tcc/TccAction.java +++ b/spring/src/test/java/io/seata/spring/tcc/TccAction.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.tcc; import io.seata.rm.tcc.api.BusinessActionContext; diff --git a/spring/src/test/java/io/seata/spring/tcc/TccActionImpl.java b/spring/src/test/java/io/seata/spring/tcc/TccActionImpl.java index 838ed1632d6..c28a844c4ae 100644 --- a/spring/src/test/java/io/seata/spring/tcc/TccActionImpl.java +++ b/spring/src/test/java/io/seata/spring/tcc/TccActionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.spring.tcc; import io.seata.rm.tcc.api.BusinessActionContext; diff --git a/style/copyright b/style/copyright new file mode 100644 index 00000000000..0868accfc45 --- /dev/null +++ b/style/copyright @@ -0,0 +1,13 @@ + Copyright 1999-2019 Seata.io Group. + + 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. \ No newline at end of file diff --git a/style/feats_checkstyle.xml b/style/feats_checkstyle.xml index 5804d5b6dbc..d74d820de75 100644 --- a/style/feats_checkstyle.xml +++ b/style/feats_checkstyle.xml @@ -28,12 +28,12 @@ - + - + @@ -60,10 +60,6 @@ - - - - c = bean.getClass(); - if("com.alibaba.dubbo.config.spring.ReferenceBean".equals(c.getName()) - || "org.apache.dubbo.config.spring.ReferenceBean".equals(c.getName())){ - return true; - } - return false; + return "com.alibaba.dubbo.config.spring.ReferenceBean".equals(c.getName()) + || "org.apache.dubbo.config.spring.ReferenceBean".equals(c.getName()); } @Override public boolean isService(Object bean, String beanName) throws FrameworkException { Class c = bean.getClass(); - if("com.alibaba.dubbo.config.spring.ServiceBean".equals(c.getName()) - || "org.apache.dubbo.config.spring.ServiceBean".equals(c.getName())){ - return true; - } - return false; + return "com.alibaba.dubbo.config.spring.ServiceBean".equals(c.getName()) + || "org.apache.dubbo.config.spring.ServiceBean".equals(c.getName()); } @Override diff --git a/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/DubboUtil.java b/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/DubboUtil.java index 006ff0f150b..ab9bc071f90 100644 --- a/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/DubboUtil.java +++ b/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/DubboUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.tcc.remoting.parser; import io.seata.common.util.ReflectionUtil; diff --git a/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParser.java b/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParser.java index 366a3194b49..d07050c5f34 100644 --- a/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParser.java +++ b/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParser.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.tcc.remoting.parser; import io.seata.common.exception.FrameworkException; diff --git a/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/SofaRpcRemotingParser.java b/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/SofaRpcRemotingParser.java index eb8c2ca3203..ff1cc8349cf 100644 --- a/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/SofaRpcRemotingParser.java +++ b/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/SofaRpcRemotingParser.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.tcc.remoting.parser; import io.seata.common.exception.FrameworkException; @@ -41,10 +40,7 @@ public class SofaRpcRemotingParser extends AbstractedRemotingParser { public boolean isReference(Object bean, String beanName) throws FrameworkException { String beanClassName = bean.getClass().getName(); - if("com.alipay.sofa.runtime.spring.factory.ReferenceFactoryBean".equals(beanClassName) ){ - return true; - } - return false; + return "com.alipay.sofa.runtime.spring.factory.ReferenceFactoryBean".equals(beanClassName); } /** @@ -57,10 +53,7 @@ public boolean isReference(Object bean, String beanName) @Override public boolean isService(Object bean, String beanName) throws FrameworkException { String beanClassName = bean.getClass().getName(); - if("com.alipay.sofa.runtime.spring.factory.ServiceFactoryBean".equals(beanClassName) ){ - return true; - } - return false; + return "com.alipay.sofa.runtime.spring.factory.ServiceFactoryBean".equals(beanClassName); } @Override diff --git a/tcc/src/test/java/io/seata/rm/tcc/TccAction.java b/tcc/src/test/java/io/seata/rm/tcc/TccAction.java index 58d88b8e85c..0db5b8d0283 100644 --- a/tcc/src/test/java/io/seata/rm/tcc/TccAction.java +++ b/tcc/src/test/java/io/seata/rm/tcc/TccAction.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.tcc; import io.seata.rm.tcc.api.BusinessActionContext; diff --git a/tcc/src/test/java/io/seata/rm/tcc/TccActionImpl.java b/tcc/src/test/java/io/seata/rm/tcc/TccActionImpl.java index d330222ae05..bd1407cf118 100644 --- a/tcc/src/test/java/io/seata/rm/tcc/TccActionImpl.java +++ b/tcc/src/test/java/io/seata/rm/tcc/TccActionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.tcc; import io.seata.rm.tcc.api.BusinessActionContext; diff --git a/tcc/src/test/java/io/seata/rm/tcc/TccParam.java b/tcc/src/test/java/io/seata/rm/tcc/TccParam.java index e1d9f68e64d..c5013a4958a 100644 --- a/tcc/src/test/java/io/seata/rm/tcc/TccParam.java +++ b/tcc/src/test/java/io/seata/rm/tcc/TccParam.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.tcc; import io.seata.rm.tcc.api.BusinessActionContextParameter; diff --git a/tcc/src/test/java/io/seata/rm/tcc/interceptor/ActionInterceptorHandlerTest.java b/tcc/src/test/java/io/seata/rm/tcc/interceptor/ActionInterceptorHandlerTest.java index 9f28813a52d..df234b3c3a9 100644 --- a/tcc/src/test/java/io/seata/rm/tcc/interceptor/ActionInterceptorHandlerTest.java +++ b/tcc/src/test/java/io/seata/rm/tcc/interceptor/ActionInterceptorHandlerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.tcc.interceptor; import io.seata.rm.tcc.TccAction; import io.seata.rm.tcc.TccParam; import io.seata.rm.tcc.api.BusinessActionContext; -import io.seata.rm.tcc.TccParam; import org.junit.Assert; import org.junit.Test; @@ -48,7 +46,7 @@ public class ActionInterceptorHandlerTest { @Test public void testBusinessActionContext() throws NoSuchMethodException { Method prepareMethod = TccAction.class.getDeclaredMethod("prepare", - new Class[]{BusinessActionContext.class, int.class, List.class, TccParam.class}); + BusinessActionContext.class, int.class, List.class, TccParam.class); List list = new ArrayList(); list.add("b"); TccParam tccParam = new TccParam (1, "abc@ali.com"); diff --git a/tcc/src/test/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParserTest.java b/tcc/src/test/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParserTest.java index 0bd80125639..dda8f6f59b4 100644 --- a/tcc/src/test/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParserTest.java +++ b/tcc/src/test/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParserTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.rm.tcc.remoting.parser; import io.seata.rm.tcc.TccAction; diff --git a/test/pom.xml b/test/pom.xml index 5bf7134e3e3..dad41e96bdc 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -91,11 +91,6 @@ zookeeper 3.4.8
- - com.coreos - jetcd-core - 0.0.2 - redis.clients jedis @@ -114,4 +109,4 @@
- + \ No newline at end of file diff --git a/test/src/main/java/io/seata/common/loader/LoaderTestImpl1.java b/test/src/main/java/io/seata/common/loader/LoaderTestImpl1.java index a2f07e0ee8b..5b26c187441 100644 --- a/test/src/main/java/io/seata/common/loader/LoaderTestImpl1.java +++ b/test/src/main/java/io/seata/common/loader/LoaderTestImpl1.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.loader; /** diff --git a/test/src/main/java/io/seata/common/loader/LoaderTestImpl2.java b/test/src/main/java/io/seata/common/loader/LoaderTestImpl2.java index 06c3b5d6d79..3a733f8ba92 100644 --- a/test/src/main/java/io/seata/common/loader/LoaderTestImpl2.java +++ b/test/src/main/java/io/seata/common/loader/LoaderTestImpl2.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.loader; /** diff --git a/test/src/main/java/io/seata/common/loader/LoaderTestSPI.java b/test/src/main/java/io/seata/common/loader/LoaderTestSPI.java index 4a4a9a6272e..c85ed108b35 100644 --- a/test/src/main/java/io/seata/common/loader/LoaderTestSPI.java +++ b/test/src/main/java/io/seata/common/loader/LoaderTestSPI.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.loader; /** diff --git a/test/src/main/java/io/seata/test/DataSourceBasicTest.java b/test/src/main/java/io/seata/test/DataSourceBasicTest.java index e2dc96ae34b..a323c1db43a 100644 --- a/test/src/main/java/io/seata/test/DataSourceBasicTest.java +++ b/test/src/main/java/io/seata/test/DataSourceBasicTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.test; import java.util.Date; diff --git a/test/src/main/java/io/seata/test/LocalTransactionWithGlobalLockDataSourceBasicTest.java b/test/src/main/java/io/seata/test/LocalTransactionWithGlobalLockDataSourceBasicTest.java index 9e1a09cd3e5..a1dfdbeac41 100644 --- a/test/src/main/java/io/seata/test/LocalTransactionWithGlobalLockDataSourceBasicTest.java +++ b/test/src/main/java/io/seata/test/LocalTransactionWithGlobalLockDataSourceBasicTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.test; import java.util.Date; diff --git a/test/src/main/java/io/seata/test/client/AppTest.java b/test/src/main/java/io/seata/test/client/AppTest.java index 5ae4084544a..0795ec268e8 100644 --- a/test/src/main/java/io/seata/test/client/AppTest.java +++ b/test/src/main/java/io/seata/test/client/AppTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.test.client; import io.seata.rm.RMClient; diff --git a/test/src/main/java/io/seata/test/common/ApplicationKeeper.java b/test/src/main/java/io/seata/test/common/ApplicationKeeper.java index 0e5d9891e37..0bbdf7fdce6 100644 --- a/test/src/main/java/io/seata/test/common/ApplicationKeeper.java +++ b/test/src/main/java/io/seata/test/common/ApplicationKeeper.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.test.common; import java.util.concurrent.locks.Condition; diff --git a/test/src/main/resources/file.conf b/test/src/main/resources/file.conf index 9cd05c0ec5f..30801f29901 100644 --- a/test/src/main/resources/file.conf +++ b/test/src/main/resources/file.conf @@ -20,16 +20,37 @@ transport { worker-thread-size = 8 } } +## transaction log store store { - # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions - max-branch-session-size = 16384 - # globe session size , if exceeded throws exceptions - max-global-session-size = 512 - # file buffer size , if exceeded allocate new buffer - file-write-buffer-cache-size = 16384 - # when recover batch read size - session.reload.read_size = 100 + ## store mode: file、db + mode = "file" + + ## file store + file { + dir = "sessionStore" + + # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions + max-branch-session-size = 16384 + # globe session size , if exceeded throws exceptions + max-global-session-size = 512 + # file buffer size , if exceeded allocate new buffer + file-write-buffer-cache-size = 16384 + # when recover batch read size + session.reload.read_size = 100 + # async, sync + flush-disk-mode = async + } + + ## database store + db { + driver_class = "" + url = "" + user = "" + password = "" + } + } + service { #vgroup->rgroup vgroup_mapping.my_test_tx_group = "default" diff --git a/test/src/main/resources/registry.conf b/test/src/main/resources/registry.conf index 1aa9dfa5a6f..15677236a89 100644 --- a/test/src/main/resources/registry.conf +++ b/test/src/main/resources/registry.conf @@ -1,5 +1,5 @@ registry { - # file 、nacos 、eureka、redis、zk、consul + # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa type = "file" nacos { @@ -26,6 +26,19 @@ registry { cluster = "default" serverAddr = "127.0.0.1:8500" } + etcd3 { + cluster = "default" + serverAddr = "http://localhost:2379" + } + sofa { + serverAddr = "127.0.0.1:9603" + application = "default" + region = "DEFAULT_ZONE" + datacenter = "DefaultDataCenter" + cluster = "default" + group = "SEATA_GROUP" + addressWaitTime = "3000" + } file { name = "file.conf" } diff --git a/test/src/test/java/io/seata/common/loader/EnhancedServiceLoaderTest.java b/test/src/test/java/io/seata/common/loader/EnhancedServiceLoaderTest.java index a319c150ce2..b5b4c1a39a4 100644 --- a/test/src/test/java/io/seata/common/loader/EnhancedServiceLoaderTest.java +++ b/test/src/test/java/io/seata/common/loader/EnhancedServiceLoaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.common.loader; import org.junit.Assert; diff --git a/test/src/test/java/io/seata/core/rpc/netty/TmRpcClientTest.java b/test/src/test/java/io/seata/core/rpc/netty/TmRpcClientTest.java index 2e99818a891..7d07262cbd4 100644 --- a/test/src/test/java/io/seata/core/rpc/netty/TmRpcClientTest.java +++ b/test/src/test/java/io/seata/core/rpc/netty/TmRpcClientTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.core.rpc.netty; import java.lang.reflect.Method; diff --git a/tm/src/main/java/io/seata/tm/DefaultTransactionManager.java b/tm/src/main/java/io/seata/tm/DefaultTransactionManager.java index 88fd734f9d5..a2f3e945c12 100644 --- a/tm/src/main/java/io/seata/tm/DefaultTransactionManager.java +++ b/tm/src/main/java/io/seata/tm/DefaultTransactionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.tm; import java.util.concurrent.TimeoutException; @@ -41,32 +40,6 @@ */ public class DefaultTransactionManager implements TransactionManager { - private static class SingletonHolder { - private static TransactionManager INSTANCE = new DefaultTransactionManager(); - } - - /** - * Get transaction manager. - * - * @return the transaction manager - */ - public static TransactionManager get() { - return SingletonHolder.INSTANCE; - } - - /** - * Set a TM instance. - * - * @param mock commonly used for test mocking - */ - public static void set(TransactionManager mock) { - SingletonHolder.INSTANCE = mock; - } - - private DefaultTransactionManager() { - - } - @Override public String begin(String applicationId, String transactionServiceGroup, String name, int timeout) throws TransactionException { diff --git a/tm/src/main/java/io/seata/tm/TMClient.java b/tm/src/main/java/io/seata/tm/TMClient.java index 37c9c1e023c..4987dc85ecb 100644 --- a/tm/src/main/java/io/seata/tm/TMClient.java +++ b/tm/src/main/java/io/seata/tm/TMClient.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.tm; import io.seata.core.rpc.netty.TmRpcClient; diff --git a/tm/src/main/java/io/seata/tm/TransactionManagerHolder.java b/tm/src/main/java/io/seata/tm/TransactionManagerHolder.java new file mode 100644 index 00000000000..f4deba4aaf0 --- /dev/null +++ b/tm/src/main/java/io/seata/tm/TransactionManagerHolder.java @@ -0,0 +1,78 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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.seata.tm; + +import io.seata.common.exception.ShouldNeverHappenException; +import io.seata.common.loader.EnhancedServiceLoader; +import io.seata.core.exception.TransactionException; +import io.seata.core.exception.TransactionExceptionCode; +import io.seata.core.model.GlobalStatus; +import io.seata.core.model.TransactionManager; +import io.seata.core.protocol.transaction.*; +import io.seata.core.rpc.netty.TmRpcClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.TimeoutException; + +/** + * The type Default transaction manager. + * + * @author sharajava + */ +public class TransactionManagerHolder { + + private static final Logger LOGGER = LoggerFactory.getLogger(TransactionManagerHolder.class); + + private static class SingletonHolder { + + private static TransactionManager INSTANCE = null; + + static { + try { + INSTANCE = EnhancedServiceLoader.load(TransactionManager.class); + LOGGER.info("TransactionManager Singleton " + INSTANCE); + } catch (Throwable anyEx) { + LOGGER.error("Failed to load TransactionManager Singleton! ", anyEx); + } + } + } + + /** + * Get transaction manager. + * + * @return the transaction manager + */ + public static TransactionManager get() { + if (SingletonHolder.INSTANCE == null) { + throw new ShouldNeverHappenException("TransactionManager is NOT ready!"); + } + return SingletonHolder.INSTANCE; + } + + /** + * Set a TM instance. + * + * @param mock commonly used for test mocking + */ + public static void set(TransactionManager mock) { + SingletonHolder.INSTANCE = mock; + } + + private TransactionManagerHolder() { + + } +} diff --git a/tm/src/main/java/io/seata/tm/api/DefaultFailureHandlerImpl.java b/tm/src/main/java/io/seata/tm/api/DefaultFailureHandlerImpl.java index 2b7e36f881f..d98c4e19784 100644 --- a/tm/src/main/java/io/seata/tm/api/DefaultFailureHandlerImpl.java +++ b/tm/src/main/java/io/seata/tm/api/DefaultFailureHandlerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.tm.api; import org.slf4j.Logger; diff --git a/tm/src/main/java/io/seata/tm/api/DefaultGlobalTransaction.java b/tm/src/main/java/io/seata/tm/api/DefaultGlobalTransaction.java index 19012dfe2cc..2736c79d282 100644 --- a/tm/src/main/java/io/seata/tm/api/DefaultGlobalTransaction.java +++ b/tm/src/main/java/io/seata/tm/api/DefaultGlobalTransaction.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.tm.api; import io.seata.common.exception.ShouldNeverHappenException; @@ -22,7 +21,7 @@ import io.seata.core.model.GlobalStatus; import io.seata.core.model.TransactionManager; import io.seata.tm.DefaultTransactionManager; - +import io.seata.tm.TransactionManagerHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,7 +61,7 @@ public class DefaultGlobalTransaction implements GlobalTransaction { * @param role the role */ DefaultGlobalTransaction(String xid, GlobalStatus status, GlobalTransactionRole role) { - this.transactionManager = DefaultTransactionManager.get(); + this.transactionManager = TransactionManagerHolder.get(); this.xid = xid; this.status = status; this.role = role; @@ -96,8 +95,8 @@ public void begin(int timeout, String name) throws TransactionException { xid = transactionManager.begin(null, null, name, timeout); status = GlobalStatus.Begin; RootContext.bind(xid); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Begin a NEW global transaction [" + xid + "]"); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Begin new global transaction [" + xid + "]"); } } @@ -121,6 +120,9 @@ public void commit() throws TransactionException { RootContext.unbind(); } } + if (LOGGER.isInfoEnabled()) { + LOGGER.info("[" + xid + "] commit status:" + status); + } } @@ -143,7 +145,9 @@ public void rollback() throws TransactionException { RootContext.unbind(); } } - + if (LOGGER.isInfoEnabled()) { + LOGGER.info("[" + xid + "] rollback status:" + status); + } } @Override diff --git a/tm/src/main/java/io/seata/tm/api/FailureHandler.java b/tm/src/main/java/io/seata/tm/api/FailureHandler.java index e4e317b6b83..84c544ed925 100644 --- a/tm/src/main/java/io/seata/tm/api/FailureHandler.java +++ b/tm/src/main/java/io/seata/tm/api/FailureHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.tm.api; /** diff --git a/tm/src/main/java/io/seata/tm/api/GlobalTransaction.java b/tm/src/main/java/io/seata/tm/api/GlobalTransaction.java index 30ccd103b3a..fed1dbf2de2 100644 --- a/tm/src/main/java/io/seata/tm/api/GlobalTransaction.java +++ b/tm/src/main/java/io/seata/tm/api/GlobalTransaction.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.tm.api; import io.seata.core.exception.TransactionException; diff --git a/tm/src/main/java/io/seata/tm/api/GlobalTransactionContext.java b/tm/src/main/java/io/seata/tm/api/GlobalTransactionContext.java index 1a10e95c12c..547ad3f9dbe 100644 --- a/tm/src/main/java/io/seata/tm/api/GlobalTransactionContext.java +++ b/tm/src/main/java/io/seata/tm/api/GlobalTransactionContext.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.tm.api; import io.seata.core.context.RootContext; diff --git a/tm/src/main/java/io/seata/tm/api/GlobalTransactionRole.java b/tm/src/main/java/io/seata/tm/api/GlobalTransactionRole.java index 938dbd2102e..9cc1769637d 100644 --- a/tm/src/main/java/io/seata/tm/api/GlobalTransactionRole.java +++ b/tm/src/main/java/io/seata/tm/api/GlobalTransactionRole.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.tm.api; /** diff --git a/tm/src/main/java/io/seata/tm/api/TransactionalExecutor.java b/tm/src/main/java/io/seata/tm/api/TransactionalExecutor.java index 143260ebd7b..1d3135b983b 100644 --- a/tm/src/main/java/io/seata/tm/api/TransactionalExecutor.java +++ b/tm/src/main/java/io/seata/tm/api/TransactionalExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.tm.api; import io.seata.tm.api.transaction.TransactionInfo; diff --git a/tm/src/main/java/io/seata/tm/api/TransactionalTemplate.java b/tm/src/main/java/io/seata/tm/api/TransactionalTemplate.java index 1e9a5b255f0..957b658b907 100644 --- a/tm/src/main/java/io/seata/tm/api/TransactionalTemplate.java +++ b/tm/src/main/java/io/seata/tm/api/TransactionalTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.tm.api; diff --git a/tm/src/main/java/io/seata/tm/api/transaction/NoRollbackRule.java b/tm/src/main/java/io/seata/tm/api/transaction/NoRollbackRule.java index bb9d039102d..facc1cfee16 100644 --- a/tm/src/main/java/io/seata/tm/api/transaction/NoRollbackRule.java +++ b/tm/src/main/java/io/seata/tm/api/transaction/NoRollbackRule.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tm/src/main/java/io/seata/tm/api/transaction/RollbackRule.java b/tm/src/main/java/io/seata/tm/api/transaction/RollbackRule.java index 21c0b1f0d75..8f99b36d780 100644 --- a/tm/src/main/java/io/seata/tm/api/transaction/RollbackRule.java +++ b/tm/src/main/java/io/seata/tm/api/transaction/RollbackRule.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tm/src/main/java/io/seata/tm/api/transaction/TransactionHook.java b/tm/src/main/java/io/seata/tm/api/transaction/TransactionHook.java index d0552d18799..3f945379190 100644 --- a/tm/src/main/java/io/seata/tm/api/transaction/TransactionHook.java +++ b/tm/src/main/java/io/seata/tm/api/transaction/TransactionHook.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tm/src/main/java/io/seata/tm/api/transaction/TransactionHookAdapter.java b/tm/src/main/java/io/seata/tm/api/transaction/TransactionHookAdapter.java index 83e60726dec..72fe45bf9de 100644 --- a/tm/src/main/java/io/seata/tm/api/transaction/TransactionHookAdapter.java +++ b/tm/src/main/java/io/seata/tm/api/transaction/TransactionHookAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tm/src/main/java/io/seata/tm/api/transaction/TransactionHookManager.java b/tm/src/main/java/io/seata/tm/api/transaction/TransactionHookManager.java index 4d26eb8d1de..b6e8a01dd65 100644 --- a/tm/src/main/java/io/seata/tm/api/transaction/TransactionHookManager.java +++ b/tm/src/main/java/io/seata/tm/api/transaction/TransactionHookManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tm/src/main/java/io/seata/tm/api/transaction/TransactionInfo.java b/tm/src/main/java/io/seata/tm/api/transaction/TransactionInfo.java index e034763ef8a..f96855e2a2c 100644 --- a/tm/src/main/java/io/seata/tm/api/transaction/TransactionInfo.java +++ b/tm/src/main/java/io/seata/tm/api/transaction/TransactionInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tm/src/main/resources/META-INF/services/io.seata.core.model.TransactionManager b/tm/src/main/resources/META-INF/services/io.seata.core.model.TransactionManager new file mode 100644 index 00000000000..93e7661e64b --- /dev/null +++ b/tm/src/main/resources/META-INF/services/io.seata.core.model.TransactionManager @@ -0,0 +1 @@ +io.seata.tm.DefaultTransactionManager \ No newline at end of file diff --git a/tm/src/test/java/io/seata/tm/api/APITest.java b/tm/src/test/java/io/seata/tm/api/APITest.java index a1013733845..c0cbabd7704 100644 --- a/tm/src/test/java/io/seata/tm/api/APITest.java +++ b/tm/src/test/java/io/seata/tm/api/APITest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.seata.tm.api; import io.seata.core.context.RootContext; @@ -22,6 +21,7 @@ import io.seata.core.model.TransactionManager; import io.seata.tm.DefaultTransactionManager; +import io.seata.tm.TransactionManagerHolder; import io.seata.tm.api.transaction.TransactionInfo; import org.junit.After; import org.junit.Assert; @@ -42,7 +42,7 @@ public class APITest { */ @BeforeClass public static void init() { - DefaultTransactionManager.set(new TransactionManager() { + TransactionManagerHolder.set(new TransactionManager() { @Override public String begin(String applicationId, String transactionServiceGroup, String name, int timeout) throws TransactionException { diff --git a/tm/src/test/java/io/seata/tm/api/TransactionTemplateTest.java b/tm/src/test/java/io/seata/tm/api/TransactionTemplateTest.java index c20997e9b0c..3f461fb8bf2 100644 --- a/tm/src/test/java/io/seata/tm/api/TransactionTemplateTest.java +++ b/tm/src/test/java/io/seata/tm/api/TransactionTemplateTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ import io.seata.core.model.GlobalStatus; import io.seata.core.model.TransactionManager; import io.seata.tm.DefaultTransactionManager; +import io.seata.tm.TransactionManagerHolder; import io.seata.tm.api.transaction.NoRollbackRule; import io.seata.tm.api.transaction.RollbackRule; import io.seata.tm.api.transaction.TransactionHook; @@ -56,7 +57,7 @@ public void init() throws Exception { when(transactionManager.commit(DEFAULT_XID)).thenReturn(GlobalStatus.Committed); when(transactionManager.rollback(DEFAULT_XID)).thenReturn(GlobalStatus.Rollbacked); when(transactionManager.getStatus(DEFAULT_XID)).thenReturn(GlobalStatus.Begin); - DefaultTransactionManager.set(transactionManager); + TransactionManagerHolder.set(transactionManager); //mock transactionalExecutor transactionalExecutor = Mockito.mock(TransactionalExecutor.class); diff --git a/tm/src/test/java/io/seata/tm/api/transaction/MyRuntimeException.java b/tm/src/test/java/io/seata/tm/api/transaction/MyRuntimeException.java index bd6cfcf1576..479476c28e8 100644 --- a/tm/src/test/java/io/seata/tm/api/transaction/MyRuntimeException.java +++ b/tm/src/test/java/io/seata/tm/api/transaction/MyRuntimeException.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tm/src/test/java/io/seata/tm/api/transaction/RollbackRuleTest.java b/tm/src/test/java/io/seata/tm/api/transaction/RollbackRuleTest.java index 6c12f9d8ece..1c6ef0e9e08 100644 --- a/tm/src/test/java/io/seata/tm/api/transaction/RollbackRuleTest.java +++ b/tm/src/test/java/io/seata/tm/api/transaction/RollbackRuleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tm/src/test/java/io/seata/tm/api/transaction/TransactionHookManagerTest.java b/tm/src/test/java/io/seata/tm/api/transaction/TransactionHookManagerTest.java index 2e21df9f3ff..d37ba09be2c 100644 --- a/tm/src/test/java/io/seata/tm/api/transaction/TransactionHookManagerTest.java +++ b/tm/src/test/java/io/seata/tm/api/transaction/TransactionHookManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tm/src/test/java/io/seata/tm/api/transaction/TransactionInfoTest.java b/tm/src/test/java/io/seata/tm/api/transaction/TransactionInfoTest.java index 89f70ef96d3..40b413982de 100644 --- a/tm/src/test/java/io/seata/tm/api/transaction/TransactionInfoTest.java +++ b/tm/src/test/java/io/seata/tm/api/transaction/TransactionInfoTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2019 Seata.io Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.