Java Code Examples for org.apache.rocketmq.store.DefaultMessageStore

The following examples show how to use org.apache.rocketmq.store.DefaultMessageStore. These examples are extracted from open source projects. 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 Project: DDMQ   Source File: AdminBrokerProcessor.java    License: Apache License 2.0 6 votes vote down vote up
private RemotingCommand getAllDelayOffset(ChannelHandlerContext ctx, RemotingCommand request) {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

    String content = ((DefaultMessageStore) this.brokerController.getMessageStore()).getScheduleMessageService().encode();
    if (content != null && content.length() > 0) {
        try {
            response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
        } catch (UnsupportedEncodingException e) {
            log.error("get all delay offset from master error.", e);

            response.setCode(ResponseCode.SYSTEM_ERROR);
            response.setRemark("UnsupportedEncodingException " + e);
            return response;
        }
    } else {
        log.error("No delay offset in this broker, client: {} ", ctx.channel().remoteAddress());
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark("No delay offset in this broker");
        return response;
    }

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);

    return response;
}
 
Example 2
Source Project: DDMQ   Source File: AdminBrokerProcessor.java    License: Apache License 2.0 6 votes vote down vote up
private RemotingCommand getAllMaxOffset(ChannelHandlerContext ctx, RemotingCommand request) {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

    DefaultMessageStore messageStore = (DefaultMessageStore) this.brokerController.getMessageStore();
    ConcurrentHashMap<String, ConcurrentHashMap<Integer, Long>> offsetTable = new ConcurrentHashMap<String, ConcurrentHashMap<Integer, Long>>();
    ConcurrentMap<String, ConcurrentMap<Integer, ConsumeQueue>> consumeQueueTable = messageStore.getConsumeQueueTable();
    for (Map.Entry<String, ConcurrentMap<Integer, ConsumeQueue>> entry : consumeQueueTable.entrySet()) {
        String topic = entry.getKey();
        for (Map.Entry<Integer, ConsumeQueue> entry1 : entry.getValue().entrySet()) {
            Integer qid = entry1.getKey();
            long maxOffset = entry1.getValue().getMaxOffsetInQueue();
            if (!offsetTable.containsKey(topic)) {
                offsetTable.put(topic, new ConcurrentHashMap<Integer, Long>());
            }
            offsetTable.get(topic).put(qid, maxOffset);
        }
    }
    AllMaxOffset allMaxOffset = new AllMaxOffset();
    allMaxOffset.setOffsetTable(offsetTable);
    response.setBody(allMaxOffset.encode());
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example 3
Source Project: DDMQ   Source File: MessageStoreWithFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount,
                                             int msgCountPerTopic) throws Exception {
    List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>();
    for (int i = 0; i < topicCount; i++) {
        String realTopic = topic + i;
        for (int j = 0; j < msgCountPerTopic; j++) {
            MessageExtBrokerInner msg = buildMessage();
            msg.setTopic(realTopic);
            msg.putUserProperty("a", String.valueOf(j * 10 + 5));
            msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties()));

            PutMessageResult result = master.putMessage(msg);

            msg.setMsgId(result.getAppendMessageResult().getMsgId());

            msgs.add(msg);
        }
    }

    return msgs;
}
 
Example 4
Source Project: rocketmq-4.3.0   Source File: MessageStoreWithFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount,
                                             int msgCountPerTopic) throws Exception {
    List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>();
    for (int i = 0; i < topicCount; i++) {
        String realTopic = topic + i;
        for (int j = 0; j < msgCountPerTopic; j++) {
            MessageExtBrokerInner msg = buildMessage();
            msg.setTopic(realTopic);
            msg.putUserProperty("a", String.valueOf(j * 10 + 5));
            msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties()));

            PutMessageResult result = master.putMessage(msg);

            msg.setMsgId(result.getAppendMessageResult().getMsgId());

            msgs.add(msg);
        }
    }

    return msgs;
}
 
