Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reindexes rest of batch if one resource fails #2118

Merged
merged 9 commits into from
Aug 2, 2021

Conversation

rotodd
Copy link
Contributor

@rotodd rotodd commented Jul 26, 2021

Description

Prior to this PR, when one resource failed to reindex due to a versioning conflict, the entire batch would fail.

Now, the remaining resources in the batch are reindexed. The query will be retried, fetching the most recent version of the failed resource from the database. In the rare scenario where all consecutive retry attempts fail, the reindexing operation will fail with the following error message:

2021-07-26 09_56_20-Response(241ms) - Visual Studio Code

Related issues

Addresses AB#79925

Testing

  • Manually edited database to create version conflicts and confirming appropriate failure behaviour
  • Performed schema upgrades to ensure compatibility

Next steps

When one or more resources in a batch initially fail to reindex but succeed on later attempts, the reindex job progress does not pick up the resources that succeeded on the first attempt. I created AB#83909 to track this.

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 50 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • ✅ Tag the PR with the type of update: Bug, Dependencies, Enhancement, or New-Feature
  • ✅ Tag the PR with Azure API for FHIR if this will release to the managed service
  • Review squash-merge requirements

Semver Change (docs)

Patch (new schema version)

@rotodd rotodd requested a review from a team as a code owner July 26, 2021 17:27
Comment on lines 95 to 111
DECLARE @resourcesNotInDatabase int
SET @resourcesNotInDatabase = (SELECT COUNT(*) FROM @computedValues WHERE ResourceSurrogateId IS NULL)

IF (@resourcesNotInDatabase > 0) BEGIN
-- We can't reindex resources that do not exist
DELETE FROM @computedValues
WHERE ResourceSurrogateId IS NULL
END

DECLARE @versionDiff int
SET @versionDiff = (SELECT COUNT(*) FROM @computedValues WHERE VersionProvided IS NOT NULL AND VersionProvided <> VersionInDatabase)

IF (@versionDiff > 0) BEGIN
-- Don't reindex resources that have outdated versions
DELETE FROM @computedValues
WHERE VersionProvided IS NOT NULL AND VersionProvided <> VersionInDatabase
END
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of throwing exceptions here, we simply remove the resources from @computedValues, the table of resources to be reindexed.

Comment on lines 351 to 352
// TODO: Return total number of successfully reindexed resources.
int numberOfDeletedResources = sqlDataReader.GetInt32(1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBD in AB#83909.

@lgtm-com
Copy link

lgtm-com bot commented Jul 27, 2021

This pull request introduces 1 alert when merging 5d8b004 into 2f0d55d - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

var issue = new OperationOutcomeIssue(
OperationOutcomeConstants.IssueSeverity.Error,
OperationOutcomeConstants.IssueType.Exception,
ex.Message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ex

If it was FhirException I think it would be ok to push it to user, but this is generic exception.

What user suppose to do with it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I am currently using this to pass an action item to the user on PreconditionFailed exceptions, but I can see how this might lead to us sending info to the user that wouldn't be helpful. Working on finding a nice fix now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an extra catch block in 52ea697.

Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@rotodd
Copy link
Contributor Author

rotodd commented Aug 2, 2021

/azp run

@azure-pipelines
Copy link

Pull request contains merge conflicts.

@rotodd rotodd merged commit 58f35a4 into main Aug 2, 2021
@rotodd rotodd deleted the personal/rotodd/add-sql-retry-logic branch August 2, 2021 22:54
-- @tokenNumberNumberCompositeSearchParams
-- * Extracted token$number$number search params
--
CREATE OR ALTER PROCEDURE dbo.ReindexResource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask why it doesn't upgrade version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants