Skip to content

Commit 3bfafbf

Browse files
Make the index-to-project map empty rather than null in the BWC deserialization case.
This works out fine, for the reasons given in the comment. As it happens, I'd already forgotten to do the null check in the one place it's actively used.
1 parent 7f60ef3 commit 3bfafbf

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

server/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ public NodeIndicesStats(StreamInput in) throws IOException {
9494
}
9595

9696
if (in.getTransportVersion().onOrAfter(TransportVersions.NODES_STATS_SUPPORTS_MULTI_PROJECT)) {
97-
boolean hasProjectsByIndex = in.readBoolean();
98-
projectsByIndex = hasProjectsByIndex ? in.readMap(Index::new, ProjectId::readFrom) : null;
97+
projectsByIndex = in.readMap(Index::new, ProjectId::readFrom);
9998
} else {
100-
projectsByIndex = null;
99+
// Older nodes do not include the index-to-project map, so we leave it empty. This means all indices will be treated as if the
100+
// project is unknown. This does not matter as the map is only used in multi-project clusters which will not have old nodes.
101+
projectsByIndex = Map.of();
101102
}
102103
}
103104

@@ -243,10 +244,7 @@ public void writeTo(StreamOutput out) throws IOException {
243244
out.writeMap(statsByIndex);
244245
}
245246
if (out.getTransportVersion().onOrAfter(TransportVersions.NODES_STATS_SUPPORTS_MULTI_PROJECT)) {
246-
out.writeBoolean(projectsByIndex != null);
247-
if (projectsByIndex != null) {
248-
out.writeMap(projectsByIndex);
249-
}
247+
out.writeMap(projectsByIndex);
250248
}
251249
}
252250

@@ -258,7 +256,7 @@ public boolean equals(Object o) {
258256
return stats.equals(that.stats)
259257
&& statsByShard.equals(that.statsByShard)
260258
&& statsByIndex.equals(that.statsByIndex)
261-
&& Objects.equals(projectsByIndex, that.projectsByIndex);
259+
&& projectsByIndex.equals(that.projectsByIndex);
262260
}
263261

264262
@Override

0 commit comments

Comments
 (0)