Skip to content

Commit

Permalink
chore(dtaobj): add test for cleaning up metadata columns between buff…
Browse files Browse the repository at this point in the history
…er flushes
  • Loading branch information
rfratto committed Jan 22, 2025
1 parent cdaf279 commit 23d758b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
6 changes: 0 additions & 6 deletions pkg/dataobj/internal/sections/logs/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package logs
import (
"cmp"
"fmt"
"iter"
"slices"

"github.com/grafana/loki/v3/pkg/dataobj/internal/dataset"
Expand Down Expand Up @@ -139,11 +138,6 @@ func (b *tableBuffer) Metadata(key string, pageSize int, compressionOpts dataset
return col
}

// MetadataIter returns an iterator over the metadata columns.
func (b *tableBuffer) MetadataIter() iter.Seq2[int, *dataset.ColumnBuilder] {
return slices.All(b.metadatas)
}

// Reset resets the buffer to its initial state.
func (b *tableBuffer) Reset() {
if b.streamID != nil {
Expand Down
35 changes: 35 additions & 0 deletions pkg/dataobj/internal/sections/logs/table_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package logs

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/grafana/loki/v3/pkg/dataobj/internal/dataset"
)

func Test_table_metadataCleanup(t *testing.T) {
var buf tableBuffer
initBuffer(&buf)

_ = buf.Metadata("foo", 1024, dataset.CompressionOptions{})
_ = buf.Metadata("bar", 1024, dataset.CompressionOptions{})

table, err := buf.Flush()
require.NoError(t, err)
require.Equal(t, 2, len(table.metadatas))

initBuffer(&buf)
_ = buf.Metadata("bar", 1024, dataset.CompressionOptions{})

table, err = buf.Flush()
require.NoError(t, err)
require.Equal(t, 1, len(table.metadatas))
require.Equal(t, "bar", table.metadatas[0].Info.Name)
}

func initBuffer(buf *tableBuffer) {
buf.StreamID(1024)
buf.Timestamp(1024)
buf.Message(1024, dataset.CompressionOptions{})
}

0 comments on commit 23d758b

Please sign in to comment.