-
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
feat(pubsub): introduce PublisherOptionList (g::c::Options) #7273
feat(pubsub): introduce PublisherOptionList (g::c::Options) #7273
Conversation
Google Cloud Build Logs
ℹ️ NOTE: Kokoro logs are linked from "Details" below. |
Codecov Report
@@ Coverage Diff @@
## main #7273 +/- ##
==========================================
+ Coverage 94.34% 94.36% +0.02%
==========================================
Files 1317 1320 +3
Lines 114594 114688 +94
==========================================
+ Hits 108108 108226 +118
+ Misses 6486 6462 -24
Continue to review full report at Codecov.
|
Google Cloud Build Logs
ℹ️ NOTE: Kokoro logs are linked from "Details" below. |
* @note Application developers should keep in mind that Cloud Pub/Sub | ||
* sets [limits][pubsub-quota-link] on the size of a batch (1,000 messages) | ||
* The library makes no attempt to validate the value provided in this | ||
* function. |
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.
s/function/option/ ?
* @note Application developers should keep in mind that Cloud Pub/Sub | ||
* sets [limits][pubsub-quota-link] on the size of a batch (10MB). The | ||
* library makes no attempt to validate the value provided in this | ||
* function. |
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.
Ditto.
}; | ||
|
||
/// Actions taken by a full publisher. | ||
enum class FullPublisherAction { |
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.
Hmmm... I was trying to not make these enums public, I cannot recall why. Maybe because I hate enum
:
- They are the devil to evolve
- They are a code smell for "somebody is using switch when they should be using virtual functions"
But I cannot recall why I did not want them in this case.... Can we hide them in an opaque type?
class FullPublisherAction {
public:
// maybe == and operator!=
static FullPublisherAction BlockIfFull() { return FullPublisherAction(kBlocks); }
static FullPublisherAction RejectIfFull() { return FullPublisherAction(kRejects); }
static FullPublisherAction None() { return FullPublisherAction(kIgnored); }
private:
enum Discriminant { kIgnored, kRejects, kBlocks };
explicit FullPublisherAction(Discriminant d) : discriminant_(d) {}
friend ... internal::DoStuff(FullPublisherAction a);
};
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 am not convinced that a public enum is a bad idea, but I am not convinced it is a good idea. Can you provide an argument one way or the other?
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.
So quick thoughts are that
- user code doesn't change much either way.
opts.set<FullPublisherActionOption>(FullPublisherAction::kBlockIfFull); // or kBlocks
// vs.
opts.set<FullPublisherActionOption>(FullPublisherAction::BlockIfFull());
-
Spanner has a similar enum
google-cloud-cpp/google/cloud/spanner/options.h
Lines 117 to 125 in 6750048
/// Action to take when the session pool is exhausted. enum class ActionOnExhaustion { kBlock, kFail }; /** * Option for `google::cloud::Options` to set the action to take when * attempting to allocate a session when the pool is exhausted. */ struct SessionPoolActionOnExhaustionOption { using Type = spanner::ActionOnExhaustion; }; -
I'm going to guess it's easier to deprecate a method from the class than it is to deprecate a value from the
enum
. Also it seems slightly better to grow aclass
by adding methods than by appending values to anenum
. -
Currently, the value is used as an enum. Would it ever grow? For example something that could take in a callback? Like do generic user provided action when Publisher is full, instead of one of the three actions we have listed for you.
-
the class is more complex for us to write. It is ever so slightly more complicated for a user to understand.
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.
If there is an action to be taken, other than the ones we list, then the class
makes sense. Here is a stupid one:
static FullPublisherAction RejectIfFullWithProbability(double p);
What might a real action be?
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.
Let's go with the public enum.
@@ -46,7 +60,19 @@ inline namespace GOOGLE_CLOUD_CPP_PUBSUB_NS { | |||
*/ | |||
class PublisherOptions { | |||
public: | |||
PublisherOptions() = default; | |||
PublisherOptions() : PublisherOptions(Options{}) {} | |||
/** |
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.
nit: blank line before comment block
PublisherOptions) | ||
Publisher::Publisher( | ||
std::shared_ptr<PublisherConnection> connection, | ||
PublisherOptions) // NOLINT(performance-unnecessary-value-param) |
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.
Q: do you know why this is needed now?
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.
A: Honestly, no... clang-tidy
yelled at me, so I changed it. (It also yelled at me to make the change in flow_controlled_publisher_connection_test.cc
)
I wanted to get this done but I do not have the patience to set up a development workstation on my windows laptop right now. So I am temporarily closing this, to be reopened in one week. |
Start of the work for #6306
Some choices:
FullPublisherAction
. I considered having 3bool
options, which might conflict, but ultimately decided that although the enum is verbose, it is clearest. It is also consistent with this in spanner. (I could use a check on doxygen comments for enum values)publisher_options_test
, but I personally prefer it.PublisherOptions
is ugly. Not sure how to avoid it though.This change is