2015-05-28 21:47:47 +00:00
|
|
|
package tsdb
|
|
|
|
|
2015-05-29 19:50:05 +00:00
|
|
|
import (
|
2015-10-27 18:57:21 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2015-05-29 19:50:05 +00:00
|
|
|
"time"
|
|
|
|
|
2016-02-10 17:26:18 +00:00
|
|
|
"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
|
2016-01-11 19:02:36 +00:00
|
|
|
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
|
|
|
|
|
2015-12-06 23:50:39 +00:00
|
|
|
// Default settings for TSM
|
2015-12-02 18:01:13 +00:00
|
|
|
|
2015-12-06 23:50:39 +00:00
|
|
|
// DefaultCacheMaxMemorySize is the maximum size a shard's cache can
|
|
|
|
// reach before it starts rejecting writes.
|
2016-10-26 02:49:43 +00:00
|
|
|
DefaultCacheMaxMemorySize = 1024 * 1024 * 1024 // 1GB
|
2015-12-02 18:01:13 +00:00
|
|
|
|
2015-12-06 23:50:39 +00:00
|
|
|
// 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
|
2015-12-07 19:47:17 +00:00
|
|
|
// the shard hasn't received writes or deletes
|
2016-10-26 02:49:43 +00:00
|
|
|
DefaultCacheSnapshotWriteColdDuration = time.Duration(10 * time.Minute)
|
2015-12-06 23:50:39 +00:00
|
|
|
|
|
|
|
// 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
|
2016-10-26 02:49:43 +00:00
|
|
|
DefaultCompactFullWriteColdDuration = time.Duration(4 * time.Hour)
|
2015-12-06 23:50:39 +00:00
|
|
|
|
|
|
|
// DefaultMaxPointsPerBlock is the maximum number of points in an encoded
|
|
|
|
// block in a TSM file
|
|
|
|
DefaultMaxPointsPerBlock = 1000
|
2016-07-21 12:11:06 +00:00
|
|
|
|
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 {
|
2016-03-08 19:59:33 +00:00
|
|
|
Dir string `toml:"dir"`
|
2016-10-24 21:19:11 +00:00
|
|
|
Engine string `toml:"-"`
|
2016-11-21 17:11:59 +00:00
|
|
|
Index string `toml:"index-version"`
|
2015-08-18 20:59:54 +00:00
|
|
|
|
2016-03-20 19:33:45 +00:00
|
|
|
// General WAL configuration options
|
2016-10-24 21:19:11 +00:00
|
|
|
WALDir string `toml:"wal-dir"`
|
2015-09-17 02:26:23 +00:00
|
|
|
|
|
|
|
// Query logging
|
|
|
|
QueryLogEnabled bool `toml:"query-log-enabled"`
|
2015-12-02 18:01:13 +00:00
|
|
|
|
2015-12-06 23:50:39 +00:00
|
|
|
// 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
|
|
|
|
2016-07-21 12:11:06 +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.
|
2016-07-21 12:11:06 +00:00
|
|
|
// A value of 0 disables the limit.
|
2016-11-29 12:26:52 +00:00
|
|
|
MaxSeriesPerShard int `toml:"max-series-per-shard"`
|
2016-07-21 12:11:06 +00:00
|
|
|
|
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"`
|
|
|
|
|
2016-07-07 15:27:09 +00:00
|
|
|
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{
|
2016-03-20 19:33:45 +00:00
|
|
|
Engine: DefaultEngine,
|
2016-11-14 15:55:40 +00:00
|
|
|
Index: DefaultIndex,
|
2016-03-20 19:33:45 +00:00
|
|
|
|
2015-09-17 02:26:23 +00:00
|
|
|
QueryLogEnabled: true,
|
2015-12-02 18:01:13 +00:00
|
|
|
|
2015-12-06 23:50:39 +00:00
|
|
|
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,
|
2016-07-21 12:11:06 +00:00
|
|
|
|
2016-07-07 15:27:09 +00:00
|
|
|
TraceLoggingEnabled: false,
|
2015-05-29 19:50:05 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-27 18:57:21 +00:00
|
|
|
|
2016-02-10 20:04:18 +00:00
|
|
|
// Validate validates the configuration hold by c.
|
2015-10-27 18:57:21 +00:00
|
|
|
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
|
|
|
|
}
|