Skip to content

Commit c85778c

Browse files
authored
Move tenant-deletion-mark to a global dir (#5676)
* Move tenant-deletion-mark to a global dir Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]> * Fix tests Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]> * Add CHANGELOG Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]> * Address comments Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]> --------- Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
1 parent 7f8d194 commit c85778c

12 files changed

+132
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
* [ENHANCEMENT] Ingester: Added new ingester TSDB metrics `cortex_ingester_tsdb_head_samples_appended_total`, `cortex_ingester_tsdb_head_out_of_order_samples_appended_total`, `cortex_ingester_tsdb_snapshot_replay_error_total`, `cortex_ingester_tsdb_sample_ooo_delta` and `cortex_ingester_tsdb_mmap_chunks_total`. #5624
9090
* [ENHANCEMENT] Query Frontend: Handle context error before decoding and merging responses. #5499
9191
* [ENHANCEMENT] Store-Gateway and AlertManager: Add a `wait_instance_time_out` to context to avoid waiting forever. #5581
92+
* [ENHANCEMENT] Blocks storage: Move the tenant deletion mark from `<tenantID>/markers/tenant-deletion-mark.json` to `__markers__/<tenantID>/tenant-deletion-mark.json`. #5676
9293
* [BUGFIX] Compactor: Fix possible division by zero during compactor config validation. #5535
9394
* [BUGFIX] Ruler: Validate if rule group can be safely converted back to rule group yaml from protobuf message #5265
9495
* [BUGFIX] Querier: Convert gRPC `ResourceExhausted` status code from store gateway to 422 limit error. #5286

pkg/compactor/blocks_cleaner.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,16 @@ func (c *BlocksCleaner) deleteUserMarkedForDeletion(ctx context.Context, userID
293293
level.Info(userLogger).Log("msg", "deleted files under "+block.DebugMetas+" for tenant marked for deletion", "count", deleted)
294294
}
295295

296-
// Tenant deletion mark file is inside Markers as well.
297296
if deleted, err := bucket.DeletePrefix(ctx, userBucket, bucketindex.MarkersPathname, userLogger); err != nil {
298297
return errors.Wrap(err, "failed to delete marker files")
299298
} else if deleted > 0 {
300299
level.Info(userLogger).Log("msg", "deleted marker files for tenant marked for deletion", "count", deleted)
301300
}
302301

302+
if err := cortex_tsdb.DeleteTenantDeletionMark(ctx, c.bucketClient, userID); err != nil {
303+
return errors.Wrap(err, "failed to delete tenant deletion mark")
304+
}
305+
303306
return nil
304307
}
305308

pkg/compactor/blocks_cleaner_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,26 @@ func testBlocksCleanerWithOptions(t *testing.T, options testBlocksCleanerOptions
209209
{path: path.Join("user-3", block9.String(), "index"), expectedExists: false},
210210
{path: path.Join("user-3", block10.String(), metadata.MetaFilename), expectedExists: false},
211211
{path: path.Join("user-3", block10.String(), "index"), expectedExists: false},
212-
// Tenant deletion mark is not removed.
213-
{path: path.Join("user-3", tsdb.TenantDeletionMarkPath), expectedExists: true},
214-
// User-4 is removed fully.
215-
{path: path.Join("user-4", tsdb.TenantDeletionMarkPath), expectedExists: options.user4FilesExist},
216212
{path: path.Join("user-4", block.DebugMetas, "meta.json"), expectedExists: options.user4FilesExist},
217213
} {
218214
exists, err := bucketClient.Exists(ctx, tc.path)
219215
require.NoError(t, err)
220216
assert.Equal(t, tc.expectedExists, exists, tc.path)
221217
}
222218

219+
// Check if tenant deletion mark exists
220+
for _, tc := range []struct {
221+
user string
222+
expectedExists bool
223+
}{
224+
{"user-3", true},
225+
{"user-4", options.user4FilesExist},
226+
} {
227+
exists, err := tsdb.TenantDeletionMarkExists(ctx, bucketClient, tc.user)
228+
require.NoError(t, err)
229+
assert.Equal(t, tc.expectedExists, exists, tc.user)
230+
}
231+
223232
assert.Equal(t, float64(1), testutil.ToFloat64(cleaner.runsStarted))
224233
assert.Equal(t, float64(1), testutil.ToFloat64(cleaner.runsCompleted))
225234
assert.Equal(t, float64(0), testutil.ToFloat64(cleaner.runsFailed))

