From ba725f8986463d41d14fd331b82702ab65a2e87e Mon Sep 17 00:00:00 2001 From: kimchy Date: Mon, 17 Jan 2011 14:37:36 +0200 Subject: [PATCH] fix a (rare) case where search will fail due to failed serialization --- .../search/SearchPhaseExecutionException.java | 8 ++++++-- .../search/SearchShardTarget.java | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java index 3a4011ed44d..4a8e8c83e05 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java @@ -50,13 +50,17 @@ public class SearchPhaseExecutionException extends ElasticSearchException { return shardFailures; } - private static final String buildMessage(String phaseName, String msg, ShardSearchFailure[] shardFailures) { + private static String buildMessage(String phaseName, String msg, ShardSearchFailure[] shardFailures) { StringBuilder sb = new StringBuilder(); sb.append("Failed to execute phase [").append(phaseName).append("], ").append(msg); if (shardFailures != null && shardFailures.length > 0) { sb.append("; shardFailures "); for (ShardSearchFailure shardFailure : shardFailures) { - sb.append("{").append(shardFailure.shard()).append(": ").append(shardFailure.reason()).append("}"); + if (shardFailure.shard() != null) { + sb.append("{").append(shardFailure.shard()).append(": ").append(shardFailure.reason()).append("}"); + } else { + sb.append("{").append(shardFailure.reason()).append("}"); + } } } return sb.toString(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchShardTarget.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchShardTarget.java index cbcd017e7b2..cb204ad01a1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchShardTarget.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchShardTarget.java @@ -23,6 +23,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; +import javax.annotation.Nullable; import java.io.IOException; import java.io.Serializable; @@ -49,11 +50,11 @@ public class SearchShardTarget implements Streamable, Serializable { this.shardId = shardId; } - public String nodeId() { + @Nullable public String nodeId() { return nodeId; } - public String getNodeId() { + @Nullable public String getNodeId() { return nodeId; } @@ -80,13 +81,20 @@ public class SearchShardTarget implements Streamable, Serializable { } @Override public void readFrom(StreamInput in) throws IOException { - nodeId = in.readUTF(); + if (in.readBoolean()) { + nodeId = in.readUTF(); + } index = in.readUTF(); shardId = in.readVInt(); } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeUTF(nodeId); + if (nodeId == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + out.writeUTF(nodeId); + } out.writeUTF(index); out.writeVInt(shardId); } @@ -112,6 +120,9 @@ public class SearchShardTarget implements Streamable, Serializable { } @Override public String toString() { + if (nodeId == null) { + return "[_na_][" + index + "][" + shardId + "]"; + } return "[" + nodeId + "][" + index + "][" + shardId + "]"; } }