org.apache.rocketmq.common.UtilAll Java Examples

The following examples show how to use org.apache.rocketmq.common.UtilAll. 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: ConsumeQueueExtTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGet_invalidAddress() {
    ConsumeQueueExt consumeQueueExt = genExt();

    putSth(consumeQueueExt, false, true, unitCount);

    try {
        ConsumeQueueExt.CqExtUnit unit = consumeQueueExt.get(0);

        assertThat(unit).isNull();

        long addr = (cqExtFileSize / unitSizeWithBitMap) * unitSizeWithBitMap;
        addr += unitSizeWithBitMap;

        unit = consumeQueueExt.get(addr);
        assertThat(unit).isNull();
    } finally {
        consumeQueueExt.destroy();
        UtilAll.deleteFile(new File(storePath));
    }
}
 
Example #2
Source File: StoreCheckpoint.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public StoreCheckpoint(final String scpPath) throws IOException {
    File file = new File(scpPath);
    MappedFile.ensureDirOK(file.getParent());
    boolean fileExists = file.exists();

    this.randomAccessFile = new RandomAccessFile(file, "rw");
    this.fileChannel = this.randomAccessFile.getChannel();
    this.mappedByteBuffer = fileChannel.map(MapMode.READ_WRITE, 0, MappedFile.OS_PAGE_SIZE);

    if (fileExists) {
        log.info("store checkpoint file exists, " + scpPath);
        this.physicMsgTimestamp = this.mappedByteBuffer.getLong(0);
        this.logicsMsgTimestamp = this.mappedByteBuffer.getLong(8);
        this.indexMsgTimestamp = this.mappedByteBuffer.getLong(16);

        log.info("store checkpoint file physicMsgTimestamp " + this.physicMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.physicMsgTimestamp));
        log.info("store checkpoint file logicsMsgTimestamp " + this.logicsMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.logicsMsgTimestamp));
        log.info("store checkpoint file indexMsgTimestamp " + this.indexMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.indexMsgTimestamp));
    } else {
        log.info("store checkpoint file not exists, " + scpPath);
    }
}
 
Example #3
Source File: ConsumeQueueExtTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncateByMaxOffset() {
    ConsumeQueueExt consumeQueueExt = genExt();

    putSth(consumeQueueExt, false, true, unitCount * 2);

    try {
        // truncate, only first 3 files exist.
        long address = consumeQueueExt.decorate(cqExtFileSize * 2 + unitSizeWithBitMap);

        long expectMaxAddress = address + unitSizeWithBitMap;

        consumeQueueExt.truncateByMaxAddress(address);

        long maxAddress = consumeQueueExt.getMaxAddress();

        assertThat(expectMaxAddress).isEqualTo(maxAddress);
    } finally {
        consumeQueueExt.destroy();
        UtilAll.deleteFile(new File(storePath));
    }
}
 
Example #4
Source File: StoreCheckpoint.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public StoreCheckpoint(final String scpPath) throws IOException {
    File file = new File(scpPath);
    MappedFile.ensureDirOK(file.getParent());
    boolean fileExists = file.exists();

    this.randomAccessFile = new RandomAccessFile(file, "rw");
    this.fileChannel = this.randomAccessFile.getChannel();
    this.mappedByteBuffer = fileChannel.map(MapMode.READ_WRITE, 0, MappedFile.OS_PAGE_SIZE);

    if (fileExists) {
        log.info("store checkpoint file exists, " + scpPath);
        this.physicMsgTimestamp = this.mappedByteBuffer.getLong(0);
        this.logicsMsgTimestamp = this.mappedByteBuffer.getLong(8);
        this.indexMsgTimestamp = this.mappedByteBuffer.getLong(16);

        log.info("store checkpoint file physicMsgTimestamp " + this.physicMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.physicMsgTimestamp));
        log.info("store checkpoint file logicsMsgTimestamp " + this.logicsMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.logicsMsgTimestamp));
        log.info("store checkpoint file indexMsgTimestamp " + this.indexMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.indexMsgTimestamp));
    } else {
        log.info("store checkpoint file not exists, " + scpPath);
    }
}
 
Example #5
Source File: ClientConfig.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public String buildMQClientId() {
    if (clientId != null) {
        return clientId;
    }

    StringBuilder sb = new StringBuilder();
    sb.append(this.getClientIP());

    sb.append("@");
    sb.append(this.getInstanceName());
    if (!UtilAll.isBlank(this.unitName)) {
        sb.append("@");
        sb.append(this.unitName);
    }

    return sb.toString();
}
 