Example 5
Source Project: rocketmq-read   Source File: MessageStoreWithFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount,
                                             int msgCountPerTopic) throws Exception {
    List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>();
    for (int i = 0; i < topicCount; i++) {
        String realTopic = topic + i;
        for (int j = 0; j < msgCountPerTopic; j++) {
            MessageExtBrokerInner msg = buildMessage();
            msg.setTopic(realTopic);
            msg.putUserProperty("a", String.valueOf(j * 10 + 5));
            msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties()));

            PutMessageResult result = master.putMessage(msg);

            msg.setMsgId(result.getAppendMessageResult().getMsgId());

            msgs.add(msg);
        }
    }

    return msgs;
}
 
Example 6
Source Project: rocketmq   Source File: AdminBrokerProcessor.java    License: Apache License 2.0 6 votes vote down vote up
private RemotingCommand getAllDelayOffset(ChannelHandlerContext ctx, RemotingCommand request) {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

    String content = ((DefaultMessageStore)this.brokerController.getMessageStore()).getScheduleMessageService().encode();
    if (content != null && content.length() > 0) {
        try {
            response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
        } catch (UnsupportedEncodingException e) {
            log.error("get all delay offset from master error.", e);

            response.setCode(ResponseCode.SYSTEM_ERROR);
            response.setRemark("UnsupportedEncodingException " + e);
            return response;
        }
    } else {
        log.error("No delay offset in this broker, client: {} ", ctx.channel().remoteAddress());
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark("No delay offset in this broker");
        return response;
    }

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);

    return response;
}
 
Example 7
Source Project: DDMQ   Source File: AdminBrokerProcessor.java    License: Apache License 2.0 6 votes vote down vote up
private RemotingCommand getAllDelayOffset(ChannelHandlerContext ctx, RemotingCommand request) {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

    String content = ((DefaultMessageStore) this.brokerController.getMessageStore()).getScheduleMessageService().encode();
    if (content != null && content.length() > 0) {
        try {
            response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
        } catch (UnsupportedEncodingException e) {
            log.error("get all delay offset from master error.", e);

            response.setCode(ResponseCode.SYSTEM_ERROR);
            response.setRemark("UnsupportedEncodingException " + e);
            return response;
        }
    } else {
        log.error("No delay offset in this broker, client: {} ", ctx.channel().remoteAddress());
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark("No delay offset in this broker");
        return response;
    }

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);

    return response;
}
 
Example 8
Source Project: DDMQ   Source File: AdminBrokerProcessor.java    License: Apache License 2.0 6 votes vote down vote up
private RemotingCommand getAllMaxOffset(ChannelHandlerContext ctx, RemotingCommand request) {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

    DefaultMessageStore messageStore = (DefaultMessageStore) this.brokerController.getMessageStore();
    ConcurrentHashMap<String, ConcurrentHashMap<Integer, Long>> offsetTable = new ConcurrentHashMap<String, ConcurrentHashMap<Integer, Long>>();
    ConcurrentMap<String, ConcurrentMap<Integer, ConsumeQueue>> consumeQueueTable = messageStore.getConsumeQueueTable();
    for (Map.Entry<String, ConcurrentMap<Integer, ConsumeQueue>> entry : consumeQueueTable.entrySet()) {
        String topic = entry.getKey();
        for (Map.Entry<Integer, ConsumeQueue> entry1 : entry.getValue().entrySet()) {
            Integer qid = entry1.getKey();
            long maxOffset = entry1.getValue().getMaxOffsetInQueue();
            if (!offsetTable.containsKey(topic)) {
                offsetTable.put(topic, new ConcurrentHashMap<Integer, Long>());
            }
            offsetTable.get(topic).put(qid, maxOffset);
        }
    }
    AllMaxOffset allMaxOffset = new AllMaxOffset();
    allMaxOffset.setOffsetTable(offsetTable);
    response.setBody(allMaxOffset.encode());
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example 9
Source Project: DDMQ   Source File: MessageStoreWithFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount,
                                             int msgCountPerTopic) throws Exception {
    List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>();
    for (int i = 0; i < topicCount; i++) {
        String realTopic = topic + i;
        for (int j = 0; j < msgCountPerTopic; j++) {
            MessageExtBrokerInner msg = buildMessage();
            msg.setTopic(realTopic);
            msg.putUserProperty("a", String.valueOf(j * 10 + 5));
            msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties()));

            PutMessageResult result = master.putMessage(msg);

            msg.setMsgId(result.getAppendMessageResult().getMsgId());

            msgs.add(msg);
        }
    }

    return msgs;
}
 
