-
Notifications
You must be signed in to change notification settings - Fork 409
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
flush cache before segment merge (#4955) #4971
Closed
ti-chi-bot
wants to merge
5
commits into
pingcap:release-4.0
from
ti-chi-bot:cherry-pick-4955-to-release-4.0
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,7 +240,7 @@ bool Segment::writeToCache(DMContext & dm_context, const Block & block, size_t o | |
return delta->appendToCache(dm_context, block, offset, limit); | ||
} | ||
|
||
bool Segment::write(DMContext & dm_context, const Block & block) | ||
bool Segment::write(DMContext & dm_context, const Block & block, bool flush_cache) | ||
{ | ||
LOG_TRACE(log, "Segment [" << segment_id << "] write to disk rows: " << block.rows()); | ||
WriteBatches wbs(dm_context.storage_pool); | ||
|
@@ -249,7 +249,14 @@ bool Segment::write(DMContext & dm_context, const Block & block) | |
|
||
if (delta->appendToDisk(dm_context, pack)) | ||
{ | ||
flushCache(dm_context); | ||
if (flush_cache) | ||
{ | ||
while (!flushCache(dm_context)) | ||
{ | ||
if (hasAbandoned()) | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
else | ||
|
@@ -957,6 +964,28 @@ SegmentPair Segment::applySplit(DMContext & dm_context, // | |
SegmentPtr Segment::merge(DMContext & dm_context, const ColumnDefinesPtr & schema_snap, const SegmentPtr & left, const SegmentPtr & right) | ||
{ | ||
WriteBatches wbs(dm_context.storage_pool); | ||
/// This segment may contain some rows that not belong to this segment range which is left by previous split operation. | ||
/// And only saved data in this segment will be filtered by the segment range in the merge process, | ||
/// unsaved data will be directly copied to the new segment. | ||
/// So we flush here to make sure that all potential data left by previous split operation is saved. | ||
while (!left->flushCache(dm_context)) | ||
{ | ||
// keep flush until success if not abandoned | ||
if (left->hasAbandoned()) | ||
{ | ||
LOG_FMT_DEBUG(left->log, "Give up merge segments left [{}], right [{}]", left->segmentId(), right->segmentId()); | ||
return {}; | ||
} | ||
} | ||
while (!right->flushCache(dm_context)) | ||
{ | ||
// keep flush until success if not abandoned | ||
if (right->hasAbandoned()) | ||
{ | ||
LOG_FMT_DEBUG(right->log, "Give up merge segments left [{}], right [{}]", left->segmentId(), right->segmentId()); | ||
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. ditto |
||
return {}; | ||
} | ||
} | ||
|
||
auto left_snap = left->createSnapshot(dm_context, true); | ||
auto right_snap = right->createSnapshot(dm_context, true); | ||
|
@@ -977,6 +1006,10 @@ SegmentPtr Segment::merge(DMContext & dm_context, const ColumnDefinesPtr & schem | |
return merged; | ||
} | ||
|
||
/// Segments may contain some rows that not belong to its range which is left by previous split operation. | ||
/// And only saved data in the segment will be filtered by the segment range in the merge process, | ||
/// unsaved data will be directly copied to the new segment. | ||
/// So remember to do a flush for the segments before merge. | ||
StableValueSpacePtr Segment::prepareMerge(DMContext & dm_context, // | ||
const ColumnDefinesPtr & schema_snap, | ||
const SegmentPtr & left, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use
LOG_DEBUG
in 4.0