Skip to content
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

fix(pubsub): dont move PublisherOptions that we are still using #7270

Merged
merged 3 commits into from
Sep 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions google/cloud/pubsub/publisher_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,12 @@ std::shared_ptr<pubsub::PublisherConnection> MakePublisherConnection(
if (options.message_ordering()) {
auto factory = [topic, options, sink, cq](std::string const& key) {
return BatchingPublisherConnection::Create(
topic, options, key, SequentialBatchSink::Create(std::move(sink)),
cq);
topic, options, key, SequentialBatchSink::Create(sink), cq);
};
return OrderingKeyPublisherConnection::Create(std::move(factory));
}
return RejectsWithOrderingKey::Create(BatchingPublisherConnection::Create(
std::move(topic), std::move(options), {}, sink, std::move(cq)));
std::move(topic), options, {}, std::move(sink), std::move(cq)));
};
auto connection = make_connection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am beginning to think this is too clever for its own good.

Maybe we should do this (starting around line 133):

auto cp = background->cq();
auto sink = DefaultBatchSink::Create(stub, cq, std::move(retry_policy), std::move(backoff_policy));
auto connection = RejectsWithOrderingKey::Create(BatchingPublisherConnection::Create(topic, options, {}, sink, cq);
if (options.message_ordering()) {
  auto factory = [topic, options, sink, cq](std::string const& key) {
    return BatchingPublisherConnection::Create(topic, options, key, SequentialBatchSink(std::move(sink), std::move(cq)));
  };
  connection = OrderKeyPublisherConnection(std::move(factory));
}

It makes a few more copies than it should, but it is probably more readable. Alternatively, moving the lambda to a function may make it more obvious. Your call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code is fine. I like that BatchingPublisherConnection::Create() is only called once

if (options.full_publisher_rejects() || options.full_publisher_blocks()) {
Expand Down