Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6116ab0

Browse files
author
guyinyou
committed
feat: add enableRunningFlagsInFlush switch for CommitLog reliability control
- Add configuration to control runningFlags usage in CommitLog (default: false) - Update CommitLog and AllocateMappedFileService to respect the configuration - Users can enable runningFlags validation as needed
1 parent 1d9b02c commit 6116ab0

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

store/src/main/java/org/apache/rocketmq/store/AllocateMappedFileService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,18 @@ private boolean mmapOperation() {
173173

174174
MappedFile mappedFile;
175175
boolean writeWithoutMmap = messageStore.getMessageStoreConfig().isWriteWithoutMmap();
176+
RunningFlags runningFlags = messageStore.getMessageStoreConfig().isEnableRunningFlagsInFlush()
177+
? messageStore.getRunningFlags() : null;
176178
if (messageStore.isTransientStorePoolEnable()) {
177179
try {
178180
mappedFile = ServiceLoader.load(MappedFile.class).iterator().next();
179-
mappedFile.init(req.getFilePath(), req.getFileSize(), messageStore.getRunningFlags(), messageStore.getTransientStorePool());
181+
mappedFile.init(req.getFilePath(), req.getFileSize(), runningFlags, messageStore.getTransientStorePool());
180182
} catch (RuntimeException e) {
181183
log.warn("Use default implementation.");
182-
mappedFile = new DefaultMappedFile(req.getFilePath(), req.getFileSize(), messageStore.getRunningFlags(), messageStore.getTransientStorePool(), writeWithoutMmap);
184+
mappedFile = new DefaultMappedFile(req.getFilePath(), req.getFileSize(), runningFlags, messageStore.getTransientStorePool(), writeWithoutMmap);
183185
}
184186
} else {
185-
mappedFile = new DefaultMappedFile(req.getFilePath(), req.getFileSize(), messageStore.getRunningFlags(), writeWithoutMmap);
187+
mappedFile = new DefaultMappedFile(req.getFilePath(), req.getFileSize(), runningFlags, writeWithoutMmap);
186188
}
187189

188190
long elapsedTime = UtilAll.computeElapsedTimeMilliseconds(beginTime);

store/src/main/java/org/apache/rocketmq/store/CommitLog.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,18 @@ public class CommitLog implements Swappable {
111111

112112
public CommitLog(final DefaultMessageStore messageStore) {
113113
String storePath = messageStore.getMessageStoreConfig().getStorePathCommitLog();
114+
RunningFlags runningFlags = messageStore.getMessageStoreConfig().isEnableRunningFlagsInFlush()
115+
? messageStore.getRunningFlags() : null;
116+
114117
if (storePath.contains(MixAll.MULTI_PATH_SPLITTER)) {
115118
this.mappedFileQueue = new MultiPathMappedFileQueue(messageStore.getMessageStoreConfig(),
116119
messageStore.getMessageStoreConfig().getMappedFileSizeCommitLog(),
117-
messageStore.getAllocateMappedFileService(), this::getFullStorePaths, messageStore.getRunningFlags());
120+
messageStore.getAllocateMappedFileService(), this::getFullStorePaths, runningFlags);
118121
} else {
119122
this.mappedFileQueue = new MappedFileQueue(storePath,
120123
messageStore.getMessageStoreConfig().getMappedFileSizeCommitLog(),
121124
messageStore.getAllocateMappedFileService(),
122-
messageStore.getRunningFlags(),
125+
runningFlags,
123126
messageStore.getMessageStoreConfig().isWriteWithoutMmap());
124127
}
125128

store/src/main/java/org/apache/rocketmq/store/config/MessageStoreConfig.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ public class MessageStoreConfig {
282282
*/
283283
private boolean autoMessageVersionOnTopicLen = true;
284284

285+
/**
286+
* Whether to use runningFlags when flushing data to disk.
287+
* When disabled, runningFlags will be set to null during MappedFileQueue and MappedFile initialization.
288+
*/
289+
@ImportantField
290+
private boolean enableRunningFlagsInFlush = false;
291+
285292
/**
286293
* It cannot be changed after the broker is started.
287294
* Modifications need to be restarted to take effect.
@@ -2042,4 +2049,12 @@ public boolean isEnableAcceleratedRecovery() {
20422049
public void setEnableAcceleratedRecovery(boolean enableAcceleratedRecovery) {
20432050
this.enableAcceleratedRecovery = enableAcceleratedRecovery;
20442051
}
2052+
2053+
public boolean isEnableRunningFlagsInFlush() {
2054+
return enableRunningFlagsInFlush;
2055+
}
2056+
2057+
public void setEnableRunningFlagsInFlush(boolean enableRunningFlagsInFlush) {
2058+
this.enableRunningFlagsInFlush = enableRunningFlagsInFlush;
2059+
}
20452060
}

0 commit comments

Comments
 (0)