Java Code Examples for com.alibaba.rocketmq.common.sysflag.MessageSysFlag#TransactionCommitType
The following examples show how to use
com.alibaba.rocketmq.common.sysflag.MessageSysFlag#TransactionCommitType .
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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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"); } }