Fix ANS v2 current-row Ord omitting token_standard from PK - #63
Open
sausagee wants to merge 3 commits into
Open
Conversation
CurrentAnsLookupV2 and CurrentAnsPrimaryNameV2 derive Eq over all fields (including token_standard) but Ord compared only the PK prefix. v1 and v2 rows for the same name/address compared Equal despite not being Eq-equal, so extractor .sort() left their order undefined and parallel upserts could deadlock on distinct PK tuples. Co-authored-by: Young Yang Liauw <sausagee@users.noreply.github.com>
CI Lint: apply cargo +nightly fmt so rustfmt --check passes.
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.
Bug
CurrentAnsLookupV2andCurrentAnsPrimaryNameV2derivePartialEq/Eqover all fields (includingtoken_standard) but their customOrdimplementations compared only a prefix of the Postgres primary key.Schema PKs:
current_ans_lookup_v2 (domain, subdomain, token_standard)current_ans_primary_name_v2 (registered_address, token_standard)token_standardis in the PK so v1-migrated and native v2 rows can coexist.pk()already includes it for in-memory dedup.Orddid not.Root cause
v1 and v2 rows for the same name/address are not
PartialEqequal, yetOrd::cmpreturnedEqual.parse_ansinans_extractor.rssorts these maps before upsert specifically to avoid Postgres deadlocks during parallel chunked writes (execute_in_chunksinans_storer.rs). Distinct PK tuples that compare equal have undefined relative order after.sort()(HashMap iteration), so two workers can lock(domain, subdomain, v1)vs(domain, subdomain, v2)(or the primary-name equivalent) in opposite orders and deadlock.This is not the intentional ANS domains rename, and it is not covered by PRs #16–#62.
Fix
Extend both
Ordimplementations to match the schema PK (+ token_standard). No domain/subdomain rename, no ANS table-shape change.Tests
Verified locally (rustc 1.85.0):
processors::ans::models::ans_lookup_v2::tests::ord_includes_token_standard_in_pk— okprocessors::ans::models::ans_primary_name_v2::tests::ord_includes_token_standard_in_pk— okFinished cleanly.