forked from apache/incubator-seata
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize: @GlobalTransactional and @GlobalLock can now customize lock…
… retry config (apache#2962)
- Loading branch information
1 parent
f1cf404
commit 6c0c759
Showing
17 changed files
with
609 additions
and
147 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
core/src/main/java/io/seata/core/context/GlobalLockConfigHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.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.context; | ||
|
||
import io.seata.core.model.GlobalLockConfig; | ||
|
||
/** use this class to access current GlobalLockConfig from anywhere | ||
* @author selfishlover | ||
*/ | ||
public class GlobalLockConfigHolder { | ||
|
||
private static ThreadLocal<GlobalLockConfig> holder = new ThreadLocal<>(); | ||
|
||
public static GlobalLockConfig getCurrentGlobalLockConfig() { | ||
return holder.get(); | ||
} | ||
|
||
public static GlobalLockConfig setAndReturnPrevious(GlobalLockConfig config) { | ||
GlobalLockConfig previous = holder.get(); | ||
holder.set(config); | ||
return previous; | ||
} | ||
|
||
public static void remove() { | ||
holder.remove(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
core/src/main/java/io/seata/core/model/GlobalLockConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.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.model; | ||
|
||
/** | ||
* @author selfishlover | ||
*/ | ||
public class GlobalLockConfig { | ||
|
||
private int lockRetryInternal; | ||
|
||
private int lockRetryTimes; | ||
|
||
public int getLockRetryInternal() { | ||
return lockRetryInternal; | ||
} | ||
|
||
public void setLockRetryInternal(int lockRetryInternal) { | ||
this.lockRetryInternal = lockRetryInternal; | ||
} | ||
|
||
public int getLockRetryTimes() { | ||
return lockRetryTimes; | ||
} | ||
|
||
public void setLockRetryTimes(int lockRetryTimes) { | ||
this.lockRetryTimes = lockRetryTimes; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
core/src/test/java/io/seata/core/context/GlobalLockConfigHolderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.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.context; | ||
|
||
import io.seata.core.model.GlobalLockConfig; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class GlobalLockConfigHolderTest { | ||
|
||
@BeforeEach | ||
void setUp() { | ||
assertNull(GlobalLockConfigHolder.getCurrentGlobalLockConfig(), "should be null at first"); | ||
} | ||
|
||
@Test | ||
void setAndReturnPrevious() { | ||
GlobalLockConfig config1 = new GlobalLockConfig(); | ||
assertNull(GlobalLockConfigHolder.setAndReturnPrevious(config1), "should return null"); | ||
assertSame(config1, GlobalLockConfigHolder.getCurrentGlobalLockConfig(), "holder fail to store config"); | ||
|
||
GlobalLockConfig config2 = new GlobalLockConfig(); | ||
assertSame(config1, GlobalLockConfigHolder.setAndReturnPrevious(config2), "fail to get previous config"); | ||
assertSame(config2, GlobalLockConfigHolder.getCurrentGlobalLockConfig(), "holder fail to store latest config"); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
assertDoesNotThrow(GlobalLockConfigHolder::remove, "clear method should not throw anything"); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
rm-datasource/src/main/java/io/seata/rm/GlobalLockExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.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; | ||
|
||
import io.seata.core.model.GlobalLockConfig; | ||
|
||
/** | ||
* executor to execute business logic that require global lock | ||
* @author selfishlover | ||
*/ | ||
public interface GlobalLockExecutor { | ||
|
||
/** | ||
* execute business logic | ||
* @return business return | ||
* @throws Throwable whatever throw during execution | ||
*/ | ||
Object execute() throws Throwable; | ||
|
||
/** | ||
* global lock config info | ||
* @return | ||
*/ | ||
GlobalLockConfig getGlobalLockConfig(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.