com.alibaba.rocketmq.store.DispatchRequest Java Examples

The following examples show how to use com.alibaba.rocketmq.store.DispatchRequest. 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: IndexService.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private IndexFile putKey(IndexFile indexFile, DispatchRequest msg, String idxKey) {
    for (boolean ok =
            indexFile.putKey(idxKey, msg.getCommitLogOffset(),
                msg.getStoreTimestamp()); !ok;) {
        log.warn("index file full, so create another one, " + indexFile.getFileName());
        indexFile = retryGetAndCreateIndexFile();
        if (null == indexFile) {
            return null;
        }

        ok =
                indexFile.putKey(idxKey, msg.getCommitLogOffset(),
                    msg.getStoreTimestamp());
    }
    return indexFile;
}
 
Example #2
Source File: IndexService.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
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 #3
Source File: IndexService.java    From rocketmq 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.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 #4
Source File: IndexService.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
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");
    }
}