lizhimins commented on code in PR #9256: URL: https://github.com/apache/rocketmq/pull/9256#discussion_r2050296669
########## store/src/main/java/org/apache/rocketmq/store/queue/CombineConsumeQueueStore.java: ########## @@ -0,0 +1,528 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.store.queue; + +import com.alibaba.fastjson.JSON; +import com.google.common.annotations.VisibleForTesting; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.commons.lang3.StringUtils; +import org.apache.rocketmq.common.BoundaryType; +import org.apache.rocketmq.common.CheckRocksdbCqWriteResult; +import org.apache.rocketmq.common.Pair; +import org.apache.rocketmq.common.constant.LoggerName; +import org.apache.rocketmq.common.message.MessageExtBrokerInner; +import org.apache.rocketmq.store.DefaultMessageStore; +import org.apache.rocketmq.store.DispatchRequest; +import org.apache.rocketmq.store.StoreType; +import org.apache.rocketmq.store.config.MessageStoreConfig; +import org.apache.rocketmq.store.exception.ConsumeQueueException; +import org.apache.rocketmq.store.exception.StoreException; +import org.rocksdb.RocksDBException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CombineConsumeQueueStore implements ConsumeQueueStoreInterface { + private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME); + private static final Logger BROKER_LOG = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); + + private final MessageStoreConfig messageStoreConfig; + + // Inner consume queue store. + private final List<AbstractConsumeQueueStore> innerConsumeQueueStoreList = new ArrayList<>(); + private final ConsumeQueueStore consumeQueueStore; + private final RocksDBConsumeQueueStore rocksDBConsumeQueueStore; + + // currentReadStore can be dynamically changed during the broker running + private final AbstractConsumeQueueStore currentReadStore; + + // consume queue store for assign offset and increase offset. + private final AbstractConsumeQueueStore assignOffsetStore; + + // used for search recover form which commitLog mappedFile. + // when assignOffsetStore allow recovering from here, but other do not allow, toleranceFailuresNum will minus 1. + // if toleranceFailuresNum is 0, only pay attention to whether assignOffsetStore is allowed + private final AtomicInteger toleranceLookBackFailuresNum; + + public CombineConsumeQueueStore(DefaultMessageStore messageStore) { + this.messageStoreConfig = messageStore.getMessageStoreConfig(); + toleranceLookBackFailuresNum = new AtomicInteger(messageStoreConfig.getCombineCQMaxExtraLookBackCommitLogFiles()); + + Set<StoreType> loadingConsumeQueueTypeSet = StoreType.fromString(messageStoreConfig.getCombineCQLoadingCQTypes()); + if (loadingConsumeQueueTypeSet.isEmpty()) { + throw new IllegalArgumentException("CombineConsumeQueueStore loadingCQTypes is empty"); + } + + if (loadingConsumeQueueTypeSet.contains(StoreType.DEFAULT)) { + this.consumeQueueStore = new ConsumeQueueStore(messageStore); + this.innerConsumeQueueStoreList.add(consumeQueueStore); + } else { + this.consumeQueueStore = null; + } + + if (loadingConsumeQueueTypeSet.contains(StoreType.DEFAULT_ROCKSDB)) { + this.rocksDBConsumeQueueStore = new RocksDBConsumeQueueStore(messageStore); + this.innerConsumeQueueStoreList.add(rocksDBConsumeQueueStore); + } else { + this.rocksDBConsumeQueueStore = null; + } + + if (innerConsumeQueueStoreList.isEmpty()) { + throw new IllegalArgumentException("CombineConsumeQueueStore loadingCQTypes is empty"); + } + + assignOffsetStore = getInnerStoreByString(messageStoreConfig.getCombineAssignOffsetCQType()); + if (assignOffsetStore == null) { + log.error("CombineConsumeQueue chooseAssignOffsetStore fail, prefer={}", messageStoreConfig.getCombineAssignOffsetCQType()); + throw new IllegalArgumentException("CombineConsumeQueue chooseAssignOffsetStore fail"); + } + + currentReadStore = getInnerStoreByString(messageStoreConfig.getCombineCQPreferCQType()); + if (currentReadStore == null) { + log.error("CombineConsumeQueue choosePreferCQ fail, prefer={}", messageStoreConfig.getCombineCQPreferCQType()); + throw new IllegalArgumentException("CombineConsumeQueue choosePreferCQ fail"); + } + + log.info("CombineConsumeQueueStore init, consumeQueueStoreList={}, currentReadStore={}, assignOffsetStore={}", + innerConsumeQueueStoreList, currentReadStore.getClass().getSimpleName(), assignOffsetStore.getClass().getSimpleName()); + } + + @Override + public boolean load() { + log.info("CombineConsumeQueueStore load begin"); Review Comment: 日志一般在成功之后,下同 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@rocketmq.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org