Skip to content

Commit 536eee6

Browse files
authored
Unconditionally delete payloads from the attachments cache (#102771)
1 parent a4f945a commit 536eee6

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/sentry/attachments/__init__.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"attachment_cache",
55
"store_attachments_for_event",
66
"get_attachments_for_event",
7-
"delete_ratelimited_attachments",
7+
"delete_cached_and_ratelimited_attachments",
88
"CachedAttachment",
99
"MissingAttachmentChunks",
1010
]
@@ -70,21 +70,30 @@ def get_attachments_for_event(event: Any) -> Generator[CachedAttachment]:
7070
return attachment_cache.get(cache_key)
7171

7272

73-
def delete_ratelimited_attachments(
73+
@sentry_sdk.trace
74+
def delete_cached_and_ratelimited_attachments(
7475
project: Project, event: Any, attachments: list[CachedAttachment]
7576
):
7677
"""
77-
This deletes all the attachments that are `rate_limited` from `objectstore` in case they are stored,
78-
and it will also remove all the attachments from the attachments cache as well.
78+
This deletes all attachment payloads and metadata from the attachment cache
79+
(if those are stored there), as well as delete all the `rate_limited`
80+
attachments from the `objectstore`.
81+
Non-ratelimited attachments which are already stored in `objectstore` will
82+
be retained there for long-term storage.
7983
"""
8084
client: ObjectstoreClient | None = None
8185
for attachment in attachments:
86+
# deletes from objectstore if no long-term storage is desired
8287
if attachment.rate_limited and attachment.stored_id:
8388
if client is None:
8489
client = get_attachments_client().for_project(project.organization_id, project.id)
8590
client.delete(attachment.stored_id)
8691

87-
# all other attachments which only exist in the cache but are not stored will
88-
# be cleaned up here:
92+
# unconditionally deletes any payloads from the attachment cache
93+
attachment.delete()
94+
95+
# this cleans up the metadata from the attachments cache:
96+
# any payloads living in the attachments cache have been cleared by the
97+
# `attachment.delete()` call above.
8998
cache_key = cache_key_for_event(event)
9099
attachment_cache.delete(cache_key)

src/sentry/attachments/base.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from collections.abc import Generator
22

3-
import sentry_sdk
43
import zstandard
54

65
from sentry.utils import metrics
@@ -185,9 +184,5 @@ def get_data(self, attachment: CachedAttachment) -> bytes:
185184

186185
return bytes(data)
187186

188-
@sentry_sdk.trace
189187
def delete(self, key: str):
190-
for attachment in self.get(key):
191-
attachment.delete()
192-
193188
self.inner.delete(ATTACHMENT_META_KEY.format(key=key))

src/sentry/tasks/store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from sentry_relay.processing import StoreNormalizer
1313

1414
from sentry import options, reprocessing2
15-
from sentry.attachments import delete_ratelimited_attachments, get_attachments_for_event
15+
from sentry.attachments import delete_cached_and_ratelimited_attachments, get_attachments_for_event
1616
from sentry.constants import DEFAULT_STORE_NORMALIZER_ARGS
1717
from sentry.feedback.usecases.ingest.save_event_feedback import (
1818
save_event_feedback as save_event_feedback_impl,
@@ -627,7 +627,7 @@ def _do_save_event(
627627

628628
reprocessing2.mark_event_reprocessed(data)
629629
if all_attachments and project:
630-
delete_ratelimited_attachments(project, data, all_attachments)
630+
delete_cached_and_ratelimited_attachments(project, data, all_attachments)
631631

632632
if start_time:
633633
metrics.timing(

0 commit comments

Comments
 (0)