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

[release-v2.2] Avoid index errors for deleted tenants #2808

Merged
merged 1 commit into from
Aug 18, 2023
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
2 changes: 1 addition & 1 deletion tempodb/backend/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (rw *readerWriter) Delete(ctx context.Context, name string, keypath backend
}

if _, err = blobURL.Delete(ctx, blob.DeleteSnapshotsOptionInclude, blob.BlobAccessConditions{}); err != nil {
return errors.Wrapf(err, "error deleting blob, name: %s", name)
return readError(err)
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions tempodb/backend/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ func (rw *readerWriter) CloseAppend(_ context.Context, tracker backend.AppendTra
}

func (rw *readerWriter) Delete(ctx context.Context, name string, keypath backend.KeyPath, _ bool) error {
handle := rw.bucket.Object(backend.ObjectFileName(keypath, name))
return handle.Delete(ctx)
return readError(rw.bucket.Object(backend.ObjectFileName(keypath, name)).Delete(ctx))
}

// List implements backend.Reader
Expand Down
3 changes: 2 additions & 1 deletion tempodb/backend/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type MockRawWriter struct {
appendBuffer []byte
closeAppendCalled bool
deleteCalls map[string]map[string]int
err error
}

func (m *MockRawWriter) Write(_ context.Context, _ string, _ KeyPath, data io.Reader, size int64, _ bool) error {
Expand Down Expand Up @@ -89,7 +90,7 @@ func (m *MockRawWriter) Delete(_ context.Context, name string, keypath KeyPath,
}

m.deleteCalls[name][strings.Join(keypath, "/")]++
return nil
return m.err
}

// MockCompactor
Expand Down
6 changes: 5 additions & 1 deletion tempodb/backend/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ func (w *writer) CloseAppend(ctx context.Context, tracker AppendTracker) error {
func (w *writer) WriteTenantIndex(ctx context.Context, tenantID string, meta []*BlockMeta, compactedMeta []*CompactedBlockMeta) error {
// If meta and compactedMeta are empty, call delete the tenant index.
if len(meta) == 0 && len(compactedMeta) == 0 {
return w.w.Delete(ctx, TenantIndexName, KeyPath([]string{tenantID}), false)
// Skip returning an error when the object is already deleted.
if err := w.w.Delete(ctx, TenantIndexName, KeyPath([]string{tenantID}), false); err != nil && err != ErrDoesNotExist {
return err
}
return nil
}

b := newTenantIndex(meta, compactedMeta)
Expand Down
6 changes: 6 additions & 0 deletions tempodb/backend/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func TestWriter(t *testing.T) {

expectedDeleteMap := map[string]map[string]int{TenantIndexName: {"test": 1}}
assert.Equal(t, expectedDeleteMap, w.(*writer).w.(*MockRawWriter).deleteCalls)

// When a backend returns ErrDoesNotExist, the tenant index should be deleted, but no error should be returned if the tenant index does not exist
m = &MockRawWriter{err: ErrDoesNotExist}
w = NewWriter(m)
err = w.WriteTenantIndex(ctx, "test", nil, nil)
assert.NoError(t, err)
}

func TestReader(t *testing.T) {
Expand Down