From 7894cfb28489fa31fd4fcc0b10d08c6795569251 Mon Sep 17 00:00:00 2001 From: opensnail <598092184@qq.com> Date: Thu, 13 Jun 2024 17:12:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(sj=5F1.1.0):=20=E4=BC=98=E5=8C=96=E8=B4=9F?= =?UTF-8?q?=E8=BD=BD=E5=9D=87=E8=A1=A1=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/AllocateMessageQueueAveragely.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/snail-job-server/snail-job-server-common/src/main/java/com/aizuda/snailjob/server/common/allocate/server/AllocateMessageQueueAveragely.java b/snail-job-server/snail-job-server-common/src/main/java/com/aizuda/snailjob/server/common/allocate/server/AllocateMessageQueueAveragely.java index 15564c91..abe9e277 100644 --- a/snail-job-server/snail-job-server-common/src/main/java/com/aizuda/snailjob/server/common/allocate/server/AllocateMessageQueueAveragely.java +++ b/snail-job-server/snail-job-server-common/src/main/java/com/aizuda/snailjob/server/common/allocate/server/AllocateMessageQueueAveragely.java @@ -1,6 +1,9 @@ package com.aizuda.snailjob.server.common.allocate.server; +import cn.hutool.core.collection.CollUtil; +import com.aizuda.snailjob.common.log.SnailJobLog; import com.aizuda.snailjob.server.common.ServerLoadBalance; +import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.List; @@ -17,10 +20,18 @@ public class AllocateMessageQueueAveragely implements ServerLoadBalance allocate(String currentCID, List bucketList, List serverList) { + if (CollUtil.isEmpty(serverList)) { + return Lists.newArrayList(); + } + List consumerBucket = new ArrayList<>(); // 找到当前消费者在消费者队列里面的下标 int index = serverList.indexOf(currentCID); + if (index < 0) { + SnailJobLog.LOCAL.warn("currentCID: [{}] not in serverList:[{}]", currentCID, serverList); + return Lists.newArrayList(); + } // 此处取余是为了判断队列与总消费者数的是否是整数倍 mod=0则是整数倍,否则不是 int mod = bucketList.size() % serverList.size();