Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: file session manager changed to singleton and optimize task thread pool model #4451

Merged
merged 89 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
1d89b88
optimize: skip reload
caohdgege Feb 18, 2022
87234e6
optimize: close undo log delete
caohdgege Feb 18, 2022
df5b93a
add md
caohdgege Feb 18, 2022
3c8939c
Merge branch 'develop' into skip-reload_
wangliang181230 Feb 23, 2022
8e39036
fix logic and ci
caohdgege Feb 28, 2022
a54426b
Merge remote-tracking branch 'origin/skip-reload_' into skip-reload_
caohdgege Feb 28, 2022
9c48ec9
Merge branch 'develop' into skip-reload_
caohdgege Feb 28, 2022
125e29f
fix pmd
caohdgege Feb 28, 2022
47b2bfa
Merge remote-tracking branch 'origin/skip-reload_' into skip-reload_
caohdgege Feb 28, 2022
6534549
fix ci
caohdgege Feb 28, 2022
7309dad
md
caohdgege Mar 3, 2022
f3cc555
fixed the inability to get some remote configurations
funky-eyes Mar 3, 2022
0db8a8f
update
funky-eyes Mar 3, 2022
2598db9
update
funky-eyes Mar 3, 2022
1a6618a
code formatting
funky-eyes Mar 3, 2022
5013b19
fix
funky-eyes Mar 3, 2022
b80cead
bugfix
funky-eyes Mar 4, 2022
e9dce09
bugfix
funky-eyes Mar 4, 2022
d445556
bugfix
funky-eyes Mar 4, 2022
7117812
bugfix
funky-eyes Mar 4, 2022
eb53e00
bugfix
funky-eyes Mar 4, 2022
db19a9f
bugfix
funky-eyes Mar 4, 2022
a0d800d
bugfix
funky-eyes Mar 4, 2022
643d214
add a log && set val for errorStatusGlobalSessions
caohdgege Mar 5, 2022
320c334
add log
caohdgege Mar 5, 2022
03b2739
optimize
caohdgege Mar 5, 2022
9bb1ec9
Merge branch 'develop' into 0303
funky-eyes Mar 6, 2022
204f234
Merge branch 'develop' into 0303
wangliang181230 Mar 7, 2022
a61fc96
Merge branch 'develop' into skip-reload_
slievrly Mar 7, 2022
756f542
Merge branch 'develop' into 0303
slievrly Mar 7, 2022
e03f8c3
optimize
funky-eyes Mar 8, 2022
97ed206
Merge branch '0303' of github.com:a364176773/seata into 0303
funky-eyes Mar 8, 2022
36467e2
optimize
funky-eyes Mar 8, 2022
8307356
optimize
funky-eyes Mar 8, 2022
8d6634b
fix typo
caohdgege Mar 8, 2022
12c0569
fix
caohdgege Mar 8, 2022
1cf3830
Merge remote-tracking branch 'origin/skip-reload_' into skip-reload_
caohdgege Mar 8, 2022
4b16d2b
reverse space
caohdgege Mar 8, 2022
a98cf19
UnusedImports
caohdgege Mar 8, 2022
e414172
fix ci
caohdgege Mar 8, 2022
0bf17a9
Merge branch 'develop' into skip-reload_
caohdgege Mar 8, 2022
6367c9b
fix ci
caohdgege Mar 8, 2022
67d0fae
Merge remote-tracking branch 'origin/skip-reload_' into skip-reload_
caohdgege Mar 8, 2022
106290f
Merge branch 'develop' of github.com:seata/seata into 0309
funky-eyes Mar 9, 2022
a92eeb3
optimize: seata-server timing tasks
funky-eyes Mar 9, 2022
8271ee7
optimize: seata-server timing tasks
funky-eyes Mar 9, 2022
1509b2f
opt
funky-eyes Mar 9, 2022
7f24217
Merge branch 'skip-reload_' of https://github.com/caohdgege/seata int…
funky-eyes Mar 9, 2022
8bc2229
commit
funky-eyes Mar 9, 2022
b758b77
commit
funky-eyes Mar 9, 2022
cfa29cd
Merge branch 'skip-reload_' of github.com:caohdgege/seata into 0309
funky-eyes Mar 10, 2022
46aff5a
optimize
funky-eyes Mar 10, 2022
7cb8d59
optimize
funky-eyes Mar 10, 2022
61f4e5e
commit
funky-eyes Mar 10, 2022
3c9a03d
Merge branch '0309' of github.com:a364176773/seata into 0309
funky-eyes Mar 10, 2022
3841138
Merge branch 'develop' into 0309
funky-eyes Mar 10, 2022
78db1b0
optimize
funky-eyes Mar 11, 2022
e8b6b71
optimize
funky-eyes Mar 11, 2022
ee8b5f9
Merge branch 'develop' into 0309
funky-eyes Mar 12, 2022
acf8151
commit
funky-eyes Mar 13, 2022
657d26d
Merge branch 'develop' into 0309
slievrly Mar 14, 2022
162e1c1
Merge branch 'develop' of github.com:seata/seata into 0309
funky-eyes Mar 14, 2022
7b18221
Merge branch 'develop' of github.com:seata/seata into 0309
funky-eyes Mar 14, 2022
54b1b02
opt
funky-eyes Mar 14, 2022
308768b
opt
funky-eyes Mar 14, 2022
3899a69
Merge branch 'develop' into 0309
funky-eyes Mar 18, 2022
6b9c5cf
Merge branch 'develop' into 0309
funky-eyes Mar 19, 2022
da327dd
Merge branch 'develop' into 0309
funky-eyes Apr 6, 2022
030ee9f
modify test case
funky-eyes Apr 6, 2022
43938d8
Merge remote-tracking branch 'origin/0309' into 0309
funky-eyes Apr 6, 2022
8e3953e
opt
funky-eyes Apr 6, 2022
099d0d3
optimize
funky-eyes Apr 7, 2022
e795464
modify test case
funky-eyes Apr 8, 2022
3d9080e
Merge remote-tracking branch 'origin/0309' into 0309
funky-eyes Apr 8, 2022
c38fe21
modify test case
funky-eyes Apr 8, 2022
0b3c928
modify test case
funky-eyes Apr 8, 2022
5a4c5fb
fix test case fail
funky-eyes Apr 9, 2022
d586673
Merge branch 'develop' of github.com:seata/seata into 0309
funky-eyes Apr 9, 2022
988c759
opt
funky-eyes Apr 19, 2022
bc58bc4
Merge branch 'develop' of github.com:seata/seata into 0309
funky-eyes Apr 19, 2022
2228bc9
opt
funky-eyes Apr 19, 2022
4e25ee7
opt
funky-eyes Apr 19, 2022
aeabd59
opt
funky-eyes Apr 19, 2022
4631220
bugfix
funky-eyes Apr 19, 2022
47fa7de
optimize
funky-eyes Apr 20, 2022
474e866
Merge branch '0309' of github.com:a364176773/seata into 0309
funky-eyes Apr 20, 2022
3abb98e
optimize
funky-eyes Apr 20, 2022
f7bd2e5
fix case
funky-eyes Apr 20, 2022
4b3f1a9
fix case
funky-eyes Apr 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
  • Loading branch information
