Skip to content

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

Merged
dbolduc merged 3 commits intogoogleapis:mainfrom
dbolduc:fix-pubsub-ub
Sep 3, 2021
Merged

fix(pubsub): dont move PublisherOptions that we are still using#7270
dbolduc merged 3 commits intogoogleapis:mainfrom
dbolduc:fix-pubsub-ub

Conversation

@dbolduc
Copy link
Copy Markdown
Member

@dbolduc dbolduc commented Sep 3, 2021

we std::move(options) in the make_connection lambda which captures by reference. Then we keep using options...

I am not sure how to test for this change.


This change is Reviewable

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Sep 3, 2021
@product-auto-label product-auto-label Bot added the api: pubsub Issues related to the Pub/Sub API. label Sep 3, 2021
coryan
coryan previously approved these changes Sep 3, 2021
@google-cloud-cpp-bot
Copy link
Copy Markdown
Contributor

Google Cloud Build Logs
For commit: f18a3828e6c8573ae7ca18cbc8db2b924251d597

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 3, 2021

Codecov Report

Merging #7270 (4b4726c) into main (8650515) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #7270   +/-   ##
=======================================
  Coverage   94.34%   94.34%           
=======================================
  Files        1317     1317           
  Lines      114595   114594    -1     
=======================================
  Hits       108112   108112           
+ Misses       6483     6482    -1     
Impacted Files Coverage Δ
google/cloud/pubsub/publisher_connection.cc 92.30% <100.00%> (-0.12%) ⬇️
...ud/spanner/integration_tests/client_stress_test.cc 85.52% <0.00%> (-0.66%) ⬇️
.../cloud/storage/benchmarks/throughput_experiment.cc 74.37% <0.00%> (-0.51%) ⬇️
...le/cloud/storage/internal/curl_download_request.cc 89.21% <0.00%> (-0.38%) ⬇️
google/cloud/completion_queue_test.cc 96.95% <0.00%> (-0.20%) ⬇️
google/cloud/pubsub/subscriber_connection_test.cc 97.90% <0.00%> (+0.69%) ⬆️
google/cloud/bigtable/internal/common_client.h 100.00% <0.00%> (+5.97%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6df425c...4b4726c. Read the comment docs.

@dbolduc dbolduc marked this pull request as ready for review September 3, 2021 15:50
@dbolduc dbolduc requested a review from a team September 3, 2021 15:50
@google-cloud-cpp-bot
Copy link
Copy Markdown
Contributor

Google Cloud Build Logs
For commit: 480d0347f49b1fca207846bfbbe5e63ca6c80e34

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

return BatchingPublisherConnection::Create(
topic, options, key, SequentialBatchSink::Create(std::move(sink)),
cq);
std::move(topic), std::move(options), key,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not think you want to std::move here. factory may be called multiple times, once for each ordering key that is discovered (dynamically). You want a copy, and note that they are captured by copy too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

}
return RejectsWithOrderingKey::Create(BatchingPublisherConnection::Create(
std::move(topic), std::move(options), {}, sink, std::move(cq)));
topic, options, {}, std::move(sink), std::move(cq)));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is called at most once, and therefore a std::move(topic) was appropriate.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

whoops

std::move(topic), std::move(options), {}, sink, std::move(cq)));
topic, options, {}, std::move(sink), std::move(cq)));
};
auto connection = make_connection();
Copy link
Copy Markdown
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
Copy Markdown
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

@google-cloud-cpp-bot
Copy link
Copy Markdown
Contributor

Google Cloud Build Logs
For commit: 4b4726c8f952bf9321f1def3e22945e0dc3821e5

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@dbolduc dbolduc merged commit 6750048 into googleapis:main Sep 3, 2021
@dbolduc dbolduc deleted the fix-pubsub-ub branch September 3, 2021 21:11
dbolduc added a commit to dbolduc/google-cloud-cpp that referenced this pull request Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: pubsub Issues related to the Pub/Sub API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants