Repository navigation
Stop MetricsDB.update() from re-inserting rows it just updated - #882
Merged
Merged
Conversation
executemanySQL only returns one aggregate rowcount for the whole batch UPDATE, not per-row results, so when any row in a cycle is new, the fallback loop re-attempts an INSERT for every row in the batch - not just the ones that weren't actually updated. Rows that just succeeded the UPDATE hit the unique constraint on (computingSite, gshare, metric) and get logged as a full ORA-00001 error every single cycle this happens, which in production is most cycles given the site/gshare set changes over time. Makes the insert a guarded INSERT ... SELECT ... WHERE NOT EXISTS, matching the pattern DBProxy.backfill_pilot_attributes already uses for the same kind of race - re-inserting an already-present row becomes a harmless no-op instead of a constraint violation. Also adds the same Postgres JSON-cast guard that function needs, even though this daemon isn't enabled on any Postgres deployment today - the schema name itself already gets rewritten transparently for any backend by WrappedCursor's change_schema(), so this would silently break the moment someone enables it there without the guard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MetricsDB.update()inmetric_collector.pydoes a batchUPDATEviaexecutemanySQL, then falls back to inserting rows that weren't updated. SinceexecutemanySQLonly returns one aggregate rowcount for the whole batch (not per-row results), the fallback loop re-attempts anINSERTfor every row in the batch whenever any row is new - including rows that were just successfully updated a moment earlier in the same cycle.(computingSite, gshare, metric)and get logged as a fullORA-00001error, every time this happens - in production this is most cycles, since the live site/gshare set changes over time. This accounts for 830 of this week's ~2900 DBProxy errors (the single largest non-deadlock contributor), confirmed via the Kibana error-signature report.INSERT ... SELECT ... WHERE NOT EXISTS, the same patternDBProxy.backfill_pilot_attributesalready uses for an identical race - re-inserting an already-present row becomes a harmless no-op instead of a constraint violation, instead of trying to track exactly which rows need it (not possible with the currentexecutemanySQLprimitive without a bigger rework).backfill_pilot_attributesneeds (CAST(:x AS JSON)for Postgres, since a text bind isn't implicitly cast to a JSON column's type inINSERT ... SELECTthe way it is inINSERT ... VALUES). This daemon isn't enabled on any Postgres deployment today (confirmed on DOMA:panda_server.cfghas[daemon] enable = False), but theATLAS_PANDA.schema prefix already gets rewritten transparently for any backend byWrappedCursor.change_schema(), so this would silently break the moment someone enables daemons on a Postgres cluster without the guard.Test plan
python -m py_compileon the changed file.isort --check-onlyclean.flake8/blackcould not be run in this environment (missing/broken local install) - worth a CI check before merging.