What's the recommended way to implement a simple locking mechanism to be used in conjunction with S3?
Example of what I want to do:
Ideally looking for a cloud based locking mechanism. I could use memcached locally, but then I have to deal with scaling that. I don't see an obvious way to implement lightweight locking with any AWS APIs, but it seems like a common problem.
I wonder if you could use SimpleDB to do an atomic acquire lock operation. Has anyone tried that?
When you lock an object version, Amazon S3 stores the lock information in the metadata for that object version. Placing a retention period or legal hold on an object protects only the version specified in the request. It doesn't prevent new versions of the object from being created.
Object Lock is an Amazon S3 feature that blocks object version deletion during a user-defined retention period, to enforce retention policies as an additional layer of data protection and/or for strict regulatory compliance.
There is no additional charge for using this feature – so go on and add some retention dates to your objects in S3. Many AWS customers use AWS' WORM storage capabilities (S3 Glacier Vault Lock and S3 Object Lock) today.
You can only enable Object Lock for new buckets. If you want to turn on Object Lock for an existing bucket, contact AWS Support. When you create a bucket with Object Lock enabled, Amazon S3 automatically enables versioning for the bucket.
Ok, I spent some time this morning playing with boto and I think I have a solution that works using SimpleDB. You need the latest boto release so that conditional puts and consistent reads are supported.
Example code here: http://pastebin.com/3XzhPqfY
Please post comments/suggestions. I believe this code should be fairly safe -- my test in main() tries it with 10 threads.
One thing I haven't addressed is that S3 reads are not consistent (right?), so in theory a thread may be operating on an old copy of the S3 value. It looks like there may be a workaround for that as described here:
http://www.shlomoswidler.com/2009/12/read-after-write-consistency-in-amazon.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With