caohdgege committed Mar 8, 2022
commit 12c0569cbc1a7e28c534d1b0fd01ea319ed6f9fc
41 changes: 23 additions & 18 deletions server/src/main/java/io/seata/server/session/SessionHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.CompletableFuture;

import io.seata.common.ConfigurationKeys;
import io.seata.core.model.LockStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -80,7 +81,7 @@ public class SessionHolder {
/**
* The redis distributed lock expire time
*/
private static long DISTRIBUTED_LOCK_EXPIRE_TIME = CONFIG.getLong(ConfigurationKeys.DISTRIBUTED_LOCK_EXPIRE_TIME,10000);
private static long DISTRIBUTED_LOCK_EXPIRE_TIME = CONFIG.getLong(ConfigurationKeys.DISTRIBUTED_LOCK_EXPIRE_TIME, 10000);

private static SessionManager ROOT_SESSION_MANAGER;
private static SessionManager ASYNC_COMMITTING_SESSION_MANAGER;
Expand All @@ -98,43 +99,43 @@ public class SessionHolder {
public static void init(String mode) {
if (StringUtils.isBlank(mode)) {
mode = CONFIG.getConfig(ConfigurationKeys.STORE_SESSION_MODE,
CONFIG.getConfig(ConfigurationKeys.STORE_MODE, SERVER_DEFAULT_STORE_MODE));
CONFIG.getConfig(ConfigurationKeys.STORE_MODE, SERVER_DEFAULT_STORE_MODE));
}
StoreMode storeMode = StoreMode.get(mode);
if (StoreMode.DB.equals(storeMode)) {
ROOT_SESSION_MANAGER = EnhancedServiceLoader.load(SessionManager.class, StoreMode.DB.getName());
ASYNC_COMMITTING_SESSION_MANAGER = EnhancedServiceLoader.load(SessionManager.class, StoreMode.DB.getName(),
new Object[] {ASYNC_COMMITTING_SESSION_MANAGER_NAME});
new Object[]{ASYNC_COMMITTING_SESSION_MANAGER_NAME});
RETRY_COMMITTING_SESSION_MANAGER = EnhancedServiceLoader.load(SessionManager.class, StoreMode.DB.getName(),
new Object[] {RETRY_COMMITTING_SESSION_MANAGER_NAME});
new Object[]{RETRY_COMMITTING_SESSION_MANAGER_NAME});
RETRY_ROLLBACKING_SESSION_MANAGER = EnhancedServiceLoader.load(SessionManager.class, StoreMode.DB.getName(),
new Object[] {RETRY_ROLLBACKING_SESSION_MANAGER_NAME});
new Object[]{RETRY_ROLLBACKING_SESSION_MANAGER_NAME});

