[go: up one dir, main page]

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

Add DumpOrdinalIndex and VerifyPageChecksum meta tool #51489

Open
wants to merge 1 commit 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
}

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]

pass : 0 / 0 (0%)

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

Successfully merging this pull request may close these issues.

1 participant