Hi all,

  We run a Kafka-fed topology on Storm 2.8.x with acking enabled and
topology.max.spout.pending set. The spout moves its Kafka position forward
only after a tuple
  tree is fully acked. We hit two problems and would like your feedback on
a fix we're testing.

  Problem 1: with message timeouts off, a worker crash stops spouts on
other workers

  We killed one worker (kill -9). The supervisor restarted it within
seconds, but spouts on the other workers stopped emitting and never
recovered until we restarted
  the topology.

  What we found:
  - Tuple trees that passed through the dead worker never complete. Their
tuples and acks were lost with it, or dropped while the connection was down.
  - Nobody fails these trees. The acker can't tell "lost" from "still in
progress", and the bolt that held the tuple is gone.
  - With timeouts off, their entries stay in the spout's pending map
forever. Once a spout has max.spout.pending of them, it stops calling
nextTuple for good.
  - When Kafka moves a partition to another consumer, those entries still
stay, because the pending map knows nothing about partitions. So the newly
assigned
    partitions are stuck too.

  We understand that the message timeout is the intended way to recover
from this.

  Problem 2: with message timeouts on, slow tuples are failed as well as
lost ones

  The timeout clock starts at emit, so time spent waiting in queues counts.
Under load, tuples that are only waiting their turn also time out. Storm
then:
  - calls fail() on the spout,
  - but doesn't stop the tuple, which is still processed shortly after,
  - and drops its later ack, because the pending entry has already been
removed.

  So the spout can't tell a slow tuple from a lost one. If it re-emits on
every fail, slow tuples get processed twice. If it treats the fail as done,
it can move
  past a record that hasn't finished processing yet, and a crash at that
moment loses it. We reproduced both outcomes in local tests.

  What we're testing (three small changes, all off unless a topology config
enables them)

  1. Late ack after a timeout. When a tuple times out, move its entry from
pending to a second rotating map instead of failing it. This frees its
max.spout.pending
     slot. If its ack (or fail) arrives within one more rotation, deliver
it to the spout as normal. Only if it expires there too is the spout's
fail() called. Slow
     tuples complete normally, and only trees that never finish reach the
spout as failed.
  2. Tell the spout why it failed. An optional spout interface, fail(Object
msgId, String reason), with the reason TIMEOUT or FAIL-STREAM. The spout
can then re-emit
     a presumed-lost tuple but treat a bolt-reported failure differently.
  3. Let the spout drop its own pending entries. A default method on the
spout output collector, dropPending(Predicate<Object> msgIdMatch), safe
from any thread and
     applied on the spout thread. It removes matching entries emitted
before the call, without calling ack or fail. A Kafka spout calls it after
a rebalance for
     partitions it no longer owns, so they stop holding max.spout.pending.

  In local tests (LocalCluster plus Kafka, with a bolt that silently drops
some tuples for a few seconds to imitate a dead worker):
  - stock behaviour with timeouts off stalls until restart;
  - stock behaviour with timeouts on can skip records;
  - with the three changes, there is no stall and no record is lost, and
only the lost tuples are re-emitted.

  Questions
  1. Is there an existing JIRA or discussion about either problem? We may
have missed it.
  2. Do you see a problem with delivering an ack to the spout after its
timeout has fired, for example with metrics, hooks or the event logger?
  3. Would changes like these be considered for upstream, and if so, as one
change or three?

Thanks,
Karthick

Reply via email to