Beispiel #1
0
func (cmd *MetaCommand) Exec(cl model.Cluster) error {
	b, err := cl.Leader(cmd.Topic, int32(cmd.Partition))
	if err != nil {
		return err
	}
	res, err := proto.Metadata(cmd.Topic).Fetch(b)
	if err != nil {
		return err
	}
	fmt.Println(toJSON(res))
	return nil
}
Beispiel #2
0
func (c *C) updateFromTopicMetadata(topic string) error {
	brokers, err := c.pool.Brokers()
	if err != nil {
		return err
	}
	var merr MultiError
	for _, broker := range brokers {
		// no retry, fail fast
		m, err := proto.Metadata(topic).Fetch(broker)
		if err != nil {
			merr.Add(err)
			continue
		}
		for i := range m.Brokers {
			b := &m.Brokers[i]
			c.pool.Add(b.NodeID, b.Addr())
		}
		for i := range m.TopicMetadatas {
			t := &m.TopicMetadatas[i]
			if t.TopicName == topic {
				partitions := make([]int32, len(t.PartitionMetadatas))
				for i := range t.PartitionMetadatas {
					partition := &t.PartitionMetadatas[i]
					partitions[i] = partition.PartitionID
					if err := c.pool.SetLeader(topic, partition.PartitionID, partition.Leader); err != nil {
						merr.Add(err)
						continue
					}
				}
				c.topics.addPartitions(topic, partitions)
				return nil
			}
		}
	}
	return merr
}