@@ -15,7 +15,6 @@ package ingester
1515
1616import (
1717 "sync"
18- "time"
1918
2019 "github.com/prometheus/common/model"
2120
@@ -29,7 +28,7 @@ type fingerprintSeriesPair struct {
2928}
3029
3130// seriesMap maps fingerprints to memory series. All its methods are
32- // goroutine-safe. A SeriesMap is effectively is a goroutine-safe version of
31+ // goroutine-safe. A seriesMap is effectively is a goroutine-safe version of
3332// map[model.Fingerprint]*memorySeries.
3433type seriesMap struct {
3534 mtx sync.RWMutex
@@ -107,77 +106,26 @@ type memorySeries struct {
107106 metric model.Metric
108107 // Sorted by start time, overlapping chunk ranges are forbidden.
109108 chunkDescs []* chunk.Desc
110- // The index (within chunkDescs above) of the first chunk.Desc that
111- // points to a non-persisted chunk. If all chunks are persisted, then
112- // persistWatermark == len(chunkDescs).
113- persistWatermark int
114- // The modification time of the series file. The zero value of time.Time
115- // is used to mark an unknown modification time.
116- modTime time.Time
117- // The chunkDescs in memory might not have all the chunkDescs for the
118- // chunks that are persisted to disk. The missing chunkDescs are all
119- // contiguous and at the tail end. chunkDescsOffset is the index of the
120- // chunk on disk that corresponds to the first chunk.Desc in memory. If
121- // it is 0, the chunkDescs are all loaded. A value of -1 denotes a
122- // special case: There are chunks on disk, but the offset to the
123- // chunkDescs in memory is unknown. Also, in this special case, there is
124- // no overlap between chunks on disk and chunks in memory (implying that
125- // upon first persisting of a chunk in memory, the offset has to be
126- // set).
127- chunkDescsOffset int
128- // The savedFirstTime field is used as a fallback when the
129- // chunkDescsOffset is not 0. It can be used to save the FirstTime of the
130- // first chunk before its chunk desc is evicted. In doubt, this field is
131- // just set to the oldest possible timestamp.
132- savedFirstTime model.Time
133- // The timestamp of the last sample in this series. Needed for fast
134- // access for federation and to ensure timestamp monotonicity during
135- // ingestion.
109+ // The timestamp of the last sample in this series. Needed to
110+ // ensure timestamp monotonicity during ingestion.
136111 lastTime model.Time
137- // The last ingested sample value. Needed for fast access for
138- // federation .
112+ // The value of the last sample in this series. Needed to
113+ // ensure timestamp monotonicity during ingestion .
139114 lastSampleValue model.SampleValue
140115 // Whether lastSampleValue has been set already.
141116 lastSampleValueSet bool
142117 // Whether the current head chunk has already been finished. If true,
143118 // the current head chunk must not be modified anymore.
144119 headChunkClosed bool
145- // Whether the current head chunk is used by an iterator. In that case,
146- // a non-closed head chunk has to be cloned before more samples are
147- // appended.
148- headChunkUsedByIterator bool
149- // Whether the series is inconsistent with the last checkpoint in a way
150- // that would require a disk seek during crash recovery.
151- dirty bool
152120}
153121
154122// newMemorySeries returns a pointer to a newly allocated memorySeries for the
155- // given metric. chunkDescs and modTime in the new series are set according to
156- // the provided parameters. chunkDescs can be nil or empty if this is a
157- // genuinely new time series (i.e. not one that is being unarchived). In that
158- // case, headChunkClosed is set to false, and firstTime and lastTime are both
159- // set to model.Earliest. The zero value for modTime can be used if the
160- // modification time of the series file is unknown (e.g. if this is a genuinely
161- // new series).
162- func newMemorySeries (m model.Metric , chunkDescs []* chunk.Desc , modTime time.Time ) (* memorySeries , error ) {
163- var err error
164- firstTime := model .Earliest
165- lastTime := model .Earliest
166- if len (chunkDescs ) > 0 {
167- firstTime = chunkDescs [0 ].FirstTime ()
168- if lastTime , err = chunkDescs [len (chunkDescs )- 1 ].LastTime (); err != nil {
169- return nil , err
170- }
171- }
123+ // given metric.
124+ func newMemorySeries (m model.Metric ) * memorySeries {
172125 return & memorySeries {
173- metric : m ,
174- chunkDescs : chunkDescs ,
175- headChunkClosed : len (chunkDescs ) > 0 ,
176- savedFirstTime : firstTime ,
177- lastTime : lastTime ,
178- persistWatermark : len (chunkDescs ),
179- modTime : modTime ,
180- }, nil
126+ metric : m ,
127+ lastTime : model .Earliest ,
128+ }
181129}
182130
183131// add adds a sample pair to the series. It returns the number of newly
@@ -189,21 +137,6 @@ func (s *memorySeries) add(v model.SamplePair) (int, error) {
189137 newHead := chunk .NewDesc (chunk .New (), v .Timestamp )
190138 s .chunkDescs = append (s .chunkDescs , newHead )
191139 s .headChunkClosed = false
192- } else if s .headChunkUsedByIterator && s .head ().RefCount () > 1 {
193- // We only need to clone the head chunk if the current head
194- // chunk was used in an iterator at all and if the refCount is
195- // still greater than the 1 we always have because the head
196- // chunk is not yet persisted. The latter is just an
197- // approximation. We will still clone unnecessarily if an older
198- // iterator using a previous version of the head chunk is still
199- // around and keep the head chunk pinned. We needed to track
200- // pins by version of the head chunk, which is probably not
201- // worth the effort.
202- chunk .Ops .WithLabelValues (chunk .Clone ).Inc ()
203- // No locking needed here because a non-persisted head chunk can
204- // not get evicted concurrently.
205- s .head ().C = s .head ().C .Clone ()
206- s .headChunkUsedByIterator = false
207140 }
208141
209142 chunks , err := s .head ().Add (v )
@@ -233,13 +166,3 @@ func (s *memorySeries) add(v model.SamplePair) (int, error) {
233166func (s * memorySeries ) head () * chunk.Desc {
234167 return s .chunkDescs [len (s .chunkDescs )- 1 ]
235168}
236-
237- // firstTime returns the timestamp of the first sample in the series.
238- //
239- // The caller must have locked the fingerprint of the memorySeries.
240- func (s * memorySeries ) firstTime () model.Time {
241- if s .chunkDescsOffset == 0 && len (s .chunkDescs ) > 0 {
242- return s .chunkDescs [0 ].FirstTime ()
243- }
244- return s .savedFirstTime
245- }
0 commit comments