yx9o commented on code in PR #11502:
URL: https://github.com/apache/rocketmq/pull/11502#discussion_r4440299139
##########
store/src/main/java/org/apache/rocketmq/store/delay/DelayLogService.java:
##########
@@ -0,0 +1,106 @@
+package org.apache.rocketmq.store.delay;
+
+import org.apache.rocketmq.common.constant.LoggerName;
+import org.apache.rocketmq.common.message.MessageDecoder;
+import org.apache.rocketmq.common.message.MessageExt;
+import org.apache.rocketmq.logging.InternalLogger;
+import org.apache.rocketmq.logging.InternalLoggerFactory;
+import org.apache.rocketmq.store.AllocateMappedFileService;
+import org.apache.rocketmq.store.MappedFile;
+import org.apache.rocketmq.store.MappedFileQueue;
+import org.apache.rocketmq.store.SelectMappedBufferResult;
+
+import java.io.File;
+import java.nio.ByteBuffer;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.apache.rocketmq.store.delay.DelayService.resolveFolder;
+
+public class DelayLogService {
+ private static final InternalLogger log =
InternalLoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME);
+ private static final int DELAY_LOG_FILE_SIZE = 50 * 1024 * 1024; // 延时消息
WAL 文件,50MB
+ private final String storePath;
+ private final AllocateMappedFileService allocateMappedFileService;
+ private final ConcurrentHashMap<Long, MappedFileQueue> walFileMap = new
ConcurrentHashMap<>();
+
+ public DelayLogService(String logDir, AllocateMappedFileService
allocateMappedFileService) {
+ this.storePath = logDir;
+ this.allocateMappedFileService = allocateMappedFileService;
+ }
+
+ public long appendMessage(long fileId, byte[] rawBytes) {
+ try {
+ MappedFileQueue logQueue = getOrCreateLogQueue(fileId);
+ MappedFile activeLogFile = logQueue.getLastMappedFile();
+ if (activeLogFile == null || activeLogFile.isFull()) {
+ activeLogFile = logQueue.getLastMappedFile(0);
+ }
+
+ long delayWalOffset = activeLogFile.getFileFromOffset() +
activeLogFile.getWrotePosition();
+
+ activeLogFile.appendMessage(rawBytes);
Review Comment:
Could we roll over when the remaining space is smaller than rawBytes.length
and check the append result before returning the offset? isFull() only detects
an exactly full file, so a boundary-crossing record is silently rejected here
while DelayService.build() still creates an index for bytes that were never
written.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]