Example 10
private RemotingCommand getAllDelayOffset(ChannelHandlerContext ctx, RemotingCommand request) {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

    String content = ((DefaultMessageStore) this.brokerController.getMessageStore()).getScheduleMessageService().encode();
    if (content != null && content.length() > 0) {
        try {
            response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
        } catch (UnsupportedEncodingException e) {
            log.error("get all delay offset from master error.", e);

            response.setCode(ResponseCode.SYSTEM_ERROR);
            response.setRemark("UnsupportedEncodingException " + e);
            return response;
        }
    } else {
        log.error("No delay offset in this broker, client: {} ", ctx.channel().remoteAddress());
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark("No delay offset in this broker");
        return response;
    }

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);

    return response;
}
 
Example 11
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount, int msgCountPerTopic) throws Exception {
    List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>();
    for (int i = 0; i < topicCount; i++) {
        String realTopic = topic + i;
        for (int j = 0; j < msgCountPerTopic; j++) {
            MessageExtBrokerInner msg = buildMessage();
            msg.setTopic(realTopic);
            msg.putUserProperty("a", String.valueOf(j * 10 + 5));
            msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties()));

            PutMessageResult result = master.putMessage(msg);

            msg.setMsgId(result.getAppendMessageResult().getMsgId());

            msgs.add(msg);
        }
    }

    return msgs;
}
 
Example 12
public TransactionRecordFlush2DBService(DefaultMessageStore defaultMessageStore) {
    MessageStoreConfig messageStoreConfig = defaultMessageStore.getMessageStoreConfig();
    this.transactionOffsetConifgService = new TransactionOffsetConifgService(defaultMessageStore);
    TransactionTableDefConfigService transactionTableDefConfigService = new TransactionTableDefConfigService(defaultMessageStore);
    transactionTableDefConfigService.load();
    int retry = 0;
    boolean isCheckTable = false;
    this.transactionStore = new JDBCTransactionStore(messageStoreConfig);
    this.transactionStore.load();
    do {
        int tableSuffix = transactionTableDefConfigService.getTableSuffix(messageStoreConfig);
        this.transactionStore.setTableSuffix(tableSuffix);
        log.info("loadTableStoreConfig tableSuffix={}", tableSuffix);
    } while (!(isCheckTable = transactionStore.createTableIfNotExists()) && ++retry < 5);

    if (!isCheckTable) {
        throw new RuntimeException("check db info error!");
    } else {
        transactionTableDefConfigService.persist();
    }

    for (int i = 0; i < REQUEST_BUFFER_IN_QUEUE; i++) {
        dispatchRequestBufferQueue.add(new DispatchRequestCollections(new AtomicInteger(0), new ArrayList<>()));
    }
}
 
Example 13
Source Project: rocketmq   Source File: MessageStoreWithFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount,
                                             int msgCountPerTopic) throws Exception {
    List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>();
    for (int i = 0; i < topicCount; i++) {
        String realTopic = topic + i;
        for (int j = 0; j < msgCountPerTopic; j++) {
            MessageExtBrokerInner msg = buildMessage();
            msg.setTopic(realTopic);
            msg.putUserProperty("a", String.valueOf(j * 10 + 5));
            msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties()));

            PutMessageResult result = master.putMessage(msg);

            msg.setMsgId(result.getAppendMessageResult().getMsgId());

            msgs.add(msg);
        }
    }

    return msgs;
}
 
