Skip to content

Commit 12b3064

Browse files
authored
imp(deletes): ongoing mutations check (#7639)
We observed ClickHouse being queried on a tight loop when we emit backpressure in the lightweight deletes consumer: https://app.datadoghq.com/s/FH6-Y3/v2m-kc2-fq5 With this change, we keep emitting the backpressure signal but only query once/second
1 parent 54b0de1 commit 12b3064

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

snuba/lw_deletions/strategy.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(
6060
self.__tables = storage.get_deletion_settings().tables
6161
self.__formatter: Formatter = formatter
6262
self.__metrics = metrics
63+
self.__last_ongoing_mutations_check: Optional[float] = None
6364

6465
def poll(self) -> None:
6566
self.__next_step.poll()
@@ -155,8 +156,17 @@ def _execute_delete(self, conditions: Sequence[ConditionsBag]) -> None:
155156
raise LWDeleteQueryException(exc.message)
156157

157158
def _check_ongoing_mutations(self) -> None:
159+
now = time.time()
160+
if (
161+
self.__last_ongoing_mutations_check is not None
162+
and now - self.__last_ongoing_mutations_check < 1.0
163+
):
164+
raise TooManyOngoingMutationsError(
165+
"ongoing mutations check is throttled to once per second"
166+
)
158167
start = time.time()
159168
ongoing_mutations = _num_ongoing_mutations(self.__storage.get_cluster(), self.__tables)
169+
self.__last_ongoing_mutations_check = time.time()
160170
max_ongoing_mutations = typing.cast(
161171
int,
162172
get_int_config(
@@ -167,7 +177,6 @@ def _check_ongoing_mutations(self) -> None:
167177
self.__metrics.timing("ongoing_mutations_query_ms", (time.time() - start) * 1000)
168178
max_ongoing_mutations = int(settings.MAX_ONGOING_MUTATIONS_FOR_DELETE)
169179
if ongoing_mutations > max_ongoing_mutations:
170-
171180
raise TooManyOngoingMutationsError(
172181
f"{ongoing_mutations} mutations for {self.__tables} table(s) is above max ongoing mutations: {max_ongoing_mutations} "
173182
)

0 commit comments

Comments
 (0)