Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
* NodeRuntimeMetadata is a runtime view of a node's metadata.
Expand All @@ -39,6 +40,7 @@ public final class NodeRuntimeMetadata {
* @see ClusterControlManager#getNextNodeId()
*/
private static final int MAX_CONTROLLER_ID = 1000 - 1;
private static final long DONT_FAILOVER_AFTER_NEW_EPOCH_MS = TimeUnit.MINUTES.toMillis(1);
private final int id;
private final long epoch;
private final String walConfigs;
Expand All @@ -60,7 +62,11 @@ public NodeRuntimeMetadata(int id, long epoch, String walConfigs, Map<String, St
}

public boolean shouldFailover() {
return isFenced() && hasOpeningStreams;
return isFenced() && hasOpeningStreams
// The node epoch is the start timestamp of node.
// We need to avoid failover just after node restart.
// The node may take some time to recover its data.
&& System.currentTimeMillis() - epoch > DONT_FAILOVER_AFTER_NEW_EPOCH_MS;
}

public boolean isFenced() {
Expand Down
Loading