config.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package etcdserver
  2. import (
  3. "fmt"
  4. "net/http"
  5. "path"
  6. "github.com/coreos/etcd/pkg/types"
  7. )
  8. // ServerConfig holds the configuration of etcd as taken from the command line or discovery.
  9. type ServerConfig struct {
  10. Name string
  11. DiscoveryURL string
  12. ClientURLs types.URLs
  13. DataDir string
  14. SnapCount uint64
  15. Cluster *Cluster
  16. ClusterState ClusterState
  17. Transport *http.Transport
  18. }
  19. // Verify sanity-checks the config struct and returns an error for things that
  20. // should never happen.
  21. func (c *ServerConfig) Verify() error {
  22. // Make sure the cluster at least contains the local server.
  23. m := c.Cluster.FindName(c.Name)
  24. if m == nil {
  25. return fmt.Errorf("could not find name %v in cluster", c.Name)
  26. }
  27. // No identical IPs in the cluster peer list
  28. urlMap := make(map[string]bool)
  29. for _, m := range *c.Cluster {
  30. for _, url := range m.PeerURLs {
  31. if urlMap[url] {
  32. return fmt.Errorf("duplicate url %v in server config", url)
  33. }
  34. urlMap[url] = true
  35. }
  36. }
  37. return nil
  38. }
  39. func (c *ServerConfig) WALDir() string { return path.Join(c.DataDir, "wal") }
  40. func (c *ServerConfig) SnapDir() string { return path.Join(c.DataDir, "snap") }
  41. func (c *ServerConfig) ID() uint64 { return c.Cluster.FindName(c.Name).ID }
  42. func (c *ServerConfig) ShouldDiscover() bool {
  43. return c.DiscoveryURL != ""
  44. }
  45. // IsBootstrap returns true if a bootstrap method is provided.
  46. func (c *ServerConfig) IsBootstrap() bool {
  47. return c.DiscoveryURL != "" || c.ClusterState == ClusterStateValueNew
  48. }