Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the writeTo and read for get requests #87467

Merged
merged 1 commit into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions server/src/main/java/org/elasticsearch/action/get/GetRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
private VersionType versionType = VersionType.INTERNAL;
private long version = Versions.MATCH_ANY;

public GetRequest() {}

GetRequest(StreamInput in) throws IOException {
super(in);
if (in.getVersion().before(Version.V_8_0_0)) {
Expand All @@ -72,7 +74,23 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
fetchSourceContext = in.readOptionalWriteable(FetchSourceContext::readFrom);
}

public GetRequest() {}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (out.getVersion().before(Version.V_8_0_0)) {
out.writeString(MapperService.SINGLE_MAPPING_NAME);
}
out.writeString(id);
out.writeOptionalString(routing);
out.writeOptionalString(preference);

out.writeBoolean(refresh);
out.writeOptionalStringArray(storedFields);
out.writeBoolean(realtime);
out.writeByte(versionType.getValue());
out.writeLong(version);
out.writeOptionalWriteable(fetchSourceContext);
}

/**
* Constructs a new get request against the specified index. The {@link #id(String)} must also be set.
Expand Down Expand Up @@ -224,24 +242,6 @@ public VersionType versionType() {
return this.versionType;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (out.getVersion().before(Version.V_8_0_0)) {
out.writeString(MapperService.SINGLE_MAPPING_NAME);
}
out.writeString(id);
out.writeOptionalString(routing);
out.writeOptionalString(preference);

out.writeBoolean(refresh);
out.writeOptionalStringArray(storedFields);
out.writeBoolean(realtime);
out.writeByte(versionType.getValue());
out.writeLong(version);
out.writeOptionalWriteable(fetchSourceContext);
}

@Override
public String toString() {
return "get [" + index + "][" + id + "]: routing [" + routing + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ public MultiGetRequest(StreamInput in) throws IOException {
items = in.readList(Item::new);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalString(preference);
out.writeBoolean(refresh);
out.writeBoolean(realtime);
out.writeList(items);
}

public List<Item> getItems() {
return this.items;
}
Expand Down Expand Up @@ -541,15 +550,6 @@ public Iterator<Item> iterator() {
return Collections.unmodifiableCollection(items).iterator();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalString(preference);
out.writeBoolean(refresh);
out.writeBoolean(realtime);
out.writeList(items);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
List<Integer> locations;
List<MultiGetRequest.Item> items;

MultiGetShardRequest(MultiGetRequest multiGetRequest, String index, int shardId) {
super(index);
this.shardId = shardId;
locations = new ArrayList<>();
items = new ArrayList<>();
preference = multiGetRequest.preference;
realtime = multiGetRequest.realtime;
refresh = multiGetRequest.refresh;
}

MultiGetShardRequest(StreamInput in) throws IOException {
super(in);
int size = in.readVInt();
Expand All @@ -43,14 +53,19 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
realtime = in.readBoolean();
}

MultiGetShardRequest(MultiGetRequest multiGetRequest, String index, int shardId) {
super(index);
this.shardId = shardId;
locations = new ArrayList<>();
items = new ArrayList<>();
preference = multiGetRequest.preference;
realtime = multiGetRequest.realtime;
refresh = multiGetRequest.refresh;
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVInt(locations.size());

for (int i = 0; i < locations.size(); i++) {
out.writeVInt(locations.get(i));
items.get(i).writeTo(out);
}

out.writeOptionalString(preference);
out.writeBoolean(refresh);
out.writeBoolean(realtime);
}

@Override
Expand Down Expand Up @@ -107,19 +122,4 @@ public String[] indices() {
}
return indices;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVInt(locations.size());

for (int i = 0; i < locations.size(); i++) {
out.writeVInt(locations.get(i));
items.get(i).writeTo(out);
}

out.writeOptionalString(preference);
out.writeBoolean(refresh);
out.writeBoolean(realtime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,30 @@ public ShardSearchRequest(
this.forceSyntheticSource = forceSyntheticSource;
}

public ShardSearchRequest(ShardSearchRequest clone) {
this.shardId = clone.shardId;
this.shardRequestIndex = clone.shardRequestIndex;
this.searchType = clone.searchType;
this.numberOfShards = clone.numberOfShards;
this.scroll = clone.scroll;
this.source(clone.source);
this.aliasFilter = clone.aliasFilter;
this.indexBoost = clone.indexBoost;
this.nowInMillis = clone.nowInMillis;
this.requestCache = clone.requestCache;
this.clusterAlias = clone.clusterAlias;
this.allowPartialSearchResults = clone.allowPartialSearchResults;
this.canReturnNullResponseIfMatchNoDocs = clone.canReturnNullResponseIfMatchNoDocs;
this.bottomSortValues = clone.bottomSortValues;
this.originalIndices = clone.originalIndices;
this.readerId = clone.readerId;
this.keepAlive = clone.keepAlive;
this.channelVersion = clone.channelVersion;
this.waitForCheckpoint = clone.waitForCheckpoint;
this.waitForCheckpointsTimeout = clone.waitForCheckpointsTimeout;
this.forceSyntheticSource = clone.forceSyntheticSource;
}

public ShardSearchRequest(StreamInput in) throws IOException {
super(in);
shardId = new ShardId(in);
Expand Down Expand Up @@ -302,30 +326,6 @@ public ShardSearchRequest(StreamInput in) throws IOException {
originalIndices = OriginalIndices.readOriginalIndices(in);
}

public ShardSearchRequest(ShardSearchRequest clone) {
this.shardId = clone.shardId;
this.shardRequestIndex = clone.shardRequestIndex;
this.searchType = clone.searchType;
this.numberOfShards = clone.numberOfShards;
this.scroll = clone.scroll;
this.source(clone.source);
this.aliasFilter = clone.aliasFilter;
this.indexBoost = clone.indexBoost;
this.nowInMillis = clone.nowInMillis;
this.requestCache = clone.requestCache;
this.clusterAlias = clone.clusterAlias;
this.allowPartialSearchResults = clone.allowPartialSearchResults;
this.canReturnNullResponseIfMatchNoDocs = clone.canReturnNullResponseIfMatchNoDocs;
this.bottomSortValues = clone.bottomSortValues;
this.originalIndices = clone.originalIndices;
this.readerId = clone.readerId;
this.keepAlive = clone.keepAlive;
this.channelVersion = clone.channelVersion;
this.waitForCheckpoint = clone.waitForCheckpoint;
this.waitForCheckpointsTimeout = clone.waitForCheckpointsTimeout;
this.forceSyntheticSource = clone.forceSyntheticSource;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand Down