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

Remove redundant version checks in transport serialisation #4731

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -21,7 +21,6 @@

import com.carrotsearch.hppc.ObjectObjectOpenHashMap;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.stats.CommonStats;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -152,11 +151,7 @@ public void readFrom(StreamInput in) throws IOException {
idCache = IdCacheStats.readIdCacheStats(in);
completion = CompletionStats.readCompletionStats(in);
segments = SegmentsStats.readSegmentsStats(in);
if (in.getVersion().after(Version.V_1_0_0_RC1)) {
peroclate = PercolateStats.readPercolateStats(in);
} else {
peroclate = new PercolateStats();
}
peroclate = PercolateStats.readPercolateStats(in);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo! :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix :)

}

@Override
Expand All @@ -170,9 +165,7 @@ public void writeTo(StreamOutput out) throws IOException {
idCache.writeTo(out);
completion.writeTo(out);
segments.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_1_0_0_RC1)) {
peroclate.writeTo(out);
}
peroclate.writeTo(out);
}

public static ClusterStatsIndices readIndicesStats(StreamInput in) throws IOException {
Expand Down
Expand Up @@ -452,21 +452,17 @@ public void readFrom(StreamInput in) throws IOException {
count = in.readVInt();
cpuPercent = in.readVInt();
totalOpenFileDescriptors = in.readVLong();
if (in.getVersion().onOrAfter(Version.V_0_90_10)) {
minOpenFileDescriptors = in.readLong();
maxOpenFileDescriptors = in.readLong();
}
minOpenFileDescriptors = in.readLong();
maxOpenFileDescriptors = in.readLong();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(count);
out.writeVInt(cpuPercent);
out.writeVLong(totalOpenFileDescriptors);
if (out.getVersion().onOrAfter(Version.V_0_90_10)) {
out.writeLong(minOpenFileDescriptors);
out.writeLong(maxOpenFileDescriptors);
}
out.writeLong(minOpenFileDescriptors);
out.writeLong(maxOpenFileDescriptors);
}

public static ProcessStats readStats(StreamInput in) throws IOException {
Expand Down
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.action.admin.indices.flush;

import org.elasticsearch.Version;
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -87,19 +86,13 @@ public FlushRequest force(boolean force) {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (out.getVersion().onOrBefore(Version.V_0_90_3)) {
out.writeBoolean(false); // refresh flag
}
out.writeBoolean(full);
out.writeBoolean(force);
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
if (in.getVersion().onOrBefore(Version.V_0_90_3)) {
in.readBoolean(); // refresh flag
}
full = in.readBoolean();
force = in.readBoolean();
}
Expand Down
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.action.admin.indices.flush;

import org.elasticsearch.Version;
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -54,19 +53,13 @@ public boolean force() {
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
if (in.getVersion().onOrBefore(Version.V_0_90_3)) {
in.readBoolean(); // refresh flag
}
full = in.readBoolean();
force = in.readBoolean();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (out.getVersion().onOrBefore(Version.V_0_90_3)) {
out.writeBoolean(false); // refresh flag
}
out.writeBoolean(full);
out.writeBoolean(force);
}
Expand Down
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.action.admin.indices.optimize;

import org.elasticsearch.Version;
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -137,9 +136,6 @@ public void readFrom(StreamInput in) throws IOException {
maxNumSegments = in.readInt();
onlyExpungeDeletes = in.readBoolean();
flush = in.readBoolean();
if (in.getVersion().onOrBefore(Version.V_0_90_3)) {
in.readBoolean(); // old refresh flag
}
}

public void writeTo(StreamOutput out) throws IOException {
Expand All @@ -148,8 +144,5 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeInt(maxNumSegments);
out.writeBoolean(onlyExpungeDeletes);
out.writeBoolean(flush);
if (out.getVersion().onOrBefore(Version.V_0_90_3)) {
out.writeBoolean(false); // old refresh flag
}
}
}
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.action.admin.indices.optimize;

import org.elasticsearch.Version;
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -70,9 +69,6 @@ public void readFrom(StreamInput in) throws IOException {
maxNumSegments = in.readInt();
onlyExpungeDeletes = in.readBoolean();
flush = in.readBoolean();
if (in.getVersion().onOrBefore(Version.V_0_90_3)) {
in.readBoolean(); // old refresh flag
}
}

@Override
Expand All @@ -82,8 +78,5 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeInt(maxNumSegments);
out.writeBoolean(onlyExpungeDeletes);
out.writeBoolean(flush);
if (out.getVersion().onOrBefore(Version.V_0_90_3)) {
out.writeBoolean(false); // old refresh flag
}
}
}
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.action.admin.indices.stats;

