mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 02:14:54 +00:00
Rename writeThrowable to writeException
This commit renames writeThrowable to writeException. The situation here stems from the fact that the StreamOutput method for serializing Exceptions needs to accept Throwables too as Throwables can be the cause of serialized Exceptions. Yet, we do not serialize Throwables in the Error sub-hierarchy in a way that they can be deserialized into their initial type. This leads to an asymmetry in the StreamOutput method for serializing Exceptions and the StreamInput method for writing Excpetions. Namely, the former will accept Throwables but the latter will only return Exceptions. A goal with the stream methods has always been symmetry in the method names so that serialization/deserialization routines appear symmetrical in code. It is this asymmetry on the input/output types for Exceptions on StreamOutput/StreamInput that clashes with the desired symmetry of naming. Despite this, we should favor symmetry in the naming of the methods. This commit renames StreamOutput#writeThrowable to StreamOutput#writeException which leaves us with Exception StreamInput#readException and void StreamOutput#writeException(Throwable).
This commit is contained in:
parent
ebe616988a
commit
96f283c195
@ -204,7 +204,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeOptionalString(this.getMessage());
|
||||
out.writeThrowable(this.getCause());
|
||||
out.writeException(this.getCause());
|
||||
writeStackTraces(this, out);
|
||||
out.writeVInt(headers.size());
|
||||
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
@ -435,7 +435,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
||||
Throwable[] suppressed = throwable.getSuppressed();
|
||||
out.writeVInt(suppressed.length);
|
||||
for (Throwable t : suppressed) {
|
||||
out.writeThrowable(t);
|
||||
out.writeException(t);
|
||||
}
|
||||
return throwable;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public final class TaskOperationFailure implements Writeable, ToXContent {
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(nodeId);
|
||||
out.writeLong(taskId);
|
||||
out.writeThrowable(reason);
|
||||
out.writeException(reason);
|
||||
RestStatus.writeTo(out, status);
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ public class IndicesShardStoresResponse extends ActionResponse implements ToXCon
|
||||
allocationStatus.writeTo(out);
|
||||
if (storeException != null) {
|
||||
out.writeBoolean(true);
|
||||
out.writeThrowable(storeException);
|
||||
out.writeException(storeException);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ public class BulkItemResponse implements Streamable, StatusToXContent {
|
||||
out.writeString(getIndex());
|
||||
out.writeString(getType());
|
||||
out.writeOptionalString(getId());
|
||||
out.writeThrowable(getCause());
|
||||
out.writeException(getCause());
|
||||
}
|
||||
|
||||
|
||||
|
@ -100,7 +100,7 @@ public class MultiGetResponse extends ActionResponse implements Iterable<MultiGe
|
||||
out.writeString(index);
|
||||
out.writeOptionalString(type);
|
||||
out.writeString(id);
|
||||
out.writeThrowable(exception);
|
||||
out.writeException(exception);
|
||||
}
|
||||
|
||||
public Exception getFailure() {
|
||||
|
@ -63,7 +63,7 @@ public final class SimulateDocumentBaseResult implements SimulateDocumentResult
|
||||
ingestDocument.writeTo(out);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
out.writeThrowable(failure);
|
||||
out.writeException(failure);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class SimulateProcessorResult implements Writeable, ToXContent {
|
||||
ingestDocument.writeTo(out);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
out.writeThrowable(failure);
|
||||
out.writeException(failure);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ public class MultiSearchResponse extends ActionResponse implements Iterable<Mult
|
||||
response.writeTo(out);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
out.writeThrowable(exception);
|
||||
out.writeException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ public class ShardSearchFailure implements ShardOperationFailedException {
|
||||
}
|
||||
out.writeString(reason);
|
||||
RestStatus.writeTo(out, status);
|
||||
out.writeThrowable(cause);
|
||||
out.writeException(cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,7 +111,7 @@ public class DefaultShardOperationFailedException implements ShardOperationFaile
|
||||
out.writeString(index);
|
||||
}
|
||||
out.writeVInt(shardId);
|
||||
out.writeThrowable(reason);
|
||||
out.writeException(reason);
|
||||
RestStatus.writeTo(out, status);
|
||||
}
|
||||
|
||||
|
@ -260,7 +260,7 @@ public class ReplicationResponse extends ActionResponse {
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
shardId.writeTo(out);
|
||||
out.writeOptionalString(nodeId);
|
||||
out.writeThrowable(cause);
|
||||
out.writeException(cause);
|
||||
RestStatus.writeTo(out, status);
|
||||
out.writeBoolean(primary);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ public class MultiTermVectorsResponse extends ActionResponse implements Iterable
|
||||
out.writeString(index);
|
||||
out.writeOptionalString(type);
|
||||
out.writeString(id);
|
||||
out.writeThrowable(cause);
|
||||
out.writeException(cause);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -437,7 +437,7 @@ public class ShardStateAction extends AbstractComponent {
|
||||
shardRouting.writeTo(out);
|
||||
sourceShardRouting.writeTo(out);
|
||||
out.writeString(message);
|
||||
out.writeThrowable(failure);
|
||||
out.writeException(failure);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -167,7 +167,7 @@ public final class UnassignedInfo implements ToXContent, Writeable {
|
||||
// Do not serialize unassignedTimeNanos as System.nanoTime() cannot be compared across different JVMs
|
||||
out.writeBoolean(delayed);
|
||||
out.writeOptionalString(message);
|
||||
out.writeThrowable(failure);
|
||||
out.writeException(failure);
|
||||
out.writeVInt(failedAllocations);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This exception can be used to wrap a given, not serializable exception
|
||||
* to serialize via {@link StreamOutput#writeThrowable(Throwable)}.
|
||||
* to serialize via {@link StreamOutput#writeException(Throwable)}.
|
||||
* This class will preserve 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.
|
||||
|
@ -631,7 +631,7 @@ public abstract class StreamOutput extends OutputStream {
|
||||
}
|
||||
}
|
||||
|
||||
public void writeThrowable(Throwable throwable) throws IOException {
|
||||
public void writeException(Throwable throwable) throws IOException {
|
||||
if (throwable == null) {
|
||||
writeBoolean(false);
|
||||
} else {
|
||||
@ -739,7 +739,7 @@ public abstract class StreamOutput extends OutputStream {
|
||||
writeOptionalString(throwable.getMessage());
|
||||
}
|
||||
if (writeCause) {
|
||||
writeThrowable(throwable.getCause());
|
||||
writeException(throwable.getCause());
|
||||
}
|
||||
ElasticsearchException.writeStackTraces(throwable, this);
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ public class TransportNodesListGatewayStartedShards extends
|
||||
out.writeBoolean(primary);
|
||||
if (storeException != null) {
|
||||
out.writeBoolean(true);
|
||||
out.writeThrowable(storeException);
|
||||
out.writeException(storeException);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
}
|
||||
|
@ -1337,7 +1337,7 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
|
||||
try (IndexOutput output = this.directory().createOutput(uuid, IOContext.DEFAULT)) {
|
||||
CodecUtil.writeHeader(output, CODEC, VERSION);
|
||||
BytesStreamOutput out = new BytesStreamOutput();
|
||||
out.writeThrowable(exception);
|
||||
out.writeException(exception);
|
||||
BytesReference bytes = out.bytes();
|
||||
output.writeVInt(bytes.length());
|
||||
BytesRef ref = bytes.toBytesRef();
|
||||
|
@ -59,7 +59,7 @@ public class VerificationFailure implements Streamable {
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeOptionalString(nodeId);
|
||||
out.writeThrowable(cause);
|
||||
out.writeException(cause);
|
||||
}
|
||||
|
||||
public static VerificationFailure readNode(StreamInput in) throws IOException {
|
||||
|
@ -940,7 +940,7 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
|
||||
stream.setVersion(nodeVersion);
|
||||
RemoteTransportException tx = new RemoteTransportException(
|
||||
nodeName(), new InetSocketTransportAddress(getLocalAddress(channel)), action, error);
|
||||
stream.writeThrowable(tx);
|
||||
stream.writeException(tx);
|
||||
byte status = 0;
|
||||
status = TransportStatus.setResponse(status);
|
||||
status = TransportStatus.setError(status);
|
||||
|
@ -96,7 +96,7 @@ public class LocalTransportChannel implements TransportChannel {
|
||||
writeResponseExceptionHeader(stream);
|
||||
RemoteTransportException tx = new RemoteTransportException(targetTransport.nodeName(),
|
||||
targetTransport.boundAddress().boundAddresses()[0], action, exception);
|
||||
stream.writeThrowable(tx);
|
||||
stream.writeException(tx);
|
||||
sendResponseData(BytesReference.toBytes(stream.bytes()));
|
||||
sourceTransportServiceAdapter.onResponseSent(requestId, action, exception);
|
||||
}
|
||||
|
@ -301,7 +301,7 @@ public class ESExceptionTests extends ESTestCase {
|
||||
public void testSerializeElasticsearchException() throws IOException {
|
||||
BytesStreamOutput out = new BytesStreamOutput();
|
||||
ParsingException ex = new ParsingException(1, 2, "foobar", null);
|
||||
out.writeThrowable(ex);
|
||||
out.writeException(ex);
|
||||
|
||||
StreamInput in = out.bytes().streamInput();
|
||||
ParsingException e = in.readException();
|
||||
@ -315,7 +315,7 @@ public class ESExceptionTests extends ESTestCase {
|
||||
BytesStreamOutput out = new BytesStreamOutput();
|
||||
ParsingException parsingException = new ParsingException(1, 2, "foobar", null);
|
||||
final Exception ex = new UnknownException("eggplant", parsingException);
|
||||
out.writeThrowable(ex);
|
||||
out.writeException(ex);
|
||||
|
||||
StreamInput in = out.bytes().streamInput();
|
||||
Throwable throwable = in.readException();
|
||||
@ -354,7 +354,7 @@ public class ESExceptionTests extends ESTestCase {
|
||||
for (final Exception cause : causes) {
|
||||
BytesStreamOutput out = new BytesStreamOutput();
|
||||
ElasticsearchException ex = new ElasticsearchException("topLevel", cause);
|
||||
out.writeThrowable(ex);
|
||||
out.writeException(ex);
|
||||
StreamInput in = out.bytes().streamInput();
|
||||
ElasticsearchException e = in.readException();
|
||||
assertEquals(e.getMessage(), ex.getMessage());
|
||||
|
@ -222,7 +222,7 @@ public class ExceptionSerializationTests extends ESTestCase {
|
||||
private <T extends Exception> T serialize(T exception) throws IOException {
|
||||
ElasticsearchAssertions.assertVersionSerializable(VersionUtils.randomVersion(random()), exception);
|
||||
BytesStreamOutput out = new BytesStreamOutput();
|
||||
out.writeThrowable(exception);
|
||||
out.writeException(exception);
|
||||
StreamInput in = out.bytes().streamInput();
|
||||
return in.readException();
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public class MultiSearchTemplateResponse extends ActionResponse implements Itera
|
||||
response.writeTo(out);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
out.writeThrowable(exception);
|
||||
out.writeException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ public class MultiPercolateResponse extends ActionResponse implements Iterable<M
|
||||
response.writeTo(out);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
out.writeThrowable(exception);
|
||||
out.writeException(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -682,7 +682,7 @@ public class ElasticsearchAssertions {
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeThrowable(exception);
|
||||
out.writeException(exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user