NIFI-1301: Ensure that when creating site-to-site connection, if remote instance is applying backpressure that we do not block indefinitely waiting for the connection to be made

Signed-off-by: joewitt <joewitt@apache.org>
This commit is contained in:
Mark Payne 2015-12-17 15:40:00 -05:00 committed by joewitt
parent 608287f9fe
commit bef3fc8b40

View File

@ -250,6 +250,8 @@ public class EndpointConnectionPool {
EndpointConnection connection; EndpointConnection connection;
Peer peer = null; Peer peer = null;
do {
final List<EndpointConnection> addBack = new ArrayList<>();
logger.debug("{} getting next peer status", this); logger.debug("{} getting next peer status", this);
final PeerStatus peerStatus = getNextPeerStatus(direction); final PeerStatus peerStatus = getNextPeerStatus(direction);
logger.debug("{} next peer status = {}", this, peerStatus); logger.debug("{} next peer status = {}", this, peerStatus);
@ -267,9 +269,7 @@ public class EndpointConnectionPool {
} }
} }
final List<EndpointConnection> addBack = new ArrayList<>();
try { try {
do {
connection = connectionQueue.poll(); connection = connectionQueue.poll();
logger.debug("{} Connection State for {} = {}", this, clusterUrl, connection); logger.debug("{} Connection State for {} = {}", this, clusterUrl, connection);
final String portId = getPortIdentifier(direction); final String portId = getPortIdentifier(direction);
@ -387,7 +387,6 @@ public class EndpointConnectionPool {
protocol = connection.getSocketClientProtocol(); protocol = connection.getSocketClientProtocol();
} }
} }
} while (connection == null || codec == null || commsSession == null || protocol == null);
} catch (final Throwable t) { } catch (final Throwable t) {
if (commsSession != null) { if (commsSession != null) {
try { try {
@ -400,9 +399,12 @@ public class EndpointConnectionPool {
} finally { } finally {
if (!addBack.isEmpty()) { if (!addBack.isEmpty()) {
connectionQueue.addAll(addBack); connectionQueue.addAll(addBack);
addBack.clear();
} }
} }
} while (connection == null || codec == null || commsSession == null || protocol == null);
activeConnections.add(connection); activeConnections.add(connection);
return connection; return connection;
} }
@ -773,7 +775,7 @@ public class EndpointConnectionPool {
final StringBuilder distributionDescription = new StringBuilder(); final StringBuilder distributionDescription = new StringBuilder();
distributionDescription.append("New Weighted Distribution of Nodes:"); distributionDescription.append("New Weighted Distribution of Nodes:");
for (final Map.Entry<NodeInformation, Integer> entry : entryCountMap.entrySet()) { for (final Map.Entry<NodeInformation, Integer> entry : entryCountMap.entrySet()) {
final double percentage = entry.getValue() * 100D / (double) destinations.size(); final double percentage = entry.getValue() * 100D / destinations.size();
distributionDescription.append("\n").append(entry.getKey()).append(" will receive ").append(percentage).append("% of data"); distributionDescription.append("\n").append(entry.getKey()).append(" will receive ").append(percentage).append("% of data");
} }
logger.info(distributionDescription.toString()); logger.info(distributionDescription.toString());