Skip to content

Conversation

@airborne12
Copy link
Member

@airborne12 airborne12 commented Jun 19, 2025

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #51393

Problem Summary:
This PR ensures that copying an empty inverted index segment no longer throws an exception.

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@hello-stephen
Copy link
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@airborne12
Copy link
Member Author

run buildall

@airborne12 airborne12 changed the title [fix](inverted index) fix null index writing problem [fix](inverted index) fix error when writing empty index file Jun 19, 2025
@airborne12 airborne12 requested a review from Copilot June 19, 2025 13:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that copying an empty inverted index segment no longer throws an exception and adds a unit test to cover this scenario.

  • Gracefully skip empty index files (CL_ERR_EmptyIndexSegment) in InvertedIndexFileWriter::copyFile
  • Introduce CopyFileEmptyFileTest to verify empty-file behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
be/src/olap/rowset/segment_v2/inverted_index_file_writer.cpp Added a check for CL_ERR_EmptyIndexSegment to log a warning and return instead of throwing
be/test/olap/rowset/segment_v2/inverted_index_file_writer_test.cpp Added CopyFileEmptyFileTest to ensure copyFile handles empty files without error
Comments suppressed due to low confidence (2)

be/test/olap/rowset/segment_v2/inverted_index_file_writer_test.cpp:1569

  • After invoking copyFile, add an assertion to verify that the output stream remains empty or has a length of zero, to confirm the empty-file case is handled correctly.
    EXPECT_NO_THROW({ writer.copyFile("_0.frq", mock_dir.get(), output, buffer, sizeof(buffer)); });

be/src/olap/rowset/segment_v2/inverted_index_file_writer.cpp:269

  • [nitpick] Add a brief comment explaining that empty index segments are intentionally skipped here to prevent throwing when no data is present.
        if (err.number() == CL_ERR_EmptyIndexSegment) {

});
if (!open) {
if (err.number() == CL_ERR_EmptyIndexSegment) {
LOG(WARNING) << "InvertedIndexFileWriter::copyFile: " << fileName << " is empty";
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider including the full file path or segment identifiers in the log message for better traceability when debugging.

Suggested change
LOG(WARNING) << "InvertedIndexFileWriter::copyFile: " << fileName << " is empty";
LOG(WARNING) << "InvertedIndexFileWriter::copyFile: " << dir->getFullPath(fileName) << " is empty";

Copilot uses AI. Check for mistakes.
Copy link
Member

@eldenmoon eldenmoon left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Jun 19, 2025
@github-actions
Copy link
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (4/4) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 61.36% (16129/26285)
Line Coverage 50.91% (151835/298257)
Region Coverage 48.32% (86962/179976)
Branch Coverage 41.70% (42638/102256)

Copy link
Contributor

@csun5285 csun5285 left a comment

Choose a reason for hiding this comment

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

add test for v1, v2

CREATE TABLE `test` (
  `k` int NOT NULL,
  `v` string,
  INDEX idx_v_a (v) USING INVERTED PROPERTIES("parser" = "english")
) ENGINE=OLAP
UNIQUE KEY(`k`)
DISTRIBUTED BY HASH(`k`) BUCKETS 1
PROPERTIES (
    "replication_num" = "1"
);

insert into test values (427009, '');

Copy link
Contributor

@zzzxl1993 zzzxl1993 left a comment

Choose a reason for hiding this comment

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

LGTM

@airborne12 airborne12 merged commit f7e1d7c into apache:master Jun 20, 2025
33 of 37 checks passed
@airborne12 airborne12 deleted the fix-empty-index branch June 20, 2025 03:04
zhiqiang-hhhh pushed a commit to zhiqiang-hhhh/doris that referenced this pull request Jul 2, 2025
…#51984)

Related PR: apache#51393

Problem Summary:
This PR ensures that copying an empty inverted index segment no longer
throws an exception.
zhiqiang-hhhh pushed a commit to zhiqiang-hhhh/doris that referenced this pull request Jul 2, 2025
…#51984)

Related PR: apache#51393

Problem Summary:
This PR ensures that copying an empty inverted index segment no longer
throws an exception.
morrySnow pushed a commit that referenced this pull request Jul 3, 2025
…file #51984 (#52690)

cherry pick from #51984

---------

Co-authored-by: airborne12 <jiangkai@selectdb.com>
airborne12 added a commit to airborne12/apache-doris that referenced this pull request Jul 7, 2025
…#51984)

Related PR: apache#51393

Problem Summary:
This PR ensures that copying an empty inverted index segment no longer
throws an exception.
dataroaring pushed a commit that referenced this pull request Jul 7, 2025
etah000 pushed a commit to etah000/doris that referenced this pull request Jul 7, 2025
…file apache#51984 (apache#52690)

cherry pick from apache#51984

---------

Co-authored-by: airborne12 <jiangkai@selectdb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. dev/3.0.7-merged dev/3.1.0-merged reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants