@@ -11,6 +11,9 @@ import (
11
11
"io/ioutil"
12
12
"path"
13
13
"sort"
14
+ "time"
15
+
16
+ "github.com/thanos-io/thanos/pkg/model"
14
17
15
18
"github.com/go-kit/kit/log"
16
19
"github.com/go-kit/kit/log/level"
@@ -114,6 +117,9 @@ type replicationScheme struct {
114
117
metrics * replicationMetrics
115
118
116
119
reg prometheus.Registerer
120
+
121
+ maxTime * model.TimeOrDurationValue
122
+ markBlocksForFutureDeletion bool
117
123
}
118
124
119
125
type replicationMetrics struct {
@@ -124,6 +130,8 @@ type replicationMetrics struct {
124
130
blocksAlreadyReplicated prometheus.Counter
125
131
blocksReplicated prometheus.Counter
126
132
objectsReplicated prometheus.Counter
133
+
134
+ blocksMarkedForDeletion prometheus.Counter
127
135
}
128
136
129
137
func newReplicationMetrics (reg prometheus.Registerer ) * replicationMetrics {
@@ -152,31 +160,29 @@ func newReplicationMetrics(reg prometheus.Registerer) *replicationMetrics {
152
160
Name : "thanos_replicate_objects_replicated_total" ,
153
161
Help : "Total number of objects replicated." ,
154
162
}),
163
+ blocksMarkedForDeletion : promauto .With (reg ).NewCounter (prometheus.CounterOpts {
164
+ Name : "thanos_replicate _blocks_marked_for_deletion_total" ,
165
+ Help : "Total number of blocks marked for deletion in compactor." ,
166
+ }),
155
167
}
156
168
return m
157
169
}
158
170
159
- func newReplicationScheme (
160
- logger log.Logger ,
161
- metrics * replicationMetrics ,
162
- blockFilter blockFilterFunc ,
163
- fetcher thanosblock.MetadataFetcher ,
164
- from objstore.InstrumentedBucketReader ,
165
- to objstore.Bucket ,
166
- reg prometheus.Registerer ,
167
- ) * replicationScheme {
171
+ func newReplicationScheme (logger log.Logger , metrics * replicationMetrics , blockFilter blockFilterFunc , fetcher thanosblock.MetadataFetcher , from objstore.InstrumentedBucketReader , to objstore.Bucket , reg prometheus.Registerer , maxTime * model.TimeOrDurationValue , markFoFutureDeletion bool ) * replicationScheme {
168
172
if logger == nil {
169
173
logger = log .NewNopLogger ()
170
174
}
171
175
172
176
return & replicationScheme {
173
- logger : logger ,
174
- blockFilter : blockFilter ,
175
- fetcher : fetcher ,
176
- fromBkt : from ,
177
- toBkt : to ,
178
- metrics : metrics ,
179
- reg : reg ,
177
+ logger : logger ,
178
+ blockFilter : blockFilter ,
179
+ fetcher : fetcher ,
180
+ fromBkt : from ,
181
+ toBkt : to ,
182
+ metrics : metrics ,
183
+ reg : reg ,
184
+ maxTime : maxTime ,
185
+ markBlocksForFutureDeletion : markFoFutureDeletion ,
180
186
}
181
187
}
182
188
@@ -231,7 +237,7 @@ func (rs *replicationScheme) execute(ctx context.Context) error {
231
237
})
232
238
233
239
for _ , b := range availableBlocks {
234
- if err := rs .ensureBlockIsReplicated (ctx , b . BlockMeta . ULID ); err != nil {
240
+ if err := rs .ensureBlockIsReplicated (ctx , b ); err != nil {
235
241
return errors .Wrapf (err , "ensure block %v is replicated" , b .BlockMeta .ULID .String ())
236
242
}
237
243
}
@@ -241,8 +247,8 @@ func (rs *replicationScheme) execute(ctx context.Context) error {
241
247
242
248
// ensureBlockIsReplicated ensures that a block present in the origin bucket is
243
249
// present in the target bucket.
244
- func (rs * replicationScheme ) ensureBlockIsReplicated (ctx context.Context , id ulid. ULID ) error {
245
- blockID := id .String ()
250
+ func (rs * replicationScheme ) ensureBlockIsReplicated (ctx context.Context , meta * metadata. Meta ) error {
251
+ blockID := meta . ULID .String ()
246
252
chunksDir := path .Join (blockID , thanosblock .ChunksDirname )
247
253
indexFile := path .Join (blockID , thanosblock .IndexFilename )
248
254
metaFile := path .Join (blockID , thanosblock .MetaFilename )
@@ -281,7 +287,7 @@ func (rs *replicationScheme) ensureBlockIsReplicated(ctx context.Context, id uli
281
287
// If the origin meta file content and target meta file content is
282
288
// equal, we know we have already successfully replicated
283
289
// previously.
284
- level .Debug (rs .logger ).Log ("msg" , "skipping block as already replicated" , "block_uuid" , id .String ())
290
+ level .Debug (rs .logger ).Log ("msg" , "skipping block as already replicated" , "block_uuid" , meta . ULID .String ())
285
291
rs .metrics .blocksAlreadyReplicated .Inc ()
286
292
287
293
return nil
@@ -309,6 +315,14 @@ func (rs *replicationScheme) ensureBlockIsReplicated(ctx context.Context, id uli
309
315
return errors .Wrap (err , "upload meta file" )
310
316
}
311
317
318
+ if rs .markBlocksForFutureDeletion {
319
+ deletionTime := time .Unix (meta .MaxTime / 1000 , 0 ).Add (time .Duration (* rs .maxTime .Dur ))
320
+ if err := thanosblock .MarkForFutureDeletion (ctx , rs .logger , rs .toBkt , meta .ULID , deletionTime , nil ); err != nil {
321
+ return errors .Wrap (err , "failed to mark block for future deletion" )
322
+ }
323
+ rs .metrics .blocksMarkedForDeletion .Inc ()
324
+ }
325
+
312
326
rs .metrics .blocksReplicated .Inc ()
313
327
314
328
return nil
0 commit comments