Skip to content

Commit

Permalink
Avoid index errors for deleted tenants (#2781) (#2808)
Browse files Browse the repository at this point in the history
* Catch backend.ErrDoesNotExist from WriteTenantIndex

* Handle tenant index deletion when already deleted

* Capture notfound from azure.Delete

* Capture notfound from gcs.Delete

* Update changelog

* Add note for why we skip ErrDoesNotExist

* Avoid handling the error twice

(cherry picked from commit e960fd0)

Co-authored-by: Zach Leslie <zach.leslie@grafana.com>
  • Loading branch information
joe-elliott and zalegrala committed Aug 18, 2023
1 parent 852e952 commit 2ee88b4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
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

0 comments on commit 2ee88b4

Please sign in to comment.