[Openstack] [Swift] : Update Operation

John Dickinson me at not.mn
Wed Jul 19 16:49:22 UTC 2017


It depends on what you mean by "update", so let me describe the two things it could mean.

Suppose you upload cat.jpg to your cluster:

`curl -i -H "x-auth-token: foobar" https://awesome.swift.cluster.foobar/v1/AUTH_me/cats/bestcat.jpg -T cat1.jpg -XPUT`

Now you've got bestcat.jpg in your cluster.

But, oh no! You forgot to add your metadata to the picture. Let's do that:

`curl -i -H "x-auth-token: foobar" https://awesome.swift.cluster.foobar/v1/AUTH_me/cats/bestcat.jpg -XPOST -H "x-object-meta-name: mr snugglz" -H "x-object-meta-breed: tabby"`

In this case, the Swift cluster has updated the metadata, but the data itself hasn't changed or moved.[1] This operation is fast and lightweight. Note, however, that when you POST to an object, you must give the whole set of x-object-meta-* keys and values. The metadata sent to an object on POST replaces the current set.

Oh no! We mis-spelled the cat's name! Let's fix it:

`curl -i -H "x-auth-token: foobar" https://awesome.swift.cluster.foobar/v1/AUTH_me/cats/bestcat.jpg -XPOST -H "x-object-meta-name: mr snuggles" -H "x-object-meta-breed: tabby"`


Tragedy strikes again! Mr Snuggles ran into the road and was hit by a car. Tragic, yes, but you have overcome this trial and adopted a new cat from the local rescue shelter. The new cat, Ms Sunshine, is better in every possible way. We certainly can't still have a "bestcat.jpg" object that is an old pic of Mr Sunggles!

`curl -i -H "x-auth-token: foobar" https://awesome.swift.cluster.foobar/v1/AUTH_me/cats/bestcat.jpg -T cat2.jpg -H "x-object-meta-name: ms sunshine" -H "x-object-meta-birthday: July 12, 2017" -XPUT`

Now Swift as written the data of cat2.jpg and replaced the previous content that was there, along with the new metadata we set in the PUT request.

Swift is a durable storage system which means that it stores multiple copies of the data in different places. If one of those locations was offline when you did the overwrite and then came back online (e.g. a server restarting), Swift will reconcile the data asynchronously in the background. From the perspective of you the API user (or any client), bestcat.jpg has the most up to data contents and the most recent metadata.


[1] Assuming Swift 2.13.0 with default settings or Swift 2.7.0 or later with object_post_as_copy set to False.


Hope that helps

--John




On 19 Jul 2017, at 9:15, Sameer Kulkarni wrote:

> Hi All,
>
> How does update operation work in Swift?
>
> Like, does it deletes the older object and creates new entry or It finds
> out which part of object is modified and just copies or pushes the modified
> object?
>
>
> Thank you
> _______________________________________________
> Mailing list: http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
> Post to     : openstack at lists.openstack.org
> Unsubscribe : http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack/attachments/20170719/9f144181/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: OpenPGP digital signature
URL: <http://lists.openstack.org/pipermail/openstack/attachments/20170719/9f144181/attachment.sig>


More information about the Openstack mailing list