Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only consider an interval to have possible expired chunks if it overlaps a delete. #6297

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,15 @@ func (d *DeleteRequestsManager) MarkPhaseFinished() {
}
}

func (d *DeleteRequestsManager) IntervalMayHaveExpiredChunks(_ model.Interval, userID string) bool {
func (d *DeleteRequestsManager) IntervalMayHaveExpiredChunks(interval model.Interval, userID string) bool {
d.deleteRequestsToProcessMtx.Lock()
defer d.deleteRequestsToProcessMtx.Unlock()

if userID != "" {
for _, deleteRequest := range d.deleteRequestsToProcess {
if deleteRequest.UserID == userID {
if deleteRequest.UserID == userID &&
deleteRequest.StartTime <= interval.End &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your comment on the PR you mention if an interval overlaps a delete request, but this logic requires the interval to be fully within the delete request time period (so excluding an overlap at the start or end of the interval). Is that intended? Would there be a situation where we'd want an || here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually handles overlaps because any overlapping interval will always start before the end of the delete and end after the start of the delete. Fully overlapping is just a special case. I've included a picture

Untitled-2022-05-25-1713

deleteRequest.EndTime >= interval.Start {
return true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,31 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
}
}

func TestDeleteRequestsManager_IntervalMayHaveExpiredChunks(t *testing.T) {
tt := []struct {
deleteRequestsFromStore []DeleteRequest
hasChunks bool
user string
}{
{[]DeleteRequest{{Query: `0`, UserID: "test-user", StartTime: 0, EndTime: 100}}, false, "test-user"},
{[]DeleteRequest{{Query: `1`, UserID: "test-user", StartTime: 200, EndTime: 400}}, true, "test-user"},
{[]DeleteRequest{{Query: `2`, UserID: "test-user", StartTime: 400, EndTime: 500}}, true, "test-user"},
{[]DeleteRequest{{Query: `3`, UserID: "test-user", StartTime: 500, EndTime: 700}}, true, "test-user"},
{[]DeleteRequest{{Query: `3`, UserID: "other-user", StartTime: 500, EndTime: 700}}, false, "test-user"},
{[]DeleteRequest{{Query: `4`, UserID: "test-user", StartTime: 700, EndTime: 900}}, false, "test-user"},
{[]DeleteRequest{{Query: `4`, UserID: "", StartTime: 700, EndTime: 900}}, true, ""},
{[]DeleteRequest{}, false, ""},
}

for _, tc := range tt {
mgr := NewDeleteRequestsManager(mockDeleteRequestsStore{deleteRequests: tc.deleteRequestsFromStore}, time.Hour, nil, FilterAndDelete)
require.NoError(t, mgr.loadDeleteRequestsToProcess())

interval := model.Interval{Start: 300, End: 600}
require.Equal(t, tc.hasChunks, mgr.IntervalMayHaveExpiredChunks(interval, tc.user))
}
}

type mockDeleteRequestsStore struct {
DeleteRequestsStore
deleteRequests []DeleteRequest
Expand Down