influxdb/tsdb/config.go

124 lines
3.8 KiB
Go
Raw Normal View History

2015-05-28 21:47:47 +00:00
package tsdb
2015-05-29 19:50:05 +00:00
import (
"errors"
"fmt"
2015-05-29 19:50:05 +00:00
"time"
"github.com/influxdata/influxdb/toml"
2015-05-29 19:50:05 +00:00
)
const (
2015-09-17 02:05:20 +00:00
// DefaultEngine is the default engine for new shards
DefaultEngine = "tsm1"
2015-09-17 02:05:20 +00:00
2016-11-14 15:55:40 +00:00
// DefaultIndex is the default index for new shards
2017-01-31 15:47:18 +00:00
DefaultIndex = "inmem"
2016-11-14 15:55:40 +00:00
2015-08-18 20:59:54 +00:00
// tsdb/engine/wal configuration options
// Default settings for TSM
// DefaultCacheMaxMemorySize is the maximum size a shard's cache can
// reach before it starts rejecting writes.
DefaultCacheMaxMemorySize = 1024 * 1024 * 1024 // 1GB
// DefaultCacheSnapshotMemorySize is the size at which the engine will
// snapshot the cache and write it to a TSM file, freeing up memory
DefaultCacheSnapshotMemorySize = 25 * 1024 * 1024 // 25MB
// DefaultCacheSnapshotWriteColdDuration is the length of time at which
// the engine will snapshot the cache and write it to a new TSM file if
// the shard hasn't received writes or deletes
DefaultCacheSnapshotWriteColdDuration = time.Duration(10 * time.Minute)
// DefaultCompactFullWriteColdDuration is the duration at which the engine
// will compact all TSM files in a shard if it hasn't received a write or delete
DefaultCompactFullWriteColdDuration = time.Duration(4 * time.Hour)
// DefaultMaxPointsPerBlock is the maximum number of points in an encoded
// block in a TSM file
DefaultMaxPointsPerBlock = 1000
2016-11-29 12:26:52 +00:00
// DefaultMaxSeriesPerShard is the maximum number of series a node can hold per shard.
DefaultMaxSeriesPerShard = 100000
2016-10-05 05:52:49 +00:00
// DefaultMaxValuesPerTag is the maximum number of values a tag can have within a measurement.
DefaultMaxValuesPerTag = 100000
2015-05-29 19:50:05 +00:00
)
2015-05-29 15:53:33 +00:00
2016-02-10 20:04:18 +00:00
// Config holds the configuration for the tsbd package.
2015-05-28 21:47:47 +00:00
type Config struct {
Dir string `toml:"dir"`
2016-10-24 21:19:11 +00:00
Engine string `toml:"-"`
Index string `toml:"index-version"`
2015-08-18 20:59:54 +00:00
// General WAL configuration options
2016-10-24 21:19:11 +00:00
WALDir string `toml:"wal-dir"`
// Query logging
QueryLogEnabled bool `toml:"query-log-enabled"`
// Compaction options for tsm1 (descriptions above with defaults)
CacheMaxMemorySize uint64 `toml:"cache-max-memory-size"`
CacheSnapshotMemorySize uint64 `toml:"cache-snapshot-memory-size"`
CacheSnapshotWriteColdDuration toml.Duration `toml:"cache-snapshot-write-cold-duration"`
CompactFullWriteColdDuration toml.Duration `toml:"compact-full-write-cold-duration"`
2015-12-14 23:58:27 +00:00
// Limits
2016-11-29 12:26:52 +00:00
// MaxSeriesPerShard is the maximum number of series a node can hold per shard.
// When this limit is exceeded, writes return a 'max series per shard exceeded' error.
// A value of 0 disables the limit.
2016-11-29 12:26:52 +00:00
MaxSeriesPerShard int `toml:"max-series-per-shard"`
2016-10-05 05:52:49 +00:00
// MaxValuesPerTag is the maximum number of tag values a single tag key can have within
// a measurement. When the limit is execeeded, writes return an error.
// A value of 0 disables the limit.
MaxValuesPerTag int `toml:"max-values-per-tag"`
TraceLoggingEnabled bool `toml:"trace-logging-enabled"`
2015-05-28 21:47:47 +00:00
}
2015-05-29 19:50:05 +00:00
2016-02-10 20:04:18 +00:00
// NewConfig returns the default configuration for tsdb.
2015-05-29 19:50:05 +00:00
func NewConfig() Config {
return Config{
Engine: DefaultEngine,
2016-11-14 15:55:40 +00:00
Index: DefaultIndex,
QueryLogEnabled: true,
CacheMaxMemorySize: DefaultCacheMaxMemorySize,
CacheSnapshotMemorySize: DefaultCacheSnapshotMemorySize,
CacheSnapshotWriteColdDuration: toml.Duration(DefaultCacheSnapshotWriteColdDuration),
CompactFullWriteColdDuration: toml.Duration(DefaultCompactFullWriteColdDuration),
2015-12-15 21:15:38 +00:00
2016-11-29 12:26:52 +00:00
MaxSeriesPerShard: DefaultMaxSeriesPerShard,
MaxValuesPerTag: DefaultMaxValuesPerTag,
TraceLoggingEnabled: false,
2015-05-29 19:50:05 +00:00
}
}
2016-02-10 20:04:18 +00:00
// Validate validates the configuration hold by c.
func (c *Config) Validate() error {
if c.Dir == "" {
return errors.New("Data.Dir must be specified")
} else if c.WALDir == "" {
return errors.New("Data.WALDir must be specified")
}
valid := false
for _, e := range RegisteredEngines() {
if e == c.Engine {
valid = true
break
}
}
if !valid {
return fmt.Errorf("unrecognized engine %s", c.Engine)
}
return nil
}