streamnative / pulsar-archived

Apache Pulsar - distributed pub-sub messaging system
https://pulsar.apache.org
Apache License 2.0
73 stars 25 forks source link

ISSUE-14073: Key shared subscription: hash ranges are not fully reported in stats #3672

Open sijie opened 2 years ago

sijie commented 2 years ago

Original Issue: apache/pulsar#14073


Describe the bug When I run pulsar-admin topics stats TOPIC-NAME and I have a KeyShared subscription with stickyHashRanges, with many ranges, the stats are not fully reporting the ranges, it looks like that for each consumer they report only the last set of ranges assigned to each Consumer and for some Consumers the list is empty even if the Consumer set the range and it is actually consuming messages.

There should be some bug here: https://github.com/apache/pulsar/blob/9abd6d30f39f74e255cd5dac40b77af3dce5c468/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/HashRangeExclusiveStickyKeyConsumerSelector.java#L69

 public Map<Consumer, List<Range>> getConsumerKeyHashRanges() {
        Map<Consumer, List<Range>> result = new HashMap<>();
        Map.Entry<Integer, Consumer> prev = null;
        for (Map.Entry<Integer, Consumer> entry: rangeMap.entrySet()) {
            if (prev == null) {
                prev = entry;
            } else {
                if (prev.getValue().equals(entry.getValue())) {
                    result.computeIfAbsent(entry.getValue(), key -> new ArrayList<>())
                            .add(Range.of(prev.getKey(), entry.getKey()));
                }
                prev = null;
            }
        }
        return result;
    }

Additional context Pulsar 2.8.2

github-actions[bot] commented 2 years ago

The issue had no activity for 30 days, mark with Stale label.