Repository: storm Updated Branches: refs/heads/master 71733add4 -> 5f818b9ad
netty loss of messages resolution Project: http://git-wip-us.apache.org/repos/asf/storm/repo Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/54b6ac49 Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/54b6ac49 Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/54b6ac49 Branch: refs/heads/master Commit: 54b6ac4975582bb6b3ef3511369e52ad81db05b3 Parents: b477939 Author: Sanket <schintap@untilservice-lm> Authored: Tue Mar 8 13:06:39 2016 -0600 Committer: Sanket <schintap@untilservice-lm> Committed: Tue Mar 8 13:06:39 2016 -0600 ---------------------------------------------------------------------- .../apache/storm/messaging/netty/Client.java | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/storm/blob/54b6ac49/storm-core/src/jvm/org/apache/storm/messaging/netty/Client.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/messaging/netty/Client.java b/storm-core/src/jvm/org/apache/storm/messaging/netty/Client.java index 976b550..3e15d34 100644 --- a/storm-core/src/jvm/org/apache/storm/messaging/netty/Client.java +++ b/storm-core/src/jvm/org/apache/storm/messaging/netty/Client.java @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.Collection; import java.util.Map; import java.util.HashMap; +import java.util.Timer; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -74,6 +75,7 @@ public class Client extends ConnectionWithStatus implements IStatefulObject, ISa private static final Logger LOG = LoggerFactory.getLogger(Client.class); private static final String PREFIX = "Netty-Client-"; private static final long NO_DELAY_MS = 0L; + private static Timer timer; private final Map stormConf; private final StormBoundedExponentialBackoffRetry retryPolicy; @@ -108,6 +110,13 @@ public class Client extends ConnectionWithStatus implements IStatefulObject, ISa private final AtomicInteger messagesLost = new AtomicInteger(0); /** + * Periodically checks for connected channel in order to avoid loss + * of messages + */ + private final long CHANNEL_ALIVE_INTERVAL_MS = 30000L; + + + /** * Number of messages buffered in memory. */ private final AtomicLong pendingMessages = new AtomicLong(0); @@ -130,6 +139,10 @@ public class Client extends ConnectionWithStatus implements IStatefulObject, ISa private final Object writeLock = new Object(); + static { + timer = new Timer("Netty-ChannelAlive-Timer", true); + } + @SuppressWarnings("rawtypes") Client(Map stormConf, ChannelFactory factory, HashedWheelTimer scheduler, String host, int port, Context context) { this.stormConf = stormConf; @@ -151,10 +164,35 @@ public class Client extends ConnectionWithStatus implements IStatefulObject, ISa bootstrap = createClientBootstrap(factory, bufferSize, stormConf); dstAddress = new InetSocketAddress(host, port); dstAddressPrefixedName = prefixedName(dstAddress); + launchChannelAliveThread(); scheduleConnect(NO_DELAY_MS); batcher = new MessageBuffer(messageBatchSize); } + /** + * This thread helps us to check for channel connection periodically. + * This is performed just to know whether the destination address + * is alive or attempts to refresh connections if not alive. This + * solution is better than what we have now in case of a bad channel. + */ + private void launchChannelAliveThread() { + // netty TimerTask is already defined and hence a fully + // qualified name + timer.schedule(new java.util.TimerTask() { + public void run() { + try { + LOG.debug("running timer task, address {}", dstAddress); + if(closing) { + this.cancel(); + } + getConnectedChannel(); + } catch (Exception exp) { + LOG.error("channel connection error {}", exp); + } + } + }, 0, CHANNEL_ALIVE_INTERVAL_MS); + } + private ClientBootstrap createClientBootstrap(ChannelFactory factory, int bufferSize, Map stormConf) { ClientBootstrap bootstrap = new ClientBootstrap(factory); bootstrap.setOption("tcpNoDelay", true);
