From 3ef7da33c8ee38bfb171d2c11328a741f38fa40a Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Thu, 8 Dec 2016 12:21:03 +0100 Subject: [PATCH] Restructure files --- db.go | 49 +++++++++++++++++++++++++++++++++++++++++ shard.go => head.go | 53 --------------------------------------------- 2 files changed, 49 insertions(+), 53 deletions(-) rename shard.go => head.go (63%) diff --git a/db.go b/db.go index 19aa5d736..d39dc56ec 100644 --- a/db.go +++ b/db.go @@ -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) +} diff --git a/shard.go b/head.go similarity index 63% rename from shard.go rename to head.go index e8f36810f..5c52a90dd 100644 --- a/shard.go +++ b/head.go @@ -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) -}