com.alibaba.rocketmq.common.sysflag.MessageSysFlag Java Examples
The following examples show how to use
com.alibaba.rocketmq.common.sysflag.MessageSysFlag.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EndTransactionRequestHeader.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
@Override public void checkFields() throws RemotingCommandException { if (MessageSysFlag.TransactionNotType == this.commitOrRollback) { return; } if (MessageSysFlag.TransactionCommitType == this.commitOrRollback) { return; } if (MessageSysFlag.TransactionRollbackType == this.commitOrRollback) { return; } throw new RemotingCommandException("commitOrRollback field wrong"); }
Example #2
Source File: EndTransactionRequestHeader.java From rocketmq with Apache License 2.0 | 6 votes |
@Override public void checkFields() throws RemotingCommandException { if (MessageSysFlag.TransactionNotType == this.commitOrRollback) { return; } if (MessageSysFlag.TransactionCommitType == this.commitOrRollback) { return; } if (MessageSysFlag.TransactionRollbackType == this.commitOrRollback) { return; } throw new RemotingCommandException("commitOrRollback field wrong"); }
Example #3
Source File: DefaultMessageStore.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
/** * 构建消费队列项和msgkey的索引项。 * @param req */ public void doDispatch(DispatchRequest req) { final int tranType = MessageSysFlag.getTransactionValue(req.getSysFlag()); switch (tranType) { case MessageSysFlag.TransactionNotType: case MessageSysFlag.TransactionCommitType: //把从commitlog中读取到的消息与consumeQueue关联起来,把该条消息的offset len taghash写入到 consumeQueue DefaultMessageStore.this.putMessagePostionInfo(req.getTopic(), req.getQueueId(), req.getCommitLogOffset(), req.getMsgSize(), req.getTagsCode(), req.getStoreTimestamp(), req.getConsumeQueueOffset()); break; case MessageSysFlag.TransactionPreparedType: //如果是事务prepared或者rollback类型的消息,则不用把commitlog消息对应的索引dispatch到consumeQueue case MessageSysFlag.TransactionRollbackType: break; } if (DefaultMessageStore.this.getMessageStoreConfig().isMessageIndexEnable()) { DefaultMessageStore.this.indexService.buildIndex(req); } }
Example #4
Source File: EndTransactionRequestHeader.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
@Override public void checkFields() throws RemotingCommandException { if (MessageSysFlag.TransactionNotType == this.commitOrRollback) { return; } if (MessageSysFlag.TransactionCommitType == this.commitOrRollback) { return; } if (MessageSysFlag.TransactionRollbackType == this.commitOrRollback) { return; } throw new RemotingCommandException("commitOrRollback field wrong"); }
Example #5
Source File: EndTransactionProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
private MessageExtBrokerInner endMessageTransaction(MessageExt msgExt) { MessageExtBrokerInner msgInner = new MessageExtBrokerInner(); msgInner.setBody(msgExt.getBody()); msgInner.setFlag(msgExt.getFlag()); MessageAccessor.setProperties(msgInner, msgExt.getProperties()); TopicFilterType topicFilterType = (msgInner.getSysFlag() & MessageSysFlag.MultiTagsFlag) == MessageSysFlag.MultiTagsFlag ? TopicFilterType.MULTI_TAG : TopicFilterType.SINGLE_TAG; long tagsCodeValue = MessageExtBrokerInner.tagsString2tagsCode(topicFilterType, msgInner.getTags()); msgInner.setTagsCode(tagsCodeValue); msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgExt.getProperties())); msgInner.setSysFlag(msgExt.getSysFlag()); msgInner.setBornTimestamp(msgExt.getBornTimestamp()); msgInner.setBornHost(msgExt.getBornHost()); msgInner.setStoreHost(msgExt.getStoreHost()); msgInner.setReconsumeTimes(msgExt.getReconsumeTimes()); msgInner.setWaitStoreMsgOK(false); MessageAccessor.clearProperty(msgInner, MessageConst.PROPERTY_DELAY_TIME_LEVEL); msgInner.setTopic(msgExt.getTopic()); msgInner.setQueueId(msgExt.getQueueId()); return msgInner; }
Example #6
Source File: DefaultMQProducerImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
private void endTransaction(// final SendResult sendResult, // final LocalTransactionState localTransactionState, // final Throwable localException) throws RemotingException, MQBrokerException, InterruptedException, UnknownHostException { final MessageId id = MessageDecoder.decodeMessageId(sendResult.getMsgId()); String transactionId = sendResult.getTransactionId(); final String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(sendResult.getMessageQueue().getBrokerName()); EndTransactionRequestHeader requestHeader = new EndTransactionRequestHeader(); requestHeader.setTransactionId(transactionId); requestHeader.setCommitLogOffset(id.getOffset()); switch (localTransactionState) { case COMMIT_MESSAGE: requestHeader.setCommitOrRollback(MessageSysFlag.TransactionCommitType); break; case ROLLBACK_MESSAGE: requestHeader.setCommitOrRollback(MessageSysFlag.TransactionRollbackType); break; case UNKNOW: requestHeader.setCommitOrRollback(MessageSysFlag.TransactionNotType); break; default: break; } requestHeader.setProducerGroup(this.defaultMQProducer.getProducerGroup()); requestHeader.setTranStateTableOffset(sendResult.getQueueOffset()); requestHeader.setMsgId(sendResult.getMsgId()); String remark = localException != null ? ("executeLocalTransactionBranch exception: " + localException.toString()) : null; this.mQClientFactory.getMQClientAPIImpl().endTransactionOneway(brokerAddr, requestHeader, remark, this.defaultMQProducer.getSendMsgTimeout()); }
Example #7
Source File: CheckTransactionStateResponseHeader.java From rocketmq with Apache License 2.0 | 5 votes |
@Override public void checkFields() throws RemotingCommandException { if (MessageSysFlag.TransactionCommitType == this.commitOrRollback) { return; } if (MessageSysFlag.TransactionRollbackType == this.commitOrRollback) { return; } throw new RemotingCommandException("commitOrRollback field wrong"); }
Example #8
Source File: MessageExt.java From rocketmq with Apache License 2.0 | 5 votes |
public static TopicFilterType parseTopicFilterType(final int sysFlag) { if ((sysFlag & MessageSysFlag.MultiTagsFlag) == MessageSysFlag.MultiTagsFlag) { return TopicFilterType.MULTI_TAG; } return TopicFilterType.SINGLE_TAG; }
Example #9
Source File: AbstractSendMessageProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
protected MessageExtBrokerInner buildInnerMsg(final ChannelHandlerContext ctx, final SendMessageRequestHeader requestHeader, final byte[] body, TopicConfig topicConfig) { int queueIdInt = requestHeader.getQueueId(); // 闅忔満鎸囧畾涓�涓槦鍒� if (queueIdInt < 0) { queueIdInt = Math.abs(this.random.nextInt() % 99999999) % topicConfig.getWriteQueueNums(); } int sysFlag = requestHeader.getSysFlag(); // 澶氭爣绛捐繃婊ら渶瑕佺疆浣� if (TopicFilterType.MULTI_TAG == topicConfig.getTopicFilterType()) { sysFlag |= MessageSysFlag.MultiTagsFlag; } MessageExtBrokerInner msgInner = new MessageExtBrokerInner(); msgInner.setTopic(requestHeader.getTopic()); msgInner.setBody(body); msgInner.setFlag(requestHeader.getFlag()); MessageAccessor.setProperties(msgInner, MessageDecoder.string2messageProperties(requestHeader.getProperties())); msgInner.setPropertiesString(requestHeader.getProperties()); msgInner.setTagsCode( MessageExtBrokerInner.tagsString2tagsCode(topicConfig.getTopicFilterType(), msgInner.getTags())); msgInner.setQueueId(queueIdInt); msgInner.setSysFlag(sysFlag); msgInner.setBornTimestamp(requestHeader.getBornTimestamp()); msgInner.setBornHost(ctx.channel().remoteAddress()); msgInner.setStoreHost(this.getStoreHost()); msgInner.setReconsumeTimes( requestHeader.getReconsumeTimes() == null ? 0 : requestHeader.getReconsumeTimes()); return msgInner; }
Example #10
Source File: DefaultMQProducerImpl.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
private void endTransaction(// final SendResult sendResult, // final LocalTransactionState localTransactionState, // final Throwable localException) throws RemotingException, MQBrokerException, InterruptedException, UnknownHostException { final MessageId id = MessageDecoder.decodeMessageId(sendResult.getMsgId()); String transactionId = sendResult.getTransactionId(); final String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(sendResult.getMessageQueue().getBrokerName()); EndTransactionRequestHeader requestHeader = new EndTransactionRequestHeader(); requestHeader.setTransactionId(transactionId); requestHeader.setCommitLogOffset(id.getOffset()); switch (localTransactionState) { case COMMIT_MESSAGE: //本地事务处理成功,消费者可以消费投递的消息 requestHeader.setCommitOrRollback(MessageSysFlag.TransactionCommitType); break; case ROLLBACK_MESSAGE: //如果本地事务处理失败,则会通知broker回滚,之前投递到broker的消息不会dispatch到consumeQueue,这样消费端就不会消费到消息 requestHeader.setCommitOrRollback(MessageSysFlag.TransactionRollbackType); break; case UNKNOW: requestHeader.setCommitOrRollback(MessageSysFlag.TransactionNotType); break; default: break; } requestHeader.setProducerGroup(this.defaultMQProducer.getProducerGroup()); requestHeader.setTranStateTableOffset(sendResult.getQueueOffset()); requestHeader.setMsgId(sendResult.getMsgId()); String remark = localException != null ? ("executeLocalTransactionBranch exception: " + localException .toString()) : null; this.mQClientFactory.getMQClientAPIImpl().endTransactionOneway(brokerAddr, requestHeader, remark, this.defaultMQProducer.getSendMsgTimeout()); }
Example #11
Source File: DefaultMessageStore.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
private void doDispatch() { if (!this.requestsRead.isEmpty()) { for (DispatchRequest req : this.requestsRead) { final int tranType = MessageSysFlag.getTransactionValue(req.getSysFlag()); // 1、分发消息位置信息到ConsumeQueue switch (tranType) { case MessageSysFlag.TransactionNotType: case MessageSysFlag.TransactionCommitType: // 将请求发到具体的Consume Queue DefaultMessageStore.this.putMessagePostionInfo(req.getTopic(), req.getQueueId(), req.getCommitLogOffset(), req.getMsgSize(), req.getTagsCode(), req.getStoreTimestamp(), req.getConsumeQueueOffset()); break; case MessageSysFlag.TransactionPreparedType: case MessageSysFlag.TransactionRollbackType: break; } } if (DefaultMessageStore.this.getMessageStoreConfig().isMessageIndexEnable()) { DefaultMessageStore.this.indexService.putRequest(this.requestsRead.toArray()); } this.requestsRead.clear(); } }
Example #12
Source File: TransactionStateService.java From rocketmq with Apache License 2.0 | 5 votes |
public boolean appendPreparedTransaction(// final long clOffset,// final int size,// final int timestamp,// final int groupHashCode// ) { MapedFile mapedFile = this.tranStateTable.getLastMapedFile(); if (null == mapedFile) { log.error("appendPreparedTransaction: create mapedfile error."); return false; } if (0 == mapedFile.getWrotePostion()) { this.addTimerTask(mapedFile); } this.byteBufferAppend.position(0); this.byteBufferAppend.limit(TSStoreUnitSize); // Commit Log Offset this.byteBufferAppend.putLong(clOffset); // Message Size this.byteBufferAppend.putInt(size); // Timestamp this.byteBufferAppend.putInt(timestamp); // Producer Group Hashcode this.byteBufferAppend.putInt(groupHashCode); // Transaction State this.byteBufferAppend.putInt(MessageSysFlag.TransactionPreparedType); return mapedFile.appendMessage(this.byteBufferAppend.array()); }
Example #13
Source File: AbstractSendMessageProcessor.java From rocketmq with Apache License 2.0 | 5 votes |
protected MessageExtBrokerInner buildInnerMsg(final ChannelHandlerContext ctx, final SendMessageRequestHeader requestHeader, final byte[] body, TopicConfig topicConfig) { int queueIdInt = requestHeader.getQueueId(); if (queueIdInt < 0) { queueIdInt = Math.abs(this.random.nextInt() % 99999999) % topicConfig.getWriteQueueNums(); } int sysFlag = requestHeader.getSysFlag(); if (TopicFilterType.MULTI_TAG == topicConfig.getTopicFilterType()) { sysFlag |= MessageSysFlag.MultiTagsFlag; } MessageExtBrokerInner msgInner = new MessageExtBrokerInner(); msgInner.setTopic(requestHeader.getTopic()); msgInner.setBody(body); msgInner.setFlag(requestHeader.getFlag()); MessageAccessor.setProperties(msgInner, MessageDecoder.string2messageProperties(requestHeader.getProperties())); msgInner.setPropertiesString(requestHeader.getProperties()); msgInner.setTagsCode(MessageExtBrokerInner.tagsString2tagsCode(topicConfig.getTopicFilterType(), msgInner.getTags())); msgInner.setQueueId(queueIdInt); msgInner.setSysFlag(sysFlag); msgInner.setBornTimestamp(requestHeader.getBornTimestamp()); msgInner.setBornHost(ctx.channel().remoteAddress()); msgInner.setStoreHost(this.getStoreHost()); msgInner.setReconsumeTimes(requestHeader.getReconsumeTimes() == null ? 0 : requestHeader .getReconsumeTimes()); return msgInner; }
Example #14
Source File: EndTransactionProcessor.java From rocketmq with Apache License 2.0 | 5 votes |
private MessageExtBrokerInner endMessageTransaction(MessageExt msgExt) { MessageExtBrokerInner msgInner = new MessageExtBrokerInner(); msgInner.setBody(msgExt.getBody()); msgInner.setFlag(msgExt.getFlag()); MessageAccessor.setProperties(msgInner, msgExt.getProperties()); TopicFilterType topicFilterType = (msgInner.getSysFlag() & MessageSysFlag.MultiTagsFlag) == MessageSysFlag.MultiTagsFlag ? TopicFilterType.MULTI_TAG : TopicFilterType.SINGLE_TAG; long tagsCodeValue = MessageExtBrokerInner.tagsString2tagsCode(topicFilterType, msgInner.getTags()); msgInner.setTagsCode(tagsCodeValue); msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgExt.getProperties())); msgInner.setSysFlag(msgExt.getSysFlag()); msgInner.setBornTimestamp(msgExt.getBornTimestamp()); msgInner.setBornHost(msgExt.getBornHost()); msgInner.setStoreHost(msgExt.getStoreHost()); msgInner.setReconsumeTimes(msgExt.getReconsumeTimes()); msgInner.setWaitStoreMsgOK(false); MessageAccessor.clearProperty(msgInner, MessageConst.PROPERTY_DELAY_TIME_LEVEL); MessageAccessor.clearProperty(msgInner, MessageConst.PROPERTY_TRANSACTION_PREPARED); msgInner.setTopic(msgExt.getTopic()); msgInner.setQueueId(msgExt.getQueueId()); return msgInner; }
Example #15
Source File: MessageExt.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
public static TopicFilterType parseTopicFilterType(final int sysFlag) { if ((sysFlag & MessageSysFlag.MultiTagsFlag) == MessageSysFlag.MultiTagsFlag) { return TopicFilterType.MULTI_TAG; } return TopicFilterType.SINGLE_TAG; }
Example #16
Source File: DefaultMQProducerImpl.java From rocketmq with Apache License 2.0 | 5 votes |
public void endTransaction(// final SendResult sendResult, // final LocalTransactionState localTransactionState, // final Throwable localException) throws RemotingException, MQBrokerException, InterruptedException, UnknownHostException { final MessageId id; if (sendResult.getOffsetMsgId() != null) { id = MessageDecoder.decodeMessageId(sendResult.getOffsetMsgId()); } else { id = MessageDecoder.decodeMessageId(sendResult.getMsgId()); } String transactionId = sendResult.getTransactionId(); final String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(sendResult.getMessageQueue().getBrokerName()); EndTransactionRequestHeader requestHeader = new EndTransactionRequestHeader(); requestHeader.setTransactionId(transactionId); requestHeader.setCommitLogOffset(id.getOffset()); switch (localTransactionState) { case COMMIT_MESSAGE: requestHeader.setCommitOrRollback(MessageSysFlag.TransactionCommitType); break; case ROLLBACK_MESSAGE: requestHeader.setCommitOrRollback(MessageSysFlag.TransactionRollbackType); break; case UNKNOW: requestHeader.setCommitOrRollback(MessageSysFlag.TransactionNotType); break; default: break; } requestHeader.setProducerGroup(this.defaultMQProducer.getProducerGroup()); requestHeader.setTranStateTableOffset(sendResult.getQueueOffset()); requestHeader.setMsgId(sendResult.getMsgId()); String remark = localException != null ? ("executeLocalTransactionBranch exception: " + localException.toString()) : null; this.mQClientFactory.getMQClientAPIImpl().endTransactionOneway(brokerAddr, requestHeader, remark, this.defaultMQProducer.getSendMsgTimeout()); }
Example #17
Source File: CheckTransactionStateResponseHeader.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
@Override public void checkFields() throws RemotingCommandException { if (MessageSysFlag.TransactionCommitType == this.commitOrRollback) { return; } if (MessageSysFlag.TransactionRollbackType == this.commitOrRollback) { return; } throw new RemotingCommandException("commitOrRollback field wrong"); }
Example #18
Source File: MessageExt.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
public static TopicFilterType parseTopicFilterType(final int sysFlag) { if ((sysFlag & MessageSysFlag.MultiTagsFlag) == MessageSysFlag.MultiTagsFlag) { return TopicFilterType.MULTI_TAG; } return TopicFilterType.SINGLE_TAG; }
Example #19
Source File: CheckTransactionStateResponseHeader.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
@Override public void checkFields() throws RemotingCommandException { if (MessageSysFlag.TransactionCommitType == this.commitOrRollback) { return; } if (MessageSysFlag.TransactionRollbackType == this.commitOrRollback) { return; } throw new RemotingCommandException("commitOrRollback field wrong"); }
Example #20
Source File: AbstractSendMessageProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
protected MessageExtBrokerInner buildInnerMsg(final ChannelHandlerContext ctx, final SendMessageRequestHeader requestHeader, final byte[] body, TopicConfig topicConfig) { int queueIdInt = requestHeader.getQueueId(); if (queueIdInt < 0) { queueIdInt = Math.abs(this.random.nextInt() % 99999999) % topicConfig.getWriteQueueNums(); } int sysFlag = requestHeader.getSysFlag(); if (TopicFilterType.MULTI_TAG == topicConfig.getTopicFilterType()) { sysFlag |= MessageSysFlag.MultiTagsFlag; } MessageExtBrokerInner msgInner = new MessageExtBrokerInner(); msgInner.setTopic(requestHeader.getTopic()); msgInner.setBody(body); msgInner.setFlag(requestHeader.getFlag()); MessageAccessor.setProperties(msgInner, MessageDecoder.string2messageProperties(requestHeader.getProperties())); msgInner.setPropertiesString(requestHeader.getProperties()); msgInner.setTagsCode(MessageExtBrokerInner.tagsString2tagsCode(topicConfig.getTopicFilterType(), msgInner.getTags())); msgInner.setQueueId(queueIdInt); msgInner.setSysFlag(sysFlag); msgInner.setBornTimestamp(requestHeader.getBornTimestamp()); msgInner.setBornHost(ctx.channel().remoteAddress()); msgInner.setStoreHost(this.getStoreHost()); msgInner.setReconsumeTimes(requestHeader.getReconsumeTimes() == null ? 0 : requestHeader .getReconsumeTimes()); return msgInner; }
Example #21
Source File: EndTransactionProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
private MessageExtBrokerInner endMessageTransaction(MessageExt msgExt) { MessageExtBrokerInner msgInner = new MessageExtBrokerInner(); msgInner.setBody(msgExt.getBody()); msgInner.setFlag(msgExt.getFlag()); MessageAccessor.setProperties(msgInner, msgExt.getProperties()); TopicFilterType topicFilterType = (msgInner.getSysFlag() & MessageSysFlag.MultiTagsFlag) == MessageSysFlag.MultiTagsFlag ? TopicFilterType.MULTI_TAG : TopicFilterType.SINGLE_TAG; long tagsCodeValue = MessageExtBrokerInner.tagsString2tagsCode(topicFilterType, msgInner.getTags()); msgInner.setTagsCode(tagsCodeValue); msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgExt.getProperties())); msgInner.setSysFlag(msgExt.getSysFlag()); msgInner.setBornTimestamp(msgExt.getBornTimestamp()); msgInner.setBornHost(msgExt.getBornHost()); msgInner.setStoreHost(msgExt.getStoreHost()); msgInner.setReconsumeTimes(msgExt.getReconsumeTimes()); msgInner.setWaitStoreMsgOK(false); MessageAccessor.clearProperty(msgInner, MessageConst.PROPERTY_DELAY_TIME_LEVEL); msgInner.setTopic(msgExt.getTopic()); msgInner.setQueueId(msgExt.getQueueId()); return msgInner; }
Example #22
Source File: IndexService.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
public void buildIndex(Object[] req) { boolean breakdown = false; IndexFile indexFile = retryGetAndCreateIndexFile(); if (indexFile != null) { long endPhyOffset = indexFile.getEndPhyOffset(); MSG_WHILE: for (Object o : req) { DispatchRequest msg = (DispatchRequest) o; String topic = msg.getTopic(); String keys = msg.getKeys(); if (msg.getCommitLogOffset() < endPhyOffset) { continue; } final int tranType = MessageSysFlag.getTransactionValue(msg.getSysFlag()); switch (tranType) { case MessageSysFlag.TransactionNotType: case MessageSysFlag.TransactionPreparedType: break; case MessageSysFlag.TransactionCommitType: case MessageSysFlag.TransactionRollbackType: continue; } if (keys != null && keys.length() > 0) { String[] keyset = keys.split(MessageConst.KEY_SEPARATOR); for (String key : keyset) { // TODO 是否需要TRIM if (key.length() > 0) { for (boolean ok = indexFile.putKey(buildKey(topic, key), msg.getCommitLogOffset(), msg.getStoreTimestamp()); !ok;) { log.warn( "index file full, so create another one, " + indexFile.getFileName()); indexFile = retryGetAndCreateIndexFile(); if (null == indexFile) { breakdown = true; break MSG_WHILE; } ok = indexFile.putKey(buildKey(topic, key), msg.getCommitLogOffset(), msg.getStoreTimestamp()); } } } } } } // IO发生故障,build索引过程中断,需要人工参与处理 else { breakdown = true; } if (breakdown) { log.error("build index error, stop building index"); } }
Example #23
Source File: TransactionStateService.java From rocketmq with Apache License 2.0 | 4 votes |
public boolean updateTransactionState(// final long tsOffset,// final long clOffset,// final int groupHashCode,// final int state// ) { SelectMapedBufferResult selectMapedBufferResult = this.findTransactionBuffer(tsOffset); if (selectMapedBufferResult != null) { try { final long clOffset_read = selectMapedBufferResult.getByteBuffer().getLong(); final int size_read = selectMapedBufferResult.getByteBuffer().getInt(); final int timestamp_read = selectMapedBufferResult.getByteBuffer().getInt(); final int groupHashCode_read = selectMapedBufferResult.getByteBuffer().getInt(); final int state_read = selectMapedBufferResult.getByteBuffer().getInt(); if (clOffset != clOffset_read) { log.error("updateTransactionState error clOffset: {} clOffset_read: {}", clOffset, clOffset_read); return false; } if (groupHashCode != groupHashCode_read) { log.error("updateTransactionState error groupHashCode: {} groupHashCode_read: {}", groupHashCode, groupHashCode_read); return false; } if (MessageSysFlag.TransactionPreparedType != state_read) { log.warn("updateTransactionState error, the transaction is updated before."); return true; } selectMapedBufferResult.getByteBuffer().putInt(TS_STATE_POS, state); } catch (Exception e) { log.error("updateTransactionState exception", e); } finally { selectMapedBufferResult.release(); } } return false; }
Example #24
Source File: DefaultRequestProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
private ByteBuffer messageToByteBuffer(final MessageExt msg) throws IOException { int sysFlag = MessageSysFlag.clearCompressedFlag(msg.getSysFlag()); if (msg.getBody() != null) { if (msg.getBody().length >= this.filtersrvController.getFiltersrvConfig() .getCompressMsgBodyOverHowmuch()) { byte[] data = UtilAll.compress(msg.getBody(), this.filtersrvController.getFiltersrvConfig().getZipCompressLevel()); if (data != null) { msg.setBody(data); sysFlag |= MessageSysFlag.CompressedFlag; } } } final int bodyLength = msg.getBody() != null ? msg.getBody().length : 0; byte[] topicData = msg.getTopic().getBytes(MixAll.DEFAULT_CHARSET); final int topicLength = topicData.length; String properties = MessageDecoder.messageProperties2String(msg.getProperties()); byte[] propertiesData = properties.getBytes(MixAll.DEFAULT_CHARSET); final int propertiesLength = propertiesData.length; final int msgLen = 4 // 1 TOTALSIZE + 4 // 2 MAGICCODE + 4 // 3 BODYCRC + 4 // 4 QUEUEID + 4 // 5 FLAG + 8 // 6 QUEUEOFFSET + 8 // 7 PHYSICALOFFSET + 4 // 8 SYSFLAG + 8 // 9 BORNTIMESTAMP + 8 // 10 BORNHOST + 8 // 11 STORETIMESTAMP + 8 // 12 STOREHOSTADDRESS + 4 // 13 RECONSUMETIMES + 8 // 14 Prepared Transaction Offset + 4 + bodyLength // 14 BODY + 1 + topicLength // 15 TOPIC + 2 + propertiesLength // 16 propertiesLength + 0; ByteBuffer msgStoreItemMemory = ByteBuffer.allocate(msgLen); final MessageExt msgInner = msg; // 1 TOTALSIZE msgStoreItemMemory.putInt(msgLen); // 2 MAGICCODE msgStoreItemMemory.putInt(CommitLog.MessageMagicCode); // 3 BODYCRC msgStoreItemMemory.putInt(UtilAll.crc32(msgInner.getBody())); // 4 QUEUEID msgStoreItemMemory.putInt(msgInner.getQueueId()); // 5 FLAG msgStoreItemMemory.putInt(msgInner.getFlag()); // 6 QUEUEOFFSET msgStoreItemMemory.putLong(msgInner.getQueueOffset()); // 7 PHYSICALOFFSET msgStoreItemMemory.putLong(msgInner.getCommitLogOffset()); // 8 SYSFLAG msgStoreItemMemory.putInt(sysFlag); // 9 BORNTIMESTAMP msgStoreItemMemory.putLong(msgInner.getBornTimestamp()); // 10 BORNHOST msgStoreItemMemory.put(msgInner.getBornHostBytes()); // 11 STORETIMESTAMP msgStoreItemMemory.putLong(msgInner.getStoreTimestamp()); // 12 STOREHOSTADDRESS msgStoreItemMemory.put(msgInner.getStoreHostBytes()); // 13 RECONSUMETIMES msgStoreItemMemory.putInt(msgInner.getReconsumeTimes()); // 14 Prepared Transaction Offset msgStoreItemMemory.putLong(msgInner.getPreparedTransactionOffset()); // 15 BODY msgStoreItemMemory.putInt(bodyLength); if (bodyLength > 0) msgStoreItemMemory.put(msgInner.getBody()); // 16 TOPIC msgStoreItemMemory.put((byte) topicLength); msgStoreItemMemory.put(topicData); // 17 PROPERTIES msgStoreItemMemory.putShort((short) propertiesLength); if (propertiesLength > 0) msgStoreItemMemory.put(propertiesData); return msgStoreItemMemory; }
Example #25
Source File: DefaultMessageStore.java From rocketmq with Apache License 2.0 | 4 votes |
public void doDispatch(DispatchRequest req) { final int tranType = MessageSysFlag.getTransactionValue(req.getSysFlag()); switch (tranType) { case MessageSysFlag.TransactionNotType: case MessageSysFlag.TransactionCommitType: DefaultMessageStore.this.putMessagePostionInfo(req.getTopic(), req.getQueueId(), req.getCommitLogOffset(), req.getMsgSize(), req.getTagsCode(), req.getStoreTimestamp(), req.getConsumeQueueOffset()); break; case MessageSysFlag.TransactionPreparedType: case MessageSysFlag.TransactionRollbackType: break; } if (req.getProducerGroup() != null) { switch (tranType) { case MessageSysFlag.TransactionNotType: break; case MessageSysFlag.TransactionPreparedType: DefaultMessageStore.this.getTransactionStateService().appendPreparedTransaction(// req.getCommitLogOffset(),// req.getMsgSize(),// (int) (req.getStoreTimestamp() / 1000),// req.getProducerGroup().hashCode()); break; case MessageSysFlag.TransactionCommitType: case MessageSysFlag.TransactionRollbackType: DefaultMessageStore.this.getTransactionStateService().updateTransactionState(// req.getTranStateTableOffset(),// req.getPreparedTransactionOffset(),// req.getProducerGroup().hashCode(),// tranType// ); break; } } switch (tranType) { case MessageSysFlag.TransactionNotType: break; case MessageSysFlag.TransactionPreparedType: DefaultMessageStore.this.getTransactionStateService().getTranRedoLog() .putMessagePostionInfoWrapper(// req.getCommitLogOffset(),// req.getMsgSize(),// TransactionStateService.PreparedMessageTagsCode,// req.getStoreTimestamp(),// 0L// ); break; case MessageSysFlag.TransactionCommitType: case MessageSysFlag.TransactionRollbackType: DefaultMessageStore.this.getTransactionStateService().getTranRedoLog() .putMessagePostionInfoWrapper(// req.getCommitLogOffset(),// req.getMsgSize(),// req.getPreparedTransactionOffset(),// req.getStoreTimestamp(),// 0L// ); break; } if (DefaultMessageStore.this.getMessageStoreConfig().isMessageIndexEnable()) { DefaultMessageStore.this.indexService.buildIndex(req); } }
Example #26
Source File: IndexService.java From rocketmq with Apache License 2.0 | 4 votes |
public void buildIndex(DispatchRequest req) { IndexFile indexFile = retryGetAndCreateIndexFile(); if (indexFile != null) { long endPhyOffset = indexFile.getEndPhyOffset(); DispatchRequest msg = req; String topic = msg.getTopic(); String keys = msg.getKeys(); if (msg.getCommitLogOffset() < endPhyOffset) { return; } final int tranType = MessageSysFlag.getTransactionValue(msg.getSysFlag()); switch (tranType) { case MessageSysFlag.TransactionNotType: case MessageSysFlag.TransactionPreparedType: case MessageSysFlag.TransactionCommitType: break; case MessageSysFlag.TransactionRollbackType: return; } if (req.getUniqKey() != null) { indexFile = putKey(indexFile, msg, buildKey(topic, req.getUniqKey())); if (indexFile == null) { log.error("putKey error commitlog {} uniqkey {}", req.getCommitLogOffset(), req.getUniqKey()); return; } } if ((keys != null && keys.length() > 0)) { String[] keyset = keys.split(MessageConst.KEY_SEPARATOR); for (int i = 0; i < keyset.length; i++) { String key = keyset[i]; if (key.length() > 0) { indexFile = putKey(indexFile, msg, buildKey(topic, key)); if (indexFile == null) { log.error("putKey error commitlog {} uniqkey {}", req.getCommitLogOffset(), req.getUniqKey()); return; } } } } } else { log.error("build index error, stop building index"); } }
Example #27
Source File: TransactionStateService.java From rocketmq with Apache License 2.0 | 4 votes |
private void recoverStateTableNormal() { final List<MapedFile> mapedFiles = this.tranStateTable.getMapedFiles(); if (!mapedFiles.isEmpty()) { int index = mapedFiles.size() - 3; if (index < 0) index = 0; int mapedFileSizeLogics = this.tranStateTable.getMapedFileSize(); MapedFile mapedFile = mapedFiles.get(index); ByteBuffer byteBuffer = mapedFile.sliceByteBuffer(); /* * queue offset(global offset) */ long processOffset = mapedFile.getFileFromOffset(); /* * file offset(local offset) */ long mapedFileOffset = 0; while (true) { for (int i = 0; i < mapedFileSizeLogics; i += TSStoreUnitSize) { final long clOffset_read = byteBuffer.getLong(); final int size_read = byteBuffer.getInt(); final int timestamp_read = byteBuffer.getInt(); final int groupHashCode_read = byteBuffer.getInt(); /** * prepared/commit/rollback */ final int state_read = byteBuffer.getInt(); boolean stateOK = false; switch (state_read) { case MessageSysFlag.TransactionPreparedType: case MessageSysFlag.TransactionCommitType: case MessageSysFlag.TransactionRollbackType: stateOK = true; break; default: break; } if (clOffset_read >= 0 && size_read > 0 && stateOK) { mapedFileOffset = i + TSStoreUnitSize; } else { log.info("recover current transaction state table file over, " + mapedFile.getFileName() + " " + clOffset_read + " " + size_read + " " + timestamp_read); break; } } if (mapedFileOffset == mapedFileSizeLogics) { index++; if (index >= mapedFiles.size()) { log.info("recover last transaction state table file over, last maped file " + mapedFile.getFileName()); break; } else { mapedFile = mapedFiles.get(index); byteBuffer = mapedFile.sliceByteBuffer(); processOffset = mapedFile.getFileFromOffset(); mapedFileOffset = 0; log.info("recover next transaction state table file, " + mapedFile.getFileName()); } } else { log.info("recover current transaction state table queue over " + mapedFile.getFileName() + " " + (processOffset + mapedFileOffset)); break; } } processOffset += mapedFileOffset; this.tranStateTable.truncateDirtyFiles(processOffset); this.tranStateTableOffset.set(this.tranStateTable.getMaxOffset() / TSStoreUnitSize); log.info("recover normal over, transaction state table max offset: {}", this.tranStateTableOffset.get()); } }
Example #28
Source File: DefaultRequestProcessor.java From rocketmq with Apache License 2.0 | 4 votes |
private ByteBuffer messageToByteBuffer(final MessageExt msg) throws IOException { int sysFlag = MessageSysFlag.clearCompressedFlag(msg.getSysFlag()); if (msg.getBody() != null) { if (msg.getBody().length >= this.filtersrvController.getFiltersrvConfig().getCompressMsgBodyOverHowmuch()) { byte[] data = UtilAll.compress(msg.getBody(), this.filtersrvController.getFiltersrvConfig().getZipCompressLevel()); if (data != null) { msg.setBody(data); sysFlag |= MessageSysFlag.CompressedFlag; } } } final int bodyLength = msg.getBody() != null ? msg.getBody().length : 0; byte[] topicData = msg.getTopic().getBytes(MixAll.DEFAULT_CHARSET); final int topicLength = topicData.length; String properties = MessageDecoder.messageProperties2String(msg.getProperties()); byte[] propertiesData = properties.getBytes(MixAll.DEFAULT_CHARSET); final int propertiesLength = propertiesData.length; final int msgLen = 4 // 1 TOTALSIZE + 4 // 2 MAGICCODE + 4 // 3 BODYCRC + 4 // 4 QUEUEID + 4 // 5 FLAG + 8 // 6 QUEUEOFFSET + 8 // 7 PHYSICALOFFSET + 4 // 8 SYSFLAG + 8 // 9 BORNTIMESTAMP + 8 // 10 BORNHOST + 8 // 11 STORETIMESTAMP + 8 // 12 STOREHOSTADDRESS + 4 // 13 RECONSUMETIMES + 8 // 14 Prepared Transaction Offset + 4 + bodyLength // 14 BODY + 1 + topicLength // 15 TOPIC + 2 + propertiesLength // 16 propertiesLength + 0; ByteBuffer msgStoreItemMemory = ByteBuffer.allocate(msgLen); final MessageExt msgInner = msg; // 1 TOTALSIZE msgStoreItemMemory.putInt(msgLen); // 2 MAGICCODE msgStoreItemMemory.putInt(CommitLog.MessageMagicCode); // 3 BODYCRC msgStoreItemMemory.putInt(UtilAll.crc32(msgInner.getBody())); // 4 QUEUEID msgStoreItemMemory.putInt(msgInner.getQueueId()); // 5 FLAG msgStoreItemMemory.putInt(msgInner.getFlag()); // 6 QUEUEOFFSET msgStoreItemMemory.putLong(msgInner.getQueueOffset()); // 7 PHYSICALOFFSET msgStoreItemMemory.putLong(msgInner.getCommitLogOffset()); // 8 SYSFLAG msgStoreItemMemory.putInt(sysFlag); // 9 BORNTIMESTAMP msgStoreItemMemory.putLong(msgInner.getBornTimestamp()); // 10 BORNHOST msgStoreItemMemory.put(msgInner.getBornHostBytes()); // 11 STORETIMESTAMP msgStoreItemMemory.putLong(msgInner.getStoreTimestamp()); // 12 STOREHOSTADDRESS msgStoreItemMemory.put(msgInner.getStoreHostBytes()); // 13 RECONSUMETIMES msgStoreItemMemory.putInt(msgInner.getReconsumeTimes()); // 14 Prepared Transaction Offset msgStoreItemMemory.putLong(msgInner.getPreparedTransactionOffset()); // 15 BODY msgStoreItemMemory.putInt(bodyLength); if (bodyLength > 0) msgStoreItemMemory.put(msgInner.getBody()); // 16 TOPIC msgStoreItemMemory.put((byte) topicLength); msgStoreItemMemory.put(topicData); // 17 PROPERTIES msgStoreItemMemory.putShort((short) propertiesLength); if (propertiesLength > 0) msgStoreItemMemory.put(propertiesData); return msgStoreItemMemory; }
Example #29
Source File: IndexService.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 votes |
public void buildIndex(DispatchRequest req) { boolean breakdown = false; IndexFile indexFile = retryGetAndCreateIndexFile(); if (indexFile != null) { long endPhyOffset = indexFile.getEndPhyOffset(); DispatchRequest msg = req; String topic = msg.getTopic(); String keys = msg.getKeys(); if (msg.getCommitLogOffset() < endPhyOffset) { return; } final int tranType = MessageSysFlag.getTransactionValue(msg.getSysFlag()); switch (tranType) { case MessageSysFlag.TransactionNotType: case MessageSysFlag.TransactionPreparedType: break; case MessageSysFlag.TransactionCommitType: case MessageSysFlag.TransactionRollbackType: return; } if (keys != null && keys.length() > 0) { String[] keyset = keys.split(MessageConst.KEY_SEPARATOR); for (String key : keyset) { if (key.length() > 0) { for (boolean ok = indexFile.putKey(buildKey(topic, key), msg.getCommitLogOffset(), msg.getStoreTimestamp()); !ok;) { log.warn("index file full, so create another one, " + indexFile.getFileName()); indexFile = retryGetAndCreateIndexFile(); if (null == indexFile) { breakdown = true; return; } ok = indexFile.putKey(buildKey(topic, key), msg.getCommitLogOffset(), msg.getStoreTimestamp()); } } } } } else { log.error("build index error, stop building index"); } }
Example #30
Source File: DefaultRequestProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 votes |
private ByteBuffer messageToByteBuffer(final MessageExt msg) throws IOException { int sysFlag = MessageSysFlag.clearCompressedFlag(msg.getSysFlag()); if (msg.getBody() != null) { if (msg.getBody().length >= this.filtersrvController.getFiltersrvConfig().getCompressMsgBodyOverHowmuch()) { byte[] data = UtilAll.compress(msg.getBody(), this.filtersrvController.getFiltersrvConfig().getZipCompressLevel()); if (data != null) { msg.setBody(data); sysFlag |= MessageSysFlag.CompressedFlag; } } } final int bodyLength = msg.getBody() != null ? msg.getBody().length : 0; byte[] topicData = msg.getTopic().getBytes(MixAll.DEFAULT_CHARSET); final int topicLength = topicData.length; String properties = MessageDecoder.messageProperties2String(msg.getProperties()); byte[] propertiesData = properties.getBytes(MixAll.DEFAULT_CHARSET); final int propertiesLength = propertiesData.length; final int msgLen = 4 // 1 TOTALSIZE + 4 // 2 MAGICCODE + 4 // 3 BODYCRC + 4 // 4 QUEUEID + 4 // 5 FLAG + 8 // 6 QUEUEOFFSET + 8 // 7 PHYSICALOFFSET + 4 // 8 SYSFLAG + 8 // 9 BORNTIMESTAMP + 8 // 10 BORNHOST + 8 // 11 STORETIMESTAMP + 8 // 12 STOREHOSTADDRESS + 4 // 13 RECONSUMETIMES + 8 // 14 Prepared Transaction Offset + 4 + bodyLength // 14 BODY + 1 + topicLength // 15 TOPIC + 2 + propertiesLength // 16 propertiesLength + 0; ByteBuffer msgStoreItemMemory = ByteBuffer.allocate(msgLen); final MessageExt msgInner = msg; // 1 TOTALSIZE msgStoreItemMemory.putInt(msgLen); // 2 MAGICCODE msgStoreItemMemory.putInt(CommitLog.MessageMagicCode); // 3 BODYCRC msgStoreItemMemory.putInt(UtilAll.crc32(msgInner.getBody())); // 4 QUEUEID msgStoreItemMemory.putInt(msgInner.getQueueId()); // 5 FLAG msgStoreItemMemory.putInt(msgInner.getFlag()); // 6 QUEUEOFFSET msgStoreItemMemory.putLong(msgInner.getQueueOffset()); // 7 PHYSICALOFFSET msgStoreItemMemory.putLong(msgInner.getCommitLogOffset()); // 8 SYSFLAG msgStoreItemMemory.putInt(sysFlag); // 9 BORNTIMESTAMP msgStoreItemMemory.putLong(msgInner.getBornTimestamp()); // 10 BORNHOST msgStoreItemMemory.put(msgInner.getBornHostBytes()); // 11 STORETIMESTAMP msgStoreItemMemory.putLong(msgInner.getStoreTimestamp()); // 12 STOREHOSTADDRESS msgStoreItemMemory.put(msgInner.getStoreHostBytes()); // 13 RECONSUMETIMES msgStoreItemMemory.putInt(msgInner.getReconsumeTimes()); // 14 Prepared Transaction Offset msgStoreItemMemory.putLong(msgInner.getPreparedTransactionOffset()); // 15 BODY msgStoreItemMemory.putInt(bodyLength); if (bodyLength > 0) msgStoreItemMemory.put(msgInner.getBody()); // 16 TOPIC msgStoreItemMemory.put((byte) topicLength); msgStoreItemMemory.put(topicData); // 17 PROPERTIES msgStoreItemMemory.putShort((short) propertiesLength); if (propertiesLength > 0) msgStoreItemMemory.put(propertiesData); return msgStoreItemMemory; }