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

Negative versions #3840

Merged
merged 47 commits into from
May 28, 2024
Merged

Negative versions #3840

merged 47 commits into from
May 28, 2024

Conversation

SergeyGaluzo
Copy link
Contributor

No description provided.

@SergeyGaluzo SergeyGaluzo added Enhancement Enhancement on existing functionality. Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Schema Version unchanged labels May 7, 2024
@SergeyGaluzo SergeyGaluzo added this to the S138 milestone May 7, 2024
@SergeyGaluzo SergeyGaluzo requested a review from a team as a code owner May 7, 2024 00:09
@SergeyGaluzo SergeyGaluzo changed the title [Do not review] Users/sergal/importdedupping Negative versions May 8, 2024
@@ -105,7 +105,8 @@ Content-Type:application/fhir+json
| Parameter Name | Description | Card. | Accepted values |
| ----------- | ----------- | ----------- | ----------- |
| inputFormat | String representing the name of the data source format. Currently only FHIR NDJSON files are supported. | 1..1 | ```application/fhir+ndjson``` |
| mode | Import mode. Currently only initial load mode is supported. | 1..1 | For initial import use ```InitialLoad``` mode value. For incremental import mode use ```IncrementalLoad``` mode value. If no mode value is provided, IncrementalLoad mode value is considered by default. |
| mode | Import mode. | 0..1 | For initial import use ```InitialLoad``` mode value. For incremental import mode use ```IncrementalLoad``` mode value. If no mode value is provided, IncrementalLoad mode value is considered by default. |
| allowNegativeVersions | Allows FHIR server assigning negative versions for out of order processed records with explicit lastUpdated value and no version specified. | 0..1 | To enable this feature pass true. By default it is false. |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we update the flag name to "resource-versionagnostic"? So when it is set to true, this feature is enabled.

Copy link
Contributor Author

@SergeyGaluzo SergeyGaluzo May 21, 2024

Choose a reason for hiding this comment

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

This flag does not enable "version agnostic" import, because imports without input version are supported regardless of this flag. It just changes behavior of existing "version agnostic" functionality to create negative versions in case when input does not fit in contiguous space of positive versions existing in the database.

Current name directly addresses this additional functionality.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In future, we decided to got with character support for version. How will this flag consumed?

Copy link
Contributor Author

@SergeyGaluzo SergeyGaluzo May 21, 2024

Choose a reason for hiding this comment

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

When we decide to support version as string, "version agnostic" imports without version conflicts will be supported without any special flags. This will be their default behavior as there will be not any version contiguity requirements. When and if this happens, this flag will not be needed and should be deprecated.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok looks good to me

@@ -105,7 +105,8 @@ Content-Type:application/fhir+json
| Parameter Name | Description | Card. | Accepted values |
| ----------- | ----------- | ----------- | ----------- |
| inputFormat | String representing the name of the data source format. Currently only FHIR NDJSON files are supported. | 1..1 | ```application/fhir+ndjson``` |
| mode | Import mode. Currently only initial load mode is supported. | 1..1 | For initial import use ```InitialLoad``` mode value. For incremental import mode use ```IncrementalLoad``` mode value. If no mode value is provided, IncrementalLoad mode value is considered by default. |
| mode | Import mode. | 0..1 | For initial import use ```InitialLoad``` mode value. For incremental import mode use ```IncrementalLoad``` mode value. If no mode value is provided, IncrementalLoad mode value is considered by default. |
| allowNegativeVersions | Allows FHIR server assigning negative versions for out of order processed records with explicit lastUpdated value and no version specified. | 0..1 | To enable this feature pass true. By default it is false. |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the description state -" Ingests records in FHIR service based on lastUpdated value when no version is specified. In case of records ingested out of order, negative version values can be assigned.

Copy link
Contributor Author

@SergeyGaluzo SergeyGaluzo May 21, 2024

Choose a reason for hiding this comment

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

"Ingests records in FHIR service based on lastUpdated value when no version is specified"
is not limited to this new flag. This behavior exists even without it. Only in cases when there is no "room" for incoming record in positive version space this flag changes behavior from "drop on the floor with conflict" to "ingest with negative version".