Example 14
Source Project: rocketmq   Source File: DLedgerCommitLog.java    License: Apache License 2.0 6 votes vote down vote up
public DLedgerCommitLog(final DefaultMessageStore defaultMessageStore) {
    super(defaultMessageStore);
    dLedgerConfig = new DLedgerConfig();
    dLedgerConfig.setEnableDiskForceClean(defaultMessageStore.getMessageStoreConfig().isCleanFileForciblyEnable());
    dLedgerConfig.setStoreType(DLedgerConfig.FILE);
    dLedgerConfig.setSelfId(defaultMessageStore.getMessageStoreConfig().getdLegerSelfId());
    dLedgerConfig.setGroup(defaultMessageStore.getMessageStoreConfig().getdLegerGroup());
    dLedgerConfig.setPeers(defaultMessageStore.getMessageStoreConfig().getdLegerPeers());
    dLedgerConfig.setStoreBaseDir(defaultMessageStore.getMessageStoreConfig().getStorePathRootDir());
    dLedgerConfig.setMappedFileSizeForEntryData(defaultMessageStore.getMessageStoreConfig().getMappedFileSizeCommitLog());
    dLedgerConfig.setDeleteWhen(defaultMessageStore.getMessageStoreConfig().getDeleteWhen());
    dLedgerConfig.setFileReservedHours(defaultMessageStore.getMessageStoreConfig().getFileReservedTime() + 1);
    id = Integer.valueOf(dLedgerConfig.getSelfId().substring(1)) + 1;
    dLedgerServer = new DLedgerServer(dLedgerConfig);
    dLedgerFileStore = (DLedgerMmapFileStore) dLedgerServer.getdLedgerStore();
    DLedgerMmapFileStore.AppendHook appendHook = (entry, buffer, bodyOffset) -> {
        assert bodyOffset == DLedgerEntry.BODY_OFFSET;
        buffer.position(buffer.position() + bodyOffset + MessageDecoder.PHY_POS_POSITION);
        buffer.putLong(entry.getPos() + bodyOffset);
    };
    dLedgerFileStore.addAppendHook(appendHook);
    dLedgerFileList = dLedgerFileStore.getDataFileList();
    this.messageSerializer = new MessageSerializer(defaultMessageStore.getMessageStoreConfig().getMaxMessageSize());

}
 
Example 15
Source Project: rocketmq   Source File: MessageStoreTestBase.java    License: Apache License 2.0 6 votes vote down vote up
protected DefaultMessageStore createMessageStore(String base, boolean createAbort) throws Exception {
    baseDirs.add(base);
    MessageStoreConfig storeConfig = new MessageStoreConfig();
    storeConfig.setMappedFileSizeCommitLog(1024 * 100);
    storeConfig.setMappedFileSizeConsumeQueue(1024);
    storeConfig.setMaxHashSlotNum(100);
    storeConfig.setMaxIndexNum(100 * 10);
    storeConfig.setStorePathRootDir(base);
    storeConfig.setStorePathCommitLog(base + File.separator + "commitlog");
    storeConfig.setFlushDiskType(FlushDiskType.ASYNC_FLUSH);
    DefaultMessageStore defaultMessageStore = new DefaultMessageStore(storeConfig,  new BrokerStatsManager("CommitlogTest"), (topic, queueId, logicOffset, tagsCode, msgStoreTime, filterBitMap, properties) -> {

    }, new BrokerConfig());

    if (createAbort) {
        String fileName = StorePathConfigHelper.getAbortFile(storeConfig.getStorePathRootDir());
        makeSureFileExists(fileName);
    }
    Assert.assertTrue(defaultMessageStore.load());
    defaultMessageStore.start();
    return defaultMessageStore;
}
 
