2015-12-15 22:01:03 +00:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
2015-12-23 17:46:22 +00:00
|
|
|
"errors"
|
2016-01-19 22:36:39 +00:00
|
|
|
"net"
|
2015-12-15 22:01:03 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/influxdb/influxdb/toml"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-12-23 15:48:25 +00:00
|
|
|
// DefaultEnabled is the default state for the meta service to run
|
|
|
|
DefaultEnabled = true
|
|
|
|
|
2015-12-15 22:01:03 +00:00
|
|
|
// DefaultHostname is the default hostname if one is not provided.
|
|
|
|
DefaultHostname = "localhost"
|
|
|
|
|
|
|
|
// DefaultRaftBindAddress is the default address to bind to.
|
|
|
|
DefaultRaftBindAddress = ":8088"
|
|
|
|
|
2015-12-30 13:15:00 +00:00
|
|
|
// DefaultHTTPBindAddress is the default address to bind the API to.
|
|
|
|
DefaultHTTPBindAddress = ":8091"
|
2015-12-15 22:01:03 +00:00
|
|
|
|
|
|
|
// DefaultHeartbeatTimeout is the default heartbeat timeout for the store.
|
|
|
|
DefaultHeartbeatTimeout = 1000 * time.Millisecond
|
|
|
|
|
|
|
|
// DefaultElectionTimeout is the default election timeout for the store.
|
|
|
|
DefaultElectionTimeout = 1000 * time.Millisecond
|
|
|
|
|
|
|
|
// DefaultLeaderLeaseTimeout is the default leader lease for the store.
|
|
|
|
DefaultLeaderLeaseTimeout = 500 * time.Millisecond
|
|
|
|
|
|
|
|
// DefaultCommitTimeout is the default commit timeout for the store.
|
|
|
|
DefaultCommitTimeout = 50 * time.Millisecond
|
|
|
|
|
|
|
|
// DefaultRaftPromotionEnabled is the default for auto promoting a node to a raft node when needed
|
|
|
|
DefaultRaftPromotionEnabled = true
|
|
|
|
|
2016-01-09 04:29:48 +00:00
|
|
|
// DefaultLeaseDuration is the default duration for leases.
|
|
|
|
DefaultLeaseDuration = 60 * time.Second
|
|
|
|
|
2015-12-15 22:01:03 +00:00
|
|
|
// DefaultLoggingEnabled determines if log messages are printed for the meta service
|
|
|
|
DefaultLoggingEnabled = true
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config represents the meta configuration.
|
|
|
|
type Config struct {
|
2016-01-06 22:34:34 +00:00
|
|
|
Enabled bool `toml:"enabled"`
|
|
|
|
Dir string `toml:"dir"`
|
2015-12-30 13:15:00 +00:00
|
|
|
|
|
|
|
// this is deprecated. Should use the address from run/config.go
|
|
|
|
BindAddress string `toml:"bind-address"`
|
|
|
|
|
|
|
|
// HTTPBindAddress is the bind address for the metaservice HTTP API
|
|
|
|
HTTPBindAddress string `toml:"http-bind-address"`
|
|
|
|
HTTPSEnabled bool `toml:"https-enabled"`
|
|
|
|
HTTPSCertificate string `toml:"https-certificate"`
|
|
|
|
|
|
|
|
// JoinPeers if specified gives other metastore servers to join this server to the cluster
|
|
|
|
JoinPeers []string `toml:"-"`
|
2015-12-15 22:01:03 +00:00
|
|
|
RetentionAutoCreate bool `toml:"retention-autocreate"`
|
|
|
|
ElectionTimeout toml.Duration `toml:"election-timeout"`
|
|
|
|
HeartbeatTimeout toml.Duration `toml:"heartbeat-timeout"`
|
|
|
|
LeaderLeaseTimeout toml.Duration `toml:"leader-lease-timeout"`
|
|
|
|
CommitTimeout toml.Duration `toml:"commit-timeout"`
|
|
|
|
ClusterTracing bool `toml:"cluster-tracing"`
|
|
|
|
RaftPromotionEnabled bool `toml:"raft-promotion-enabled"`
|
|
|
|
LoggingEnabled bool `toml:"logging-enabled"`
|
|
|
|
PprofEnabled bool `toml:"pprof-enabled"`
|
2016-01-09 04:29:48 +00:00
|
|
|
|
|
|
|
LeaseDuration toml.Duration `toml:"lease-duration"`
|
2015-12-15 22:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewConfig builds a new configuration with default values.
|
|
|
|
func NewConfig() *Config {
|
|
|
|
return &Config{
|
2015-12-30 13:15:00 +00:00
|
|
|
Enabled: true, // enabled by default
|
|
|
|
BindAddress: DefaultRaftBindAddress,
|
|
|
|
HTTPBindAddress: DefaultHTTPBindAddress,
|
2015-12-15 22:01:03 +00:00
|
|
|
RetentionAutoCreate: true,
|
|
|
|
ElectionTimeout: toml.Duration(DefaultElectionTimeout),
|
|
|
|
HeartbeatTimeout: toml.Duration(DefaultHeartbeatTimeout),
|
|
|
|
LeaderLeaseTimeout: toml.Duration(DefaultLeaderLeaseTimeout),
|
|
|
|
CommitTimeout: toml.Duration(DefaultCommitTimeout),
|
|
|
|
RaftPromotionEnabled: DefaultRaftPromotionEnabled,
|
2016-01-09 04:29:48 +00:00
|
|
|
LeaseDuration: toml.Duration(DefaultLeaseDuration),
|
2015-12-15 22:01:03 +00:00
|
|
|
LoggingEnabled: DefaultLoggingEnabled,
|
|
|
|
}
|
|
|
|
}
|
2015-12-23 17:46:22 +00:00
|
|
|
|
|
|
|
func (c *Config) Validate() error {
|
|
|
|
if c.Enabled && c.Dir == "" {
|
|
|
|
return errors.New("Meta.Dir must be specified")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2016-01-19 22:36:39 +00:00
|
|
|
|
|
|
|
func (c *Config) defaultHost(addr string) string {
|
|
|
|
host, port, err := net.SplitHostPort(addr)
|
|
|
|
if err != nil {
|
|
|
|
return addr
|
|
|
|
}
|
|
|
|
|
|
|
|
if host == "" {
|
2016-01-23 00:02:54 +00:00
|
|
|
return net.JoinHostPort(DefaultHostname, port)
|
2016-01-19 22:36:39 +00:00
|
|
|
}
|
|
|
|
return addr
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultedBindAddress returns the BindAddress normalized with the
|
|
|
|
// hosts name or "localhost" if that could not be determined. If
|
|
|
|
// the BindAddress already has a hostname, BindAddress is returned.
|
|
|
|
func (c *Config) DefaultedBindAddress() string {
|
|
|
|
return c.defaultHost(c.BindAddress)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultedHTTPBindAddress returns the HTTPBindAddress normalized with the
|
|
|
|
// hosts name or "localhost" if that could not be determined. If
|
|
|
|
// the HTTPBindAddress already has a hostname, HTTPBindAddress is returned.
|
|
|
|
func (c *Config) DefaultedHTTPBindAddress() string {
|
|
|
|
return c.defaultHost(c.HTTPBindAddress)
|
|
|
|
}
|