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
Don't join master nodes or accept join requests of old and too new nodes #11972
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import com.carrotsearch.hppc.ObjectContainer; | ||
import com.google.common.collect.Lists; | ||
import org.apache.lucene.util.CollectionUtil; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.common.component.AbstractComponent; | ||
import org.elasticsearch.common.inject.Inject; | ||
|
@@ -36,13 +37,17 @@ public class ElectMasterService extends AbstractComponent { | |
|
||
public static final String DISCOVERY_ZEN_MINIMUM_MASTER_NODES = "discovery.zen.minimum_master_nodes"; | ||
|
||
// This is the minimum version a master needs to be on, otherwise it gets ignored | ||
// This is based on the minimum compatible version of the current version this node is on | ||
private final Version minMasterVersion; | ||
private final NodeComparator nodeComparator = new NodeComparator(); | ||
|
||
private volatile int minimumMasterNodes; | ||
|
||
@Inject | ||
public ElectMasterService(Settings settings) { | ||
public ElectMasterService(Settings settings, Version version) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rename version into minMasterVersion, call it with Version. minimumCompatibilityVersion() and document what it means? I think it will be clearer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It turns out it's hard(ish) to remove ElectMasterService from guice.. not doing. |
||
super(settings); | ||
this.minMasterVersion = version.minimumCompatibilityVersion(); | ||
this.minimumMasterNodes = settings.getAsInt(DISCOVERY_ZEN_MINIMUM_MASTER_NODES, -1); | ||
logger.debug("using minimum_master_nodes [{}]", minimumMasterNodes); | ||
} | ||
|
@@ -108,7 +113,14 @@ public DiscoveryNode electMaster(Iterable<DiscoveryNode> nodes) { | |
if (sortedNodes == null || sortedNodes.isEmpty()) { | ||
return null; | ||
} | ||
return sortedNodes.get(0); | ||
DiscoveryNode masterNode = sortedNodes.get(0); | ||
// Sanity check: maybe we don't end up here, because serialization may have failed. | ||
if (masterNode.getVersion().before(minMasterVersion)) { | ||
logger.warn("ignoring master [{}], because the version [{}] is lower than the minimum compatible version [{}]", masterNode, masterNode.getVersion(), minMasterVersion); | ||
return null; | ||
} else { | ||
return masterNode; | ||
} | ||
} | ||
|
||
private List<DiscoveryNode> sortedMasterNodes(Iterable<DiscoveryNode> nodes) { | ||
|
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.
this can go back to private now, no?
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.
true
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.
oops... no, because it is used in a test (ZenDiscoveryTests#testHandleNodeJoin_incompatibleMinVersion)