Skip to content

Commit a201f2b

Browse files
authored
Merge pull request #8691 from thibaultmg/delete-s3-directory
compact: delete directory markers in block.Delete
2 parents 96f8f8a + a8171d4 commit a201f2b

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ It is recommend to upgrade the storage components first (Receive, Store, etc.) a
2020

2121
### Added
2222

23+
- [#8691](https://github.com/thanos-io/thanos/pull/8691): Compactor: remove the directory marker objects for some s3 compatible object stores
24+
2325
### Changed
2426

2527
- [#8670](https://github.com/thanos-io/thanos/pull/8670): Receive: *breaking :warning:* removed `--shipper.ignore-unequal-block-size`. TSDB now delays compaction until blocks have been uploaded by the shipper, allowing compaction while uploading without risking data loss.

pkg/block/block.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,19 @@ func Delete(ctx context.Context, logger log.Logger, bkt objstore.Bucket, id ulid
240240
level.Debug(logger).Log("msg", "deleted file", "file", deletionMarkFile, "bucket", bkt.Name())
241241
}
242242

243+
// Some object storages represent directories as explicit empty objects.
244+
// We try to delete the directory marker objects themselves after all their contents are removed.
245+
directoryMarkerPaths := []string{
246+
path.Join(id.String(), ChunksDirname) + objstore.DirDelim,
247+
id.String() + objstore.DirDelim,
248+
}
249+
250+
for _, p := range directoryMarkerPaths {
251+
if err := bkt.Delete(ctx, p); err != nil && !bkt.IsObjNotFoundErr(err) {
252+
level.Debug(logger).Log("msg", "failed to delete directory marker object", "dir", p, "err", err)
253+
}
254+
}
255+
243256
return nil
244257
}
245258

pkg/block/block_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ func TestDelete(t *testing.T) {
257257
testutil.Ok(t, Delete(ctx, log.NewNopLogger(), bkt, b2))
258258
testutil.Equals(t, 0, len(bkt.Objects()))
259259
}
260+
{
261+
b3 := ulid.MustNew(3, nil)
262+
263+
// Upload explicit directory markers.
264+
dirName := b3.String() + objstore.DirDelim
265+
testutil.Ok(t, bkt.Upload(ctx, dirName, bytes.NewReader([]byte{})))
266+
267+
chunksDirName := path.Join(b3.String(), ChunksDirname) + objstore.DirDelim
268+
testutil.Ok(t, bkt.Upload(ctx, chunksDirName, bytes.NewReader([]byte{})))
269+
270+
testutil.Equals(t, 2, len(bkt.Objects()))
271+
272+
// Check if delete also deletes the directory markers.
273+
testutil.Ok(t, Delete(ctx, log.NewNopLogger(), bkt, b3))
274+
testutil.Equals(t, 0, len(bkt.Objects()))
275+
}
260276
}
261277

262278
func TestMarkForDeletion(t *testing.T) {

0 commit comments

Comments
 (0)