blob: e911b22c62fb0a58309a2c1a6667417ba8dd1fd4 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.cluster.impl;
tom2d7c65f2014-09-23 01:09:35 -070017
HIGUCHI Yuta1979f552015-12-28 21:24:26 -080018import com.google.common.base.MoreObjects;
Jonathan Hart4a4d18f2015-03-26 12:16:16 -070019import com.google.common.collect.ImmutableSet;
20import com.google.common.collect.Maps;
Madan Jampanie3375062016-04-19 16:32:10 -070021
tom2d7c65f2014-09-23 01:09:35 -070022import org.apache.felix.scr.annotations.Activate;
23import org.apache.felix.scr.annotations.Component;
24import org.apache.felix.scr.annotations.Deactivate;
sangyun-hanf98df542016-03-24 20:28:03 +090025import org.apache.felix.scr.annotations.Modified;
26import org.apache.felix.scr.annotations.Property;
Madan Jampaniafeebbd2015-05-19 15:26:01 -070027import org.apache.felix.scr.annotations.Reference;
28import org.apache.felix.scr.annotations.ReferenceCardinality;
tom2d7c65f2014-09-23 01:09:35 -070029import org.apache.felix.scr.annotations.Service;
Madan Jampani7d2fab22015-03-18 17:21:57 -070030import org.joda.time.DateTime;
Ayaka Koshibedd91b842015-03-02 14:48:47 -080031import org.onlab.packet.IpAddress;
32import org.onlab.util.KryoNamespace;
sangyun-hanf98df542016-03-24 20:28:03 +090033import org.onlab.util.Tools;
sangyun-han9f0af2d2016-08-04 13:04:59 +090034import org.onosproject.cfg.ComponentConfigService;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import org.onosproject.cluster.ClusterEvent;
Madan Jampaniec1df022015-10-13 21:23:03 -070036import org.onosproject.cluster.ClusterMetadataService;
Brian O'Connorabafb502014-12-02 22:26:20 -080037import org.onosproject.cluster.ClusterStore;
38import org.onosproject.cluster.ClusterStoreDelegate;
39import org.onosproject.cluster.ControllerNode;
Ayaka Koshibedd91b842015-03-02 14:48:47 -080040import org.onosproject.cluster.ControllerNode.State;
Jonathan Hart4a4d18f2015-03-26 12:16:16 -070041import org.onosproject.cluster.DefaultControllerNode;
Brian O'Connorabafb502014-12-02 22:26:20 -080042import org.onosproject.cluster.NodeId;
Ayaka Koshibedd91b842015-03-02 14:48:47 -080043import org.onosproject.store.AbstractStore;
Madan Jampanic26eede2015-04-16 11:42:16 -070044import org.onosproject.store.cluster.messaging.Endpoint;
Madan Jampaniafeebbd2015-05-19 15:26:01 -070045import org.onosproject.store.cluster.messaging.MessagingService;
Ayaka Koshibedd91b842015-03-02 14:48:47 -080046import org.onosproject.store.serializers.KryoNamespaces;
HIGUCHI Yutae7290652016-05-18 11:29:01 -070047import org.onosproject.store.serializers.StoreSerializer;
sangyun-hanf98df542016-03-24 20:28:03 +090048import org.osgi.service.component.ComponentContext;
Ayaka Koshibedd91b842015-03-02 14:48:47 -080049import org.slf4j.Logger;
tom2d7c65f2014-09-23 01:09:35 -070050
sangyun-hanf98df542016-03-24 20:28:03 +090051import java.util.Dictionary;
Jonathan Hart4a4d18f2015-03-26 12:16:16 -070052import java.util.Map;
Thomas Vachuskafba7f3d2016-03-23 15:46:25 -070053import java.util.Objects;
Jonathan Hart4a4d18f2015-03-26 12:16:16 -070054import java.util.Set;
55import java.util.concurrent.ExecutorService;
56import java.util.concurrent.Executors;
57import java.util.concurrent.ScheduledExecutorService;
58import java.util.concurrent.TimeUnit;
Madan Jampanid36def02016-01-13 11:21:56 -080059import java.util.function.BiConsumer;
Jonathan Hart4a4d18f2015-03-26 12:16:16 -070060import java.util.stream.Collectors;
61
sangyun-hanf98df542016-03-24 20:28:03 +090062import static com.google.common.base.Preconditions.checkArgument;
Jonathan Hart4a4d18f2015-03-26 12:16:16 -070063import static com.google.common.base.Preconditions.checkNotNull;
64import static org.onlab.util.Tools.groupedThreads;
Thomas Vachuskafba7f3d2016-03-23 15:46:25 -070065import static org.onosproject.cluster.ClusterEvent.Type.INSTANCE_ACTIVATED;
66import static org.onosproject.cluster.ClusterEvent.Type.INSTANCE_DEACTIVATED;
67import static org.onosproject.cluster.ClusterEvent.Type.INSTANCE_READY;
Jonathan Hart4a4d18f2015-03-26 12:16:16 -070068import static org.slf4j.LoggerFactory.getLogger;
tom2d7c65f2014-09-23 01:09:35 -070069
tom2d7c65f2014-09-23 01:09:35 -070070@Component(immediate = true)
71@Service
Ayaka Koshibedd91b842015-03-02 14:48:47 -080072/**
73 * Distributed cluster nodes store that employs an accrual failure
74 * detector to identify cluster member up/down status.
75 */
tom0755a362014-09-24 11:54:43 -070076public class DistributedClusterStore
Ayaka Koshibedd91b842015-03-02 14:48:47 -080077 extends AbstractStore<ClusterEvent, ClusterStoreDelegate>
tomb41d1ac2014-09-24 01:51:24 -070078 implements ClusterStore {
tom2d7c65f2014-09-23 01:09:35 -070079
Thomas Vachuska8dc1a692015-03-31 01:01:37 -070080 private static final Logger log = getLogger(DistributedClusterStore.class);
tom2d7c65f2014-09-23 01:09:35 -070081
Thomas Vachuskade563cf2015-04-01 00:28:50 -070082 public static final String HEARTBEAT_MESSAGE = "onos-cluster-heartbeat";
83
sangyun-hanf98df542016-03-24 20:28:03 +090084 private static final int DEFAULT_HEARTBEAT_INTERVAL = 100;
85 @Property(name = "heartbeatInterval", intValue = DEFAULT_HEARTBEAT_INTERVAL,
86 label = "Interval time to send heartbeat to other controller nodes (millisecond)")
87 private int heartbeatInterval = DEFAULT_HEARTBEAT_INTERVAL;
88
89 private static final int DEFAULT_PHI_FAILURE_THRESHOLD = 10;
90 @Property(name = "phiFailureThreshold", intValue = DEFAULT_PHI_FAILURE_THRESHOLD,
91 label = "the value of Phi threshold to detect accrual failure")
92 private int phiFailureThreshold = DEFAULT_PHI_FAILURE_THRESHOLD;
tom2d7c65f2014-09-23 01:09:35 -070093
HIGUCHI Yutae7290652016-05-18 11:29:01 -070094 private static final StoreSerializer SERIALIZER = StoreSerializer.using(
95 KryoNamespace.newBuilder()
Thomas Vachuska8dc1a692015-03-31 01:01:37 -070096 .register(KryoNamespaces.API)
HIGUCHI Yutae7290652016-05-18 11:29:01 -070097 .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID)
Thomas Vachuska8dc1a692015-03-31 01:01:37 -070098 .register(HeartbeatMessage.class)
HIGUCHI Yutae7290652016-05-18 11:29:01 -070099 .build("ClusterStore"));
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800100
101 private static final String INSTANCE_ID_NULL = "Instance ID cannot be null";
102
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800103 private final Map<NodeId, ControllerNode> allNodes = Maps.newConcurrentMap();
104 private final Map<NodeId, State> nodeStates = Maps.newConcurrentMap();
Madan Jampani7d2fab22015-03-18 17:21:57 -0700105 private final Map<NodeId, DateTime> nodeStateLastUpdatedTimes = Maps.newConcurrentMap();
Thomas Vachuska7a8de842016-03-07 20:56:35 -0800106
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800107 private ScheduledExecutorService heartBeatSender = Executors.newSingleThreadScheduledExecutor(
HIGUCHI Yutad9e01052016-04-14 09:31:42 -0700108 groupedThreads("onos/cluster/membership", "heartbeat-sender", log));
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800109 private ExecutorService heartBeatMessageHandler = Executors.newSingleThreadExecutor(
HIGUCHI Yutad9e01052016-04-14 09:31:42 -0700110 groupedThreads("onos/cluster/membership", "heartbeat-receiver", log));
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800111
112 private PhiAccrualFailureDetector failureDetector;
113
114 private ControllerNode localNode;
115
Madan Jampaniafeebbd2015-05-19 15:26:01 -0700116 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Madan Jampaniec1df022015-10-13 21:23:03 -0700117 protected ClusterMetadataService clusterMetadataService;
Madan Jampaniafeebbd2015-05-19 15:26:01 -0700118
119 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
120 protected MessagingService messagingService;
121
sangyun-han9f0af2d2016-08-04 13:04:59 +0900122 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
123 protected ComponentConfigService cfgService;
124
tom2d7c65f2014-09-23 01:09:35 -0700125 @Activate
sangyun-han9f0af2d2016-08-04 13:04:59 +0900126 public void activate(ComponentContext context) {
127 cfgService.registerProperties(getClass());
128
129 modified(context);
130
Madan Jampaniec1df022015-10-13 21:23:03 -0700131 localNode = clusterMetadataService.getLocalNode();
Thomas Vachuska8dc1a692015-03-31 01:01:37 -0700132
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800133 messagingService.registerHandler(HEARTBEAT_MESSAGE,
Thomas Vachuska8dc1a692015-03-31 01:01:37 -0700134 new HeartbeatMessageHandler(), heartBeatMessageHandler);
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800135
136 failureDetector = new PhiAccrualFailureDetector();
137
138 heartBeatSender.scheduleWithFixedDelay(this::heartbeat, 0,
sangyun-hanf98df542016-03-24 20:28:03 +0900139 heartbeatInterval, TimeUnit.MILLISECONDS);
tomb41d1ac2014-09-24 01:51:24 -0700140
141 log.info("Started");
142 }
143
tom2d7c65f2014-09-23 01:09:35 -0700144 @Deactivate
145 public void deactivate() {
sangyun-han9f0af2d2016-08-04 13:04:59 +0900146 cfgService.unregisterProperties(getClass(), false);
Madan Jampaniafeebbd2015-05-19 15:26:01 -0700147 messagingService.unregisterHandler(HEARTBEAT_MESSAGE);
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800148 heartBeatSender.shutdownNow();
149 heartBeatMessageHandler.shutdownNow();
150
tom2d7c65f2014-09-23 01:09:35 -0700151 log.info("Stopped");
152 }
153
sangyun-hanf98df542016-03-24 20:28:03 +0900154 @Modified
155 public void modified(ComponentContext context) {
156 readComponentConfiguration(context);
157 restartHeartbeatSender();
158 }
159
tom2d7c65f2014-09-23 01:09:35 -0700160 @Override
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800161 public void setDelegate(ClusterStoreDelegate delegate) {
162 checkNotNull(delegate, "Delegate cannot be null");
163 this.delegate = delegate;
164 }
165
166 @Override
167 public void unsetDelegate(ClusterStoreDelegate delegate) {
168 this.delegate = null;
169 }
170
171 @Override
172 public boolean hasDelegate() {
173 return this.delegate != null;
174 }
175
176 @Override
tom2d7c65f2014-09-23 01:09:35 -0700177 public ControllerNode getLocalNode() {
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800178 return localNode;
tom2d7c65f2014-09-23 01:09:35 -0700179 }
180
181 @Override
182 public Set<ControllerNode> getNodes() {
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800183 return ImmutableSet.copyOf(allNodes.values());
tom2d7c65f2014-09-23 01:09:35 -0700184 }
185
186 @Override
187 public ControllerNode getNode(NodeId nodeId) {
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800188 checkNotNull(nodeId, INSTANCE_ID_NULL);
189 return allNodes.get(nodeId);
tom2d7c65f2014-09-23 01:09:35 -0700190 }
191
192 @Override
tomb41d1ac2014-09-24 01:51:24 -0700193 public State getState(NodeId nodeId) {
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800194 checkNotNull(nodeId, INSTANCE_ID_NULL);
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800195 return MoreObjects.firstNonNull(nodeStates.get(nodeId), State.INACTIVE);
tomb41d1ac2014-09-24 01:51:24 -0700196 }
197
198 @Override
Thomas Vachuska7a8de842016-03-07 20:56:35 -0800199 public void markFullyStarted(boolean started) {
200 updateState(localNode.id(), started ? State.READY : State.ACTIVE);
201 }
202
203 @Override
Pavlin Radoslavov444b5192014-10-28 10:45:19 -0700204 public ControllerNode addNode(NodeId nodeId, IpAddress ip, int tcpPort) {
sangyun-hanf98df542016-03-24 20:28:03 +0900205 checkNotNull(nodeId, INSTANCE_ID_NULL);
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800206 ControllerNode node = new DefaultControllerNode(nodeId, ip, tcpPort);
Madan Jampaniafeebbd2015-05-19 15:26:01 -0700207 addNode(node);
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800208 return node;
tomee49c372014-09-26 15:14:50 -0700209 }
210
211 @Override
tomb41d1ac2014-09-24 01:51:24 -0700212 public void removeNode(NodeId nodeId) {
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800213 checkNotNull(nodeId, INSTANCE_ID_NULL);
214 ControllerNode node = allNodes.remove(nodeId);
215 if (node != null) {
216 nodeStates.remove(nodeId);
Jonathan Hartf1141262015-04-23 11:27:07 -0700217 notifyDelegate(new ClusterEvent(ClusterEvent.Type.INSTANCE_REMOVED, node));
tomb41d1ac2014-09-24 01:51:24 -0700218 }
219 }
220
Madan Jampaniafeebbd2015-05-19 15:26:01 -0700221 private void addNode(ControllerNode node) {
222 allNodes.put(node.id(), node);
Madan Jampaniec1df022015-10-13 21:23:03 -0700223 updateState(node.id(), node.equals(localNode) ? State.ACTIVE : State.INACTIVE);
Madan Jampaniafeebbd2015-05-19 15:26:01 -0700224 notifyDelegate(new ClusterEvent(ClusterEvent.Type.INSTANCE_ADDED, node));
Thomas Vachuskade563cf2015-04-01 00:28:50 -0700225 }
226
Madan Jampani7d2fab22015-03-18 17:21:57 -0700227 private void updateState(NodeId nodeId, State newState) {
Thomas Vachuskafba7f3d2016-03-23 15:46:25 -0700228 State currentState = nodeStates.get(nodeId);
229 if (!Objects.equals(currentState, newState)) {
230 nodeStates.put(nodeId, newState);
231 nodeStateLastUpdatedTimes.put(nodeId, DateTime.now());
232 notifyStateChange(nodeId, currentState, newState);
233 }
Madan Jampani7d2fab22015-03-18 17:21:57 -0700234 }
235
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800236 private void heartbeat() {
237 try {
238 Set<ControllerNode> peers = allNodes.values()
239 .stream()
240 .filter(node -> !(node.id().equals(localNode.id())))
241 .collect(Collectors.toSet());
Thomas Vachuska7a8de842016-03-07 20:56:35 -0800242 State state = nodeStates.get(localNode.id());
Madan Jampanie3375062016-04-19 16:32:10 -0700243 byte[] hbMessagePayload = SERIALIZER.encode(new HeartbeatMessage(localNode, state));
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800244 peers.forEach((node) -> {
245 heartbeatToPeer(hbMessagePayload, node);
246 State currentState = nodeStates.get(node.id());
247 double phi = failureDetector.phi(node.id());
sangyun-hanf98df542016-03-24 20:28:03 +0900248 if (phi >= phiFailureThreshold) {
Thomas Vachuska7a8de842016-03-07 20:56:35 -0800249 if (currentState.isActive()) {
Madan Jampani7d2fab22015-03-18 17:21:57 -0700250 updateState(node.id(), State.INACTIVE);
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800251 }
252 } else {
253 if (currentState == State.INACTIVE) {
Madan Jampani7d2fab22015-03-18 17:21:57 -0700254 updateState(node.id(), State.ACTIVE);
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800255 }
256 }
257 });
258 } catch (Exception e) {
259 log.debug("Failed to send heartbeat", e);
260 }
tomb41d1ac2014-09-24 01:51:24 -0700261 }
262
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800263 private void notifyStateChange(NodeId nodeId, State oldState, State newState) {
Thomas Vachuskafba7f3d2016-03-23 15:46:25 -0700264 if (oldState != newState) {
265 ControllerNode node = allNodes.get(nodeId);
Jon Hall1f13d642016-05-13 17:53:01 -0700266 // Either this node or that node is no longer part of the same cluster
267 if (node == null) {
Jon Hall66870baa2016-06-20 12:12:10 -0700268 log.debug("Could not find node {} in the cluster, ignoring state change", nodeId);
Jon Hall1f13d642016-05-13 17:53:01 -0700269 return;
270 }
Thomas Vachuskafba7f3d2016-03-23 15:46:25 -0700271 ClusterEvent.Type type = newState == State.READY ? INSTANCE_READY :
272 newState == State.ACTIVE ? INSTANCE_ACTIVATED :
273 INSTANCE_DEACTIVATED;
274 notifyDelegate(new ClusterEvent(type, node));
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800275 }
tomb41d1ac2014-09-24 01:51:24 -0700276 }
277
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800278 private void heartbeatToPeer(byte[] messagePayload, ControllerNode peer) {
Madan Jampaniafeebbd2015-05-19 15:26:01 -0700279 Endpoint remoteEp = new Endpoint(peer.ip(), peer.tcpPort());
Madan Jampani175e8fd2015-05-20 14:10:45 -0700280 messagingService.sendAsync(remoteEp, HEARTBEAT_MESSAGE, messagePayload).whenComplete((result, error) -> {
281 if (error != null) {
282 log.trace("Sending heartbeat to {} failed", remoteEp, error);
283 }
284 });
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800285 }
286
Madan Jampanid36def02016-01-13 11:21:56 -0800287 private class HeartbeatMessageHandler implements BiConsumer<Endpoint, byte[]> {
tomb41d1ac2014-09-24 01:51:24 -0700288 @Override
Madan Jampanid36def02016-01-13 11:21:56 -0800289 public void accept(Endpoint sender, byte[] message) {
Madan Jampanic26eede2015-04-16 11:42:16 -0700290 HeartbeatMessage hb = SERIALIZER.decode(message);
Madan Jampanie3375062016-04-19 16:32:10 -0700291 if (clusterMetadataService.getClusterMetadata().getNodes().contains(hb.source())) {
292 failureDetector.report(hb.source().id());
293 updateState(hb.source().id(), hb.state);
294 }
tomb41d1ac2014-09-24 01:51:24 -0700295 }
tom2d7c65f2014-09-23 01:09:35 -0700296 }
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800297
298 private static class HeartbeatMessage {
299 private ControllerNode source;
Thomas Vachuska7a8de842016-03-07 20:56:35 -0800300 private State state;
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800301
Madan Jampanie3375062016-04-19 16:32:10 -0700302 public HeartbeatMessage(ControllerNode source, State state) {
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800303 this.source = source;
Thomas Vachuska7a8de842016-03-07 20:56:35 -0800304 this.state = state != null ? state : State.ACTIVE;
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800305 }
306
307 public ControllerNode source() {
308 return source;
309 }
Ayaka Koshibedd91b842015-03-02 14:48:47 -0800310 }
311
Madan Jampani7d2fab22015-03-18 17:21:57 -0700312 @Override
313 public DateTime getLastUpdated(NodeId nodeId) {
314 return nodeStateLastUpdatedTimes.get(nodeId);
315 }
Thomas Vachuskade563cf2015-04-01 00:28:50 -0700316
sangyun-hanf98df542016-03-24 20:28:03 +0900317 /**
318 * Extracts properties from the component configuration context.
319 *
320 * @param context the component context
321 */
322 private void readComponentConfiguration(ComponentContext context) {
323 Dictionary<?, ?> properties = context.getProperties();
324
325 Integer newHeartbeatInterval = Tools.getIntegerProperty(properties,
326 "heartbeatInterval");
327 if (newHeartbeatInterval == null) {
328 setHeartbeatInterval(DEFAULT_HEARTBEAT_INTERVAL);
329 log.info("Heartbeat interval time is not configured, default value is {}",
330 DEFAULT_HEARTBEAT_INTERVAL);
331 } else {
332 setHeartbeatInterval(newHeartbeatInterval);
333 log.info("Configured. Heartbeat interval time is configured to {}",
334 heartbeatInterval);
335 }
336
337 Integer newPhiFailureThreshold = Tools.getIntegerProperty(properties,
338 "phiFailureThreshold");
339 if (newPhiFailureThreshold == null) {
340 setPhiFailureThreshold(DEFAULT_PHI_FAILURE_THRESHOLD);
341 log.info("Phi failure threshold is not configured, default value is {}",
342 DEFAULT_PHI_FAILURE_THRESHOLD);
343 } else {
344 setPhiFailureThreshold(newPhiFailureThreshold);
345 log.info("Configured. Phi failure threshold is configured to {}",
346 phiFailureThreshold);
347 }
348 }
349
350 /**
351 * Sets heartbeat interval between the termination of one execution of heartbeat
352 * and the commencement of the next.
353 *
354 * @param interval term between each heartbeat
355 */
356 private void setHeartbeatInterval(int interval) {
357 try {
358 checkArgument(interval > 0, "Interval must be greater than zero");
359 heartbeatInterval = interval;
360 } catch (IllegalArgumentException e) {
361 log.warn(e.getMessage());
362 heartbeatInterval = DEFAULT_HEARTBEAT_INTERVAL;
363 }
364 }
365
366 /**
367 * Sets Phi failure threshold.
368 * Phi is based on a paper titled: "The φ Accrual Failure Detector" by Hayashibara, et al.
369 *
370 * @param threshold
371 */
372 private void setPhiFailureThreshold(int threshold) {
373 phiFailureThreshold = threshold;
374 }
375
376 /**
377 * Restarts heartbeatSender executor.
sangyun-hanf98df542016-03-24 20:28:03 +0900378 */
379 private void restartHeartbeatSender() {
380 try {
381 ScheduledExecutorService prevSender = heartBeatSender;
382 heartBeatSender = Executors.newSingleThreadScheduledExecutor(
HIGUCHI Yutad9e01052016-04-14 09:31:42 -0700383 groupedThreads("onos/cluster/membership", "heartbeat-sender-%d", log));
sangyun-hanf98df542016-03-24 20:28:03 +0900384 heartBeatSender.scheduleWithFixedDelay(this::heartbeat, 0,
385 heartbeatInterval, TimeUnit.MILLISECONDS);
386 prevSender.shutdown();
387 } catch (Exception e) {
388 log.warn(e.getMessage());
389 }
390 }
Jon Hall1f13d642016-05-13 17:53:01 -0700391}