Java Code Examples for org.apache.rocketmq.common.MixAll#string2File()

The following examples show how to use org.apache.rocketmq.common.MixAll#string2File() . 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: LocalFileOffsetStore.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public void persistAll(Set<MessageQueue> mqs) {
    if (null == mqs || mqs.isEmpty())
        return;

    OffsetSerializeWrapper offsetSerializeWrapper = new OffsetSerializeWrapper();
    for (Map.Entry<MessageQueue, AtomicLong> entry : this.offsetTable.entrySet()) {
        if (mqs.contains(entry.getKey())) {
            AtomicLong offset = entry.getValue();
            offsetSerializeWrapper.getOffsetTable().put(entry.getKey(), offset);
        }
    }

    String jsonString = offsetSerializeWrapper.toJson(true);
    if (jsonString != null) {
        try {
            MixAll.string2File(jsonString, this.storePath);
        } catch (IOException e) {
            log.error("persistAll consumer offset Exception, " + this.storePath, e);
        }
    }
}
 
Example 2
Source File: HAService.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void saveInSyncOffset() {
    if (this.defaultMessageStore.getMessageStoreConfig().getBrokerRole() == BrokerRole.SLAVE) {
        return;
    }

    long minInSyncOffset = getMinOffsetInSync();
    if (minInSyncOffset == -1) {
        return;
    }

    String fileName = StorePathConfigHelper.getOffsetInSyncStorePath(this.defaultMessageStore.getMessageStoreConfig().getStorePathRootDir());
    try {
        MixAll.string2File(String.valueOf(minInSyncOffset), fileName);
    } catch (IOException e) {
        log.error("save phy offset slave reported [{}] exception", fileName, e);
    }

    log.info("save slave min offset in sync:{}", minInSyncOffset);
}
 
Example 3
Source File: HAService.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void initInSyncOffset(long offset) {
    if (this.defaultMessageStore.getMessageStoreConfig().getBrokerRole() == BrokerRole.SLAVE) {
        return;
    }
    String fileName = StorePathConfigHelper.getOffsetInSyncStorePath(this.defaultMessageStore.getMessageStoreConfig().getStorePathRootDir());
    File file = new File(fileName);
    if (file.exists()) {
        log.info("as master before, no need to sync offset");
        return;
    }

    try {
        MixAll.string2File(String.valueOf(offset), fileName);
    } catch (IOException e) {
        log.error("save phy offset slave reported [{}] exception", fileName, e);
    }

}
 
Example 4
Source File: DefaultMessageStoreTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncate() throws Exception {
    String topic = "truncateTopic";

    for (int i = 0; i < 1000; i++) {
        MessageExtBrokerInner messageExtBrokerInner = buildMessage();
        messageExtBrokerInner.setTopic(topic);
        messageExtBrokerInner.setQueueId(0);
        messageStore.putMessage(messageExtBrokerInner);
    }
    if (messageStore instanceof DefaultMessageStore) {
        DefaultMessageStore defaultMessageStore = (DefaultMessageStore) messageStore;
        long maxPhyOffset = defaultMessageStore.getMaxPhyOffset();
        String fileName = StorePathConfigHelper.getOffsetInSyncStorePath(defaultMessageStore.getMessageStoreConfig().getStorePathRootDir());
        MixAll.string2File(String.valueOf(defaultMessageStore.getMaxPhyOffset() - 100), fileName);

        defaultMessageStore.getMessageStoreConfig().setBrokerRole(BrokerRole.SLAVE);
        defaultMessageStore.truncateNotSync();

        assertThat(defaultMessageStore.getMaxPhyOffset()).isEqualTo(maxPhyOffset - 100);
    }
}
 
Example 5
Source File: LocalFileOffsetStore.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Override
    public void persistAll(Set<MessageQueue> mqs) {
        if (null == mqs || mqs.isEmpty())
            return;

//        包装offset信息
        OffsetSerializeWrapper offsetSerializeWrapper = new OffsetSerializeWrapper();
        for (Map.Entry<MessageQueue, AtomicLong> entry : this.offsetTable.entrySet()) {
            if (mqs.contains(entry.getKey())) {
                AtomicLong offset = entry.getValue();
                offsetSerializeWrapper.getOffsetTable().put(entry.getKey(), offset);
            }
        }

//        json序列化
        String jsonString = offsetSerializeWrapper.toJson(true);
        if (jsonString != null) {
            try {
//                文件存储=》
                MixAll.string2File(jsonString, this.storePath);
            } catch (IOException e) {
                log.error("persistAll consumer offset Exception, " + this.storePath, e);
            }
        }
    }
 
