From 69da018f28c156fa37cfd80ee23ad7dc0ce6842f Mon Sep 17 00:00:00 2001 From: Souvik Biswas Date: Thu, 26 Nov 2026 10:29:32 +0530 Subject: [PATCH 1/3] Compactor: skip parquet converter files when downloading blocks The parquet converter writes its output under the same object prefix as the TSDB block, along with parquet-converter-mark.json. block.Download lists and downloads everything under that prefix and has no allowlist or filter for these files, so the compactor pulled *.parquet files and the marker onto local disk even though compaction only reads the index and chunks. block.Download is vendored Thanos code and builds its own ignore list, so the filter cannot be passed in from here. Wrap the per-tenant bucket used for compaction so that parquet files and the converter marker are hidden from Iter and IterWithAttributes. Reads, uploads and deletes are unchanged, and the blocks cleaner keeps using the unwrapped bucket, so it still sees and deletes these files with the block. Fixes #7967 Signed-off-by: Souvik Biswas --- CHANGELOG.md | 1 + pkg/compactor/compactor.go | 2 +- pkg/compactor/parquet_filtered_bucket.go | 67 ++++++++ pkg/compactor/parquet_filtered_bucket_test.go | 144 ++++++++++++++++++ 4 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 pkg/compactor/parquet_filtered_bucket.go create mode 100644 pkg/compactor/parquet_filtered_bucket_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index afad9d19f4..689971bfa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ * [BUGFIX] Ring: Ignore READONLY ingesters when assigning tokens so the active series remain balanced. #7946 * [BUGFIX] Distributor: Fix a `panic: send on closed channel` crash during shutdown when `-distributor.num-push-workers` or `-distributor.num-query-workers` is greater than 0. #7964 * [BUGFIX] Ring: Fix `DoBatch` counting a key more than once when more replicas than the quorum succeed, which in rare cases could hide a write error from a key that did not reach quorum. A distributor push now always waits until every series reaches quorum, so it returns the error of a series that misses quorum, and takes as long as its slowest series to reach quorum. #7975 +* [BUGFIX] Compactor: Stop downloading the parquet files and the `parquet-converter-mark.json` marker written by the parquet converter under a block's prefix. Compaction never reads them, so they only used local disk and bandwidth until the compaction job ended. #7972 ## 1.22.0 2026-11-19 diff --git a/pkg/compactor/compactor.go b/pkg/compactor/compactor.go index 123327911d..33f7c1ebce 100644 --- a/pkg/compactor/compactor.go +++ b/pkg/compactor/compactor.go @@ -1022,7 +1022,7 @@ func (c *Compactor) compactUserWithRetries(ctx context.Context, userID string) e } func (c *Compactor) compactUser(ctx context.Context, userID string) error { - bucket := bucket.NewUserBucketClient(userID, c.bucketClient, c.limits) + bucket := newParquetFilteredBucket(bucket.NewUserBucketClient(userID, c.bucketClient, c.limits)) reg := prometheus.NewRegistry() diff --git a/pkg/compactor/parquet_filtered_bucket.go b/pkg/compactor/parquet_filtered_bucket.go new file mode 100644 index 0000000000..1a1147b2ef --- /dev/null +++ b/pkg/compactor/parquet_filtered_bucket.go @@ -0,0 +1,67 @@ +package compactor + +import ( + "context" + "path" + "strings" + + "github.com/thanos-io/objstore" + + cortex_parquet "github.com/cortexproject/cortex/pkg/storage/parquet" +) + +// parquetFileSuffix is the extension of the parquet files written by the parquet converter. +const parquetFileSuffix = ".parquet" + +// parquetFilteredBucket hides the files produced by the parquet converter from +// listings. The converter writes them under the same prefix as the TSDB block, +// and block.Download lists and downloads everything under that prefix, although +// compaction never reads them. Only listings are filtered: reads, uploads and +// deletes behave as usual. +type parquetFilteredBucket struct { + objstore.Bucket +} + +// newParquetFilteredBucket wraps the bucket used for compaction so that parquet +// files and the parquet converter marker are not listed. +func newParquetFilteredBucket(b objstore.InstrumentedBucket) objstore.InstrumentedBucket { + return &parquetFilteredBucket{Bucket: b} +} + +func isParquetObject(name string) bool { + if strings.HasSuffix(name, objstore.DirDelim) { + return false + } + return strings.HasSuffix(name, parquetFileSuffix) || path.Base(name) == cortex_parquet.ConverterMarkerFileName +} + +func (b *parquetFilteredBucket) Iter(ctx context.Context, dir string, f func(name string) error, options ...objstore.IterOption) error { + return b.Bucket.Iter(ctx, dir, func(name string) error { + if isParquetObject(name) { + return nil + } + return f(name) + }, options...) +} + +func (b *parquetFilteredBucket) IterWithAttributes(ctx context.Context, dir string, f func(attrs objstore.IterObjectAttributes) error, options ...objstore.IterOption) error { + return b.Bucket.IterWithAttributes(ctx, dir, func(attrs objstore.IterObjectAttributes) error { + if isParquetObject(attrs.Name) { + return nil + } + return f(attrs) + }, options...) +} + +// WithExpectedErrs keeps the filtering when the underlying bucket is re-wrapped. +func (b *parquetFilteredBucket) WithExpectedErrs(fn objstore.IsOpFailureExpectedFunc) objstore.Bucket { + if ib, ok := b.Bucket.(objstore.InstrumentedBucket); ok { + return &parquetFilteredBucket{Bucket: ib.WithExpectedErrs(fn)} + } + return b +} + +// ReaderWithExpectedErrs keeps the filtering when the underlying bucket is re-wrapped. +func (b *parquetFilteredBucket) ReaderWithExpectedErrs(fn objstore.IsOpFailureExpectedFunc) objstore.BucketReader { + return b.WithExpectedErrs(fn) +} diff --git a/pkg/compactor/parquet_filtered_bucket_test.go b/pkg/compactor/parquet_filtered_bucket_test.go new file mode 100644 index 0000000000..9314886598 --- /dev/null +++ b/pkg/compactor/parquet_filtered_bucket_test.go @@ -0,0 +1,144 @@ +package compactor + +import ( + "bytes" + "context" + "path/filepath" + "testing" + + "github.com/go-kit/log" + "github.com/oklog/ulid/v2" + "github.com/stretchr/testify/require" + "github.com/thanos-io/objstore" + "github.com/thanos-io/thanos/pkg/block" + "github.com/thanos-io/thanos/pkg/block/metadata" + + cortex_parquet "github.com/cortexproject/cortex/pkg/storage/parquet" +) + +var parquetTestFiles = []string{ + "0.labels.parquet", + "0.chunks.parquet", + "1.labels.parquet", + "nested/2.chunks.parquet", + cortex_parquet.ConverterMarkerFileName, +} + +func uploadBlockWithParquetFiles(t *testing.T, bkt objstore.Bucket, id ulid.ULID) { + t.Helper() + + var meta metadata.Meta + meta.ULID = id + meta.MinTime = 0 + meta.MaxTime = 1000 + meta.Version = metadata.TSDBVersion1 + meta.Thanos = metadata.Thanos{Version: metadata.ThanosVersion1, Source: metadata.TestSource} + var buf bytes.Buffer + require.NoError(t, meta.Write(&buf)) + + files := map[string][]byte{ + block.MetaFilename: buf.Bytes(), + block.IndexFilename: []byte("index"), + "chunks/000001": []byte("chunk"), + } + for _, name := range parquetTestFiles { + files[name] = []byte("parquet") + } + + for name, data := range files { + require.NoError(t, bkt.Upload(context.Background(), id.String()+"/"+name, bytes.NewReader(data))) + } +} + +func TestParquetFilteredBucket_Iter(t *testing.T) { + ctx := context.Background() + inmem := objstore.NewInMemBucket() + id := ulid.MustNew(1, nil) + uploadBlockWithParquetFiles(t, inmem, id) + + filtered := newParquetFilteredBucket(objstore.WithNoopInstr(inmem)) + + listRecursive := func(bkt objstore.BucketReader) []string { + var names []string + require.NoError(t, bkt.Iter(ctx, id.String(), func(name string) error { + names = append(names, name) + return nil + }, objstore.WithRecursiveIter())) + return names + } + + // Control: the unfiltered bucket lists the parquet files. + unfiltered := listRecursive(inmem) + for _, name := range parquetTestFiles { + require.Contains(t, unfiltered, id.String()+"/"+name) + } + + got := listRecursive(filtered) + for _, name := range parquetTestFiles { + require.NotContains(t, got, id.String()+"/"+name) + } + require.Contains(t, got, id.String()+"/"+block.MetaFilename) + require.Contains(t, got, id.String()+"/"+block.IndexFilename) + require.Contains(t, got, id.String()+"/chunks/000001") + + // Same behavior for IterWithAttributes. + var gotAttrs []string + require.NoError(t, filtered.IterWithAttributes(ctx, id.String(), func(attrs objstore.IterObjectAttributes) error { + gotAttrs = append(gotAttrs, attrs.Name) + return nil + }, objstore.WithRecursiveIter())) + for _, name := range parquetTestFiles { + require.NotContains(t, gotAttrs, id.String()+"/"+name) + } + require.Contains(t, gotAttrs, id.String()+"/"+block.IndexFilename) +} + +func TestParquetFilteredBucket_ReadsAreNotFiltered(t *testing.T) { + ctx := context.Background() + inmem := objstore.NewInMemBucket() + id := ulid.MustNew(1, nil) + uploadBlockWithParquetFiles(t, inmem, id) + + filtered := newParquetFilteredBucket(objstore.WithNoopInstr(inmem)) + + for _, name := range parquetTestFiles { + exists, err := filtered.Exists(ctx, id.String()+"/"+name) + require.NoError(t, err) + require.True(t, exists, name) + } + + // The filter survives re-wrapping for expected errors. + rewrapped := filtered.WithExpectedErrs(filtered.IsObjNotFoundErr) + var names []string + require.NoError(t, rewrapped.Iter(ctx, id.String(), func(name string) error { + names = append(names, name) + return nil + }, objstore.WithRecursiveIter())) + require.NotContains(t, names, id.String()+"/0.labels.parquet") + require.Contains(t, names, id.String()+"/"+block.IndexFilename) +} + +func TestParquetFilteredBucket_BlockDownloadSkipsParquetFiles(t *testing.T) { + ctx := context.Background() + inmem := objstore.NewInMemBucket() + id := ulid.MustNew(1, nil) + uploadBlockWithParquetFiles(t, inmem, id) + + // Control: downloading from the unfiltered bucket pulls the parquet files. + controlDir := t.TempDir() + require.NoError(t, block.Download(ctx, log.NewNopLogger(), inmem, id, controlDir)) + require.FileExists(t, filepath.Join(controlDir, "0.labels.parquet")) + require.FileExists(t, filepath.Join(controlDir, cortex_parquet.ConverterMarkerFileName)) + + filtered := newParquetFilteredBucket(objstore.WithNoopInstr(inmem)) + dst := t.TempDir() + require.NoError(t, block.Download(ctx, log.NewNopLogger(), filtered, id, dst)) + + require.FileExists(t, filepath.Join(dst, block.MetaFilename)) + require.FileExists(t, filepath.Join(dst, block.IndexFilename)) + require.FileExists(t, filepath.Join(dst, block.ChunksDirname, "000001")) + + for _, name := range parquetTestFiles { + require.NoFileExists(t, filepath.Join(dst, name)) + } +} From 30bb74b693de3fcbb51d8afdd9998a4b9de9ea52 Mon Sep 17 00:00:00 2001 From: Souvik Biswas Date: Thu, 26 Nov 2026 16:39:35 +0530 Subject: [PATCH 2/3] Compactor: also hide the no-convert marker and add a compactor-level test The parquet converter also writes parquet-no-convert-mark.json under the block prefix when it skips a block with too many label names. Hide it from listings together with the other parquet converter files. Add a compactor-level test: two real TSDB blocks plus parquet files and both markers in an in-memory bucket, run a compaction cycle, and assert that the index and chunks were read while no parquet file or marker was. Signed-off-by: Souvik Biswas --- CHANGELOG.md | 2 +- pkg/compactor/compactor_parquet_files_test.go | 139 ++++++++++++++++++ pkg/compactor/parquet_filtered_bucket.go | 7 +- pkg/compactor/parquet_filtered_bucket_test.go | 1 + 4 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 pkg/compactor/compactor_parquet_files_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 689971bfa2..4cebf7f928 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,7 +41,7 @@ * [BUGFIX] Ring: Ignore READONLY ingesters when assigning tokens so the active series remain balanced. #7946 * [BUGFIX] Distributor: Fix a `panic: send on closed channel` crash during shutdown when `-distributor.num-push-workers` or `-distributor.num-query-workers` is greater than 0. #7964 * [BUGFIX] Ring: Fix `DoBatch` counting a key more than once when more replicas than the quorum succeed, which in rare cases could hide a write error from a key that did not reach quorum. A distributor push now always waits until every series reaches quorum, so it returns the error of a series that misses quorum, and takes as long as its slowest series to reach quorum. #7975 -* [BUGFIX] Compactor: Stop downloading the parquet files and the `parquet-converter-mark.json` marker written by the parquet converter under a block's prefix. Compaction never reads them, so they only used local disk and bandwidth until the compaction job ended. #7972 +* [BUGFIX] Compactor: Stop downloading the parquet files and the `parquet-converter-mark.json` and `parquet-no-convert-mark.json` markers written by the parquet converter under a block's prefix. Compaction never reads them, so they only used local disk and bandwidth until the compaction job ended. #7972 ## 1.22.0 2026-11-19 diff --git a/pkg/compactor/compactor_parquet_files_test.go b/pkg/compactor/compactor_parquet_files_test.go new file mode 100644 index 0000000000..bc4cc3e564 --- /dev/null +++ b/pkg/compactor/compactor_parquet_files_test.go @@ -0,0 +1,139 @@ +package compactor + +import ( + "context" + "io" + "path" + "strings" + "sync" + "testing" + "time" + + "github.com/oklog/ulid/v2" + prom_testutil "github.com/prometheus/client_golang/prometheus/testutil" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + "github.com/thanos-io/objstore" + "github.com/thanos-io/thanos/pkg/block/metadata" + + cortex_parquet "github.com/cortexproject/cortex/pkg/storage/parquet" + "github.com/cortexproject/cortex/pkg/util/services" +) + +// bucketReadRecorder records the names of the objects read from a bucket. +type bucketReadRecorder struct { + mtx sync.Mutex + reads []string +} + +func (r *bucketReadRecorder) record(name string) { + r.mtx.Lock() + defer r.mtx.Unlock() + r.reads = append(r.reads, name) +} + +func (r *bucketReadRecorder) names() []string { + r.mtx.Lock() + defer r.mtx.Unlock() + return append([]string(nil), r.reads...) +} + +// readRecordingBucket records every object read through Get and GetRange. +type readRecordingBucket struct { + objstore.Bucket + rec *bucketReadRecorder +} + +func newReadRecordingBucket(b objstore.Bucket, rec *bucketReadRecorder) objstore.InstrumentedBucket { + return &readRecordingBucket{Bucket: b, rec: rec} +} + +func (b *readRecordingBucket) Get(ctx context.Context, name string) (io.ReadCloser, error) { + b.rec.record(name) + return b.Bucket.Get(ctx, name) +} + +func (b *readRecordingBucket) GetRange(ctx context.Context, name string, off, length int64) (io.ReadCloser, error) { + b.rec.record(name) + return b.Bucket.GetRange(ctx, name, off, length) +} + +func (b *readRecordingBucket) WithExpectedErrs(fn objstore.IsOpFailureExpectedFunc) objstore.Bucket { + if ib, ok := b.Bucket.(objstore.InstrumentedBucket); ok { + return &readRecordingBucket{Bucket: ib.WithExpectedErrs(fn), rec: b.rec} + } + return b +} + +func (b *readRecordingBucket) ReaderWithExpectedErrs(fn objstore.IsOpFailureExpectedFunc) objstore.BucketReader { + return b.WithExpectedErrs(fn) +} + +func TestCompactor_ShouldNotDownloadParquetFilesWhenCompacting(t *testing.T) { + rec := &bucketReadRecorder{} + bucketClient := newReadRecordingBucket(objstore.WithNoopInstr(objstore.NewInMemBucket()), rec) + + blocks := []ulid.ULID{ + createTSDBBlock(t, bucketClient, "user-1", 10, 20, map[string]string{"__name__": "Teste"}), + createTSDBBlock(t, bucketClient, "user-1", 20, 30, map[string]string{"__name__": "Teste"}), + } + + // Put the parquet converter output next to each block. + for _, id := range blocks { + for _, name := range parquetTestFiles { + require.NoError(t, bucketClient.Upload(context.Background(), path.Join("user-1", id.String(), name), strings.NewReader("parquet"))) + } + } + + c, tsdbCompactor, tsdbPlanner, _, _ := prepare(t, prepareConfig(), bucketClient, nil) + + // The TSDB compaction only runs once the blocks are on disk, so interrupt + // the run from there. + ctx, cancel := context.WithCancel(context.Background()) + tsdbCompactor.On("CompactWithBlockPopulator", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]ulid.ULID{}, context.Canceled).Run(func(args mock.Arguments) { + cancel() + }) + tsdbPlanner.On("Plan", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*metadata.Meta{ + { + ULID: blocks[0], + MinTime: 10, + MaxTime: 20, + }, + { + ULID: blocks[1], + MinTime: 20, + MaxTime: 30, + }, + }, nil) + + require.NoError(t, services.StartAndAwaitRunning(ctx, c)) + require.Eventually(t, func() bool { + return prom_testutil.ToFloat64(c.CompactionRunsInterrupted) == 1 + }, 20*time.Second, 50*time.Millisecond) + require.NoError(t, services.StopAndAwaitTerminated(context.Background(), c)) + + tsdbCompactor.AssertCalled(t, "CompactWithBlockPopulator", mock.Anything, mock.Anything, mock.Anything, mock.Anything) + + reads := rec.names() + + // The compaction inputs were really downloaded. + for _, id := range blocks { + prefix := path.Join("user-1", id.String()) + "/" + require.Contains(t, reads, prefix+"index") + + hasChunks := false + for _, name := range reads { + if strings.HasPrefix(name, prefix+"chunks/") { + hasChunks = true + } + } + require.True(t, hasChunks, "no chunk file of block %s was read", id) + } + + // None of the parquet converter files were. + for _, name := range reads { + require.False(t, strings.HasSuffix(name, ".parquet"), name) + require.NotEqual(t, cortex_parquet.ConverterMarkerFileName, path.Base(name), name) + require.NotEqual(t, cortex_parquet.NoConvertMarkerFileName, path.Base(name), name) + } +} diff --git a/pkg/compactor/parquet_filtered_bucket.go b/pkg/compactor/parquet_filtered_bucket.go index 1a1147b2ef..6655e7bdae 100644 --- a/pkg/compactor/parquet_filtered_bucket.go +++ b/pkg/compactor/parquet_filtered_bucket.go @@ -23,7 +23,7 @@ type parquetFilteredBucket struct { } // newParquetFilteredBucket wraps the bucket used for compaction so that parquet -// files and the parquet converter marker are not listed. +// files and the parquet converter markers are not listed. func newParquetFilteredBucket(b objstore.InstrumentedBucket) objstore.InstrumentedBucket { return &parquetFilteredBucket{Bucket: b} } @@ -32,7 +32,10 @@ func isParquetObject(name string) bool { if strings.HasSuffix(name, objstore.DirDelim) { return false } - return strings.HasSuffix(name, parquetFileSuffix) || path.Base(name) == cortex_parquet.ConverterMarkerFileName + base := path.Base(name) + return strings.HasSuffix(name, parquetFileSuffix) || + base == cortex_parquet.ConverterMarkerFileName || + base == cortex_parquet.NoConvertMarkerFileName } func (b *parquetFilteredBucket) Iter(ctx context.Context, dir string, f func(name string) error, options ...objstore.IterOption) error { diff --git a/pkg/compactor/parquet_filtered_bucket_test.go b/pkg/compactor/parquet_filtered_bucket_test.go index 9314886598..bbc7a2d30d 100644 --- a/pkg/compactor/parquet_filtered_bucket_test.go +++ b/pkg/compactor/parquet_filtered_bucket_test.go @@ -22,6 +22,7 @@ var parquetTestFiles = []string{ "1.labels.parquet", "nested/2.chunks.parquet", cortex_parquet.ConverterMarkerFileName, + cortex_parquet.NoConvertMarkerFileName, } func uploadBlockWithParquetFiles(t *testing.T, bkt objstore.Bucket, id ulid.ULID) { From 9be3f71343f58b51e5977ea392b639e0d3b6e3e2 Mon Sep 17 00:00:00 2001 From: Souvik Biswas Date: Fri, 27 Nov 2026 13:32:04 +0530 Subject: [PATCH 3/3] Compactor: declare the parquet test files inline in each test Signed-off-by: Souvik Biswas --- pkg/compactor/compactor_parquet_files_test.go | 10 +++- pkg/compactor/parquet_filtered_bucket_test.go | 53 ++++++++++++------- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/pkg/compactor/compactor_parquet_files_test.go b/pkg/compactor/compactor_parquet_files_test.go index bc4cc3e564..eecd27e03b 100644 --- a/pkg/compactor/compactor_parquet_files_test.go +++ b/pkg/compactor/compactor_parquet_files_test.go @@ -79,8 +79,16 @@ func TestCompactor_ShouldNotDownloadParquetFilesWhenCompacting(t *testing.T) { } // Put the parquet converter output next to each block. + parquetFiles := []string{ + "0.labels.parquet", + "0.chunks.parquet", + "1.labels.parquet", + "nested/2.chunks.parquet", + cortex_parquet.ConverterMarkerFileName, + cortex_parquet.NoConvertMarkerFileName, + } for _, id := range blocks { - for _, name := range parquetTestFiles { + for _, name := range parquetFiles { require.NoError(t, bucketClient.Upload(context.Background(), path.Join("user-1", id.String(), name), strings.NewReader("parquet"))) } } diff --git a/pkg/compactor/parquet_filtered_bucket_test.go b/pkg/compactor/parquet_filtered_bucket_test.go index bbc7a2d30d..5771d28524 100644 --- a/pkg/compactor/parquet_filtered_bucket_test.go +++ b/pkg/compactor/parquet_filtered_bucket_test.go @@ -16,16 +16,7 @@ import ( cortex_parquet "github.com/cortexproject/cortex/pkg/storage/parquet" ) -var parquetTestFiles = []string{ - "0.labels.parquet", - "0.chunks.parquet", - "1.labels.parquet", - "nested/2.chunks.parquet", - cortex_parquet.ConverterMarkerFileName, - cortex_parquet.NoConvertMarkerFileName, -} - -func uploadBlockWithParquetFiles(t *testing.T, bkt objstore.Bucket, id ulid.ULID) { +func uploadBlockWithParquetFiles(t *testing.T, bkt objstore.Bucket, id ulid.ULID, parquetFiles []string) { t.Helper() var meta metadata.Meta @@ -42,7 +33,7 @@ func uploadBlockWithParquetFiles(t *testing.T, bkt objstore.Bucket, id ulid.ULID block.IndexFilename: []byte("index"), "chunks/000001": []byte("chunk"), } - for _, name := range parquetTestFiles { + for _, name := range parquetFiles { files[name] = []byte("parquet") } @@ -55,7 +46,15 @@ func TestParquetFilteredBucket_Iter(t *testing.T) { ctx := context.Background() inmem := objstore.NewInMemBucket() id := ulid.MustNew(1, nil) - uploadBlockWithParquetFiles(t, inmem, id) + parquetFiles := []string{ + "0.labels.parquet", + "0.chunks.parquet", + "1.labels.parquet", + "nested/2.chunks.parquet", + cortex_parquet.ConverterMarkerFileName, + cortex_parquet.NoConvertMarkerFileName, + } + uploadBlockWithParquetFiles(t, inmem, id, parquetFiles) filtered := newParquetFilteredBucket(objstore.WithNoopInstr(inmem)) @@ -70,12 +69,12 @@ func TestParquetFilteredBucket_Iter(t *testing.T) { // Control: the unfiltered bucket lists the parquet files. unfiltered := listRecursive(inmem) - for _, name := range parquetTestFiles { + for _, name := range parquetFiles { require.Contains(t, unfiltered, id.String()+"/"+name) } got := listRecursive(filtered) - for _, name := range parquetTestFiles { + for _, name := range parquetFiles { require.NotContains(t, got, id.String()+"/"+name) } require.Contains(t, got, id.String()+"/"+block.MetaFilename) @@ -88,7 +87,7 @@ func TestParquetFilteredBucket_Iter(t *testing.T) { gotAttrs = append(gotAttrs, attrs.Name) return nil }, objstore.WithRecursiveIter())) - for _, name := range parquetTestFiles { + for _, name := range parquetFiles { require.NotContains(t, gotAttrs, id.String()+"/"+name) } require.Contains(t, gotAttrs, id.String()+"/"+block.IndexFilename) @@ -98,11 +97,19 @@ func TestParquetFilteredBucket_ReadsAreNotFiltered(t *testing.T) { ctx := context.Background() inmem := objstore.NewInMemBucket() id := ulid.MustNew(1, nil) - uploadBlockWithParquetFiles(t, inmem, id) + parquetFiles := []string{ + "0.labels.parquet", + "0.chunks.parquet", + "1.labels.parquet", + "nested/2.chunks.parquet", + cortex_parquet.ConverterMarkerFileName, + cortex_parquet.NoConvertMarkerFileName, + } + uploadBlockWithParquetFiles(t, inmem, id, parquetFiles) filtered := newParquetFilteredBucket(objstore.WithNoopInstr(inmem)) - for _, name := range parquetTestFiles { + for _, name := range parquetFiles { exists, err := filtered.Exists(ctx, id.String()+"/"+name) require.NoError(t, err) require.True(t, exists, name) @@ -123,7 +130,15 @@ func TestParquetFilteredBucket_BlockDownloadSkipsParquetFiles(t *testing.T) { ctx := context.Background() inmem := objstore.NewInMemBucket() id := ulid.MustNew(1, nil) - uploadBlockWithParquetFiles(t, inmem, id) + parquetFiles := []string{ + "0.labels.parquet", + "0.chunks.parquet", + "1.labels.parquet", + "nested/2.chunks.parquet", + cortex_parquet.ConverterMarkerFileName, + cortex_parquet.NoConvertMarkerFileName, + } + uploadBlockWithParquetFiles(t, inmem, id, parquetFiles) // Control: downloading from the unfiltered bucket pulls the parquet files. controlDir := t.TempDir() @@ -139,7 +154,7 @@ func TestParquetFilteredBucket_BlockDownloadSkipsParquetFiles(t *testing.T) { require.FileExists(t, filepath.Join(dst, block.IndexFilename)) require.FileExists(t, filepath.Join(dst, block.ChunksDirname, "000001")) - for _, name := range parquetTestFiles { + for _, name := range parquetFiles { require.NoFileExists(t, filepath.Join(dst, name)) } }