Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bd5693f
persistency works (node join problems TBD)
bleskes Apr 16, 2016
31bc94e
enforce unique network addresses across nodes in cluster
bleskes Apr 16, 2016
512c4f4
add node environment test
bleskes Apr 16, 2016
199e7e5
introduce explicit node storage setting
bleskes Apr 17, 2016
af1ecee
minor naming tweak
bleskes Apr 17, 2016
536a377
line lengths
bleskes Apr 17, 2016
ea8931e
fix min state version check
bleskes Apr 17, 2016
4ae867d
Disable persistence for tribe node clients and strengthen test
bleskes Apr 17, 2016
570ff47
fix tribe test and rename local_storage method
bleskes Apr 17, 2016
5cc4236
add migration docs
bleskes Apr 17, 2016
07e5558
stupid fixes
bleskes Apr 17, 2016
2ac579d
unneeded lines
bleskes Apr 17, 2016
56d68d5
private things private
bleskes Apr 17, 2016
881b24f
woops
bleskes Apr 17, 2016
7e96a08
tweaks
bleskes Apr 17, 2016
7968736
more renaming of `add_lock_id_to_custom_path`
bleskes Apr 17, 2016
bb6f062
add protect against same node id in local discovery
bleskes Apr 19, 2016
76f1a1d
apply feedback from @ywelsch
bleskes Apr 19, 2016
fce829d
fix ClusterStateDiffIT
bleskes Apr 19, 2016
afb14c3
when resetting shared test cluster, shut down new nodes first as they…
bleskes Apr 19, 2016
697419c
fix some references to node_id.seed
bleskes Apr 19, 2016
4090290
do replace existing node to accomodate for a quick restart and change…
bleskes Apr 20, 2016
2a7daf1
typo
bleskes Apr 20, 2016
39fc924
added process id
ywelsch Apr 25, 2016
e57232f
Generate node id of a tribe client node based on node id of parent tr…
ywelsch Apr 28, 2016
49b871a
fix failing test
ywelsch Apr 28, 2016
7f95af0
naming
ywelsch Apr 28, 2016
7dbe1bf
rename nodeId() to getNodeId() and documentation
ywelsch May 3, 2016
4f382b9
Make node.local_storage filtered setting
ywelsch May 3, 2016
13c993c
Use ephemeral id for discovery and persistent node id for all else
ywelsch May 10, 2016
258fbad
fix tests
ywelsch May 10, 2016
10bbddb
minor fixes
ywelsch May 10, 2016
a1ff308
Fix test
ywelsch May 10, 2016
0174ea5
Stop overloading madness
ywelsch May 12, 2016
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
3 changes: 0 additions & 3 deletions buildSrc/src/main/resources/checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]cluster[/\\]metadata[/\\]MetaDataMappingService.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]cluster[/\\]metadata[/\\]MetaDataUpdateSettingsService.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]cluster[/\\]metadata[/\\]RepositoriesMetaData.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]cluster[/\\]node[/\\]DiscoveryNodes.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]cluster[/\\]routing[/\\]IndexRoutingTable.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]cluster[/\\]routing[/\\]IndexShardRoutingTable.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]cluster[/\\]routing[/\\]OperationRouting.java" checks="LineLength" />
Expand Down Expand Up @@ -380,7 +379,6 @@
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]DiscoveryService.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]DiscoverySettings.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]local[/\\]LocalDiscovery.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]zen[/\\]NodeJoinController.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]zen[/\\]ZenDiscovery.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]zen[/\\]elect[/\\]ElectMasterService.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]zen[/\\]fd[/\\]FaultDetection.java" checks="LineLength" />
Expand Down Expand Up @@ -979,7 +977,6 @@
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]DiscoveryWithServiceDisruptionsIT.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]ZenFaultDetectionTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]ZenUnicastDiscoveryIT.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]zen[/\\]NodeJoinControllerTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]zen[/\\]ZenDiscoveryUnitTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]zen[/\\]ping[/\\]unicast[/\\]UnicastZenPingIT.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]zen[/\\]publish[/\\]PublishClusterStateActionTests.java" checks="LineLength" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ public LivenessResponse newInstance() {
// use discovered information but do keep the original transport address,
// so people can control which address is exactly used.
DiscoveryNode nodeWithInfo = livenessResponse.getDiscoveryNode();
newNodes.add(new DiscoveryNode(nodeWithInfo.getName(), nodeWithInfo.getId(), nodeWithInfo.getHostName(),
nodeWithInfo.getHostAddress(), listedNode.getAddress(), nodeWithInfo.getAttributes(),
nodeWithInfo.getRoles(), nodeWithInfo.getVersion()));
newNodes.add(new DiscoveryNode(nodeWithInfo.getName(), nodeWithInfo.getId(), nodeWithInfo.getEphemeralId(),
nodeWithInfo.getHostName(), nodeWithInfo.getHostAddress(), listedNode.getAddress(),
nodeWithInfo.getAttributes(), nodeWithInfo.getRoles(), nodeWithInfo.getVersion()));
} else {
// although we asked for one node, our target may not have completed
// initialization yet and doesn't have cluster nodes
Expand Down
130 changes: 89 additions & 41 deletions core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.elasticsearch.cluster.node;

import org.elasticsearch.Version;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
Expand Down Expand Up @@ -64,7 +63,15 @@ public static boolean isLocalNode(Settings settings) {
}

public static boolean nodeRequiresLocalStorage(Settings settings) {
return Node.NODE_DATA_SETTING.get(settings) || Node.NODE_MASTER_SETTING.get(settings);
boolean localStorageEnable = Node.NODE_LOCAL_STORAGE_SETTING.get(settings);
if (localStorageEnable == false &&
(Node.NODE_DATA_SETTING.get(settings) ||
Node.NODE_MASTER_SETTING.get(settings))
) {
// TODO: make this a proper setting validation logic, requiring multi-settings validation
throw new IllegalArgumentException("storage can not be disabled for master and data nodes");
}
return localStorageEnable;
}

public static boolean isMasterNode(Settings settings) {
Expand All @@ -81,6 +88,7 @@ public static boolean isIngestNode(Settings settings) {

private final String nodeName;
private final String nodeId;
private final String ephemeralId;
private final String hostName;
private final String hostAddress;
private final TransportAddress address;
Expand All @@ -97,14 +105,15 @@ public static boolean isIngestNode(Settings settings) {
* and updated.
* </p>
*
* @param nodeId the nodes unique id.
* @param address the nodes transport address
* @param attributes node attributes
* @param roles node roles
* @param version the version of the node.
* @param id the nodes unique (ephemeral and persistent) node id
* @param address the nodes transport address
* @param attributes node attributes
* @param roles node roles
* @param version the version of the node
*/
public DiscoveryNode(String nodeId, TransportAddress address, Map<String, String> attributes, Set<Role> roles, Version version) {
this("", nodeId, address.getHost(), address.getAddress(), address, attributes, roles, version);
public DiscoveryNode(String id, TransportAddress address, Map<String, String> attributes, Set<Role> roles,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. I think this is tricky having no id string. How about using the supplied id as the nodeId and generate a random ephemeral one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean here. This constructor is mainly used by tests where we don't care much about the actual values and construction of temporary nodes for pinging. I don't think we should just randomly generate a ephemeral id here. Better would be to get rid of this constructor altogether...

Version version) {
this("", id, id, address, attributes, roles, version);
}

/**
Expand All @@ -116,16 +125,17 @@ public DiscoveryNode(String nodeId, TransportAddress address, Map<String, String
* and updated.
* </p>
*
* @param nodeName the nodes name
* @param nodeId the nodes unique id.
* @param address the nodes transport address
* @param attributes node attributes
* @param roles node roles
* @param version the version of the node.
* @param nodeName the nodes name
* @param nodeId the nodes unique persistent id
* @param ephemeralId the nodes unique ephemeral id
* @param address the nodes transport address
* @param attributes node attributes
* @param roles node roles
* @param version the version of the node
*/
public DiscoveryNode(String nodeName, String nodeId, TransportAddress address, Map<String, String> attributes,
Set<Role> roles, Version version) {
this(nodeName, nodeId, address.getHost(), address.getAddress(), address, attributes, roles, version);
public DiscoveryNode(String nodeName, String nodeId, String ephemeralId, TransportAddress address,
Map<String, String> attributes, Set<Role> roles, Version version) {
this(nodeName, nodeId, ephemeralId, address.getHost(), address.getAddress(), address, attributes, roles, version);
}

/**
Expand All @@ -137,23 +147,24 @@ public DiscoveryNode(String nodeName, String nodeId, TransportAddress address, M
* and updated.
* </p>
*
* @param nodeName the nodes name
* @param nodeId the nodes unique id.
* @param hostName the nodes hostname
* @param hostAddress the nodes host address
* @param address the nodes transport address
* @param attributes node attributes
* @param roles node roles
* @param version the version of the node.
* @param nodeName the nodes name
* @param nodeId the nodes unique persistent id
* @param ephemeralId the nodes unique ephemeral id
* @param hostAddress the nodes host address
* @param address the nodes transport address
* @param attributes node attributes
* @param roles node roles
* @param version the version of the node
*/
public DiscoveryNode(String nodeName, String nodeId, String hostName, String hostAddress, TransportAddress address,
Map<String, String> attributes, Set<Role> roles, Version version) {
public DiscoveryNode(String nodeName, String nodeId, String ephemeralId, String hostName, String hostAddress,
TransportAddress address, Map<String, String> attributes, Set<Role> roles, Version version) {
if (nodeName != null) {
this.nodeName = nodeName.intern();
} else {
this.nodeName = "";
}
this.nodeId = nodeId.intern();
this.ephemeralId = ephemeralId.intern();
this.hostName = hostName.intern();
this.hostAddress = hostAddress.intern();
this.address = address;
Expand Down Expand Up @@ -184,6 +195,7 @@ public DiscoveryNode(String nodeName, String nodeId, String hostName, String hos
public DiscoveryNode(StreamInput in) throws IOException {
this.nodeName = in.readString().intern();
this.nodeId = in.readString().intern();
this.ephemeralId = in.readString().intern();
this.hostName = in.readString().intern();
this.hostAddress = in.readString().intern();
this.address = TransportAddressSerializers.addressFromStream(in);
Expand All @@ -208,6 +220,7 @@ public DiscoveryNode(StreamInput in) throws IOException {
public void writeTo(StreamOutput out) throws IOException {
out.writeString(nodeName);
out.writeString(nodeId);
out.writeString(ephemeralId);
out.writeString(hostName);
out.writeString(hostAddress);
addressToStream(out, address);
Expand Down Expand Up @@ -237,6 +250,13 @@ public String getId() {
return nodeId;
}

/**
* The unique ephemeral id of the node.
Copy link
Contributor

@bleskes bleskes May 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add some docs as to what we mean with ephemeral - most notably when it changes, and it's implication to identity

*/
public String getEphemeralId() {
return ephemeralId;
}

/**
* The name of the node.
*/
Expand Down Expand Up @@ -293,17 +313,49 @@ public String getHostAddress() {
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof DiscoveryNode)) {
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

DiscoveryNode that = (DiscoveryNode) o;

if (!nodeId.equals(that.nodeId)) {
return false;
}
if (!ephemeralId.equals(that.ephemeralId)) {
return false;
}
if (!nodeName.equals(that.nodeName)) {
return false;
}
if (!hostName.equals(that.hostName)) {
return false;
}
if (!hostAddress.equals(that.hostAddress)) {
return false;
}
if (!address.equals(that.address)) {
return false;
}
if (!attributes.equals(that.attributes)) {
return false;
}
if (!version.equals(that.version)) {
return false;
}
return roles.equals(that.roles);

DiscoveryNode other = (DiscoveryNode) obj;
return this.nodeId.equals(other.nodeId);
}

@Override
public int hashCode() {
// we only need to hash the id because it's highly unlikely that two nodes
// in our system will have the same id but be different
// This is done so that this class can be used efficiently as a key in a map
return nodeId.hashCode();
}

Expand All @@ -313,15 +365,10 @@ public String toString() {
if (nodeName.length() > 0) {
sb.append('{').append(nodeName).append('}');
}
if (nodeId != null) {
sb.append('{').append(nodeId).append('}');
}
if (Strings.hasLength(hostName)) {
sb.append('{').append(hostName).append('}');
}
if (address != null) {
sb.append('{').append(address).append('}');
}
sb.append('{').append(nodeId).append('}');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodeId is never null
ephemeralId is never null
hostName/address is never null

sb.append('{').append(ephemeralId).append('}');
sb.append('{').append(hostName).append('}');
sb.append('{').append(address).append('}');
if (!attributes.isEmpty()) {
sb.append(attributes);
}
Expand All @@ -332,6 +379,7 @@ public String toString() {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(getId());
builder.field("name", getName());
builder.field("ephemeral_id", getEphemeralId());
builder.field("transport_address", getAddress().toString());

builder.startObject("attributes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.node.Node;
Expand All @@ -42,30 +41,35 @@
*/
public class DiscoveryNodeService extends AbstractComponent {

public static final Setting<Long> NODE_ID_SEED_SETTING =
// don't use node.id.seed so it won't be seen as an attribute
Setting.longSetting("node_id.seed", 0L, Long.MIN_VALUE, Property.NodeScope);
public static final Setting<Long> EPHEMERAL_ID_SEED_SETTING =
Setting.longSetting("node.ephemeral_id.seed", 0L, Long.MIN_VALUE, Setting.Property.NodeScope);

private final List<CustomAttributesProvider> customAttributesProviders = new CopyOnWriteArrayList<>();
private final Version version;
private final String ephemeralId;

@Inject
public DiscoveryNodeService(Settings settings, Version version) {
super(settings);
this.version = version;
this.ephemeralId = generateEphemeralId(settings);
}

public static String generateNodeId(Settings settings) {
Random random = Randomness.get(settings, NODE_ID_SEED_SETTING);
return UUIDs.randomBase64UUID(random);
public String getEphemeralId() {
return ephemeralId;
}

public DiscoveryNodeService addCustomAttributeProvider(CustomAttributesProvider customAttributesProvider) {
customAttributesProviders.add(customAttributesProvider);
return this;
}

public DiscoveryNode buildLocalNode(TransportAddress publishAddress) {
final String nodeId = generateNodeId(settings);
public static String generateEphemeralId(Settings settings) {
Random random = Randomness.get(settings, EPHEMERAL_ID_SEED_SETTING);
return UUIDs.randomBase64UUID(random);
}

public DiscoveryNode buildLocalNode(TransportAddress publishAddress, String nodeId) {
Map<String, String> attributes = new HashMap<>(Node.NODE_ATTRIBUTES.get(this.settings).getAsMap());
Set<DiscoveryNode.Role> roles = new HashSet<>();
if (Node.NODE_INGEST_SETTING.get(settings)) {
Expand All @@ -92,8 +96,8 @@ public DiscoveryNode buildLocalNode(TransportAddress publishAddress) {
logger.warn("failed to build custom attributes from provider [{}]", e, provider);
}
}
return new DiscoveryNode(Node.NODE_NAME_SETTING.get(settings), nodeId, publishAddress, attributes,
roles, version);
return new DiscoveryNode(Node.NODE_NAME_SETTING.get(settings), nodeId, ephemeralId, publishAddress,
attributes, roles, version);
}

public interface CustomAttributesProvider {
Expand Down
Loading