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

refactor(transaction): use userdata to cache the local checker callback #252

Merged
merged 1 commit into from
Feb 24, 2020
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
29 changes: 17 additions & 12 deletions src/extern/CProducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ extern "C" {
#endif
using namespace rocketmq;
using namespace std;

class MyLocalTransactionExecuterInner {
public:
MyLocalTransactionExecuterInner(CLocalTransactionExecutorCallback executor, CMessage* msg, void* userData)
: m_ExcutorCallback(executor), message(msg), data(userData) {}
~MyLocalTransactionExecuterInner() {}
CLocalTransactionExecutorCallback m_ExcutorCallback;
CMessage* message;
void* data;
};
class LocalTransactionListenerInner : public TransactionListener {
public:
LocalTransactionListenerInner() {}
Expand All @@ -56,8 +64,10 @@ class LocalTransactionListenerInner : public TransactionListener {
if (m_CheckerCallback == NULL) {
return LocalTransactionState::UNKNOWN;
}
CMessage* msg = (CMessage*)(&message);
CTransactionStatus status = m_ExcutorCallback(m_producer, msg, arg);
(void)(message);
MyLocalTransactionExecuterInner* executerInner = (MyLocalTransactionExecuterInner*)arg;
CTransactionStatus status =
executerInner->m_ExcutorCallback(m_producer, executerInner->message, executerInner->data);
switch (status) {
case E_COMMIT_TRANSACTION:
return LocalTransactionState::COMMIT_MESSAGE;
Expand Down Expand Up @@ -91,15 +101,8 @@ class LocalTransactionListenerInner : public TransactionListener {

private:
CLocalTransactionCheckerCallback m_CheckerCallback;
CLocalTransactionExecutorCallback m_ExcutorCallback;

CProducer* m_producer;
void* m_data;

public:
void setM_m_ExcutorCallback(CLocalTransactionExecutorCallback excutorcallback) {
m_ExcutorCallback = excutorcallback;
}
};

class SelectMessageQueueInner : public MessageQueueSelector {
Expand Down Expand Up @@ -584,8 +587,10 @@ int SendMessageTransaction(CProducer* producer,
try {
DefaultProducer* defaultMQProducer = (DefaultProducer*)producer;
MQMessage* message = (MQMessage*)msg;
defaultMQProducer->listenerInner->setM_m_ExcutorCallback(callback);
SendResult sendResult = defaultMQProducer->innerTransactionProducer->sendMessageInTransaction(*message, userData);
MyLocalTransactionExecuterInner executerInner(callback, msg, userData);
// defaultMQProducer->listenerInner->setM_m_ExcutorCallback(callback);
SendResult sendResult =
defaultMQProducer->innerTransactionProducer->sendMessageInTransaction(*message, &executerInner);
result->sendStatus = CSendStatus((int)sendResult.getSendStatus());
result->offset = sendResult.getQueueOffset();
strncpy(result->msgId, sendResult.getMsgId().c_str(), MAX_MESSAGE_ID_LENGTH - 1);
Expand Down