Restructure files

This commit is contained in:
Fabian Reinartz 2016-12-08 12:21:03 +01:00
parent 63b887eb62
commit 3ef7da33c8
2 changed files with 49 additions and 53 deletions

49
db.go
View file

@ -280,3 +280,52 @@ func (db *DB) AppendVector(ts int64, v *Vector) error {
return nil
}
const sep = '\xff'
// SeriesShard handles reads and writes of time series falling into
// a hashed shard of a series.
type SeriesShard struct {
mtx sync.RWMutex
blocks *Block
head *HeadBlock
}
// NewSeriesShard returns a new SeriesShard.
func NewSeriesShard() *SeriesShard {
return &SeriesShard{
// TODO(fabxc): restore from checkpoint.
head: &HeadBlock{
index: newMemIndex(),
descs: map[uint64][]*chunkDesc{},
values: map[string][]string{},
forward: map[uint32]*chunkDesc{},
},
// TODO(fabxc): provide access to persisted blocks.
}
}
// chunkDesc wraps a plain data chunk and provides cached meta data about it.
type chunkDesc struct {
lset Labels
chunk chunks.Chunk
// Caching fields.
lastTimestamp int64
lastValue float64
app chunks.Appender // Current appender for the chunks.
}
func (cd *chunkDesc) append(ts int64, v float64) (err error) {
if cd.app == nil {
cd.app, err = cd.chunk.Appender()
if err != nil {
return err
}
}
cd.lastTimestamp = ts
cd.lastValue = v
return cd.app.Append(ts, v)
}

View file

@ -9,30 +9,6 @@ import (
"github.com/fabxc/tsdb/chunks"
)
const sep = '\xff'
// SeriesShard handles reads and writes of time series falling into
// a hashed shard of a series.
type SeriesShard struct {
mtx sync.RWMutex
blocks *Block
head *HeadBlock
}
// NewSeriesShard returns a new SeriesShard.
func NewSeriesShard() *SeriesShard {
return &SeriesShard{
// TODO(fabxc): restore from checkpoint.
head: &HeadBlock{
index: newMemIndex(),
descs: map[uint64][]*chunkDesc{},
values: map[string][]string{},
forward: map[uint32]*chunkDesc{},
},
// TODO(fabxc): provide access to persisted blocks.
}
}
// HeadBlock handles reads and writes of time series data within a time window.
type HeadBlock struct {
mtx sync.RWMutex
@ -44,10 +20,6 @@ type HeadBlock struct {
samples uint64
}
// Block handles reads against a completed block of time series data within a time window.
type Block struct {
}
// WriteTo serializes the current head block contents into w.
func (h *HeadBlock) WriteTo(w io.Writer) (int64, error) {
h.mtx.RLock()
@ -106,28 +78,3 @@ func (h *HeadBlock) append(hash uint64, lset Labels, ts int64, v float64) error
h.samples++
return nil
}
// chunkDesc wraps a plain data chunk and provides cached meta data about it.
type chunkDesc struct {
lset Labels
chunk chunks.Chunk
// Caching fields.
lastTimestamp int64
lastValue float64
app chunks.Appender // Current appender for the chunks.
}
func (cd *chunkDesc) append(ts int64, v float64) (err error) {
if cd.app == nil {
cd.app, err = cd.chunk.Appender()
if err != nil {
return err
}
}
cd.lastTimestamp = ts
cd.lastValue = v
return cd.app.Append(ts, v)
}