-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
impl: add Await methods to poll already started LRO #14329
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #14329 +/- ##
==========================================
+ Coverage 93.22% 93.23% +0.01%
==========================================
Files 2181 2181
Lines 191155 191451 +296
==========================================
+ Hits 178203 178500 +297
+ Misses 12952 12951 -1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see how this is expedient. It does introduce some extra layers of indirection (at non-zero cost).
If you would rather do this refactoring later, I understand, please open a bug and leave some TODO comments.
using ::google::longrunning::Operation; | ||
auto loc = std::string{location}; | ||
return AsyncPollingLoop(std::move(cq), std::move(options), | ||
make_ready_future(StatusOr<Operation>(operation)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should add an overload to AsyncPollingLoop::Start()
that consumes the operation directly, that is, take this code:
future<StatusOr<Operation>> Start(future<StatusOr<Operation>> op) { |
And include something like:
future<StatusOr<Operation>> Start(future<StatusOr<Operation>> op) {
auto self = shared_from_this();
return op.then([self](auto f) { return self->Start(op.get(); }
}
future<StatusOr<Operation>> Start(StatusOr<Operation> op) {
auto self = shared_from_this();
auto w = WeakFromThis();
promise_ = promise<StatusOr<Operation>>([w, c = CallContext{}]() mutable {
if (auto self = w.lock()) {
ScopedCallContext scope(std::move(c));
self->DoCancel();
}
});
self->OnStart(f.get());
return promise_.get_future();
}
Eventually we should reimplement AsyncLongRunningOperation()
using AsyncAwaitLongRunningOperation
()and remove the existing
AsyncPollingLoop()` overload.
Something like:
future<StatusOr<ReturnType>> AsyncLongRunningOperation(
google::cloud::CompletionQueue cq, ImmutableOptions options,
RequestType&& request, StartFunctor&& start,
AsyncPollLongRunningOperation poll, AsyncCancelLongRunningOperation cancel,
LongRunningOperationValueExtractor<ReturnType> value_extractor,
std::unique_ptr<RetryPolicyType> retry_policy,
std::unique_ptr<BackoffPolicy> backoff_policy, Idempotency idempotent,
std::unique_ptr<PollingPolicy> polling_policy, char const* location) {
using ::google::longrunning::Operation;
auto operation =
AsyncRetryLoop(std::move(retry_policy), std::move(backoff_policy),
idempotent, cq, std::forward<StartFunctor>(start), options,
std::forward<RequestType>(request), location);
auto loc = std::string{location};
return operation.then([=](auto f) mutable {
return AsyncAwaitLongRunningOperation(
std::move(cq), std::move(options),
f.get(), // note we pass the `StatusOr<T>` and not a future
std::move(poll),
std::move(cancel), std::move(polling_policy),
std::move(location))
});
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 6 files reviewed, 1 unresolved discussion (waiting on @coryan)
google/cloud/internal/async_long_running_operation.h
line 163 at r1 (raw file):
Previously, coryan (Carlos O'Ryan) wrote…
I think you should add an overload to
AsyncPollingLoop::Start()
that consumes the operation directly, that is, take this code:
future<StatusOr<Operation>> Start(future<StatusOr<Operation>> op) { And include something like:
future<StatusOr<Operation>> Start(future<StatusOr<Operation>> op) { auto self = shared_from_this(); return op.then([self](auto f) { return self->Start(op.get(); } } future<StatusOr<Operation>> Start(StatusOr<Operation> op) { auto self = shared_from_this(); auto w = WeakFromThis(); promise_ = promise<StatusOr<Operation>>([w, c = CallContext{}]() mutable { if (auto self = w.lock()) { ScopedCallContext scope(std::move(c)); self->DoCancel(); } }); self->OnStart(f.get()); return promise_.get_future(); }Eventually we should reimplement
AsyncLongRunningOperation()
usingAsyncAwaitLongRunningOperation
()and remove the existing
AsyncPollingLoop()` overload.Something like:
future<StatusOr<ReturnType>> AsyncLongRunningOperation( google::cloud::CompletionQueue cq, ImmutableOptions options, RequestType&& request, StartFunctor&& start, AsyncPollLongRunningOperation poll, AsyncCancelLongRunningOperation cancel, LongRunningOperationValueExtractor<ReturnType> value_extractor, std::unique_ptr<RetryPolicyType> retry_policy, std::unique_ptr<BackoffPolicy> backoff_policy, Idempotency idempotent, std::unique_ptr<PollingPolicy> polling_policy, char const* location) { using ::google::longrunning::Operation; auto operation = AsyncRetryLoop(std::move(retry_policy), std::move(backoff_policy), idempotent, cq, std::forward<StartFunctor>(start), options, std::forward<RequestType>(request), location); auto loc = std::string{location}; return operation.then([=](auto f) mutable { return AsyncAwaitLongRunningOperation( std::move(cq), std::move(options), f.get(), // note we pass the `StatusOr<T>` and not a future std::move(poll), std::move(cancel), std::move(polling_policy), std::move(location)) }); }
Assuming the unit tests in async_polling_loop_test are correct, attempting to consume the Operation directly alters the sequence of setting up the promise and returned future from Start such that in tests that attempt to cancel the operation, the AsyncCancelOperation method never gets called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 6 of 6 files at r1, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @scotthart)
google/cloud/internal/async_long_running_operation.h
line 163 at r1 (raw file):
Previously, scotthart (Scott Hart) wrote…
Assuming the unit tests in async_polling_loop_test are correct, attempting to consume the Operation directly alters the sequence of setting up the promise and returned future from Start such that in tests that attempt to cancel the operation, the AsyncCancelOperation method never gets called.
Fair enough, we can do the refactoring in a future PR.
part of the work for #7658
Add variations of existing
AsyncLongRunningOperation
template functions that do not start the LRO, but accept an Operation type from an already started LRO.This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)