@@ -649,8 +649,9 @@ func (client *client) tryRefreshMetadata(topics []string, attemptsRemaining int)
649
649
650
650
switch err .(type ) {
651
651
case nil :
652
+ allKnownMetaData := len (topics ) == 0
652
653
// valid response, use it
653
- shouldRetry , err := client .updateMetadata (response )
654
+ shouldRetry , err := client .updateMetadata (response , allKnownMetaData )
654
655
if shouldRetry {
655
656
Logger .Println ("client/metadata found some partitions to be leaderless" )
656
657
return retry (err ) // note: err can be nil
@@ -674,7 +675,7 @@ func (client *client) tryRefreshMetadata(topics []string, attemptsRemaining int)
674
675
}
675
676
676
677
// if no fatal error, returns a list of topics that need retrying due to ErrLeaderNotAvailable
677
- func (client * client ) updateMetadata (data * MetadataResponse ) (retry bool , err error ) {
678
+ func (client * client ) updateMetadata (data * MetadataResponse , allKnownMetaData bool ) (retry bool , err error ) {
678
679
client .lock .Lock ()
679
680
defer client .lock .Unlock ()
680
681
@@ -685,7 +686,10 @@ func (client *client) updateMetadata(data *MetadataResponse) (retry bool, err er
685
686
for _ , broker := range data .Brokers {
686
687
client .registerBroker (broker )
687
688
}
688
-
689
+ if allKnownMetaData {
690
+ client .metadata = make (map [string ]map [int32 ]* PartitionMetadata )
691
+ client .cachedPartitionsResults = make (map [string ][maxPartitionIndex ][]int32 )
692
+ }
689
693
for _ , topic := range data .Topics {
690
694
delete (client .metadata , topic .Name )
691
695
delete (client .cachedPartitionsResults , topic .Name )
0 commit comments