@@ -15,6 +15,7 @@ import (
15
15
"github.com/thanos-io/thanos/pkg/block"
16
16
"github.com/thanos-io/thanos/pkg/block/metadata"
17
17
18
+ "github.com/cortexproject/cortex/pkg/storage/parquet"
18
19
"github.com/cortexproject/cortex/pkg/storage/tsdb"
19
20
20
21
"github.com/cortexproject/cortex/pkg/storage/bucket"
@@ -65,12 +66,12 @@ func (w *Updater) UpdateIndex(ctx context.Context, old *Index) (*Index, map[ulid
65
66
oldBlockDeletionMarks = old .BlockDeletionMarks
66
67
}
67
68
68
- blockDeletionMarks , deletedBlocks , totalBlocksBlocksMarkedForNoCompaction , err := w .updateBlockMarks (ctx , oldBlockDeletionMarks )
69
+ blockDeletionMarks , deletedBlocks , totalBlocksBlocksMarkedForNoCompaction , discoveredParquetBlocks , err := w .updateBlockMarks (ctx , oldBlockDeletionMarks )
69
70
if err != nil {
70
71
return nil , nil , 0 , err
71
72
}
72
73
73
- blocks , partials , err := w .updateBlocks (ctx , oldBlocks , deletedBlocks )
74
+ blocks , partials , err := w .updateBlocks (ctx , oldBlocks , deletedBlocks , discoveredParquetBlocks )
74
75
if err != nil {
75
76
return nil , nil , 0 , err
76
77
}
@@ -83,7 +84,7 @@ func (w *Updater) UpdateIndex(ctx context.Context, old *Index) (*Index, map[ulid
83
84
}, partials , totalBlocksBlocksMarkedForNoCompaction , nil
84
85
}
85
86
86
- func (w * Updater ) updateBlocks (ctx context.Context , old []* Block , deletedBlocks map [ulid.ULID ]struct {}) (blocks []* Block , partials map [ulid.ULID ]error , _ error ) {
87
+ func (w * Updater ) updateBlocks (ctx context.Context , old []* Block , deletedBlocks map [ulid.ULID ]struct {}, discoveredParquetBlocks map [ulid. ULID ] struct {} ) (blocks []* Block , partials map [ulid.ULID ]error , _ error ) {
87
88
discovered := map [ulid.ULID ]struct {}{}
88
89
partials = map [ulid.ULID ]error {}
89
90
@@ -107,12 +108,14 @@ func (w *Updater) updateBlocks(ctx context.Context, old []*Block, deletedBlocks
107
108
level .Warn (w .logger ).Log ("msg" , "skipped block with missing global deletion marker" , "block" , b .ID .String ())
108
109
continue
109
110
}
110
- // Check if parquet mark has been uploaded for the old block.
111
- // TODO: this should be optimized to have all parquet marker in a global path.
112
- // We assume parquet marker cannot be removed from a block if it exists before.
113
- if w .parquetEnabled && b .Parquet == nil {
114
- if err := w .updateParquetBlockIndexEntry (ctx , b .ID , b ); err != nil {
115
- return nil , nil , err
111
+ // Check if parquet mark has been uploaded or deleted for the old block.
112
+ if w .parquetEnabled {
113
+ if _ , ok := discoveredParquetBlocks [b .ID ]; ok {
114
+ if err := w .updateParquetBlockIndexEntry (ctx , b .ID , b ); err != nil {
115
+ return nil , nil , err
116
+ }
117
+ } else if b .Parquet != nil {
118
+ b .Parquet = nil
116
119
}
117
120
}
118
121
blocks = append (blocks , b )
@@ -126,7 +129,11 @@ func (w *Updater) updateBlocks(ctx context.Context, old []*Block, deletedBlocks
126
129
b , err := w .updateBlockIndexEntry (ctx , id )
127
130
if err == nil {
128
131
if w .parquetEnabled {
129
- err = w .updateParquetBlockIndexEntry (ctx , id , b )
132
+ if _ , ok := discoveredParquetBlocks [b .ID ]; ok {
133
+ if err := w .updateParquetBlockIndexEntry (ctx , b .ID , b ); err != nil {
134
+ return nil , nil , err
135
+ }
136
+ }
130
137
}
131
138
if err == nil {
132
139
blocks = append (blocks , b )
@@ -203,7 +210,7 @@ func (w *Updater) updateBlockIndexEntry(ctx context.Context, id ulid.ULID) (*Blo
203
210
}
204
211
205
212
func (w * Updater ) updateParquetBlockIndexEntry (ctx context.Context , id ulid.ULID , block * Block ) error {
206
- parquetMarkFile := path .Join (id .String (), tsdb . ParquetConverterMakerFileName )
213
+ parquetMarkFile := path .Join (id .String (), parquet . ConverterMakerFileName )
207
214
208
215
// Get the block's parquet marker file.
209
216
r , err := w .bkt .ReaderWithExpectedErrs (tsdb .IsOneOfTheExpectedErrors (w .bkt .IsObjNotFoundErr , w .bkt .IsAccessDeniedErr )).Get (ctx , parquetMarkFile )
@@ -223,18 +230,19 @@ func (w *Updater) updateParquetBlockIndexEntry(ctx context.Context, id ulid.ULID
223
230
return errors .Wrapf (err , "read parquet converter marker file: %v" , parquetMarkFile )
224
231
}
225
232
226
- m := tsdb .ParquetMeta {}
233
+ m := parquet .ParquetMeta {}
227
234
if err := json .Unmarshal (markContent , & m ); err != nil {
228
235
return errors .Wrapf (ErrBlockParquetMarkCorrupted , "unmarshal parquet converter marker file %s: %v" , parquetMarkFile , err )
229
236
}
230
237
block .Parquet = & m
231
238
return nil
232
239
}
233
240
234
- func (w * Updater ) updateBlockMarks (ctx context.Context , old []* BlockDeletionMark ) ([]* BlockDeletionMark , map [ulid.ULID ]struct {}, int64 , error ) {
241
+ func (w * Updater ) updateBlockMarks (ctx context.Context , old []* BlockDeletionMark ) ([]* BlockDeletionMark , map [ulid.ULID ]struct {}, int64 , map [ ulid . ULID ] struct {}, error ) {
235
242
out := make ([]* BlockDeletionMark , 0 , len (old ))
236
243
deletedBlocks := map [ulid.ULID ]struct {}{}
237
244
discovered := map [ulid.ULID ]struct {}{}
245
+ discoveredParquetBlocks := map [ulid.ULID ]struct {}{}
238
246
totalBlocksBlocksMarkedForNoCompaction := int64 (0 )
239
247
240
248
// Find all markers in the storage.
@@ -247,10 +255,16 @@ func (w *Updater) updateBlockMarks(ctx context.Context, old []*BlockDeletionMark
247
255
totalBlocksBlocksMarkedForNoCompaction ++
248
256
}
249
257
258
+ if w .parquetEnabled {
259
+ if blockID , ok := IsBlockParquetConverterMarkFilename (path .Base (name )); ok {
260
+ discoveredParquetBlocks [blockID ] = struct {}{}
261
+ }
262
+ }
263
+
250
264
return nil
251
265
})
252
266
if err != nil {
253
- return nil , nil , totalBlocksBlocksMarkedForNoCompaction , errors .Wrap (err , "list block deletion marks" )
267
+ return nil , nil , totalBlocksBlocksMarkedForNoCompaction , discoveredParquetBlocks , errors .Wrap (err , "list block deletion marks" )
254
268
}
255
269
256
270
// Since deletion marks are immutable, all markers already existing in the index can just be copied.
@@ -276,13 +290,13 @@ func (w *Updater) updateBlockMarks(ctx context.Context, old []*BlockDeletionMark
276
290
continue
277
291
}
278
292
if err != nil {
279
- return nil , nil , totalBlocksBlocksMarkedForNoCompaction , err
293
+ return nil , nil , totalBlocksBlocksMarkedForNoCompaction , discoveredParquetBlocks , err
280
294
}
281
295
282
296
out = append (out , m )
283
297
}
284
298
285
- return out , deletedBlocks , totalBlocksBlocksMarkedForNoCompaction , nil
299
+ return out , deletedBlocks , totalBlocksBlocksMarkedForNoCompaction , discoveredParquetBlocks , nil
286
300
}
287
301
288
302
func (w * Updater ) updateBlockDeletionMarkIndexEntry (ctx context.Context , id ulid.ULID ) (* BlockDeletionMark , error ) {
0 commit comments