Repository navigation
fix(dal): lock the operator row while updating - #652
LKSNDRTMLKV wants to merge 1 commit into
Conversation
[Medium impact] The PR appears safe to merge. SummaryOperator updates now hold a database row lock while reading, applying changes, and saving, so overlapping requests keep each other's changes.
No actionable issues found. Reviews (1) · Last reviewed commit: "fix(dal): lock the operator row while up..." · Reviewed by Greptile |
|
@coderabbitai review |
|
Tip For best results, initiate chat on the files or code changes. @LKSNDRTMLKV What would you like me to do on this pull request? You are interacting with an AI system. |
Action performed
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Closes #619.
OperatorService::updateread the operator config, patched it in memory and wrote the whole row back throughPgOperatorConfigRepo::upsert, with nothing held in between. When twoPATCH /vault/api/v1/operatorrequests overlapped, the one that read first and wrote last restored whatever the other had changed. Here is an example:enterpriseSize;enterpriseSizedecides whether the ESPR Art. 25(1) destruction ban reaches the operator, so a lost correction changes whether a destruction must cite a derogation. TheCOALESCEin the upsert did not help: it keeps the stored value only when the incoming one isNULL, and a stale value is notNULL.What changes
OperatorConfigRepository::update(operator_id, &UpdateOperatorConfig)runs the whole update in one transaction:OperatorConfig::emptywithON CONFLICT DO NOTHING, so the row exists. With no row,FOR UPDATElocks nothing and two first updates would both start from "absent". A second first update now waits on the first one's uncommitted insert.SELECT … FOR UPDATEreads the row and holds it. A concurrent update waits here, then reads what this one wrote.UpdateOperatorConfig::applypatches the row it read. It is still the only copy of the patch rule.upsert's own statement, so theCOALESCEonregistry_verified_atandenterprise_size, and the refusal of aretention_policy_daysbeyondi32, apply as before. Both statements share one column list and onebind_row.Any error drops the transaction, so a refused first update leaves no row behind.
OperatorService::updatecalls it and no longer callsgetorupsert.upsertis documented as a whole-row write for seeding. Its remaining callers are test seeding:dpp-node'ssmokeandregistry_outbox, anddpp-vault's test helpers.No migration and no new dependency.
Tests
crates/dpp-dal/tests/pg_operator_config.rs, against PostgreSQL:two_overlapping_updates_to_different_fields_both_survive. The test holds the rowFOR UPDATE, starts a size correction and a rebranding, and waits until PostgreSQL shows both queued behind its lock. It then commits and asserts both fields.two_first_updates_with_no_row_yet_both_survive. The test holds an uncommitted insert of the row, so only that insert can make the two updates wait. It usesbrandPrimaryandcustomDomain, because theCOALESCEkeeps a storedenterpriseSizewhatever an update read, which would hide the lost update.a_first_update_creates_the_row_from_the_empty_config,an_update_that_carries_no_size_or_date_keeps_the_stored_ones,a_retention_beyond_the_column_is_refused_and_leaves_no_row_behindanda_retention_beyond_the_column_leaves_the_stored_config_unchanged. Nothing tested theCOALESCErule or thei32refusal before.Checked
just checkgreen on this branch (1929 tests passed, 3 skipped, audit included), andpg_operator_configpassed 6 of 6.dpp-dalintegration tier: 162 tests passed.dpp-vaultoperator suites: 18 passed.dpp-nodesmoke: 40 passed.FOR UPDATEremoved from the locking read. Both race tests fail with a lost field: the size goes back toSmall, and the rebranding isNone.Summary by CodeRabbit