Skip to content

Commit

Permalink
Avoid index errors for deleted tenants (#2781)
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
  • Loading branch information
zalegrala authored Aug 14, 2023
1 parent bc3f543 commit e960fd0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [BUGFIX] Fix panic in metrics summary api [#2738](https://github.com/grafana/tempo/pull/2738) (@mdisibio)
* [BUGFIX] Fix node role auth IDMSv1 [#2760](https://github.com/grafana/tempo/pull/2760) (@coufalja)
* [BUGFIX] Only search ingester blocks that fall within the request time range. [#2783](https://github.com/grafana/tempo/pull/2783) (@joe-elliott)
* [BUGFIX] Fix incorrect metrics for index failures [#2781](https://github.com/grafana/tempo/pull/2781) (@zalegrala)

## v2.2.0 / 2023-07-31

Expand Down
2 changes: 1 addition & 1 deletion tempodb/backend/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,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 @@ -153,8 +153,7 @@ func (rw *readerWriter) CloseAppend(_ context.Context, tracker backend.AppendTra
}

func (rw *readerWriter) Delete(ctx context.Context, name string, keypath backend.KeyPath, _ bool) error {
return rw.bucket.Object(backend.ObjectFileName(keypath, name)).
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 e960fd0

Please sign in to comment.