Example 16
Source Project: DDMQ   Source File: BrokerController.java    License: Apache License 2.0 5 votes vote down vote up
private void shutdownOldMaster() {
    if (masterAndSlaveDiffPrintFuture != null) {
        masterAndSlaveDiffPrintFuture.cancel(false);
        masterAndSlaveDiffPrintFuture = null;
    }
    if (messageStore instanceof DefaultMessageStore) {
        ((DefaultMessageStore) messageStore).getHaService().destroyConnections();
    }

    log.info("shutdown the master role");
}
 
Example 17
Source Project: DDMQ   Source File: MessageStoreWithFilterTest.java    License: Apache License 2.0 5 votes vote down vote up
protected DefaultMessageStore gen(ConsumerFilterManager filterManager) throws Exception {
    MessageStoreConfig messageStoreConfig = buildStoreConfig(
        commitLogFileSize, cqFileSize, true, cqExtFileSize
    );

    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setEnableCalcFilterBitMap(true);
    brokerConfig.setMaxErrorRateOfBloomFilter(20);
    brokerConfig.setExpectConsumerNumUseFilter(64);

    DefaultMessageStore master = new DefaultMessageStore(
        messageStoreConfig,
        new BrokerStatsManager(brokerConfig.getBrokerClusterName()),
        new MessageArrivingListener() {
            @Override
            public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
                                 long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
            }
        }
        , brokerConfig);

    master.getDispatcherList().addFirst(new CommitLogDispatcher() {
        @Override
        public void dispatch(DispatchRequest request) {
            try {
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    });
    master.getDispatcherList().addFirst(new CommitLogDispatcherCalcBitMap(brokerConfig, filterManager));

    assertThat(master.load()).isTrue();

    master.start();

    return master;
}
 
Example 18
Source Project: DDMQ   Source File: HAService.java    License: Apache License 2.0 5 votes vote down vote up
public HAService(final DefaultMessageStore defaultMessageStore) throws IOException {
    this.defaultMessageStore = defaultMessageStore;
    this.acceptSocketService =
        new AcceptSocketService(defaultMessageStore.getMessageStoreConfig().getHaListenPort());
    this.groupTransferService = new GroupTransferService();
    this.haClient = new HAClient();
}
 
Example 19
Source Project: DDMQ   Source File: IndexService.java    License: Apache License 2.0 5 votes vote down vote up
public IndexService(final DefaultMessageStore store) {
    this.defaultMessageStore = store;
    this.hashSlotNum = store.getMessageStoreConfig().getMaxHashSlotNum();
    this.indexNum = store.getMessageStoreConfig().getMaxIndexNum();
    this.storePath =
        StorePathConfigHelper.getStorePathIndex(store.getMessageStoreConfig().getStorePathRootDir());
}
 
Example 20
Source Project: rocketmq-4.3.0   Source File: AdminBrokerProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private RemotingCommand getAllDelayOffset(ChannelHandlerContext ctx, RemotingCommand request) {
        final RemotingCommand response = RemotingCommand.createResponseCommand(null);

//        消息编码=》
        String content = ((DefaultMessageStore) this.brokerController.getMessageStore()).getScheduleMessageService().encode();
        if (content != null && content.length() > 0) {
            try {
                response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
            } catch (UnsupportedEncodingException e) {
                log.error("get all delay offset from master error.", e);

                response.setCode(ResponseCode.SYSTEM_ERROR);
                response.setRemark("UnsupportedEncodingException " + e);
                return response;
            }
        } else {
            log.error("No delay offset in this broker, client: {} ", ctx.channel().remoteAddress());
            response.setCode(ResponseCode.SYSTEM_ERROR);
            response.setRemark("No delay offset in this broker");
            return response;
        }

        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);

        return response;
    }
 