Example #6
Source File: ConsumeQueueExtTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncateByMaxOffset() {
    ConsumeQueueExt consumeQueueExt = genExt();

    putSth(consumeQueueExt, false, true, unitCount * 2);

    try {
        // truncate, only first 3 files exist.
        long address = consumeQueueExt.decorate(cqExtFileSize * 2 + unitSizeWithBitMap);

        long expectMaxAddress = address + unitSizeWithBitMap;

        consumeQueueExt.truncateByMaxAddress(address);

        long maxAddress = consumeQueueExt.getMaxAddress();

        assertThat(expectMaxAddress).isEqualTo(maxAddress);
    } finally {
        consumeQueueExt.destroy();
        UtilAll.deleteFile(new File(storePath));
    }
}
 
Example #7
Source File: ClientRemotingProcessor.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final GetConsumerRunningInfoRequestHeader requestHeader =
        (GetConsumerRunningInfoRequestHeader) request.decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class);

    ConsumerRunningInfo consumerRunningInfo = this.mqClientFactory.consumerRunningInfo(requestHeader.getConsumerGroup());
    if (null != consumerRunningInfo) {
        if (requestHeader.isJstackEnable()) {
            Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces();
            String jstack = UtilAll.jstack(map);
            consumerRunningInfo.setJstack(jstack);
        }

        response.setCode(ResponseCode.SUCCESS);
        response.setBody(consumerRunningInfo.encode());
    } else {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(String.format("The Consumer Group <%s> not exist in this consumer", requestHeader.getConsumerGroup()));
    }

    return response;
}
 
Example #8
Source File: MessageClientIDSetter.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static Date getNearlyTimeFromID(String msgID) {
    ByteBuffer buf = ByteBuffer.allocate(8);
    byte[] bytes = UtilAll.string2bytes(msgID);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put(bytes, 10, 4);
    buf.position(0);
    long spanMS = buf.getLong();
    Calendar cal = Calendar.getInstance();
    long now = cal.getTimeInMillis();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    long monStartTime = cal.getTimeInMillis();
    if (monStartTime + spanMS >= now) {
        cal.add(Calendar.MONTH, -1);
        monStartTime = cal.getTimeInMillis();
    }
    cal.setTimeInMillis(monStartTime + spanMS);
    return cal.getTime();
}
 
Example #9
Source File: Validators.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
/**
 * Validate topic
 *
 * @param topic
 * @throws MQClientException
 */
public static void checkTopic(String topic) throws MQClientException {
    if (UtilAll.isBlank(topic)) {
        throw new MQClientException("The specified topic is blank", null);
    }

    if (!regularExpressionMatcher(topic, PATTERN)) {
        throw new MQClientException(String.format(
            "The specified topic[%s] contains illegal characters, allowing only %s", topic,
            VALID_PATTERN_STR), null);
    }

    if (topic.length() > CHARACTER_MAX_LENGTH) {
        throw new MQClientException("The specified topic is longer than topic max length 255.", null);
    }

    //whether the same with system reserved keyword
    if (topic.equals(MixAll.DEFAULT_TOPIC)) {
        throw new MQClientException(
            String.format("The topic[%s] is conflict with default topic.", topic), null);
    }
}
 
Example #10
Source File: MappedFile.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public boolean destroy(final long intervalForcibly) {
    this.shutdown(intervalForcibly);

    if (this.isCleanupOver()) {
        try {
            this.fileChannel.close();
            log.info("close file channel " + this.fileName + " OK");

            long beginTime = System.currentTimeMillis();
            boolean result = this.file.delete();
            log.info("delete file[REF:" + this.getRefCount() + "] " + this.fileName
                + (result ? " OK, " : " Failed, ") + "W:" + this.getWrotePosition() + " M:"
                + this.getFlushedPosition() + ", "
                + UtilAll.computeEclipseTimeMilliseconds(beginTime));
        } catch (Exception e) {
            log.warn("close file channel " + this.fileName + " Failed. ", e);
        }

        return true;
    } else {
        log.warn("destroy mapped file[REF:" + this.getRefCount() + "] " + this.fileName
            + " Failed. cleanupOver: " + this.cleanupOver);
    }

    return false;
}
 
Example #11
Source File: Validators.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
/**
 * Validate topic
 */