pkg/compactor/compactor_test.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ func TestCompactor_SkipCompactionWhenCmkError(t *testing.T) {
176176
bucketClient.MockGet(userID+"/bucket-index.json.gz", "", nil)
177177
bucketClient.MockUpload(userID+"/bucket-index-sync-status.json", nil)
178178
bucketClient.MockUpload(userID+"/bucket-index.json.gz", nil)
179-
bucketClient.MockExists(path.Join(userID, cortex_tsdb.TenantDeletionMarkPath), false, nil)
179+
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath(userID), false, nil)
180+
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath(userID), false, nil)
180181

181182
cfg := prepareConfig()
182183
c, _, _, logs, _ := prepare(t, cfg, bucketClient, nil)
@@ -500,7 +501,8 @@ func TestCompactor_ShouldIncrementCompactionErrorIfFailedToCompactASingleTenant(
500501
bucketClient.MockIter("", []string{userID}, nil)
501502
bucketClient.MockIter(userID+"/", []string{userID + "/01DTVP434PA9VFXSW2JKB3392D/meta.json", userID + "/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
502503
bucketClient.MockIter(userID+"/markers/", nil, nil)
503-
bucketClient.MockExists(path.Join(userID, cortex_tsdb.TenantDeletionMarkPath), false, nil)
504+
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath(userID), false, nil)
505+
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath(userID), false, nil)
504506
bucketClient.MockGet(userID+"/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
505507
bucketClient.MockGet(userID+"/01DTVP434PA9VFXSW2JKB3392D/no-compact-mark.json", "", nil)
506508
bucketClient.MockGet(userID+"/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json", "", nil)
@@ -549,7 +551,8 @@ func TestCompactor_ShouldIncrementCompactionErrorIfFailedToCompactASingleTenant(
549551
func TestCompactor_ShouldCompactAndRemoveUserFolder(t *testing.T) {
550552
bucketClient := &bucket.ClientMock{}
551553
bucketClient.MockIter("", []string{"user-1"}, nil)
552-
bucketClient.MockExists(path.Join("user-1", cortex_tsdb.TenantDeletionMarkPath), false, nil)
554+
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-1"), false, nil)
555+
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
553556
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
554557
bucketClient.MockIter("user-1/markers/", nil, nil)
555558
bucketClient.MockGet("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
@@ -593,8 +596,10 @@ func TestCompactor_ShouldIterateOverUsersAndRunCompaction(t *testing.T) {
593596
// Mock the bucket to contain two users, each one with one block.
594597
bucketClient := &bucket.ClientMock{}
595598
bucketClient.MockIter("", []string{"user-1", "user-2"}, nil)
596-
bucketClient.MockExists(path.Join("user-1", cortex_tsdb.TenantDeletionMarkPath), false, nil)
597-
bucketClient.MockExists(path.Join("user-2", cortex_tsdb.TenantDeletionMarkPath), false, nil)
599+
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-1"), false, nil)
600+
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
601+
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-2"), false, nil)
602+
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-2"), false, nil)
598603
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
599604
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
600605
bucketClient.MockIter("user-1/markers/", nil, nil)
@@ -734,7 +739,8 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForDeletion(t *testing.T) {
734739
bucketClient := &bucket.ClientMock{}
735740
bucketClient.MockIter("", []string{"user-1"}, nil)
736741
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D", "user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ"}, nil)
737-
bucketClient.MockExists(path.Join("user-1", cortex_tsdb.TenantDeletionMarkPath), false, nil)
742+
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-1"), false, nil)
743+
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
738744

739745
// Block that has just been marked for deletion. It will not be deleted just yet, and it also will not be compacted.
740746
bucketClient.MockGet("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
@@ -856,8 +862,10 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForSkipCompact(t *testing.T) {
856862
// Mock the bucket to contain two users, each one with one block.
857863
bucketClient := &bucket.ClientMock{}
858864
bucketClient.MockIter("", []string{"user-1", "user-2"}, nil)
859-
bucketClient.MockExists(path.Join("user-1", cortex_tsdb.TenantDeletionMarkPath), false, nil)
860-
bucketClient.MockExists(path.Join("user-2", cortex_tsdb.TenantDeletionMarkPath), false, nil)
865+
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-1"), false, nil)
866+
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
867+
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-2"), false, nil)
868+
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-2"), false, nil)
861869
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
862870
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
863871
bucketClient.MockIter("user-1/markers/", nil, nil)
@@ -933,8 +941,8 @@ func TestCompactor_ShouldNotCompactBlocksForUsersMarkedForDeletion(t *testing.T)
933941
bucketClient := &bucket.ClientMock{}
934942
bucketClient.MockIter("", []string{"user-1"}, nil)
935943
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D"}, nil)
936-
bucketClient.MockGet(path.Join("user-1", cortex_tsdb.TenantDeletionMarkPath), `{"deletion_time": 1}`, nil)
937-
bucketClient.MockUpload(path.Join("user-1", cortex_tsdb.TenantDeletionMarkPath), nil)
944+
bucketClient.MockGet(cortex_tsdb.GetGlobalDeletionMarkPath("user-1"), `{"deletion_time": 1}`, nil)
945+
bucketClient.MockUpload(cortex_tsdb.GetGlobalDeletionMarkPath("user-1"), nil)
938946

939947
bucketClient.MockIter("user-1/01DTVP434PA9VFXSW2JKB3392D", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01DTVP434PA9VFXSW2JKB3392D/index"}, nil)
940948
bucketClient.MockGet("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
@@ -1094,8 +1102,10 @@ func TestCompactor_ShouldCompactAllUsersOnShardingEnabledButOnlyOneInstanceRunni
10941102
// Mock the bucket to contain two users, each one with one block.
10951103
bucketClient := &bucket.ClientMock{}
10961104
bucketClient.MockIter("", []string{"user-1", "user-2"}, nil)
1097-
bucketClient.MockExists(path.Join("user-1", cortex_tsdb.TenantDeletionMarkPath), false, nil)
1098-
bucketClient.MockExists(path.Join("user-2", cortex_tsdb.TenantDeletionMarkPath), false, nil)
1105+
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-1"), false, nil)
1106+
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
1107+
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-2"), false, nil)
1108+
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-2"), false, nil)
10991109
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
11001110
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
11011111
bucketClient.MockIter("user-1/markers/", nil, nil)
@@ -1202,7 +1212,8 @@ func TestCompactor_ShouldCompactOnlyUsersOwnedByTheInstanceOnShardingEnabledAndM
12021212
for _, userID := range userIDs {
12031213
bucketClient.MockIter(userID+"/", []string{userID + "/01DTVP434PA9VFXSW2JKB3392D"}, nil)
12041214
bucketClient.MockIter(userID+"/markers/", nil, nil)
1205-
bucketClient.MockExists(path.Join(userID, cortex_tsdb.TenantDeletionMarkPath), false, nil)
1215+
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath(userID), false, nil)
1216+
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath(userID), false, nil)
12061217
bucketClient.MockGet(userID+"/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
12071218
bucketClient.MockGet(userID+"/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json", "", nil)
12081219
bucketClient.MockGet(userID+"/01DTVP434PA9VFXSW2JKB3392D/no-compact-mark.json", "", nil)
@@ -1334,7 +1345,8 @@ func TestCompactor_ShouldCompactOnlyShardsOwnedByTheInstanceOnShardingEnabledWit
13341345

13351346
bucketClient.MockIter(userID+"/", blockFiles, nil)
13361347
bucketClient.MockIter(userID+"/markers/", nil, nil)
1337-
bucketClient.MockExists(path.Join(userID, cortex_tsdb.TenantDeletionMarkPath), false, nil)
1348+
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath(userID), false, nil)
1349+
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath(userID), false, nil)
13381350
bucketClient.MockGet(userID+"/bucket-index.json.gz", "", nil)
13391351
bucketClient.MockUpload(userID+"/bucket-index.json.gz", nil)
13401352
bucketClient.MockUpload(userID+"/bucket-index-sync-status.json", nil)

pkg/purger/tenant_deletion_api_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"net/http"
77
"net/http/httptest"
8-
"path"
98
"testing"
109

1110
"github.com/go-kit/log"
@@ -35,8 +34,9 @@ func TestDeleteTenant(t *testing.T) {
3534
api.DeleteTenant(resp, req.WithContext(ctx))
3635

3736
require.Equal(t, http.StatusOK, resp.Code)
38-
objs := bkt.Objects()
39-
require.NotNil(t, objs[path.Join("fake", tsdb.TenantDeletionMarkPath)])
37+
exists, err := tsdb.TenantDeletionMarkExists(ctx, bkt, "fake")
38+
require.NoError(t, err)
39+
require.True(t, exists)
4040
}
4141
}
4242

pkg/querier/blocks_finder_bucket_scan_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"os"
7-
"path"
87
"strings"
98
"testing"
109
"time"
@@ -96,7 +95,8 @@ func TestBucketScanBlocksFinder_InitialScanFailure(t *testing.T) {
9695
// Mock the storage to simulate a failure when reading objects.
9796
bucket.MockIter("", []string{"user-1"}, nil)
9897
bucket.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json"}, nil)
99-
bucket.MockExists(path.Join("user-1", cortex_tsdb.TenantDeletionMarkPath), false, nil)
98+
bucket.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-1"), false, nil)
99+
bucket.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
100100
bucket.MockGet("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "invalid", errors.New("mocked error"))
101101

102102
require.NoError(t, s.StartAsync(ctx))
@@ -143,7 +143,8 @@ func TestBucketScanBlocksFinder_StopWhileRunningTheInitialScanOnManyTenants(t *t
143143
bucket.MockIterWithCallback(tenantID+"/", []string{}, nil, func() {
144144
time.Sleep(time.Second)
145145
})
146-
bucket.MockExists(path.Join(tenantID, cortex_tsdb.TenantDeletionMarkPath), false, nil)
146+
bucket.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath(tenantID), false, nil)
147+
bucket.MockExists(cortex_tsdb.GetLocalDeletionMarkPath(tenantID), false, nil)
147148
}
148149

149150
cfg := prepareBucketScanBlocksFinderConfig()

pkg/storage/tsdb/caching_bucket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ var chunksMatcher = regexp.MustCompile(`^.*/chunks/\d+$`)
183183
func isTSDBChunkFile(name string) bool { return chunksMatcher.MatchString(name) }
184184

185185
func isMetaFile(name string) bool {
186-
return strings.HasSuffix(name, "/"+metadata.MetaFilename) || strings.HasSuffix(name, "/"+metadata.DeletionMarkFilename) || strings.HasSuffix(name, "/"+TenantDeletionMarkPath)
186+
return strings.HasSuffix(name, "/"+metadata.MetaFilename) || strings.HasSuffix(name, "/"+metadata.DeletionMarkFilename) || strings.HasSuffix(name, "/"+TenantDeletionMarkFile)
187187
}
188188

189189
func isBlockIndexFile(name string) bool {

pkg/storage/tsdb/tenant_deletion_mark.go

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
"github.com/pkg/errors"
1212
"github.com/thanos-io/objstore"
1313

14+
"github.com/cortexproject/cortex/pkg/util"
1415
util_log "github.com/cortexproject/cortex/pkg/util/log"
1516
)
1617

17-
// Relative to user-specific prefix.
18-
const TenantDeletionMarkPath = "markers/tenant-deletion-mark.json"
18+
const TenantDeletionMarkFile = "tenant-deletion-mark.json"
1919

2020
type TenantDeletionMark struct {
2121
// Unix timestamp when deletion marker was created.
@@ -31,15 +31,60 @@ func NewTenantDeletionMark(deletionTime time.Time) *TenantDeletionMark {
3131

3232
// Checks for deletion mark for tenant. Errors other than "object not found" are returned.
3333
func TenantDeletionMarkExists(ctx context.Context, bkt objstore.BucketReader, userID string) (bool, error) {
34-
markerFile := path.Join(userID, TenantDeletionMarkPath)
34+
markerFile := GetGlobalDeletionMarkPath(userID)
35+
if globalExists, err := exists(ctx, bkt, markerFile); err != nil {
36+
return false, err
37+
} else if globalExists {
38+
return true, nil
39+
}
3540

36-
return bkt.Exists(ctx, markerFile)
41+
markerFile = GetLocalDeletionMarkPath(userID)
42+
return exists(ctx, bkt, markerFile)
3743
}
3844

3945
// Uploads deletion mark to the tenant location in the bucket.
4046
func WriteTenantDeletionMark(ctx context.Context, bkt objstore.Bucket, userID string, mark *TenantDeletionMark) error {
41-
markerFile := path.Join(userID, TenantDeletionMarkPath)
47+
markerFile := GetGlobalDeletionMarkPath(userID)
48+
return write(ctx, bkt, markerFile, mark)
49+
}
50+
51+
// Returns tenant deletion mark for given user, if it exists. If it doesn't exist, returns nil mark, and no error.
52+
func ReadTenantDeletionMark(ctx context.Context, bkt objstore.BucketReader, userID string) (*TenantDeletionMark, error) {
53+
markerFile := GetGlobalDeletionMarkPath(userID)
54+
if mark, err := read(ctx, bkt, markerFile); err != nil {
55+
return nil, err
56+
} else if mark != nil {
57+
return mark, nil
58+
}
59+
60+
markerFile = GetLocalDeletionMarkPath(userID)
61+
return read(ctx, bkt, markerFile)
62+
}
4263

64+
// Deletes the tenant deletion mark for given user if it exists.
65+
func DeleteTenantDeletionMark(ctx context.Context, bkt objstore.Bucket, userID string) error {
66+
if err := bkt.Delete(ctx, GetGlobalDeletionMarkPath(userID)); err != nil {
67+
return err
68+
}
69+
if err := bkt.Delete(ctx, GetLocalDeletionMarkPath(userID)); err != nil {
70+
return err
71+
}
72+
return nil
73+
}
74+
75+
func GetLocalDeletionMarkPath(userID string) string {
76+
return path.Join(userID, "markers", TenantDeletionMarkFile)
77+
}
78+
79+
func GetGlobalDeletionMarkPath(userID string) string {
80+
return path.Join(util.GlobalMarkersDir, userID, TenantDeletionMarkFile)
81+
}
82+
83+
func exists(ctx context.Context, bkt objstore.BucketReader, markerFile string) (bool, error) {
84+
return bkt.Exists(ctx, markerFile)
85+
}
86+
87+
func write(ctx context.Context, bkt objstore.Bucket, markerFile string, mark *TenantDeletionMark) error {
4388
data, err := json.Marshal(mark)
4489
if err != nil {
4590
return errors.Wrap(err, "serialize tenant deletion mark")
@@ -48,10 +93,7 @@ func WriteTenantDeletionMark(ctx context.Context, bkt objstore.Bucket, userID st
4893
return errors.Wrap(bkt.Upload(ctx, markerFile, bytes.NewReader(data)), "upload tenant deletion mark")
4994
}
5095

51-
// Returns tenant deletion mark for given user, if it exists. If it doesn't exist, returns nil mark, and no error.
52-
func ReadTenantDeletionMark(ctx context.Context, bkt objstore.BucketReader, userID string) (*TenantDeletionMark, error) {
53-
markerFile := path.Join(userID, TenantDeletionMarkPath)
54-
96+
func read(ctx context.Context, bkt objstore.BucketReader, markerFile string) (*TenantDeletionMark, error) {
5597
r, err := bkt.Get(ctx, markerFile)
5698
if err != nil {
5799
if bkt.IsObjNotFoundErr(err) {

pkg/storage/tsdb/tenant_deletion_mark_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,17 @@ func TestTenantDeletionMarkExists(t *testing.T) {
2929
exists: false,
3030
},
3131

32-
"mark exists": {
32+
"local mark exists": {
3333
objects: map[string][]byte{
3434
"user/01EQK4QKFHVSZYVJ908Y7HH9E0/meta.json": []byte("data"),
35-
"user/" + TenantDeletionMarkPath: []byte("data"),
35+
GetLocalDeletionMarkPath("user"): []byte("data"),
36+
},
37+
exists: true,
38+
},
39+
"global mark exists": {
40+
objects: map[string][]byte{
41+
"user/01EQK4QKFHVSZYVJ908Y7HH9E0/meta.json": []byte("data"),
42+
GetGlobalDeletionMarkPath("user"): []byte("data"),
3643
},
3744
exists: true,
3845
},

pkg/storage/tsdb/users_scanner.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import (
44
"context"
55
"strings"
66

7+
"github.com/cortexproject/cortex/pkg/util"
78
"github.com/go-kit/log"
89
"github.com/go-kit/log/level"
910
"github.com/thanos-io/objstore"
1011
)
1112

1213
// AllUsers returns true to each call and should be used whenever the UsersScanner should not filter out
1314
// any user due to sharding.
14-
func AllUsers(_ string) (bool, error) {
15+
func AllUsers(user string) (bool, error) {
16+
if user == util.GlobalMarkersDir {
17+
return false, nil
18+
}
1519
return true, nil
1620
}
1721

0 commit comments

Comments
 (0)