Skip to content

Commit

Permalink
Extend the on flush new series event to account for differing types o…
Browse files Browse the repository at this point in the history
…f series metadata and memory lifetimes.
  • Loading branch information
notbdu committed Nov 20, 2020
1 parent 535f63c commit b749b66
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/dbnode/persist/fs/merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,15 @@ func (m *merger) Merge(

if err == nil {
err = onFlush.OnFlushNewSeries(persist.OnFlushNewSeriesEvent{
Shard: shard,
BlockStart: startTime,
FirstWrite: mergeWithData.FirstWrite,
SeriesMetadata: seriesMetadata,
Shard: shard,
BlockStart: startTime,
FirstWrite: mergeWithData.FirstWrite,
SeriesMetadata: persist.SeriesMetadata{
Type: persist.SeriesDocumentType,
Document: seriesMetadata,
// The lifetime of the shard series metadata is longly lived.
LifeTime: persist.SeriesMetadataLifeTimeLongLived,
},
})
}

Expand Down
43 changes: 39 additions & 4 deletions src/dbnode/persist/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ import (
"github.com/pborman/uuid"
)

var (
errReuseableTagIteratorRequired = errors.New("reuseable tags iterator is required")
)
var errReuseableTagIteratorRequired = errors.New("reuseable tags iterator is required")

// Metadata is metadata for a time series, it can
// have several underlying sources.
Expand Down Expand Up @@ -322,12 +320,49 @@ const (
FileSetIndexContentType
)

// SeriesMetadataLifeTime describes the memory life time type.
type SeriesMetadataLifeTime int

const (
// SeriesMetadataLifeTimeLongLived means the underlying memory's life time is long lived and exceeds
// the execution duration of the series metadata receiver.
SeriesMetadataLifeTimeLongLived SeriesMetadataLifeTime = iota
// SeriesMetadataLifeTimeShortLived means that the underlying memory is only valid for the duration
// of the OnFlushNewSeries call. Must clone the underlying bytes in order to extend the life time.
SeriesMetadataLifeTimeShortLived
)

// SeriesMetadataType describes the type of series metadata.
type SeriesMetadataType int

const (
// SeriesDocumentType means the metadata is in doc.Document form.
SeriesDocumentType SeriesMetadataType = iota
// SeriesIDAndEncodedTagsType means the metadata is in IDAndEncodedTags form.
SeriesIDAndEncodedTagsType
)

// IDAndEncodedTags contains a series ID and encoded tags.
type IDAndEncodedTags struct {
ID []byte
EncodedTags []byte
}

// SeriesMetadata captures different representations of series metadata and
// the ownership status of the underlying memory.
type SeriesMetadata struct {
Type SeriesMetadataType
LifeTime SeriesMetadataLifeTime
Document doc.Document
IDAndEncodedTags IDAndEncodedTags
}

// OnFlushNewSeriesEvent is the fields related to a flush of a new series.
type OnFlushNewSeriesEvent struct {
Shard uint32
BlockStart time.Time
FirstWrite time.Time
SeriesMetadata doc.Document
SeriesMetadata SeriesMetadata
}

// OnFlushSeries performs work on a per series level.
Expand Down

0 comments on commit b749b66

Please sign in to comment.