Skip to content

Commit 05c9455

Browse files
committed
Merge remote-tracking branch 'elastic/zen2' into testable-master-service
2 parents 506608c + 433b7b8 commit 05c9455

23 files changed

+3107
-168
lines changed

server/src/main/java/org/elasticsearch/cluster/coordination/CoordinationState.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,18 @@ public void handleCommit(ApplyCommitRequest applyCommit) {
388388
assert getLastCommittedConfiguration().equals(getLastAcceptedConfiguration());
389389
}
390390

391+
public void invariant() {
392+
assert getLastAcceptedTerm() <= getCurrentTerm();
393+
assert electionWon() == isElectionQuorum(joinVotes);
394+
if (electionWon()) {
395+
assert getLastPublishedVersion() >= getLastAcceptedVersion();
396+
} else {
397+
assert getLastPublishedVersion() == 0L;
398+
}
399+
assert electionWon() == false || startedJoinSinceLastReboot;
400+
assert publishVotes.isEmpty() || electionWon();
401+
}
402+
391403
/**
392404
* Pluggable persistence layer for {@link CoordinationState}.
393405
*

server/src/main/java/org/elasticsearch/cluster/coordination/FutureExecutor.java

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.cluster.coordination;
21+
22+
import org.elasticsearch.cluster.node.DiscoveryNode;
23+
import org.elasticsearch.common.io.stream.StreamInput;
24+
import org.elasticsearch.common.io.stream.StreamOutput;
25+
import org.elasticsearch.transport.TransportResponse;
26+
27+
import java.io.IOException;
28+
import java.util.List;
29+
import java.util.Objects;
30+
import java.util.Optional;
31+
32+
public class PeersResponse extends TransportResponse {
33+
private final Optional<DiscoveryNode> masterNode;
34+
private final List<DiscoveryNode> knownPeers;
35+
private final long term;
36+
37+
public PeersResponse(Optional<DiscoveryNode> masterNode, List<DiscoveryNode> knownPeers, long term) {
38+
assert masterNode.isPresent() == false || knownPeers.isEmpty();
39+
this.masterNode = masterNode;
40+
this.knownPeers = knownPeers;
41+
this.term = term;
42+
}
43+
44+
public PeersResponse(StreamInput in) throws IOException {
45+
masterNode = Optional.ofNullable(in.readOptionalWriteable(DiscoveryNode::new));
46+
knownPeers = in.readList(DiscoveryNode::new);
47+
term = in.readLong();
48+
assert masterNode.isPresent() == false || knownPeers.isEmpty();
49+
}
50+
51+
@Override
52+
public void writeTo(StreamOutput out) throws IOException {
53+
super.writeTo(out);
54+
out.writeOptionalWriteable(masterNode.orElse(null));
55+
out.writeList(knownPeers);
56+
out.writeLong(term);
57+
}
58+
59+
/**
60+
* @return the node that is currently leading, according to the responding node.
61+
*/
62+
public Optional<DiscoveryNode> getMasterNode() {
63+
return masterNode;
64+
}
65+
66+
/**
67+
* @return the collection of known peers of the responding node, or an empty collection if the responding node believes there
68+
* is currently a leader.
69+
*/
70+
public List<DiscoveryNode> getKnownPeers() {
71+
return knownPeers;
72+
}
73+
74+
/**
75+
* @return the current term of the responding node. If the responding node is the leader then this is the term in which it is
76+
* currently leading.
77+
*/
78+
public long getTerm() {
79+
return term;
80+
}
81+
82+
@Override
83+
public String toString() {
84+
return "PeersResponse{" +
85+
"masterNode=" + masterNode +
86+
", knownPeers=" + knownPeers +
87+
", term=" + term +
88+
'}';
89+
}
90+
91+
@Override
92+
public boolean equals(Object o) {
93+
if (this == o) return true;
94+
if (o == null || getClass() != o.getClass()) return false;
95+
PeersResponse that = (PeersResponse) o;
96+
return term == that.term &&
97+
Objects.equals(masterNode, that.masterNode) &&
98+
Objects.equals(knownPeers, that.knownPeers);
99+
}
100+
101+
@Override
102+
public int hashCode() {
103+
return Objects.hash(masterNode, knownPeers, term);
104+
}
105+
}

0 commit comments

Comments
 (0)