You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "shibd (via GitHub)" <gi...@apache.org> on 2023/09/01 09:30:50 UTC
[GitHub] [pulsar-client-cpp] shibd commented on a diff in pull request #308: Avoid copying OpSendMsg when sending messages
shibd commented on code in PR #308:
URL: https://github.com/apache/pulsar-client-cpp/pull/308#discussion_r1312803001
##########
lib/BatchMessageContainerBase.cc:
##########
@@ -70,45 +60,18 @@ Result BatchMessageContainerBase::createOpSendMsgHelper(OpSendMsg& opSendMsg,
SharedBuffer encryptedPayload;
if (!msgCrypto->encrypt(producerConfig_.getEncryptionKeys(), producerConfig_.getCryptoKeyReader(),
impl->metadata, impl->payload, encryptedPayload)) {
- return ResultCryptoError;
+ return OpSendMsg::create(ResultCryptoError, std::move(sendCallback));
}
impl->payload = encryptedPayload;
}
if (impl->payload.readableBytes() > ClientConnection::getMaxMessageSize()) {
- return ResultMessageTooBig;
+ return OpSendMsg::create(ResultMessageTooBig, std::move(sendCallback));
}
- opSendMsg.metadata_ = impl->metadata;
- opSendMsg.payload_ = impl->payload;
- opSendMsg.sequenceId_ = impl->metadata.sequence_id();
- opSendMsg.producerId_ = producerId_;
- opSendMsg.timeout_ = TimeUtils::now() + milliseconds(producerConfig_.getSendTimeout());
-
- return ResultOk;
-}
-
-void BatchMessageContainerBase::processAndClear(
- std::function<void(Result, const OpSendMsg&)> opSendMsgCallback, FlushCallback flushCallback) {
- if (isEmpty()) {
- if (flushCallback) {
- // do nothing, flushCallback complete until the lastOpSend complete
- }
- } else {
- const auto numBatches = getNumBatches();
- if (numBatches == 1) {
- OpSendMsg opSendMsg;
- Result result = createOpSendMsg(opSendMsg, flushCallback);
- opSendMsgCallback(result, opSendMsg);
- } else if (numBatches > 1) {
- std::vector<OpSendMsg> opSendMsgs;
- std::vector<Result> results = createOpSendMsgs(opSendMsgs, flushCallback);
- for (size_t i = 0; i < results.size(); i++) {
- opSendMsgCallback(results[i], opSendMsgs[i]);
- }
- } // else numBatches is 0, do nothing
- }
- clear();
+ return OpSendMsg::create(impl->metadata, batch.messagesCount(), batch.messagesSize(),
+ producerConfig_.getSendTimeout(), batch.createSendCallback(flushCallback),
Review Comment:
Can use `sendCallback` to replace `batch.createSendCallback(flushCallback)`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org