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

The following examples show how to use org.apache.rocketmq.common.sysflag.MessageSysFlag#TRANSACTION_ROLLBACK_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: 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 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: DefaultMessageStore.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
/**
 * 执行调度请求
 * 1. 非事务消息 或 事务提交消息 建立 消息位置信息 到 ConsumeQueue
 * 2. 建立 索引信息 到 IndexFile
 *
 * @param req 调度请求
 */
public void doDispatch(DispatchRequest req) {
    // 非事务消息 或 事务提交消息 建立 消息位置信息 到 ConsumeQueue
    final int tranType = MessageSysFlag.getTransactionValue(req.getSysFlag());
    switch (tranType) {
        case MessageSysFlag.TRANSACTION_NOT_TYPE: // 非事务消息
        case MessageSysFlag.TRANSACTION_COMMIT_TYPE: // 事务消息COMMIT
            DefaultMessageStore.this.putMessagePositionInfo(req.getTopic(), req.getQueueId(), req.getCommitLogOffset(), req.getMsgSize(),
                req.getTagsCode(), req.getStoreTimestamp(), req.getConsumeQueueOffset());
            break;
        case MessageSysFlag.TRANSACTION_PREPARED_TYPE: // 事务消息PREPARED
        case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE: // 事务消息ROLLBACK
            break;
    }
    // 建立 索引信息 到 IndexFile
    if (DefaultMessageStore.this.getMessageStoreConfig().isMessageIndexEnable()) {
        DefaultMessageStore.this.indexService.buildIndex(req);
    }
}
 
Example 4
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 5
Source File: DefaultMessageStore.java    From DDMQ 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 6
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 7
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 8
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 9
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 10
Source File: DefaultMessageStore.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
/**
 * 记录事务状态
 *
 * @param req
 */
private void handingTransactionState(DispatchRequest req) {
    final int tranType = MessageSysFlag.getTransactionValue(req.getSysFlag());
    boolean persistInDB = DefaultMessageStore.this.getMessageStoreConfig().isTransactionLogInDB();
    if (req.getProducerGroup() != null) {
        switch (tranType) {
            case MessageSysFlag.TRANSACTION_NOT_TYPE:
                break;
            case MessageSysFlag.TRANSACTION_PREPARED_TYPE:
                getTransactionStateService().appendPreparedTransaction(req);
                break;
            case MessageSysFlag.TRANSACTION_COMMIT_TYPE:
            case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE:
                getTransactionStateService().updateTransactionState(req);
                break;
        }
    }
    if (!persistInDB) {
        switch (tranType) {
            case MessageSysFlag.TRANSACTION_NOT_TYPE:
                break;
            case MessageSysFlag.TRANSACTION_PREPARED_TYPE:
                DefaultMessageStore.this.getTransactionStateService().getTranRedoLog().putMessagePositionInfoWrapper(
                        req.getCommitLogOffset(), req.getMsgSize(), TransactionStateFileService.PREPARED_MESSAGE_TAGS_CODE,
                        req.getStoreTimestamp(), 0L);
                break;
            case MessageSysFlag.TRANSACTION_COMMIT_TYPE:
            case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE:
                DefaultMessageStore.this.getTransactionStateService().getTranRedoLog().putMessagePositionInfoWrapper(
                        req.getCommitLogOffset(), req.getMsgSize(), req.getPreparedTransactionOffset(),
                        req.getStoreTimestamp(), 0L);
                break;
        }
    }
}
 
Example 11
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 12
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 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: DefaultMessageStore.java    From DDMQ 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 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 DDMQ 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();
        Map<String, String> properties = msg.getPropertiesMap();
        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 {} key {}", req.getCommitLogOffset(), key);
                        return;
                    }
                }
            }
        }

        if (properties != null & properties.containsKey(MessageConst.PROPERTY_USER_TRACE_ID)) {
            String traceId = properties.get(MessageConst.PROPERTY_USER_TRACE_ID);
            if (traceId != null) {
                indexFile = putKey(indexFile, msg, buildKey(topic, traceId));
                if (indexFile == null) {
                    log.error("putKey error commitlog {} traceId {}", req.getCommitLogOffset(), traceId);
                    return;
                }
            }
        }
    } else {
        log.error("build index error, stop building index");
    }
}
 
Example 20
Source File: IndexService.java    From DDMQ 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();
        Map<String, String> properties = msg.getPropertiesMap();
        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 {} key {}", req.getCommitLogOffset(), key);
                        return;
                    }
                }
            }
        }

        if (properties != null & properties.containsKey(MessageConst.PROPERTY_USER_TRACE_ID)) {
            String traceId = properties.get(MessageConst.PROPERTY_USER_TRACE_ID);
            if (traceId != null) {
                indexFile = putKey(indexFile, msg, buildKey(topic, traceId));
                if (indexFile == null) {
                    log.error("putKey error commitlog {} traceId {}", req.getCommitLogOffset(), traceId);
                    return;
                }
            }
        }
    } else {
        log.error("build index error, stop building index");
    }
}