Google Cloud Bigtable C++ Client  2.0.0
A C++ Client Library for Google Cloud Bigtable
idempotent_mutation_policy.h
Go to the documentation of this file.
1 // Copyright 2017 Google Inc.
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 // https://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_BIGTABLE_IDEMPOTENT_MUTATION_POLICY_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_IDEMPOTENT_MUTATION_POLICY_H
17 
18 #include "google/cloud/bigtable/mutations.h"
19 #include "google/cloud/bigtable/version.h"
20 #include <memory>
21 
22 namespace google {
23 namespace cloud {
24 namespace bigtable {
26 
27 /**
28  * Defines the interface to control which mutations are idempotent and therefore
29  * can be re-tried.
30  */
32  public:
33  virtual ~IdempotentMutationPolicy() = default;
34 
35  /// Return a copy of the policy.
36  virtual std::unique_ptr<IdempotentMutationPolicy> clone() const = 0;
37 
38  /// Return true if the mutation is idempotent.
39  virtual bool is_idempotent(google::bigtable::v2::Mutation const&) = 0;
40  /// Return true if a conditional mutation is idempotent
41  virtual bool is_idempotent(
42  google::bigtable::v2::CheckAndMutateRowRequest const&) = 0;
43 };
44 
45 /// Return an instance of the default IdempotentMutationPolicy.
47 
48 /**
49  * Implements a policy that only accepts truly idempotent mutations.
50  *
51  * This policy accepts only truly idempotent mutations, that is, it rejects
52  * mutations where the server sets the timestamp. Some applications may find
53  * this too restrictive and can set their own policies if they wish.
54  */
56  public:
58 
59  std::unique_ptr<IdempotentMutationPolicy> clone() const override;
60  bool is_idempotent(google::bigtable::v2::Mutation const&) override;
62  google::bigtable::v2::CheckAndMutateRowRequest const&) override;
63 };
64 
65 /**
66  * Implements a policy that retries all mutations.
67  *
68  * Notice that this will may result in non-idempotent mutations being resent
69  * to the server. Re-trying a SetCell() mutation where the server selects the
70  * timestamp can result in multiple copies of the data stored with different
71  * timestamps. Only use this policy if your application is prepared to handle
72  * such problems, for example, by only querying the last value and setting
73  * garbage collection policies to delete the old values.
74  */
76  public:
78 
79  std::unique_ptr<IdempotentMutationPolicy> clone() const override;
80  bool is_idempotent(google::bigtable::v2::Mutation const&) override;
82  google::bigtable::v2::CheckAndMutateRowRequest const&) override;
83 };
84 
86 } // namespace bigtable
87 } // namespace cloud
88 } // namespace google
89 
90 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_IDEMPOTENT_MUTATION_POLICY_H