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

[Feature]: 5959961188 - CosmosDB Optimistic concurrency through e-tags #16

Open
wants to merge 16 commits into
base: development
Choose a base branch
from

Conversation

stephanjohnson
Copy link
Contributor

Implemented Optimistic Concurrency Control functionality on the CosmosDB module.

As per this issue comment:

I would imagine, and prefer, to have the Use Optimistic Concurrency Default in the Document Database setting group. I could not figure out how to reference the module from the Intent.Modules.NET to the Intent.Modules projects without potentially breaking the build.

- Upgraded IEvangelist.Azure.CosmosRepository package version
- Added new settings class for CosmosDB module
- Updated templates to generate code supporting optimistic concurrency if enabled in settings
- Optimistic concurrency is handled using Etag property of Azure Cosmos documents
- Introduced dictionary to track Etags for each entity in the base repository class
The CosmosDB module has been updated to improve concurrency management. The 'Use Optimistic Concurrency Default' setting type has been changed from checkbox to switch, with an added hint for clarity. In the 'PopulateFromEntity' method, the parameter type was corrected. Additionally, a new statement was added in the else block of this method for better handling when not using optimistic concurrency.
All of the project, barring one (CosmosDB) have the Use Optimistic Concurrency turned off.
@stephanjohnson
Copy link
Contributor Author

@joelsteventurner please do not merge this PR, it seems I can do it now, and I am happy with the implementation. However I do have a question about Setting Group Extensions as per this comment. If you could spend 5 minutes with me tomorrow to show me how then I can complete this task

The new version introduces support for Optimistic Concurrency using ETag, enhancing the functionality of the CosmosDB module. This update follows the previous fix for an issue with nullable collections not being realized correctly in version 1.0.3.
@stephanjohnson stephanjohnson changed the title 2 feature 5959961188 [Feature]: 5959961188 - CosmosDB Optomistic concurrency through e-tags Feb 8, 2024
@stephanjohnson stephanjohnson changed the title [Feature]: 5959961188 - CosmosDB Optomistic concurrency through e-tags [Feature]: 5959961188 - CosmosDB Optimistic concurrency through e-tags Feb 8, 2024
@class.AddField("string?", "etag", field =>
{
field.Private();
field.AddAttribute($"{UseType("Newtonsoft.Json.JsonProperty")}(\"_etag\")");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to revisit this in the future. If I add the attribute to the public property, it doesn't deserialize the etag correctly when reading from the repository. This is true if I do not add the public property either. The public can also not implement the ICosmodDBDocument interface, even though that interface implements IItemWithEtag. There is also a problem when adding the interface implementation for Etag on the ICosmosDBDocument interface.

I am not happy with this implementation, but it seems to be the only combination that works. The public property for Etag below is superfluous, and is never used. It SHOULD not break the functionality to retrieve the etag if I remove this.

synchronizing branches via PR because I accidentally created the feature
branch from master and not development
Tested every test project, 
ran the integration tests for the AdvancedMappingCrud.Cosmos.Tests project in VS, 
reviewed applied all the changes that my code made (especially the HttpClient nuget version) to all test applications.
The 'GetEtag' method has been refactored to only be added when optimistic concurrency is in use. This change reduces unnecessary code and improves performance by avoiding the execution of this method when it's not needed. The 'GetEtag' method was also removed from several test repositories as part of this optimization.
"Refactored Etag retrieval for optimistic concurrency

The 'GetEtag' method has been conditionally added only when optimistic concurrency is in use. This change reduces unnecessary code execution and improves performance. The 'GetEtag' method was also removed from several test repositories as part of this optimization."
Merging from IA source
- Updated various package versions across multiple projects.
- Refactored the way Nuget dependencies are handled, now using output target to determine version.
- Made minor changes in CosmosDBRepositoryBase.cs for better code readability.
- Adjusted project GUIDs in Intent.Modules.NET.sln.
Signed-off-by: Stephan Johnson <stephanjohnson@users.noreply.github.com>
The commit includes updates to the version numbers of several modules. The changes are mainly in the .imodspec files where the version number has been incremented. Additionally, there's a change in NuGetPackages.cs file where the MicrosoftExtensionsHttp method now returns an instance of NugetPackageInfo instead of NugetPackageInfo directly. Also, it corrects the version number for when GetMaxNetAppVersion() returns (5, 0). Lastly, a reference to 'Microsoft.Extensions.Http' in a test project file was downgraded from version "8.0.0" to "7.0.0".
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.

1 participant