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

feature: Realize the interface of console: get global session and global lock in the redis mode #4281

Merged
merged 54 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
dd38eae
通用分页计算
doubleDimple Jan 3, 2022
1d2bce2
redis query globalsession(if request param isnull) commit
doubleDimple Jan 9, 2022
7dde6f4
redis query globalsession(if request param isnull) commit
doubleDimple Jan 9, 2022
6c2d330
redis query globalsession third commit
doubleDimple Jan 10, 2022
9c41301
redis query globalsession third commit
doubleDimple Jan 10, 2022
a772160
redis query globalsession third commit
doubleDimple Jan 10, 2022
806f812
Merge branch 'develop' into develop
doubleDimple Jan 11, 2022
edac1e4
redis query globalsession five commit
doubleDimple Jan 11, 2022
143cf18
Merge remote-tracking branch 'origin/develop' into develop
doubleDimple Jan 11, 2022
ff833d1
add test case code
Jan 13, 2022
85b66ec
Merge branch 'seata:develop' into develop
doubleDimple Jan 13, 2022
1429677
add redis query globalSession by page test code
doubleDimple Jan 13, 2022
c6970e6
add redis query globalSession by page test code
doubleDimple Jan 13, 2022
75e2b68
add redis query globalSession by page test code
doubleDimple Jan 13, 2022
02fa91b
Merge branch 'seata:develop' into develop
doubleDimple Jan 13, 2022
3c2c268
add test case code
doubleDimple Jan 14, 2022
ce9886a
add redis mode query globalLock code submit
doubleDimple Jan 14, 2022
0572e16
add globalSessionService test code
doubleDimple Jan 14, 2022
dbb4376
Merge branch 'seata:develop' into develop
doubleDimple Jan 14, 2022
dcceeff
add author
doubleDimple Jan 14, 2022
19bf5a6
Merge remote-tracking branch 'origin/develop' into develop
doubleDimple Jan 14, 2022
db243ec
qery redis globalSession and globalLock optimize
doubleDimple Jan 15, 2022
5c68d2c
add author
doubleDimple Jan 17, 2022
bc04c40
update test case
doubleDimple Jan 17, 2022
2b7edb3
Merge branch 'seata:develop' into develop
doubleDimple Jan 17, 2022
db0326c
code format
doubleDimple Jan 17, 2022
ee798d4
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Jan 22, 2022
348a0a2
update changes.md
doubleDimple Jan 22, 2022
c4993fc
optimize
doubleDimple Jan 22, 2022
4328c07
Merge branch 'develop' into develop
doubleDimple Jan 23, 2022
bf62829
Merge branch 'develop' into develop
funky-eyes Jan 24, 2022
6c87f34
optimize
doubleDimple Jan 25, 2022
1c7b8f7
Merge branch 'seata:develop' into develop
doubleDimple Jan 25, 2022
82580c7
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Jan 26, 2022
e6f8194
global lock 查询增加参数resourceId,pk,tableName
doubleDimple Jan 26, 2022
8e3fa32
Merge branch 'seata:develop' into develop
doubleDimple Jan 26, 2022
f663515
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Feb 7, 2022
4899fa8
optimize
doubleDimple Feb 7, 2022
3d9b17c
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Feb 8, 2022
4baba76
close piplied
doubleDimple Feb 8, 2022
7bba2bb
Merge branch 'develop' into develop
doubleDimple Feb 9, 2022
575c879
add rowLockkey test
doubleDimple Feb 10, 2022
e917094
add rowLockkey test
doubleDimple Feb 10, 2022
ac85f0e
optimize query globalSession condition judge
doubleDimple Feb 13, 2022
d6ee786
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Feb 16, 2022
0dbad8b
Resolve code conflicts
doubleDimple Feb 16, 2022
08a0347
Merge branch 'develop' into develop
doubleDimple Feb 17, 2022
8ecea26
Merge branch 'develop' into develop
doubleDimple Feb 22, 2022
20e9318
optimize error prompt
doubleDimple Feb 22, 2022
770bb77
optimize error prompt
doubleDimple Feb 22, 2022
3811a43
optimize code empty line
doubleDimple Feb 23, 2022
5dd5f4d
Merge branch 'develop' into develop
doubleDimple Feb 23, 2022
bf319cc
Merge branch 'develop' into develop
doubleDimple Feb 24, 2022
5dac2cc
update redis local connection
doubleDimple Feb 24, 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
2 changes: 2 additions & 0 deletions changes/1.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
- [[#3968](https://github.com/seata/seata/pull/3968)] 支持 brpc-java RPC框架
- [[#4134](https://github.com/seata/seata/pull/4134)] 初始化控制台基础代码
- [[#4268](https://github.com/seata/seata/pull/4268)] 控制台Global Session页面File模式实现
- [[#4281](https://github.com/seata/seata/pull/4281)] 控制台Global Session页面和Global LockRedis模式实现
- [[#4293](https://github.com/seata/seata/pull/4293)] 控制台Global Lock页面File模式实现
- [[#4335](https://github.com/seata/seata/pull/4335)] 实现配置中心上传配置交互脚本(nacos,etcd3)
- [[#4332](https://github.com/seata/seata/pull/4332)] 实现配置中心上传配置交互脚本(apollo,consul,zk)
Expand Down Expand Up @@ -230,6 +231,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
- [anselleeyy](https://github.com/anselleeyy)
- [GoodBoyCoder](https://github.com/GoodBoyCoder)
- [xiaochangbai](https://github.com/xiaochangbai)
- [doubleDimple](https://github.com/doubleDimple)
- [imherewait](https://github.com/imherewait)
- [wangyuewen](https://github.com/2858917634)

Expand Down
2 changes: 2 additions & 0 deletions changes/en-us/1.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- [[#3968](https://github.com/seata/seata/pull/3968)] support brpc-java RPC framework
- [[#4134](https://github.com/seata/seata/pull/4134)] init the console basic code
- [[#4268](https://github.com/seata/seata/pull/4268)] query global session in the file mode
- [[#4281](https://github.com/seata/seata/pull/4281)] query global session and global lock in the redis mode
- [[#4293](https://github.com/seata/seata/pull/4293)] get global lock in the file mode
- [[#4335](https://github.com/seata/seata/pull/4335)] Realize configuration center upload configuration interactive script (nacos,etcd3)
- [[#4332](https://github.com/seata/seata/pull/4332)] Realize configuration center upload configuration interactive script (apollo,consul,zk)
Expand Down Expand Up @@ -232,6 +233,7 @@
- [anselleeyy](https://github.com/anselleeyy)
- [GoodBoyCoder](https://github.com/GoodBoyCoder)
- [xiaochangbai](https://github.com/xiaochangbai)
- [doubleDimple](https://github.com/doubleDimple)
- [imherewait](https://github.com/imherewait)
- [wangyuewen](https://github.com/2858917634)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public class GlobalLockParam extends BaseParam implements Serializable {
* the branch id
*/
private String branchId;
/**
* the primary Key
*/
private String pk;
/**
* the resourceId
*/
private String resourceId;

public String getTransactionId() {
return transactionId;
Expand Down Expand Up @@ -74,13 +82,31 @@ public void setTableName(String tableName) {
this.tableName = tableName;
}

public String getPk() {
return pk;
}

public void setPk(String pk) {
this.pk = pk;
}

public String getResourceId() {
return resourceId;
}

public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}

@Override
public String toString() {
return "GlobalLockParam{" +
"xid='" + xid + '\'' +
", tableName='" + tableName + '\'' +
", transactionId='" + transactionId + '\'' +
", branchId='" + branchId + '\'' +
", pk='" + pk + '\'' +
", resourceId='" + resourceId + '\'' +
'}';
}
}
34 changes: 31 additions & 3 deletions core/src/main/java/io/seata/core/console/result/PageResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
*/
package io.seata.core.console.result;

import java.io.Serializable;
import java.util.List;

import io.seata.common.exception.FrameworkErrorCode;
import io.seata.core.console.param.BaseParam;

import java.io.Serializable;
import java.util.List;
/**
* The page result
* @author: zhongxiang.wang
* @author miaoxueyu
* @author doubleDimple
*/
public class PageResult<T> extends Result<T> implements Serializable {
private static final long serialVersionUID = 7761262662429121287L;
Expand Down Expand Up @@ -84,6 +85,20 @@ public static <T> PageResult<T> build(List<T> list, Integer pageNum, Integer pag
);
}

public PageResult(List<T> data, Integer total, Integer pageNum, Integer pageSize) {
super(SUCCESS_CODE, SUCCESS_MSG);
this.total = total;
this.pageNum = pageNum;
this.pageSize = pageSize;
this.data = data;

if (total % pageSize == 0) {
this.pages = total / pageSize;
} else {
this.pages = total / pageSize + 1;
}
}

public static <T> PageResult<T> failure(String code, String msg) {
return new PageResult<>(code, msg);
}
Expand All @@ -99,6 +114,19 @@ public static <T> PageResult<T> success() {
public static <T> PageResult<T> success(List<T> data, Integer total, Integer pages, Integer pageNum, Integer pageSize) {
return new PageResult<>(data, total, pages, pageNum, pageSize);
}
public static <T> PageResult<T> success(List<T> data, Integer total, Integer pageNum, Integer pageSize) {
return new PageResult<>(data, total, pageNum, pageSize);
}

public static void checkPage(BaseParam param) {
if (param.getPageNum() <= 0) {
param.setPageNum(1);
}

if (param.getPageSize() <= 0) {
param.setPageSize(20);
}
}

public Integer getTotal() {
return total;
Expand Down
15 changes: 15 additions & 0 deletions core/src/main/java/io/seata/core/constants/RedisKeyConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,19 @@ public class RedisKeyConstants {
*/
public static final String REDIS_KEY_BRANCH_GMT_MODIFIED = "gmtModified";

/**
* The globalLock key
*/
public static final String DEFAULT_REDIS_SEATA_GLOBAL_LOCK_PREFIX = "SEATA_GLOBAL_LOCK";
doubleDimple marked this conversation as resolved.
Show resolved Hide resolved

/**
* The globalLock keys
*/
public static final String DEFAULT_REDIS_SEATA_ROW_LOCK_PREFIX = "SEATA_ROW_LOCK_";

/**
* The split
*/
public static final String SPLIT = "^^^";

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@
*/
package io.seata.server.console.impl.redis;

import io.seata.common.exception.NotSupportYetException;
import io.seata.core.console.vo.BranchSessionVO;
import java.util.ArrayList;
import java.util.List;
import io.seata.common.util.CollectionUtils;
import io.seata.common.util.StringUtils;
import io.seata.core.console.result.PageResult;
import io.seata.core.console.vo.BranchSessionVO;
import io.seata.core.store.BranchTransactionDO;
import io.seata.server.console.service.BranchSessionService;
import io.seata.server.storage.redis.store.RedisTransactionStoreManager;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;

/**
* Branch Session Redis ServiceImpl
*
* @author: zhongxiang.wang
* @author: doubleDimple
*/
@Component
@org.springframework.context.annotation.Configuration
Expand All @@ -33,6 +41,24 @@ public class BranchSessionRedisServiceImpl implements BranchSessionService {

@Override
public PageResult<BranchSessionVO> queryByXid(String xid) {
throw new NotSupportYetException();
if (StringUtils.isBlank(xid)) {
return PageResult.success();
}

List<BranchSessionVO> branchSessionVos = new ArrayList<>();

RedisTransactionStoreManager instance = RedisTransactionStoreManager.getInstance();

List<BranchTransactionDO> branchSessionDos = instance.findBranchSessionByXid(xid);

if (CollectionUtils.isNotEmpty(branchSessionDos)) {
for (BranchTransactionDO branchSessionDo : branchSessionDos) {
BranchSessionVO branchSessionVO = new BranchSessionVO();
BeanUtils.copyProperties(branchSessionDo, branchSessionVO);
branchSessionVos.add(branchSessionVO);
}
}

return PageResult.success(branchSessionVos, branchSessionVos.size(), 0, branchSessionVos.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,34 @@
*/
package io.seata.server.console.impl.redis;

import io.seata.common.exception.NotSupportYetException;


doubleDimple marked this conversation as resolved.
Show resolved Hide resolved
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import io.seata.common.util.CollectionUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import io.seata.common.util.BeanUtils;
import io.seata.core.console.param.GlobalLockParam;
import io.seata.core.console.vo.GlobalLockVO;
import io.seata.core.console.result.PageResult;
import io.seata.core.console.vo.GlobalLockVO;
import io.seata.server.console.service.GlobalLockService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import io.seata.server.storage.redis.JedisPooledFactory;
import redis.clients.jedis.Jedis;
import static io.seata.common.Constants.ROW_LOCK_KEY_SPLIT_CHAR;
import static io.seata.common.exception.FrameworkErrorCode.ParameterRequired;
import static io.seata.common.util.StringUtils.isNotBlank;
import static io.seata.core.console.result.PageResult.checkPage;
import static io.seata.core.constants.RedisKeyConstants.DEFAULT_REDIS_SEATA_GLOBAL_LOCK_PREFIX;
import static io.seata.core.constants.RedisKeyConstants.DEFAULT_REDIS_SEATA_ROW_LOCK_PREFIX;
import static io.seata.core.constants.RedisKeyConstants.SPLIT;

/**
* Global Lock Redis Service Impl
* @author: zhongxiang.wang
* @author: doubleDimple
*/
@Component
@org.springframework.context.annotation.Configuration
Expand All @@ -34,7 +51,71 @@ public class GlobalLockRedisServiceImpl implements GlobalLockService {

@Override
public PageResult<GlobalLockVO> query(GlobalLockParam param) {
throw new NotSupportYetException();

doubleDimple marked this conversation as resolved.
Show resolved Hide resolved
int total = 0;
List<GlobalLockVO> globalLockVos;
checkPage(param);
if (isNotBlank(param.getXid())) {
globalLockVos = queryGlobalByXid(param.getXid());
total = globalLockVos.size();
return PageResult.success(globalLockVos,total,param.getPageNum(),param.getPageSize());
} else if (isNotBlank(param.getTableName()) && isNotBlank(param.getPk()) && isNotBlank(param.getResourceId())) {
doubleDimple marked this conversation as resolved.
Show resolved Hide resolved
//SEATA_ROW_LOCK_jdbc:mysql://116.62.62.26/seata-order^^^order^^^2188
String tableName = param.getTableName();
String pk = param.getPk();
String resourceId = param.getResourceId();
globalLockVos = queryGlobalLockByRowKey(buildRowKey(tableName,pk,resourceId));
total = globalLockVos.size();
return PageResult.success(globalLockVos,total,param.getPageNum(),param.getPageSize());
funky-eyes marked this conversation as resolved.
Show resolved Hide resolved
} else {
return PageResult.failure(ParameterRequired.getErrCode(),"only three parameters of tableName,pk,resourceId or Xid are supported");
}
}

private List<GlobalLockVO> queryGlobalLockByRowKey(String buildRowKey) {
return readGlobalLockByRowKey(buildRowKey);
}

private String buildRowKey(String tableName, String pk,String resourceId) {
return DEFAULT_REDIS_SEATA_ROW_LOCK_PREFIX + resourceId + SPLIT + tableName + SPLIT + pk;
}


private List<GlobalLockVO> queryGlobalByXid(String xid) {
return readGlobalLockByXid(DEFAULT_REDIS_SEATA_GLOBAL_LOCK_PREFIX + xid);
}

private List<GlobalLockVO> readGlobalLockByXid(String key) {
List<GlobalLockVO> vos = new ArrayList<>();
try (Jedis jedis = JedisPooledFactory.getJedisInstance()) {
Map<String, String> mapGlobalKeys = jedis.hgetAll(key);
if (CollectionUtils.isNotEmpty(mapGlobalKeys)) {
List<String> rowLockKeys = new ArrayList<>();
mapGlobalKeys.forEach((k,v) -> rowLockKeys.addAll(Arrays.asList(v.split(ROW_LOCK_KEY_SPLIT_CHAR))));
for (String rowLoclKey : rowLockKeys) {
Map<String, String> mapRowLockKey = jedis.hgetAll(rowLoclKey);
GlobalLockVO vo = (GlobalLockVO)BeanUtils.mapToObject(mapRowLockKey, GlobalLockVO.class);
if (vo != null) {
vos.add(vo);
}
}
}
}

return vos;
}


private List<GlobalLockVO> readGlobalLockByRowKey(String key) {
List<GlobalLockVO> vos = new ArrayList<>();
try (Jedis jedis = JedisPooledFactory.getJedisInstance()) {
Map<String, String> map = jedis.hgetAll(key);
doubleDimple marked this conversation as resolved.
Show resolved Hide resolved
GlobalLockVO vo = (GlobalLockVO)BeanUtils.mapToObject(map, GlobalLockVO.class);
if (vo != null) {
vos.add(vo);
}
}
return vos;
}

}
Loading