-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
[ISSUE #292] Add support of transactional message feature #358
Changes from all commits
18cea40
6ec0c7f
aeca8a1
0ce72f1
6825247
835e013
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,25 +17,15 @@ | |
package org.apache.rocketmq.broker.client.net; | ||
|
||
import io.netty.channel.Channel; | ||
import io.netty.channel.ChannelFuture; | ||
import io.netty.channel.ChannelFutureListener; | ||
import io.netty.channel.FileRegion; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.concurrent.ConcurrentMap; | ||
import org.apache.rocketmq.broker.BrokerController; | ||
import org.apache.rocketmq.broker.client.ClientChannelInfo; | ||
import org.apache.rocketmq.broker.client.ConsumerGroupInfo; | ||
import org.apache.rocketmq.broker.pagecache.OneMessageTransfer; | ||
import org.apache.rocketmq.common.MQVersion; | ||
import org.apache.rocketmq.common.TopicConfig; | ||
import org.apache.rocketmq.common.UtilAll; | ||
import org.apache.rocketmq.common.constant.LoggerName; | ||
import org.apache.rocketmq.logging.InternalLogger; | ||
import org.apache.rocketmq.logging.InternalLoggerFactory; | ||
import org.apache.rocketmq.common.message.MessageDecoder; | ||
import org.apache.rocketmq.common.message.MessageExt; | ||
import org.apache.rocketmq.common.message.MessageQueue; | ||
import org.apache.rocketmq.common.message.MessageQueueForC; | ||
import org.apache.rocketmq.common.protocol.RequestCode; | ||
|
@@ -47,11 +37,19 @@ | |
import org.apache.rocketmq.common.protocol.header.GetConsumerStatusRequestHeader; | ||
import org.apache.rocketmq.common.protocol.header.NotifyConsumerIdsChangedRequestHeader; | ||
import org.apache.rocketmq.common.protocol.header.ResetOffsetRequestHeader; | ||
import org.apache.rocketmq.logging.InternalLogger; | ||
import org.apache.rocketmq.logging.InternalLoggerFactory; | ||
import org.apache.rocketmq.remoting.common.RemotingHelper; | ||
import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; | ||
import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; | ||
import org.apache.rocketmq.remoting.protocol.RemotingCommand; | ||
import org.apache.rocketmq.store.SelectMappedBufferResult; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
public class Broker2Client { | ||
private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); | ||
|
@@ -62,34 +60,22 @@ public Broker2Client(BrokerController brokerController) { | |
} | ||
|
||
public void checkProducerTransactionState( | ||
final String group, | ||
final Channel channel, | ||
final CheckTransactionStateRequestHeader requestHeader, | ||
final SelectMappedBufferResult selectMappedBufferResult) { | ||
final MessageExt messageExt) throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this Exception be specific? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your review,in fact, I don't want to throw any exceptions here,but considering that the encode method may cause exception,so in this method just throws exception following with the encode method. |
||
RemotingCommand request = | ||
RemotingCommand.createRequestCommand(RequestCode.CHECK_TRANSACTION_STATE, requestHeader); | ||
request.markOnewayRPC(); | ||
|
||
request.setBody(MessageDecoder.encode(messageExt, false)); | ||
try { | ||
FileRegion fileRegion = | ||
new OneMessageTransfer(request.encodeHeader(selectMappedBufferResult.getSize()), | ||
selectMappedBufferResult); | ||
channel.writeAndFlush(fileRegion).addListener(new ChannelFutureListener() { | ||
@Override | ||
public void operationComplete(ChannelFuture future) throws Exception { | ||
selectMappedBufferResult.release(); | ||
if (!future.isSuccess()) { | ||
log.error("invokeProducer failed,", future.cause()); | ||
} | ||
} | ||
}); | ||
} catch (Throwable e) { | ||
log.error("invokeProducer exception", e); | ||
selectMappedBufferResult.release(); | ||
this.brokerController.getRemotingServer().invokeOneway(channel, request, 10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 10 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an empirical value when using the invokeOneWay method. In the check scenario , we don't need to wait for the producer‘s response, and in order to prevent too many threads waiting,we adopted this configuration,but we also considered that whether it is necessary to make this parameter configurable,what’s your opinion? |
||
} catch (Exception e) { | ||
log.error("Check transaction failed because invoke producer exception. group={}, msgId={}", group, messageExt.getMsgId(), e.getMessage()); | ||
} | ||
} | ||
|
||
public RemotingCommand callClient(final Channel channel, | ||
final RemotingCommand request | ||
final RemotingCommand request | ||
) throws RemotingSendRequestException, RemotingTimeoutException, InterruptedException { | ||
return this.brokerController.getRemotingServer().invokeSync(channel, request, 10000); | ||
} | ||
|
@@ -119,7 +105,7 @@ public RemotingCommand resetOffset(String topic, String group, long timeStamp, b | |
} | ||
|
||
public RemotingCommand resetOffset(String topic, String group, long timeStamp, boolean isForce, | ||
boolean isC) { | ||
boolean isC) { | ||
final RemotingCommand response = RemotingCommand.createResponseCommand(null); | ||
|
||
TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); | ||
|
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.
here if isOk= true will return next channel.
i think it should be like
while ( count++ < GET_AVALIABLE_CHANNEL_RETRY_COUNT) { if(isOk){ return channel; } index = (++index) % size; channel = channelList.get(index); isOk = channel.isActive() && channel.isWritable(); }
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.
Thanks for your careful review,and I will fix this problem ASAP.