Merge pull request #1105 from WEIZIBIN/fix_graceful_shutdown_unregister_fast

优雅停机时,admin快速注销执行器地址
pull/14/head
许雪里 5 years ago committed by GitHub
commit 4a0fe49b26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,6 +16,10 @@ public interface XxlJobGroupDao {
public List<XxlJobGroup> findByAddressType(@Param("addressType") int addressType); public List<XxlJobGroup> findByAddressType(@Param("addressType") int addressType);
public List<XxlJobGroup> findAutoRegisterGroupByAppName(@Param("appName") String appName);
public int updateAddressListById(@Param("id") int id, @Param("addressList") String addressList);
public int save(XxlJobGroup xxlJobGroup); public int save(XxlJobGroup xxlJobGroup);
public int update(XxlJobGroup xxlJobGroup); public int update(XxlJobGroup xxlJobGroup);

@ -1,10 +1,12 @@
package com.xxl.job.admin.service.impl; package com.xxl.job.admin.service.impl;
import com.xxl.job.admin.core.model.XxlJobGroup;
import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.model.XxlJobLog; import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.core.thread.JobTriggerPoolHelper; import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
import com.xxl.job.admin.core.trigger.TriggerTypeEnum; import com.xxl.job.admin.core.trigger.TriggerTypeEnum;
import com.xxl.job.admin.core.util.I18nUtil; import com.xxl.job.admin.core.util.I18nUtil;
import com.xxl.job.admin.dao.XxlJobGroupDao;
import com.xxl.job.admin.dao.XxlJobInfoDao; import com.xxl.job.admin.dao.XxlJobInfoDao;
import com.xxl.job.admin.dao.XxlJobLogDao; import com.xxl.job.admin.dao.XxlJobLogDao;
import com.xxl.job.admin.dao.XxlJobRegistryDao; import com.xxl.job.admin.dao.XxlJobRegistryDao;
@ -16,6 +18,8 @@ import com.xxl.job.core.handler.IJobHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.text.MessageFormat; import java.text.MessageFormat;
@ -35,6 +39,8 @@ public class AdminBizImpl implements AdminBiz {
private XxlJobInfoDao xxlJobInfoDao; private XxlJobInfoDao xxlJobInfoDao;
@Resource @Resource
private XxlJobRegistryDao xxlJobRegistryDao; private XxlJobRegistryDao xxlJobRegistryDao;
@Resource
private XxlJobGroupDao xxlJobGroupDao;
@Override @Override
@ -132,8 +138,40 @@ public class AdminBizImpl implements AdminBiz {
@Override @Override
public ReturnT<String> registryRemove(RegistryParam registryParam) { public ReturnT<String> registryRemove(RegistryParam registryParam) {
xxlJobRegistryDao.registryDelete(registryParam.getRegistGroup(), registryParam.getRegistryKey(), registryParam.getRegistryValue()); int ret = xxlJobRegistryDao.registryDelete(registryParam.getRegistGroup(), registryParam.getRegistryKey(), registryParam.getRegistryValue());
if (ret == 1) {
List<XxlJobGroup> autoRegisterGroups = xxlJobGroupDao.findAutoRegisterGroupByAppName(registryParam.getRegistryKey());
removeRegisterFromGroups(autoRegisterGroups, registryParam.getRegistryValue());
}
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }
private void removeRegisterFromGroups(List<XxlJobGroup> groups, String address) {
if (StringUtils.isEmpty(address)) {
return;
}
if (CollectionUtils.isEmpty(groups)) {
return;
}
for (XxlJobGroup group : groups) {
List<String> addressList = group.getRegistryList();
if (addressList == null) {
continue;
}
if (!addressList.contains(address)) {
continue;
}
addressList.remove(address);
String newAddressListStr = StringUtils.collectionToCommaDelimitedString(addressList);
String oldAddressListStr = group.getAddressList();
int update = xxlJobGroupDao.updateAddressListById(group.getId(), newAddressListStr);
if (logger.isDebugEnabled()) {
logger.debug("update group name [{}] title [{}] old address list [{}] new address list [{}] update result [{}]",
group.getAppName(), group.getTitle(), oldAddressListStr, newAddressListStr, update);
}
}
}
} }

@ -27,6 +27,13 @@
ORDER BY t.order ASC ORDER BY t.order ASC
</select> </select>
<select id="findAutoRegisterGroupByAppName" resultMap="XxlJobGroup">
SELECT <include refid="Base_Column_List" />
FROM xxl_job_group AS t
WHERE `app_name` = #{appName}
AND `address_type` = 0
</select>
<select id="findByAddressType" parameterType="java.lang.Integer" resultMap="XxlJobGroup"> <select id="findByAddressType" parameterType="java.lang.Integer" resultMap="XxlJobGroup">
SELECT <include refid="Base_Column_List" /> SELECT <include refid="Base_Column_List" />
FROM xxl_job_group AS t FROM xxl_job_group AS t
@ -49,6 +56,12 @@
WHERE id = #{id} WHERE id = #{id}
</update> </update>
<update id="updateAddressListById">
UPDATE xxl_job_group
SET `address_list` = #{addressList}
WHERE id = #{id}
</update>
<delete id="remove" parameterType="java.lang.Integer" > <delete id="remove" parameterType="java.lang.Integer" >
DELETE FROM xxl_job_group DELETE FROM xxl_job_group
WHERE id = #{id} WHERE id = #{id}

@ -86,6 +86,9 @@ public class XxlJobExecutor {
initRpcProvider(ip, port, appName, accessToken); initRpcProvider(ip, port, appName, accessToken);
} }
public void destroy(){ public void destroy(){
// destory executor-server
stopRpcProvider();
// destory jobThreadRepository // destory jobThreadRepository
if (jobThreadRepository.size() > 0) { if (jobThreadRepository.size() > 0) {
for (Map.Entry<Integer, JobThread> item: jobThreadRepository.entrySet()) { for (Map.Entry<Integer, JobThread> item: jobThreadRepository.entrySet()) {
@ -102,9 +105,6 @@ public class XxlJobExecutor {
// destory TriggerCallbackThread // destory TriggerCallbackThread
TriggerCallbackThread.getInstance().toStop(); TriggerCallbackThread.getInstance().toStop();
// destory executor-server
stopRpcProvider();
// destory invoker // destory invoker
stopInvokerFactory(); stopInvokerFactory();
} }

Loading…
Cancel
Save