Skip to content

Consumer not persisting Cursor #180

Closed

Description

@sschepens

We have 4 consumers for the same topic, all are supposedly up to date (0 backlog).
But when restarting brokers, thus loading cursor state from zookeeper and bookkeeper, we're consistently getting one consumer reset a long time backwards.
Looking at zookeeper metadata that consumer is the only one to have an outdated markDeleteLedgerId and markDeleteEntryId, this happens for all 10 partitions of the consumer.
Not only has this consumer an outdated cursor, it seems to no be updating it as it consumes all the backlog generated when a broker is restarted and thus consumer is reset.

Activity

  1. sschepens commented on Jan 30, 2017

    @sschepens
    ContributorAuthor

    @merlimat @rdhabalia we really need help with this it's causing issues to us in production.

  2. merlimat commented on Jan 30, 2017

    @merlimat
    Contributor

    @sschepens Few questions to try identify the issue:

    • Is that consumer receiving at the same rate as the other consumer?
    • Is it keeping some messages in the consumer receiving queue?
    • Does it change if using ack timeout on the consumer ?
    • Can you try to remove the throttling of persisting the mark-delete position? There are 2 ways for doing that :
      • Change the broker-wide setting: managedLedgerDefaultMarkDeleteRateLimit=0. That mens to persist each and every update
      • Change the setting on a particular namespace :
        bin/pulsar-admin namespaces set-persistent --bookkeeper-ensemble 2 --bookkeeper-write-quorum 2 --bookkeeper-ack-quorum 2 --ml-mark-delete-max-rate 0
  3. merlimat commented on Jan 30, 2017

    @merlimat
    Contributor

    managedLedgerDefaultMarkDeleteRateLimit controls how frequently the position is being persisted, to avoid too many writes on BookKeeper when consuming messages.
    The default is 0.1 (updates per seconds), which means 1 update every 10 seconds.

    Given the current implementation (using a guava rate limiter), subsequent acks are tracked in memory. The problem might be related to the fact that if there are no more writes on the topic, the persisted position for the cursor doesn't get a chance to get updated.

  4. sschepens commented on Jan 30, 2017

    @sschepens
    ContributorAuthor

    @merlimat

    Is that consumer receiving at the same rate as the other consumer?

    Yes it is, we also tried consuming harder.

    Is it keeping some messages in the consumer receiving queue?

    It wouldn't appear so, as backlog reported by broker before restarting is 0, which would confirm that it considers all messages were acked.

    Does it change if using ack timeout on the consumer ?

    We're already using ack timeout for all consumers.

    Can you try to remove the throttling of persisting the mark-delete position?

    I'll try, we're now using managedLedgerDefaultMarkDeleteRateLimit=10 to theoretically save state 10 times per second.

    Given the current implementation (using a guava rate limiter), subsequent acks are tracked in memory. The problem might be related to the fact that if there are no more writes on the topic, the persisted position for the cursor doesn't get a chance to get updated.

    Hmm shouldn't this have at least a way of checking when state has not been saved for some time and force a save?

  5. merlimat commented on Jan 30, 2017

    @merlimat
    Contributor

    Right now all the checking is done when processing an acknowledgment. There was the plan of fixing that, by going through all the topics every 1min to flush all the pending cursor updates, thought it's still like this.

  6. sschepens commented on Jan 30, 2017

    @sschepens
    ContributorAuthor

    @merlimat does changing managedLedgerMaxMarkDeleteRate via pulsar-admin require restarting brokers to take changes?

  7. merlimat commented on Jan 30, 2017

    @merlimat
    Contributor

    it requires re-loading the topics, pulsar-admin namespaces unload ...

  8. sschepens commented on Jan 30, 2017

    @sschepens
    ContributorAuthor

    Right now all the checking is done when processing an acknowledgment. There was the plan of fixing that, by going through all the topics every 1min to flush all the pending cursor updates, thought it's still like this.

    The strage thing is, all consumers consume at the same rate, and should have acked messages and saved state at about the same time, still this is the only consumer experiencing this issue.

    Here are metrics showing what happened:
    Thursday 17:20 Buenos Aires Time a bunch of messages were produced:
    screenshot from 2017-01-30 16-08-45

    About the same time, all 4 consumers, consumed all the messages at about the same rate:
    screenshot from 2017-01-30 16-08-56

    Friday 19:40 Buenos Aires Time following a bundle unload one consumer gets reset and starts consuming messages again:
    screenshot from 2017-01-30 16-09-16

  9. merlimat commented on Jan 30, 2017

    @merlimat
    Contributor

    Are these consumers on the same subscription or in 4 different subscriptions?

  10. sschepens commented on Jan 30, 2017

    @sschepens
    ContributorAuthor

    4 different subscriptions, all are shared subscriptions and are hosted on the same 2 instances

  11. merlimat commented on Jan 30, 2017

    @merlimat
    Contributor

    Ok, anything in the logs that could signal there was any failure in recovering the cursor after the unload?
    In case of failure to recover the cursor position, the behavior is to rollback to the oldest available message, to ensure no data is skipped.

  12. sschepens commented on Jan 30, 2017

    @sschepens
    ContributorAuthor

    I couln't find any log specifying a failure recovering the cursor, on the contrary, the cursor appeared to be recovered correctly, but on a really old position.

  13. merlimat commented on Jan 30, 2017

    @merlimat
    Contributor

    If you're able to reproduce it, can you past the stats-internal for the topic (after consuming and before restarting)?

  14. sschepens commented on Jan 30, 2017

    @sschepens
    ContributorAuthor

    I wasn't able to reproduce this again, but we had already set markDeleteRatio=0, and also reset the consumer.
    I will inform if we experience this behavior again

  15. sschepens commented on Feb 3, 2017

    @sschepens
    ContributorAuthor

    @merlimat this has happened again for different consumers when restarting a broker. We have the following persistence for the namespace settings:

    {
      "bookkeeperEnsemble" : 3,
      "bookkeeperWriteQuorum" : 3,
      "bookkeeperAckQuorum" : 3,
      "managedLedgerMaxMarkDeleteRate" : 0.0
    }
    

    This is absolutely not tolerable, we must find a way to fix this

  16. 20 remaining items

  17. estebangarcia commented on Feb 3, 2017

    @estebangarcia

    The message is from yesterday for some reason it was never consumed.

  18. merlimat commented on Feb 3, 2017

    @merlimat
    Contributor

    So, if you have set the ack-timeout, this message should be keeping getting resent to the consumer. You can enable debug logs (either on broker or consumer) to check that.
    Another option is to get a tcpdump capture of the traffic to the consumer (for port 6650).

  19. sschepens commented on Feb 3, 2017

    @sschepens
    ContributorAuthor

    @merlimat this messages is effectively being redelivered constantly.
    This brings up the question, should pulsar support dead-letter queues?
    I don't know what we can use to detect this realtime to prevent this issues.

  20. merlimat commented on Feb 3, 2017

    @merlimat
    Contributor

    Just to clarify, is the consumer acknowledging the message?

    About how to detect that, one way is to monitor the storage size constantly increasing (though in your case, with retention that is not feasible). Otherwise, monitor the re-delivery rate for the consumers (in the topic stats).

    About dead-letter queue. It's an interesting topic and I'd would support that, just not enabled by default. Potentially it could be an option on the namespace itself to define a dead-letter topic where to dump messages after N delivery attempts.
    When placing messages there, the broker could attach few properties to the messages themselves.

  21. sschepens commented on Feb 3, 2017

    @sschepens
    ContributorAuthor

    Just to clarify, is the consumer acknowledging the message?

    No, because it's failing to process it.

    About how to detect that, one way is to monitor the storage size constantly increasing (though in your case, with retention that is not feasible). Otherwise, monitor the re-delivery rate for the consumers (in the topic stats).

    I don't think message re-delivery rate is going to work, messages are potentially constantly being redelivered because they could spend ackTimeout in the internal queue of the consumers.
    Plus, we would like to identify which precise messages are being constantly redelivered.

    About dead-letter queue. It's an interesting topic and I'd would support that, just not enabled by default. Potentially it could be an option on the namespace itself to define a dead-letter topic where to dump messages after N delivery attempts.
    When placing messages there, the broker could attach few properties to the messages themselves.

    Of course, dead-letter queues should be optional, but there are also things to consider, should there be a dead-letter topic for each consumer? if not, how would we handle this?

  22. sschepens commented on Feb 3, 2017

    @sschepens
    ContributorAuthor

    Another thought @merlimat
    Would it be possible for brokers to store the value of individuallyDeletedMessages every given time or something, and have new brokers read that value to restore the actual state of that consumer?
    The only issue I can think of is that the value of individuallyDeletedMessages could grow forever, maybe we could allow for a given number of unacked messages and then print warnings or errors for that consumer?

    The line of thought is: what can we possibly do to prevent this from happening? (a consumer re-processing all messages when a broker restarts because it did not acknowledge a message)

  23. sschepens commented on Feb 6, 2017

    @sschepens
    ContributorAuthor

    @merlimat I'm thinking, what would happen if a consumer like the one we had issues with has a single messages that it cannot process and that message get expired via ttl or retention policies, would broker immediately discard it from individuallyDeletedMessages list.
    My concern is, when this message gets expired the broker could advance the markDeletePosition, if it would not do this, when bundle gets unloaded it would reset the consumer back to the beginning, wouldn't it?

  24. merlimat commented on Feb 7, 2017

    @merlimat
    Contributor

    Would it be possible for brokers to store the value of individuallyDeletedMessages every given time or something, and have new brokers read that value to restore the actual state of that consumer?

    Yes, we thought about that many times. The thing is storing that information, avoids the big backlog on restart but doesn't address the root cause of why the message wasn't acked.

    At the end, having a hole in the ack-sequence is always the symptom of a separate problem. And for the system, the data cannot be removed from disk because the storage is not a traditional key-value store where you can point-delete data.

    About the size of the individuallyDeletedMessages data itself, the good thing is that we have
    introduced a max amount of "unacked" messages that a consumer can have. After that, the broker will stop pushing messages to the consumer. I think default is 50K.

    To summarize my point of view

    • It would be nice to address the ack-hole problem, even if only to a limited degree, in a way that has no performance impact when it's not needed:
      • eg: only do that if mark-delete falls behind more than X thousand messages compared to read-positition
    • Give an intuitive and easy to use way to reject messages
    • Better report in stats when an "ack-hole" is detected, for quicker identification or alerting

    My concern is, when this message gets expired the broker could advance the markDeletePosition, if it would not do this, when bundle gets unloaded it would reset the consumer back to the beginning, wouldn't it?

    When the broker applies TTL, it will acknowledge the messages and thus close the gap and move the markDeletePosition forward.

  25. merlimat commented on Mar 24, 2017

    @merlimat
    Contributor

    Closing this one since the changes are already implemented and merged in #276

  26. added this to the 1.17 milestone on Mar 24, 2017
  27. added a commit that references this issue on Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions