Skip to content

Commit 05cb0e1

Browse files
committed
impl(bigtable): save and restore Options across query plan refresh threads
1 parent 361f9b8 commit 05cb0e1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

google/cloud/bigtable/internal/data_connection_impl.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,8 @@ StatusOr<bigtable::PreparedQuery> DataConnectionImpl::PrepareQuery(
752752
return std::move(response).status();
753753
}
754754
auto const* func = __func__;
755-
auto refresh_fn = [this, request, current, func]() mutable {
755+
auto refresh_fn = [this, request, func]() mutable {
756+
auto current = google::cloud::internal::SaveCurrentOptions();
756757
auto retry = retry_policy(*current);
757758
auto backoff = backoff_policy(*current);
758759
auto operation_context = operation_context_factory_->PrepareQuery(
@@ -834,7 +835,8 @@ future<StatusOr<bigtable::PreparedQuery>> DataConnectionImpl::AsyncPrepareQuery(
834835
return std::move(response).status();
835836
}
836837

837-
auto refresh_fn = [this, request, current, func]() mutable {
838+
auto refresh_fn = [this, request, func]() mutable {
839+
auto current = google::cloud::internal::SaveCurrentOptions();
838840
auto retry = retry_policy(*current);
839841
auto backoff = backoff_policy(*current);
840842
auto operation_context = operation_context_factory_->PrepareQuery(

google/cloud/bigtable/internal/query_plan.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ void QueryPlan::ScheduleRefresh(std::unique_lock<std::mutex> const&) {
5050
std::weak_ptr<QueryPlan> plan = shared_from_this();
5151
refresh_timer_ =
5252
cq_.MakeDeadlineTimer(refresh_deadline)
53-
.then([plan](future<StatusOr<std::chrono::system_clock::time_point>>
54-
result) {
53+
.then([plan, current = internal::SaveCurrentOptions()](
54+
future<StatusOr<std::chrono::system_clock::time_point>>
55+
result) {
56+
// Options are stored in a thread_local variable. When this timer
57+
// expires and this lambda is executed we need to restore the
58+
// Options that were saved in the capture group as a different
59+
// thread may be used.
60+
internal::OptionsSpan options_span(current);
5561
if (result.get().ok()) {
5662
if (auto p = plan.lock()) {
5763
p->ExpiredRefresh();

0 commit comments

Comments
 (0)