1. bucket 的 versioning 狀態切換
* 默認狀態 unversioned* --> versioning-enabled <--> versioning-suspended
Warning
Once you version-enable a bucket, it can never return to an unversioned state
- Objects stored in your bucket before you set the versioning state have aversion ID of null
- When you enable versioning, existing objects in your bucket do not changes
- What changes is how Amazon S3 handles the objects in future requests
- When you suspend versioning, existing objects in your bucket do not changes
- What changes is how Amazon S3 handles objects in future requests
2. add obj 操作
2.1 unversioned
- 刪除同名key的所有內容(標記爲'null'的所有 元數據 記錄)
- 插入新key的 元數據 , 標記版本爲'null'
2.2 enabled
- 不關心是否有同名key存在, 爲新key生成新的version_id 作爲其數據記錄的版本
- 不能覆蓋/刪除已經存在的 'null' version 的記錄(如果有)
- response 中有 version_id(就是新生成的那個)
2.3 suspended [2]
- 如果 'null' 版本的同名key不存在(新key或者 'null' 版本被刪除),新增加的key的版本標記爲'null'。
- 如果 'null' 版本的同名key存在,新增加的key的數據覆蓋已有的 'null' 版本數據記錄。
Note
刪除 'null' 版本的已有數據(如果有),新增內容作爲新的'null'版本的數據
- response 中 version_id 爲 None
3. delete obj 操作
3.1 unversioned
- 刪除該key版本爲'null'的記錄 (只可能有這些版本的記錄)
3.2 enabled [3]
未指定 version_id:
- 新建 delete maker,併爲 delete maker 生成新的 version_id
- response 中,version_id 非空,delete_marker爲True
指定了 version_id (要刪除該id關聯的快照或者delete marker):
- 直接刪除用戶指定版本的快照/delete marker的所有記錄
- response 中,version_id 非空(就是用戶指定的那個),delete_marker爲 False
- 對於指定 version_id 爲 'null'的場景處理相同
3.3 suspended
未指定version_id
| v3 | |null* | +------+ +------+ | null | | v3 | +------+ ==== delete ===> +------+ | v2 | | v2 | +------+ +------+ | v1 | | v1 | +------+ +------+
- 刪除 'null' 版本的記錄
- 插入一個delete marker,該marker的id爲 'null'
- response 中 delete_marker 爲 True,version_id 爲 None
Note
雖然同爲 'null',但右邊的 'null*' 已經只是一個delete marker了,沒有任何有用的用戶數據和其關聯了
Note
對於沒有指定版本的刪除請求,只能刪除'null'版本,不會刪除任何非'null'版本。如果沒有'null'版本,那麼什麼都不刪,僅僅插入'null' delete marker
指定了version_id
同3.2
4. copy obj 操作中 metadata 的處理
A: 源metadata
- A1: 用戶提供,使用用戶提供的值
- A2: 用戶指定源版本,使用源版本的值
- A3: 無用戶提示,源bucket 關閉versioning,使用源key的 null 版本
- A4: 無用戶提示,源bucket versioning suspend,使用源key的 當前 版本
- A5: 無用戶提示,源bucket versioning enabled,使用源key的 當前 版本
B: 目標metadata版本
- B1: 目標bucket versioning 關閉, insert 'null'
- B2: 目標bucket versioning supend, overwrite 'null'
- B3: 目標bucket versioning enabled,目標key的新version id
5. 訪問對象
5.1 訪問對象快照
- 未指定版本的獲取請求,訪問的是current version
- 指定版本的獲取請求,訪問的是對象的指定版本
5.2 有兩種方式將對象的非當前版本搞成當前版本
- 拷貝指定版本到相同bucket
- 永久刪除指定版本之後的所有版本
參考
[1] Using Versioning http://docs.aws.amazon.com/AmazonS3/latest/dev/Versioning.html
[2] Adding Objects to Versioning-Suspended Buckets http://docs.aws.amazon.com/AmazonS3/latest/dev/AddingObjectstoVersionSuspendedBuckets.html
[3] Deleting Object Versions http://docs.aws.amazon.com/AmazonS3/latest/dev/DeletingObjectVersions.html
[4] Deleting Objects from Versioning-Suspended Buckets http://docs.aws.amazon.com/AmazonS3/latest/dev/DeletingObjectsfromVersioningSuspendedBuckets.html
聯繫作者
楊紅剛 <[email protected]>