rollback multi get fields change

seems like it still fails while serializing with sporadic failures in the tests (due to routing on serialization), need to test it in a consistent manner
This commit is contained in:
Shay Banon 2013-05-20 06:56:37 -07:00
parent 0066566357
commit e0825686f3
2 changed files with 30 additions and 57 deletions

View File

@ -20,7 +20,6 @@
package org.elasticsearch.action.get;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ValidateActions;
@ -35,10 +34,9 @@ import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements Iterable<MultiGetRequest.Item> {
public class MultiGetRequest extends ActionRequest<MultiGetRequest> {
/**
* A single get item.
@ -114,26 +112,18 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements I
@Override
public void readFrom(StreamInput in) throws IOException {
index = in.readString();
type = in.readOptionalString();
if (in.readBoolean()) {
type = in.readString();
}
id = in.readString();
routing = in.readOptionalString();
if (in.getVersion().before(Version.V_0_90_1)) {
int size = in.readVInt();
if (size > 0) {
fields = new String[size];
for (int i = 0; i < size; i++) {
fields[i] = in.readString();
}
}
} else {
// post 0.90.1, we maintain the semantic difference between not setting fields (default to _source)
// and setting fields to empty array (no data to return)
int size = in.readInt();
if (size >= 0) {
fields = new String[size];
for (int i = 0; i < size; i++) {
fields[i] = in.readString();
}
if (in.readBoolean()) {
routing = in.readString();
}
int size = in.readVInt();
if (size > 0) {
fields = new String[size];
for (int i = 0; i < size; i++) {
fields[i] = in.readString();
}
}
}
@ -141,26 +131,25 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements I
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(index);
out.writeOptionalString(type);
out.writeString(id);
out.writeOptionalString(routing);
if (out.getVersion().before(Version.V_0_90_1)) {
if (fields == null) {
out.writeVInt(0);
} else {
out.writeVInt(fields.length);
for (String field : fields) {
out.writeString(field);
}
}
if (type == null) {
out.writeBoolean(false);
} else {
if (fields == null) {
out.writeInt(-1);
} else {
out.writeInt(fields.length);
for (String field : fields) {
out.writeString(field);
}
out.writeBoolean(true);
out.writeString(type);
}
out.writeString(id);
if (routing == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeString(routing);
}
if (fields == null) {
out.writeVInt(0);
} else {
out.writeVInt(fields.length);
for (String field : fields) {
out.writeString(field);
}
}
}
@ -174,11 +163,6 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements I
List<Item> items = new ArrayList<Item>();
@Override
public Iterator<Item> iterator() {
return items.iterator();
}
public MultiGetRequest add(Item item) {
items.add(item);
return this;

View File

@ -199,17 +199,6 @@ public class GetActionTests extends AbstractNodesTests {
assertThat(response.getResponses().length, equalTo(2));
assertThat(response.getResponses()[0].getResponse().getSourceAsBytes(), nullValue());
assertThat(response.getResponses()[0].getResponse().getField("field").getValues().get(0).toString(), equalTo("value1"));
// multi get with "no" fields, nothing should return, exists indication should still be around
response = client.prepareMultiGet()
.add(new MultiGetRequest.Item("test", "type1", "1").fields(Strings.EMPTY_ARRAY))
.add(new MultiGetRequest.Item("test", "type1", "3").fields(Strings.EMPTY_ARRAY))
.execute().actionGet();
assertThat(response.getResponses().length, equalTo(2));
assertThat(response.getResponses()[0].getResponse().isExists(), equalTo(true));
assertThat(response.getResponses()[0].getResponse().getSourceAsBytes(), nullValue());
assertThat(response.getResponses()[0].getResponse().getFields().size(), equalTo(0));
}
@Test