feat(sj_1.0.0): 删除分区配置total-partition

This commit is contained in:
opensnail 2024-04-22 18:14:45 +08:00
parent 0b928deda1
commit a422f2e0a0
4 changed files with 26 additions and 21 deletions

View File

@ -37,11 +37,6 @@ public class SystemProperties {
*/
private int nettyPort = 1788;
/**
* 分区数
*/
private int totalPartition = 32;
/**
* 一个客户端每秒最多接收的重试数量指令
*/

View File

@ -68,7 +68,6 @@ snail-job:
retry-pull-page-size: 1000 # 拉取重试数据的每批次的大小
job-pull-page-size: 1000 # 拉取重试数据的每批次的大小
netty-port: 1788 # 服务端netty端口
total-partition: 2 # 重试和死信表的分区总数
limiter: 1000 # 一个客户端每秒最多接收的重试数量指令
step: 100 # 号段模式下步长配置
log-storage: 90 # 日志保存时间(单位: day)

View File

@ -94,12 +94,12 @@ public class GroupConfigServiceImpl implements GroupConfigService {
() -> new SnailJobServerException("GroupName已经存在 {}", groupConfigRequestVO.getGroupName()));
// 保存组配置
doSaveGroupConfig(systemUser, groupConfigRequestVO);
Boolean isSuccess = doSaveGroupConfig(systemUser, groupConfigRequestVO);
// 保存生成唯一id配置
doSaveSequenceAlloc(systemUser, groupConfigRequestVO);
return Boolean.TRUE;
return isSuccess;
}
/**
@ -123,6 +123,11 @@ public class GroupConfigServiceImpl implements GroupConfigService {
@Transactional
public Boolean updateGroup(GroupConfigRequestVO groupConfigRequestVO) {
List<Integer> tablePartitionList = getTablePartitionList();
if (CollectionUtils.isEmpty(tablePartitionList)) {
return Boolean.FALSE;
}
String groupName = groupConfigRequestVO.getGroupName();
String namespaceId = UserSessionUtils.currentUserSession().getNamespaceId();
@ -140,8 +145,8 @@ public class GroupConfigServiceImpl implements GroupConfigService {
// 使用@TableField(value = "version", update= "%s+1") 进行更新version, 这里必须初始化一个值
groupConfig.setVersion(1);
groupConfig.setToken(null);
Assert.isTrue(systemProperties.getTotalPartition() > groupConfigRequestVO.getGroupPartition(),
() -> new SnailJobServerException("分区超过最大分区. [{}]", systemProperties.getTotalPartition() - 1));
Assert.isTrue(tablePartitionList.contains(groupConfigRequestVO.getGroupPartition()),
() -> new SnailJobServerException("分区不存在. [{}]", tablePartitionList));
Assert.isTrue(groupConfigRequestVO.getGroupPartition() >= 0,
() -> new SnailJobServerException("分区不能是负数."));
@ -223,7 +228,12 @@ public class GroupConfigServiceImpl implements GroupConfigService {
return pageResult;
}
private void doSaveGroupConfig(UserSessionVO systemUser, GroupConfigRequestVO groupConfigRequestVO) {
private boolean doSaveGroupConfig(UserSessionVO systemUser, GroupConfigRequestVO groupConfigRequestVO) {
List<Integer> tablePartitionList = getTablePartitionList();
if (CollectionUtils.isEmpty(tablePartitionList)) {
return Boolean.FALSE;
}
GroupConfig groupConfig = GroupConfigConverter.INSTANCE.convert(groupConfigRequestVO);
groupConfig.setCreateDt(LocalDateTime.now());
groupConfig.setVersion(1);
@ -233,10 +243,10 @@ public class GroupConfigServiceImpl implements GroupConfigService {
groupConfig.setDescription(Optional.ofNullable(groupConfigRequestVO.getDescription()).orElse(StrUtil.EMPTY));
if (Objects.isNull(groupConfigRequestVO.getGroupPartition())) {
groupConfig.setGroupPartition(
HashUtil.bkdrHash(groupConfigRequestVO.getGroupName()) % systemProperties.getTotalPartition());
HashUtil.bkdrHash(groupConfigRequestVO.getGroupName()) % tablePartitionList.size());
} else {
Assert.isTrue(systemProperties.getTotalPartition() > groupConfigRequestVO.getGroupPartition(),
() -> new SnailJobServerException("分区超过最大分区. [{}]", systemProperties.getTotalPartition() - 1));
Assert.isTrue(tablePartitionList.contains(groupConfigRequestVO.getGroupPartition()),
() -> new SnailJobServerException("分区不存在. [{}]", tablePartitionList));
Assert.isTrue(groupConfigRequestVO.getGroupPartition() >= 0,
() -> new SnailJobServerException("分区不能是负数."));
}
@ -249,6 +259,8 @@ public class GroupConfigServiceImpl implements GroupConfigService {
// 校验retry_task_x和retry_dead_letter_x是否存在
checkGroupPartition(groupConfig, systemUser.getNamespaceId());
return Boolean.TRUE;
}
/**
@ -369,7 +381,7 @@ public class GroupConfigServiceImpl implements GroupConfigService {
}
return tableList.stream().map(ReUtil::getFirstNumber).filter(i ->
!Objects.isNull(i) && i <= systemProperties.getTotalPartition()).distinct()
!Objects.isNull(i)).distinct()
.collect(Collectors.toList());
} catch (SQLException ignored) {
} finally {
@ -381,12 +393,7 @@ public class GroupConfigServiceImpl implements GroupConfigService {
}
}
// 兜底
List<Integer> tableList = Lists.newArrayList();
for (int i = 0; i < systemProperties.getTotalPartition(); i++) {
tableList.add(i);
}
return tableList;
return Lists.newArrayList();
}
}

View File

@ -99,6 +99,10 @@ public class SceneConfigServiceImpl implements SceneConfigService {
RetrySceneConfig retrySceneConfig = SceneConfigConverter.INSTANCE.toSceneConfigRequestVO(requestVO);
retrySceneConfig.setCreateDt(LocalDateTime.now());
retrySceneConfig.setNamespaceId(namespaceId);
if (requestVO.getBackOff() == WaitStrategies.WaitStrategyEnum.DELAY_LEVEL.getType()) {
retrySceneConfig.setTriggerInterval(StrUtil.EMPTY);
}
Assert.isTrue(1 == sceneConfigAccess.insert(retrySceneConfig),
() -> new SnailJobServerException("failed to insert scene. retrySceneConfig:[{}]",
JsonUtil.toJsonString(retrySceneConfig)));