Comments (4)
Hi @DaleyKD thanks for your interest in the library.
The implementation tries to clean up after itself, so currently we donβt support creating containers on the fly.
I also wanted to minimize the number of API calls on the main lock acquisition path, although in this case I suppose we could wait to catch the exception before creating the container.
What use case do you have that would make that desirable? As someone who is not an Azure expert, do you know if there is anything about container creation that would make it less desirable/harder to automate than automatic blob creation?
from distributedlock.
First, I totally misread the code path and see where you're automatically creating the blob, while I thought it was the container. My apologies.
The main reason is that I don't want to ask my customers to go in and manually create a container. I'd hope asking them to create the storage account would suffice. (If I DO have to ask them, it's not the end of the world.)
Creating a container isn't that bad. Let me see if I can find a code snippet from my other project.
Well, this is straight from MSFT and how they had us do election mutexes: https://github.com/mspnp/cloud-design-patterns/blob/master/leader-election/DistributedMutex/BlobLeaseManager.cs
At the very bottom, you see that they use a BlobContainerClient
to create the container.
I would kindly "argue" that the code should create the container if it doesn't exist, but not clean it up. Reason? In my code, we have MANY services doing leader election. We use the same container, but different blobs.
from distributedlock.
Here's what I have as a workaround:
var blobServiceClient = new BlobServiceClient(azureStorageConnectionString);
if (!blobServiceClient.GetBlobContainers().Any(x => x.Name.Equals(containerName)))
{
blobServiceClient.CreateBlobContainer(containerName);
}
services.AddAzureClients(builder =>
{
builder.AddClient<BlobContainerClient, BlobClientOptions>(options => new BlobContainerClient(azureStorageConnectionString, containerName));
});
from distributedlock.
The main reason is that I don't want to ask my customers to go in and manually create a container. I'd hope asking them to create the storage account would suffice. (If I DO have to ask them, it's not the end of the world.)
Makes sense. Also fits with one of the goals of the library which is to "just work" without extra setup on the back-end.
Well, this is straight from MSFT and how they had us do election mutexes
Nice!
I would kindly "argue" that the code should create the container if it doesn't exist, but not clean it up. Reason? In my code, we have MANY services doing leader election. We use the same container, but different blobs.
I agree. Upon consideration I think this would be good behavior to add. In fact, it is very consistent with our FileDistributedLock
which lazily creates (but does not clean up) the lock file's directory.
Is this something you'd be interested in contributing?
Implementation notes:
- Add a function
CreateContainerIfNotExistsAsync
toBlobClientWrapper
. Should usethis._blobClient.GetParentBlobContainerClient()
and should create the container with the same debugging metadata tag thatAzureBlobLeaseDistributedLock
uses when creating blobs. - In
AzureBlobLeaseDistributedLock.TryAcquireAsync
, catch the case where the container does not exist and in that condition create the container and then the blob before retrying. - Add a test case
TestWrapperCreateContainerIfNotExists
toAzureBlobLeaseDistributedLockTest
similar toTestWrapperCreateIfNotExists
(but simpler since there aren't multiple types). - Replace the test case
TestThrowsIfContainerDoesNotExist
with one calledTestCreatesContainerIfNeeded
that asserts the successful lock acquisition and that the container is not cleaned up when the lock is released. The test itself should clean up the container after the fact.
Also, at risk of stating the obvious, in the short-term you should be able to work around this by simply creating the container yourself during process spinup or right before lock acquisition.
from distributedlock.
Related Issues (20)
- Timeout exceeded when trying to acquire the lock HOT 2
- Promote all NonParallelizable tests to their own non-parallelizable fixtures and try adding Parallelizable at the fixture level
- Azure leases expire HOT 1
- Adding a synchronization channel HOT 2
- Adding logging HOT 2
- Optimize TestSetupTest.VerifyAllTestsAreCreated
- FileDistributedLock - Use FileSystemWatcher to optimize wait
- Where locks are stored when using Postgres HOT 3
- Postgres lock is not released in specific multi-threaded scenarios HOT 13
- Timeouts seems not work in DistributedLock.Redis HOT 5
- Update minimum SqlClient versions to avoid vulnerability HOT 2
- Postgres: consider leveraging batching for efficiency (newer versions only)
- Postgres: consider switching to positional parameter style
- Postgres: consider constructor with NpgsqlDatasource
- ZooKeeperNetEx connection loss issue: an acquired lock seems is not released HOT 50
- Increase in lost lock after upgrading to .NET 7, EF Core 7 and Microsoft.Data.SqlClient 5.0.1 HOT 21
- Add custom data to AzureBlobLeaseDistributedLock HOT 10
- Redis: RedisScript (LuaScript) execution error - CultureInfo problem HOT 7
- DistributedLock.Azure: Remove MaxNonInfiniteLeaseDuration HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from distributedlock.