|
| 1 | +// Copyright 2026 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 | +// 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 | +#include "google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl.h" |
| 16 | +#include "google/cloud/common_options.h" |
| 17 | +#include "google/cloud/internal/async_retry_loop.h" |
| 18 | +#include <memory> |
| 19 | +#include <utility> |
| 20 | + |
| 21 | +namespace google { |
| 22 | +namespace cloud { |
| 23 | +namespace bigtable_admin_internal { |
| 24 | +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN |
| 25 | +namespace { |
| 26 | + |
| 27 | +std::unique_ptr<bigtable_admin::BigtableTableAdminRetryPolicy> retry_policy( |
| 28 | + Options const& options) { |
| 29 | + return options.get<bigtable_admin::BigtableTableAdminRetryPolicyOption>() |
| 30 | + ->clone(); |
| 31 | +} |
| 32 | + |
| 33 | +std::unique_ptr<BackoffPolicy> backoff_policy(Options const& options) { |
| 34 | + return options.get<bigtable_admin::BigtableTableAdminBackoffPolicyOption>() |
| 35 | + ->clone(); |
| 36 | +} |
| 37 | + |
| 38 | +std::unique_ptr<bigtable_admin::BigtableTableAdminConnectionIdempotencyPolicy> |
| 39 | +idempotency_policy(Options const& options) { |
| 40 | + return options |
| 41 | + .get< |
| 42 | + bigtable_admin::BigtableTableAdminConnectionIdempotencyPolicyOption>() |
| 43 | + ->clone(); |
| 44 | +} |
| 45 | + |
| 46 | +} // namespace |
| 47 | + |
| 48 | +future<StatusOr<google::bigtable::admin::v2::CheckConsistencyResponse>> |
| 49 | +BigtableTableAdminConnectionImpl::WaitForConsistency( |
| 50 | + google::bigtable::admin::v2::CheckConsistencyRequest const& request) { |
| 51 | + auto current = google::cloud::internal::SaveCurrentOptions(); |
| 52 | + auto request_copy = request; |
| 53 | + auto const idempotent = |
| 54 | + idempotency_policy(*current)->CheckConsistency(request_copy); |
| 55 | + auto retry = retry_policy(*current); |
| 56 | + auto backoff = backoff_policy(*current); |
| 57 | + auto attempt_predicate = |
| 58 | + [](StatusOr<google::bigtable::admin::v2::CheckConsistencyResponse> const& |
| 59 | + r) { return r.ok() && r->consistent(); }; |
| 60 | + return google::cloud::internal::AsyncRetryLoop( |
| 61 | + std::move(retry), std::move(backoff), idempotent, background_->cq(), |
| 62 | + [stub = stub_]( |
| 63 | + CompletionQueue& cq, std::shared_ptr<grpc::ClientContext> context, |
| 64 | + google::cloud::internal::ImmutableOptions options, |
| 65 | + google::bigtable::admin::v2::CheckConsistencyRequest const& request) { |
| 66 | + return stub->AsyncCheckConsistency(cq, std::move(context), |
| 67 | + std::move(options), request); |
| 68 | + }, |
| 69 | + std::move(current), std::move(request_copy), __func__, |
| 70 | + std::move(attempt_predicate)); |
| 71 | +} |
| 72 | + |
| 73 | +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END |
| 74 | +} // namespace bigtable_admin_internal |
| 75 | +} // namespace cloud |
| 76 | +} // namespace google |
0 commit comments