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

[WIP] PageStorage: introduce ExternalMap to manage DTFile lifetime #4000

Closed
wants to merge 8 commits into from

Conversation

JaySon-Huang
Copy link
Contributor

@JaySon-Huang JaySon-Huang commented Feb 11, 2022

What problem does this PR solve?

Issue Number: close #4017

Problem Summary:

What is changed and how it works?

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

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Feb 11, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • jiaqizho

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/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 11, 2022
@JaySon-Huang
Copy link
Contributor Author

/run-unit-test

@JaySon-Huang JaySon-Huang force-pushed the fix_ref_id branch 2 times, most recently from 85c502a to 0d1ec4b Compare February 11, 2022 11:38
@JaySon-Huang
Copy link
Contributor Author

TODO:

  • Split 6617289 into a sepeart PR and fix the lints in V2
  • Add a struct for the callbacks in V2 && V3
  • Update CollapsingPageDirectory
  • Update PageDirectory::create PageDirectory::gc and related tests

@JaySon-Huang
Copy link
Contributor Author

/run-unit-test

1 similar comment
@JaySon-Huang
Copy link
Contributor Author

/run-unit-test

@sre-bot
Copy link
Collaborator

sre-bot commented Feb 14, 2022

Coverage for changed files

Filename                                                  Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DeltaMerge/DeltaMergeStore.cpp                               1297               454    65.00%          66                 6    90.91%        1908               439    76.99%         760               364    52.11%
Page/PageStorage.h                                             16                 8    50.00%          16                 8    50.00%          53                20    62.26%           0                 0         -
Page/V2/PageFile.cpp                                          498               141    71.69%          55                 3    94.55%         988               221    77.63%         344               117    65.99%
Page/V2/PageStorage.cpp                                       518               146    71.81%          36                 3    91.67%         880               163    81.48%         350               144    58.86%
Page/V2/PageStorage.h                                          41                 9    78.05%          16                 3    81.25%          44                 3    93.18%          20                 9    55.00%
Page/V2/VersionSet/PageEntriesVersionSetWithDelta.cpp         188                37    80.32%          22                 0   100.00%         393                75    80.92%         138                39    71.74%
Page/V2/tests/gtest_page_storage.cpp                         4855               980    79.81%          32                 2    93.75%        1044                 5    99.52%        1498               712    52.47%
Page/V3/BlobStore.cpp                                         346               121    65.03%          39                 6    84.62%         726               217    70.11%         218                89    59.17%
Page/V3/PageDirectory.cpp                                     294                47    84.01%          34                 4    88.24%         641               113    82.37%         216                46    78.70%
Page/V3/PageDirectory.h                                        41                 7    82.93%          24                 6    75.00%         104                26    75.00%          20                 4    80.00%
Page/V3/PageEntriesEdit.h                                      36                10    72.22%          24                 5    79.17%          89                18    79.78%          12                 6    50.00%
Page/V3/PageStorageImpl.cpp                                    66                23    65.15%          18                 8    55.56%         153                64    58.17%          36                20    44.44%
Page/V3/PageStorageImpl.h                                       8                 4    50.00%           8                 4    50.00%           8                 4    50.00%           0                 0         -
Page/V3/WAL/serialize.cpp                                      40                 8    80.00%          13                 0   100.00%         191                28    85.34%          40                 8    80.00%
Page/V3/tests/gtest_blob_store.cpp                           3479               559    83.93%          16                 0   100.00%         694                 0   100.00%        1080               508    52.96%
Page/V3/tests/gtest_collapsing_page_directory.cpp            1287               203    84.23%           7                 0   100.00%         275                 0   100.00%         420               199    52.62%
Page/V3/tests/gtest_page_directory.cpp                       7101              1010    85.78%          31                 0   100.00%        1052                 0   100.00%        2366              1183    50.00%
Page/V3/tests/gtest_page_storage.cpp                         2394               900    62.41%          27                 8    70.37%         637               161    74.73%         770               464    39.74%
Page/V3/tests/gtest_wal_store.cpp                            2439               320    86.88%          20                 4    80.00%         505                 9    98.22%         802               393    51.00%
Page/WriteBatch.h                                              39                 4    89.74%          18                 2    88.89%          80                11    86.25%          22                 3    86.36%
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                       24983              4991    80.02%         522                72    86.21%       10465              1577    84.93%        9112              4308    52.72%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
16411      9727             40.73%    180478  98677        45.32%

full coverage report (for internal network access only)

dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp Outdated Show resolved Hide resolved
dbms/src/Storages/Page/V3/PageDirectory.cpp Show resolved Hide resolved
: iter->second->getEntry(last_sequence + 1));
entry)
{
// copy the entry to be ref
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seem like there still have some GC problem?

If ori_page_id has been removed by gc. then the entry used ref_pageid can't find data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is an unsolved problem that after implementing the "REF", when should we remove the entry from the BlobStore(spacemap)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #4061

Signed-off-by: JaySon-Huang <tshent@qq.com>
Signed-off-by: JaySon-Huang <tshent@qq.com>
Signed-off-by: JaySon-Huang <tshent@qq.com>
Signed-off-by: JaySon-Huang <tshent@qq.com>
Signed-off-by: JaySon-Huang <tshent@qq.com>
Signed-off-by: JaySon-Huang <tshent@qq.com>
Copy link
Contributor

@jiaqizho jiaqizho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some comments

dbms/src/Storages/Page/V3/PageDirectory.cpp Outdated Show resolved Hide resolved
bool ExternalMap::createExternal(PageId page_id, UInt64 sequence)
{
auto [iter, new_inserted] = external_table_directory.insert(std::make_pair(page_id, ExternalPageHolder(page_id, sequence)));
if (unlikely(!new_inserted))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we roll back it here?

Copy link
Contributor Author

@JaySon-Huang JaySon-Huang Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing needs to be roll back here.
If new_inserted == false, then iter is an iterator that points to the existing item. Nothing gets inserted or changed so nothing needs to be roll back.

>  cat a.cpp
#include <map>
#include <iostream>
using namespace std;

struct A
{
    int a, b;
    A(int a_, int b_): a(a_), b(b_) {}
};

int main()
{
    map<int, A> m;
    {
        auto [iter, new_inserted] = m.insert(std::make_pair(1, A{1, 2}));
        cout << "new: " << new_inserted << ". " << iter->first << ":" << iter->second.a << "," << iter->second.b << endl;
    }
    {
        auto [iter, new_inserted] = m.insert(std::make_pair(1, A{3, 4}));
        cout << "new: " << new_inserted << ". " << iter->first << ":" << iter->second.a << "," << iter->second.b << endl;
    }
    return 0;
}

>  g++ a.cpp -std=c++17 && ./a.out
new: 1. 1:1,2
new: 0. 1:1,2

// Try to apply ref on external pages
if (!external_directory.tryCreateRef(record.page_id, record.ori_page_id, record.version.sequence))
{
// LOG_FMT_WARNING(log, "Trying to add ref from {} to non-exist {} with seq={}", record.page_id, record.ori_page_id, record.version.sequence);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not return false? or should we throw a exception here, cause it looks like a logic error.

{
table_directory.erase(iter);
// put after ref, must be sth wrong!!!
// LOG_FMT_WARNING(log, "Trying to add ref from {} to non-exist {} with seq={}", record.page_id, record.ori_page_id, record.version.sequence);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep this log.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 15, 2022
Signed-off-by: JaySon-Huang <tshent@qq.com>
Signed-off-by: JaySon-Huang <tshent@qq.com>
@JaySon-Huang
Copy link
Contributor Author

do it by another design #4174

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ref page lifetime management is broken
4 participants