Skip to content

Commit

Permalink
Remove remoteAddress field from TransportResponse
Browse files Browse the repository at this point in the history
This field is only used (by security) for requests, having it in responses is redundant.
Also, we have a couple of responses that are singletons/quasi-enums where setting the value
needlessly might introduce some strange contention even though it's a plain store.

This isn't just a cosmetic change. It makes it clear at compile time that each response instance
is exclusively defined by the bytes that it is read from. This makes it easier to reason about the
validity of suggested optimizations like elastic#120010
  • Loading branch information
original-brownbear committed Jan 11, 2025
1 parent b5c29f1 commit 27623f7
Show file tree
Hide file tree
Showing 208 changed files with 20 additions and 266 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public Response(@Nullable Long runDuration, @Nullable Long timeBetweenStarts, Li
}

public Response(StreamInput in) throws IOException {
super(in);
this.runDuration = in.readOptionalVLong();
this.timeBetweenStarts = in.readOptionalVLong();
this.dataStreamStats = in.readCollectionAsImmutableList(DataStreamStats::read);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public static class Response extends ActionResponse implements ToXContentObject
}

Response(StreamInput in) throws IOException {
super(in);
grokPatterns = in.readMap(StreamInput::readString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ public static class Response extends ActionResponse implements ToXContentObject
}

Response(StreamInput in) throws IOException {
super(in);
result = in.readGenericValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public RankEvalResponse(double metricScore, Map<String, EvalQueryQuality> partia
}

RankEvalResponse(StreamInput in) throws IOException {
super(in);
this.metricScore = in.readDouble();
int partialResultSize = in.readVInt();
this.details = Maps.newMapWithExpectedSize(partialResultSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,7 @@ public TestResponse() {

}

public TestResponse(StreamInput in) throws IOException {
super(in);
}
public TestResponse(StreamInput in) {}

@Override
public void writeTo(StreamOutput out) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,6 @@ public TestRerankingActionResponse(List<Float> scores) {
this.scores = scores;
}

public TestRerankingActionResponse(StreamInput in) throws IOException {
super(in);
this.scores = in.readCollectionAsList(StreamInput::readFloat);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeCollection(scores, StreamOutput::writeFloat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,18 @@

package org.elasticsearch.action;

import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.transport.TransportResponse;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;

import java.io.IOException;

/**
* Base class for responses to action requests.
*/
public abstract class ActionResponse extends TransportResponse {

public ActionResponse() {}

public ActionResponse(StreamInput in) throws IOException {
super(in);
}

public static final class Empty extends ActionResponse implements ToXContentObject {
public static final ActionResponse.Empty INSTANCE = new ActionResponse.Empty();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class ClusterAllocationExplainResponse extends ActionResponse implements
private final ClusterAllocationExplanation cae;

public ClusterAllocationExplainResponse(StreamInput in) throws IOException {
super(in);
this.cae = new ClusterAllocationExplanation(in);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public Response(Map<String, NodeAllocationStats> nodeAllocationStats, DiskThresh
}

public Response(StreamInput in) throws IOException {
super(in);
this.nodeAllocationStats = in.readImmutableMap(StreamInput::readString, NodeAllocationStats::new);
if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_15_0)) {
this.diskThresholdSettings = in.readOptionalWriteable(DiskThresholdSettings::readFrom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public static class Response extends ActionResponse {
private final ClusterFormationFailureHelper.ClusterFormationState clusterFormationState;

public Response(StreamInput in) throws IOException {
super(in);
clusterFormationState = new ClusterFormationFailureHelper.ClusterFormationState(in);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public static class Response extends ActionResponse {
private final CoordinationDiagnosticsResult result;

public Response(StreamInput in) throws IOException {
super(in);
result = new CoordinationDiagnosticsResult(in);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public Response(DesiredNodes desiredNodes) {
}

public Response(StreamInput in) throws IOException {
super(in);
this.desiredNodes = DesiredNodes.readFrom(in);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public UpdateDesiredNodesResponse(boolean replacedExistingHistoryId, boolean dry
}

public UpdateDesiredNodesResponse(StreamInput in) throws IOException {
super(in);
this.replacedExistingHistoryId = in.readBoolean();
dryRun = in.getTransportVersion().onOrAfter(DRY_RUN_SUPPORTING_VERSION) ? in.readBoolean() : false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class ClusterHealthResponse extends ActionResponse implements ToXContentO
public ClusterHealthResponse() {}

public ClusterHealthResponse(StreamInput in) throws IOException {
super(in);
clusterName = in.readString();
clusterHealthStatus = ClusterHealthStatus.readFrom(in);
clusterStateHealth = new ClusterStateHealth(in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public GetFeatureUpgradeStatusResponse(List<FeatureUpgradeStatus> statuses, Upgr
* @throws IOException if we can't deserialize the object
*/
public GetFeatureUpgradeStatusResponse(StreamInput in) throws IOException {
super(in);
this.featureUpgradeStatuses = in.readCollectionAsImmutableList(FeatureUpgradeStatus::new);
this.upgradeStatus = in.readEnum(UpgradeStatus.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public PostFeatureUpgradeResponse(
* @throws IOException if we can't deserialize the object
*/
public PostFeatureUpgradeResponse(StreamInput in) throws IOException {
super(in);
this.accepted = in.readBoolean();
this.features = in.readCollectionAsImmutableList(Feature::new);
this.reason = in.readOptionalString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public NodesRemovalPrevalidation getPrevalidation() {
}

public PrevalidateNodeRemovalResponse(StreamInput in) throws IOException {
super(in);
prevalidation = NodesRemovalPrevalidation.readFrom(in);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public GetTaskResponse(TaskResult task) {
}

public GetTaskResponse(StreamInput in) throws IOException {
super(in);
task = in.readOptionalWriteable(TaskResult::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public Response(List<DiscoveryNode> nodes) {
}

public Response(StreamInput in) throws IOException {
super(in);
this.nodes = in.readCollectionAsList(DiscoveryNode::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public int hashCode() {
public VerifyRepositoryResponse() {}

public VerifyRepositoryResponse(StreamInput in) throws IOException {
super(in);
this.nodes = in.readCollectionAsList(NodeView::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class ClusterRerouteResponse extends ActionResponse implements IsAcknowle
private final boolean acknowledged;

ClusterRerouteResponse(StreamInput in) throws IOException {
super(in);
acknowledged = in.readBoolean();
state = ClusterState.readFrom(in, null);
explanations = RoutingExplanations.readFrom(in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public int hashCode() {
}

public Response(StreamInput in) throws IOException {
super(in);
assert in.getTransportVersion().onOrAfter(TransportVersions.V_8_3_0);
persistentSettings = Settings.readSettingsFromStream(in);
transientSettings = Settings.readSettingsFromStream(in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class ClusterSearchShardsResponse extends ActionResponse implements ToXCo
private final Map<String, AliasFilter> indicesAndFilters;

public ClusterSearchShardsResponse(StreamInput in) throws IOException {
super(in);
groups = in.readArray(ClusterSearchShardsGroup::new, ClusterSearchShardsGroup[]::new);
nodes = in.readArray(DiscoveryNode::new, DiscoveryNode[]::new);
indicesAndFilters = in.readMap(AliasFilter::readFrom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public CreateSnapshotResponse(@Nullable SnapshotInfo snapshotInfo) {
}

public CreateSnapshotResponse(StreamInput in) throws IOException {
super(in);
snapshotInfo = in.readOptionalWriteable(SnapshotInfo::readFrom);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public GetSnapshottableFeaturesResponse(List<SnapshottableFeature> features) {
}

public GetSnapshottableFeaturesResponse(StreamInput in) throws IOException {
super(in);
snapshottableFeatures = in.readCollectionAsImmutableList(SnapshottableFeature::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public ResetFeatureStateResponse(List<ResetFeatureStateStatus> resetFeatureState
}

public ResetFeatureStateResponse(StreamInput in) throws IOException {
super(in);
this.resetFeatureStateStatusList = in.readCollectionAsList(ResetFeatureStateStatus::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class GetShardSnapshotResponse extends ActionResponse {
}

GetShardSnapshotResponse(StreamInput in) throws IOException {
super(in);
this.latestShardSnapshot = in.readOptionalWriteable(ShardSnapshotInfo::new);
this.repositoryFailures = in.readMap(RepositoryException::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public RestoreSnapshotResponse(@Nullable RestoreInfo restoreInfo) {
}

public RestoreSnapshotResponse(StreamInput in) throws IOException {
super(in);
restoreInfo = in.readOptionalWriteable(RestoreInfo::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class SnapshotsStatusResponse extends ActionResponse implements ChunkedTo
private final List<SnapshotStatus> snapshots;

public SnapshotsStatusResponse(StreamInput in) throws IOException {
super(in);
snapshots = in.readCollectionAsImmutableList(SnapshotStatus::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class ClusterStateResponse extends ActionResponse {
private final boolean waitForTimedOut;

public ClusterStateResponse(StreamInput in) throws IOException {
super(in);
clusterName = new ClusterName(in);
clusterState = in.readOptionalWriteable(innerIn -> ClusterState.readFrom(innerIn, null));
waitForTimedOut = in.readBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public void writeTo(StreamOutput out) throws IOException {
}

public RemoteClusterStatsResponse(StreamInput in) throws IOException {
super(in);
this.clusterUUID = in.readString();
this.status = ClusterHealthStatus.readFrom(in);
this.versions = in.readCollectionAsSet(StreamInput::readString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class GetScriptContextResponse extends ActionResponse implements ToXConte
final Map<String, ScriptContextInfo> contexts;

GetScriptContextResponse(StreamInput in) throws IOException {
super(in);
int size = in.readInt();
Map<String, ScriptContextInfo> contexts = Maps.newMapWithExpectedSize(size);
for (int i = 0; i < size; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class GetScriptLanguageResponse extends ActionResponse implements ToXCont
}

GetScriptLanguageResponse(StreamInput in) throws IOException {
super(in);
info = new ScriptLanguagesInfo(in);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public class GetStoredScriptResponse extends ActionResponse implements ToXConten
private final StoredScriptSource source;

public GetStoredScriptResponse(StreamInput in) throws IOException {
super(in);

if (in.readBoolean()) {
source = new StoredScriptSource(in);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class PendingClusterTasksResponse extends ActionResponse implements Chunk
private final List<PendingClusterTask> pendingTasks;

public PendingClusterTasksResponse(StreamInput in) throws IOException {
super(in);
pendingTasks = in.readCollectionAsList(PendingClusterTask::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public GetIndexResponse(
}

GetIndexResponse(StreamInput in) throws IOException {
super(in);
this.indices = in.readStringArray();
mappings = in.readImmutableOpenMap(StreamInput::readString, in.getTransportVersion().before(TransportVersions.V_8_0_0) ? i -> {
int numMappings = i.readVInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
}

GetFieldMappingsResponse(StreamInput in) throws IOException {
super(in);
mappings = in.readImmutableMap(mapIn -> {
if (mapIn.getTransportVersion().before(TransportVersions.V_8_0_0)) {
int typesSize = mapIn.readVInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public GetMappingsResponse(Map<String, MappingMetadata> mappings) {
}

GetMappingsResponse(StreamInput in) throws IOException {
super(in);
mappings = in.readImmutableMap(in.getTransportVersion().before(TransportVersions.V_8_0_0) ? i -> {
int mappingCount = i.readVInt();
assert mappingCount == 1 || mappingCount == 0 : "Expected 0 or 1 mappings but got " + mappingCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public ResolveClusterActionResponse(Map<String, ResolveClusterInfo> infoMap) {
}

public ResolveClusterActionResponse(StreamInput in) throws IOException {
super(in);
this.infoMap = in.readImmutableMap(ResolveClusterInfo::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public GetSettingsResponse(Map<String, Settings> indexToSettings, Map<String, Se
}

public GetSettingsResponse(StreamInput in) throws IOException {
super(in);
indexToSettings = in.readImmutableMap(Settings::readSettingsFromStream);
indexToDefaultSettings = in.readImmutableMap(Settings::readSettingsFromStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ public IndicesShardStoresResponse(Map<String, Map<Integer, List<StoreStatus>>> s
}

public IndicesShardStoresResponse(StreamInput in) throws IOException {
super(in);
storeStatuses = in.readImmutableMap(
i -> i.readImmutableMap(StreamInput::readInt, j -> j.readCollectionAsImmutableList(StoreStatus::new))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public RolloverConfiguration getRolloverConfiguration() {
}

public SimulateIndexTemplateResponse(StreamInput in) throws IOException {
super(in);
resolvedTemplate = in.readOptionalWriteable(Template::new);
if (in.readBoolean()) {
int overlappingTemplatesCount = in.readInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class BulkResponse extends ActionResponse implements Iterable<BulkItemRes
private final BulkRequest.IncrementalState incrementalState;

public BulkResponse(StreamInput in) throws IOException {
super(in);
responses = in.readArray(BulkItemResponse::new, BulkItemResponse[]::new);
tookInMillis = in.readVLong();
ingestTookInMillis = in.readZLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public Response(
}

public Response(StreamInput in) throws IOException {
super(in);
this.indices = in.readCollectionAsList(ExplainIndexDataStreamLifecycle::new);
this.rolloverConfiguration = in.readOptionalWriteable(RolloverConfiguration::new);
this.globalRetention = in.getTransportVersion().onOrAfter(TransportVersions.V_8_14_0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public ExplainResponse(String index, String id, boolean exists, Explanation expl
}

public ExplainResponse(StreamInput in) throws IOException {
super(in);
index = in.readString();
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
in.readString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class FieldCapabilitiesNodeResponse extends ActionResponse implements Writeable
}

FieldCapabilitiesNodeResponse(StreamInput in) throws IOException {
super(in);
this.indexResponses = FieldCapabilitiesIndexResponse.readList(in);
this.failures = in.readMap(ShardId::new, StreamInput::readException);
this.unmatchedShardIds = in.readCollectionAsSet(ShardId::new);
Expand Down
Loading

0 comments on commit 27623f7

Please sign in to comment.