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

[BugFix] Fix the has_output check bug of scan operator (backport #42994) #43006

Merged
merged 8 commits into from
Mar 25, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Mar 22, 2024

Why I'm doing:

What we expect is that ScanOperator::pull_chunk can be executed only after ScanPrepareOperator::pull_chunk is executed finished and return success.

If ScanPrepareOperator::pull_chunk returns EOF, ScanOperator::pull_chunk should not be executed.

But when in function OlapScanPrepareOperator::pull_chunk, if _ctx->set_prepare_finished is executed finished and before _ctx->set_finished() is executed,

bool OlapScanOperator::has_output() const {
    if (!_ctx->is_prepare_finished() || _ctx->is_finished()) {
        return false;
    }

    return ScanOperator::has_output();
} 

will return true, causing OlapScanOperator::pull_chunk will be executed, causing some unexpected crashes.

There are dependencies between operators. The current scheduling does not consider this dependency, which is not a good design.

But the current fix does not change the implementation of this pipeline engine.

#7  0x0000000004712288 in starrocks::BinaryDictPageDecoder<(starrocks::FieldType)17>::next_batch (this=this@entry=0x7f97c0803f60, range=..., dst=dst@entry=0x7f97c08ed610) at /build/starrocks/be/src/storage/rowset/binary_dict_page.cpp:257
#8  0x00000000047125c8 in starrocks::BinaryDictPageDecoder<(starrocks::FieldType)17>::next_batch (this=0x7f97c0803f60, n=0x7f943db22210, dst=0x7f97c08ed610) at /build/starrocks/be/src/storage/rowset/binary_dict_page.cpp:219
#9  0x000000000472fd2b in starrocks::ParsedPageV2::read (this=0x7f97b22954c0, column=0x7f97c08ed610, count=0x7f943db22210) at /build/starrocks/be/src/storage/rowset/parsed_page.cpp:217
#10 0x0000000004702862 in operator() (count=0x7f943db22210, column=0x7f97c08ed610, __closure=<synthetic pointer>) at /build/starrocks/be/src/storage/rowset/scalar_column_iterator.cpp:495
#11 starrocks::ScalarColumnIterator::_fetch_by_rowid<starrocks::ScalarColumnIterator::fetch_values_by_rowid(const rowid_t*, size_t, starrocks::vectorized::Column*)::<lambda(starrocks::vectorized::Column*, size_t*)>&> (page_parse=<synthetic pointer>..., 
    values=0x7f97c08ed610, size=<optimized out>, rowids=<optimized out>, this=0x7f923b4ba300) at /build/starrocks/be/src/storage/rowset/scalar_column_iterator.cpp:482
