From a422f2e0a0de85c245b690bbc18380e671cc2949 Mon Sep 17 00:00:00 2001 From: opensnail <598092184@qq.com> Date: Mon, 22 Apr 2024 18:14:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(sj=5F1.0.0):=20=E5=88=A0=E9=99=A4=E5=88=86?= =?UTF-8?q?=E5=8C=BA=E9=85=8D=E7=BD=AEtotal-partition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/config/SystemProperties.java | 5 --- .../src/main/resources/application.yml | 1 - .../service/impl/GroupConfigServiceImpl.java | 37 +++++++++++-------- .../service/impl/SceneConfigServiceImpl.java | 4 ++ 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/snail-job-server/snail-job-server-common/src/main/java/com/aizuda/snailjob/server/common/config/SystemProperties.java b/snail-job-server/snail-job-server-common/src/main/java/com/aizuda/snailjob/server/common/config/SystemProperties.java index 4cc2db119..e8c02ba51 100644 --- a/snail-job-server/snail-job-server-common/src/main/java/com/aizuda/snailjob/server/common/config/SystemProperties.java +++ b/snail-job-server/snail-job-server-common/src/main/java/com/aizuda/snailjob/server/common/config/SystemProperties.java @@ -37,11 +37,6 @@ public class SystemProperties { */ private int nettyPort = 1788; - /** - * 分区数 - */ - private int totalPartition = 32; - /** * 一个客户端每秒最多接收的重试数量指令 */ diff --git a/snail-job-server/snail-job-server-starter/src/main/resources/application.yml b/snail-job-server/snail-job-server-starter/src/main/resources/application.yml index 472e619f0..fab22bc8a 100644 --- a/snail-job-server/snail-job-server-starter/src/main/resources/application.yml +++ b/snail-job-server/snail-job-server-starter/src/main/resources/application.yml @@ -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) diff --git a/snail-job-server/snail-job-server-web/src/main/java/com/aizuda/snailjob/server/web/service/impl/GroupConfigServiceImpl.java b/snail-job-server/snail-job-server-web/src/main/java/com/aizuda/snailjob/server/web/service/impl/GroupConfigServiceImpl.java index 3f015b6b0..117265fbc 100644 --- a/snail-job-server/snail-job-server-web/src/main/java/com/aizuda/snailjob/server/web/service/impl/GroupConfigServiceImpl.java +++ b/snail-job-server/snail-job-server-web/src/main/java/com/aizuda/snailjob/server/web/service/impl/GroupConfigServiceImpl.java @@ -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 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 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 tableList = Lists.newArrayList(); - for (int i = 0; i < systemProperties.getTotalPartition(); i++) { - tableList.add(i); - } - return tableList; + return Lists.newArrayList(); } } diff --git a/snail-job-server/snail-job-server-web/src/main/java/com/aizuda/snailjob/server/web/service/impl/SceneConfigServiceImpl.java b/snail-job-server/snail-job-server-web/src/main/java/com/aizuda/snailjob/server/web/service/impl/SceneConfigServiceImpl.java index 885da640e..5759c2f52 100644 --- a/snail-job-server/snail-job-server-web/src/main/java/com/aizuda/snailjob/server/web/service/impl/SceneConfigServiceImpl.java +++ b/snail-job-server/snail-job-server-web/src/main/java/com/aizuda/snailjob/server/web/service/impl/SceneConfigServiceImpl.java @@ -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)));