Skip to content

Commit 55e003d

Browse files
authored
Map data tiers roles onto DATA legacy role for <7.3 (#71628)
Map data tiers roles onto DATA legacy role for <7.3
1 parent c4fceb4 commit 55e003d

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Collections;
2525
import java.util.HashMap;
2626
import java.util.HashSet;
27-
import java.util.List;
2827
import java.util.Locale;
2928
import java.util.Map;
3029
import java.util.Set;
@@ -339,8 +338,11 @@ public void writeTo(StreamOutput out) throws IOException {
339338
}
340339
} else {
341340
// an old node will only understand legacy roles since pluggable roles is a new concept
342-
final List<DiscoveryNodeRole> rolesToWrite =
343-
roles.stream().filter(DiscoveryNodeRole.LEGACY_ROLES::contains).collect(Collectors.toList());
341+
final Set<DiscoveryNodeRole> rolesToWrite = roles.stream()
342+
.map(role -> role.getCompatibilityRole(out.getVersion()))
343+
.filter(DiscoveryNodeRole.LEGACY_ROLES::contains)
344+
.collect(Collectors.toSet());
345+
344346
out.writeVInt(rolesToWrite.size());
345347
for (final DiscoveryNodeRole role : rolesToWrite) {
346348
if (role == DiscoveryNodeRole.MASTER_ROLE) {

server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@ public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) {
137137
equalTo("data"));
138138
}
139139

140+
{
141+
// a pre 7.3.0 node will only understand legacy roles so let's test a custom data containing node role is mapped onto the
142+
// `DATA` role
143+
DiscoveryNode nodeToWrite = new DiscoveryNode("name1", "id1", transportAddress, emptyMap(),
144+
org.elasticsearch.common.collect.Set.of(customRole, DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
145+
146+
BytesStreamOutput streamOutput = new BytesStreamOutput();
147+
streamOutput.setVersion(Version.V_7_2_0);
148+
nodeToWrite.writeTo(streamOutput);
149+
150+
StreamInput in = StreamInput.wrap(streamOutput.bytes().toBytesRef().bytes);
151+
in.setVersion(Version.V_7_2_0);
152+
DiscoveryNode serialized = new DiscoveryNode(in);
153+
assertThat(serialized.getRoles().stream().map(DiscoveryNodeRole::roleName).sorted().collect(Collectors.joining(",")),
154+
equalTo("data,master"));
155+
}
140156
}
141157

142158
public void testDiscoveryNodeIsRemoteClusterClientDefault() {

0 commit comments

Comments
 (0)