Example 21
Source Project: rocketmq-4.3.0   Source File: MessageStoreWithFilterTest.java    License: Apache License 2.0 5 votes vote down vote up
protected DefaultMessageStore gen(ConsumerFilterManager filterManager) throws Exception {
    MessageStoreConfig messageStoreConfig = buildStoreConfig(
        commitLogFileSize, cqFileSize, true, cqExtFileSize
    );

    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setEnableCalcFilterBitMap(true);
    brokerConfig.setMaxErrorRateOfBloomFilter(20);
    brokerConfig.setExpectConsumerNumUseFilter(64);

    DefaultMessageStore master = new DefaultMessageStore(
        messageStoreConfig,
        new BrokerStatsManager(brokerConfig.getBrokerClusterName()),
        new MessageArrivingListener() {
            @Override
            public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
                                 long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
            }
        }
        , brokerConfig);

    master.getDispatcherList().addFirst(new CommitLogDispatcher() {
        @Override
        public void dispatch(DispatchRequest request) {
            try {
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    });
    master.getDispatcherList().addFirst(new CommitLogDispatcherCalcBitMap(brokerConfig, filterManager));

    assertThat(master.load()).isTrue();

    master.start();

    return master;
}
 
Example 22
Source Project: rocketmq-4.3.0   Source File: HAService.java    License: Apache License 2.0 5 votes vote down vote up
public HAService(final DefaultMessageStore defaultMessageStore) throws IOException {
    this.defaultMessageStore = defaultMessageStore;
    this.acceptSocketService =
        new AcceptSocketService(defaultMessageStore.getMessageStoreConfig().getHaListenPort());
    this.groupTransferService = new GroupTransferService();
    this.haClient = new HAClient();
}
 
Example 23
Source Project: rocketmq   Source File: DLedgerCommitlogTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCommittedPos() throws Exception {
    String peers = String.format("n0-localhost:%d;n1-localhost:%d", nextPort(), nextPort());
    String group = UUID.randomUUID().toString();
    DefaultMessageStore leaderStore = createDledgerMessageStore(createBaseDir(), group,"n0", peers, "n0", false, 0);

    String topic = UUID.randomUUID().toString();
    MessageExtBrokerInner msgInner =  buildMessage();
    msgInner.setTopic(topic);
    msgInner.setQueueId(0);
    PutMessageResult putMessageResult = leaderStore.putMessage(msgInner);
    Assert.assertEquals(PutMessageStatus.OS_PAGECACHE_BUSY, putMessageResult.getPutMessageStatus());

    Thread.sleep(1000);

    Assert.assertEquals(0, leaderStore.getCommitLog().getMaxOffset());
    Assert.assertEquals(0, leaderStore.getMaxOffsetInQueue(topic, 0));


    DefaultMessageStore followerStore = createDledgerMessageStore(createBaseDir(), group,"n1", peers, "n0", false, 0);
    Thread.sleep(2000);

    Assert.assertEquals(1, leaderStore.getMaxOffsetInQueue(topic, 0));
    Assert.assertEquals(1, followerStore.getMaxOffsetInQueue(topic, 0));
    Assert.assertTrue(leaderStore.getCommitLog().getMaxOffset() > 0);


    leaderStore.destroy();
    followerStore.destroy();

    leaderStore.shutdown();
    followerStore.shutdown();
}
 
Example 24
Source Project: rocketmq-4.3.0   Source File: IndexService.java    License: Apache License 2.0 5 votes vote down vote up
public IndexService(final DefaultMessageStore store) {
    this.defaultMessageStore = store;
    this.hashSlotNum = store.getMessageStoreConfig().getMaxHashSlotNum();
    this.indexNum = store.getMessageStoreConfig().getMaxIndexNum();
    this.storePath =
        StorePathConfigHelper.getStorePathIndex(store.getMessageStoreConfig().getStorePathRootDir());
}
 
Example 25
Source Project: rocketmq-read   Source File: AdminBrokerProcessor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取所有延迟队列的偏移量
 * @param ctx ;
 * @param request ;
 * @return ;
 */
private RemotingCommand getAllDelayOffset(ChannelHandlerContext ctx, RemotingCommand request) {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

    if (!(this.brokerController.getMessageStore() instanceof DefaultMessageStore)) {
        log.error("Delay offset not supported in this messagetore, client: {} ", ctx.channel().remoteAddress());
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark("Delay offset not supported in this messagetore");
        return response;
    }

    String content = ((DefaultMessageStore) this.brokerController.getMessageStore()).getScheduleMessageService().encode();
    if (content != null && content.length() > 0) {
        try {
            response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
        } catch (UnsupportedEncodingException e) {
            log.error("Get all delay offset from master error.", e);

            response.setCode(ResponseCode.SYSTEM_ERROR);
            response.setRemark("UnsupportedEncodingException " + e);
            return response;
        }
    } else {
        log.error("No delay offset in this broker, client: {} ", ctx.channel().remoteAddress());
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark("No delay offset in this broker");
        return response;
    }

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);

    return response;
}
 