DISTRIBUTED_LOCKER = DistributedLockerFactory.getDistributedLocker(StoreMode.DB.getName());
} else if (StoreMode.FILE.equals(storeMode)) {
String sessionStorePath = CONFIG.getConfig(ConfigurationKeys.STORE_FILE_DIR,
DEFAULT_SESSION_STORE_FILE_DIR);
DEFAULT_SESSION_STORE_FILE_DIR);
if (StringUtils.isBlank(sessionStorePath)) {
throw new StoreException("the {store.file.dir} is empty.");
}
ROOT_SESSION_MANAGER = EnhancedServiceLoader.load(SessionManager.class, StoreMode.FILE.getName(),
new Object[] {ROOT_SESSION_MANAGER_NAME, sessionStorePath});
new Object[]{ROOT_SESSION_MANAGER_NAME, sessionStorePath});
ASYNC_COMMITTING_SESSION_MANAGER = EnhancedServiceLoader.load(SessionManager.class, StoreMode.FILE.getName(),
new Class[] {String.class, String.class}, new Object[] {ASYNC_COMMITTING_SESSION_MANAGER_NAME, null});
new Class[]{String.class, String.class}, new Object[]{ASYNC_COMMITTING_SESSION_MANAGER_NAME, null});
RETRY_COMMITTING_SESSION_MANAGER = EnhancedServiceLoader.load(SessionManager.class, StoreMode.FILE.getName(),
new Class[] {String.class, String.class}, new Object[] {RETRY_COMMITTING_SESSION_MANAGER_NAME, null});
new Class[]{String.class, String.class}, new Object[]{RETRY_COMMITTING_SESSION_MANAGER_NAME, null});
RETRY_ROLLBACKING_SESSION_MANAGER = EnhancedServiceLoader.load(SessionManager.class, StoreMode.FILE.getName(),
new Class[] {String.class, String.class}, new Object[] {RETRY_ROLLBACKING_SESSION_MANAGER_NAME, null});
new Class[]{String.class, String.class}, new Object[]{RETRY_ROLLBACKING_SESSION_MANAGER_NAME, null});

