2016-11-15 01:34:25 -08:00
|
|
|
// Package tsdb implements a time series storage for float64 sample data.
|
|
|
|
package tsdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/fabxc/tsdb/chunks"
|
|
|
|
"github.com/prometheus/common/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DefaultOptions used for the DB.
|
|
|
|
var DefaultOptions = &Options{
|
|
|
|
StalenessDelta: 5 * time.Minute,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Options of the DB storage.
|
|
|
|
type Options struct {
|
|
|
|
StalenessDelta time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
// DB is a time series storage.
|
|
|
|
type DB struct {
|
|
|
|
logger log.Logger
|
|
|
|
opts *Options
|
|
|
|
|
2016-12-02 08:49:05 -08:00
|
|
|
shards map[uint64]*TimeShards
|
2016-11-15 01:34:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Open or create a new DB.
|
|
|
|
func Open(path string, l log.Logger, opts *Options) (*DB, error) {
|
|
|
|
if opts == nil {
|
|
|
|
opts = DefaultOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
c := &DB{
|
2016-12-02 08:49:05 -08:00
|
|
|
logger: l,
|
|
|
|
opts: opts,
|
2016-11-15 01:34:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
2016-12-02 08:49:05 -08:00
|
|
|
type Label struct {
|
|
|
|
Name, Value string
|
2016-11-15 01:34:25 -08:00
|
|
|
}
|
|
|
|
|
2016-12-02 08:49:05 -08:00
|
|
|
// LabelSet is a sorted set of labels. Order has to be guaranteed upon
|
|
|
|
// instantiation.
|
|
|
|
type LabelSet []Label
|
2016-11-15 01:34:25 -08:00
|
|
|
|
2016-12-02 08:49:05 -08:00
|
|
|
func (ls LabelSet) Len() int { return len(ls) }
|
|
|
|
func (ls LabelSet) Swap(i, j int) { ls[i], ls[j] = ls[j], ls[i]}
|
|
|
|
func (ls LabelSet) Less(i, j int) bool { return ls[i].Name < ls[j].Name }
|
2016-11-15 01:34:25 -08:00
|
|
|
|
2016-12-02 08:49:05 -08:00
|
|
|
// NewLabelSet returns a sorted LabelSet from the given labels.
|
|
|
|
// The caller has to guarantee that all label names are unique.
|
|
|
|
func NewLabelSet(ls ...Label) LabelSet {
|
|
|
|
set := make(LabelSet, 0, len(l))
|
|
|
|
for _, l := range ls {
|
|
|
|
set = append(set, l)
|
2016-11-15 01:34:25 -08:00
|
|
|
}
|
2016-12-02 08:49:05 -08:00
|
|
|
sort.Sort(set)
|
2016-11-15 01:34:25 -08:00
|
|
|
|
2016-12-02 08:49:05 -08:00
|
|
|
return set
|
2016-11-15 01:34:25 -08:00
|
|
|
}
|
|
|
|
|
2016-12-02 08:49:05 -08:00
|
|
|
type Vector struct {
|
|
|
|
LabelSets []LabelSet
|
|
|
|
Values []float64
|
2016-11-15 01:34:25 -08:00
|
|
|
}
|
|
|
|
|
2016-12-02 08:49:05 -08:00
|
|
|
func (db *DB) AppendVector(v *Vector) error {
|
|
|
|
return nil
|
|
|
|
}
|