Skip to content
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

Merged
merged 6 commits into from
May 23, 2022
Merged

Conversation

lidezhu
Copy link
Contributor

@lidezhu lidezhu commented May 22, 2022

What problem does this PR solve?

Issue Number: close #4956

Problem Summary:
When do segment split, we try to copy the tail column files in the delta layer of the original segment to the new result
segments. So the new segments may contain data that doesn't belong to its segment range.

And this is ok for most cases, because the redundant data will be filtered out by the segment range when serve the read requests to the segment. So the redundant is invisible in almost all cases.

But when do segment merge later, if the previous redundant data is still not flushed to disk, it will be directly copied to the new merged segment again.

So the redundant data in each segment become visible again after segment merge which may cause potential data incorrectness.

What is changed and how it works?

Flush cache before every merge operation. So the potential unsaved data will be filtered out by the segment range when do merge.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Fix potential wrong result after a lot of insert and delete operations

@ti-chi-bot
Copy link
Member

ti-chi-bot commented May 22, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • JaySon-Huang
  • flowbehappy

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge/needs-triage-completed needs-cherry-pick-release-4.0 PR which needs to be cherry-picked to release-4.0 needs-cherry-pick-release-5.0 PR which needs to be cherry-picked to release-5.0 needs-cherry-pick-release-5.1 PR which needs to be cherry-picked to release-5.1 needs-cherry-pick-release-5.2 PR which needs to be cherry-picked to release-5.2 needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.0 Type: Need cherry pick to release-6.0 needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/needs-linked-issue do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. labels May 22, 2022
@lidezhu
Copy link
Contributor Author

lidezhu commented May 22, 2022

/run-all-tests

@sre-bot
Copy link
Collaborator

sre-bot commented May 22, 2022

Coverage for changed files

Filename                       Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DeltaMergeStore.cpp               1422               475    66.60%          67                 5    92.54%        2020               441    78.17%         822               370    54.99%
Segment.cpp                        650               185    71.54%          47                 3    93.62%        1144               248    78.32%         342               175    48.83%
Segment.h                           34                 5    85.29%          22                 3    86.36%          31                 4    87.10%           6                 3    50.00%
tests/gtest_dm_segment.cpp        3404               814    76.09%          38                 1    97.37%        1505                21    98.60%        1130               471    58.32%
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                             5510              1479    73.16%         174                12    93.10%        4700               714    84.81%        2300              1019    55.70%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18224      9785             46.31%    204149  97870        52.06%

full coverage report (for internal network access only)

@lidezhu
Copy link
Contributor Author

lidezhu commented May 22, 2022

/run-all-tests

@sre-bot
Copy link
Collaborator

sre-bot commented May 22, 2022

Coverage for changed files

Filename                       Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DeltaMergeStore.cpp               1426               477    66.55%          67                 5    92.54%        2024               445    78.01%         826               373    54.84%
Segment.cpp                        654               187    71.41%          47                 3    93.62%        1148               252    78.05%         346               180    47.98%
Segment.h                           34                 5    85.29%          22                 3    86.36%          31                 4    87.10%           6                 3    50.00%
tests/gtest_dm_segment.cpp        3404               814    76.09%          38                 1    97.37%        1505                21    98.60%        1130               471    58.32%
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                             5518              1483    73.12%         174                12    93.10%        4708               722    84.66%        2308              1027    55.50%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18224      9785             46.31%    204157  97924        52.03%

full coverage report (for internal network access only)

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request May 23, 2022
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #4966.

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request May 23, 2022
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #4967.

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request May 23, 2022
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #4968.

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request May 23, 2022
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #4969.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #4970.

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request May 23, 2022
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #4971.

lidezhu added a commit that referenced this pull request May 23, 2022
* flush cache before segment merge

* keep flush until success

* check whether segment is valid if flush failed

* Update dbms/src/Storages/DeltaMerge/tests/gtest_dm_segment.cpp

Co-authored-by: JaySon <tshent@qq.com>

* add more fix

* check flush result in segment::write

Co-authored-by: lidezhu <lidezhu@pingcap.com>
Co-authored-by: lidezhu <47731263+lidezhu@users.noreply.github.com>
Co-authored-by: JaySon <tshent@qq.com>
lidezhu added a commit to lidezhu/tics that referenced this pull request May 31, 2022
ti-chi-bot added a commit that referenced this pull request Jun 1, 2022
ti-chi-bot added a commit that referenced this pull request Jun 2, 2022
ti-chi-bot added a commit that referenced this pull request Jun 2, 2022
ti-chi-bot added a commit that referenced this pull request Jun 2, 2022
ti-chi-bot added a commit that referenced this pull request Jun 3, 2022
lidezhu added a commit to lidezhu/tics that referenced this pull request Jul 5, 2022
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@lidezhu lidezhu mentioned this pull request Jul 5, 2022
12 tasks
lidezhu added a commit that referenced this pull request Jul 6, 2022
* This is an automated cherry-pick of #4955

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>

* Update DeltaMergeStore.cpp

* Fix conflict

* fix build

* try fix unit test

* fix unit test fail
breezewish pushed a commit that referenced this pull request Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-4.0 PR which needs to be cherry-picked to release-4.0 needs-cherry-pick-release-5.0 PR which needs to be cherry-picked to release-5.0 needs-cherry-pick-release-5.1 PR which needs to be cherry-picked to release-5.1 needs-cherry-pick-release-5.2 PR which needs to be cherry-picked to release-5.2 needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.0 Type: Need cherry pick to release-6.0 needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Count result may be wrong after a lot of insert and delete
5 participants