#12 starrocks::ScalarColumnIterator::fetch_values_by_rowid (this=0x7f923b4ba300, rowids=<optimized out>, size=<optimized out>, values=0x7f97c08ed610) at /build/starrocks/be/src/storage/rowset/scalar_column_iterator.cpp:496
#13 0x00000000046b4492 in starrocks::ColumnIterator::fetch_values_by_rowid (this=0x7f923b4ba300, rowids=..., values=0x7f97c08ed610) at /build/starrocks/be/src/storage/rowset/column_iterator.cpp:45
#14 0x00000000042d5eff in starrocks::ColumnDecoder::decode_values_by_rowid (values=<optimized out>, rowids=..., this=<optimized out>) at /build/starrocks/be/src/storage/rowset/column_decoder.h:28
#15 starrocks::vectorized::SegmentIterator::_finish_late_materialization (this=0x7f92cfdfac10, ctx=0x7f92cfdfb060) at /build/starrocks/be/src/storage/rowset/segment_iterator.cpp:1435
#16 0x00000000042dedd0 in starrocks::vectorized::SegmentIterator::_do_get_next (this=0x7f92cfdfac10, result=0x7f8b213c8ef0, rowid=0x0) at /build/starrocks/be/src/storage/rowset/segment_iterator.cpp:932
#17 0x00000000042e18b0 in starrocks::vectorized::SegmentIterator::do_get_next (this=0x7f92cfdfac10, chunk=0x7f8b213c8ef0) at /build/starrocks/be/src/storage/rowset/segment_iterator.cpp:811
#18 0x00000000043661f2 in starrocks::vectorized::ChunkIterator::get_next (chunk=<optimized out>, this=<optimized out>) at /build/starrocks/be/src/storage/chunk_iterator.h:40
#19 starrocks::vectorized::ProjectionIterator::do_get_next (this=0x7f9354333810, chunk=0x7f8b213c9960) at /build/starrocks/be/src/storage/projection_iterator.cpp:69
#20 0x0000000004916db5 in starrocks::vectorized::ChunkIterator::get_next (chunk=<optimized out>, this=<optimized out>) at /build/starrocks/be/src/storage/chunk_iterator.h:40
#21 starrocks::SegmentIteratorWrapper::do_get_next (this=<optimized out>, chunk=<optimized out>) at /build/starrocks/be/src/storage/rowset/rowset.cpp:337
#22 0x00000000047461a3 in starrocks::vectorized::ChunkIterator::get_next (chunk=0x7f8b213c9960, this=0x7f9354333990) at /build/starrocks/be/src/storage/chunk_iterator.h:40
#23 starrocks::vectorized::TimedChunkIterator::do_get_next (this=0x7f9354345390, chunk=0x7f8b213c9960) at /build/starrocks/be/src/storage/chunk_iterator.cpp:37
#24 0x0000000004397656 in starrocks::vectorized::ChunkIterator::get_next (chunk=0x7f8b213c9960, this=<optimized out>) at /build/starrocks/be/src/storage/chunk_iterator.h:40
#25 starrocks::vectorized::TabletReader::do_get_next (this=0x7f7999190c10, chunk=0x7f8b213c9960) at /build/starrocks/be/src/storage/tablet_reader.cpp:219
#26 0x00000000030342fb in starrocks::vectorized::ChunkIterator::get_next (chunk=0x7f8b213c9960, this=<optimized out>) at /build/starrocks/be/src/storage/chunk_iterator.h:40
#27 starrocks::pipeline::OlapChunkSource::_read_chunk_from_storage (this=0x7f91121a3710, state=<optimized out>, chunk=0x7f8b213c9960) at /build/starrocks/be/src/exec/pipeline/scan/olap_chunk_source.cpp:332
#28 0x00000000030349db in starrocks::pipeline::OlapChunkSource::_read_chunk (this=0x7f91121a3710, state=<optimized out>, chunk=0x7f943db228c0) at /build/starrocks/be/src/exec/pipeline/scan/olap_chunk_source.cpp:293
#29 0x00000000030242af in starrocks::pipeline::ChunkSource::buffer_next_batch_chunks_blocking (this=0x7f91121a3710, state=0x7f91f81f0500, batch_size=batch_size@entry=64, running_wg=0x7f97df8b8d50) at /build/starrocks/be/src/exec/pipeline/scan/chunk_source.cpp:57
#30 0x0000000002d9e9a4 in operator() (__closure=0x7f92cfda96c0) at /build/starrocks/be/src/exec/pipeline/scan/scan_operator.cpp:374
#31 0x0000000002dafdce in std::function<void ()>::operator()() const (this=0x7f943db22cf0) at /opt/gcc/usr/include/c++/10.3.0/bits/std_function.h:622
#32 starrocks::workgroup::ScanExecutor::worker_thread (this=0x7f97df7c5220) at /build/starrocks/be/src/exec/workgroup/scan_executor.cpp:58
#33 0x0000000004b17352 in std::function<void ()>::operator()() const (this=0x7f94b2871e98) at /opt/gcc/usr/include/c++/10.3.0/bits/std_function.h:622
#34 starrocks::FunctionRunnable::run (this=0x7f94b2871e90) at /build/starrocks/be/src/util/threadpool.cpp:44
#35 starrocks::ThreadPool::dispatch_thread (this=0x7f97df8b90c0) at /build/starrocks/be/src/util/threadpool.cpp:539
#36 0x0000000004b11e4a in std::function<void ()>::operator()() const (this=0x7f94b287b418) at /opt/gcc/usr/include/c++/10.3.0/bits/std_function.h:622
#37 starrocks::Thread::supervise_thread (arg=0x7f94b287b400) at /build/starrocks/be/src/util/thread.cpp:351
#38 0x00007f97e346e17a in start_thread () from /home/disk6/lxh/core/lib64/[libpthread-2.28.so](http://libpthread-2.28.so/)
#39 0x00007f97e2a0fdf3 in clone () from /home/disk6/lxh/core/lib64/[libc-2.28.so](http://libc-2.28.so/)

