Java Code Examples for org.apache.rocketmq.common.sysflag.MessageSysFlag#TRANSACTION_COMMIT_TYPE

The following examples show how to use org.apache.rocketmq.common.sysflag.MessageSysFlag#TRANSACTION_COMMIT_TYPE . 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 rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
public void doDispatch(DispatchRequest req) {
    final int tranType = MessageSysFlag.getTransactionValue(req.getSysFlag());
    switch (tranType) {
        case MessageSysFlag.TRANSACTION_NOT_TYPE:
        case MessageSysFlag.TRANSACTION_COMMIT_TYPE:
            DefaultMessageStore.this.putMessagePositionInfo(req.getTopic(), req.getQueueId(), req.getCommitLogOffset(), req.getMsgSize(),
                    req.getTagsCode(), req.getStoreTimestamp(), req.getConsumeQueueOffset());
            break;
        case MessageSysFlag.TRANSACTION_PREPARED_TYPE:
        case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE:
            break;
    }
    this.handingTransactionState(req);
    if (DefaultMessageStore.this.getMessageStoreConfig().isMessageIndexEnable()) {
        DefaultMessageStore.this.indexService.buildIndex(req);
    }
}
 
Example 2
Source File: EndTransactionRequestHeader.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Override
public void checkFields() throws RemotingCommandException {
    if (MessageSysFlag.TRANSACTION_NOT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_COMMIT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_ROLLBACK_TYPE == this.commitOrRollback) {
        return;
    }

    throw new RemotingCommandException("commitOrRollback field wrong");
}
 
Example 3
Source File: EndTransactionRequestHeader.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Override
public void checkFields() throws RemotingCommandException {
    if (MessageSysFlag.TRANSACTION_NOT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_COMMIT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_ROLLBACK_TYPE == this.commitOrRollback) {
        return;
    }

    throw new RemotingCommandException("commitOrRollback field wrong");
}
 
Example 4
Source File: EndTransactionRequestHeader.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Override
public void checkFields() throws RemotingCommandException {
    if (MessageSysFlag.TRANSACTION_NOT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_COMMIT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_ROLLBACK_TYPE == this.commitOrRollback) {
        return;
    }

    throw new RemotingCommandException("commitOrRollback field wrong");
}
 
Example 5
Source File: EndTransactionRequestHeader.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Override
public void checkFields() throws RemotingCommandException {
    if (MessageSysFlag.TRANSACTION_NOT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_COMMIT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_ROLLBACK_TYPE == this.commitOrRollback) {
        return;
    }

    throw new RemotingCommandException("commitOrRollback field wrong");
}
 
Example 6
Source File: EndTransactionRequestHeader.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public void checkFields() throws RemotingCommandException {
    if (MessageSysFlag.TRANSACTION_NOT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_COMMIT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_ROLLBACK_TYPE == this.commitOrRollback) {
        return;
    }

    throw new RemotingCommandException("commitOrRollback field wrong");
}
 
Example 7
Source File: EndTransactionRequestHeader.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Override
public void checkFields() throws RemotingCommandException {
    if (MessageSysFlag.TRANSACTION_NOT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_COMMIT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_ROLLBACK_TYPE == this.commitOrRollback) {
        return;
    }

    throw new RemotingCommandException("commitOrRollback field wrong");
}
 
Example 8
Source File: CheckTransactionStateResponseHeader.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public void checkFields() throws RemotingCommandException {
    if (MessageSysFlag.TRANSACTION_COMMIT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_ROLLBACK_TYPE == this.commitOrRollback) {
        return;
    }

    throw new RemotingCommandException("commitOrRollback field wrong");
}
 
Example 9
Source File: DefaultMessageStore.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Override
public void dispatch(DispatchRequest request) {
    final int tranType = MessageSysFlag.getTransactionValue(request.getSysFlag());
    switch (tranType) {
        // 1、分发消息位置信息到ConsumeQueue
        case MessageSysFlag.TRANSACTION_NOT_TYPE:
        case MessageSysFlag.TRANSACTION_COMMIT_TYPE:
            DefaultMessageStore.this.putMessagePositionInfo(request);  // 将请求发到具体的Consume Queue
            break;
        case MessageSysFlag.TRANSACTION_PREPARED_TYPE:
        case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE:
            break;
    }
}
 
Example 10
Source File: CheckTransactionStateResponseHeader.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public void checkFields() throws RemotingCommandException {
    if (MessageSysFlag.TRANSACTION_COMMIT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_ROLLBACK_TYPE == this.commitOrRollback) {
        return;
    }

    throw new RemotingCommandException("commitOrRollback field wrong");
}
 
Example 11
Source File: DefaultMessageStore.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public void dispatch(DispatchRequest request) {
    final int tranType = MessageSysFlag.getTransactionValue(request.getSysFlag());
    switch (tranType) {
        case MessageSysFlag.TRANSACTION_NOT_TYPE:
        case MessageSysFlag.TRANSACTION_COMMIT_TYPE:
            DefaultMessageStore.this.putMessagePositionInfo(request);
            break;
        case MessageSysFlag.TRANSACTION_PREPARED_TYPE:
        case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE:
            break;
        default:
            break;
    }
}
 
Example 12
Source File: CheckTransactionStateResponseHeader.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void checkFields() throws RemotingCommandException {
    if (MessageSysFlag.TRANSACTION_COMMIT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_ROLLBACK_TYPE == this.commitOrRollback) {
        return;
    }

    throw new RemotingCommandException("commitOrRollback field wrong");
}
 
Example 13
Source File: DefaultMessageStore.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Override
        public void dispatch(DispatchRequest request) {
//            获取事务类型=》
            final int tranType = MessageSysFlag.getTransactionValue(request.getSysFlag());
            switch (tranType) {
                case MessageSysFlag.TRANSACTION_NOT_TYPE:
                case MessageSysFlag.TRANSACTION_COMMIT_TYPE:
//                    构建存放消息位置信息=》
                    DefaultMessageStore.this.putMessagePositionInfo(request);
                    break;
                case MessageSysFlag.TRANSACTION_PREPARED_TYPE:
                case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE:
                    break;
            }
        }
 
Example 14
Source File: CheckTransactionStateResponseHeader.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Override
public void checkFields() throws RemotingCommandException {
    if (MessageSysFlag.TRANSACTION_COMMIT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_ROLLBACK_TYPE == this.commitOrRollback) {
        return;
    }

    throw new RemotingCommandException("commitOrRollback field wrong");
}
 
Example 15
Source File: CheckTransactionStateResponseHeader.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Override
public void checkFields() throws RemotingCommandException {
    if (MessageSysFlag.TRANSACTION_COMMIT_TYPE == this.commitOrRollback) {
        return;
    }

    if (MessageSysFlag.TRANSACTION_ROLLBACK_TYPE == this.commitOrRollback) {
        return;
    }

    throw new RemotingCommandException("commitOrRollback field wrong");
}
 
Example 16
Source File: IndexService.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
/**
 * 构造索引。当commitlog添加成功后构造索引
 * 构造keys的每一个key的索引文件和uniquekeys的文件
 * @param req req
 */
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();

        //已经提交过偏移量了,直接return
        if (msg.getCommitLogOffset() < endPhyOffset) {
            return;
        }

        final int tranType = MessageSysFlag.getTransactionValue(msg.getSysFlag());
        switch (tranType) {
            case MessageSysFlag.TRANSACTION_NOT_TYPE:
            case MessageSysFlag.TRANSACTION_PREPARED_TYPE:
            case MessageSysFlag.TRANSACTION_COMMIT_TYPE:
                break;
            case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE:
                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;
            }
        }

        //遍历keys循环添加索引文件
        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 17
Source File: IndexService.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
public void buildIndex(DispatchRequest req) {
    IndexFile indexFile = retryGetAndCreateIndexFile();//如果indexFile有就获取没有就创建
    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.TRANSACTION_NOT_TYPE:
            case MessageSysFlag.TRANSACTION_PREPARED_TYPE:
            case MessageSysFlag.TRANSACTION_COMMIT_TYPE:
                break;
            case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE:
                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 18
Source File: IndexService.java    From rocketmq_trans_message with Apache License 2.0 4 votes vote down vote up
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.TRANSACTION_NOT_TYPE:
            case MessageSysFlag.TRANSACTION_PREPARED_TYPE:
            case MessageSysFlag.TRANSACTION_COMMIT_TYPE:
                break;
            case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE:
                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 19
Source File: IndexService.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
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.TRANSACTION_NOT_TYPE:
                case MessageSysFlag.TRANSACTION_PREPARED_TYPE:
                case MessageSysFlag.TRANSACTION_COMMIT_TYPE:
                    break;
                case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE:
                    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 20
Source File: TransactionStateFileService.java    From rocketmq_trans_message with Apache License 2.0 4 votes vote down vote up
/**
 * 加载(解析)TranStateTable 的 MappedFile
 * 1. 清理多余 MappedFile,设置最后一个 MappedFile的写入位置(position
 * 2. 设置 TanStateTable 最大物理位置(可写入位置)
 */
private void recoverStateTableNormal() {
    final List<MappedFile> mapedFiles = this.tranStateTable.getMappedFiles();
    if (!mapedFiles.isEmpty()) {
        // 从倒数第三个文件开始恢复
        int index = mapedFiles.size() - 3;
        if (index < 0) {
            index = 0;
        }

        int mapedFileSizeLogics = this.tranStateTable.getMappedFileSize();
        MappedFile mapedFile = mapedFiles.get(index);
        ByteBuffer byteBuffer = mapedFile.sliceByteBuffer();
        long processOffset = mapedFile.getFileFromOffset();
        long mapedFileOffset = 0;
        while (true) {
            for (int i = 0; i < mapedFileSizeLogics; i += TSS_STORE_UNIT_SIZE) {

                final long clOffset_read = byteBuffer.getLong();
                final int size_read = byteBuffer.getInt();
                final int timestamp_read = byteBuffer.getInt();
                final int groupHashCode_read = byteBuffer.getInt();
                final int state_read = byteBuffer.getInt();

                boolean stateOK = false;
                switch (state_read) {
                    case MessageSysFlag.TRANSACTION_PREPARED_TYPE:
                    case MessageSysFlag.TRANSACTION_COMMIT_TYPE:
                    case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE:
                        stateOK = true;
                        break;
                    default:
                        break;
                }

                // 说明当前存储单元有效
                if (clOffset_read >= 0 && size_read > 0 && stateOK) {
                    mapedFileOffset = i + TSS_STORE_UNIT_SIZE;
                } 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()) { // 循环while结束
                    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;
            }
        }

        // 清理多余 MappedFile,设置最后一个 MappedFile的写入位置(position
        processOffset += mapedFileOffset;
        this.tranStateTable.truncateDirtyFiles(processOffset);

        // 设置 TanStateTable 最大物理位置(可写入位置)
        this.tranStateTableOffset.set(this.tranStateTable.getMaxOffset() / TSS_STORE_UNIT_SIZE);
        log.info("recover normal over, transaction state table max offset: {}", this.tranStateTableOffset.get());
    }
}