@ -224,7 +224,7 @@ func BenchmarkLoadWAL(b *testing.B) {
require . NoError ( b , err )
for k := 0 ; k < c . batches * c . seriesPerBatch ; k ++ {
// Create one mmapped chunk per series, with one sample at the given time.
s := newMemSeries ( labels . Labels { } , chunks . HeadSeriesRef ( k ) * 101 , c . mmappedChunkT , nil , defaultIsolationDisabled )
s := newMemSeries ( labels . Labels { } , chunks . HeadSeriesRef ( k ) * 101 , c . mmappedChunkT , defaultIsolationDisabled )
s . append ( c . mmappedChunkT , 42 , 0 , chunkDiskMapper )
s . mmapCurrentHeadChunk ( chunkDiskMapper )
}
@ -515,11 +515,11 @@ func TestHead_ReadWAL(t *testing.T) {
require . NoError ( t , c . Err ( ) )
return x
}
require . Equal ( t , [ ] sample { { 100 , 2 } , { 101 , 5 } } , expandChunk ( s10 . iterator ( 0 , nil , head . chunkDiskMapper , nil ) ) )
require . Equal ( t , [ ] sample { { 101 , 6 } } , expandChunk ( s50 . iterator ( 0 , nil , head . chunkDiskMapper , nil ) ) )
require . Equal ( t , [ ] sample { { 100 , 2 } , { 101 , 5 } } , expandChunk ( s10 . iterator ( 0 , nil , head . chunkDiskMapper , nil , nil ) ) )
require . Equal ( t , [ ] sample { { 101 , 6 } } , expandChunk ( s50 . iterator ( 0 , nil , head . chunkDiskMapper , nil , nil ) ) )
// The samples before the new series record should be discarded since a duplicate record
// is only possible when old samples were compacted.
require . Equal ( t , [ ] sample { { 101 , 7 } } , expandChunk ( s100 . iterator ( 0 , nil , head . chunkDiskMapper , nil ) ) )
require . Equal ( t , [ ] sample { { 101 , 7 } } , expandChunk ( s100 . iterator ( 0 , nil , head . chunkDiskMapper , nil , nil ) ) )
q , err := head . ExemplarQuerier ( context . Background ( ) )
require . NoError ( t , err )
@ -733,7 +733,7 @@ func TestMemSeries_truncateChunks(t *testing.T) {
} ,
}
s := newMemSeries ( labels . FromStrings ( "a" , "b" ) , 1 , 2000 , & memChunkPool , defaultIsolationDisabled )
s := newMemSeries ( labels . FromStrings ( "a" , "b" ) , 1 , 2000 , defaultIsolationDisabled )
for i := 0 ; i < 4000 ; i += 5 {
ok , _ := s . append ( int64 ( i ) , float64 ( i ) , 0 , chunkDiskMapper )
@ -744,31 +744,31 @@ func TestMemSeries_truncateChunks(t *testing.T) {
// that the ID of the last chunk still gives us the same chunk afterwards.
countBefore := len ( s . mmappedChunks ) + 1 // +1 for the head chunk.
lastID := s . headChunkID ( countBefore - 1 )
lastChunk , _ , err := s . chunk ( lastID , chunkDiskMapper )
lastChunk , _ , err := s . chunk ( lastID , chunkDiskMapper , & memChunkPool )
require . NoError ( t , err )
require . NotNil ( t , lastChunk )
chk , _ , err := s . chunk ( 0 , chunkDiskMapper )
chk , _ , err := s . chunk ( 0 , chunkDiskMapper , & memChunkPool )
require . NotNil ( t , chk )
require . NoError ( t , err )
s . truncateChunksBefore ( 2000 )
require . Equal ( t , int64 ( 2000 ) , s . mmappedChunks [ 0 ] . minTime )
_ , _ , err = s . chunk ( 0 , chunkDiskMapper )
_ , _ , err = s . chunk ( 0 , chunkDiskMapper , & memChunkPool )
require . Equal ( t , storage . ErrNotFound , err , "first chunks not gone" )
require . Equal ( t , countBefore / 2 , len ( s . mmappedChunks ) + 1 ) // +1 for the head chunk.
chk , _ , err = s . chunk ( lastID , chunkDiskMapper )
chk , _ , err = s . chunk ( lastID , chunkDiskMapper , & memChunkPool )
require . NoError ( t , err )
require . Equal ( t , lastChunk , chk )
// Validate that the series' sample buffer is applied correctly to the last chunk
// after truncation.
it1 := s . iterator ( s . headChunkID ( len ( s . mmappedChunks ) ) , nil , chunkDiskMapper , nil )
it1 := s . iterator ( s . headChunkID ( len ( s . mmappedChunks ) ) , nil , chunkDiskMapper , & memChunkPool , nil )
_ , ok := it1 . ( * memSafeIterator )
require . True ( t , ok )
it2 := s . iterator ( s . headChunkID ( len ( s . mmappedChunks ) - 1 ) , nil , chunkDiskMapper , nil )
it2 := s . iterator ( s . headChunkID ( len ( s . mmappedChunks ) - 1 ) , nil , chunkDiskMapper , & memChunkPool , nil )
_ , ok = it2 . ( * memSafeIterator )
require . False ( t , ok , "non-last chunk incorrectly wrapped with sample buffer" )
}
@ -1271,7 +1271,7 @@ func TestMemSeries_append(t *testing.T) {
require . NoError ( t , chunkDiskMapper . Close ( ) )
} ( )
s := newMemSeries ( labels . Labels { } , 1 , 500 , nil , defaultIsolationDisabled )
s := newMemSeries ( labels . Labels { } , 1 , 500 , defaultIsolationDisabled )
// Add first two samples at the very end of a chunk range and the next two
// on and after it.
@ -1325,7 +1325,7 @@ func TestMemSeries_append_atVariableRate(t *testing.T) {
require . NoError ( t , chunkDiskMapper . Close ( ) )
} )
s := newMemSeries ( labels . Labels { } , 1 , DefaultBlockDuration , nil , defaultIsolationDisabled )
s := newMemSeries ( labels . Labels { } , 1 , DefaultBlockDuration , defaultIsolationDisabled )
// At this slow rate, we will fill the chunk in two block durations.
slowRate := ( DefaultBlockDuration * 2 ) / samplesPerChunk
@ -2483,14 +2483,14 @@ func TestMemSafeIteratorSeekIntoBuffer(t *testing.T) {
require . NoError ( t , chunkDiskMapper . Close ( ) )
} ( )
s := newMemSeries ( labels . Labels { } , 1 , 500 , nil , defaultIsolationDisabled )
s := newMemSeries ( labels . Labels { } , 1 , 500 , defaultIsolationDisabled )
for i := 0 ; i < 7 ; i ++ {
ok , _ := s . append ( int64 ( i ) , float64 ( i ) , 0 , chunkDiskMapper )
require . True ( t , ok , "sample append failed" )
}
it := s . iterator ( s . headChunkID ( len ( s . mmappedChunks ) ) , nil , chunkDiskMapper , nil )
it := s . iterator ( s . headChunkID ( len ( s . mmappedChunks ) ) , nil , chunkDiskMapper , nil , nil )
_ , ok := it . ( * memSafeIterator )
require . True ( t , ok )