Example 6
Source File: LocalFileOffsetStore.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Override
public void persistAll(Set<MessageQueue> mqs) {
    if (null == mqs || mqs.isEmpty()) {
        return;
    }

    OffsetSerializeWrapper offsetSerializeWrapper = new OffsetSerializeWrapper();
    for (Map.Entry<MessageQueue, AtomicLong> entry : this.offsetTable.entrySet()) {
        if (mqs.contains(entry.getKey())) {
            AtomicLong offset = entry.getValue();
            offsetSerializeWrapper.getOffsetTable().put(entry.getKey(), offset);
        }
    }

    String jsonString = offsetSerializeWrapper.toJson(true);
    if (jsonString != null) {
        try {
            MixAll.string2File(jsonString, this.storePath);
        } catch (IOException e) {
            log.error("persistAll consumer offset Exception, " + this.storePath, e);
        }
    }
}
 
Example 7
Source File: LocalFileOffsetStore.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Override
public void persistAll(Set<MessageQueue> mqs) {
    if (null == mqs || mqs.isEmpty())
        return;

    OffsetSerializeWrapper offsetSerializeWrapper = new OffsetSerializeWrapper();
    for (Map.Entry<MessageQueue, AtomicLong> entry : this.offsetTable.entrySet()) {
        if (mqs.contains(entry.getKey())) {
            AtomicLong offset = entry.getValue();
            offsetSerializeWrapper.getOffsetTable().put(entry.getKey(), offset);
        }
    }

    String jsonString = offsetSerializeWrapper.toJson(true);
    if (jsonString != null) {
        try {
            MixAll.string2File(jsonString, this.storePath);
        } catch (IOException e) {
            log.error("persistAll consumer offset Exception, " + this.storePath, e);
        }
    }
}
 
Example 8
Source File: LocalFileOffsetStore.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public void persistAll(Set<MessageQueue> mqs) {
    if (null == mqs || mqs.isEmpty())
        return;

    OffsetSerializeWrapper offsetSerializeWrapper = new OffsetSerializeWrapper();
    for (Map.Entry<MessageQueue, AtomicLong> entry : this.offsetTable.entrySet()) {
        if (mqs.contains(entry.getKey())) {
            AtomicLong offset = entry.getValue();
            offsetSerializeWrapper.getOffsetTable().put(entry.getKey(), offset);
        }
    }

    String jsonString = offsetSerializeWrapper.toJson(true);
    if (jsonString != null) {
        try {
            MixAll.string2File(jsonString, this.storePath);
        } catch (IOException e) {
            log.error("persistAll consumer offset Exception, " + this.storePath, e);
        }
    }
}
 
Example 9
Source File: HAService.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void saveInSyncOffset() {
    if (this.defaultMessageStore.getMessageStoreConfig().getBrokerRole() == BrokerRole.SLAVE) {
        return;
    }

    long minInSyncOffset = getMinOffsetInSync();
    if (minInSyncOffset == -1) {
        return;
    }

    String fileName = StorePathConfigHelper.getOffsetInSyncStorePath(this.defaultMessageStore.getMessageStoreConfig().getStorePathRootDir());
    try {
        MixAll.string2File(String.valueOf(minInSyncOffset), fileName);
    } catch (IOException e) {
        log.error("save phy offset slave reported [{}] exception", fileName, e);
    }

    log.info("save slave min offset in sync:{}", minInSyncOffset);
}
 