public static void checkTopic(String topic) throws MQClientException {
    if (UtilAll.isBlank(topic)) {
        throw new MQClientException("The specified topic is blank", null);
    }

    if (!regularExpressionMatcher(topic, PATTERN)) {
        throw new MQClientException(String.format(
            "The specified topic[%s] contains illegal characters, allowing only %s", topic,
            VALID_PATTERN_STR), null);
    }

    if (topic.length() > CHARACTER_MAX_LENGTH) {
        throw new MQClientException("The specified topic is longer than topic max length 255.", null);
    }

    //whether the same with system reserved keyword
    if (topic.equals(MixAll.DEFAULT_TOPIC)) {
        throw new MQClientException(
            String.format("The topic[%s] is conflict with default topic.", topic), null);
    }
}
 
Example #12
Source File: StoreCheckpoint.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public StoreCheckpoint(final String scpPath) throws IOException {
    File file = new File(scpPath);
    MappedFile.ensureDirOK(file.getParent());
    boolean fileExists = file.exists();

    this.randomAccessFile = new RandomAccessFile(file, "rw");
    this.fileChannel = this.randomAccessFile.getChannel();
    this.mappedByteBuffer = fileChannel.map(MapMode.READ_WRITE, 0, MappedFile.OS_PAGE_SIZE);

    if (fileExists) {
        log.info("store checkpoint file exists, " + scpPath);
        this.physicMsgTimestamp = this.mappedByteBuffer.getLong(0);
        this.logicsMsgTimestamp = this.mappedByteBuffer.getLong(8);
        this.indexMsgTimestamp = this.mappedByteBuffer.getLong(16);

        log.info("store checkpoint file physicMsgTimestamp " + this.physicMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.physicMsgTimestamp));
        log.info("store checkpoint file logicsMsgTimestamp " + this.logicsMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.logicsMsgTimestamp));
        log.info("store checkpoint file indexMsgTimestamp " + this.indexMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.indexMsgTimestamp));
    } else {
        log.info("store checkpoint file not exists, " + scpPath);
    }
}
 
Example #13
Source File: ConsumeQueueExtTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncateByMaxOffset() {
    ConsumeQueueExt consumeQueueExt = genExt();

    putSth(consumeQueueExt, false, true, unitCount * 2);

    try {
        // truncate, only first 3 files exist.
        long address = consumeQueueExt.decorate(cqExtFileSize * 2 + unitSizeWithBitMap);

        long expectMaxAddress = address + unitSizeWithBitMap;

        consumeQueueExt.truncateByMaxAddress(address);

        long maxAddress = consumeQueueExt.getMaxAddress();

        assertThat(expectMaxAddress).isEqualTo(maxAddress);
    } finally {
        consumeQueueExt.destroy();
        UtilAll.deleteFile(new File(storePath));
    }
}
 
Example #14
Source File: StoreCheckpoint.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public StoreCheckpoint(final String scpPath) throws IOException {
    File file = new File(scpPath);
    MappedFile.ensureDirOK(file.getParent());
    boolean fileExists = file.exists();

    this.randomAccessFile = new RandomAccessFile(file, "rw");
    this.fileChannel = this.randomAccessFile.getChannel();
    this.mappedByteBuffer = fileChannel.map(MapMode.READ_WRITE, 0, MappedFile.OS_PAGE_SIZE);

    if (fileExists) {
        log.info("store checkpoint file exists, " + scpPath);
        this.physicMsgTimestamp = this.mappedByteBuffer.getLong(0);
        this.logicsMsgTimestamp = this.mappedByteBuffer.getLong(8);
        this.indexMsgTimestamp = this.mappedByteBuffer.getLong(16);

        log.info("store checkpoint file physicMsgTimestamp " + this.physicMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.physicMsgTimestamp));
        log.info("store checkpoint file logicsMsgTimestamp " + this.logicsMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.logicsMsgTimestamp));
        log.info("store checkpoint file indexMsgTimestamp " + this.indexMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.indexMsgTimestamp));
    } else {
        log.info("store checkpoint file not exists, " + scpPath);
    }
}
 
Example #15
Source File: ConsumeQueueExtTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncateByMaxOffset() {
    ConsumeQueueExt consumeQueueExt = genExt();

    putSth(consumeQueueExt, false, true, unitCount * 2);

    try {
        // truncate, only first 3 files exist.
        long address = consumeQueueExt.decorate(cqExtFileSize * 2 + unitSizeWithBitMap);

        long expectMaxAddress = address + unitSizeWithBitMap;

        consumeQueueExt.truncateByMaxAddress(address);

        long maxAddress = consumeQueueExt.getMaxAddress();

        assertThat(expectMaxAddress).isEqualTo(maxAddress);
    } finally {
        consumeQueueExt.destroy();
        UtilAll.deleteFile(new File(storePath));
    }
}
 
Example #16
Source File: MessageClientIDSetter.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public static Date getNearlyTimeFromID(String msgID) {
    ByteBuffer buf = ByteBuffer.allocate(8);
    byte[] bytes = UtilAll.string2bytes(msgID);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put(bytes, 10, 4);
    buf.position(0);
    long spanMS = buf.getLong();
    Calendar cal = Calendar.getInstance();
    long now = cal.getTimeInMillis();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    long monStartTime = cal.getTimeInMillis();
    if (monStartTime + spanMS >= now) {
        cal.add(Calendar.MONTH, -1);
        monStartTime = cal.getTimeInMillis();
    }
    cal.setTimeInMillis(monStartTime + spanMS);
    return cal.getTime();
}
 
Example #17
Source File: MessageClientIDSetter.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static Date getNearlyTimeFromID(String msgID) {
    ByteBuffer buf = ByteBuffer.allocate(8);
    byte[] bytes = UtilAll.string2bytes(msgID);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put(bytes, 10, 4);
    buf.position(0);
    long spanMS = buf.getLong();
    Calendar cal = Calendar.getInstance();
    long now = cal.getTimeInMillis();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    long monStartTime = cal.getTimeInMillis();
    if (monStartTime + spanMS >= now) {
        cal.add(Calendar.MONTH, -1);
        monStartTime = cal.getTimeInMillis();
    }
    cal.setTimeInMillis(monStartTime + spanMS);
    return cal.getTime();
}
 
Example #18
Source File: DefaultMessageStoreTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@After
public void destory() {
    messageStore.shutdown();
    messageStore.destroy();

    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
    File file = new File(messageStoreConfig.getStorePathRootDir());
    UtilAll.deleteFile(file);
}
 
Example #19
Source File: MQClientInstance.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private void uploadFilterClassToAllFilterServer(final String consumerGroup, final String fullClassName,
    final String topic,
    final String filterClassSource) throws UnsupportedEncodingException {
    byte[] classBody = null;
    int classCRC = 0;
    try {
        classBody = filterClassSource.getBytes(MixAll.DEFAULT_CHARSET);
        classCRC = UtilAll.crc32(classBody);
    } catch (Exception e1) {
        log.warn("uploadFilterClassToAllFilterServer Exception, ClassName: {} {}",
            fullClassName,
            RemotingHelper.exceptionSimpleDesc(e1));
    }

    TopicRouteData topicRouteData = this.topicRouteTable.get(topic);
    if (topicRouteData != null
        && topicRouteData.getFilterServerTable() != null && !topicRouteData.getFilterServerTable().isEmpty()) {
        Iterator<Entry<String, List<String>>> it = topicRouteData.getFilterServerTable().entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, List<String>> next = it.next();
            List<String> value = next.getValue();
            for (final String fsAddr : value) {
                try {
                    this.mQClientAPIImpl.registerMessageFilterClass(fsAddr, consumerGroup, topic, fullClassName, classCRC, classBody,
                        5000);

                    log.info("register message class filter to {} OK, ConsumerGroup: {} Topic: {} ClassName: {}", fsAddr, consumerGroup,
                        topic, fullClassName);

                } catch (Exception e) {
                    log.error("uploadFilterClassToAllFilterServer Exception", e);
                }
            }
        }
    } else {
        log.warn("register message class filter failed, because no filter server, ConsumerGroup: {} Topic: {} ClassName: {}",
            consumerGroup, topic, fullClassName);
    }
}
 
Example #20
Source File: Validators.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 检查组名
 * Validate group
 */
public static void checkGroup(String group) throws MQClientException {
    if (UtilAll.isBlank(group)) {
        throw new MQClientException("the specified group is blank", null);
    }
    if (!regularExpressionMatcher(group, PATTERN)) {
        throw new MQClientException(String.format(
            "the specified group[%s] contains illegal characters, allowing only %s", group,
            VALID_PATTERN_STR), null);
    }
    if (group.length() > CHARACTER_MAX_LENGTH) {
        throw new MQClientException("the specified group is longer than group max length 255.", null);
    }
}
 
Example #21
Source File: ResetOffsetByTimeOldCommand.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static void resetOffset(DefaultMQAdminExt defaultMQAdminExt, String consumerGroup, String topic,
    long timestamp, boolean force,
    String timeStampStr) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    List<RollbackStats> rollbackStatsList = defaultMQAdminExt.resetOffsetByTimestampOld(consumerGroup, topic, timestamp, force);
    System.out.printf(
        "rollback consumer offset by specified consumerGroup[%s], topic[%s], force[%s], timestamp(string)[%s], timestamp(long)[%s]%n",
        consumerGroup, topic, force, timeStampStr, timestamp);

    System.out.printf("%-20s  %-20s  %-20s  %-20s  %-20s  %-20s%n",
        "#brokerName",
        "#queueId",
        "#brokerOffset",
        "#consumerOffset",
        "#timestampOffset",
        "#rollbackOffset"
    );

    for (RollbackStats rollbackStats : rollbackStatsList) {
        System.out.printf("%-20s  %-20d  %-20d  %-20d  %-20d  %-20d%n",
            UtilAll.frontStringAtLeast(rollbackStats.getBrokerName(), 32),
            rollbackStats.getQueueId(),
            rollbackStats.getBrokerOffset(),
            rollbackStats.getConsumerOffset(),
            rollbackStats.getTimestampOffset(),
            rollbackStats.getRollbackOffset()
        );
    }
}
 
Example #22
Source File: ConsumeQueueExtTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testPut() {
    ConsumeQueueExt consumeQueueExt = genExt();

    try {
        putSth(consumeQueueExt, true, false, unitCount);
    } finally {
        consumeQueueExt.destroy();
        UtilAll.deleteFile(new File(storePath));
    }
}
 
Example #23
Source File: AdminBrokerProcessor.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private synchronized RemotingCommand updateGlobalWhiteAddrsConfig(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {

    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

    final UpdateGlobalWhiteAddrsConfigRequestHeader requestHeader =
        (UpdateGlobalWhiteAddrsConfigRequestHeader) request.decodeCommandCustomHeader(UpdateGlobalWhiteAddrsConfigRequestHeader.class);

    try {
        AccessValidator accessValidator = this.brokerController.getAccessValidatorMap().get(PlainAccessValidator.class);
        if (accessValidator.updateGlobalWhiteAddrsConfig(UtilAll.string2List(requestHeader.getGlobalWhiteAddrs(), ","))) {
            response.setCode(ResponseCode.SUCCESS);
            response.setOpaque(request.getOpaque());
            response.markResponseType();
            response.setRemark(null);
            ctx.writeAndFlush(response);
        } else {
            String errorMsg = "The globalWhiteAddresses[" + requestHeader.getGlobalWhiteAddrs() + "] has been updated failed.";
            log.warn(errorMsg);
            response.setCode(ResponseCode.UPDATE_GLOBAL_WHITE_ADDRS_CONFIG_FAILED);
            response.setRemark(errorMsg);
            return response;
        }
    } catch (Exception e) {
        log.error("Failed to generate a proper update globalWhiteAddresses response", e);
        response.setCode(ResponseCode.UPDATE_GLOBAL_WHITE_ADDRS_CONFIG_FAILED);
        response.setRemark(e.getMessage());
        return response;
    }

    return null;
}
 
Example #24
Source File: DeFiReplyMessageProcessor.java    From DeFiBus with Apache License 2.0 5 votes vote down vote up
private String diskUtil() {
    String storePathPhysic = this.deFiBrokerController.getMessageStoreConfig().getStorePathCommitLog();
    double physicRatio = UtilAll.getDiskPartitionSpaceUsedPercent(storePathPhysic);

    String storePathLogis =
        StorePathConfigHelper.getStorePathConsumeQueue(this.deFiBrokerController.getMessageStoreConfig().getStorePathRootDir());
    double logisRatio = UtilAll.getDiskPartitionSpaceUsedPercent(storePathLogis);

    String storePathIndex =
        StorePathConfigHelper.getStorePathIndex(this.deFiBrokerController.getMessageStoreConfig().getStorePathRootDir());
    double indexRatio = UtilAll.getDiskPartitionSpaceUsedPercent(storePathIndex);

    return String.format("CL: %5.2f CQ: %5.2f INDEX: %5.2f", physicRatio, logisRatio, indexRatio);
}
 
Example #25
Source File: ConsumeQueueExtTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testRecovery() {
    ConsumeQueueExt putCqExt = genExt();

    putSth(putCqExt, false, true, unitCount);

    ConsumeQueueExt loadCqExt = genExt();

    loadCqExt.load();

    loadCqExt.recover();

    try {
        assertThat(loadCqExt.getMinAddress()).isEqualTo(Long.MIN_VALUE);

        // same unit size.
        int countPerFile = (cqExtFileSize - ConsumeQueueExt.END_BLANK_DATA_LENGTH) / unitSizeWithBitMap;

        int lastFileUnitCount = unitCount % countPerFile;

        int fileCount = unitCount / countPerFile + 1;
        if (lastFileUnitCount == 0) {
            fileCount -= 1;
        }

        if (lastFileUnitCount == 0) {
            assertThat(loadCqExt.unDecorate(loadCqExt.getMaxAddress()) % cqExtFileSize).isEqualTo(0);
        } else {
            assertThat(loadCqExt.unDecorate(loadCqExt.getMaxAddress()))
                .isEqualTo(lastFileUnitCount * unitSizeWithBitMap + (fileCount - 1) * cqExtFileSize);
        }
    } finally {
        putCqExt.destroy();
        loadCqExt.destroy();
        UtilAll.deleteFile(new File(storePath));
    }
}
 
Example #26
Source File: MomentStatsItem.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void init() {
    this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            try {
                printAtMinutes();

                MomentStatsItem.this.value.set(0);
            } catch (Throwable e) {
            }
        }
    }, Math.abs(UtilAll.computNextMinutesTimeMillis() - System.currentTimeMillis()), logIntervalMinutes, TimeUnit.MINUTES);
}
 
