Merge branch 'master' into feature/query-refactoring

Conflicts:
	core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
	core/src/main/java/org/elasticsearch/transport/local/LocalTransport.java
	core/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java
This commit is contained in:
javanna 2015-06-30 17:38:31 +02:00 committed by Luca Cavanna
commit 654dc20897
225 changed files with 2985 additions and 1289 deletions

View File

@ -819,7 +819,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1.2</version>
<version>2.1.3</version>
<configuration>
<distribution>Elasticsearch</distribution>
<group>Application/Internet</group>
@ -834,11 +834,6 @@
<defaultDirmode>755</defaultDirmode>
<defaultUsername>root</defaultUsername>
<defaultGroupname>root</defaultGroupname>
<keyname>${gpg.key}</keyname>
<keypath>${gpg.keyring}</keypath>
<keyPassphrase>
<passphrase>${gpg.passphrase}</passphrase>
</keyPassphrase>
<mappings>
<!-- Add bin directory -->
<mapping>
@ -1101,5 +1096,29 @@
</activation>
<!-- not including license-maven-plugin is sufficent to expose default license -->
</profile>
<profile>
<id>sign-rpm</id>
<activation>
<property>
<name>rpm.sign</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<configuration>
<keyname>${gpg.key}</keyname>
<keypath>${gpg.keyring}</keypath>
<keyPassphrase>
<passphrase>${gpg.passphrase}</passphrase>
</keyPassphrase>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -22,17 +22,19 @@ package org.elasticsearch;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexException;
import org.elasticsearch.rest.HasRestHeaders;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
@ -41,6 +43,7 @@ import java.util.*;
public class ElasticsearchException extends RuntimeException implements ToXContent {
public static final String REST_EXCEPTION_SKIP_CAUSE = "rest.exception.skip_cause";
private static final Map<String, Constructor<? extends ElasticsearchException>> MAPPING;
/**
* Construct a <code>ElasticsearchException</code> with the specified detail message.
@ -62,6 +65,11 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
super(msg, cause);
}
public ElasticsearchException(StreamInput in) throws IOException {
super(in.readOptionalString(), in.readThrowable());
readStackTrace(this, in);
}
/**
* Returns the rest status code associated with this exception.
*/
@ -152,21 +160,79 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
}
}
public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(this.getMessage());
out.writeThrowable(this.getCause());
writeStackTraces(this, out);
}
public static ElasticsearchException readException(StreamInput input, String name) throws IOException {
Constructor<? extends ElasticsearchException> elasticsearchException = MAPPING.get(name);
if (elasticsearchException == null) {
throw new IllegalStateException("unknown exception with name: " + name);
}
try {
return elasticsearchException.newInstance(input);
} catch (InstantiationException|IllegalAccessException|InvocationTargetException e) {
throw new IOException("failed to read exception: [" + name + "]", e);
}
}
/**
* Retruns <code>true</code> iff the given name is a registered for an exception to be read.
*/
public static boolean isRegistered(String name) {
return MAPPING.containsKey(name);
}
static Set<String> getRegisteredKeys() { // for testing
return MAPPING.keySet();
}
/**
* A base class for exceptions that should carry rest headers
*/
@SuppressWarnings("unchecked")
public static class WithRestHeaders extends ElasticsearchException implements HasRestHeaders {
public static class WithRestHeadersException extends ElasticsearchException implements HasRestHeaders {
private final ImmutableMap<String, List<String>> headers;
private final Map<String, List<String>> headers;
public WithRestHeaders(String msg, Tuple<String, String[]>... headers) {
public WithRestHeadersException(String msg, Tuple<String, String[]>... headers) {
super(msg);
this.headers = headers(headers);
}
public WithRestHeadersException(StreamInput in) throws IOException {
super(in);
int numKeys = in.readVInt();
ImmutableMap.Builder<String, List<String>> builder = ImmutableMap.builder();
for (int i = 0; i < numKeys; i++) {
final String key = in.readString();
final int numValues = in.readVInt();
final ArrayList<String> headers = new ArrayList<>(numValues);
for (int j = 0; j < numValues; j++) {
headers.add(in.readString());
}
builder.put(key, headers);
}
headers = builder.build();
}
@Override
public ImmutableMap<String, List<String>> getHeaders() {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVInt(headers.size());
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
out.writeString(entry.getKey());
out.writeVInt(entry.getValue().size());
for (String v : entry.getValue()) {
out.writeString(v);
}
}
}
@Override
public Map<String, List<String>> getHeaders() {
return headers;
}
@ -174,7 +240,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
return Tuple.tuple(name, values);
}
private static ImmutableMap<String, List<String>> headers(Tuple<String, String[]>... headers) {
private static Map<String, List<String>> headers(Tuple<String, String[]>... headers) {
Map<String, List<String>> map = Maps.newHashMap();
for (Tuple<String, String[]> header : headers) {
List<String> list = map.get(header.v1());
@ -290,4 +356,212 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
public String toString() {
return ExceptionsHelper.detailedMessage(this).trim();
}
/**
* Deserializes stacktrace elements as well as suppressed exceptions from the given output stream and
* adds it to the given exception.
*/
public static <T extends Throwable> T readStackTrace(T throwable, StreamInput in) throws IOException {
final int stackTraceElements = in.readVInt();
StackTraceElement[] stackTrace = new StackTraceElement[stackTraceElements];
for (int i = 0; i < stackTraceElements; i++) {
final String declaringClasss = in.readString();
final String fileName = in.readOptionalString();
final String methodName = in.readString();
final int lineNumber = in.readVInt();
stackTrace[i] = new StackTraceElement(declaringClasss,methodName, fileName, lineNumber);
}
throwable.setStackTrace(stackTrace);
int numSuppressed = in.readVInt();
for (int i = 0; i < numSuppressed; i++) {
throwable.addSuppressed(in.readThrowable());
}
return throwable;
}
/**
* Serializes the given exceptions stacktrace elements as well as it's suppressed exceptions to the given output stream.
*/
public static <T extends Throwable> T writeStackTraces(T throwable, StreamOutput out) throws IOException {
StackTraceElement[] stackTrace = throwable.getStackTrace();
out.writeVInt(stackTrace.length);
for (StackTraceElement element : stackTrace) {
out.writeString(element.getClassName());
out.writeOptionalString(element.getFileName());
out.writeString(element.getMethodName());
out.writeVInt(element.getLineNumber());
}
Throwable[] suppressed = throwable.getSuppressed();
out.writeVInt(suppressed.length);
for (Throwable t : suppressed) {
out.writeThrowable(t);
}
return throwable;
}
static {
Class<? extends ElasticsearchException>[] exceptions = new Class[]{
org.elasticsearch.common.settings.SettingsException.class,
org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException.class,
org.elasticsearch.index.engine.IndexFailedEngineException.class,
org.elasticsearch.indices.recovery.RecoverFilesRecoveryException.class,
org.elasticsearch.index.translog.TruncatedTranslogException.class,
org.elasticsearch.repositories.RepositoryException.class,
org.elasticsearch.index.shard.IndexShardException.class,
org.elasticsearch.index.engine.DocumentSourceMissingException.class,
org.elasticsearch.index.engine.DocumentMissingException.class,
org.elasticsearch.common.util.concurrent.EsRejectedExecutionException.class,
org.elasticsearch.cluster.routing.RoutingException.class,
org.elasticsearch.common.lucene.Lucene.EarlyTerminationException.class,
org.elasticsearch.indices.InvalidAliasNameException.class,
org.elasticsearch.index.engine.EngineCreationFailureException.class,
org.elasticsearch.index.snapshots.IndexShardRestoreFailedException.class,
org.elasticsearch.script.groovy.GroovyScriptCompilationException.class,
org.elasticsearch.cluster.routing.RoutingValidationException.class,
org.elasticsearch.snapshots.SnapshotMissingException.class,
org.elasticsearch.index.shard.IndexShardRecoveryException.class,
org.elasticsearch.action.search.SearchPhaseExecutionException.class,
org.elasticsearch.common.util.concurrent.UncategorizedExecutionException.class,
org.elasticsearch.index.engine.SnapshotFailedEngineException.class,
org.elasticsearch.action.search.ReduceSearchPhaseException.class,
org.elasticsearch.action.RoutingMissingException.class,
org.elasticsearch.index.engine.DeleteFailedEngineException.class,
org.elasticsearch.indices.recovery.RecoveryFailedException.class,
org.elasticsearch.search.builder.SearchSourceBuilderException.class,
org.elasticsearch.index.engine.RefreshFailedEngineException.class,
org.elasticsearch.index.snapshots.IndexShardSnapshotException.class,
org.elasticsearch.search.query.QueryPhaseExecutionException.class,
org.elasticsearch.cluster.metadata.ProcessClusterEventTimeoutException.class,
org.elasticsearch.index.shard.IndexShardCreationException.class,
org.elasticsearch.index.percolator.PercolatorException.class,
org.elasticsearch.snapshots.ConcurrentSnapshotExecutionException.class,
org.elasticsearch.indices.IndexTemplateAlreadyExistsException.class,
org.elasticsearch.indices.InvalidIndexNameException.class,
org.elasticsearch.index.IndexException.class,
org.elasticsearch.indices.recovery.DelayRecoveryException.class,
org.elasticsearch.indices.AliasFilterParsingException.class,
org.elasticsearch.indices.InvalidIndexTemplateException.class,
org.elasticsearch.http.HttpException.class,
org.elasticsearch.index.shard.IndexShardNotRecoveringException.class,
org.elasticsearch.indices.IndexPrimaryShardNotAllocatedException.class,
org.elasticsearch.env.FailedToResolveConfigException.class,
org.elasticsearch.action.UnavailableShardsException.class,
org.elasticsearch.transport.ActionNotFoundTransportException.class,
org.elasticsearch.index.shard.TranslogRecoveryPerformer.BatchOperationException.class,
org.elasticsearch.ElasticsearchException.class,
org.elasticsearch.index.shard.IndexShardClosedException.class,
org.elasticsearch.client.transport.NoNodeAvailableException.class,
org.elasticsearch.cluster.block.ClusterBlockException.class,
org.elasticsearch.action.FailedNodeException.class,
org.elasticsearch.indices.TypeMissingException.class,
org.elasticsearch.index.IndexShardMissingException.class,
org.elasticsearch.indices.InvalidTypeNameException.class,
org.elasticsearch.transport.netty.SizeHeaderFrameDecoder.HttpOnTransportException.class,
org.elasticsearch.common.util.CancellableThreads.ExecutionCancelledException.class,
org.elasticsearch.snapshots.SnapshotCreationException.class,
org.elasticsearch.script.groovy.GroovyScriptExecutionException.class,
org.elasticsearch.indices.IndexTemplateMissingException.class,
org.elasticsearch.transport.NodeNotConnectedException.class,
org.elasticsearch.index.shard.IndexShardRecoveringException.class,
org.elasticsearch.index.shard.IndexShardStartedException.class,
org.elasticsearch.indices.IndexClosedException.class,
org.elasticsearch.repositories.RepositoryMissingException.class,
org.elasticsearch.search.warmer.IndexWarmerMissingException.class,
org.elasticsearch.percolator.PercolateException.class,
org.elasticsearch.index.engine.EngineException.class,
org.elasticsearch.script.expression.ExpressionScriptExecutionException.class,
org.elasticsearch.action.NoShardAvailableActionException.class,
org.elasticsearch.transport.ReceiveTimeoutTransportException.class,
org.elasticsearch.http.BindHttpException.class,
org.elasticsearch.transport.RemoteTransportException.class,
org.elasticsearch.index.shard.IndexShardRelocatedException.class,
org.elasticsearch.snapshots.InvalidSnapshotNameException.class,
org.elasticsearch.repositories.RepositoryVerificationException.class,
org.elasticsearch.search.SearchException.class,
org.elasticsearch.transport.ActionTransportException.class,
org.elasticsearch.common.settings.NoClassSettingsException.class,
org.elasticsearch.transport.NodeShouldNotConnectException.class,
org.elasticsearch.index.mapper.MapperParsingException.class,
org.elasticsearch.action.support.replication.TransportReplicationAction.RetryOnReplicaException.class,
org.elasticsearch.search.dfs.DfsPhaseExecutionException.class,
org.elasticsearch.index.engine.VersionConflictEngineException.class,
org.elasticsearch.snapshots.SnapshotRestoreException.class,
org.elasticsearch.script.Script.ScriptParseException.class,
org.elasticsearch.ElasticsearchGenerationException.class,
org.elasticsearch.action.TimestampParsingException.class,
org.elasticsearch.action.NoSuchNodeException.class,
org.elasticsearch.transport.BindTransportException.class,
org.elasticsearch.snapshots.SnapshotException.class,
org.elasticsearch.index.mapper.MapperException.class,
org.elasticsearch.transport.TransportException.class,
org.elasticsearch.search.SearchContextException.class,
org.elasticsearch.index.translog.TranslogCorruptedException.class,
org.elasticsearch.transport.TransportSerializationException.class,
org.elasticsearch.cluster.IncompatibleClusterStateVersionException.class,
org.elasticsearch.indices.IndexCreationException.class,
org.elasticsearch.index.mapper.MergeMappingException.class,
org.elasticsearch.transport.NotSerializableTransportException.class,
org.elasticsearch.ElasticsearchTimeoutException.class,
org.elasticsearch.search.SearchContextMissingException.class,
org.elasticsearch.transport.SendRequestTransportException.class,
org.elasticsearch.indices.IndexMissingException.class,
org.elasticsearch.index.IndexShardAlreadyExistsException.class,
org.elasticsearch.indices.IndexAlreadyExistsException.class,
org.elasticsearch.index.engine.DocumentAlreadyExistsException.class,
org.elasticsearch.transport.ConnectTransportException.class,
org.elasticsearch.gateway.GatewayException.class,
org.elasticsearch.script.ScriptException.class,
org.elasticsearch.script.expression.ExpressionScriptCompilationException.class,
org.elasticsearch.index.shard.IndexShardNotStartedException.class,
org.elasticsearch.index.mapper.StrictDynamicMappingException.class,
org.elasticsearch.index.engine.EngineClosedException.class,
org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException.class,
org.elasticsearch.transport.ResponseHandlerFailureTransportException.class,
org.elasticsearch.search.SearchParseException.class,
org.elasticsearch.search.fetch.FetchPhaseExecutionException.class,
org.elasticsearch.transport.NodeDisconnectedException.class,
org.elasticsearch.common.breaker.CircuitBreakingException.class,
org.elasticsearch.search.aggregations.AggregationInitializationException.class,
org.elasticsearch.search.aggregations.InvalidAggregationPathException.class,
org.elasticsearch.cluster.routing.IllegalShardRoutingStateException.class,
org.elasticsearch.index.engine.FlushFailedEngineException.class,
org.elasticsearch.index.AlreadyExpiredException.class,
org.elasticsearch.index.translog.TranslogException.class,
org.elasticsearch.index.engine.FlushNotAllowedEngineException.class,
org.elasticsearch.index.engine.RecoveryEngineException.class,
org.elasticsearch.common.blobstore.BlobStoreException.class,
org.elasticsearch.index.snapshots.IndexShardRestoreException.class,
org.elasticsearch.index.store.StoreException.class,
org.elasticsearch.index.query.QueryParsingException.class,
org.elasticsearch.action.support.replication.TransportReplicationAction.RetryOnPrimaryException.class,
org.elasticsearch.index.engine.DeleteByQueryFailedEngineException.class,
org.elasticsearch.index.engine.ForceMergeFailedEngineException.class,
org.elasticsearch.discovery.MasterNotDiscoveredException.class,
org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException.class,
org.elasticsearch.node.NodeClosedException.class,
org.elasticsearch.search.aggregations.AggregationExecutionException.class,
org.elasticsearch.ElasticsearchParseException.class,
org.elasticsearch.action.PrimaryMissingActionException.class,
org.elasticsearch.index.engine.CreateFailedEngineException.class,
org.elasticsearch.index.shard.IllegalIndexShardStateException.class,
NotSerializableExceptionWrapper.class
};
Map<String, Constructor<? extends ElasticsearchException>> mapping = new HashMap<>(exceptions.length);
for (Class<? extends ElasticsearchException> e : exceptions) {
String name = e.getName();
try {
Constructor<? extends ElasticsearchException> constructor = e.getDeclaredConstructor(StreamInput.class);
if (constructor == null) {
throw new IllegalStateException(name + " has not StreamInput ctor");
}
mapping.put(name, constructor);
} catch (NoSuchMethodException t) {
throw new RuntimeException("failed to register [" + name + "] exception must have a public StreamInput ctor", t);
}
}
MAPPING = Collections.unmodifiableMap(mapping);
}
}

View File

@ -19,6 +19,10 @@
package org.elasticsearch;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
* A generic exception indicating failure to generate.
*
@ -33,4 +37,8 @@ public class ElasticsearchGenerationException extends ElasticsearchException {
public ElasticsearchGenerationException(String msg, Throwable cause) {
super(msg, cause);
}
public ElasticsearchGenerationException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -1,38 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch;
/**
*
*/
public class ElasticsearchNullPointerException extends ElasticsearchException {
public ElasticsearchNullPointerException() {
super(null);
}
public ElasticsearchNullPointerException(String msg) {
super(msg);
}
public ElasticsearchNullPointerException(String msg, Throwable cause) {
super(msg, cause);
}
}

View File

@ -19,8 +19,11 @@
package org.elasticsearch;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*
*/
@ -34,6 +37,9 @@ public class ElasticsearchParseException extends ElasticsearchException {
super(msg, cause);
}
public ElasticsearchParseException(StreamInput in) throws IOException {
super(in);
}
@Override
public RestStatus status() {
return RestStatus.BAD_REQUEST;

View File

@ -19,12 +19,19 @@
package org.elasticsearch;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
* The same as {@link java.util.concurrent.TimeoutException} simply a runtime one.
*
*
*/
public class ElasticsearchTimeoutException extends ElasticsearchException {
public ElasticsearchTimeoutException(StreamInput in) throws IOException {
super(in);
}
public ElasticsearchTimeoutException(String message) {
super(message);

View File

@ -20,6 +20,10 @@
package org.elasticsearch.action;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
/**
*
@ -36,4 +40,15 @@ public class FailedNodeException extends ElasticsearchException {
public String nodeId() {
return this.nodeId;
}
public FailedNodeException(StreamInput in) throws IOException {
super(in);
nodeId = in.readOptionalString();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalString(nodeId);
}
}

View File

@ -19,10 +19,13 @@
package org.elasticsearch.action;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*
*/
@ -44,4 +47,8 @@ public class NoShardAvailableActionException extends IndexShardException {
public RestStatus status() {
return RestStatus.SERVICE_UNAVAILABLE;
}
public NoShardAvailableActionException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -19,6 +19,11 @@
package org.elasticsearch.action;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
*
*/
@ -27,4 +32,8 @@ public class NoSuchNodeException extends FailedNodeException {
public NoSuchNodeException(String nodeId) {
super(nodeId, "No such node [" + nodeId + "]", null);
}
public NoSuchNodeException(StreamInput in) throws IOException {
super(in);
}
}

View File

@ -20,6 +20,9 @@
package org.elasticsearch.action;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
*
@ -29,4 +32,8 @@ public class PrimaryMissingActionException extends ElasticsearchException {
public PrimaryMissingActionException(String message) {
super(message);
}
public PrimaryMissingActionException(StreamInput in) throws IOException {
super(in);
}
}

View File

@ -20,8 +20,13 @@
package org.elasticsearch.action;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
import java.util.Objects;
/**
*
*/
@ -35,6 +40,9 @@ public class RoutingMissingException extends ElasticsearchException {
public RoutingMissingException(String index, String type, String id) {
super("routing is required for [" + index + "]/[" + type + "]/[" + id + "]");
Objects.requireNonNull(index, "index must not be null");
Objects.requireNonNull(type, "type must not be null");
Objects.requireNonNull(id, "id must not be null");
this.index = index;
this.type = type;
this.id = id;
@ -56,4 +64,19 @@ public class RoutingMissingException extends ElasticsearchException {
public RestStatus status() {
return RestStatus.BAD_REQUEST;
}
public RoutingMissingException(StreamInput in) throws IOException{
super(in);
index = in.readString();
type = in.readString();
id = in.readString();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(index);
out.writeString(type);
out.writeString(id);
}
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.action;
import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexException;
import org.elasticsearch.rest.RestStatus;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* An exception indicating that a failure occurred performing an operation on the shard.
*
*
*/
public interface ShardOperationFailedException extends Streamable, Serializable, ToXContent {
public interface ShardOperationFailedException extends Streamable, ToXContent {
/**
* The index the operation failed on. Might return <tt>null</tt> if it can't be derived.

View File

@ -20,6 +20,10 @@
package org.elasticsearch.action;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
/**
*/
@ -40,4 +44,15 @@ public class TimestampParsingException extends ElasticsearchException {
public String timestamp() {
return timestamp;
}
public TimestampParsingException(StreamInput in) throws IOException{
super(in);
this.timestamp = in.readOptionalString();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalString(timestamp);
}
}

View File

@ -21,9 +21,12 @@ package org.elasticsearch.action;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*
*/
@ -40,6 +43,10 @@ public class UnavailableShardsException extends ElasticsearchException {
return "[" + shardId.index().name() + "][" + shardId.id() + "] " + message;
}
public UnavailableShardsException(StreamInput in) throws IOException {
super(in);
}
@Override
public RestStatus status() {
return RestStatus.SERVICE_UNAVAILABLE;

View File

@ -28,9 +28,8 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import java.io.IOException;
import java.io.Serializable;
public class PluginInfo implements Streamable, Serializable, ToXContent {
public class PluginInfo implements Streamable, ToXContent {
public static final String DESCRIPTION_NOT_AVAILABLE = "No description found.";
public static final String VERSION_NOT_AVAILABLE = "NA";

View File

@ -27,11 +27,10 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class PluginsInfo implements Streamable, Serializable, ToXContent {
public class PluginsInfo implements Streamable, ToXContent {
static final class Fields {
static final XContentBuilderString PLUGINS = new XContentBuilderString("plugins");
}

View File

@ -19,6 +19,10 @@
package org.elasticsearch.action.search;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
* A failure during a reduce phase (when receiving results from several shards, and reducing them
* into one or more results and possible actions).
@ -27,11 +31,11 @@ package org.elasticsearch.action.search;
*/
public class ReduceSearchPhaseException extends SearchPhaseExecutionException {
public ReduceSearchPhaseException(String phaseName, String msg, ShardSearchFailure[] shardFailures) {
super(phaseName, "[reduce] " + msg, shardFailures);
}
public ReduceSearchPhaseException(String phaseName, String msg, Throwable cause, ShardSearchFailure[] shardFailures) {
super(phaseName, "[reduce] " + msg, cause, shardFailures);
}
public ReduceSearchPhaseException(StreamInput in) throws IOException {
super(in);
}
}

View File

@ -22,6 +22,8 @@ package org.elasticsearch.action.search;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexException;
@ -35,8 +37,7 @@ import java.util.*;
*/
public class SearchPhaseExecutionException extends ElasticsearchException {
private final String phaseName;
private ShardSearchFailure[] shardFailures;
private final ShardSearchFailure[] shardFailures;
public SearchPhaseExecutionException(String phaseName, String msg, ShardSearchFailure[] shardFailures) {
super(msg);
@ -50,6 +51,28 @@ public class SearchPhaseExecutionException extends ElasticsearchException {
this.shardFailures = shardFailures;
}
public SearchPhaseExecutionException(StreamInput in) throws IOException {
super(in);
phaseName = in.readOptionalString();
int numFailures = in.readVInt();
shardFailures = new ShardSearchFailure[numFailures];
for (int i = 0; i < numFailures; i++) {
shardFailures[i] = ShardSearchFailure.readShardSearchFailure(in);
}
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalString(phaseName);
out.writeVInt(shardFailures == null ? 0 : shardFailures.length);
if (shardFailures != null) {
for (ShardSearchFailure failure : shardFailures) {
failure.writeTo(out);
}
}
}
@Override
public RestStatus status() {
if (shardFailures.length == 0) {
@ -120,4 +143,8 @@ public class SearchPhaseExecutionException extends ElasticsearchException {
public String toString() {
return buildMessage(phaseName, getMessage(), shardFailures);
}
public String getPhaseName() {
return phaseName;
}
}

View File

@ -56,8 +56,8 @@ public abstract class HandledTransportAction<Request extends ActionRequest, Resp
try {
channel.sendResponse(e);
} catch (Exception e1) {
logger.warn("Failed to send error response for action [{}] and request [{}]",
actionName, request, e1);
logger.warn("Failed to send error response for action [{}] and request [{}]", e1,
actionName, request);
}
}
});

View File

@ -20,9 +20,12 @@
package org.elasticsearch.action.support.broadcast;
import org.elasticsearch.ElasticsearchWrapperException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
/**
* An exception indicating that a failure occurred performing an operation on the shard.
*
@ -41,4 +44,8 @@ public class BroadcastShardOperationFailedException extends IndexShardException
public BroadcastShardOperationFailedException(ShardId shardId, String msg, Throwable cause) {
super(shardId, msg, cause);
}
public BroadcastShardOperationFailedException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -1,44 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.support.replication;
import org.elasticsearch.ElasticsearchWrapperException;
import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
/**
* An exception indicating that a failure occurred performing an operation on the shard.
*
*
*/
public class ReplicationShardOperationFailedException extends IndexShardException implements ElasticsearchWrapperException {
public ReplicationShardOperationFailedException(ShardId shardId, String msg) {
super(shardId, msg, null);
}
public ReplicationShardOperationFailedException(ShardId shardId, Throwable cause) {
super(shardId, "", cause);
}
public ReplicationShardOperationFailedException(ShardId shardId, String msg, Throwable cause) {
super(shardId, msg, cause);
}
}

View File

@ -43,6 +43,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.*;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.settings.Settings;
@ -239,14 +240,14 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
}
}
protected static class RetryOnReplicaException extends IndexShardException {
public static class RetryOnReplicaException extends IndexShardException {
public RetryOnReplicaException(ShardId shardId, String msg) {
super(shardId, msg);
}
public RetryOnReplicaException(ShardId shardId, String msg, Throwable cause) {
super(shardId, msg, cause);
public RetryOnReplicaException(StreamInput in) throws IOException{
super(in);
}
}
@ -322,14 +323,13 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
}
}
protected static class RetryOnPrimaryException extends IndexShardException {
public static class RetryOnPrimaryException extends IndexShardException {
public RetryOnPrimaryException(ShardId shardId, String msg) {
super(shardId, msg);
}
public RetryOnPrimaryException(ShardId shardId, String msg, Throwable cause) {
super(shardId, msg, cause);
public RetryOnPrimaryException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -25,6 +25,7 @@ import org.elasticsearch.common.io.PathUtils;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
@ -55,12 +56,12 @@ class JarHell {
final Map<String,URL> clazzes = new HashMap<>(32768);
Set<String> seenJars = new HashSet<>();
for (final URL url : ((URLClassLoader)loader).getURLs()) {
String path = url.getPath();
String path = URLDecoder.decode(url.getPath(), "UTF-8");
if (path.endsWith(".jar")) {
if (!seenJars.add(path)) {
continue; // we can't fail because of sheistiness with joda-time
}
try (JarFile file = new JarFile(url.getPath())) {
try (JarFile file = new JarFile(path)) {
Manifest manifest = file.getManifest();
if (manifest != null) {
// inspect Manifest: give a nice error if jar requires a newer java version

View File

@ -20,8 +20,11 @@
package org.elasticsearch.client.transport;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
* An exception indicating no node is available to perform the operation.
*/
@ -35,6 +38,10 @@ public class NoNodeAvailableException extends ElasticsearchException {
super(message, t);
}
public NoNodeAvailableException(StreamInput in) throws IOException{
super(in);
}
@Override
public RestStatus status() {
return RestStatus.SERVICE_UNAVAILABLE;

View File

@ -20,6 +20,9 @@
package org.elasticsearch.cluster;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
* Thrown by {@link Diffable#readDiffAndApply(org.elasticsearch.common.io.stream.StreamInput)} method
@ -32,4 +35,8 @@ public class IncompatibleClusterStateVersionException extends ElasticsearchExcep
public IncompatibleClusterStateVersionException(long expectedVersion, String expectedUuid, long receivedVersion, String receivedUuid) {
super("Expected diff for version " + expectedVersion + " with uuid " + expectedUuid + " got version " + receivedVersion + " and uuid " + receivedUuid);
}
public IncompatibleClusterStateVersionException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -27,7 +27,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Locale;
@ -35,7 +34,7 @@ import java.util.Locale;
/**
*
*/
public class ClusterBlock implements Serializable, Streamable, ToXContent {
public class ClusterBlock implements Streamable, ToXContent {
private int id;

View File

@ -21,8 +21,13 @@ package org.elasticsearch.cluster.block;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
import java.util.Set;
/**
*
*/
@ -35,6 +40,29 @@ public class ClusterBlockException extends ElasticsearchException {
this.blocks = blocks;
}
public ClusterBlockException(StreamInput in) throws IOException {
super(in);
int num = in.readVInt();
ImmutableSet.Builder<ClusterBlock> builder = ImmutableSet.builder();
for (int i = 0; i < num; i++) {
builder.add(ClusterBlock.readClusterBlock(in));
}
blocks = builder.build();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (blocks != null) {
out.writeVInt(blocks.size());
for (ClusterBlock block : blocks) {
block.writeTo(out);
}
} else {
out.writeVInt(0);
}
}
public boolean retryable() {
for (ClusterBlock block : blocks) {
if (!block.retryable()) {

View File

@ -20,9 +20,12 @@
package org.elasticsearch.cluster.metadata;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*/
public class ProcessClusterEventTimeoutException extends ElasticsearchException {
@ -31,6 +34,10 @@ public class ProcessClusterEventTimeoutException extends ElasticsearchException
super("failed to process cluster event (" + source + ") within " + timeValue);
}
public ProcessClusterEventTimeoutException(StreamInput in) throws IOException {
super(in);
}
@Override
public RestStatus status() {
return RestStatus.SERVICE_UNAVAILABLE;

View File

@ -24,12 +24,11 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import java.io.IOException;
import java.io.Serializable;
/**
* Snapshot ID - repository name + snapshot name
*/
public class SnapshotId implements Serializable, Streamable {
public class SnapshotId implements Streamable {
private String repository;

View File

@ -31,7 +31,6 @@ import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.transport.TransportAddressSerializers;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import static org.elasticsearch.common.transport.TransportAddressSerializers.addressToStream;
@ -39,7 +38,7 @@ import static org.elasticsearch.common.transport.TransportAddressSerializers.add
/**
* A discovery node represents a node that is part of the cluster.
*/
public class DiscoveryNode implements Streamable, Serializable {
public class DiscoveryNode implements Streamable {
/**
* Minimum version of a node to communicate with. This version corresponds to the minimum compatibility version
@ -373,19 +372,4 @@ public class DiscoveryNode implements Streamable, Serializable {
}
return sb.toString();
}
// we need this custom serialization logic because Version is not serializable (because org.apache.lucene.util.Version is not serializable)
private void writeObject(java.io.ObjectOutputStream out)
throws IOException {
StreamOutput streamOutput = new OutputStreamStreamOutput(out);
streamOutput.setVersion(Version.CURRENT.minimumCompatibilityVersion());
this.writeTo(streamOutput);
}
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
StreamInput streamInput = new InputStreamStreamInput(in);
streamInput.setVersion(Version.CURRENT.minimumCompatibilityVersion());
this.readFrom(streamInput);
}
}

View File

@ -19,6 +19,11 @@
package org.elasticsearch.cluster.routing;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
/**
* This exception defines illegal states of shard routing
*/
@ -35,6 +40,17 @@ public class IllegalShardRoutingStateException extends RoutingException {
this.shard = shard;
}
public IllegalShardRoutingStateException(StreamInput in) throws IOException {
super(in);
shard = ShardRouting.readShardRoutingEntry(in);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
shard.writeTo(out);
}
/**
* Returns the shard instance referenced by this exception
* @return shard instance referenced by this exception

View File

@ -20,6 +20,9 @@
package org.elasticsearch.cluster.routing;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
* A base {@link Exception}s for all exceptions thrown by routing related operations.
@ -33,4 +36,8 @@ public class RoutingException extends ElasticsearchException {
public RoutingException(String message, Throwable cause) {
super(message, cause);
}
public RoutingException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -27,7 +27,6 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
@ -39,7 +38,7 @@ import static com.google.common.collect.Maps.newHashMap;
* Encapsulates the result of a routing table validation and provides access to
* validation failures.
*/
public class RoutingTableValidation implements Serializable, Streamable {
public class RoutingTableValidation implements Streamable {
private boolean valid = true;

View File

@ -19,6 +19,11 @@
package org.elasticsearch.cluster.routing;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
/**
* This class defines {@link RoutingException}s related to
* the validation of routing
@ -32,6 +37,17 @@ public class RoutingValidationException extends RoutingException {
this.validation = validation;
}
public RoutingValidationException(StreamInput in) throws IOException {
super(in);
validation = in.readOptionalStreamable(new RoutingTableValidation());
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalStreamable(validation);
}
public RoutingTableValidation validation() {
return this.validation;
}

View File

@ -29,7 +29,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
@ -37,7 +36,7 @@ import java.util.List;
* {@link ShardRouting} immutably encapsulates information about shard
* routings like id, state, version, etc.
*/
public final class ShardRouting implements Streamable, Serializable, ToXContent {
public final class ShardRouting implements Streamable, ToXContent {
protected String index;

View File

@ -632,116 +632,6 @@ public class Base64 {
}
/**
* Serializes an object and returns the Base64-encoded
* version of that serialized object.
* <p/>
* <p>As of v 2.3, if the object
* cannot be serialized or there is another error,
* the method will throw an java.io.IOException. <b>This is new to v2.3!</b>
* In earlier versions, it just returned a null value, but
* in retrospect that's a pretty poor way to handle it.</p>
* <p/>
* The object is not GZip-compressed before being encoded.
*
* @param serializableObject The object to encode
* @return The Base64-encoded object
* @throws java.io.IOException if there is an error
* @throws NullPointerException if serializedObject is null
* @since 1.4
*/
public static String encodeObject(java.io.Serializable serializableObject)
throws java.io.IOException {
return encodeObject(serializableObject, NO_OPTIONS);
} // end encodeObject
/**
* Serializes an object and returns the Base64-encoded
* version of that serialized object.
* <p/>
* <p>As of v 2.3, if the object
* cannot be serialized or there is another error,
* the method will throw an java.io.IOException. <b>This is new to v2.3!</b>
* In earlier versions, it just returned a null value, but
* in retrospect that's a pretty poor way to handle it.</p>
* <p/>
* The object is not GZip-compressed before being encoded.
* <p/>
* Example options:<pre>
* GZIP: gzip-compresses object before encoding it.
* DO_BREAK_LINES: break lines at 76 characters
* </pre>
* <p/>
* Example: <code>encodeObject( myObj, Base64.GZIP )</code> or
* <p/>
* Example: <code>encodeObject( myObj, Base64.GZIP | Base64.DO_BREAK_LINES )</code>
*
* @param serializableObject The object to encode
* @param options Specified options
* @return The Base64-encoded object
* @throws java.io.IOException if there is an error
* @see Base64#GZIP
* @see Base64#DO_BREAK_LINES
* @since 2.0
*/
public static String encodeObject(java.io.Serializable serializableObject, int options)
throws java.io.IOException {
if (serializableObject == null) {
throw new NullPointerException("Cannot serialize a null object.");
} // end if: null
// Streams
java.io.ByteArrayOutputStream baos = null;
java.io.OutputStream b64os = null;
java.util.zip.GZIPOutputStream gzos = null;
java.io.ObjectOutputStream oos = null;
try {
// ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream
baos = new java.io.ByteArrayOutputStream();
b64os = new Base64.OutputStream(baos, ENCODE | options);
if ((options & GZIP) != 0) {
// Gzip
gzos = new java.util.zip.GZIPOutputStream(b64os);
oos = new java.io.ObjectOutputStream(gzos);
} else {
// Not gzipped
oos = new java.io.ObjectOutputStream(b64os);
}
oos.writeObject(serializableObject);
} // end try
catch (java.io.IOException e) {
// Catch it and then throw it immediately so that
// the finally{} block is called for cleanup.
throw e;
} // end catch
finally {
try {
oos.close();
} catch (Exception e) {
}
try {
gzos.close();
} catch (Exception e) {
}
try {
b64os.close();
} catch (Exception e) {
}
try {
baos.close();
} catch (Exception e) {
}
} // end finally
// Return value according to relevant encoding.
return new String(baos.toByteArray(), PREFERRED_ENCODING);
} // end encode
/**
* Encodes a byte array into Base64 notation.
@ -799,7 +689,6 @@ public class Base64 {
return encodeBytes(source, 0, source.length, options);
} // end encodeBytes
/**
* Encodes a byte array into Base64 notation.
* Does not GZip-compress data.
@ -1335,97 +1224,6 @@ public class Base64 {
} // end decode
/**
* Attempts to decode Base64 data and deserialize a Java
* Object within. Returns <tt>null</tt> if there was an error.
*
* @param encodedObject The Base64 data to decode
* @return The decoded and deserialized object
* @throws NullPointerException if encodedObject is null
* @throws java.io.IOException if there is a general error
* @throws ClassNotFoundException if the decoded object is of a
* class that cannot be found by the JVM
* @since 1.5
*/
public static Object decodeToObject(String encodedObject)
throws java.io.IOException, java.lang.ClassNotFoundException {
return decodeToObject(encodedObject, NO_OPTIONS, null);
}
/**
* Attempts to decode Base64 data and deserialize a Java
* Object within. Returns <tt>null</tt> if there was an error.
* If <tt>loader</tt> is not null, it will be the class loader
* used when deserializing.
*
* @param encodedObject The Base64 data to decode
* @param options Various parameters related to decoding
* @param loader Optional class loader to use in deserializing classes.
* @return The decoded and deserialized object
* @throws NullPointerException if encodedObject is null
* @throws java.io.IOException if there is a general error
* @throws ClassNotFoundException if the decoded object is of a
* class that cannot be found by the JVM
* @since 2.3.4
*/
public static Object decodeToObject(
String encodedObject, int options, final ClassLoader loader)
throws java.io.IOException, java.lang.ClassNotFoundException {
// Decode and gunzip if necessary
byte[] objBytes = decode(encodedObject, options);
java.io.ByteArrayInputStream bais = null;
java.io.ObjectInputStream ois = null;
Object obj = null;
try {
bais = new java.io.ByteArrayInputStream(objBytes);
// If no custom class loader is provided, use Java's builtin OIS.
if (loader == null) {
ois = new java.io.ObjectInputStream(bais);
} // end if: no loader provided
// Else make a customized object input stream that uses
// the provided class loader.
else {
ois = new java.io.ObjectInputStream(bais) {
@Override
public Class<?> resolveClass(java.io.ObjectStreamClass streamClass)
throws java.io.IOException, ClassNotFoundException {
Class<?> c = Class.forName(streamClass.getName(), false, loader);
if (c == null) {
return super.resolveClass(streamClass);
} else {
return c; // Class loader knows of this class.
} // end else: not null
} // end resolveClass
}; // end ois
} // end else: no custom class loader
obj = ois.readObject();
} // end try
catch (java.io.IOException e) {
throw e; // Catch and throw in order to execute finally{}
} // end catch
catch (java.lang.ClassNotFoundException e) {
throw e; // Catch and throw in order to execute finally{}
} // end catch
finally {
try {
bais.close();
} catch (Exception e) {
}
try {
ois.close();
} catch (Exception e) {
}
} // end finally
return obj;
} // end decodeObject
/* ******** I N N E R C L A S S I N P U T S T R E A M ******** */

View File

@ -20,6 +20,9 @@
package org.elasticsearch.common.blobstore;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
*
@ -33,4 +36,8 @@ public class BlobStoreException extends ElasticsearchException {
public BlobStoreException(String msg, Throwable cause) {
super(msg, cause);
}
public BlobStoreException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -19,6 +19,11 @@
package org.elasticsearch.common.breaker;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
/**
* Exception thrown when the circuit breaker trips
@ -34,12 +39,25 @@ public class CircuitBreakingException extends ElasticsearchException {
this.byteLimit = 0;
}
public CircuitBreakingException(StreamInput in) throws IOException {
super(in);
byteLimit = in.readLong();
bytesWanted = in.readLong();
}
public CircuitBreakingException(String message, long bytesWanted, long byteLimit) {
super(message);
this.bytesWanted = bytesWanted;
this.byteLimit = byteLimit;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeLong(byteLimit);
out.writeLong(bytesWanted);
}
public long getBytesWanted() {
return this.bytesWanted;
}
@ -47,4 +65,11 @@ public class CircuitBreakingException extends ElasticsearchException {
public long getByteLimit() {
return this.byteLimit;
}
@Override
protected void innerToXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("bytes_wanted", bytesWanted);
builder.field("bytes_limit", byteLimit);
super.innerToXContent(builder, params);
}
}

View File

@ -1,99 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.common.io;
import org.elasticsearch.common.Classes;
import java.io.*;
/**
*
*/
public class ThrowableObjectInputStream extends ObjectInputStream {
private final ClassLoader classLoader;
public ThrowableObjectInputStream(InputStream in) throws IOException {
this(in, null);
}
public ThrowableObjectInputStream(InputStream in, ClassLoader classLoader) throws IOException {
super(in);
this.classLoader = classLoader;
}
@Override
protected void readStreamHeader() throws IOException, StreamCorruptedException {
int version = readByte() & 0xFF;
if (version != STREAM_VERSION) {
throw new StreamCorruptedException(
"Unsupported version: " + version);
}
}
@Override
protected ObjectStreamClass readClassDescriptor()
throws IOException, ClassNotFoundException {
int type = read();
if (type < 0) {
throw new EOFException();
}
switch (type) {
case ThrowableObjectOutputStream.TYPE_EXCEPTION:
return ObjectStreamClass.lookup(Exception.class);
case ThrowableObjectOutputStream.TYPE_STACKTRACEELEMENT:
return ObjectStreamClass.lookup(StackTraceElement.class);
case ThrowableObjectOutputStream.TYPE_FAT_DESCRIPTOR:
return super.readClassDescriptor();
case ThrowableObjectOutputStream.TYPE_THIN_DESCRIPTOR:
String className = readUTF();
Class<?> clazz = loadClass(className);
return ObjectStreamClass.lookup(clazz);
default:
throw new StreamCorruptedException(
"Unexpected class descriptor type: " + type);
}
}
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
String className = desc.getName();
try {
return loadClass(className);
} catch (ClassNotFoundException ex) {
return super.resolveClass(desc);
}
}
protected Class<?> loadClass(String className) throws ClassNotFoundException {
Class<?> clazz;
ClassLoader classLoader = this.classLoader;
if (classLoader == null) {
classLoader = Classes.getDefaultClassLoader();
}
if (classLoader != null) {
clazz = classLoader.loadClass(className);
} else {
clazz = Class.forName(className);
}
return clazz;
}
}

View File

@ -1,68 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.common.io;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.io.OutputStream;
/**
*
*/
public class ThrowableObjectOutputStream extends ObjectOutputStream {
static final int TYPE_FAT_DESCRIPTOR = 0;
static final int TYPE_THIN_DESCRIPTOR = 1;
private static final String EXCEPTION_CLASSNAME = Exception.class.getName();
static final int TYPE_EXCEPTION = 2;
private static final String STACKTRACEELEMENT_CLASSNAME = StackTraceElement.class.getName();
static final int TYPE_STACKTRACEELEMENT = 3;
public ThrowableObjectOutputStream(OutputStream out) throws IOException {
super(out);
}
@Override
protected void writeStreamHeader() throws IOException {
writeByte(STREAM_VERSION);
}
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
if (desc.getName().equals(EXCEPTION_CLASSNAME)) {
write(TYPE_EXCEPTION);
} else if (desc.getName().equals(STACKTRACEELEMENT_CLASSNAME)) {
write(TYPE_STACKTRACEELEMENT);
} else {
Class<?> clazz = desc.forClass();
if (clazz.isPrimitive() || clazz.isArray()) {
write(TYPE_FAT_DESCRIPTOR);
super.writeClassDescriptor(desc);
} else {
write(TYPE_THIN_DESCRIPTOR);
writeUTF(desc.getName());
}
}
}
}

View File

@ -0,0 +1,61 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.common.io.stream;
import org.elasticsearch.ElasticsearchException;
import java.io.IOException;
/**
* This exception can be used to wrap a given, not serializable exception
* to serialize via {@link StreamOutput#writeThrowable(Throwable)}.
* This class will perserve the stacktrace as well as the suppressed exceptions of
* the throwable it was created with instead of it's own. The stacktrace has no indication
* of where this exception was created.
*/
public final class NotSerializableExceptionWrapper extends ElasticsearchException {
private final String name;
public NotSerializableExceptionWrapper(Throwable other) {
super(other.getMessage(), other.getCause());
this.name = ElasticsearchException.getExceptionName(other);
setStackTrace(other.getStackTrace());
for (Throwable otherSuppressed : other.getSuppressed()) {
addSuppressed(otherSuppressed);
}
}
public NotSerializableExceptionWrapper(StreamInput in) throws IOException {
super(in);
name = in.readString();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(name);
}
@Override
protected String getExceptionName() {
return name;
}
}

View File

@ -19,8 +19,16 @@
package org.elasticsearch.common.io.stream;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonParseException;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexFormatTooNewException;
import org.apache.lucene.index.IndexFormatTooOldException;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRefBuilder;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
@ -31,11 +39,13 @@ import org.elasticsearch.common.text.Text;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.*;
import java.nio.file.NoSuchFileException;
import java.util.*;
import java.util.regex.Pattern;
import static org.elasticsearch.ElasticsearchException.readException;
import static org.elasticsearch.ElasticsearchException.readStackTrace;
/**
*
@ -491,14 +501,60 @@ public abstract class StreamInput extends InputStream {
}
public <T extends Throwable> T readThrowable() throws IOException {
try {
ObjectInputStream oin = new ObjectInputStream(this);
@SuppressWarnings("unchecked")
T object = (T) oin.readObject();
return object;
} catch (ClassNotFoundException e) {
throw new IOException("failed to deserialize exception", e);
if (readBoolean()) {
int key = readVInt();
switch (key) {
case 0:
final String name = readString();
return (T) readException(this, name);
case 1:
// this sucks it would be nice to have a better way to construct those?
String msg = readOptionalString();
final int idx = msg.indexOf(" (resource=");
final String resource = msg.substring(idx + " (resource=".length(), msg.length()-1);
msg = msg.substring(0, idx);
return (T) readStackTrace(new CorruptIndexException(msg, resource, readThrowable()), this); // Lucene 5.3 will have getters for all these
case 2:
return (T) readStackTrace(new IndexFormatTooNewException(readOptionalString(), -1, -1, -1), this); // Lucene 5.3 will have getters for all these
case 3:
return (T) readStackTrace(new IndexFormatTooOldException(readOptionalString(), -1, -1, -1), this); // Lucene 5.3 will have getters for all these
case 4:
return (T) readStackTrace(new NullPointerException(readOptionalString()), this);
case 5:
return (T) readStackTrace(new NumberFormatException(readOptionalString()), this);
case 6:
return (T) readStackTrace(new IllegalArgumentException(readOptionalString(), readThrowable()), this);
case 7:
return (T) readStackTrace(new IllegalStateException(readOptionalString(), readThrowable()), this);
case 8:
return (T) readStackTrace(new EOFException(readOptionalString()), this);
case 9:
return (T) readStackTrace(new SecurityException(readOptionalString(), readThrowable()), this);
case 10:
return (T) readStackTrace(new StringIndexOutOfBoundsException(readOptionalString()), this);
case 11:
return (T) readStackTrace(new ArrayIndexOutOfBoundsException(readOptionalString()), this);
case 12:
return (T) readStackTrace(new AssertionError(readOptionalString(), readThrowable()), this);
case 13:
return (T) readStackTrace(new FileNotFoundException(readOptionalString()), this);
case 14:
final String file = readOptionalString();
final String other = readOptionalString();
final String reason = readOptionalString();
readOptionalString(); // skip the msg - it's composed from file, other and reason
return (T) readStackTrace(new NoSuchFileException(file, other, reason), this);
case 15:
return (T) readStackTrace(new OutOfMemoryError(readOptionalString()), this);
case 16:
return (T) readStackTrace(new AlreadyClosedException(readOptionalString(), readThrowable()), this);
case 17:
return (T) readStackTrace(new LockObtainFailedException(readOptionalString(), readThrowable()), this);
default:
assert false : "no such exception for id: " + key;
}
}
return null;
}
/**
@ -539,4 +595,5 @@ public abstract class StreamInput extends InputStream {
public static StreamInput wrap(byte[] bytes, int offset, int length) {
return new InputStreamStreamInput(new ByteArrayInputStream(bytes, offset, length));
}
}

View File

@ -19,17 +19,26 @@
package org.elasticsearch.common.io.stream;
import com.vividsolutions.jts.util.Assert;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexFormatTooNewException;
import org.apache.lucene.index.IndexFormatTooOldException;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.text.Text;
import org.joda.time.ReadableInstant;
import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.nio.file.NoSuchFileException;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
@ -446,9 +455,78 @@ public abstract class StreamOutput extends OutputStream {
}
public void writeThrowable(Throwable throwable) throws IOException {
ObjectOutputStream out = new ObjectOutputStream(this);
out.writeObject(throwable);
out.flush();
if (throwable == null) {
writeBoolean(false);
} else {
writeBoolean(true);
boolean writeCause = true;
if (throwable instanceof CorruptIndexException) {
writeVInt(1);
} else if (throwable instanceof IndexFormatTooNewException) {
writeVInt(2);
writeCause = false;
} else if (throwable instanceof IndexFormatTooOldException) {
writeVInt(3);
writeCause = false;
} else if (throwable instanceof NullPointerException) {
writeVInt(4);
writeCause = false;
} else if (throwable instanceof NumberFormatException) {
writeVInt(5);
writeCause = false;
} else if (throwable instanceof IllegalArgumentException) {
writeVInt(6);
} else if (throwable instanceof IllegalStateException) {
writeVInt(7);
} else if (throwable instanceof EOFException) {
writeVInt(8);
writeCause = false;
} else if (throwable instanceof SecurityException) {
writeVInt(9);
} else if (throwable instanceof StringIndexOutOfBoundsException) {
writeVInt(10);
writeCause = false;
} else if (throwable instanceof ArrayIndexOutOfBoundsException) {
writeVInt(11);
writeCause = false;
} else if (throwable instanceof AssertionError) {
writeVInt(12);
} else if (throwable instanceof FileNotFoundException) {
writeVInt(13);
writeCause = false;
} else if (throwable instanceof NoSuchFileException) {
writeVInt(14);
writeOptionalString(((NoSuchFileException) throwable).getFile());
writeOptionalString(((NoSuchFileException) throwable).getOtherFile());
writeOptionalString(((NoSuchFileException) throwable).getReason());
writeCause = false;
} else if (throwable instanceof OutOfMemoryError) {
writeVInt(15);
writeCause = false;
} else if (throwable instanceof AlreadyClosedException) {
writeVInt(16);
} else if (throwable instanceof LockObtainFailedException) {
writeVInt(17);
} else {
ElasticsearchException ex;
final String name = throwable.getClass().getName();
if (throwable instanceof ElasticsearchException && ElasticsearchException.isRegistered(name)) {
ex = (ElasticsearchException) throwable;
} else {
ex = new NotSerializableExceptionWrapper(throwable);
}
writeVInt(0);
writeString(ex.getClass().getName());
ex.writeTo(this);
return;
}
writeOptionalString(throwable.getMessage());
if (writeCause) {
writeThrowable(throwable.getCause());
}
ElasticsearchException.writeStackTraces(throwable, this);
}
}
/**

View File

@ -604,6 +604,10 @@ public class Lucene {
public EarlyTerminationException(String msg) {
super(msg);
}
public EarlyTerminationException(StreamInput in) throws IOException{
super(in);
}
}
/**

View File

@ -19,6 +19,10 @@
package org.elasticsearch.common.settings;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
* A specific type of {@link SettingsException} indicating failure to load a class
* based on a settings value.
@ -27,11 +31,11 @@ package org.elasticsearch.common.settings;
*/
public class NoClassSettingsException extends SettingsException {
public NoClassSettingsException(String message) {
super(message);
}
public NoClassSettingsException(String message, Throwable cause) {
super(message, cause);
}
public NoClassSettingsException(StreamInput in) throws IOException {
super(in);
}
}

View File

@ -20,6 +20,9 @@
package org.elasticsearch.common.settings;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
* A generic failure to handle settings.
@ -35,4 +38,8 @@ public class SettingsException extends ElasticsearchException {
public SettingsException(String message, Throwable cause) {
super(message, cause);
}
public SettingsException(StreamInput in) throws IOException {
super(in);
}
}

View File

@ -20,14 +20,13 @@ package org.elasticsearch.common.text;
import org.elasticsearch.common.bytes.BytesReference;
import java.io.Serializable;
/**
* Text represents a (usually) long text data. We use this abstraction instead of {@link String}
* so we can represent it in a more optimized manner in memory as well as serializing it over the
* network as well as converting it to json format.
*/
public interface Text extends Comparable<Text>, Serializable {
public interface Text extends Comparable<Text> {
/**
* Are bytes available without the need to be converted into bytes when calling {@link #bytes()}.

View File

@ -60,12 +60,6 @@ public class InetSocketTransportAddress implements TransportAddress {
this.address = address;
}
public static InetSocketTransportAddress readInetSocketTransportAddress(StreamInput in) throws IOException {
InetSocketTransportAddress address = new InetSocketTransportAddress();
address.readFrom(in);
return address;
}
@Override
public short uniqueAddressTypeId() {
return 1;

View File

@ -21,12 +21,11 @@ package org.elasticsearch.common.transport;
import org.elasticsearch.common.io.stream.Streamable;
import java.io.Serializable;
/**
*
*/
public interface TransportAddress extends Streamable, Serializable {
public interface TransportAddress extends Streamable {
short uniqueAddressTypeId();

View File

@ -28,11 +28,10 @@ import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.settings.Settings;
import java.io.IOException;
import java.io.Serializable;
import java.util.Locale;
import java.util.Objects;
public class ByteSizeValue implements Serializable, Streamable {
public class ByteSizeValue implements Streamable {
private long size;

View File

@ -27,12 +27,11 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import java.io.IOException;
import java.io.Serializable;
/**
*
*/
public class SizeValue implements Serializable, Streamable {
public class SizeValue implements Streamable {
private long size;

View File

@ -37,7 +37,7 @@ import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
public class TimeValue implements Serializable, Streamable {
public class TimeValue implements Streamable {
/** How many nano-seconds in one milli-second */
public static final long NSEC_PER_MSEC = 1000000;

View File

@ -20,7 +20,9 @@ package org.elasticsearch.common.util;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
@ -132,14 +134,14 @@ public class CancellableThreads {
public void run() throws InterruptedException;
}
public class ExecutionCancelledException extends ElasticsearchException {
public static class ExecutionCancelledException extends ElasticsearchException {
public ExecutionCancelledException(String msg) {
super(msg);
}
public ExecutionCancelledException(String msg, Throwable cause) {
super(msg, cause);
public ExecutionCancelledException(StreamInput in) throws IOException {
super(in);
}
}
}

View File

@ -20,8 +20,11 @@
package org.elasticsearch.common.util.concurrent;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*/
public class EsRejectedExecutionException extends ElasticsearchException {
@ -31,7 +34,7 @@ public class EsRejectedExecutionException extends ElasticsearchException {
}
public EsRejectedExecutionException() {
super(null);
super((String)null);
}
public EsRejectedExecutionException(Throwable e) {
@ -42,4 +45,8 @@ public class EsRejectedExecutionException extends ElasticsearchException {
public RestStatus status() {
return RestStatus.TOO_MANY_REQUESTS;
}
public EsRejectedExecutionException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -20,6 +20,9 @@
package org.elasticsearch.common.util.concurrent;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
*
@ -29,4 +32,8 @@ public class UncategorizedExecutionException extends ElasticsearchException {
public UncategorizedExecutionException(String msg, Throwable cause) {
super(msg, cause);
}
public UncategorizedExecutionException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -20,8 +20,11 @@
package org.elasticsearch.discovery;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*
*/
@ -39,4 +42,8 @@ public class MasterNotDiscoveredException extends ElasticsearchException {
public RestStatus status() {
return RestStatus.SERVICE_UNAVAILABLE;
}
public MasterNotDiscoveredException(StreamInput in) throws IOException {
super(in);
}
}

View File

@ -20,6 +20,9 @@
package org.elasticsearch.env;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
*
@ -33,4 +36,8 @@ public class FailedToResolveConfigException extends ElasticsearchException {
public FailedToResolveConfigException(String msg, Throwable cause) {
super(msg, cause);
}
public FailedToResolveConfigException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -20,6 +20,9 @@
package org.elasticsearch.gateway;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
*
@ -33,4 +36,8 @@ public class GatewayException extends ElasticsearchException {
public GatewayException(String msg, Throwable cause) {
super(msg, cause);
}
public GatewayException(StreamInput in) throws IOException {
super(in);
}
}

View File

@ -19,16 +19,20 @@
package org.elasticsearch.http;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
*
*/
public class BindHttpException extends HttpException {
public BindHttpException(String message) {
super(message);
}
public BindHttpException(String message, Throwable cause) {
super(message, cause);
}
public BindHttpException(StreamInput in) throws IOException {
super(in);
}
}

View File

@ -20,6 +20,9 @@
package org.elasticsearch.http;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
*
@ -33,4 +36,8 @@ public class HttpException extends ElasticsearchException {
public HttpException(String message, Throwable cause) {
super(message, cause);
}
public HttpException(StreamInput in) throws IOException {
super(in);
}
}

View File

@ -29,12 +29,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import java.io.IOException;
import java.io.Serializable;
/**
*
*/
public class HttpInfo implements Streamable, Serializable, ToXContent {
public class HttpInfo implements Streamable, ToXContent {
private BoundTransportAddress address;
private long maxContentLength;

View File

@ -20,8 +20,12 @@
package org.elasticsearch.index;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.index.engine.IgnoreOnRecoveryEngineException;
import java.io.IOException;
public class AlreadyExpiredException extends ElasticsearchException implements IgnoreOnRecoveryEngineException {
private String index;
private String type;
@ -63,4 +67,25 @@ public class AlreadyExpiredException extends ElasticsearchException implements I
public long now() {
return now;
}
public AlreadyExpiredException(StreamInput in) throws IOException{
super(in);
index = in.readOptionalString();
type = in.readOptionalString();
id = in.readOptionalString();
timestamp = in.readLong();
ttl = in.readLong();
now = in.readLong();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalString(index);
out.writeOptionalString(type);
out.writeOptionalString(id);
out.writeLong(timestamp);
out.writeLong(ttl);
out.writeLong(now);
}
}

View File

@ -24,12 +24,11 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import java.io.IOException;
import java.io.Serializable;
/**
*
*/
public class Index implements Serializable, Streamable {
public class Index implements Streamable {
private String name;

View File

@ -20,6 +20,8 @@
package org.elasticsearch.index;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
@ -56,4 +58,16 @@ public class IndexException extends ElasticsearchException {
public String toString() {
return "[" + (index == null ? "_na" : index.name()) + "] " + getMessage();
}
public IndexException(StreamInput in) throws IOException{
super(in);
index = in.readBoolean() ? Index.readIndexName(in) : null;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalStreamable(index);
}
}

View File

@ -20,6 +20,9 @@
package org.elasticsearch.index;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
*
@ -29,4 +32,8 @@ public class IndexShardAlreadyExistsException extends ElasticsearchException {
public IndexShardAlreadyExistsException(String message) {
super(message);
}
public IndexShardAlreadyExistsException(StreamInput in) throws IOException {
super(in);
}
}

View File

@ -19,10 +19,13 @@
package org.elasticsearch.index;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*
*/
@ -32,6 +35,10 @@ public class IndexShardMissingException extends IndexShardException {
super(shardId, "missing");
}
public IndexShardMissingException(StreamInput in) throws IOException{
super(in);
}
@Override
public RestStatus status() {
return RestStatus.NOT_FOUND;

View File

@ -1,38 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.engine;
import org.elasticsearch.index.shard.ShardId;
/**
* An exception indicating that an {@link org.elasticsearch.index.engine.Engine} close failed.
*
*
*/
public class CloseEngineException extends EngineException {
public CloseEngineException(ShardId shardId, String msg) {
super(shardId, msg);
}
public CloseEngineException(ShardId shardId, String msg, Throwable cause) {
super(shardId, msg, cause);
}
}

View File

@ -19,8 +19,13 @@
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
import java.util.Objects;
/**
*
*/
@ -30,10 +35,18 @@ public class CreateFailedEngineException extends EngineException {
private final String id;
public CreateFailedEngineException(ShardId shardId, Engine.Create create, Throwable cause) {
super(shardId, "Create failed for [" + create.type() + "#" + create.id() + "]", cause);
this.type = create.type();
this.id = create.id();
public CreateFailedEngineException(ShardId shardId, String type, String id, Throwable cause) {
super(shardId, "Create failed for [" + type + "#" + id + "]", cause);
Objects.requireNonNull(type, "type must not be null");
Objects.requireNonNull(id, "id must not be null");
this.type = type;
this.id = id;
}
public CreateFailedEngineException(StreamInput in) throws IOException{
super(in);
type = in.readString();
id = in.readString();
}
public String type() {
@ -43,4 +56,11 @@ public class CreateFailedEngineException extends EngineException {
public String id() {
return this.id;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(type);
out.writeString(id);
}
}

View File

@ -19,8 +19,11 @@
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
/** @deprecated Delete-by-query is removed in 2.0, but we keep this so translog can replay on upgrade. */
@Deprecated
public class DeleteByQueryFailedEngineException extends EngineException {
@ -28,4 +31,8 @@ public class DeleteByQueryFailedEngineException extends EngineException {
public DeleteByQueryFailedEngineException(ShardId shardId, Engine.DeleteByQuery deleteByQuery, Throwable cause) {
super(shardId, "Delete by query failed for [" + deleteByQuery.query() + "]", cause);
}
public DeleteByQueryFailedEngineException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -19,8 +19,11 @@
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
/**
*
*/
@ -29,4 +32,8 @@ public class DeleteFailedEngineException extends EngineException {
public DeleteFailedEngineException(ShardId shardId, Engine.Delete delete, Throwable cause) {
super(shardId, "Delete failed for [" + delete.uid().text() + "]", cause);
}
public DeleteFailedEngineException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -18,9 +18,12 @@
*/
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*
*/
@ -30,6 +33,10 @@ public class DocumentAlreadyExistsException extends EngineException {
super(shardId, "[" + type + "][" + id + "]: document already exists");
}
public DocumentAlreadyExistsException(StreamInput in) throws IOException{
super(in);
}
@Override
public RestStatus status() {
return RestStatus.CONFLICT;

View File

@ -18,9 +18,12 @@
*/
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*
*/
@ -30,6 +33,10 @@ public class DocumentMissingException extends EngineException {
super(shardId, "[" + type + "][" + id + "]: document missing");
}
public DocumentMissingException(StreamInput in) throws IOException{
super(in);
}
@Override
public RestStatus status() {
return RestStatus.NOT_FOUND;

View File

@ -18,9 +18,12 @@
*/
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*
*/
@ -30,6 +33,10 @@ public class DocumentSourceMissingException extends EngineException {
super(shardId, "[" + type + "][" + id + "]: document source missing");
}
public DocumentSourceMissingException(StreamInput in) throws IOException{
super(in);
}
@Override
public RestStatus status() {
return RestStatus.BAD_REQUEST;

View File

@ -1,32 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.engine;
import org.elasticsearch.index.shard.ShardId;
/**
*
*/
public class EngineAlreadyStartedException extends EngineException {
public EngineAlreadyStartedException(ShardId shardId) {
super(shardId, "Already started");
}
}

View File

@ -19,9 +19,12 @@
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.IndexShardClosedException;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
/**
* An engine is already closed.
* <p/>
@ -39,4 +42,8 @@ public class EngineClosedException extends IndexShardClosedException {
public EngineClosedException(ShardId shardId, Throwable t) {
super(shardId, t);
}
public EngineClosedException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -19,8 +19,11 @@
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
/**
* An exception indicating that an {@link Engine} creation failed.
*
@ -32,4 +35,8 @@ public class EngineCreationFailureException extends EngineException {
super(shardId, msg, cause);
}
public EngineCreationFailureException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -19,9 +19,12 @@
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.IndexShardException;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
/**
*
*/
@ -34,4 +37,8 @@ public class EngineException extends IndexShardException {
public EngineException(ShardId shardId, String msg, Throwable cause) {
super(shardId, msg, cause);
}
public EngineException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -19,8 +19,11 @@
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
/**
*
*/
@ -30,7 +33,7 @@ public class FlushFailedEngineException extends EngineException {
super(shardId, "Flush failed", t);
}
public FlushFailedEngineException(ShardId shardId, String message, Throwable t) {
super(shardId, "Flush failed [" + message + "]", t);
public FlushFailedEngineException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -19,9 +19,12 @@
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*
*/
@ -31,6 +34,10 @@ public class FlushNotAllowedEngineException extends EngineException {
super(shardId, msg);
}
public FlushNotAllowedEngineException(StreamInput in) throws IOException{
super(in);
}
@Override
public RestStatus status() {
return RestStatus.SERVICE_UNAVAILABLE;

View File

@ -19,8 +19,11 @@
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
/**
*
*/
@ -29,4 +32,8 @@ public class ForceMergeFailedEngineException extends EngineException {
public ForceMergeFailedEngineException(ShardId shardId, Throwable t) {
super(shardId, "force merge failed", t);
}
public ForceMergeFailedEngineException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -19,8 +19,13 @@
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
import java.util.Objects;
/**
*
*/
@ -30,10 +35,25 @@ public class IndexFailedEngineException extends EngineException {
private final String id;
public IndexFailedEngineException(ShardId shardId, Engine.Index index, Throwable cause) {
super(shardId, "Index failed for [" + index.type() + "#" + index.id() + "]", cause);
this.type = index.type();
this.id = index.id();
public IndexFailedEngineException(ShardId shardId, String type, String id, Throwable cause) {
super(shardId, "Index failed for [" + type + "#" + id + "]", cause);
Objects.requireNonNull(type, "type must not be null");
Objects.requireNonNull(id, "id must not be null");
this.type = type;
this.id = id;
}
public IndexFailedEngineException(StreamInput in) throws IOException{
super(in);
type = in.readString();
id = in.readString();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(type);
out.writeString(id);
}
public String type() {

View File

@ -335,7 +335,7 @@ public class InternalEngine extends Engine {
}
} catch (OutOfMemoryError | IllegalStateException | IOException t) {
maybeFailEngine("create", t);
throw new CreateFailedEngineException(shardId, create, t);
throw new CreateFailedEngineException(shardId, create.type(), create.id(), t);
}
checkVersionMapRefresh();
}
@ -441,7 +441,7 @@ public class InternalEngine extends Engine {
}
} catch (OutOfMemoryError | IllegalStateException | IOException t) {
maybeFailEngine("index", t);
throw new IndexFailedEngineException(shardId, index, t);
throw new IndexFailedEngineException(shardId, index.type(), index.id(), t);
}
checkVersionMapRefresh();
return created;

View File

@ -19,8 +19,12 @@
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
/**
*
*/
@ -33,6 +37,17 @@ public class RecoveryEngineException extends EngineException {
this.phase = phase;
}
public RecoveryEngineException(StreamInput in) throws IOException{
super(in);
phase = in.readInt();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeInt(phase);
}
public int phase() {
return phase;
}

View File

@ -19,8 +19,11 @@
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
/**
*
*/
@ -29,4 +32,8 @@ public class RefreshFailedEngineException extends EngineException {
public RefreshFailedEngineException(ShardId shardId, Throwable t) {
super(shardId, "Refresh failed", t);
}
public RefreshFailedEngineException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -1,32 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.engine;
import org.elasticsearch.index.shard.ShardId;
/**
*
*/
public class RollbackFailedEngineException extends EngineException {
public RollbackFailedEngineException(ShardId shardId, Throwable t) {
super(shardId, "Rollback failed", t);
}
}

View File

@ -1,32 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.engine;
import org.elasticsearch.index.shard.ShardId;
/**
*
*/
public class RollbackNotAllowedEngineException extends EngineException {
public RollbackNotAllowedEngineException(ShardId shardId, String msg) {
super(shardId, msg);
}
}

View File

@ -19,8 +19,11 @@
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.ShardId;
import java.io.IOException;
/**
*
*/
@ -30,4 +33,7 @@ public class SnapshotFailedEngineException extends EngineException {
super(shardId, "Snapshot failed", cause);
}
public SnapshotFailedEngineException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -18,22 +18,19 @@
*/
package org.elasticsearch.index.engine;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*
*/
public class VersionConflictEngineException extends EngineException {
private final long current;
private final long provided;
public VersionConflictEngineException(ShardId shardId, String type, String id, long current, long provided) {
super(shardId, "[" + type + "][" + id + "]: version conflict, current [" + current + "], provided [" + provided + "]");
this.current = current;
this.provided = provided;
}
@Override
@ -41,11 +38,7 @@ public class VersionConflictEngineException extends EngineException {
return RestStatus.CONFLICT;
}
public long getCurrentVersion() {
return this.current;
}
public long getProvidedVersion() {
return this.provided;
public VersionConflictEngineException(StreamInput in) throws IOException {
super(in);
}
}

View File

@ -1,34 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.mapper;
/**
*
*/
public class MapperCompressionException extends MapperException {
public MapperCompressionException(String message) {
super(message);
}
public MapperCompressionException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -20,11 +20,17 @@
package org.elasticsearch.index.mapper;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
*
*/
public class MapperException extends ElasticsearchException {
public MapperException(StreamInput in) throws IOException {
super(in);
}
public MapperException(String message) {
super(message);

View File

@ -19,13 +19,20 @@
package org.elasticsearch.index.mapper;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*
*/
public class MapperParsingException extends MapperException {
public MapperParsingException(StreamInput in) throws IOException {
super(in);
}
public MapperParsingException(String message) {
super(message);
}

View File

@ -19,22 +19,38 @@
package org.elasticsearch.index.mapper;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
/**
*
*/
public class MergeMappingException extends MapperException {
public final class MergeMappingException extends MapperException {
private final String[] failures;
public MergeMappingException(String[] failures) {
super("Merge failed with failures {" + Arrays.toString(failures) + "}");
Objects.requireNonNull(failures, "failures must be non-null");
this.failures = failures;
}
public MergeMappingException(StreamInput in) throws IOException {
super(in);
failures = in.readStringArray();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArray(failures);
}
public String[] failures() {
return failures;
}

View File

@ -18,8 +18,11 @@
*/
package org.elasticsearch.index.mapper;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*/
public class StrictDynamicMappingException extends MapperParsingException {
@ -28,6 +31,10 @@ public class StrictDynamicMappingException extends MapperParsingException {
super("mapping set to strict, dynamic introduction of [" + fieldName + "] within [" + path + "] is not allowed");
}
public StrictDynamicMappingException(StreamInput in) throws IOException {
super(in);
}
@Override
public RestStatus status() {
return RestStatus.BAD_REQUEST;

View File

@ -18,9 +18,12 @@
*/
package org.elasticsearch.index.percolator;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexException;
import java.io.IOException;
/**
* Exception during indexing a percolator query.
*/
@ -29,4 +32,8 @@ public class PercolatorException extends IndexException {
public PercolatorException(Index index, String msg, Throwable cause) {
super(index, msg, cause);
}
public PercolatorException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -23,7 +23,6 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CloseableThreadLocal;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
@ -85,13 +84,6 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent imple
private boolean mapUnmappedFieldsAsString;
private CloseableThreadLocal<QueryParseContext> cache = new CloseableThreadLocal<QueryParseContext>() {
@Override
protected QueryParseContext initialValue() {
return new QueryParseContext(shardId.index(), queryParserService);
}
};
public PercolatorQueriesRegistry(ShardId shardId, @IndexSettings Settings indexSettings, IndexQueryParserService queryParserService,
ShardIndexingService indexingService, IndicesLifecycle indicesLifecycle, MapperService mapperService,
IndexFieldDataService indexFieldDataService, ShardPercolateService shardPercolateService) {
@ -197,7 +189,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent imple
if (type != null) {
QueryParseContext.setTypesWithPrevious(new String[]{type});
}
QueryParseContext context = cache.get();
QueryParseContext context = queryParserService.getParseContext();
try {
context.reset(parser);
// This means that fields in the query need to exist in the mapping prior to registering this query

View File

@ -19,6 +19,8 @@
package org.elasticsearch.index.query;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.common.xcontent.XContentParser;
@ -34,8 +36,8 @@ import java.io.IOException;
public class QueryParsingException extends IndexException {
static final int UNKNOWN_POSITION = -1;
private int lineNumber = UNKNOWN_POSITION;
private int columnNumber = UNKNOWN_POSITION;
private final int lineNumber;
private final int columnNumber;
public QueryParsingException(QueryParseContext parseContext, String msg) {
this(parseContext, msg, null);
@ -43,7 +45,8 @@ public class QueryParsingException extends IndexException {
public QueryParsingException(QueryParseContext parseContext, String msg, Throwable cause) {
super(parseContext.index(), msg, cause);
int lineNumber = UNKNOWN_POSITION;
int columnNumber = UNKNOWN_POSITION;
XContentParser parser = parseContext.parser();
if (parser != null) {
XContentLocation location = parser.getTokenLocation();
@ -52,13 +55,15 @@ public class QueryParsingException extends IndexException {
columnNumber = location.columnNumber;
}
}
this.columnNumber = columnNumber;
this.lineNumber = lineNumber;
}
/**
* This constructor is provided for use in unit tests where a
* {@link QueryParseContext} may not be available
*/
QueryParsingException(Index index, int line, int col, String msg, Throwable cause) {
public QueryParsingException(Index index, int line, int col, String msg, Throwable cause) {
super(index, msg, cause);
this.lineNumber = line;
this.columnNumber = col;
@ -96,4 +101,17 @@ public class QueryParsingException extends IndexException {
super.innerToXContent(builder, params);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeInt(lineNumber);
out.writeInt(columnNumber);
}
public QueryParsingException(StreamInput in) throws IOException{
super(in);
lineNumber = in.readInt();
columnNumber = in.readInt();
}
}

View File

@ -19,8 +19,12 @@
package org.elasticsearch.index.shard;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/**
*
*/
@ -46,4 +50,15 @@ public class IllegalIndexShardStateException extends IndexShardException {
public RestStatus status() {
return RestStatus.NOT_FOUND;
}
public IllegalIndexShardStateException(StreamInput in) throws IOException{
super(in);
currentState = IndexShardState.fromId(in.readByte());
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeByte(currentState.id());
}
}

View File

@ -19,6 +19,10 @@
package org.elasticsearch.index.shard;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
*
*/
@ -34,4 +38,8 @@ public class IndexShardClosedException extends IllegalIndexShardStateException {
public IndexShardClosedException(ShardId shardId, String message) {
super(shardId, IndexShardState.CLOSED, message);
}
public IndexShardClosedException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -19,6 +19,10 @@
package org.elasticsearch.index.shard;
import org.elasticsearch.common.io.stream.StreamInput;
import java.io.IOException;
/**
*/
public class IndexShardCreationException extends IndexShardException {
@ -26,4 +30,8 @@ public class IndexShardCreationException extends IndexShardException {
public IndexShardCreationException(ShardId shardId, Throwable cause) {
super(shardId, "failed to create shard", cause);
}
public IndexShardCreationException(StreamInput in) throws IOException{
super(in);
}
}

View File

@ -19,6 +19,8 @@
package org.elasticsearch.index.shard;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.IndexException;
@ -56,4 +58,19 @@ public class IndexShardException extends IndexException {
}
super.innerToXContent(builder, params);
}
public IndexShardException(StreamInput in) throws IOException{
super(in);
if (in.readBoolean()) {
shardId = ShardId.readShardId(in);
} else {
shardId = null;
}
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalStreamable(shardId);
}
}

Some files were not shown because too many files have changed in this diff Show More