We should make this clear, so customers are not confused.

If current description is not specific enough, I suggest
"
Allows FHIR server assigning negative versions for resource records with explicit lastUpdated value and no version specified when input does not fit in contiguous space of positive versions existing in the store.
"

mikaelweave
mikaelweave previously approved these changes May 20, 2024
Copy link
Contributor

@mikaelweave mikaelweave left a comment

Choose a reason for hiding this comment

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

A couple small comments but approved 🦾

@@ -379,7 +378,7 @@ await using (new Timer(async _ => await _sqlStoreClient.MergeResourcesPutTransac
return results;
}

internal async Task<IReadOnlyList<string>> ImportResourcesAsync(IReadOnlyList<ImportResource> resources, ImportMode importMode, CancellationToken cancellationToken)
internal async Task<IReadOnlyList<string>> ImportResourcesAsync(IReadOnlyList<ImportResource> resources, ImportMode importMode, bool allowNegativeVersions, CancellationToken cancellationToken)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: If we enhance this in the future with more logic, we should evaluate breaking this single unit into multiple units as long units are harder to debug/enhance without breaking.

var history = await _client.SearchAsync($"Patient/{id}/_history");
Assert.Equal(2, history.Resource.Entry.Count);
Assert.Equal("1", history.Resource.Entry[0].Resource.VersionId);
Assert.Equal("-1", history.Resource.Entry[1].Resource.VersionId);
Copy link
Contributor

Choose a reason for hiding this comment

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

@SergeyGaluzo - should this be true even if the content of the resource is the same (except for explicit vs implicit last updated)? What would the behavior be if these resources were imported "in order" or "not late"?

@SergeyGaluzo
Copy link
Contributor Author

@mikaelweave in reference to #3840 (comment)

When customer specifies last updated, he/she takes control over versioning. Only if last updated is not specified, we can do checks on data content. If we do opposite, we can run into the problem, when according to current database state a record does not need to be written, but if other late arrivals come, it makes this decision invalid.

@mikaelweave
Copy link
Contributor

mikaelweave commented May 21, 2024

@mikaelweave in reference to #3840 (comment)

When customer specifies last updated, he/she takes control over versioning. Only if last updated is not specified, we can do checks on data content. If we do opposite, we can run into the problem, when according to current database state a record does not need to be written, but if other late arrivals come, it makes this decision invalid.

I understand - if resources are imported specifying last updated, then we encounter scenarios where this is required. Since we import latest first (by last updated) in a batch, the latest one here takes version number 1.

EXPEkesheth
EXPEkesheth previously approved these changes May 21, 2024
@microsoft microsoft deleted a comment from azure-pipelines bot May 28, 2024
@SergeyGaluzo SergeyGaluzo enabled auto-merge (squash) May 28, 2024 14:38
@SergeyGaluzo SergeyGaluzo disabled auto-merge May 28, 2024 15:00
Copy link
Contributor

@mikaelweave mikaelweave left a comment

Choose a reason for hiding this comment

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

small NIT but looks great 😄

@@ -182,6 +182,151 @@ public async Task GivenIncrementalLoad_80KSurrogateIds_BadRequestIsReturned()
Assert.Contains(ImportProcessingJob.SurrogateIdsErrorMessage, await message.Content.ReadAsStringAsync());
}

[Fact]
public async Task GivenIncrementalLoad_MultipleImportsWithSameLastUpdatedAndExplicitVersion()
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT - test title doesn't match pattern. Should be
GivenIncrementalLoad_MultipleImportsWithSameLastUpdatedAndExplicitVersion_ResourceReloaded or similar.

Same for test below this one.

@SergeyGaluzo SergeyGaluzo merged commit 8968ae1 into main May 28, 2024
46 of 47 checks passed
@SergeyGaluzo SergeyGaluzo deleted the users/sergal/importdedupping branch May 28, 2024 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Enhancement Enhancement on existing functionality. Schema Version unchanged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants