Skip to content

Commit

Permalink
#343 NoTraffic executor should not take over the failover shard
Browse files Browse the repository at this point in the history
  • Loading branch information
heziai committed Jan 19, 2018
1 parent e4a26f3 commit ed2d0f2
Showing 1 changed file with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,40 @@
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* </p>
*/

package com.vip.saturn.job.internal.failover;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;

import com.vip.saturn.job.basic.AbstractSaturnService;
import com.vip.saturn.job.basic.JobScheduler;
import com.vip.saturn.job.internal.config.ConfigurationNode;
import com.vip.saturn.job.internal.execution.ExecutionNode;
import com.vip.saturn.job.internal.storage.JobNodePath;
import com.vip.saturn.job.internal.storage.LeaderExecutionCallback;
import com.vip.saturn.job.sharding.node.SaturnExecutorsNode;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.vip.saturn.job.basic.AbstractSaturnService;
import com.vip.saturn.job.basic.JobScheduler;
import com.vip.saturn.job.internal.config.ConfigurationNode;
import com.vip.saturn.job.internal.execution.ExecutionNode;
import com.vip.saturn.job.internal.storage.LeaderExecutionCallback;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
* 作业失效转移服务.
*
* @author dylan.xue
*/
public class FailoverService extends AbstractSaturnService {

static Logger log = LoggerFactory.getLogger(FailoverService.class);

public FailoverService(final JobScheduler jobScheduler) {
Expand All @@ -48,7 +49,7 @@ public void start() {

/**
* 设置失效的分片项标记.
*
*
* @param item 崩溃的作业项
*/
public void createCrashedFailoverFlag(final int item) {
Expand Down Expand Up @@ -90,7 +91,7 @@ && getJobNodeStorage().isJobNodeExisted(ConfigurationNode.ENABLED)

/**
* 更新执行完毕失效转移的分片项状态.
*
*
* @param item 执行完毕失效转移的分片项列表
*/
public void updateFailoverComplete(final Integer item) {
Expand All @@ -99,7 +100,7 @@ public void updateFailoverComplete(final Integer item) {

/**
* 获取运行在本作业服务器的失效转移序列号.
*
*
* @return 运行在本作业服务器的失效转移序列号
*/
public List<Integer> getLocalHostFailoverItems() {
Expand All @@ -119,7 +120,7 @@ public List<Integer> getLocalHostFailoverItems() {

/**
* 获取运行在本作业服务器的被失效转移的序列号.
*
*
* @return 运行在本作业服务器的被失效转移的序列号
*/
public List<Integer> getLocalHostTakeOffItems() {
Expand Down Expand Up @@ -153,6 +154,9 @@ public void execute() {
if (jobScheduler == null) {
return;
}
if (coordinatorRegistryCenter.isExisted(SaturnExecutorsNode.getExecutorNoTrafficNodePath(executorName))) {
return;
}
if (!jobScheduler.getConfigService().getPreferList().contains(executorName)
&& !jobScheduler.getConfigService().isUseDispreferList()) {
return;
Expand Down

0 comments on commit ed2d0f2

Please sign in to comment.