Google Cloud Storage C++ Client  1.32.1
A C++ Client Library for Google Cloud Storage
idempotency_policy.h
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_IDEMPOTENCY_POLICY_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_IDEMPOTENCY_POLICY_H
17 
18 #include "google/cloud/storage/internal/bucket_acl_requests.h"
19 #include "google/cloud/storage/internal/bucket_requests.h"
20 #include "google/cloud/storage/internal/default_object_acl_requests.h"
21 #include "google/cloud/storage/internal/hmac_key_requests.h"
22 #include "google/cloud/storage/internal/notification_requests.h"
23 #include "google/cloud/storage/internal/object_acl_requests.h"
24 #include "google/cloud/storage/internal/object_requests.h"
25 #include "google/cloud/storage/internal/service_account_requests.h"
26 #include "google/cloud/storage/internal/sign_blob_requests.h"
27 #include "google/cloud/storage/version.h"
28 #include <memory>
29 
30 namespace google {
31 namespace cloud {
32 namespace storage {
33 inline namespace STORAGE_CLIENT_NS {
34 /**
35  * Define the interface for the idempotency policy.
36  *
37  * The idempotency policy controls which requests are treated as idempotent and
38  * therefore safe to retry on a transient failure. Non-idempotent operations can
39  * result in data loss. For example, consider `DeleteObject()`, if this
40  * operation is called without pre-conditions retrying this operation may delete
41  * more than one version of an object, which may not have the desired effect.
42  * Even operations that "add" data can result in data loss, consider
43  * `InsertObjectMedia()`, if called without pre-conditions retrying this
44  * operation will insert multiple new versions, possibly deleting old data if
45  * the bucket is configured to keep only N versions of each object.
46  *
47  * Some applications are designed to handle duplicate requests without data
48  * loss, or the library may be used in an environment where the risk of data
49  * loss due to duplicate requests is negligible or zero.
50  *
51  * This policy allows application developers to control the behavior of the
52  * library with respect to retrying non-idempotent operations. Application
53  * developers can configure the library to only retry operations that are known
54  * to be idempotent (that is, they will succeed only once). Application may also
55  * configure the library to retry all operations, regardless of whether the
56  * operations are idempotent or not.
57  */
59  public:
60  virtual ~IdempotencyPolicy() = default;
61 
62  /// Create a new copy of this object.
63  virtual std::unique_ptr<IdempotencyPolicy> clone() const = 0;
64 
65  //@{
66  /// @name Bucket resource operations
67  virtual bool IsIdempotent(
68  internal::ListBucketsRequest const& request) const = 0;
69  virtual bool IsIdempotent(
70  internal::CreateBucketRequest const& request) const = 0;
71  virtual bool IsIdempotent(
72  internal::GetBucketMetadataRequest const& request) const = 0;
73  virtual bool IsIdempotent(
74  internal::DeleteBucketRequest const& request) const = 0;
75  virtual bool IsIdempotent(
76  internal::UpdateBucketRequest const& request) const = 0;
77  virtual bool IsIdempotent(
78  internal::PatchBucketRequest const& request) const = 0;
79  virtual bool IsIdempotent(
80  internal::GetBucketIamPolicyRequest const& request) const = 0;
81  virtual bool IsIdempotent(
82  internal::SetBucketIamPolicyRequest const& request) const = 0;
83  virtual bool IsIdempotent(
84  internal::SetNativeBucketIamPolicyRequest const& request) const = 0;
85  virtual bool IsIdempotent(
86  internal::TestBucketIamPermissionsRequest const& request) const = 0;
87  virtual bool IsIdempotent(
88  internal::LockBucketRetentionPolicyRequest const& request) const = 0;
89  //@}
90 
91  //@{
92  /// @name Object resource operations
93  virtual bool IsIdempotent(
94  internal::InsertObjectMediaRequest const& request) const = 0;
95  virtual bool IsIdempotent(
96  internal::CopyObjectRequest const& request) const = 0;
97  virtual bool IsIdempotent(
98  internal::GetObjectMetadataRequest const& request) const = 0;
99  virtual bool IsIdempotent(
100  internal::ReadObjectRangeRequest const& request) const = 0;
101  virtual bool IsIdempotent(
102  internal::ListObjectsRequest const& request) const = 0;
103  virtual bool IsIdempotent(
104  internal::DeleteObjectRequest const& request) const = 0;
105  virtual bool IsIdempotent(
106  internal::UpdateObjectRequest const& request) const = 0;
107  virtual bool IsIdempotent(
108  internal::PatchObjectRequest const& request) const = 0;
109  virtual bool IsIdempotent(
110  internal::ComposeObjectRequest const& request) const = 0;
111  virtual bool IsIdempotent(
112  internal::RewriteObjectRequest const& request) const = 0;
113  virtual bool IsIdempotent(
114  internal::ResumableUploadRequest const& request) const = 0;
115  virtual bool IsIdempotent(
116  internal::UploadChunkRequest const& request) const = 0;
117  //@}
118 
119  //@{
120  /// @name BucketAccessControls resource operations
121  virtual bool IsIdempotent(
122  internal::ListBucketAclRequest const& request) const = 0;
123  virtual bool IsIdempotent(
124  internal::CreateBucketAclRequest const& request) const = 0;
125  virtual bool IsIdempotent(
126  internal::DeleteBucketAclRequest const& request) const = 0;
127  virtual bool IsIdempotent(
128  internal::GetBucketAclRequest const& request) const = 0;
129  virtual bool IsIdempotent(
130  internal::UpdateBucketAclRequest const& request) const = 0;
131  virtual bool IsIdempotent(
132  internal::PatchBucketAclRequest const& request) const = 0;
133  //@}
134 
135  //@{
136  /// @name ObjectAccessControls operations
137  virtual bool IsIdempotent(
138  internal::ListObjectAclRequest const& request) const = 0;
139  virtual bool IsIdempotent(
140  internal::CreateObjectAclRequest const& request) const = 0;
141  virtual bool IsIdempotent(
142  internal::DeleteObjectAclRequest const& request) const = 0;
143  virtual bool IsIdempotent(
144  internal::GetObjectAclRequest const& request) const = 0;
145  virtual bool IsIdempotent(
146  internal::UpdateObjectAclRequest const& request) const = 0;
147  virtual bool IsIdempotent(
148  internal::PatchObjectAclRequest const& request) const = 0;
149  //@}
150 
151  //@{
152  /// @name DefaultObjectAccessControls operations.
153  virtual bool IsIdempotent(
154  internal::ListDefaultObjectAclRequest const& request) const = 0;
155  virtual bool IsIdempotent(
156  internal::CreateDefaultObjectAclRequest const& request) const = 0;
157  virtual bool IsIdempotent(
158  internal::DeleteDefaultObjectAclRequest const& request) const = 0;
159  virtual bool IsIdempotent(
160  internal::GetDefaultObjectAclRequest const& request) const = 0;
161  virtual bool IsIdempotent(
162  internal::UpdateDefaultObjectAclRequest const& request) const = 0;
163  virtual bool IsIdempotent(
164  internal::PatchDefaultObjectAclRequest const& request) const = 0;
165  //@}
166 
167  //@{
168  virtual bool IsIdempotent(
169  internal::GetProjectServiceAccountRequest const& request) const = 0;
170  virtual bool IsIdempotent(
171  internal::ListHmacKeysRequest const& request) const = 0;
172  virtual bool IsIdempotent(
173  internal::CreateHmacKeyRequest const& request) const = 0;
174  virtual bool IsIdempotent(
175  internal::DeleteHmacKeyRequest const& request) const = 0;
176  virtual bool IsIdempotent(
177  internal::GetHmacKeyRequest const& request) const = 0;
178  virtual bool IsIdempotent(
179  internal::UpdateHmacKeyRequest const& request) const = 0;
180  virtual bool IsIdempotent(internal::SignBlobRequest const& request) const = 0;
181  //@}
182 
183  //@{
184  virtual bool IsIdempotent(
185  internal::ListNotificationsRequest const& request) const = 0;
186  virtual bool IsIdempotent(
187  internal::CreateNotificationRequest const& request) const = 0;
188  virtual bool IsIdempotent(
189  internal::GetNotificationRequest const& request) const = 0;
190  virtual bool IsIdempotent(
191  internal::DeleteNotificationRequest const& request) const = 0;
192  //@}
193 };
194 
195 /**
196  * A IdempotencyPolicy that always retries all requests.
197  */
199  public:
201 
202  std::unique_ptr<IdempotencyPolicy> clone() const override;
203 
204  //@{
205  /// @name Bucket resource operations
206  bool IsIdempotent(internal::ListBucketsRequest const& request) const override;
207  bool IsIdempotent(
208  internal::CreateBucketRequest const& request) const override;
209  bool IsIdempotent(
210  internal::GetBucketMetadataRequest const& request) const override;
211  bool IsIdempotent(
212  internal::DeleteBucketRequest const& request) const override;
213  bool IsIdempotent(
214  internal::UpdateBucketRequest const& request) const override;
215  bool IsIdempotent(internal::PatchBucketRequest const& request) const override;
216  bool IsIdempotent(
217  internal::GetBucketIamPolicyRequest const& request) const override;
218  bool IsIdempotent(
219  internal::SetBucketIamPolicyRequest const& request) const override;
220  bool IsIdempotent(
221  internal::SetNativeBucketIamPolicyRequest const& request) const override;
222  bool IsIdempotent(
223  internal::TestBucketIamPermissionsRequest const& request) const override;
224  bool IsIdempotent(
225  internal::LockBucketRetentionPolicyRequest const& request) const override;
226  //@}
227 
228  //@{
229  /// @name Object resource operations
230  bool IsIdempotent(
231  internal::InsertObjectMediaRequest const& request) const override;
232  bool IsIdempotent(internal::CopyObjectRequest const& request) const override;
233  bool IsIdempotent(
234  internal::GetObjectMetadataRequest const& request) const override;
235  bool IsIdempotent(
236  internal::ReadObjectRangeRequest const& request) const override;
237  bool IsIdempotent(internal::ListObjectsRequest const& request) const override;
238  bool IsIdempotent(
239  internal::DeleteObjectRequest const& request) const override;
240  bool IsIdempotent(
241  internal::UpdateObjectRequest const& request) const override;
242  bool IsIdempotent(internal::PatchObjectRequest const& request) const override;
243  bool IsIdempotent(
244  internal::ComposeObjectRequest const& request) const override;
245  bool IsIdempotent(
246  internal::RewriteObjectRequest const& request) const override;
247  bool IsIdempotent(
248  internal::ResumableUploadRequest const& request) const override;
249  bool IsIdempotent(internal::UploadChunkRequest const& request) const override;
250  //@}
251 
252  //@{
253  /// @name BucketAccessControls resource operations
254  bool IsIdempotent(
255  internal::ListBucketAclRequest const& request) const override;
256  bool IsIdempotent(
257  internal::CreateBucketAclRequest const& request) const override;
258  bool IsIdempotent(
259  internal::DeleteBucketAclRequest const& request) const override;
260  bool IsIdempotent(
261  internal::GetBucketAclRequest const& request) const override;
262  bool IsIdempotent(
263  internal::UpdateBucketAclRequest const& request) const override;
264  bool IsIdempotent(
265  internal::PatchBucketAclRequest const& request) const override;
266  //@}
267 
268  //@{
269  /// @name ObjectAccessControls operations
270  bool IsIdempotent(
271  internal::ListObjectAclRequest const& request) const override;
272  bool IsIdempotent(
273  internal::CreateObjectAclRequest const& request) const override;
274  bool IsIdempotent(
275  internal::DeleteObjectAclRequest const& request) const override;
276  bool IsIdempotent(
277  internal::GetObjectAclRequest const& request) const override;
278  bool IsIdempotent(
279  internal::UpdateObjectAclRequest const& request) const override;
280  bool IsIdempotent(
281  internal::PatchObjectAclRequest const& request) const override;
282  //@}
283 
284  //@{
285  /// @name DefaultObjectAccessControls operations.
286  bool IsIdempotent(
287  internal::ListDefaultObjectAclRequest const& request) const override;
288  bool IsIdempotent(
289  internal::CreateDefaultObjectAclRequest const& request) const override;
290  bool IsIdempotent(
291  internal::DeleteDefaultObjectAclRequest const& request) const override;
292  bool IsIdempotent(
293  internal::GetDefaultObjectAclRequest const& request) const override;
294  bool IsIdempotent(
295  internal::UpdateDefaultObjectAclRequest const& request) const override;
296  bool IsIdempotent(
297  internal::PatchDefaultObjectAclRequest const& request) const override;
298  //@}
299 
300  //@{
301  bool IsIdempotent(
302  internal::GetProjectServiceAccountRequest const& request) const override;
303  bool IsIdempotent(
304  internal::ListHmacKeysRequest const& request) const override;
305  bool IsIdempotent(
306  internal::CreateHmacKeyRequest const& request) const override;
307  bool IsIdempotent(
308  internal::DeleteHmacKeyRequest const& request) const override;
309  bool IsIdempotent(internal::GetHmacKeyRequest const& request) const override;
310  bool IsIdempotent(
311  internal::UpdateHmacKeyRequest const& request) const override;
312  bool IsIdempotent(internal::SignBlobRequest const& request) const override;
313  //@}
314 
315  //@{
316  bool IsIdempotent(
317  internal::ListNotificationsRequest const& request) const override;
318  bool IsIdempotent(
319  internal::CreateNotificationRequest const& request) const override;
320  bool IsIdempotent(
321  internal::GetNotificationRequest const& request) const override;
322  bool IsIdempotent(
323  internal::DeleteNotificationRequest const& request) const override;
324  //@}
325 };
326 
327 /**
328  * A IdempotencyPolicy that only retries strictly idempotent requests.
329  */
331  public:
333 
334  std::unique_ptr<IdempotencyPolicy> clone() const override;
335 
336  //@{
337  /// @name Bucket resource operations
338  bool IsIdempotent(internal::ListBucketsRequest const& request) const override;
339  bool IsIdempotent(
340  internal::CreateBucketRequest const& request) const override;
341  bool IsIdempotent(
342  internal::GetBucketMetadataRequest const& request) const override;
343  bool IsIdempotent(
344  internal::DeleteBucketRequest const& request) const override;
345  bool IsIdempotent(
346  internal::UpdateBucketRequest const& request) const override;
347  bool IsIdempotent(internal::PatchBucketRequest const& request) const override;
348  bool IsIdempotent(
349  internal::GetBucketIamPolicyRequest const& request) const override;
350  bool IsIdempotent(
351  internal::SetBucketIamPolicyRequest const& request) const override;
352  bool IsIdempotent(
353  internal::SetNativeBucketIamPolicyRequest const& request) const override;
354  bool IsIdempotent(
355  internal::TestBucketIamPermissionsRequest const& request) const override;
356  bool IsIdempotent(
357  internal::LockBucketRetentionPolicyRequest const& request) const override;
358  //@}
359 
360  //@{
361  /// @name Object resource operations
362  bool IsIdempotent(
363  internal::InsertObjectMediaRequest const& request) const override;
364  bool IsIdempotent(internal::CopyObjectRequest const& request) const override;
365  bool IsIdempotent(
366  internal::GetObjectMetadataRequest const& request) const override;
367  bool IsIdempotent(
368  internal::ReadObjectRangeRequest const& request) const override;
369  bool IsIdempotent(internal::ListObjectsRequest const& request) const override;
370  bool IsIdempotent(
371  internal::DeleteObjectRequest const& request) const override;
372  bool IsIdempotent(
373  internal::UpdateObjectRequest const& request) const override;
374  bool IsIdempotent(internal::PatchObjectRequest const& request) const override;
375  bool IsIdempotent(
376  internal::ComposeObjectRequest const& request) const override;
377  bool IsIdempotent(
378  internal::RewriteObjectRequest const& request) const override;
379  bool IsIdempotent(
380  internal::ResumableUploadRequest const& request) const override;
381  bool IsIdempotent(internal::UploadChunkRequest const& request) const override;
382  //@}
383 
384  //@{
385  /// @name BucketAccessControls resource operations
386  bool IsIdempotent(
387  internal::ListBucketAclRequest const& request) const override;
388  bool IsIdempotent(
389  internal::CreateBucketAclRequest const& request) const override;
390  bool IsIdempotent(
391  internal::DeleteBucketAclRequest const& request) const override;
392  bool IsIdempotent(
393  internal::GetBucketAclRequest const& request) const override;
394  bool IsIdempotent(
395  internal::UpdateBucketAclRequest const& request) const override;
396  bool IsIdempotent(
397  internal::PatchBucketAclRequest const& request) const override;
398  //@}
399 
400  //@{
401  /// @name ObjectAccessControls operations
402  bool IsIdempotent(
403  internal::ListObjectAclRequest const& request) const override;
404  bool IsIdempotent(
405  internal::CreateObjectAclRequest const& request) const override;
406  bool IsIdempotent(
407  internal::DeleteObjectAclRequest const& request) const override;
408  bool IsIdempotent(
409  internal::GetObjectAclRequest const& request) const override;
410  bool IsIdempotent(
411  internal::UpdateObjectAclRequest const& request) const override;
412  bool IsIdempotent(
413  internal::PatchObjectAclRequest const& request) const override;
414  //@}
415 
416  //@{
417  /// @name DefaultObjectAccessControls operations.
418  bool IsIdempotent(
419  internal::ListDefaultObjectAclRequest const& request) const override;
420  bool IsIdempotent(
421  internal::CreateDefaultObjectAclRequest const& request) const override;
422  bool IsIdempotent(
423  internal::DeleteDefaultObjectAclRequest const& request) const override;
424  bool IsIdempotent(
425  internal::GetDefaultObjectAclRequest const& request) const override;
426  bool IsIdempotent(
427  internal::UpdateDefaultObjectAclRequest const& request) const override;
428  bool IsIdempotent(
429  internal::PatchDefaultObjectAclRequest const& request) const override;
430  //@}
431 
432  //@{
433  bool IsIdempotent(
434  internal::GetProjectServiceAccountRequest const& request) const override;
435  bool IsIdempotent(
436  internal::ListHmacKeysRequest const& request) const override;
437  bool IsIdempotent(
438  internal::CreateHmacKeyRequest const& request) const override;
439  bool IsIdempotent(
440  internal::DeleteHmacKeyRequest const& request) const override;
441  bool IsIdempotent(internal::GetHmacKeyRequest const& request) const override;
442  bool IsIdempotent(
443  internal::UpdateHmacKeyRequest const& request) const override;
444  bool IsIdempotent(internal::SignBlobRequest const& request) const override;
445  //@}
446 
447  //@{
448  bool IsIdempotent(
449  internal::ListNotificationsRequest const& request) const override;
450  bool IsIdempotent(
451  internal::CreateNotificationRequest const& request) const override;
452  bool IsIdempotent(
453  internal::GetNotificationRequest const& request) const override;
454  bool IsIdempotent(
455  internal::DeleteNotificationRequest const& request) const override;
456  //@}
457 };
458 
459 } // namespace STORAGE_CLIENT_NS
460 } // namespace storage
461 } // namespace cloud
462 } // namespace google
463 
464 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_IDEMPOTENCY_POLICY_H