func (c *Manager) Register(component, addr string) error {
	c.Lock()
	defer c.Unlock()
	addr, err := validateAddr(addr)
	if err != nil {
		return err
	}
	ca, ok := c.Addresses[component]
	if exist, _ := contains(ca, addr); ok && exist {
		log.Info("address has already been registered", zap.String("component", component), zap.String("address", addr))
		return fmt.Errorf("component %s address %s has already been registered", component, addr)
	}
	ca = append(ca, addr)
	c.Addresses[component] = ca
	if err := c.storage.SaveComponent(c); err != nil {
		return fmt.Errorf("failed to save component when registering component %s address %s", component, addr)
	}
	return nil
}
Register is used for registering a component with an address to PD.
package component
import (
	"fmt"
	"net/url"
	"sync"
	"github.com/pingcap/log"
	"github.com/tikv/pd/server/core"
	"go.uber.org/zap"
)
type Manager struct {
	sync.RWMutex
	storage *core.Storage
	Addresses map[string][]string `json:"address"`
}
func NewManager(storage *core.Storage) *Manager {
	return &Manager{
		storage:   storage,
		Addresses: make(map[string][]string),
	}
}
func (c *Manager) GetComponentAddrs(component string) []string {
	c.RLock()
	defer c.RUnlock()
	addresses := []string{}
	if ca, ok := c.Addresses[component]; ok {
		addresses = append(addresses, ca...)
	}
	return addresses
}
func (c *Manager) GetAllComponentAddrs() map[string][]string {
	c.RLock()
	defer c.RUnlock()
	n := make(map[string][]string)
	for k, v := range c.Addresses {
		b := make([]string, len(v))
		copy(b, v)
		n[k] = b
	}
	return n
}
func (c *Manager) GetComponent(addr string) string {
	c.RLock()
	defer c.RUnlock()
	addr, err := validateAddr(addr)
	if err != nil {
		return ""
	}
	for component, ca := range c.Addresses {
		if exist, _ := contains(ca, addr); exist {
			return component
		}
	}
	return ""
}