Skip to content

Commit d676c0a

Browse files
committed
docs: add narrative docs for conditional params
- 'if_genration_match' - 'if_genration_not_match' - 'if_metageneration_match' - 'if_metageneration_not_match' Toward #460.
1 parent 70d19e7 commit d676c0a

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

docs/generation_metageneration.rst

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
Conditional Requests Via Generation / Metageneration
2+
====================================================
3+
4+
Concepts
5+
--------
6+
7+
Metageneration
8+
::::::::::::::
9+
10+
When you create a :class:`~google.cloud.storage.bucket.Bucket`,
11+
its :attr:`~google.cloud.storage.bucket.Bucket.metageneration` is initialized
12+
to ``1``, representing the initial version of the bucket's metadata.
13+
14+
When you first upload a
15+
:class:`~google.cloud.storage.blob.Blob` ("Object" in the GCS back-end docs),
16+
its :attr:`~google.cloud.storage.blob.Blob.metageneration` is likewise
17+
initialized to ``1``. representing the initial version of the blob's metadata.
18+
19+
The ``metageneration`` attribute is set by the GCS back-end, and is read-only
20+
in the client library.
21+
22+
WHenever you patch or update the bucket / blob's metadata, its
23+
``metageneration`` is incremented.
24+
25+
Generation
26+
::::::::::
27+
28+
Each time you upload a new version of a file to a
29+
:class:`~google.cloud.storage.blob.Blob` ("Object" in the GCS back-end docs),
30+
the Blob's :attr:`~google.cloud.storage.blob.generation` is increased, and its
31+
:attr:`~google.cloud.storage.blob.metageneration` is reset to ``1`` (the first
32+
metadata version for that generation of the blob).
33+
34+
The ``generation`` attribute is set by the GCS back-end, and is read-only
35+
in the client library.
36+
37+
See also
38+
::::::::
39+
40+
- `Storage API Generation Precondition docs`_
41+
42+
.. _Storage API Generation Precondition docs:
43+
https://cloud.google.com/storage/docs/generations-preconditions
44+
45+
46+
Conditional Parameters
47+
----------------------
48+
49+
.. _using-if-generation-match:
50+
51+
Using ``if_generation_match``
52+
:::::::::::::::::::::::::::::
53+
54+
Passing the ``if_generation_match`` parameter to a method which retrieves a
55+
blob resource (e.g.,
56+
:meth:`Blob.reload <google.cloud.storage.blob.Blob.reload>`) or modifies
57+
the blob (e.g.,
58+
:meth:`Blob.update <google.cloud.storage.blob.Blob.update>`)
59+
makes the operation conditional on whether the blob's current ``generation``
60+
matches the given value.
61+
62+
As a special case, passing ``0`` as the value for``if_generation_match``
63+
makes the operation succeed only if there are no live versions of the blob.
64+
65+
66+
.. _using-if-generation-not-match:
67+
68+
Using ``if_generation_not_match``
69+
:::::::::::::::::::::::::::::::::
70+
71+
Passing the ``if_generation_not_match`` parameter to a method which retrieves
72+
a blob resource (e.g.,
73+
:meth:`Blob.reload <google.cloud.storage.blob.Blob.reload>`) or modifies
74+
the blob (e.g.,
75+
:meth:`Blob.update <google.cloud.storage.blob.Blob.update>`)
76+
makes the operation conditional on whether the blob's current ``generation``
77+
does **not** match the given value.
78+
79+
If no live version of the blob exists, the precondition fails.
80+
81+
As a special case, passing ``0`` as the value for ``if_generation_not_match``
82+
makes the operation succeed only if there **is** a live version of the blob.
83+
84+
85+
.. _using-if-metageneration-match:
86+
87+
Using ``if_metageneration_match``
88+
:::::::::::::::::::::::::::::::::
89+
90+
Passing the ``if_metageneration_match`` parameter to a method which retrieves
91+
a blob or bucket resource
92+
(e.g., :meth:`Blob.reaload <google.cloud.storage.blob.Blob.reload>`,
93+
:meth:`Bucket.reload <google.cloud.storage.bucket.Bucket.reload>`)
94+
or modifies the blob or bucket (e.g.,
95+
:meth:`Blob.update <google.cloud.storage.blob.Blob.update>`
96+
:meth:`Bucket.patch <google.cloud.storage.bucket.Bucket.patch>`)
97+
makes the operation conditional on whether the resource's current
98+
``metageneration`` matches the given value.
99+
100+
101+
.. _using-if-metageneration-not-match:
102+
103+
Using ``if_metageneration_not_match``
104+
:::::::::::::::::::::::::::::::::::::
105+
106+
Passing the ``if_metageneration_not_match`` parameter to a method which
107+
retrieves a blob or bucket resource
108+
(e.g., :meth:`Blob.reaload <google.cloud.storage.blob.Blob.reload>`,
109+
:meth:`Bucket.reload <google.cloud.storage.bucket.Bucket.reload>`)
110+
or modifies the blob or bucket (e.g.,
111+
:meth:`Blob.update <google.cloud.storage.blob.Blob.update>`
112+
:meth:`Bucket.patch <google.cloud.storage.bucket.Bucket.patch>`)
113+
makes the operation conditional on whether the resource's current
114+
``metageneration`` does **not** match the given value.

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ API Reference
2222
hmac_key
2323
notification
2424
retry_timeout
25+
generation_metageneration
2526

2627
Changelog
2728
---------

0 commit comments

Comments
 (0)