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/10 03:25:50 UTC

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

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