You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/04/05 15:51:53 UTC

[GitHub] [rocketmq] ltamber opened a new pull request, #4118: [ISSUE #3799] support compaction topic

ltamber opened a new pull request, #4118:
URL: https://github.com/apache/rocketmq/pull/4118

   refer to #3799
   the implement was base on 5.0.0-beta


-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] ltamber commented on a diff in pull request #4118: [RIP 30] Support Compaction topic

Posted by GitBox <gi...@apache.org>.
ltamber commented on code in PR #4118:
URL: https://github.com/apache/rocketmq/pull/4118#discussion_r846926941


##########
store/src/main/java/org/apache/rocketmq/store/kv/CompactionService.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.kv;
+
+import org.apache.rocketmq.common.ServiceThread;
+import org.apache.rocketmq.common.TopicConfig;
+import org.apache.rocketmq.common.attribute.DeletePolicy;
+import org.apache.rocketmq.common.constant.LoggerName;
+import org.apache.rocketmq.common.utils.DeletePolicyUtils;
+import org.apache.rocketmq.logging.InternalLogger;
+import org.apache.rocketmq.logging.InternalLoggerFactory;
+import org.apache.rocketmq.store.CommitLog;
+import org.apache.rocketmq.store.DispatchRequest;
+import org.apache.rocketmq.store.GetMessageResult;
+import org.apache.rocketmq.store.MessageStore;
+import org.apache.rocketmq.store.SelectMappedBufferResult;
+
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+public class CompactionService extends ServiceThread {
+    private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME);
+
+    private final CompactionStore compactionStore;
+    private final MessageStore defaultMessageStore;
+    private final CommitLog commitLog;
+    private final LinkedBlockingQueue<TopicPartitionOffset> compactionMsgQ = new LinkedBlockingQueue<>();
+
+    public CompactionService(CommitLog commitLog, MessageStore messageStore, CompactionStore compactionStore) {
+        this.commitLog = commitLog;
+        this.defaultMessageStore = messageStore;
+        this.compactionStore = compactionStore;
+    }
+
+    public void putRequest(DispatchRequest request) {
+        if (request == null) {
+            return;
+        }
+
+        String topic = request.getTopic();
+        Optional<TopicConfig> topicConfig = defaultMessageStore.getTopicConfig(topic);
+        DeletePolicy policy = DeletePolicyUtils.getDeletePolicy(topicConfig);
+        //check request topic flag
+        if (Objects.equals(policy, DeletePolicy.COMPACTION)) {
+            int queueId = request.getQueueId();
+            long physicalOffset = request.getCommitLogOffset();
+            TopicPartitionOffset tpo = new TopicPartitionOffset(topic, queueId, physicalOffset);
+            compactionMsgQ.offer(tpo);
+            this.wakeup();
+        } // else skip
+    }
+
+    public GetMessageResult getMessage(final String group, final String topic, final int queueId,
+        final long offset, final int maxMsgNums, final int maxTotalMsgSize) {
+        return compactionStore.getMessage(group, topic, queueId, offset, maxMsgNums, maxTotalMsgSize);
+    }
+
+    @Override
+    public String getServiceName() {
+        return CompactionService.class.getSimpleName();
+    }

Review Comment:
   fixed



-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] coveralls commented on pull request #4118: [ISSUE #3799] support compaction topic

