|
@@ -207,6 +207,7 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
|
|
private final MeanMetric transmittedBytesMetric = new MeanMetric();
|
|
private final MeanMetric transmittedBytesMetric = new MeanMetric();
|
|
private volatile Map<String, RequestHandlerRegistry> requestHandlers = Collections.emptyMap();
|
|
private volatile Map<String, RequestHandlerRegistry> requestHandlers = Collections.emptyMap();
|
|
private final ResponseHandlers responseHandlers = new ResponseHandlers();
|
|
private final ResponseHandlers responseHandlers = new ResponseHandlers();
|
|
|
|
+ private final TransportLogger transportLogger;
|
|
private final BytesReference pingMessage;
|
|
private final BytesReference pingMessage;
|
|
|
|
|
|
public TcpTransport(String transportName, Settings settings, ThreadPool threadPool, BigArrays bigArrays,
|
|
public TcpTransport(String transportName, Settings settings, ThreadPool threadPool, BigArrays bigArrays,
|
|
@@ -221,6 +222,8 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
|
|
this.compress = Transport.TRANSPORT_TCP_COMPRESS.get(settings);
|
|
this.compress = Transport.TRANSPORT_TCP_COMPRESS.get(settings);
|
|
this.networkService = networkService;
|
|
this.networkService = networkService;
|
|
this.transportName = transportName;
|
|
this.transportName = transportName;
|
|
|
|
+ this.transportLogger = new TransportLogger(settings);
|
|
|
|
+
|
|
final Settings defaultFeatures = DEFAULT_FEATURES_SETTING.get(settings);
|
|
final Settings defaultFeatures = DEFAULT_FEATURES_SETTING.get(settings);
|
|
if (defaultFeatures == null) {
|
|
if (defaultFeatures == null) {
|
|
this.features = new String[0];
|
|
this.features = new String[0];
|
|
@@ -788,7 +791,7 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
|
|
// in case we are able to return data, serialize the exception content and sent it back to the client
|
|
// in case we are able to return data, serialize the exception content and sent it back to the client
|
|
if (channel.isOpen()) {
|
|
if (channel.isOpen()) {
|
|
BytesArray message = new BytesArray(e.getMessage().getBytes(StandardCharsets.UTF_8));
|
|
BytesArray message = new BytesArray(e.getMessage().getBytes(StandardCharsets.UTF_8));
|
|
- final SendMetricListener closeChannel = new SendMetricListener(message.length()) {
|
|
|
|
|
|
+ final SendMetricListener listener = new SendMetricListener(message.length()) {
|
|
@Override
|
|
@Override
|
|
protected void innerInnerOnResponse(Void v) {
|
|
protected void innerInnerOnResponse(Void v) {
|
|
CloseableChannel.closeChannel(channel);
|
|
CloseableChannel.closeChannel(channel);
|
|
@@ -800,7 +803,14 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
|
|
CloseableChannel.closeChannel(channel);
|
|
CloseableChannel.closeChannel(channel);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- internalSendMessage(channel, message, closeChannel);
|
|
|
|
|
|
+ // We do not call internalSendMessage because we are not sending a message that is an
|
|
|
|
+ // elasticsearch binary message. We are just serializing an exception here. Not formatting it
|
|
|
|
+ // as an elasticsearch transport message.
|
|
|
|
+ try {
|
|
|
|
+ channel.sendMessage(message, listener);
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ listener.onFailure(ex);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
logger.warn(() -> new ParameterizedMessage("exception caught on transport layer [{}], closing connection", channel), e);
|
|
logger.warn(() -> new ParameterizedMessage("exception caught on transport layer [{}], closing connection", channel), e);
|
|
@@ -906,6 +916,7 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
|
|
* sends a message to the given channel, using the given callbacks.
|
|
* sends a message to the given channel, using the given callbacks.
|
|
*/
|
|
*/
|
|
private void internalSendMessage(TcpChannel channel, BytesReference message, SendMetricListener listener) {
|
|
private void internalSendMessage(TcpChannel channel, BytesReference message, SendMetricListener listener) {
|
|
|
|
+ transportLogger.logOutboundMessage(channel, message);
|
|
try {
|
|
try {
|
|
channel.sendMessage(message, listener);
|
|
channel.sendMessage(message, listener);
|
|
} catch (Exception ex) {
|
|
} catch (Exception ex) {
|
|
@@ -1050,6 +1061,24 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
|
|
return new CompositeBytesReference(header, messageBody, zeroCopyBuffer);
|
|
return new CompositeBytesReference(header, messageBody, zeroCopyBuffer);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Handles inbound message that has been decoded.
|
|
|
|
+ *
|
|
|
|
+ * @param channel the channel the message if fomr
|
|
|
|
+ * @param message the message
|
|
|
|
+ */
|
|
|
|
+ public void inboundMessage(TcpChannel channel, BytesReference message) {
|
|
|
|
+ try {
|
|
|
|
+ transportLogger.logInboundMessage(channel, message);
|
|
|
|
+ // Message length of 0 is a ping
|
|
|
|
+ if (message.length() != 0) {
|
|
|
|
+ messageReceived(message, channel);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ onException(channel, e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Consumes bytes that are available from network reads. This method returns the number of bytes consumed
|
|
* Consumes bytes that are available from network reads. This method returns the number of bytes consumed
|
|
* in this call.
|
|
* in this call.
|
|
@@ -1067,15 +1096,8 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
|
|
|
|
|
|
if (message == null) {
|
|
if (message == null) {
|
|
return 0;
|
|
return 0;
|
|
- } else if (message.length() == 0) {
|
|
|
|
- // This is a ping and should not be handled.
|
|
|
|
- return BYTES_NEEDED_FOR_MESSAGE_SIZE;
|
|
|
|
} else {
|
|
} else {
|
|
- try {
|
|
|
|
- messageReceived(message, channel);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- onException(channel, e);
|
|
|
|
- }
|
|
|
|
|
|
+ inboundMessage(channel, message);
|
|
return message.length() + BYTES_NEEDED_FOR_MESSAGE_SIZE;
|
|
return message.length() + BYTES_NEEDED_FOR_MESSAGE_SIZE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1091,7 +1113,7 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
|
|
* @throws IllegalArgumentException if the message length is greater that the maximum allowed frame size.
|
|
* @throws IllegalArgumentException if the message length is greater that the maximum allowed frame size.
|
|
* This is dependent on the available memory.
|
|
* This is dependent on the available memory.
|
|
*/
|
|
*/
|
|
- public static BytesReference decodeFrame(BytesReference networkBytes) throws IOException {
|
|
|
|
|
|
+ static BytesReference decodeFrame(BytesReference networkBytes) throws IOException {
|
|
int messageLength = readMessageLength(networkBytes);
|
|
int messageLength = readMessageLength(networkBytes);
|
|
if (messageLength == -1) {
|
|
if (messageLength == -1) {
|
|
return null;
|
|
return null;
|