Hi Honghai, 1. If a partition has no leader (i.e. all of its replicas are down) it will become offline, and hence the metadata response will not have this partition's info.
2. Any of the brokers cache metadata and hence can handle the metadata request. It's just that their cache are updated asynchronously and hence when there is a update to the metadata, some brokers may got the new metadata value a bit eariler than others. On Thu, Feb 26, 2015 at 7:21 PM, ChenHongHai <waldenchenka...@outlook.com> wrote: > We have one topic with 4 partitions, but sometimes only get metadata of 2 > partitions, did anyone meet this kind of situation before?If some partition > has no leader at that moment, will it cause this problem? How to make > some partition has no leader?If 6 brokers has some partitions of the topic, > will they return same result? Do I need try all of them and merge the > result? > > SimpleConsumer consumer = consumerPool.getConsumer(seed.host, > seed.port, connectionTimeOut, consumerBufferSize, "refreshPartitionMeta"); > List<String> topics = new ArrayList<String>() {{ > add(topic); }}; TopicMetadataResponse > resp = consumer.send(new TopicMetadataRequest(topics)); > List<TopicMetadata> metaData = resp.topicsMetadata(); > for (TopicMetadata item : metaData) { > if(item.errorCode() != kafka.common.ErrorMapping.NoError()) > LOG.error(String.format("Something wrong with topic metadata for > topic: %s error code: %d ", item.topic(), item.errorCode() )); > for (PartitionMetadata part : item.partitionsMetadata()) { > partitionMeta.put(part.partitionId(), part); > } } > -- -- Guozhang