What I'm doing:

If prepare return eof, we will first set_finished and then set_prepare_finished.

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.2
    • 3.1
    • 3.0
    • 2.5

This is an automatic backport of pull request #42994 done by [Mergify](https://mergify.com). ## Why I'm doing:

What we expect is that ScanOperator::pull_chunk can be executed only after ScanPrepareOperator::pull_chunk is executed finished and return success.

If ScanPrepareOperator::pull_chunk returns EOF, ScanOperator::pull_chunk should not be executed.

But when in function OlapScanPrepareOperator::pull_chunk, if _ctx->set_prepare_finished is executed finished and before _ctx->set_finished() is executed,

bool OlapScanOperator::has_output() const {
    if (!_ctx->is_prepare_finished() || _ctx->is_finished()) {
        return false;
    }

    return ScanOperator::has_output();
} 

will return true, causing OlapScanOperator::pull_chunk will be executed, causing some unexpected crashes.

There are dependencies between operators. The current scheduling does not consider this dependency, which is not a good design.

But the current fix does not change the implementation of this pipeline engine.

#7  0x0000000004712288 in starrocks::BinaryDictPageDecoder<(starrocks::FieldType)17>::next_batch (this=this@entry=0x7f97c0803f60, range=..., dst=dst@entry=0x7f97c08ed610) at /build/starrocks/be/src/storage/rowset/binary_dict_page.cpp:257
#8  0x00000000047125c8 in starrocks::BinaryDictPageDecoder<(starrocks::FieldType)17>::next_batch (this=0x7f97c0803f60, n=0x7f943db22210, dst=0x7f97c08ed610) at /build/starrocks/be/src/storage/rowset/binary_dict_page.cpp:219
#9  0x000000000472fd2b in starrocks::ParsedPageV2::read (this=0x7f97b22954c0, column=0x7f97c08ed610, count=0x7f943db22210) at /build/starrocks/be/src/storage/rowset/parsed_page.cpp:217
#10 0x0000000004702862 in operator() (count=0x7f943db22210, column=0x7f97c08ed610, __closure=<synthetic pointer>) at /build/starrocks/be/src/storage/rowset/scalar_column_iterator.cpp:495
#11 starrocks::ScalarColumnIterator::_fetch_by_rowid<starrocks::ScalarColumnIterator::fetch_values_by_rowid(const rowid_t*, size_t, starrocks::vectorized::Column*)::<lambda(starrocks::vectorized::Column*, size_t*)>&> (page_parse=<synthetic pointer>..., 
    values=0x7f97c08ed610, size=<optimized out>, rowids=<optimized out>, this=0x7f923b4ba300) at /build/starrocks/be/src/storage/rowset/scalar_column_iterator.cpp:482
