-
Notifications
You must be signed in to change notification settings - Fork 518
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
Negative versions #3840
Conversation
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Sprocs/GetResourceVersions.sql
Show resolved
Hide resolved
docs/BulkImport.md
Outdated
@@ -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. | |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
docs/BulkImport.md
Outdated
@@ -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. | |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
"
There was a problem hiding this 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 🦾
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Show resolved
Hide resolved
@@ -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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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"?
@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. |
b438454
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Dismissed
Show dismissed
Hide dismissed
There was a problem hiding this 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() |
There was a problem hiding this comment.
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.
No description provided.