From b749b66a96359f3d984a92ca3dbfa1a0784e5ed5 Mon Sep 17 00:00:00 2001 From: Bo Du Date: Fri, 20 Nov 2020 00:14:15 -0500 Subject: [PATCH] Extend the on flush new series event to account for differing types of series metadata and memory lifetimes. --- src/dbnode/persist/fs/merger.go | 13 +++++++--- src/dbnode/persist/types.go | 43 ++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/dbnode/persist/fs/merger.go b/src/dbnode/persist/fs/merger.go index 555bbcc6d8..b3fc9f2e6d 100644 --- a/src/dbnode/persist/fs/merger.go +++ b/src/dbnode/persist/fs/merger.go @@ -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, + }, }) } diff --git a/src/dbnode/persist/types.go b/src/dbnode/persist/types.go index f93f28bb56..dc18d7d319 100644 --- a/src/dbnode/persist/types.go +++ b/src/dbnode/persist/types.go @@ -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. @@ -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.