#12 starrocks::ScalarColumnIterator::fetch_values_by_rowid (this=0x7f923b4ba300, rowids=<optimized out>, size=<optimized out>, values=0x7f97c08ed610) at /build/starrocks/be/src/storage/rowset/scalar_column_iterator.cpp:496
#13 0x00000000046b4492 in starrocks::ColumnIterator::fetch_values_by_rowid (this=0x7f923b4ba300, rowids=..., values=0x7f97c08ed610) at /build/starrocks/be/src/storage/rowset/column_iterator.cpp:45
#14 0x00000000042d5eff in starrocks::ColumnDecoder::decode_values_by_rowid (values=<optimized out>, rowids=..., this=<optimized out>) at /build/starrocks/be/src/storage/rowset/column_decoder.h:28
#15 starrocks::vectorized::SegmentIterator::_finish_late_materialization (this=0x7f92cfdfac10, ctx=0x7f92cfdfb060) at /build/starrocks/be/src/storage/rowset/segment_iterator.cpp:1435
#16 0x00000000042dedd0 in starrocks::vectorized::SegmentIterator::_do_get_next (this=0x7f92cfdfac10, result=0x7f8b213c8ef0, rowid=0x0) at /build/starrocks/be/src/storage/rowset/segment_iterator.cpp:932
#17 0x00000000042e18b0 in starrocks::vectorized::SegmentIterator::do_get_next (this=0x7f92cfdfac10, chunk=0x7f8b213c8ef0) at /build/starrocks/be/src/storage/rowset/segment_iterator.cpp:811
#18 0x00000000043661f2 in starrocks::vectorized::ChunkIterator::get_next (chunk=<optimized out>, this=<optimized out>) at /build/starrocks/be/src/storage/chunk_iterator.h:40
#19 starrocks::vectorized::ProjectionIterator::do_get_next (this=0x7f9354333810, chunk=0x7f8b213c9960) at /build/starrocks/be/src/storage/projection_iterator.cpp:69
#20 0x0000000004916db5 in starrocks::vectorized::ChunkIterator::get_next (chunk=<optimized out>, this=<optimized out>) at /build/starrocks/be/src/storage/chunk_iterator.h:40
#21 starrocks::SegmentIteratorWrapper::do_get_next (this=<optimized out>, chunk=<optimized out>) at /build/starrocks/be/src/storage/rowset/rowset.cpp:337
#22 0x00000000047461a3 in starrocks::vectorized::ChunkIterator::get_next (chunk=0x7f8b213c9960, this=0x7f9354333990) at /build/starrocks/be/src/storage/chunk_iterator.h:40
#23 starrocks::vectorized::TimedChunkIterator::do_get_next (this=0x7f9354345390, chunk=0x7f8b213c9960) at /build/starrocks/be/src/storage/chunk_iterator.cpp:37
#24 0x0000000004397656 in starrocks::vectorized::ChunkIterator::get_next (chunk=0x7f8b213c9960, this=<optimized out>) at /build/starrocks/be/src/storage/chunk_iterator.h:40
#25 starrocks::vectorized::TabletReader::do_get_next (this=0x7f7999190c10, chunk=0x7f8b213c9960) at /build/starrocks/be/src/storage/tablet_reader.cpp:219
#26 0x00000000030342fb in starrocks::vectorized::ChunkIterator::get_next (chunk=0x7f8b213c9960, this=<optimized out>) at /build/starrocks/be/src/storage/chunk_iterator.h:40
#27 starrocks::pipeline::OlapChunkSource::_read_chunk_from_storage (this=0x7f91121a3710, state=<optimized out>, chunk=0x7f8b213c9960) at /build/starrocks/be/src/exec/pipeline/scan/olap_chunk_source.cpp:332
#28 0x00000000030349db in starrocks::pipeline::OlapChunkSource::_read_chunk (this=0x7f91121a3710, state=<optimized out>, chunk=0x7f943db228c0) at /build/starrocks/be/src/exec/pipeline/scan/olap_chunk_source.cpp:293
#29 0x00000000030242af in starrocks::pipeline::ChunkSource::buffer_next_batch_chunks_blocking (this=0x7f91121a3710, state=0x7f91f81f0500, batch_size=batch_size@entry=64, running_wg=0x7f97df8b8d50) at /build/starrocks/be/src/exec/pipeline/scan/chunk_source.cpp:57
#30 0x0000000002d9e9a4 in operator() (__closure=0x7f92cfda96c0) at /build/starrocks/be/src/exec/pipeline/scan/scan_operator.cpp:374
#31 0x0000000002dafdce in std::function<void ()>::operator()() const (this=0x7f943db22cf0) at /opt/gcc/usr/include/c++/10.3.0/bits/std_function.h:622
#32 starrocks::workgroup::ScanExecutor::worker_thread (this=0x7f97df7c5220) at /build/starrocks/be/src/exec/workgroup/scan_executor.cpp:58
#33 0x0000000004b17352 in std::function<void ()>::operator()() const (this=0x7f94b2871e98) at /opt/gcc/usr/include/c++/10.3.0/bits/std_function.h:622
#34 starrocks::FunctionRunnable::run (this=0x7f94b2871e90) at /build/starrocks/be/src/util/threadpool.cpp:44
#35 starrocks::ThreadPool::dispatch_thread (this=0x7f97df8b90c0) at /build/starrocks/be/src/util/threadpool.cpp:539
#36 0x0000000004b11e4a in std::function<void ()>::operator()() const (this=0x7f94b287b418) at /opt/gcc/usr/include/c++/10.3.0/bits/std_function.h:622
#37 starrocks::Thread::supervise_thread (arg=0x7f94b287b400) at /build/starrocks/be/src/util/thread.cpp:351
#38 0x00007f97e346e17a in start_thread () from /home/disk6/lxh/core/lib64/[libpthread-2.28.so](http://libpthread-2.28.so/)
#39 0x00007f97e2a0fdf3 in clone () from /home/disk6/lxh/core/lib64/[libc-2.28.so](http://libc-2.28.so/)

