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

Introduce magic_enum into tiflash #5843

Merged
merged 9 commits into from Sep 15, 2022
Merged

Conversation

Ziy1-Tan
Copy link
Contributor

@Ziy1-Tan Ziy1-Tan commented Sep 11, 2022

What problem does this PR solve?

Issue Number: ref #5758

Problem Summary:

What is changed and how it works?

  • Neargye/magic_enum is a static reflection enumeration library, It make us to work with any enum type without any macro or boilerplate code without loss of performance;
  • I introduce Neargye/magic_enum into tiflash via git submodule;
  • The tests are located in dbms/src/Common/tests/gtest_magic_enum.cpp, which perfectly makes the conversion between the enum type and the enum name.

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 Sep 11, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • breezewish
  • fuzhe1989

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
Copy link
Member

Welcome @Ziy1-Tan!

It looks like this is your first PR to pingcap/tiflash 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to pingcap/tiflash. 😃

@ti-chi-bot ti-chi-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 11, 2022
@sre-bot
Copy link
Collaborator

sre-bot commented Sep 11, 2022

CLA assistant check
All committers have signed the CLA.

@Ziy1-Tan
Copy link
Contributor Author

Hey, @ywqzzy @JaySon-Huang. Do I need more tests, or do I need to modify the existing enum related code with magic_enum, what part should I do next? I would really appreciate if you guys could give me some guidance:).

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 11, 2022
Copy link
Contributor

@Lloyd-Pottiger Lloyd-Pottiger left a comment

Choose a reason for hiding this comment

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

@Ziy1-Tan Thanks for your excellent work! Could you please add a little bit more tests like the use of different api which not only test the correctness of the submodule, but also give an example of usage. And feel free to modify the existing enum related code.

#include <gtest/gtest.h>

#include <magic_enum.hpp>
using namespace magic_enum;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
using namespace magic_enum;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice one! I'll consider to add more tests using api which may replace existing enum related code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I evaluated the enum usage in existing projects and added the magic API test cases for accessing and converting enum types, I can add some more advanced APIs in the future if needed.

@breezewish
Copy link
Member

@Ziy1-Tan I think you can pick one of the enum in the code base which self-implemented some features that magic_enum provides, and use magic_enum to simplify it. This should be sufficient as a working usage example and why we would like to introduce magic_enum.

For example, you may consider ThreadType:

which does not need a wide refactor and you may use magic_enum to drop the toString(ThreadType).

@Ziy1-Tan
Copy link
Contributor Author

Ziy1-Tan commented Sep 12, 2022

@Ziy1-Tan I think you can pick one of the enum in the code base which self-implemented some features that magic_enum provides, and use magic_enum to simplify it. This should be sufficient as a working usage example and why we would like to introduce magic_enum.

For example, you may consider ThreadType:

which does not need a wide refactor and you may use magic_enum to drop the toString(ThreadType).

Good! I'll try it.

@JaySon-Huang
Copy link
Contributor

I think using the v0.8.1 43a9272 instead of the 1b1194b from master is better for tracking the third-party library version

@ti-chi-bot ti-chi-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 14, 2022
Copy link
Member

@breezewish breezewish left a comment

Choose a reason for hiding this comment

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

Cool!

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 14, 2022
@breezewish
Copy link
Member

@Ziy1-Tan Could you rebase your change over the latest master? We introduced several enum change recently.., which brings some conflict with this PR.

@breezewish
Copy link
Member

@Lloyd-Pottiger Please take a look for the recent change

@Ziy1-Tan
Copy link
Contributor Author

@Lloyd-Pottiger Please take a look for the recent change

OK, Let me check it.

@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 14, 2022
.gitmodules Outdated Show resolved Hide resolved
ASSERT_EQ(entry.first, magic_enum::enum_cast<Mode>(entry.second));
}
}
} // namespace DB::tests
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please add for some unusual case like magic_enum::enum_name(-1), magic_enum::enum_name(999999999) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay.

Copy link
Contributor Author

@Ziy1-Tan Ziy1-Tan Sep 15, 2022

Choose a reason for hiding this comment

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

magic_enum::enum_name based on reflection allows us to catch errors before compiling and can only pass enums instead of integers. So it's not easy to test. But I test ohters API in unusal cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

cool!

@Ziy1-Tan
Copy link
Contributor Author

/cc @Lloyd-Pottiger PTAL.

@Lloyd-Pottiger
Copy link
Contributor

/run-all-tests

@sre-bot
Copy link
Collaborator

sre-bot commented Sep 15, 2022

Coverage for changed files

Filename                                                    Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Common/tests/gtest_magic_enum.cpp                                14                 0   100.00%           1                 0   100.00%          24                 0   100.00%           2                 0   100.00%
Storages/DeltaMerge/DeltaMergeStore.cpp                         925               160    82.70%          48                 2    95.83%        1378               233    83.09%         494               160    67.61%
Storages/DeltaMerge/DeltaMergeStore.h                            17                 3    82.35%          16                 3    81.25%          50                11    78.00%           0                 0         -
Storages/DeltaMerge/DeltaMergeStore_InternalBg.cpp              343               261    23.91%          13                 4    69.23%         483               262    45.76%         176               118    32.95%
Storages/DeltaMerge/DeltaMergeStore_InternalSegment.cpp         416               206    50.48%           4                 0   100.00%         335                81    75.82%         112                57    49.11%
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                          1715               630    63.27%          82                 9    89.02%        2270               587    74.14%         784               335    57.27%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18744      8126             56.65%    217087  83475        61.55%

full coverage report (for internal network access only)

Copy link
Contributor

@JaySon-Huang JaySon-Huang left a comment

Choose a reason for hiding this comment

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

LGTM

Thank you for your work!

@Lloyd-Pottiger
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

@Lloyd-Pottiger: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 21657a5

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Sep 15, 2022
@sre-bot
Copy link
Collaborator

sre-bot commented Sep 15, 2022

Coverage for changed files

Filename                                                    Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Common/tests/gtest_magic_enum.cpp                                14                 0   100.00%           1                 0   100.00%          24                 0   100.00%           2                 0   100.00%
Storages/DeltaMerge/DeltaMergeStore.cpp                         925               160    82.70%          48                 2    95.83%        1378               233    83.09%         494               157    68.22%
Storages/DeltaMerge/DeltaMergeStore.h                            17                 3    82.35%          16                 3    81.25%          50                11    78.00%           0                 0         -
Storages/DeltaMerge/DeltaMergeStore_InternalBg.cpp              343               261    23.91%          13                 4    69.23%         483               262    45.76%         176               118    32.95%
Storages/DeltaMerge/DeltaMergeStore_InternalSegment.cpp         416               206    50.48%           4                 0   100.00%         335                81    75.82%         112                57    49.11%
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                          1715               630    63.27%          82                 9    89.02%        2270               587    74.14%         784               332    57.65%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18750      8129             56.65%    217175  83488        61.56%

full coverage report (for internal network access only)

@ti-chi-bot ti-chi-bot merged commit f4e976b into pingcap:master Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants