@@ -11,43 +11,114 @@ import (
11
11
"github.com/prometheus/client_golang/prometheus/testutil"
12
12
"github.com/stretchr/testify/assert"
13
13
"github.com/stretchr/testify/require"
14
+ "github.com/thanos-io/thanos/pkg/block/metadata"
14
15
"github.com/thanos-io/thanos/pkg/objstore"
15
16
16
17
"github.com/cortexproject/cortex/pkg/storage/bucket"
17
18
cortex_testutil "github.com/cortexproject/cortex/pkg/storage/tsdb/testutil"
18
19
)
19
20
20
- func TestGlobalMarkersBucket_Delete_ShouldSucceedIfDeletionMarkDoesNotExistInTheBlockButExistInTheGlobalLocation (t *testing.T) {
21
- bkt, _ := cortex_testutil.PrepareFilesystemBucket(t )
21
+ func TestGlobalMarker_ShouldUploadGlobalLocation (t *testing.T) {
22
+ block1 := ulid.MustNew(1, nil )
22
23
23
- ctx := context.Background()
24
- bkt = BucketWithGlobalMarkers(bkt)
24
+ tests := []struct {
25
+ mark string
26
+ globalpath string
27
+ }{
28
+ {
29
+ mark: metadata.DeletionMarkFilename,
30
+ globalpath: "markers/" + block1.String() + "-deletion-mark.json",
31
+ },
32
+ {
33
+ mark: metadata.NoCompactMarkFilename,
34
+ globalpath: "markers/" + block1.String() + "-no-compact-mark.json",
35
+ },
36
+ }
37
+
38
+ for _, tc := range tests {
39
+ t.Run(tc.mark, func(t *testing.T) {
40
+ originalPath := block1.String() + "/" + tc.mark
41
+ bkt, _ := cortex_testutil.PrepareFilesystemBucket(t)
42
+
43
+ ctx := context.Background()
44
+ bkt = BucketWithGlobalMarkers(bkt)
45
+
46
+ bkt.Upload(ctx, originalPath, strings.NewReader("{}"))
25
47
26
- // Create a mocked block deletion mark in the global location.
27
- blockID := ulid.MustNew(1, nil )
28
- globalPath := BlockDeletionMarkFilepath(blockID )
29
- require.NoError (t, bkt.Upload(ctx, globalPath, strings.NewReader("{}")) )
48
+ // Ensure it exists on originalPath
49
+ ok, err := bkt.Exists(ctx, originalPath )
50
+ require.NoError(t, err )
51
+ require.True (t, ok )
30
52
31
- // Ensure it exists before deleting it.
32
- ok, err : = bkt.Exists(ctx, globalPath )
33
- require.NoError(t, err)
34
- require.True(t, ok)
53
+ // Ensure it exists on globalPath
54
+ ok, err = bkt.Exists(ctx, tc.globalpath )
55
+ require.NoError(t, err)
56
+ require.True(t, ok)
35
57
36
- require.NoError(t, bkt.Delete(ctx, globalPath) )
58
+ bkt.Delete(ctx, originalPath )
37
59
38
- // Ensure has been actually deleted.
39
- ok, err = bkt.Exists(ctx, globalPath)
40
- require.NoError(t, err)
41
- require.False(t, ok)
60
+ // Ensure it deleted on originalPath
61
+ ok, err = bkt.Exists(ctx, originalPath)
62
+ require.NoError(t, err)
63
+ require.False(t, ok)
64
+
65
+ // Ensure it exists on globalPath
66
+ ok, err = bkt.Exists(ctx, tc.globalpath)
67
+ require.NoError(t, err)
68
+ require.False(t, ok)
69
+ })
70
+ }
42
71
}
43
72
44
- func TestGlobalMarkersBucket_isBlockDeletionMark(t *testing.T) {
73
+ func TestGlobalMarkersBucket_Delete_ShouldSucceedIfMarkDoesNotExistInTheBlockButExistInTheGlobalLocation(t *testing.T) {
74
+ tests := []struct {
75
+ name string
76
+ pathF func(ulid.ULID) string
77
+ }{
78
+ {
79
+ name: metadata.DeletionMarkFilename,
80
+ pathF: BlockDeletionMarkFilepath,
81
+ },
82
+ {
83
+ name: metadata.NoCompactMarkFilename,
84
+ pathF: NoCompactMarkFilenameMarkFilepath,
85
+ },
86
+ }
87
+
88
+ for _, tc := range tests {
89
+ t.Run(tc.name, func(t *testing.T) {
90
+ bkt, _ := cortex_testutil.PrepareFilesystemBucket(t)
91
+
92
+ ctx := context.Background()
93
+ bkt = BucketWithGlobalMarkers(bkt)
94
+
95
+ // Create a mocked block deletion mark in the global location.
96
+ blockID := ulid.MustNew(1, nil)
97
+ globalPath := tc.pathF(blockID)
98
+ require.NoError(t, bkt.Upload(ctx, globalPath, strings.NewReader("{}")))
99
+
100
+ // Ensure it exists before deleting it.
101
+ ok, err := bkt.Exists(ctx, globalPath)
102
+ require.NoError(t, err)
103
+ require.True(t, ok)
104
+
105
+ require.NoError(t, bkt.Delete(ctx, globalPath))
106
+
107
+ // Ensure has been actually deleted.
108
+ ok, err = bkt.Exists(ctx, globalPath)
109
+ require.NoError(t, err)
110
+ require.False(t, ok)
111
+ })
112
+ }
113
+ }
114
+
115
+ func TestGlobalMarkersBucket_isMark(t *testing.T) {
45
116
block1 := ulid.MustNew(1, nil)
46
117
47
118
tests := []struct {
48
- name string
49
- expectedOk bool
50
- expectedID ulid.ULID
119
+ name string
120
+ expectedOk bool
121
+ expectedGlobalPath string
51
122
}{
52
123
{
53
124
name: "",
@@ -59,23 +130,31 @@ func TestGlobalMarkersBucket_isBlockDeletionMark(t *testing.T) {
59
130
name: block1.String() + "/index",
60
131
expectedOk: false,
61
132
}, {
62
- name: block1.String() + "/deletion-mark.json",
63
- expectedOk: true,
64
- expectedID: block1,
133
+ name: block1.String() + "/deletion-mark.json",
134
+ expectedOk: true,
135
+ expectedGlobalPath: "markers/" + block1.String() + "-deletion-mark.json",
136
+ }, {
137
+ name: "/path/to/" + block1.String() + "/deletion-mark.json",
138
+ expectedOk: true,
139
+ expectedGlobalPath: "/path/to/markers/" + block1.String() + "-deletion-mark.json",
140
+ }, {
141
+ name: block1.String() + "/no-compact-mark.json",
142
+ expectedOk: true,
143
+ expectedGlobalPath: "markers/" + block1.String() + "-no-compact-mark.json",
65
144
}, {
66
- name: "/path/to/" + block1.String() + "/deletion -mark.json",
67
- expectedOk: true,
68
- expectedID: block1,
145
+ name: "/path/to/" + block1.String() + "/no-compact -mark.json",
146
+ expectedOk: true,
147
+ expectedGlobalPath: "/path/to/markers/" + block1.String() + "-no-compact-mark.json" ,
69
148
},
70
149
}
71
150
72
151
b := BucketWithGlobalMarkers(nil).(*globalMarkersBucket)
73
152
74
153
for _, tc := range tests {
75
154
t.Run(tc.name, func(t *testing.T) {
76
- actualID , actualOk := b.isBlockDeletionMark (tc.name)
155
+ globalPath , actualOk := b.isMark (tc.name)
77
156
assert.Equal(t, tc.expectedOk, actualOk)
78
- assert.Equal(t, tc.expectedID, actualID )
157
+ assert.Equal(t, tc.expectedGlobalPath, globalPath )
79
158
})
80
159
}
81
160
}
0 commit comments