Example 10
Source File: HAService.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void initInSyncOffset(long offset) {
    if (this.defaultMessageStore.getMessageStoreConfig().getBrokerRole() == BrokerRole.SLAVE) {
        return;
    }
    String fileName = StorePathConfigHelper.getOffsetInSyncStorePath(this.defaultMessageStore.getMessageStoreConfig().getStorePathRootDir());
    File file = new File(fileName);
    if (file.exists()) {
        log.info("as master before, no need to sync offset");
        return;
    }

    try {
        MixAll.string2File(String.valueOf(offset), fileName);
    } catch (IOException e) {
        log.error("save phy offset slave reported [{}] exception", fileName, e);
    }

}
 
Example 11
Source File: DefaultMessageStoreTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncate() throws Exception {
    String topic = "truncateTopic";

    for (int i = 0; i < 1000; i++) {
        MessageExtBrokerInner messageExtBrokerInner = buildMessage();
        messageExtBrokerInner.setTopic(topic);
        messageExtBrokerInner.setQueueId(0);
        messageStore.putMessage(messageExtBrokerInner);
    }
    if (messageStore instanceof DefaultMessageStore) {
        DefaultMessageStore defaultMessageStore = (DefaultMessageStore) messageStore;
        long maxPhyOffset = defaultMessageStore.getMaxPhyOffset();
        String fileName = StorePathConfigHelper.getOffsetInSyncStorePath(defaultMessageStore.getMessageStoreConfig().getStorePathRootDir());
        MixAll.string2File(String.valueOf(defaultMessageStore.getMaxPhyOffset() - 100), fileName);

        defaultMessageStore.getMessageStoreConfig().setBrokerRole(BrokerRole.SLAVE);
        defaultMessageStore.truncateNotSync();

        assertThat(defaultMessageStore.getMaxPhyOffset()).isEqualTo(maxPhyOffset - 100);
    }
}
 
Example 12
Source File: LocalFileOffsetStore.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Override
public void persistAll(Set<MessageQueue> mqs) {
    if (null == mqs || mqs.isEmpty())
        return;

    OffsetSerializeWrapper offsetSerializeWrapper = new OffsetSerializeWrapper();
    for (Map.Entry<MessageQueue, AtomicLong> entry : this.offsetTable.entrySet()) {
        if (mqs.contains(entry.getKey())) {
            AtomicLong offset = entry.getValue();
            offsetSerializeWrapper.getOffsetTable().put(entry.getKey(), offset);
        }
    }

    String jsonString = offsetSerializeWrapper.toJson(true);
    if (jsonString != null) {
        try {
            MixAll.string2File(jsonString, this.storePath);
        } catch (IOException e) {
            log.error("persistAll consumer offset Exception, " + this.storePath, e);
        }
    }
}
 
Example 13
Source File: LocalFileOffsetStore.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Override
public void persistAll(Set<MessageQueue> mqs) {
    if (null == mqs || mqs.isEmpty())
        return;

    OffsetSerializeWrapper offsetSerializeWrapper = new OffsetSerializeWrapper();
    for (Map.Entry<MessageQueue, AtomicLong> entry : this.offsetTable.entrySet()) {
        if (mqs.contains(entry.getKey())) {
            AtomicLong offset = entry.getValue();
            offsetSerializeWrapper.getOffsetTable().put(entry.getKey(), offset);
        }
    }

    String jsonString = offsetSerializeWrapper.toJson(true);
    if (jsonString != null) {
        try {
            MixAll.string2File(jsonString, this.storePath);
        } catch (IOException e) {
            log.error("persistAll consumer offset Exception, " + this.storePath, e);
        }
    }
}
 
Example 14
Source File: LocalFileOffsetStore.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Override
public void persistAll(Set<MessageQueue> mqs) {
    if (null == mqs || mqs.isEmpty())
        return;

    OffsetSerializeWrapper offsetSerializeWrapper = new OffsetSerializeWrapper();
    for (Map.Entry<MessageQueue, AtomicLong> entry : this.offsetTable.entrySet()) {
        if (mqs.contains(entry.getKey())) {
            AtomicLong offset = entry.getValue();
            offsetSerializeWrapper.getOffsetTable().put(entry.getKey(), offset);
        }
    }

    String jsonString = offsetSerializeWrapper.toJson(true);
    if (jsonString != null) {
        try {
            MixAll.string2File(jsonString, this.storePath);
        } catch (IOException e) {
            log.error("persistAll consumer offset Exception, " + this.storePath, e);
        }
    }
}