-
Notifications
You must be signed in to change notification settings - Fork 12k
[ISSUE #10288] Hold MappedFile reference in ConsumeQueue write path to prevent SIGSEGV #10566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -856,44 +856,52 @@ private boolean putMessagePositionInfo(final long offset, final int size, final | |
|
|
||
| MappedFile mappedFile = this.mappedFileQueue.getLastMappedFile(expectLogicOffset); | ||
| if (mappedFile != null) { | ||
|
|
||
| if (mappedFile.isFirstCreateInQueue() && cqOffset != 0 && mappedFile.getWrotePosition() == 0) { | ||
| this.minLogicOffset = expectLogicOffset; | ||
| this.mappedFileQueue.setFlushedWhere(expectLogicOffset); | ||
| this.mappedFileQueue.setCommittedWhere(expectLogicOffset); | ||
| this.fillPreBlank(mappedFile, expectLogicOffset); | ||
| log.info("fill pre blank space " + mappedFile.getFileName() + " " + expectLogicOffset + " " | ||
| + mappedFile.getWrotePosition()); | ||
| if (!mappedFile.hold()) { | ||
| log.warn("Failed to hold mapped file for ConsumeQueue write, topic={} queueId={}", | ||
| this.topic, this.queueId); | ||
| return false; | ||
| } | ||
| try { | ||
| if (mappedFile.isFirstCreateInQueue() && cqOffset != 0 && mappedFile.getWrotePosition() == 0) { | ||
| this.minLogicOffset = expectLogicOffset; | ||
| this.mappedFileQueue.setFlushedWhere(expectLogicOffset); | ||
| this.mappedFileQueue.setCommittedWhere(expectLogicOffset); | ||
| this.fillPreBlank(mappedFile, expectLogicOffset); | ||
| log.info("fill pre blank space " + mappedFile.getFileName() + " " + expectLogicOffset + " " | ||
| + mappedFile.getWrotePosition()); | ||
| } | ||
|
|
||
| if (cqOffset != 0) { | ||
| long currentLogicOffset = mappedFile.getWrotePosition() + mappedFile.getFileFromOffset(); | ||
| if (cqOffset != 0) { | ||
| long currentLogicOffset = mappedFile.getWrotePosition() + mappedFile.getFileFromOffset(); | ||
|
|
||
| if (expectLogicOffset < currentLogicOffset) { | ||
| log.warn("Build consume queue repeatedly, expectLogicOffset: {} currentLogicOffset: {} Topic: {} QID: {} Diff: {}", | ||
| expectLogicOffset, currentLogicOffset, this.topic, this.queueId, expectLogicOffset - currentLogicOffset); | ||
| return true; | ||
| } | ||
| if (expectLogicOffset < currentLogicOffset) { | ||
| log.warn("Build consume queue repeatedly, expectLogicOffset: {} currentLogicOffset: {} Topic: {} QID: {} Diff: {}", | ||
| expectLogicOffset, currentLogicOffset, this.topic, this.queueId, expectLogicOffset - currentLogicOffset); | ||
| return true; | ||
| } | ||
|
|
||
| if (expectLogicOffset != currentLogicOffset) { | ||
| LOG_ERROR.warn( | ||
| "[BUG]logic queue order maybe wrong, expectLogicOffset: {} currentLogicOffset: {} Topic: {} QID: {} Diff: {}", | ||
| expectLogicOffset, | ||
| currentLogicOffset, | ||
| this.topic, | ||
| this.queueId, | ||
| expectLogicOffset - currentLogicOffset | ||
| ); | ||
| if (expectLogicOffset != currentLogicOffset) { | ||
| LOG_ERROR.warn( | ||
| "[BUG]logic queue order maybe wrong, expectLogicOffset: {} currentLogicOffset: {} Topic: {} QID: {} Diff: {}", | ||
| expectLogicOffset, | ||
| currentLogicOffset, | ||
| this.topic, | ||
| this.queueId, | ||
| expectLogicOffset - currentLogicOffset | ||
| ); | ||
| } | ||
| } | ||
| this.setMaxPhysicOffset(offset + size); | ||
| boolean appendResult; | ||
| if (messageStore.getMessageStoreConfig().isPutConsumeQueueDataByFileChannel()) { | ||
| appendResult = mappedFile.appendMessageUsingFileChannel(this.byteBufferIndex.array()); | ||
| } else { | ||
| appendResult = mappedFile.appendMessage(this.byteBufferIndex.array()); | ||
| } | ||
| return appendResult; | ||
| } finally { | ||
| mappedFile.release(); | ||
| } | ||
| this.setMaxPhysicOffset(offset + size); | ||
| boolean appendResult; | ||
| if (messageStore.getMessageStoreConfig().isPutConsumeQueueDataByFileChannel()) { | ||
| appendResult = mappedFile.appendMessageUsingFileChannel(this.byteBufferIndex.array()); | ||
| } else { | ||
| appendResult = mappedFile.appendMessage(this.byteBufferIndex.array()); | ||
| } | ||
| return appendResult; | ||
| } | ||
| return false; | ||
| } | ||
|
|
@@ -1271,7 +1279,13 @@ public void initializeWithOffset(long offset, long minPhyOffset) { | |
|
|
||
| // transientStorePool is null, only need set wrote position here | ||
| MappedFile mappedFile = mappedFileQueue.getLastMappedFile(offset * ConsumeQueue.CQ_STORE_UNIT_SIZE, true); | ||
| fillPreBlank(mappedFile, offset * ConsumeQueue.CQ_STORE_UNIT_SIZE); | ||
| if (mappedFile != null && mappedFile.hold()) { | ||
| try { | ||
| fillPreBlank(mappedFile, offset * ConsumeQueue.CQ_STORE_UNIT_SIZE); | ||
| } finally { | ||
| mappedFile.release(); | ||
| } | ||
| } | ||
|
Comment on lines
1281
to
+1288
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Fixed in the latest commit — instead of silently skipping if (mappedFile == null) {
log.error("initializeWithOffset failed: mappedFile is null for offset {}", offset);
return;
}
if (!mappedFile.hold()) {
log.error("initializeWithOffset failed: mappedFile hold() failed for offset {}", offset);
return;
}This ensures the consume queue is not left in an inconsistent state (no |
||
|
|
||
| flush(0); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.