简体   繁体   中英

Is there optimistic locking in AWS S3?

I have an excel file within s3. Since different programs read and write it, I need to guarantee that each of them is writing to the version they read.

S3 only guarantees read after write consistency for newly created objects, and eventual consistency for overwriting and deleting objects. If your excel file is small enough (less than 400kb), you could store it in a binary attribute of a DynamoDB item and use conditional updates on a version attribute to ensure read after write consistency for the file. Otherwise, of the file is bigger than 400kb, you could upload each version of the file to a new key in s3 and then track the s3 URL to latest version of the file in a versioned DynamoDB item.

This is not possible with S3.

Specifically, it is impossible to determine conclusively and authoritatively whether the current version visible to you is not already in the process of being overwritten, or may have been very recently overwritten... because the overwrite in progress does not disturb the current version until it is complete or a short time later , because of the eventual consistency model of overwrites.

This is even true when bucket versioning is not enabled. It is sometimes possible to overwrite an object and still download the previous version for a brief time after the overwrite is complete.

GET and HEAD and ListObjects are all eventually consistent.

Since 2020, AWS is strongly consistent and you can use standard HTTP header If-Match to implement optimistic locking.

https://aws.amazon.com/es/blogs/aws/amazon-s3-update-strong-read-after-write-consistency/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM