You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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?
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.
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:
About the same time, all 4 consumers, consumed all the messages at about the same rate:
Friday 19:40 Buenos Aires Time following a bundle unload one consumer gets reset and starts consuming messages again:
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.
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.
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
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).
@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.
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.
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?
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)
@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?
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.
Activity
sschepens commentedon Jan 30, 2017
@merlimat @rdhabalia we really need help with this it's causing issues to us in production.
merlimat commentedon Jan 30, 2017
@sschepens Few questions to try identify the issue:
managedLedgerDefaultMarkDeleteRateLimit=0. That mens to persist each and every updatebin/pulsar-admin namespaces set-persistent --bookkeeper-ensemble 2 --bookkeeper-write-quorum 2 --bookkeeper-ack-quorum 2 --ml-mark-delete-max-rate 0merlimat commentedon Jan 30, 2017
managedLedgerDefaultMarkDeleteRateLimitcontrols 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.
sschepens commentedon Jan 30, 2017
@merlimat
Yes it is, we also tried consuming harder.
It wouldn't appear so, as backlog reported by broker before restarting is 0, which would confirm that it considers all messages were acked.
We're already using ack timeout for all consumers.
I'll try, we're now using
managedLedgerDefaultMarkDeleteRateLimit=10to theoretically save state 10 times per second.Hmm shouldn't this have at least a way of checking when state has not been saved for some time and force a save?
merlimat commentedon Jan 30, 2017
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.
sschepens commentedon Jan 30, 2017
@merlimat does changing
managedLedgerMaxMarkDeleteRateviapulsar-adminrequire restarting brokers to take changes?merlimat commentedon Jan 30, 2017
it requires re-loading the topics,
pulsar-admin namespaces unload ...sschepens commentedon Jan 30, 2017
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:
About the same time, all 4 consumers, consumed all the messages at about the same rate:

Friday 19:40 Buenos Aires Time following a bundle unload one consumer gets reset and starts consuming messages again:

merlimat commentedon Jan 30, 2017
Are these consumers on the same subscription or in 4 different subscriptions?
sschepens commentedon Jan 30, 2017
4 different subscriptions, all are shared subscriptions and are hosted on the same 2 instances
merlimat commentedon Jan 30, 2017
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.
sschepens commentedon Jan 30, 2017
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.
merlimat commentedon Jan 30, 2017
If you're able to reproduce it, can you past the stats-internal for the topic (after consuming and before restarting)?
sschepens commentedon Jan 30, 2017
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
sschepens commentedon Feb 3, 2017
@merlimat this has happened again for different consumers when restarting a broker. We have the following persistence for the namespace settings:
This is absolutely not tolerable, we must find a way to fix this
20 remaining items
estebangarcia commentedon Feb 3, 2017
The message is from yesterday for some reason it was never consumed.
merlimat commentedon Feb 3, 2017
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).
sschepens commentedon Feb 3, 2017
@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.
merlimat commentedon Feb 3, 2017
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.
sschepens commentedon Feb 3, 2017
No, because it's failing to process it.
I don't think message re-delivery rate is going to work, messages are potentially constantly being redelivered because they could spend
ackTimeoutin the internal queue of the consumers.Plus, we would like to identify which precise messages are being constantly redelivered.
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?
sschepens commentedon Feb 3, 2017
Another thought @merlimat
Would it be possible for brokers to store the value of
individuallyDeletedMessagesevery 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
individuallyDeletedMessagescould 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)
sschepens commentedon Feb 6, 2017
@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
individuallyDeletedMessageslist.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?merlimat commentedon Feb 7, 2017
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
individuallyDeletedMessagesdata itself, the good thing is that we haveintroduced 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
When the broker applies TTL, it will acknowledge the messages and thus close the gap and move the
markDeletePositionforward.merlimat commentedon Mar 24, 2017
Closing this one since the changes are already implemented and merged in #276
Add seek by time (apache#180)