What I'm doing:

If prepare return eof, we will first set_finished and then set_prepare_finished.

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

Signed-off-by: trueeyu <[email protected]>
(cherry picked from commit d9d9c70)

# Conflicts:
#	be/src/exec/pipeline/scan/olap_scan_prepare_operator.cpp
#	be/src/testutil/sync_point.h
#	be/test/CMakeLists.txt
@mergify mergify bot added the conflicts label Mar 22, 2024
Copy link
Contributor Author

mergify bot commented Mar 22, 2024

Cherry-pick of d9d9c70 has failed:

On branch mergify/bp/branch-2.5/pr-42994
Your branch is up to date with 'origin/branch-2.5'.

You are currently cherry-picking commit d9d9c70453.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   be/src/exec/pipeline/scan/olap_scan_context.cpp
	modified:   be/src/exec/pipeline/scan/scan_operator.cpp
	new file:   be/test/exec/pipeline/olap_scan_operator_test.cpp

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	both modified:   be/src/exec/pipeline/scan/olap_scan_prepare_operator.cpp
	deleted by us:   be/src/testutil/sync_point.h
	both modified:   be/test/CMakeLists.txt

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

Copy link
Contributor Author

mergify bot commented Mar 22, 2024

@mergify[bot]: Backport conflict, please reslove the conflict and resubmit the pr

auto-merge was automatically disabled March 22, 2024 12:36

Pull request was closed

@mergify mergify bot deleted the mergify/bp/branch-2.5/pr-42994 branch March 22, 2024 12:37
@trueeyu trueeyu restored the mergify/bp/branch-2.5/pr-42994 branch March 25, 2024 04:37
@trueeyu trueeyu reopened this Mar 25, 2024
@wanpengfei-git wanpengfei-git enabled auto-merge (squash) March 25, 2024 04:38
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
@wanpengfei-git wanpengfei-git merged commit d7cca4f into branch-2.5 Mar 25, 2024
23 checks passed
@wanpengfei-git wanpengfei-git deleted the mergify/bp/branch-2.5/pr-42994 branch March 25, 2024 06:59
trueeyu added a commit to trueeyu/starrocks that referenced this pull request Mar 26, 2024
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.

2 participants