Example 26
Source Project: rocketmq-read   Source File: MessageStoreWithFilterTest.java    License: Apache License 2.0 5 votes vote down vote up
protected DefaultMessageStore gen(ConsumerFilterManager filterManager) throws Exception {
    MessageStoreConfig messageStoreConfig = buildStoreConfig(
        commitLogFileSize, cqFileSize, true, cqExtFileSize
    );

    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setEnableCalcFilterBitMap(true);
    brokerConfig.setMaxErrorRateOfBloomFilter(20);
    brokerConfig.setExpectConsumerNumUseFilter(64);

    DefaultMessageStore master = new DefaultMessageStore(
        messageStoreConfig,
        new BrokerStatsManager(brokerConfig.getBrokerClusterName()),
        new MessageArrivingListener() {
            @Override
            public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
                                 long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
            }
        }
        , brokerConfig);

    master.getDispatcherList().addFirst(new CommitLogDispatcher() {
        @Override
        public void dispatch(DispatchRequest request) {
            try {
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    });
    master.getDispatcherList().addFirst(new CommitLogDispatcherCalcBitMap(brokerConfig, filterManager));

    assertThat(master.load()).isTrue();

    master.start();

    return master;
}
 
Example 27
Source Project: rocketmq-read   Source File: HAService.java    License: Apache License 2.0 5 votes vote down vote up
public HAService(final DefaultMessageStore defaultMessageStore) throws IOException {
    this.defaultMessageStore = defaultMessageStore;
    this.acceptSocketService =
        new AcceptSocketService(defaultMessageStore.getMessageStoreConfig().getHaListenPort());
    this.groupTransferService = new GroupTransferService();
    this.haClient = new HAClient();
}
 
Example 28
Source Project: rocketmq-read   Source File: IndexService.java    License: Apache License 2.0 5 votes vote down vote up
public IndexService(final DefaultMessageStore store) {
    this.defaultMessageStore = store;
    this.hashSlotNum = store.getMessageStoreConfig().getMaxHashSlotNum();
    this.indexNum = store.getMessageStoreConfig().getMaxIndexNum();
    this.storePath =
        StorePathConfigHelper.getStorePathIndex(store.getMessageStoreConfig().getStorePathRootDir());
}
 
Example 29
Source Project: rocketmq   Source File: HAService.java    License: Apache License 2.0 5 votes vote down vote up
public HAService(final DefaultMessageStore defaultMessageStore) throws IOException {
    this.defaultMessageStore = defaultMessageStore;
    this.acceptSocketService =
        new AcceptSocketService(defaultMessageStore.getMessageStoreConfig().getHaListenPort());
    this.groupTransferService = new GroupTransferService();
    this.haClient = new HAClient();
}
 
Example 30
Source Project: rocketmq   Source File: IndexService.java    License: Apache License 2.0 5 votes vote down vote up
public IndexService(final DefaultMessageStore store) {
    this.defaultMessageStore = store;
    this.hashSlotNum = store.getMessageStoreConfig().getMaxHashSlotNum();
    this.indexNum = store.getMessageStoreConfig().getMaxIndexNum();
    this.storePath =
        StorePathConfigHelper.getStorePathIndex(store.getMessageStoreConfig().getStorePathRootDir());
}