[DAP-5297] Backport fix for incorrect error message on duplicate key error for consistent_lookup_unique vindex #23
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.
This PR
This PR backports this bugfix from the upstream Vitess repo to v.15.0.2 of our fork. (Original bug report) In the upstream repo, the bugfix was only backported to v.17 and later. But there is precedence for backporting this fix to v.15.0.* -- it was backported to v.15.0.3 of Shopify's Vitess fork.
To summarize, in the case where a duplicate is found in a consistent lookup vindex, Vitess attempts to lock the existing row corresponding to the duplicate in the lookup table. There is a bug in a function call to ExecuteKeyspaceId within that logic, where an empty context element rather than the actual context of the request is passed in. Since the empty context element does not contain caller id information,
ExecuteKeyspaceId
returns a missing caller id error when it because it is unable to perform Access Control List checks against the caller.The fix is to pass in the request context to
ExecuteKeyspaceId
instead of the empty context object.Other context
This fix unblocks the following:
Testing
Unit tests in vitess/go/vt/vtgate/vindexes pass.
In our Vitess sandbox, I repro'd the bug and tested that the fix produced the correct
Duplicate entry...
error message instead of themissing caller id...
message. I confirmed theDuplicate entry...
error appeared when attempting to store a record that violated either UNIQUE KEY or PRIMARY KEY constraints. (Gist with manual test steps)