示例#1
0
文件: command.go 项目: h12w/kpax
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
}
示例#2
0
文件: cluster.go 项目: h12w/kpax
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
}