@ -229,8 +229,8 @@ 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 , 1 , defaultIsolationDisabled )
s . append ( c . mmappedChunkT , 42 , 0 , chunkDiskMapper )
s := newMemSeries ( labels . Labels { } , chunks . HeadSeriesRef ( k ) * 101 , defaultIsolationDisabled )
s . append ( c . mmappedChunkT , 42 , 0 , chunkDiskMapper , c . mmappedChunkT )
s . mmapCurrentHeadChunk ( chunkDiskMapper )
}
require . NoError ( b , chunkDiskMapper . Close ( ) )
@ -731,6 +731,7 @@ func TestMemSeries_truncateChunks(t *testing.T) {
defer func ( ) {
require . NoError ( t , chunkDiskMapper . Close ( ) )
} ( )
const chunkRange = 2000
memChunkPool := sync . Pool {
New : func ( ) interface { } {
@ -738,10 +739,10 @@ func TestMemSeries_truncateChunks(t *testing.T) {
} ,
}
s := newMemSeries ( labels . FromStrings ( "a" , "b" ) , 1 , 2000 , 1 , defaultIsolationDisabled )
s := newMemSeries ( labels . FromStrings ( "a" , "b" ) , 1 , defaultIsolationDisabled )
for i := 0 ; i < 4000 ; i += 5 {
ok , _ := s . append ( int64 ( i ) , float64 ( i ) , 0 , chunkDiskMapper )
ok , _ := s . append ( int64 ( i ) , float64 ( i ) , 0 , chunkDiskMapper , chunkRange )
require . True ( t , ok , "sample append failed" )
}
@ -1276,25 +1277,26 @@ func TestMemSeries_append(t *testing.T) {
defer func ( ) {
require . NoError ( t , chunkDiskMapper . Close ( ) )
} ( )
const chunkRange = 500
s := newMemSeries ( labels . Labels { } , 1 , 500 , 1 , defaultIsolationDisabled )
s := newMemSeries ( labels . Labels { } , 1 , defaultIsolationDisabled )
// Add first two samples at the very end of a chunk range and the next two
// on and after it.
// New chunk must correctly be cut at 1000.
ok , chunkCreated := s . append ( 998 , 1 , 0 , chunkDiskMapper )
ok , chunkCreated := s . append ( 998 , 1 , 0 , chunkDiskMapper , chunkRange )
require . True ( t , ok , "append failed" )
require . True ( t , chunkCreated , "first sample created chunk" )
ok , chunkCreated = s . append ( 999 , 2 , 0 , chunkDiskMapper )
ok , chunkCreated = s . append ( 999 , 2 , 0 , chunkDiskMapper , chunkRange )
require . True ( t , ok , "append failed" )
require . False ( t , chunkCreated , "second sample should use same chunk" )
ok , chunkCreated = s . append ( 1000 , 3 , 0 , chunkDiskMapper )
ok , chunkCreated = s . append ( 1000 , 3 , 0 , chunkDiskMapper , chunkRange )
require . True ( t , ok , "append failed" )
require . True ( t , chunkCreated , "expected new chunk on boundary" )
ok , chunkCreated = s . append ( 1001 , 4 , 0 , chunkDiskMapper )
ok , chunkCreated = s . append ( 1001 , 4 , 0 , chunkDiskMapper , chunkRange )
require . True ( t , ok , "append failed" )
require . False ( t , chunkCreated , "second sample should use same chunk" )
@ -1307,7 +1309,7 @@ func TestMemSeries_append(t *testing.T) {
// Fill the range [1000,2000) with many samples. Intermediate chunks should be cut
// at approximately 120 samples per chunk.
for i := 1 ; i < 1000 ; i ++ {
ok , _ := s . append ( 1001 + int64 ( i ) , float64 ( i ) , 0 , chunkDiskMapper )
ok , _ := s . append ( 1001 + int64 ( i ) , float64 ( i ) , 0 , chunkDiskMapper , chunkRange )
require . True ( t , ok , "append failed" )
}
@ -1330,8 +1332,9 @@ func TestMemSeries_append_atVariableRate(t *testing.T) {
t . Cleanup ( func ( ) {
require . NoError ( t , chunkDiskMapper . Close ( ) )
} )
chunkRange := DefaultBlockDuration
s := newMemSeries ( labels . Labels { } , 1 , DefaultBlockDuration , 0 , defaultIsolationDisabled )
s := newMemSeries ( labels . Labels { } , 1 , defaultIsolationDisabled )
// At this slow rate, we will fill the chunk in two block durations.
slowRate := ( DefaultBlockDuration * 2 ) / samplesPerChunk
@ -1339,7 +1342,7 @@ func TestMemSeries_append_atVariableRate(t *testing.T) {
var nextTs int64
var totalAppendedSamples int
for i := 0 ; i < samplesPerChunk / 4 ; i ++ {
ok , _ := s . append ( nextTs , float64 ( i ) , 0 , chunkDiskMapper )
ok , _ := s . append ( nextTs , float64 ( i ) , 0 , chunkDiskMapper , chunkRange )
require . Truef ( t , ok , "slow sample %d was not appended" , i )
nextTs += slowRate
totalAppendedSamples ++
@ -1348,12 +1351,12 @@ func TestMemSeries_append_atVariableRate(t *testing.T) {
// Suddenly, the rate increases and we receive a sample every millisecond.
for i := 0 ; i < math . MaxUint16 ; i ++ {
ok , _ := s . append ( nextTs , float64 ( i ) , 0 , chunkDiskMapper )
ok , _ := s . append ( nextTs , float64 ( i ) , 0 , chunkDiskMapper , chunkRange )
require . Truef ( t , ok , "quick sample %d was not appended" , i )
nextTs ++
totalAppendedSamples ++
}
ok , chunkCreated := s . append ( DefaultBlockDuration , float64 ( 0 ) , 0 , chunkDiskMapper )
ok , chunkCreated := s . append ( DefaultBlockDuration , float64 ( 0 ) , 0 , chunkDiskMapper , chunkRange )
require . True ( t , ok , "new chunk sample was not appended" )
require . True ( t , chunkCreated , "sample at block duration timestamp should create a new chunk" )
@ -1367,7 +1370,8 @@ func TestMemSeries_append_atVariableRate(t *testing.T) {
func TestGCChunkAccess ( t * testing . T ) {
// Put a chunk, select it. GC it and then access it.
h , _ := newTestHead ( t , 1000 , false , false )
const chunkRange = 1000
h , _ := newTestHead ( t , chunkRange , false , false )
defer func ( ) {
require . NoError ( t , h . Close ( ) )
} ( )
@ -1377,18 +1381,18 @@ func TestGCChunkAccess(t *testing.T) {
s , _ , _ := h . getOrCreate ( 1 , labels . FromStrings ( "a" , "1" ) )
// Appending 2 samples for the first chunk.
ok , chunkCreated := s . append ( 0 , 0 , 0 , h . chunkDiskMapper )
ok , chunkCreated := s . append ( 0 , 0 , 0 , h . chunkDiskMapper , chunkRange )
require . True ( t , ok , "series append failed" )
require . True ( t , chunkCreated , "chunks was not created" )
ok , chunkCreated = s . append ( 999 , 999 , 0 , h . chunkDiskMapper )
ok , chunkCreated = s . append ( 999 , 999 , 0 , h . chunkDiskMapper , chunkRange )
require . True ( t , ok , "series append failed" )
require . False ( t , chunkCreated , "chunks was created" )
// A new chunks should be created here as it's beyond the chunk range.
ok , chunkCreated = s . append ( 1000 , 1000 , 0 , h . chunkDiskMapper )
ok , chunkCreated = s . append ( 1000 , 1000 , 0 , h . chunkDiskMapper , chunkRange )
require . True ( t , ok , "series append failed" )
require . True ( t , chunkCreated , "chunks was not created" )
ok , chunkCreated = s . append ( 1999 , 1999 , 0 , h . chunkDiskMapper )
ok , chunkCreated = s . append ( 1999 , 1999 , 0 , h . chunkDiskMapper , chunkRange )
require . True ( t , ok , "series append failed" )
require . False ( t , chunkCreated , "chunks was created" )
@ -1419,7 +1423,8 @@ func TestGCChunkAccess(t *testing.T) {
func TestGCSeriesAccess ( t * testing . T ) {
// Put a series, select it. GC it and then access it.
h , _ := newTestHead ( t , 1000 , false , false )
const chunkRange = 1000
h , _ := newTestHead ( t , chunkRange , false , false )
defer func ( ) {
require . NoError ( t , h . Close ( ) )
} ( )
@ -1429,18 +1434,18 @@ func TestGCSeriesAccess(t *testing.T) {
s , _ , _ := h . getOrCreate ( 1 , labels . FromStrings ( "a" , "1" ) )
// Appending 2 samples for the first chunk.
ok , chunkCreated := s . append ( 0 , 0 , 0 , h . chunkDiskMapper )
ok , chunkCreated := s . append ( 0 , 0 , 0 , h . chunkDiskMapper , chunkRange )
require . True ( t , ok , "series append failed" )
require . True ( t , chunkCreated , "chunks was not created" )
ok , chunkCreated = s . append ( 999 , 999 , 0 , h . chunkDiskMapper )
ok , chunkCreated = s . append ( 999 , 999 , 0 , h . chunkDiskMapper , chunkRange )
require . True ( t , ok , "series append failed" )
require . False ( t , chunkCreated , "chunks was created" )
// A new chunks should be created here as it's beyond the chunk range.
ok , chunkCreated = s . append ( 1000 , 1000 , 0 , h . chunkDiskMapper )
ok , chunkCreated = s . append ( 1000 , 1000 , 0 , h . chunkDiskMapper , chunkRange )
require . True ( t , ok , "series append failed" )
require . True ( t , chunkCreated , "chunks was not created" )
ok , chunkCreated = s . append ( 1999 , 1999 , 0 , h . chunkDiskMapper )
ok , chunkCreated = s . append ( 1999 , 1999 , 0 , h . chunkDiskMapper , chunkRange )
require . True ( t , ok , "series append failed" )
require . False ( t , chunkCreated , "chunks was created" )
@ -1676,10 +1681,10 @@ func TestHeadReadWriterRepair(t *testing.T) {
require . True ( t , created , "series was not created" )
for i := 0 ; i < 7 ; i ++ {
ok , chunkCreated := s . append ( int64 ( i * chunkRange ) , float64 ( i * chunkRange ) , 0 , h . chunkDiskMapper )
ok , chunkCreated := s . append ( int64 ( i * chunkRange ) , float64 ( i * chunkRange ) , 0 , h . chunkDiskMapper , chunkRange )
require . True ( t , ok , "series append failed" )
require . True ( t , chunkCreated , "chunk was not created" )
ok , chunkCreated = s . append ( int64 ( i * chunkRange ) + chunkRange - 1 , float64 ( i * chunkRange ) , 0 , h . chunkDiskMapper )
ok , chunkCreated = s . append ( int64 ( i * chunkRange ) + chunkRange - 1 , float64 ( i * chunkRange ) , 0 , h . chunkDiskMapper , chunkRange )
require . True ( t , ok , "series append failed" )
require . False ( t , chunkCreated , "chunk was created" )
h . chunkDiskMapper . CutNewFile ( )
@ -2027,7 +2032,7 @@ func TestIsolationAppendIDZeroIsNoop(t *testing.T) {
s , _ , _ := h . getOrCreate ( 1 , labels . FromStrings ( "a" , "1" ) )
ok , _ := s . append ( 0 , 0 , 0 , h . chunkDiskMapper )
ok , _ := s . append ( 0 , 0 , 0 , h . chunkDiskMapper , h . chunkRange . Load ( ) )
require . True ( t , ok , "Series append failed." )
require . Equal ( t , 0 , s . txs . txIDCount , "Series should not have an appendID after append with appendID=0." )
}
@ -2489,11 +2494,12 @@ func TestMemSafeIteratorSeekIntoBuffer(t *testing.T) {
defer func ( ) {
require . NoError ( t , chunkDiskMapper . Close ( ) )
} ( )
const chunkRange = 500
s := newMemSeries ( labels . Labels { } , 1 , 500 , 1 , defaultIsolationDisabled )
s := newMemSeries ( labels . Labels { } , 1 , defaultIsolationDisabled )
for i := 0 ; i < 7 ; i ++ {
ok , _ := s . append ( int64 ( i ) , float64 ( i ) , 0 , chunkDiskMapper )
ok , _ := s . append ( int64 ( i ) , float64 ( i ) , 0 , chunkDiskMapper , chunkRange )
require . True ( t , ok , "sample append failed" )
}