@@ -552,11 +552,9 @@ def committed(self, partition):
552
552
committed = None
553
553
return committed
554
554
555
- def topics (self ):
556
- """Get all topics the user is authorized to view.
557
-
558
- Returns:
559
- set: topics
555
+ def _fetch_all_topit_metadata (self ):
556
+ """A blocking call that fetches topic metadata for all topics in the
557
+ cluster that the user is authorized to view.
560
558
"""
561
559
cluster = self ._client .cluster
562
560
if self ._client ._metadata_refresh_in_progress and self ._client ._topics :
@@ -567,18 +565,37 @@ def topics(self):
567
565
future = cluster .request_update ()
568
566
self ._client .poll (future = future )
569
567
cluster .need_all_topic_metadata = stash
570
- return cluster .topics ()
568
+
569
+ def topics (self ):
570
+ """Get all topics the user is authorized to view.
571
+ This will always issue a remote call to the cluster to fetch the latest
572
+ information.
573
+
574
+ Returns:
575
+ set: topics
576
+ """
577
+ self ._fetch_all_topic_metadata ()
578
+ return self ._client .cluster .topics ()
571
579
572
580
def partitions_for_topic (self , topic ):
573
- """Get metadata about the partitions for a given topic.
581
+ """This method first checks the local metadata cache for information
582
+ about the topic. If the topic is not found (either because the topic
583
+ does not exist, the user is not authorized to view the topic, or the
584
+ metadata cache is not populated), then it will issue a metadata update
585
+ call to the cluster.
574
586
575
587
Arguments:
576
588
topic (str): Topic to check.
577
589
578
590
Returns:
579
591
set: Partition ids
580
592
"""
581
- return self ._client .cluster .partitions_for_topic (topic )
593
+ cluster = self ._client .cluster
594
+ partitions = cluster .partitions_for_topic (topic )
595
+ if partitions is None :
596
+ self ._fetch_all_topic_metadata ()
597
+ partitions = cluster .partitions_for_topic (topic )
598
+ return partitions
582
599
583
600
def poll (self , timeout_ms = 0 , max_records = None ):
584
601
"""Fetch data from assigned topics / partitions.
0 commit comments