On my local machine I can do mkdir
and trust that this operation is atomic. I can thus use it as a lock. Can I similarly use mkdir
on an EC2 instance with EBS attached and have it be atomic?
For further context, I am thinking of a situation where I have multiple Kubernetes Pods running on a Kubernetes Node with one persistentVolume
(AWS EBS) between them. If one of these pods is looking to get exclusive access to a folder in this volume, can it do so? The pods are sharing read-only data, but I to trigger an aws s3 sync
only once per week, not once-per-pod-per-week.
Since EBS is not a filesystem...
Amazon Elastic Block Store (Amazon EBS) provides block level storage volumes for use with EC2 instances.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html
...there is no direct answer to the question, because it isn't the correct question. EBS -- as a block device -- is not responsible for or even aware of the actual filesystem operations or its guarantees.
tl;dr: If mkdir()
is atomic in the filesystem you are using, then it will still be atomic if that filesystem is on an EBS volume.
Whether using mkdir()
for locking is a good practice is a different question.