Posted by GitBox <gi...@apache.org>.
coveralls commented on PR #4118:
URL: https://github.com/apache/rocketmq/pull/4118#issuecomment-1089178042

   
   [![Coverage Status](https://coveralls.io/builds/48022493/badge)](https://coveralls.io/builds/48022493)
   
   Coverage decreased (-0.2%) to 47.011% when pulling **346651535cba9af80fddb76efa1c764fce4c2029 on ltamber:5.0.0-beta-ctopic** into **52482d4e0d610f45c139dc35b8d2d8784452331e on apache:5.0.0-beta**.
   


-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] humkum commented on a diff in pull request #4118: [RIP 30] Support Compaction topic

Posted by GitBox <gi...@apache.org>.
humkum commented on code in PR #4118:
URL: https://github.com/apache/rocketmq/pull/4118#discussion_r854819135


##########
store/src/main/java/org/apache/rocketmq/store/kv/CompactionStore.java:
##########
@@ -0,0 +1,163 @@
+/*
+ * 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.kv;
+
+import org.apache.rocketmq.common.ThreadFactoryImpl;
+import org.apache.rocketmq.common.constant.LoggerName;
+import org.apache.rocketmq.logging.InternalLogger;
+import org.apache.rocketmq.logging.InternalLoggerFactory;
+import org.apache.rocketmq.store.GetMessageResult;
+import org.apache.rocketmq.store.MessageStore;
+import org.apache.rocketmq.store.SelectMappedBufferResult;
+import org.apache.rocketmq.store.config.MessageStoreConfig;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+public class CompactionStore {
+
+    public static final String COMPACTION_DIR = "compaction";
+    public static final String COMPACTION_LOG_DIR = "compactionLog";
+    public static final String COMPACTION_CQ_DIR = "compactionCq";
+
+    private final String compactionPath;
+    private final String compactionLogPath;
+    private final String compactionCqPath;
+    private final MessageStore defaultMessageStore;
+    private final CompactionPositionMgr positionMgr;
+    private final ConcurrentHashMap<String, CompactionLog> compactionLogTable;
+    private final ScheduledExecutorService compactionSchedule;
+    private final int compactionInterval;
+    private final int compactionThreadNum;
+    private final int offsetMapSize;
+
+    private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME);
+
+    public CompactionStore(MessageStore defaultMessageStore) {
+        this.defaultMessageStore = defaultMessageStore;
+        this.compactionLogTable = new ConcurrentHashMap<>();
+        MessageStoreConfig config = defaultMessageStore.getMessageStoreConfig();
+        String storeRootPath = config.getStorePathRootDir();
+        this.compactionPath = Paths.get(storeRootPath, COMPACTION_DIR).toString();
+        this.compactionLogPath = Paths.get(compactionPath, COMPACTION_LOG_DIR).toString();
+        this.compactionCqPath = Paths.get(compactionPath, COMPACTION_CQ_DIR).toString();
+        this.positionMgr = new CompactionPositionMgr(compactionPath);
+        if (config.getCompactionThreadNum() <= 0) {
+            this.compactionThreadNum = Runtime.getRuntime().availableProcessors();
+        } else {
+            this.compactionThreadNum = config.getCompactionThreadNum();
+        }
+        this.compactionSchedule = Executors.newScheduledThreadPool(this.compactionThreadNum,
+            new ThreadFactoryImpl("compactionSchedule_"));
+        this.offsetMapSize = config.getMaxOffsetMapSize() / compactionThreadNum;
+
+        this.compactionInterval = defaultMessageStore.getMessageStoreConfig().getCompactionScheduleInternal();
+    }
+
+    public void load() {
+        File logRoot = new File(compactionLogPath);
+        File[] fileTopicList = logRoot.listFiles();
+        if (fileTopicList != null) {
+            for (File fileTopic : fileTopicList) {
+                if (!fileTopic.isDirectory()) {
+                    continue;
+                }
+
+                File[] fileQueueIdList = fileTopic.listFiles();
+                if (fileQueueIdList != null) {
+                    for (File fileQueueId : fileQueueIdList) {
+                        if (!fileQueueId.isDirectory()) {
+                            continue;
+                        }
+                        try {
+                            String topic = fileTopic.getName();
+                            int queueId = Integer.parseInt(fileQueueId.getName());
+
+                            if (Files.isDirectory(Paths.get(compactionCqPath, topic, String.valueOf(queueId)))) {
+                                CompactionLog log = new CompactionLog(defaultMessageStore, topic, queueId,
+                                    offsetMapSize, positionMgr, compactionLogPath, compactionCqPath);
+                                compactionLogTable.put(topic + "_" + queueId, log);
+                                compactionSchedule.scheduleWithFixedDelay(log::doCompaction, compactionInterval, compactionInterval, TimeUnit.SECONDS);

Review Comment:
   Different compactionLog files are distinguished by topic and queueId, and do compaction in every compactionLog. Does this mean messages with the same keys must send to the same queue?



-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] complone commented on a diff in pull request #4118: [RIP 30] Support Compaction topic

Posted by GitBox <gi...@apache.org>.
complone commented on code in PR #4118:
URL: https://github.com/apache/rocketmq/pull/4118#discussion_r862751718


##########
store/src/main/java/org/apache/rocketmq/store/queue/SparseConsumeQueue.java:
##########
@@ -0,0 +1,333 @@
+/*
+ * 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 org.apache.rocketmq.common.UtilAll;
+import org.apache.rocketmq.store.MessageStore;
+import org.apache.rocketmq.store.SelectMappedBufferResult;
+import org.apache.rocketmq.store.logfile.MappedFile;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+public class SparseConsumeQueue extends BatchConsumeQueue {
+
+    public SparseConsumeQueue(
+        final String topic,
+        final int queueId,
+        final String storePath,
+        final int mappedFileSize,
+        final MessageStore defaultMessageStore) {
+        super(topic, queueId, storePath, mappedFileSize, defaultMessageStore);
+    }
+
+    public SparseConsumeQueue(
+        final String topic,
+        final int queueId,
+        final String storePath,
+        final int mappedFileSize,
+        final MessageStore defaultMessageStore,
+        final String subfolder) {
+        super(topic, queueId, storePath, mappedFileSize, defaultMessageStore, subfolder);
+    }
+
+    @Override
+    public void recover() {
+        MappedFile lastMappedFile = this.mappedFileQueue.getLastMappedFile();
+        if (lastMappedFile == null) {
+            return;
+        }

Review Comment:
   Do I need to add ```synchronized``` or ```lock``` to ensure thread safety when restoring a ByteBuffer from native?



-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] RongtongJin commented on a diff in pull request #4118: [RIP 30] Support Compaction topic

Posted by GitBox <gi...@apache.org>.
RongtongJin commented on code in PR #4118:
URL: https://github.com/apache/rocketmq/pull/4118#discussion_r846706351


##########
store/src/main/java/org/apache/rocketmq/store/kv/CompactionService.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.kv;
+
+import org.apache.rocketmq.common.ServiceThread;
+import org.apache.rocketmq.common.TopicConfig;
+import org.apache.rocketmq.common.attribute.DeletePolicy;
+import org.apache.rocketmq.common.constant.LoggerName;
+import org.apache.rocketmq.common.utils.DeletePolicyUtils;
+import org.apache.rocketmq.logging.InternalLogger;
+import org.apache.rocketmq.logging.InternalLoggerFactory;
+import org.apache.rocketmq.store.CommitLog;
+import org.apache.rocketmq.store.DispatchRequest;
+import org.apache.rocketmq.store.GetMessageResult;
+import org.apache.rocketmq.store.MessageStore;
+import org.apache.rocketmq.store.SelectMappedBufferResult;
+
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+public class CompactionService extends ServiceThread {
+    private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME);
+
+    private final CompactionStore compactionStore;
+    private final MessageStore defaultMessageStore;
+    private final CommitLog commitLog;
+    private final LinkedBlockingQueue<TopicPartitionOffset> compactionMsgQ = new LinkedBlockingQueue<>();
+
+    public CompactionService(CommitLog commitLog, MessageStore messageStore, CompactionStore compactionStore) {
+        this.commitLog = commitLog;
+        this.defaultMessageStore = messageStore;
+        this.compactionStore = compactionStore;
+    }
+
+    public void putRequest(DispatchRequest request) {
+        if (request == null) {
+            return;
+        }
+
+        String topic = request.getTopic();
+        Optional<TopicConfig> topicConfig = defaultMessageStore.getTopicConfig(topic);
+        DeletePolicy policy = DeletePolicyUtils.getDeletePolicy(topicConfig);
+        //check request topic flag
+        if (Objects.equals(policy, DeletePolicy.COMPACTION)) {
+            int queueId = request.getQueueId();
+            long physicalOffset = request.getCommitLogOffset();
+            TopicPartitionOffset tpo = new TopicPartitionOffset(topic, queueId, physicalOffset);
+            compactionMsgQ.offer(tpo);
+            this.wakeup();
+        } // else skip
+    }
+
+    public GetMessageResult getMessage(final String group, final String topic, final int queueId,
+        final long offset, final int maxMsgNums, final int maxTotalMsgSize) {
+        return compactionStore.getMessage(group, topic, queueId, offset, maxMsgNums, maxTotalMsgSize);
+    }
+
+    @Override
+    public String getServiceName() {
+        return CompactionService.class.getSimpleName();
+    }

Review Comment:
   这里getServiceName可能要照着其他store层的ServiceThread写下,通过设置线程名来区分不同broker线程,线程名前缀必须是#BrokerClusterName_BrokerName_BrokerId#,否则BrokerContainer下的broker日志将不会分离。
   
   参考https://github.com/apache/rocketmq/blob/5.0.0-beta/docs/cn/BrokerContainer.md



##########
store/src/main/java/org/apache/rocketmq/store/kv/CompactionPositionMgr.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.kv;
+
+import org.apache.rocketmq.common.ConfigManager;
+import org.apache.rocketmq.remoting.protocol.RemotingSerializable;
+
+import java.io.File;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class CompactionPositionMgr extends ConfigManager {
+
+    public static final String CHECKPOINT_FILE = "position-checkpoint";

Review Comment:
   感觉叫checkpoint又是继承configManager有点奇怪,另外position-checkpoint好像不能体现出和compaction相关



-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] duhenglucky merged pull request #4118: [RIP 30] Support Compaction topic

Posted by GitBox <gi...@apache.org>.
duhenglucky merged PR #4118:
URL: https://github.com/apache/rocketmq/pull/4118


-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] ltamber commented on a diff in pull request #4118: [RIP 30] Support Compaction topic

Posted by GitBox <gi...@apache.org>.
ltamber commented on code in PR #4118:
URL: https://github.com/apache/rocketmq/pull/4118#discussion_r846897262


##########
store/src/main/java/org/apache/rocketmq/store/kv/CompactionPositionMgr.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.kv;
+
+import org.apache.rocketmq.common.ConfigManager;
+import org.apache.rocketmq.remoting.protocol.RemotingSerializable;
+
+import java.io.File;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class CompactionPositionMgr extends ConfigManager {
+
+    public static final String CHECKPOINT_FILE = "position-checkpoint";

Review Comment:
   1. 这里主要是复用configManager持久化的能力
   2. 从目录结构来看,position-checkpoint文件路径是在 store/compaction/position-checkpoint,与compaction还是有关系的



-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] ltamber commented on a diff in pull request #4118: [RIP 30] Support Compaction topic

Posted by GitBox <gi...@apache.org>.
ltamber commented on code in PR #4118:
URL: https://github.com/apache/rocketmq/pull/4118#discussion_r868753951


##########
store/src/main/java/org/apache/rocketmq/store/queue/SparseConsumeQueue.java:
##########
@@ -0,0 +1,333 @@
+/*
+ * 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 org.apache.rocketmq.common.UtilAll;
+import org.apache.rocketmq.store.MessageStore;
+import org.apache.rocketmq.store.SelectMappedBufferResult;
+import org.apache.rocketmq.store.logfile.MappedFile;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+public class SparseConsumeQueue extends BatchConsumeQueue {
+
+    public SparseConsumeQueue(
+        final String topic,
+        final int queueId,
+        final String storePath,
+        final int mappedFileSize,
+        final MessageStore defaultMessageStore) {
+        super(topic, queueId, storePath, mappedFileSize, defaultMessageStore);
+    }
+
+    public SparseConsumeQueue(
+        final String topic,
+        final int queueId,
+        final String storePath,
+        final int mappedFileSize,
+        final MessageStore defaultMessageStore,
+        final String subfolder) {
+        super(topic, queueId, storePath, mappedFileSize, defaultMessageStore, subfolder);
+    }
+
+    @Override
+    public void recover() {
+        MappedFile lastMappedFile = this.mappedFileQueue.getLastMappedFile();
+        if (lastMappedFile == null) {
+            return;
+        }

Review Comment:
   the method `recover` invoked by only one thread, I think there is no need to add `synchronized` or `lock`



-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] codecov-commenter commented on pull request #4118: [ISSUE #3799] support compaction topic

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #4118:
URL: https://github.com/apache/rocketmq/pull/4118#issuecomment-1089742961

   # [Codecov](https://codecov.io/gh/apache/rocketmq/pull/4118?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#4118](https://codecov.io/gh/apache/rocketmq/pull/4118?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (c0ba4a5) into [5.0.0-beta](https://codecov.io/gh/apache/rocketmq/commit/52482d4e0d610f45c139dc35b8d2d8784452331e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (52482d4) will **decrease** coverage by `0.23%`.
   > The diff coverage is `37.28%`.
   
   ```diff
   @@               Coverage Diff                @@
   ##             5.0.0-beta    #4118      +/-   ##
   ================================================
   - Coverage         43.09%   42.86%   -0.24%     
   - Complexity         6014     6082      +68     
   ================================================
     Files               795      804       +9     
     Lines             56825    57701     +876     
     Branches           7780     7898     +118     
   ================================================
   + Hits              24491    24732     +241     
   - Misses            29142    29737     +595     
   - Partials           3192     3232      +40     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/rocketmq/pull/4118?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...va/org/apache/rocketmq/common/TopicAttributes.java](https://codecov.io/gh/apache/rocketmq/pull/4118/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9yb2NrZXRtcS9jb21tb24vVG9waWNBdHRyaWJ1dGVzLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...apache/rocketmq/common/attribute/DeletePolicy.java](https://codecov.io/gh/apache/rocketmq/pull/4118/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9yb2NrZXRtcS9jb21tb24vYXR0cmlidXRlL0RlbGV0ZVBvbGljeS5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...apache/rocketmq/common/message/MessageDecoder.java](https://codecov.io/gh/apache/rocketmq/pull/4118/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9yb2NrZXRtcS9jb21tb24vbWVzc2FnZS9NZXNzYWdlRGVjb2Rlci5qYXZh) | `58.67% <ø> (ø)` | |
   | [...pache/rocketmq/common/utils/DeletePolicyUtils.java](https://codecov.io/gh/apache/rocketmq/pull/4118/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9yb2NrZXRtcS9jb21tb24vdXRpbHMvRGVsZXRlUG9saWN5VXRpbHMuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...org/apache/rocketmq/store/AppendMessageResult.java](https://codecov.io/gh/apache/rocketmq/pull/4118/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3RvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3JvY2tldG1xL3N0b3JlL0FwcGVuZE1lc3NhZ2VSZXN1bHQuamF2YQ==) | `60.60% <0.00%> (-6.07%)` | :arrow_down: |
   | [...ava/org/apache/rocketmq/store/MappedFileQueue.java](https://codecov.io/gh/apache/rocketmq/pull/4118/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3RvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3JvY2tldG1xL3N0b3JlL01hcHBlZEZpbGVRdWV1ZS5qYXZh) | `52.91% <0.00%> (-1.95%)` | :arrow_down: |
   | [...pache/rocketmq/store/MultiPathMappedFileQueue.java](https://codecov.io/gh/apache/rocketmq/pull/4118/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3RvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3JvY2tldG1xL3N0b3JlL011bHRpUGF0aE1hcHBlZEZpbGVRdWV1ZS5qYXZh) | `92.30% <ø> (ø)` | |
   | [...va/org/apache/rocketmq/store/kv/CompactionLog.java](https://codecov.io/gh/apache/rocketmq/pull/4118/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3RvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3JvY2tldG1xL3N0b3JlL2t2L0NvbXBhY3Rpb25Mb2cuamF2YQ==) | `12.28% <12.28%> (ø)` | |
   | [...ache/rocketmq/store/logfile/DefaultMappedFile.java](https://codecov.io/gh/apache/rocketmq/pull/4118/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3RvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3JvY2tldG1xL3N0b3JlL2xvZ2ZpbGUvRGVmYXVsdE1hcHBlZEZpbGUuamF2YQ==) | `43.86% <24.07%> (-3.42%)` | :arrow_down: |
   | [.../org/apache/rocketmq/store/kv/CompactionStore.java](https://codecov.io/gh/apache/rocketmq/pull/4118/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3RvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3JvY2tldG1xL3N0b3JlL2t2L0NvbXBhY3Rpb25TdG9yZS5qYXZh) | `35.71% <35.71%> (ø)` | |
   | ... and [23 more](https://codecov.io/gh/apache/rocketmq/pull/4118/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/rocketmq/pull/4118?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/rocketmq/pull/4118?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [52482d4...c0ba4a5](https://codecov.io/gh/apache/rocketmq/pull/4118?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] ltamber commented on a diff in pull request #4118: [RIP 30] Support Compaction topic

Posted by GitBox <gi...@apache.org>.
ltamber commented on code in PR #4118:
URL: https://github.com/apache/rocketmq/pull/4118#discussion_r855713038


##########
store/src/main/java/org/apache/rocketmq/store/kv/CompactionStore.java:
##########
@@ -0,0 +1,163 @@
+/*
+ * 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.kv;
+
+import org.apache.rocketmq.common.ThreadFactoryImpl;
+import org.apache.rocketmq.common.constant.LoggerName;
+import org.apache.rocketmq.logging.InternalLogger;
+import org.apache.rocketmq.logging.InternalLoggerFactory;
+import org.apache.rocketmq.store.GetMessageResult;
+import org.apache.rocketmq.store.MessageStore;
+import org.apache.rocketmq.store.SelectMappedBufferResult;
+import org.apache.rocketmq.store.config.MessageStoreConfig;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+public class CompactionStore {
+
+    public static final String COMPACTION_DIR = "compaction";
+    public static final String COMPACTION_LOG_DIR = "compactionLog";
+    public static final String COMPACTION_CQ_DIR = "compactionCq";
+
+    private final String compactionPath;
+    private final String compactionLogPath;
+    private final String compactionCqPath;
+    private final MessageStore defaultMessageStore;
+    private final CompactionPositionMgr positionMgr;
+    private final ConcurrentHashMap<String, CompactionLog> compactionLogTable;
+    private final ScheduledExecutorService compactionSchedule;
+    private final int compactionInterval;
+    private final int compactionThreadNum;
+    private final int offsetMapSize;
+
+    private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME);
+
+    public CompactionStore(MessageStore defaultMessageStore) {
+        this.defaultMessageStore = defaultMessageStore;
+        this.compactionLogTable = new ConcurrentHashMap<>();
+        MessageStoreConfig config = defaultMessageStore.getMessageStoreConfig();
+        String storeRootPath = config.getStorePathRootDir();
+        this.compactionPath = Paths.get(storeRootPath, COMPACTION_DIR).toString();
+        this.compactionLogPath = Paths.get(compactionPath, COMPACTION_LOG_DIR).toString();
+        this.compactionCqPath = Paths.get(compactionPath, COMPACTION_CQ_DIR).toString();
+        this.positionMgr = new CompactionPositionMgr(compactionPath);
+        if (config.getCompactionThreadNum() <= 0) {
+            this.compactionThreadNum = Runtime.getRuntime().availableProcessors();
+        } else {
+            this.compactionThreadNum = config.getCompactionThreadNum();
+        }
+        this.compactionSchedule = Executors.newScheduledThreadPool(this.compactionThreadNum,
+            new ThreadFactoryImpl("compactionSchedule_"));
+        this.offsetMapSize = config.getMaxOffsetMapSize() / compactionThreadNum;
+
+        this.compactionInterval = defaultMessageStore.getMessageStoreConfig().getCompactionScheduleInternal();
+    }
+
+    public void load() {
+        File logRoot = new File(compactionLogPath);
+        File[] fileTopicList = logRoot.listFiles();
+        if (fileTopicList != null) {
+            for (File fileTopic : fileTopicList) {
+                if (!fileTopic.isDirectory()) {
+                    continue;
+                }
+
+                File[] fileQueueIdList = fileTopic.listFiles();
+                if (fileQueueIdList != null) {
+                    for (File fileQueueId : fileQueueIdList) {
+                        if (!fileQueueId.isDirectory()) {
+                            continue;
+                        }
+                        try {
+                            String topic = fileTopic.getName();
+                            int queueId = Integer.parseInt(fileQueueId.getName());
+
+                            if (Files.isDirectory(Paths.get(compactionCqPath, topic, String.valueOf(queueId)))) {
+                                CompactionLog log = new CompactionLog(defaultMessageStore, topic, queueId,
+                                    offsetMapSize, positionMgr, compactionLogPath, compactionCqPath);
+                                compactionLogTable.put(topic + "_" + queueId, log);
+                                compactionSchedule.scheduleWithFixedDelay(log::doCompaction, compactionInterval, compactionInterval, TimeUnit.SECONDS);

Review Comment:
   Yes. 



-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org