Spout prematurely acks, even failed Bolt tuples

2019-05-20 23:48发布

问题:

I'm using the Python Storm library streamparse (which utilizes pystorm underneath). I've had problems calling a Spouts fail() method in the boilerplate wordcount project. According to the pystorm quickstart docs and numerous things I've read, calling fail(tuple) in a Bolt should elicit a failure in the originating Spout. However, even with the few modifications I've made, I always get a Spout ack() right when it leaves the Spout. Is this the correct behavior, or do I need to change a setting/instance variable?

I'm on streamparse 3.4.0 and storm 1.0.2.

My logs show the Spout ack() coming before the Bolt logging.

7609 [Thread-14-word_spout-executor[2 2]] INFO  o.a.s.s.ShellSpout - ShellLog pid:35761, name:word_spout 2017-02-20 15:30:33,070 - pystorm.component.word_spout - acking w
hen I shouldnt tup_id: 3219

...

7611 [Thread-21] INFO  o.a.s.t.ShellBolt - ShellLog pid:35760, name:count_bolt 2017-02-20 15:30:33,072 - pystorm.component.count_bolt - BOLT: receiving tup_id/count: 3219

word.py

from itertools import cycle

from streamparse import Spout
from streamparse import ReliableSpout


class WordSpout(ReliableSpout):
    outputs = ['word']

    def initialize(self, stormconf, context):
        self.words = cycle(['dog', 'cat', 'zebra', 'elephant'])
        self.count = 0

    def next_tuple(self):
        self.count += 1
        word = next(self.words)
        self.emit([str(self.count)], tup_id=self.count)

    def ack(self, tup_id):
        self.logger.info("acking when I shouldnt tup_id: {0}".format(tup_id))

    def fail(self, tup_id):
        self.logger.info("failing when I should tup_id: {0}".format(tup_id))

wordcount.py

import os
from collections import Counter

from streamparse import Bolt


class WordCountBolt(Bolt):
    auto_ack = False
    auto_fail = False

    outputs = ['word', 'count']

    def initialize(self, conf, ctx):
        self.counter = Counter()
        self.pid = os.getpid()
        self.total = 0

    def _increment(self, word, inc_by):
        self.counter[word] += inc_by
        self.total += inc_by

    def process(self, tup):
        word = tup.values[0]
        self._increment(word, 10 if word == "dog" else 1)
        # if self.total % 1000 == 0:
            # self.logger.info("counted [{:,}] words [pid={}]".format(self.total,
                                                                    # self.pid))
        self.logger.info("BOLT: receiving tup_id/count: {0}".format(word))
        # self.emit([word, self.counter[word]])
        self.fail(tup)

To reiterate, from what I know, I would expect the Bolt's failing to elicit a fail in the Spout and I would also not expect an ack so early. Am I wrong in thinking?