Search in sources :

Example 1 with DispatchRequest

use of org.apache.rocketmq.store.DispatchRequest in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class CommitLogDispatcherCalcBitMapTest method testDispatch_blankFilterData.

@Test
public void testDispatch_blankFilterData() {
    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setEnableCalcFilterBitMap(true);
    ConsumerFilterManager filterManager = new ConsumerFilterManager();
    CommitLogDispatcherCalcBitMap calcBitMap = new CommitLogDispatcherCalcBitMap(brokerConfig, filterManager);
    for (int i = 0; i < 10; i++) {
        Map<String, String> properties = new HashMap<String, String>(4);
        properties.put("a", String.valueOf(i * 10 + 5));
        String topic = "topic" + i;
        DispatchRequest dispatchRequest = new DispatchRequest(topic, 0, i * 100 + 123, 100, (long) ("tags" + i).hashCode(), System.currentTimeMillis(), i, null, UUID.randomUUID().toString(), 0, 0, properties);
        calcBitMap.dispatch(dispatchRequest);
        assertThat(dispatchRequest.getBitMap()).isNull();
    }
}
Also used : BrokerConfig(org.apache.rocketmq.common.BrokerConfig) HashMap(java.util.HashMap) DispatchRequest(org.apache.rocketmq.store.DispatchRequest) Test(org.junit.Test)

Example 2 with DispatchRequest

use of org.apache.rocketmq.store.DispatchRequest in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class CommitLogDispatcherCalcBitMapTest method testDispatch_filterDataIllegal.

@Test
public void testDispatch_filterDataIllegal() {
    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setEnableCalcFilterBitMap(true);
    ConsumerFilterManager filterManager = new ConsumerFilterManager();
    filterManager.register("topic0", "CID_0", "a is not null and a >= 5", ExpressionType.SQL92, System.currentTimeMillis());
    filterManager.register("topic0", "CID_1", "a is not null and a >= 15", ExpressionType.SQL92, System.currentTimeMillis());
    ConsumerFilterData nullExpression = filterManager.get("topic0", "CID_0");
    nullExpression.setExpression(null);
    nullExpression.setCompiledExpression(null);
    ConsumerFilterData nullBloomData = filterManager.get("topic0", "CID_1");
    nullBloomData.setBloomFilterData(null);
    CommitLogDispatcherCalcBitMap calcBitMap = new CommitLogDispatcherCalcBitMap(brokerConfig, filterManager);
    for (int i = 0; i < 1; i++) {
        Map<String, String> properties = new HashMap<String, String>(4);
        properties.put("a", String.valueOf(i * 10 + 5));
        String topic = "topic" + i;
        DispatchRequest dispatchRequest = new DispatchRequest(topic, 0, i * 100 + 123, 100, (long) ("tags" + i).hashCode(), System.currentTimeMillis(), i, null, UUID.randomUUID().toString(), 0, 0, properties);
        calcBitMap.dispatch(dispatchRequest);
        assertThat(dispatchRequest.getBitMap()).isNotNull();
        BitsArray bitsArray = BitsArray.create(dispatchRequest.getBitMap(), filterManager.getBloomFilter().getM());
        for (int j = 0; j < bitsArray.bitLength(); j++) {
            assertThat(bitsArray.getBit(j)).isFalse();
        }
    }
}
Also used : BrokerConfig(org.apache.rocketmq.common.BrokerConfig) HashMap(java.util.HashMap) BitsArray(org.apache.rocketmq.filter.util.BitsArray) DispatchRequest(org.apache.rocketmq.store.DispatchRequest) Test(org.junit.Test)

Example 3 with DispatchRequest

use of org.apache.rocketmq.store.DispatchRequest in project rocketmq by apache.

the class IndexService method buildIndex.

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");
    }
}
Also used : DispatchRequest(org.apache.rocketmq.store.DispatchRequest)

Example 4 with DispatchRequest

use of org.apache.rocketmq.store.DispatchRequest in project rocketmq by apache.

the class CommitLogDispatcherCalcBitMapTest method testDispatch_filterDataIllegal.

@Test
public void testDispatch_filterDataIllegal() {
    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setEnableCalcFilterBitMap(true);
    ConsumerFilterManager filterManager = new ConsumerFilterManager();
    filterManager.register("topic0", "CID_0", "a is not null and a >= 5", ExpressionType.SQL92, System.currentTimeMillis());
    filterManager.register("topic0", "CID_1", "a is not null and a >= 15", ExpressionType.SQL92, System.currentTimeMillis());
    ConsumerFilterData nullExpression = filterManager.get("topic0", "CID_0");
    nullExpression.setExpression(null);
    nullExpression.setCompiledExpression(null);
    ConsumerFilterData nullBloomData = filterManager.get("topic0", "CID_1");
    nullBloomData.setBloomFilterData(null);
    CommitLogDispatcherCalcBitMap calcBitMap = new CommitLogDispatcherCalcBitMap(brokerConfig, filterManager);
    for (int i = 0; i < 1; i++) {
        Map<String, String> properties = new HashMap<String, String>(4);
        properties.put("a", String.valueOf(i * 10 + 5));
        String topic = "topic" + i;
        DispatchRequest dispatchRequest = new DispatchRequest(topic, 0, i * 100 + 123, 100, (long) ("tags" + i).hashCode(), System.currentTimeMillis(), i, null, UUID.randomUUID().toString(), 0, 0, properties);
        calcBitMap.dispatch(dispatchRequest);
        assertThat(dispatchRequest.getBitMap()).isNotNull();
        BitsArray bitsArray = BitsArray.create(dispatchRequest.getBitMap(), filterManager.getBloomFilter().getM());
        for (int j = 0; j < bitsArray.bitLength(); j++) {
            assertThat(bitsArray.getBit(j)).isFalse();
        }
    }
}
Also used : BrokerConfig(org.apache.rocketmq.common.BrokerConfig) HashMap(java.util.HashMap) BitsArray(org.apache.rocketmq.filter.util.BitsArray) DispatchRequest(org.apache.rocketmq.store.DispatchRequest) Test(org.junit.Test)

Example 5 with DispatchRequest

use of org.apache.rocketmq.store.DispatchRequest in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class IndexService method buildIndex.

// 构建索引
public void buildIndex(DispatchRequest req) {
    // 如果indexFile有就获取没有就创建
    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");
    }
}
Also used : DispatchRequest(org.apache.rocketmq.store.DispatchRequest)

Aggregations

DispatchRequest (org.apache.rocketmq.store.DispatchRequest)10 BrokerConfig (org.apache.rocketmq.common.BrokerConfig)8 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 BitsArray (org.apache.rocketmq.filter.util.BitsArray)4 CommitLogDispatcher (org.apache.rocketmq.store.CommitLogDispatcher)2 DefaultMessageStore (org.apache.rocketmq.store.DefaultMessageStore)2 MessageArrivingListener (org.apache.rocketmq.store.MessageArrivingListener)2 MessageStoreConfig (org.apache.rocketmq.store.config.MessageStoreConfig)2 BrokerStatsManager (org.apache.rocketmq.store.stats.BrokerStatsManager)2