DISTRIBUTED_LOCKER = DistributedLockerFactory.getDistributedLocker(StoreMode.FILE.getName());
} else if (StoreMode.REDIS.equals(storeMode)) {
ROOT_SESSION_MANAGER = EnhancedServiceLoader.load(SessionManager.class, StoreMode.REDIS.getName());
ASYNC_COMMITTING_SESSION_MANAGER = EnhancedServiceLoader.load(SessionManager.class,
StoreMode.REDIS.getName(), new Object[] {ASYNC_COMMITTING_SESSION_MANAGER_NAME});
StoreMode.REDIS.getName(), new Object[]{ASYNC_COMMITTING_SESSION_MANAGER_NAME});
RETRY_COMMITTING_SESSION_MANAGER = EnhancedServiceLoader.load(SessionManager.class,
StoreMode.REDIS.getName(), new Object[] {RETRY_COMMITTING_SESSION_MANAGER_NAME});
StoreMode.REDIS.getName(), new Object[]{RETRY_COMMITTING_SESSION_MANAGER_NAME});
RETRY_ROLLBACKING_SESSION_MANAGER = EnhancedServiceLoader.load(SessionManager.class,
StoreMode.REDIS.getName(), new Object[] {RETRY_ROLLBACKING_SESSION_MANAGER_NAME});
StoreMode.REDIS.getName(), new Object[]{RETRY_ROLLBACKING_SESSION_MANAGER_NAME});

DISTRIBUTED_LOCKER = DistributedLockerFactory.getDistributedLocker(StoreMode.REDIS.getName());
} else {
Expand Down Expand Up @@ -178,12 +179,15 @@ protected static void reload(StoreMode storeMode) {
break;
case Committing:
case CommitRetrying:
lockBranchSessions(globalSession.getSortedBranches());
queueToRetryCommit(globalSession);
break;
default: {
lockBranchSessions(globalSession.getSortedBranches());

if (GlobalStatus.Rollbacking.equals(globalSession.getStatus())) {
globalSession.getBranchSessions().parallelStream().forEach(branchSession -> {
branchSession.setLockStatus(LockStatus.Rollbacking);
});
}
switch (globalStatus) {
case Rollbacking:
case RollbackRetrying:
Expand Down Expand Up @@ -357,7 +361,7 @@ public static GlobalSession findGlobalSession(String xid, boolean withBranchSess
* lock and execute
*
* @param globalSession the global session
* @param lockCallable the lock Callable
* @param lockCallable the lock Callable
* @return the value
*/
public static <T> T lockAndExecute(GlobalSession globalSession, GlobalSession.LockCallable<T> lockCallable)
Expand Down Expand Up @@ -386,8 +390,9 @@ public static boolean releaseDistributedLock(String lockKey) {

/**
* Execute the function after get the distribute lock
* @param key the distribute lock key
* @param func the function to be call
*
* @param key the distribute lock key
* @param func the function to be call
* @return whether the func be call
*/
public static boolean distributedLockAndExecute(String key, NoArgsFunc func) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,18 @@ public List<GlobalSession> findGlobalSessions(SessionCondition condition) {
}

if (!StringUtils.isEmpty(condition.getXid())) {
if (!Objects.equals(condition.getXid(), globalSession.getXid())) {
continue;
if (Objects.equals(condition.getXid(), globalSession.getXid())) {
// Only one will be found, just add and return
found.add(globalSession);
return found;
}
}

if (null != condition.getTransactionId() && condition.getTransactionId() > 0) {
if (!Objects.equals(condition.getTransactionId(), globalSession.getTransactionId())) {
continue;
if (Objects.equals(condition.getTransactionId(), globalSession.getTransactionId())) {
// Only one will be found, just add and return
found.add(globalSession);
return found;
}
}

Expand Down