Skip to content

Conversation

@Lloyd-Pottiger
Copy link
Contributor

@Lloyd-Pottiger Lloyd-Pottiger commented Aug 12, 2025

What problem does this PR solve?

Issue Number: close #10340

Problem Summary:

When there are multiple NULL rows of Strings-like column or vector-like column, TiFlash may save some "empty blocks" into the DMFile. And it happen to be the "empty blocks" are stored at the end of the DMFile.

When TiFlash try to read data from disk, DMFileReader::readFromDisk will first call FramedChecksumReadBuffer::doSeek and seek to the "empty block" at the file end. The working_buffer will be release because we read to the end of the file. When TiFlash try to seek to the next "empty block", pos move forward the released working_buffer, leading to reading random data and cause random failure.

type_on_disk->deserializeBinaryBulkWithMultipleStreams( //
*mutable_col,
[&](const IDataType::SubstreamPath & substream_path) {
const auto substream_name = DMFile::getFileNameBase(cd.id, substream_path);
auto & sub_stream = column_streams.at(substream_name);
sub_stream->buf->seek(
sub_stream->getOffsetInFile(start_pack_id),
sub_stream->getOffsetInDecompressedBlock(start_pack_id));
return sub_stream->buf.get();
},
read_rows,
top_stream->avg_size_hint,
true,
{});

if (target_frame == current_frame)
{
pos = working_buffer.begin() + target_offset;
return offset;
}

What is changed and how it works?

1. In `FramedChecksumReadBuffer::doSeek`, add guard check for `working_buffer` size and `target_offset`. If the working_buffer is cleared, then re-seek the working buffer according to the offset and load data from the underlying file again.
2. In order to support the behavior above, `S3RandomAccessFile::seekImpl` support seek backward, which is implemented by reopening the file again
3. Add retry when reading from S3 meet errno=115, EINPROGRESS

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

Fix possible read fail when column data contains lots of "NULL" values.

Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 12, 2025
@Lloyd-Pottiger
Copy link
Contributor Author

/check-issue-triage-complete

@Lloyd-Pottiger
Copy link
Contributor Author

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 12, 2025
Comment on lines 170 to 178
if (offset_ < cur_offset)
{
cur_offset = offset_;
if (!initialize())
{
return S3StreamError;
}
return cur_offset;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to seek backward?

Copy link
Member

Choose a reason for hiding this comment

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

// If we have already seek to EOF, then working_buffer was cleared
    if (target_frame == current_frame && working_buffer.size() > 0)
    {
        if (unlikely(target_offset > working_buffer.size()))
            pos = working_buffer.end();
        else
            pos = working_buffer.begin() + target_offset;
        return offset;
    }

If the same target frame is seeked again it is seeked in backward.

BTW it would be great if we could figure out some ways to avoid seeking backward.

Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
@Lloyd-Pottiger
Copy link
Contributor Author

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 13, 2025
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.

highlight what is changed

Comment on lines 87 to 90
if (unlikely(target_offset > working_buffer.size()))
pos = working_buffer.end();
else
pos = working_buffer.begin() + target_offset;
Copy link
Contributor

Choose a reason for hiding this comment

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

The main change in here is to change

        pos = working_buffer.begin() + target_offset;

to

        if (unlikely(target_offset > working_buffer.size()))
            pos = working_buffer.end();
        else
            pos = working_buffer.begin() + target_offset;

Comment on lines +40 to +48
// If we have already seek to EOF, then working_buffer was cleared
if (target_frame == current_frame && working_buffer.size() > 0)
{
if (unlikely(target_offset > working_buffer.size()))
pos = working_buffer.end();
else
pos = working_buffer.begin() + target_offset;
return offset;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The change in here is change

    if (target_frame == current_frame)
    {
        pos = working_buffer.begin() + target_offset;
        return offset;
    }

to

    // If we have already seek to EOF, then working_buffer was cleared
    if (target_frame == current_frame && working_buffer.size() > 0)
    {
        if (unlikely(target_offset > working_buffer.size()))
            pos = working_buffer.end();
        else
            pos = working_buffer.begin() + target_offset;
        return offset;
    }

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

@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

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Aug 19, 2025
@Lloyd-Pottiger
Copy link
Contributor Author

/retest

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Aug 20, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JaySon-Huang, JinheLin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [JaySon-Huang,JinheLin]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 20, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Aug 20, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-08-19 16:05:39.472356602 +0000 UTC m=+369547.415532117: ☑️ agreed by JaySon-Huang.
  • 2025-08-20 03:54:43.773329433 +0000 UTC m=+412091.716504949: ☑️ agreed by JinheLin.

@ti-chi-bot ti-chi-bot bot merged commit 28e47db into pingcap:master Aug 20, 2025
7 checks passed
@Lloyd-Pottiger Lloyd-Pottiger deleted the pick-bugfix branch August 20, 2025 05:18
@ti-chi-bot ti-chi-bot bot added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Aug 20, 2025
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #10354.

@ti-chi-bot ti-chi-bot bot added the needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. label Aug 20, 2025
ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request Aug 20, 2025
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #10355.
But this PR has conflicts, please resolve them!

ti-chi-bot bot pushed a commit that referenced this pull request Aug 20, 2025
close #10340

1. In `FramedChecksumReadBuffer::doSeek`, add guard check for `working_buffer` size and `target_offset`. If the working_buffer is cleared, then re-seek the working buffer according to the offset and load data from the underlying file again.
2. In order to support the behavior above, `S3RandomAccessFile::seekImpl` support seek backward, which is implemented by reopening the file again
3. Add retry when reading from S3 meet errno=115, EINPROGRESS

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

Co-authored-by: JaySon <tshent@qq.com>
Co-authored-by: JaySon-Huang <tshent@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Checksum seek at end cause read failed

5 participants