-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
C++ Client - Async call for getConsumerStat #255
Conversation
pulsar-client-cpp/lib/Consumer.cc
Outdated
if (!impl_) { | ||
return ResultConsumerNotInitialized; | ||
} | ||
return impl_->getConsumerStats(BrokerConsumerStats, partitionIndex); | ||
Promise<Result, BrokerConsumerStats> promise; | ||
impl_->getConsumerStatsAsync(WaitForCallbackValue<BrokerConsumerStats>(promise), partitionIndex); |
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.
Isn't it better to call the local getConsumerStatsAsync() ?
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 call Consumer-> getConsumerStatsAsync() instead of impl_-> getConsumerStatsAsync
but I saw the code for acknowledge() and unsubscribe() - they both call the async function in the impl_
, BrokerConsumerStatsCallback callback) { | ||
|
||
if (res == ResultOk) { | ||
Lock lock(mutex_); |
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.
Do we need the lock here?
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.
yes, to protect brokerConsumerStats_ in case getConsumerStats is called using multiple threads using the same consumer objects.
brokerConsumerStats = brokerConsumerStats_; | ||
return ResultOk; | ||
lock.unlock(); | ||
return callback(ResultOk, brokerConsumerStats_); |
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.
this callback isn't safe as you just dropped the lock. need to copy brokerConsumerStats_
before unlocking.
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.
@msb-at-yahoo - handled
2ee87b3
to
2618954
Compare
…llForBrokerStats
Closing the PR - need to think a little more about this - sorry for the unneccessary noise. |
* Fix perf-produce cannot be closed Signed-off-by: xiaolong.ran <rxl@apache.org> * fix comments Signed-off-by: xiaolong.ran <rxl@apache.org> * fix comments Signed-off-by: xiaolong.ran <rxl@apache.org> * fix comments Signed-off-by: xiaolong.ran <rxl@apache.org>
Motivation
C++ Client - Async call for getConsumerStats - as a part of #216
Modifications
Slightly changed the CPP Client flow for getConsumerStats and added support for async call
Result
CPP Client will have the ability to get consumer stats asynchronously