Google Cloud Bigtable C++ Client  1.1.0
A C++ Client Library for Google Cloud Bigtable
idempotent_mutation_policy.cc
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 // 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 #include "google/cloud/bigtable/idempotent_mutation_policy.h"
16 
17 namespace google {
18 namespace cloud {
19 namespace bigtable {
20 inline namespace BIGTABLE_CLIENT_NS {
21 std::unique_ptr<IdempotentMutationPolicy> DefaultIdempotentMutationPolicy() {
22  return std::unique_ptr<IdempotentMutationPolicy>(
23  new SafeIdempotentMutationPolicy);
24 }
25 
26 std::unique_ptr<IdempotentMutationPolicy> SafeIdempotentMutationPolicy::clone()
27  const {
28  return std::unique_ptr<IdempotentMutationPolicy>(
29  new SafeIdempotentMutationPolicy(*this));
30 }
31 
32 bool SafeIdempotentMutationPolicy::is_idempotent(
33  google::bigtable::v2::Mutation const& m) {
34  if (!m.has_set_cell()) {
35  return true;
36  }
37  return m.set_cell().timestamp_micros() != ServerSetTimestamp();
38 }
39 
40 bool SafeIdempotentMutationPolicy::is_idempotent(
41  google::bigtable::v2::CheckAndMutateRowRequest const&) {
42  // TODO(#1715): this is overly conservative
43  return false;
44 }
45 
46 std::unique_ptr<IdempotentMutationPolicy> AlwaysRetryMutationPolicy::clone()
47  const {
48  return std::unique_ptr<IdempotentMutationPolicy>(
49  new AlwaysRetryMutationPolicy(*this));
50 }
51 
52 bool AlwaysRetryMutationPolicy::is_idempotent(
53  google::bigtable::v2::Mutation const&) {
54  return true;
55 }
56 
57 bool AlwaysRetryMutationPolicy::is_idempotent(
58  google::bigtable::v2::CheckAndMutateRowRequest const&) {
59  return true;
60 }
61 
62 } // namespace BIGTABLE_CLIENT_NS
63 } // namespace bigtable
64 } // namespace cloud
65 } // namespace google
#define BIGTABLE_CLIENT_NS
Definition: version.h:22
Contains all the Cloud Bigtable C++ client APIs.