import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -479,19 +478,13 @@ public void readFrom(StreamInput in) throws IOException {
if (in.readBoolean()) {
percolate = PercolateStats.readPercolateStats(in);
}
if (in.getVersion().onOrAfter(Version.V_0_90_4)) {
if (in.readBoolean()) {
completion = CompletionStats.readCompletionStats(in);
}
}
if (in.getVersion().after(Version.V_0_90_6)) {
if (in.readBoolean()) {
segments = SegmentsStats.readSegmentsStats(in);
}
if (in.readBoolean()) {
completion = CompletionStats.readCompletionStats(in);
}
if (in.getVersion().after(Version.V_1_0_0_Beta2)) {
translog = in.readOptionalStreamable(new TranslogStats());
if (in.readBoolean()) {
segments = SegmentsStats.readSegmentsStats(in);
}
translog = in.readOptionalStreamable(new TranslogStats());
}

@Override
Expand Down Expand Up @@ -574,25 +567,19 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(true);
percolate.writeTo(out);
}
if (out.getVersion().onOrAfter(Version.V_0_90_4)) {
if (completion == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
completion.writeTo(out);
}
}
if (out.getVersion().after(Version.V_0_90_6)) {
if (segments == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
segments.writeTo(out);
}
if (completion == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
completion.writeTo(out);
}
if (out.getVersion().after(Version.V_1_0_0_Beta2)) {
out.writeOptionalStreamable(translog);
if (segments == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
segments.writeTo(out);
}
out.writeOptionalStreamable(translog);
}

// note, requires a wrapping object
Expand Down
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.action.admin.indices.stats;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
Expand Down Expand Up @@ -177,9 +176,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeStringArrayNullable(types);
out.writeStringArrayNullable(groups);
out.writeStringArrayNullable(fieldDataFields);
if (out.getVersion().onOrAfter(Version.V_0_90_4)) {
out.writeStringArrayNullable(completionDataFields);
}
out.writeStringArrayNullable(completionDataFields);
}

@Override
Expand All @@ -194,9 +191,7 @@ public void readFrom(StreamInput in) throws IOException {
types = in.readStringArray();
groups = in.readStringArray();
fieldDataFields = in.readStringArray();
if (in.getVersion().onOrAfter(Version.V_0_90_4)) {
completionDataFields = in.readStringArray();
}
completionDataFields = in.readStringArray();
}

@Override
Expand Down
Expand Up @@ -18,17 +18,14 @@
*/
package org.elasticsearch.action.admin.indices.template.delete;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

import java.io.IOException;

import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.common.unit.TimeValue.readTimeValue;

/**
* A request to delete an index template.
Expand Down Expand Up @@ -67,19 +64,11 @@ String name() {
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
name = in.readString();
//timeout was ignored till 0.90.7, removed afterwards
if (in.getVersion().onOrBefore(Version.V_0_90_7)) {
readTimeValue(in);
}
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(name);
//timeout was ignored till 0.90.7, removed afterwards
if (out.getVersion().onOrBefore(Version.V_0_90_7)) {
AcknowledgedRequest.DEFAULT_ACK_TIMEOUT.writeTo(out);
}
}
}
Expand Up @@ -18,7 +18,6 @@
*/
package org.elasticsearch.action.admin.indices.template.get;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
import org.elasticsearch.common.Strings;
Expand Down Expand Up @@ -76,21 +75,12 @@ public String[] names() {
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
if (in.getVersion().onOrAfter(Version.V_0_90_4)) {
names = in.readStringArray();
} else {
names = new String[1];
names[0] = in.readString();
}
names = in.readStringArray();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_0_90_4)) {
out.writeStringArray(names);
} else {
out.writeString(names.length == 0 ? "*" : names[0]);
}
out.writeStringArray(names);
}
}
Expand Up @@ -21,9 +21,7 @@
import org.elasticsearch.ElasticsearchGenerationException;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.bytes.BytesReference;
Expand All @@ -45,7 +43,6 @@
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.common.settings.ImmutableSettings.readSettingsFromStream;
import static org.elasticsearch.common.settings.ImmutableSettings.writeSettingsToStream;
import static org.elasticsearch.common.unit.TimeValue.readTimeValue;

/**
* A request to create an index template.
Expand Down Expand Up @@ -348,10 +345,6 @@ public void readFrom(StreamInput in) throws IOException {
order = in.readInt();
create = in.readBoolean();
settings = readSettingsFromStream(in);
//timeout was ignored till 0.90.7, removed afterwards
if (in.getVersion().onOrBefore(Version.V_0_90_7)) {
readTimeValue(in);
}
int size = in.readVInt();
for (int i = 0; i < size; i++) {
mappings.put(in.readString(), in.readString());
Expand All @@ -373,10 +366,6 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeInt(order);
out.writeBoolean(create);
writeSettingsToStream(settings, out);
//timeout was ignored till 0.90.7, removed afterwards
if (out.getVersion().onOrBefore(Version.V_0_90_7)) {
AcknowledgedRequest.DEFAULT_ACK_TIMEOUT.writeTo(out);
}
out.writeVInt(mappings.size());
for (Map.Entry<String, String> entry : mappings.entrySet()) {
out.writeString(entry.getKey());
Expand Down