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

[Tool] Add DumpOrdinalIndex and VerifyPageChecksum meta tool. #51489

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wuxueyang96
Copy link
Contributor

@wuxueyang96 wuxueyang96 commented Sep 27, 2024

Why I'm doing:

What I'm doing:

Add two tools to verify a segment's ordinal index is correct. It can be used like below:

meta_tool.sh --operation=dump_ordinal_index --file=<segment file> --column_index=<index id>
meta_tool.sh --operation=verify_page_checksum --file=<segment file> --page_offset=<offset> --page_size=<size>

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

std::cout << "no page offset or page size flag for verify page checksum" << std::endl;
return -1;
}
verify_page_checksum(FLAGS_file, {FLAGS_page_offset, FLAGS_page_size});
} else if (FLAGS_operation == "show_segment_footer") {
if (FLAGS_file == "") {
std::cout << "no file flag for show dict" << std::endl;
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
Undefined PagePointer in verify_page_checksum.
You can modify the code like this:

// Add this line at the top with other includes
#include "runtime/memory/page_pointer.h"

// Ensure that your verify_page_checksum and meta_tool_main functions are as follows
void verify_page_checksum(const std::string& file_name, const starrocks::PagePointer& page_pointer) {
    auto res = starrocks::FileSystem::Default()->new_random_access_file(file_name);
    if (!res.ok()) {
        std::cout << "open file failed: " << res.status() << std::endl;
        return;
    }
    auto input_file = std::move(res).value();

    const uint32_t page_size = page_pointer.size;
    std::unique_ptr<char[]> page(new char[page_size + starrocks::Column::APPEND_OVERFLOW_MAX_SIZE]);
    Slice page_slice(page.get(), page_size);

    input_file->read_at_fully(page_pointer.offset, page_slice.data, page_slice.size);

    uint32_t expect = starrocks::decode_fixed32_le((uint8_t*)page_slice.data + page_slice.size - 4);
    uint32_t actual = starrocks::crc32c::Value(page_slice.data, page_slice.size - 4);
    if (expect != actual) {
        std::cout << "Bad page: checksum mismatch (actual=" << actual << " vs expect=" << expect << ")";
        return;
    }
}

int meta_tool_main(int argc, char** argv) {
    // Add the below flags check before entering each condition
    if (FLAGS_operation == "dump_ordinal_index") {
        if (FLAGS_file == "") {
            std::cout << "no file flag for dump ordinal index" << std::endl;
            return -1;
        }
        if (FLAGS_column_index == -1) {
            std::cout << "no column_index flag for dump ordinal index" << std::endl;
            return -1;
        }
        dump_ordinal_index(FLAGS_file, FLAGS_column_index);
    } else if (FLAGS_operation == "verify_page_checksum") {
        if (FLAGS_file == "") {
            std::cout << "no file flag for verify page checksum" << std::endl;
            return -1;
        }
        if (FLAGS_page_offset == -1 || FLAGS_page_size == -1) {
            std::cout << "no page offset or page size flag for verify page checksum" << std::endl;
            return -1;
        }
        verify_page_checksum(FLAGS_file, {FLAGS_page_offset, FLAGS_page_size});
    } 
    // ...rest of the function
}

@wuxueyang96 wuxueyang96 changed the title Add DumpOrdinalIndex and VerifyPageChecksum meta tool [Tool] Add DumpOrdinalIndex and VerifyPageChecksum meta tool. Oct 8, 2024
Signed-off-by: 枢木 <[email protected]>
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[BE Incremental Coverage Report]

fail : 0 / 71 (00.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/tools/meta_tool.cpp 0 71 00.00% [551, 552, 553, 554, 557, 559, 560, 561, 563, 564, 565, 566, 570, 571, 572, 573, 574, 575, 578, 580, 581, 582, 583, 585, 586, 587, 588, 589, 590, 591, 593, 594, 595, 596, 599, 600, 601, 602, 603, 604, 605, 606, 609, 610, 614, 615, 616, 617, 620, 621, 622, 623, 624, 625, 628, 629, 631, 632, 634, 1145, 1146, 1147, 1150, 1151, 1154, 1155, 1156, 1157, 1160, 1161, 1164]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants