Internal: remove optional original indices

Original indices are optional in ShardDeleteByQueryRequest only for backwards compatibility, see #7406. We can remove this in master since 2.0 will require a full cluster restart.

Closes #8777
This commit is contained in:
javanna 2014-12-04 12:09:58 +01:00 committed by Luca Cavanna
parent 95c2d844a9
commit ad004072bb
3 changed files with 2 additions and 55 deletions

View File

@ -19,7 +19,6 @@
package org.elasticsearch.action; package org.elasticsearch.action;
import org.elasticsearch.Version;
import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
@ -31,16 +30,9 @@ import java.io.IOException;
*/ */
public class OriginalIndices implements IndicesRequest { public class OriginalIndices implements IndicesRequest {
public static OriginalIndices EMPTY = new OriginalIndices();
private final String[] indices; private final String[] indices;
private final IndicesOptions indicesOptions; private final IndicesOptions indicesOptions;
private OriginalIndices() {
this.indices = null;
this.indicesOptions = null;
}
public OriginalIndices(IndicesRequest indicesRequest) { public OriginalIndices(IndicesRequest indicesRequest) {
this(indicesRequest.indices(), indicesRequest.indicesOptions()); this(indicesRequest.indices(), indicesRequest.indicesOptions());
} }
@ -61,23 +53,6 @@ public class OriginalIndices implements IndicesRequest {
return indicesOptions; return indicesOptions;
} }
public static OriginalIndices readOptionalOriginalIndices(StreamInput in) throws IOException {
boolean empty = in.readBoolean();
if (!empty) {
return new OriginalIndices(in.readStringArray(), IndicesOptions.readIndicesOptions(in));
}
return OriginalIndices.EMPTY;
}
public static void writeOptionalOriginalIndices(OriginalIndices originalIndices, StreamOutput out) throws IOException {
boolean empty = originalIndices == EMPTY;
out.writeBoolean(empty);
if (!empty) {
out.writeStringArrayNullable(originalIndices.indices);
originalIndices.indicesOptions.writeIndicesOptions(out);
}
}
public static OriginalIndices readOriginalIndices(StreamInput in) throws IOException { public static OriginalIndices readOriginalIndices(StreamInput in) throws IOException {
return new OriginalIndices(in.readStringArray(), IndicesOptions.readIndicesOptions(in)); return new OriginalIndices(in.readStringArray(), IndicesOptions.readIndicesOptions(in));
} }

View File

@ -19,7 +19,6 @@
package org.elasticsearch.action.deletebyquery; package org.elasticsearch.action.deletebyquery;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.OriginalIndices; import org.elasticsearch.action.OriginalIndices;
import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.IndicesOptions;
@ -137,7 +136,7 @@ public class ShardDeleteByQueryRequest extends ShardReplicationOperationRequest<
} }
nowInMillis = in.readVLong(); nowInMillis = in.readVLong();
originalIndices = OriginalIndices.readOptionalOriginalIndices(in); originalIndices = OriginalIndices.readOriginalIndices(in);
} }
@Override @Override
@ -163,7 +162,7 @@ public class ShardDeleteByQueryRequest extends ShardReplicationOperationRequest<
out.writeVInt(0); out.writeVInt(0);
} }
out.writeVLong(nowInMillis); out.writeVLong(nowInMillis);
OriginalIndices.writeOptionalOriginalIndices(originalIndices, out); OriginalIndices.writeOriginalIndices(originalIndices, out);
} }
@Override @Override

View File

@ -19,7 +19,6 @@
package org.elasticsearch.action; package org.elasticsearch.action;
import org.elasticsearch.Version;
import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.io.stream.BytesStreamInput; import org.elasticsearch.common.io.stream.BytesStreamInput;
import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.BytesStreamOutput;
@ -29,7 +28,6 @@ import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
public class OriginalIndicesTests extends ElasticsearchTestCase { public class OriginalIndicesTests extends ElasticsearchTestCase {
@ -56,31 +54,6 @@ public class OriginalIndicesTests extends ElasticsearchTestCase {
} }
} }
@Test
public void testOptionalOriginalIndicesSerialization() throws IOException {
int iterations = iterations(10, 30);
for (int i = 0; i < iterations; i++) {
OriginalIndices originalIndices;
boolean missing = randomBoolean();
if (missing) {
originalIndices = randomOriginalIndices();
} else {
originalIndices = OriginalIndices.EMPTY;
}
BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(randomVersion());
OriginalIndices.writeOptionalOriginalIndices(originalIndices, out);
BytesStreamInput in = new BytesStreamInput(out.bytes());
in.setVersion(out.getVersion());
OriginalIndices originalIndices2 = OriginalIndices.readOptionalOriginalIndices(in);
assertThat(originalIndices2.indices(), equalTo(originalIndices.indices()));
assertThat(originalIndices2.indicesOptions(), equalTo(originalIndices.indicesOptions()));
}
}
private static OriginalIndices randomOriginalIndices() { private static OriginalIndices randomOriginalIndices() {
int numIndices = randomInt(10); int numIndices = randomInt(10);
String[] indices = new String[numIndices]; String[] indices = new String[numIndices];