forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP draft for ClusterStateReusingStreamInput
We read various objects from the wire that already exist in the cluster state. The most notable is `DiscoveryNode` which can consume ~2kB in heap for each fresh object, but rarely changes, so it's pretty wasteful to use fresh objects here. There could be thousands (millions?) of `DiscoveryNode` objects in flight from various `TransportNodesAction` responses. This branch introduces `ClusterStateReusingStreamInput` which lets the caller capture an appropriate `ClusterState` from which to re-use `DiscoveryNode` objects if appropriate. Relates elastic#77266
- Loading branch information
1 parent
be4bd68
commit aa61253
Showing
6 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
server/src/main/java/org/elasticsearch/common/io/stream/ClusterStateReusingStreamInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.common.io.stream; | ||
|
||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.node.DiscoveryNodes; | ||
|
||
import java.io.IOException; | ||
|
||
public class ClusterStateReusingStreamInput extends FilterStreamInput { | ||
|
||
private final DiscoveryNodes discoveryNodes; | ||
|
||
public ClusterStateReusingStreamInput(StreamInput delegate, ClusterState clusterState) { | ||
super(delegate); | ||
this.discoveryNodes = clusterState.nodes(); | ||
} | ||
|
||
public DiscoveryNode readDiscoveryNode() throws IOException { | ||
final DiscoveryNode fromStream = new DiscoveryNode(delegate); | ||
final DiscoveryNode fromClusterState = discoveryNodes.get(fromStream.getId()); | ||
return fromStream.equals(fromClusterState) && fromStream.getRoles().equals(fromClusterState.getRoles()) | ||
? fromClusterState | ||
: fromStream; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters