-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failover when we miss Mesos Master heartbeats. #1853
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7c6c785
Track the last Mesos Master heartbeat timestamp in the scheduler.
baconmania f86dc06
Expose the last heartbeat time on the SingularityState object.
baconmania b385cdb
Abort Singularity if the leader misses the configured number of heart…
baconmania 96b57e8
Make names match.
baconmania 634c0bc
This annotation isn't useful here.
baconmania 84f0410
Better readability.
baconmania File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ice/src/main/java/com/hubspot/singularity/scheduler/SingularityMesosHeartbeatChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.hubspot.singularity.scheduler; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.common.base.Optional; | ||
import com.google.inject.Inject; | ||
import com.google.inject.name.Named; | ||
import com.hubspot.singularity.SingularityAbort; | ||
import com.hubspot.singularity.SingularityAbort.AbortReason; | ||
import com.hubspot.singularity.SingularityMainModule; | ||
import com.hubspot.singularity.config.SingularityConfiguration; | ||
import com.hubspot.singularity.mesos.SingularityMesosScheduler; | ||
|
||
public class SingularityMesosHeartbeatChecker extends SingularityLeaderOnlyPoller { | ||
private static final Logger LOG = LoggerFactory.getLogger(SingularityMesosHeartbeatChecker.class); | ||
|
||
private final SingularityConfiguration configuration; | ||
private final SingularityMesosScheduler mesosScheduler; | ||
private final SingularityAbort abort; | ||
private final AtomicLong lastHeartbeatTime; | ||
|
||
@Inject | ||
public SingularityMesosHeartbeatChecker(SingularityConfiguration configuration, | ||
SingularityMesosScheduler mesosScheduler, | ||
SingularityAbort abort, | ||
@Named(SingularityMainModule.LAST_MESOS_MASTER_HEARTBEAT_TIME) AtomicLong lastHeartbeatTime) { | ||
super(configuration.getCheckMesosMasterHeartbeatEverySeconds(), TimeUnit.SECONDS); | ||
this.configuration = configuration; | ||
this.mesosScheduler = mesosScheduler; | ||
this.abort = abort; | ||
this.lastHeartbeatTime = lastHeartbeatTime; | ||
} | ||
|
||
@Override | ||
public void runActionOnPoll() { | ||
if (!mesosScheduler.getHeartbeatIntervalSeconds().isPresent()) { | ||
if (mesosScheduler.isRunning()) { | ||
LOG.debug("Not checking for a Mesos heartbeat because the Mesos Master didn't advertise a heartbeat interval."); | ||
} else { | ||
LOG.debug("Not checking for a Mesos heartbeat because we haven't subscribed with the Mesos Master yet."); | ||
} | ||
|
||
return; | ||
} | ||
|
||
long millisSinceLastHeartbeat = System.currentTimeMillis() - lastHeartbeatTime.get(); | ||
double missedHeartbeats = millisSinceLastHeartbeat / (mesosScheduler.getHeartbeatIntervalSeconds().get() * 1000); | ||
|
||
if (missedHeartbeats > configuration.getMaxMissedMesosMasterHeartbeats()) { | ||
LOG.error("I haven't received a Mesos heartbeat in {}ms! Aborting Singularity...", millisSinceLastHeartbeat); | ||
mesosScheduler.notifyStopping(); | ||
abort.abort(AbortReason.LOST_MESOS_CONNECTION, Optional.of(new RuntimeException(String.format("Didn't receive a heartbeat from the Mesos Master for %dms", millisSinceLastHeartbeat)))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like a weird thing to have the getAndSet inside the debug line. I know it gets evaluated the same, but I had to read this a few times to convince myself it would always be hit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye, it'll get eval'd before (and regardless of whether) the logger actually tries to write the line. Agreed that it's unnecessarily dense though, I can split this out for clarity.