This repository was archived by the owner on Aug 23, 2023. It is now read-only.
File tree 3 files changed +16
-5
lines changed
3 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -339,6 +339,8 @@ func (a *AggMetric) addAggregators(ts uint32, val float64) {
339
339
}
340
340
}
341
341
342
+ // pushToCache adds the chunk into the cache if it is hot
343
+ // assumes lock held by caller
342
344
func (a * AggMetric ) pushToCache (c * chunk.Chunk ) {
343
345
if a .cachePusher == nil {
344
346
return
@@ -348,14 +350,14 @@ func (a *AggMetric) pushToCache(c *chunk.Chunk) {
348
350
if a .Key .Archive != 0 {
349
351
intervalHint = a .Key .Archive .Span ()
350
352
}
351
- go a .cachePusher .AddIfHot (
352
- a .Key ,
353
- 0 ,
354
- chunk .NewBareIterGen (c .T0 , intervalHint , c .Encode (a .ChunkSpan )),
355
- )
353
+
354
+ itergen := chunk .NewBareIterGen (c .Series .T0 , intervalHint , c .Encode (a .ChunkSpan ))
355
+ go a .cachePusher .AddIfHot (a .Key , 0 , itergen )
356
356
}
357
357
358
358
// write a chunk to persistent storage. This should only be called while holding a.Lock()
359
+ // never persist a chunk that may receive further updates!
360
+ // (because the stores will read out chunk data on the unlocked chunk)
359
361
func (a * AggMetric ) persist (pos int ) {
360
362
chunk := a .Chunks [pos ]
361
363
pre := time .Now ()
Original file line number Diff line number Diff line change @@ -9,6 +9,13 @@ import (
9
9
)
10
10
11
11
// Chunk is a chunk of data. not concurrency safe.
12
+ // last check that the methods are being called safely by Dieter on 20/11/2018
13
+ // checked: String, Push, Finish, Encode
14
+ // for the most part, confirming serialized access is easy by tracking all callers.
15
+ // The main exception is the ChunkWriteRequest mechanism. any CWR created is processed
16
+ // "later", and chunk data (the series, etc) will be accessed via Encode() and reads of
17
+ // some of the members. But it can be proven
18
+ // that we only call NewChunkWriteRequest() on chunks that are no longer being modified.
12
19
type Chunk struct {
13
20
Series tsz.SeriesLong
14
21
NumPoints uint32
@@ -48,6 +55,7 @@ func (c *Chunk) Finish() {
48
55
// Encode encodes the chunk
49
56
// note: chunks don't know their own span, the caller/owner manages that,
50
57
// so for formats that encode it, it needs to be passed in.
58
+ // the returned value contains no references to the chunk. data is copied.
51
59
func (c * Chunk ) Encode (span uint32 ) []byte {
52
60
return encode (span , FormatGoTszLongWithSpan , c .Series .Bytes ())
53
61
}
Original file line number Diff line number Diff line change 7
7
)
8
8
9
9
// encode is a helper function to encode a chunk of data into various formats
10
+ // input data is copied
10
11
func encode (span uint32 , format Format , data []byte ) []byte {
11
12
switch format {
12
13
case FormatStandardGoTszWithSpan , FormatGoTszLongWithSpan :
You can’t perform that action at this time.
0 commit comments