Example #27
Source File: MessageDecoder.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static String createMessageId(SocketAddress socketAddress, long transactionIdhashCode) {
    ByteBuffer byteBuffer = ByteBuffer.allocate(MessageDecoder.MSG_ID_LENGTH);
    InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
    byteBuffer.put(inetSocketAddress.getAddress().getAddress());
    byteBuffer.putInt(inetSocketAddress.getPort());
    byteBuffer.putLong(transactionIdhashCode);
    byteBuffer.flip();
    return UtilAll.bytes2string(byteBuffer.array());
}
 
Example #28
Source File: ProcessQueueInfo.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    return "ProcessQueueInfo [commitOffset=" + commitOffset + ", cachedMsgMinOffset="
        + cachedMsgMinOffset + ", cachedMsgMaxOffset=" + cachedMsgMaxOffset
        + ", cachedMsgCount=" + cachedMsgCount + ", cachedMsgSizeInMiB=" + cachedMsgSizeInMiB
        + ", transactionMsgMinOffset=" + transactionMsgMinOffset
        + ", transactionMsgMaxOffset=" + transactionMsgMaxOffset + ", transactionMsgCount="
        + transactionMsgCount + ", locked=" + locked + ", tryUnlockTimes=" + tryUnlockTimes
        + ", lastLockTimestamp=" + UtilAll.timeMillisToHumanString(lastLockTimestamp) + ", droped="
        + droped + ", lastPullTimestamp=" + UtilAll.timeMillisToHumanString(lastPullTimestamp)
        + ", lastConsumeTimestamp=" + UtilAll.timeMillisToHumanString(lastConsumeTimestamp) + "]";
}
 
Example #29
Source File: TopAddressing.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public final String fetchNSAddr(boolean verbose, long timeoutMills) {
    String url = this.wsAddr;
    try {
        if (!UtilAll.isBlank(this.unitName)) {
            url = url + "-" + this.unitName + "?nofix=1";
        }
        HttpTinyClient.HttpResult result = HttpTinyClient.httpGet(url, null, null, "UTF-8", timeoutMills);
        if (200 == result.code) {
            String responseStr = result.content;
            if (responseStr != null) {
                return clearNewLine(responseStr);
            } else {
                log.error("fetch nameserver address is null");
            }
        } else {
            log.error("fetch nameserver address failed. statusCode=" + result.code);
        }
    } catch (IOException e) {
        if (verbose) {
            log.error("fetch name server address exception", e);
        }
    }

    if (verbose) {
        String errorMsg =
            "connect to " + url + " failed, maybe the domain name " + MixAll.getWSAddr() + " not bind in /etc/hosts";
        errorMsg += FAQUrl.suggestTodo(FAQUrl.NAME_SERVER_ADDR_NOT_EXIST_URL);

        log.warn(errorMsg);
    }
    return null;
}
 
Example #30
Source File: PrintMessageByQueueCommand.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static long timestampFormat(final String value) {
    long timestamp = 0;
    try {
        timestamp = Long.parseLong(value);
    } catch (NumberFormatException e) {

        timestamp = UtilAll.parseDate(value, UtilAll.YYYY_MM_DD_HH_MM_SS_SSS).getTime();
    }

    return timestamp;
}