[refactor][proxy] Refactor Proxy code and fix connection stalling by switching to auto read mode - #14713
Conversation
eolivelli
left a comment
There was a problem hiding this comment.
nice and useful work !
|
@lhotari please resolve the conflicts |
3c3c40e to
4a24061
Compare
|
I ended up increasing the scope of this PR and added the fix to a connection stalling issue. Please review again @eolivelli @codelipenghui @michaeljmarshall @nicoloboschi @merlimat |
|
I asked for feedback in the community meeting from @merlimat . Based on the discussion there was the conclusion that backpressure is needed to prevent a situation where the proxy buffers grow in the case where either the broker connection is slow or the client connection is slow. |
…ity changes - change auto read of the proxy-broker connection based on the writability of the client-proxy connection - change auto read of the client-proxy connection based on the writability of the proxy-broker connection
|
The channel writability change feature in Netty can be configured with |
- delegate exception handling to exceptionCaught method
…switching to auto read mode (apache#14713) Refactor Proxy code to make it easier to understand and maintain. In addition, switch to use auto read mode since the proxies connections seem to stall in some cases since the proxied connection doesn't use Netty's auto read mode and the read handling doesn't seem complete. Currently, the proxy calls `.read()` when a message is written to the connection. There might be more messages flowing in the other direction and it could result in a blocked connection with the current solution that doesn't use Netty's auto read mode. Currently auto read is disabled in DirectProxyHandler for the connection between the proxy and the broker: https://github.com/apache/pulsar/blob/a26905371749798ec5288fb07a69978a36aacfaa/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java#L112 - replace broker host parsing with a simple solution - pass remote host name to ProxyBackendHandler in the constructor - rename "targetBrokerUrl" to "brokerHostAndPort" since the "targetBrokerUrl" is really "hostname:port" string - move HA proxy message handling to ProxyBackendHandle and extract the logic to a method - remove the static "inboundOutboundChannelMap" which was used for log level 2 - make it obsolete by passing the peer channel id to ParserProxyHandler - Enable auto read in proxy and remove `ctx.read()` / `channel.read()` calls - prepare for IPv6 support (reported as apache#14732) by improving the `host:port` parsing (pick last `:` since IPv6 address might contains multiple `:` characters) - Handle backpressure properly by switching auto read off when channel writability changes - change auto read of the proxy-broker connection based on the writability of the client-proxy connection - change auto read of the client-proxy connection based on the writability of the proxy-broker connection - Consistently handle write errors by delegating exception handling to exceptionCaught method by using `.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)` (cherry picked from commit a1037c7)
…switching to auto read mode (apache#14713) Refactor Proxy code to make it easier to understand and maintain. In addition, switch to use auto read mode since the proxies connections seem to stall in some cases since the proxied connection doesn't use Netty's auto read mode and the read handling doesn't seem complete. Currently, the proxy calls `.read()` when a message is written to the connection. There might be more messages flowing in the other direction and it could result in a blocked connection with the current solution that doesn't use Netty's auto read mode. Currently auto read is disabled in DirectProxyHandler for the connection between the proxy and the broker: https://github.com/apache/pulsar/blob/a26905371749798ec5288fb07a69978a36aacfaa/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java#L112 - replace broker host parsing with a simple solution - pass remote host name to ProxyBackendHandler in the constructor - rename "targetBrokerUrl" to "brokerHostAndPort" since the "targetBrokerUrl" is really "hostname:port" string - move HA proxy message handling to ProxyBackendHandle and extract the logic to a method - remove the static "inboundOutboundChannelMap" which was used for log level 2 - make it obsolete by passing the peer channel id to ParserProxyHandler - Enable auto read in proxy and remove `ctx.read()` / `channel.read()` calls - prepare for IPv6 support (reported as apache#14732) by improving the `host:port` parsing (pick last `:` since IPv6 address might contains multiple `:` characters) - Handle backpressure properly by switching auto read off when channel writability changes - change auto read of the proxy-broker connection based on the writability of the client-proxy connection - change auto read of the client-proxy connection based on the writability of the proxy-broker connection - Consistently handle write errors by delegating exception handling to exceptionCaught method by using `.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)` (cherry picked from commit a1037c7)
…switching to auto read mode (apache#14713) ### Motivation Refactor Proxy code to make it easier to understand and maintain. In addition, switch to use auto read mode since the proxies connections seem to stall in some cases since the proxied connection doesn't use Netty's auto read mode and the read handling doesn't seem complete. Currently, the proxy calls `.read()` when a message is written to the connection. There might be more messages flowing in the other direction and it could result in a blocked connection with the current solution that doesn't use Netty's auto read mode. Currently auto read is disabled in DirectProxyHandler for the connection between the proxy and the broker: https://github.com/apache/pulsar/blob/a26905371749798ec5288fb07a69978a36aacfaa/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java#L112 ### Modifications - replace broker host parsing with a simple solution - pass remote host name to ProxyBackendHandler in the constructor - rename "targetBrokerUrl" to "brokerHostAndPort" since the "targetBrokerUrl" is really "hostname:port" string - move HA proxy message handling to ProxyBackendHandle and extract the logic to a method - remove the static "inboundOutboundChannelMap" which was used for log level 2 - make it obsolete by passing the peer channel id to ParserProxyHandler - Enable auto read in proxy and remove `ctx.read()` / `channel.read()` calls - prepare for IPv6 support (reported as apache#14732) by improving the `host:port` parsing (pick last `:` since IPv6 address might contains multiple `:` characters) - Handle backpressure properly by switching auto read off when channel writability changes - change auto read of the proxy-broker connection based on the writability of the client-proxy connection - change auto read of the client-proxy connection based on the writability of the proxy-broker connection - Consistently handle write errors by delegating exception handling to exceptionCaught method by using `.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)` (cherry picked from commit a1037c7) # Conflicts: # pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java # pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ParserProxyHandler.java # pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java
…switching to auto read mode (#14713) ### Motivation Refactor Proxy code to make it easier to understand and maintain. In addition, switch to use auto read mode since the proxies connections seem to stall in some cases since the proxied connection doesn't use Netty's auto read mode and the read handling doesn't seem complete. Currently, the proxy calls `.read()` when a message is written to the connection. There might be more messages flowing in the other direction and it could result in a blocked connection with the current solution that doesn't use Netty's auto read mode. Currently auto read is disabled in DirectProxyHandler for the connection between the proxy and the broker: https://github.com/apache/pulsar/blob/a26905371749798ec5288fb07a69978a36aacfaa/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java#L112 ### Modifications - replace broker host parsing with a simple solution - pass remote host name to ProxyBackendHandler in the constructor - rename "targetBrokerUrl" to "brokerHostAndPort" since the "targetBrokerUrl" is really "hostname:port" string - move HA proxy message handling to ProxyBackendHandle and extract the logic to a method - remove the static "inboundOutboundChannelMap" which was used for log level 2 - make it obsolete by passing the peer channel id to ParserProxyHandler - Enable auto read in proxy and remove `ctx.read()` / `channel.read()` calls - prepare for IPv6 support (reported as #14732) by improving the `host:port` parsing (pick last `:` since IPv6 address might contains multiple `:` characters) - Handle backpressure properly by switching auto read off when channel writability changes - change auto read of the proxy-broker connection based on the writability of the client-proxy connection - change auto read of the client-proxy connection based on the writability of the proxy-broker connection - Consistently handle write errors by delegating exception handling to exceptionCaught method by using `.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)` (cherry picked from commit a1037c7)
…switching to auto read mode (#14713) Refactor Proxy code to make it easier to understand and maintain. In addition, switch to use auto read mode since the proxies connections seem to stall in some cases since the proxied connection doesn't use Netty's auto read mode and the read handling doesn't seem complete. Currently, the proxy calls `.read()` when a message is written to the connection. There might be more messages flowing in the other direction and it could result in a blocked connection with the current solution that doesn't use Netty's auto read mode. Currently auto read is disabled in DirectProxyHandler for the connection between the proxy and the broker: https://github.com/apache/pulsar/blob/a26905371749798ec5288fb07a69978a36aacfaa/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java#L112 - replace broker host parsing with a simple solution - pass remote host name to ProxyBackendHandler in the constructor - rename "targetBrokerUrl" to "brokerHostAndPort" since the "targetBrokerUrl" is really "hostname:port" string - move HA proxy message handling to ProxyBackendHandle and extract the logic to a method - remove the static "inboundOutboundChannelMap" which was used for log level 2 - make it obsolete by passing the peer channel id to ParserProxyHandler - Enable auto read in proxy and remove `ctx.read()` / `channel.read()` calls - prepare for IPv6 support (reported as #14732) by improving the `host:port` parsing (pick last `:` since IPv6 address might contains multiple `:` characters) - Handle backpressure properly by switching auto read off when channel writability changes - change auto read of the proxy-broker connection based on the writability of the client-proxy connection - change auto read of the client-proxy connection based on the writability of the proxy-broker connection - Consistently handle write errors by delegating exception handling to exceptionCaught method by using `.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)` (cherry picked from commit a1037c7)
…switching to auto read mode (#14713) Refactor Proxy code to make it easier to understand and maintain. In addition, switch to use auto read mode since the proxies connections seem to stall in some cases since the proxied connection doesn't use Netty's auto read mode and the read handling doesn't seem complete. Currently, the proxy calls `.read()` when a message is written to the connection. There might be more messages flowing in the other direction and it could result in a blocked connection with the current solution that doesn't use Netty's auto read mode. Currently auto read is disabled in DirectProxyHandler for the connection between the proxy and the broker: https://github.com/apache/pulsar/blob/a26905371749798ec5288fb07a69978a36aacfaa/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java#L112 - replace broker host parsing with a simple solution - pass remote host name to ProxyBackendHandler in the constructor - rename "targetBrokerUrl" to "brokerHostAndPort" since the "targetBrokerUrl" is really "hostname:port" string - move HA proxy message handling to ProxyBackendHandle and extract the logic to a method - remove the static "inboundOutboundChannelMap" which was used for log level 2 - make it obsolete by passing the peer channel id to ParserProxyHandler - Enable auto read in proxy and remove `ctx.read()` / `channel.read()` calls - prepare for IPv6 support (reported as #14732) by improving the `host:port` parsing (pick last `:` since IPv6 address might contains multiple `:` characters) - Handle backpressure properly by switching auto read off when channel writability changes - change auto read of the proxy-broker connection based on the writability of the client-proxy connection - change auto read of the client-proxy connection based on the writability of the proxy-broker connection - Consistently handle write errors by delegating exception handling to exceptionCaught method by using `.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)` (cherry picked from commit a1037c7)
…switching to auto read mode (apache#14713) ### Motivation Refactor Proxy code to make it easier to understand and maintain. In addition, switch to use auto read mode since the proxies connections seem to stall in some cases since the proxied connection doesn't use Netty's auto read mode and the read handling doesn't seem complete. Currently, the proxy calls `.read()` when a message is written to the connection. There might be more messages flowing in the other direction and it could result in a blocked connection with the current solution that doesn't use Netty's auto read mode. Currently auto read is disabled in DirectProxyHandler for the connection between the proxy and the broker: https://github.com/apache/pulsar/blob/a26905371749798ec5288fb07a69978a36aacfaa/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java#L112 ### Modifications - replace broker host parsing with a simple solution - pass remote host name to ProxyBackendHandler in the constructor - rename "targetBrokerUrl" to "brokerHostAndPort" since the "targetBrokerUrl" is really "hostname:port" string - move HA proxy message handling to ProxyBackendHandle and extract the logic to a method - remove the static "inboundOutboundChannelMap" which was used for log level 2 - make it obsolete by passing the peer channel id to ParserProxyHandler - Enable auto read in proxy and remove `ctx.read()` / `channel.read()` calls - prepare for IPv6 support (reported as apache#14732) by improving the `host:port` parsing (pick last `:` since IPv6 address might contains multiple `:` characters) - Handle backpressure properly by switching auto read off when channel writability changes - change auto read of the proxy-broker connection based on the writability of the client-proxy connection - change auto read of the client-proxy connection based on the writability of the proxy-broker connection - Consistently handle write errors by delegating exception handling to exceptionCaught method by using `.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)`
…switching to auto read mode (apache#14713) Refactor Proxy code to make it easier to understand and maintain. In addition, switch to use auto read mode since the proxies connections seem to stall in some cases since the proxied connection doesn't use Netty's auto read mode and the read handling doesn't seem complete. Currently, the proxy calls `.read()` when a message is written to the connection. There might be more messages flowing in the other direction and it could result in a blocked connection with the current solution that doesn't use Netty's auto read mode. Currently auto read is disabled in DirectProxyHandler for the connection between the proxy and the broker: https://github.com/apache/pulsar/blob/a26905371749798ec5288fb07a69978a36aacfaa/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java#L112 - replace broker host parsing with a simple solution - pass remote host name to ProxyBackendHandler in the constructor - rename "targetBrokerUrl" to "brokerHostAndPort" since the "targetBrokerUrl" is really "hostname:port" string - move HA proxy message handling to ProxyBackendHandle and extract the logic to a method - remove the static "inboundOutboundChannelMap" which was used for log level 2 - make it obsolete by passing the peer channel id to ParserProxyHandler - Enable auto read in proxy and remove `ctx.read()` / `channel.read()` calls - prepare for IPv6 support (reported as apache#14732) by improving the `host:port` parsing (pick last `:` since IPv6 address might contains multiple `:` characters) - Handle backpressure properly by switching auto read off when channel writability changes - change auto read of the proxy-broker connection based on the writability of the client-proxy connection - change auto read of the client-proxy connection based on the writability of the proxy-broker connection - Consistently handle write errors by delegating exception handling to exceptionCaught method by using `.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)` (cherry picked from commit a1037c7) (cherry picked from commit 1e55685)
…switching to auto read mode (#14713) Refactor Proxy code to make it easier to understand and maintain. In addition, switch to use auto read mode since the proxies connections seem to stall in some cases since the proxied connection doesn't use Netty's auto read mode and the read handling doesn't seem complete. Currently, the proxy calls `.read()` when a message is written to the connection. There might be more messages flowing in the other direction and it could result in a blocked connection with the current solution that doesn't use Netty's auto read mode. Currently auto read is disabled in DirectProxyHandler for the connection between the proxy and the broker: https://github.com/apache/pulsar/blob/a26905371749798ec5288fb07a69978a36aacfaa/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java#L112 - replace broker host parsing with a simple solution - pass remote host name to ProxyBackendHandler in the constructor - rename "targetBrokerUrl" to "brokerHostAndPort" since the "targetBrokerUrl" is really "hostname:port" string - move HA proxy message handling to ProxyBackendHandle and extract the logic to a method - remove the static "inboundOutboundChannelMap" which was used for log level 2 - make it obsolete by passing the peer channel id to ParserProxyHandler - Enable auto read in proxy and remove `ctx.read()` / `channel.read()` calls - prepare for IPv6 support (reported as #14732) by improving the `host:port` parsing (pick last `:` since IPv6 address might contains multiple `:` characters) - Handle backpressure properly by switching auto read off when channel writability changes - change auto read of the proxy-broker connection based on the writability of the client-proxy connection - change auto read of the client-proxy connection based on the writability of the proxy-broker connection - Consistently handle write errors by delegating exception handling to exceptionCaught method by using `.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)` (cherry picked from commit a1037c7) (cherry picked from commit 1e55685) (cherry picked from commit 9673d6c)
Motivation
Refactor Proxy code to make it easier to understand and maintain. In addition, switch to use auto read mode since the proxies connections seem to stall in some cases since the proxied connection doesn't use Netty's auto read mode and the read handling doesn't seem complete.
Currently, the proxy calls
.read()when a message is written to the connection. There might be more messages flowing in the other direction and it could result in a blocked connection with the current solution that doesn't use Netty's auto read mode.Currently auto read is disabled in DirectProxyHandler for the connection between the proxy and the broker:
pulsar/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java
Line 112 in a269053
Modifications
ctx.read()/channel.read()callshost:portparsing (pick last:since IPv6 address might contains multiple:characters).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)