Skip to content

feat: added CreateIfNotExists option - #47

Open
f1nzer wants to merge 1 commit into
imranmomin:masterfrom
f1nzer:feat/create-if-not-exists
Open

feat: added CreateIfNotExists option#47
f1nzer wants to merge 1 commit into
imranmomin:masterfrom
f1nzer:feat/create-if-not-exists

Conversation

@f1nzer

@f1nzer f1nzer commented Jun 3, 2022

Copy link
Copy Markdown

It's not always neccessary to perform db initialization on every run.
Also, users might have issues with db/container/stored procedures creation when native RBAC is enabled due to management operation limitations: https://aka.ms/cosmos-native-rbac

New option CreateIfNotExists is enabled by default (to preserve the current behavior).

@imranmomin
imranmomin changed the base branch from develop to master June 7, 2022 10:35
@f1nzer
f1nzer force-pushed the feat/create-if-not-exists branch 3 times, most recently from 9511c03 to b6992fa Compare June 19, 2022 07:36
@f1nzer
f1nzer force-pushed the feat/create-if-not-exists branch from b6992fa to 7bc5c09 Compare June 19, 2022 07:37
@sergey-tihon

Copy link
Copy Markdown

@imranmomin can you please review/merge this PR?

Comment thread src/CosmosDbStorage.cs
try
{
Container = await Client.GetContainer(databaseName, containerName).ReadContainerAsync(cancellationToken: cancellationToken);
return;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Cannot exit from here, as there are some dependencies that need to be created on the container.

@f1nzer f1nzer Aug 11, 2022

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The idea behind this change is that I have a hangfire server app (responsible for job processing) and a hangfire client app (job scheduling only).

As for the hangfire server, I want to use CreateIfNotExists=true to preserve my database up-to-date with possible changes on this library side.

On the other hand, my clients are just clients, and I want to make them:

  1. use ManagedIdentity (now it supports only data-plane operations)
  2. have a fast startup/first query time (no need to upload multiple stored procedures and so on)

There is a DistributedCache library where the same flag is implemented: https://github.com/Azure/Microsoft.Extensions.Caching.Cosmos/blob/master/src/CosmosCache.cs#L447
Of course, there are no stored procedures, but the database might also be broken due to this flag (incorrect pk, etc.)

@f1nzer f1nzer Aug 11, 2022

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Anyway, another option (suggestion) is to store some kind of hash, that is based on a procedure's content as a single entry in a database (something similar to EF migration tables). So, if the hash entry is missing or the hash value differs from the calculated value then there is no need to upload stored procedures. It will use a bit more CPU time and 1 GET request instead of calling Get + Create/Replace for every procedure.

Using this hash-based approach we could get rid of several (non-friendly for RBAC) calls and speedup initialization in general.

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