Skip to content

Commit 60f0f2e

Browse files
committed
[fix](be) Fall back when row-store read-ahead is disabled
### What problem does this PR solve? Issue Number: apache#67611 Related PR: apache#67292 Problem Summary: A point request can pass the read-ahead enable check and then observe either mutable feature switch disabled while loading its segment. The row-store helper asserted that the factory still returned a read-ahead object, aborting the BE. Reuse the already loaded segment and the original synchronous column iterator when the factory returns no object. A deterministic test closes each switch between segment loading and factory creation, reproduces SIGABRT before the fix, and verifies identical row-store bytes after the fix. ### Release note Prevent BE aborts when query read-ahead or asynchronous File Cache writes are disabled during row-store point queries. ### Check List (For Author) - Test: ASAN/PCH BE unit test PointQueryReadAheadTest.RowStoreFallsBackWhenReadAheadSwitchChanges passed; the same test reproduced SIGABRT before the fix. Build hygiene and clang-format 16 passed. - Behavior changed: Yes; a runtime switch change falls back to the original reader. - Does this need documentation: No; preserve the existing dynamic switch contract.
1 parent 47d9e5e commit 60f0f2e

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

‎be/src/storage/tablet/base_tablet.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,16 @@ Status _read_row_store_with_read_ahead(
172172
RETURN_IF_ERROR(segment_v2::SegmentReadAhead::create_for_query(
173173
segment->file_reader(), ExecEnv::GetInstance(), read_ahead_context, read_options,
174174
&read_ahead));
175-
DORIS_CHECK(read_ahead != nullptr);
176175

177176
std::vector<segment_v2::rowid_t> rowids {static_cast<segment_v2::rowid_t>(row_location.row_id)};
178177
std::unique_ptr<segment_v2::ColumnIterator> column_iterator;
178+
// A switch can close after the point request creates its context. The factory then returns
179+
// no read-ahead object; reuse the loaded segment with the original synchronous reader.
180+
if (read_ahead == nullptr) {
181+
RETURN_IF_ERROR(_init_segment_column_iterator(rowset, segment, column, &column_iterator,
182+
stats, io_ctx));
183+
return column_iterator->read_by_rowids(rowids.data(), rowids.size(), result);
184+
}
179185
return segment_v2::read_column_by_rowids_with_read_ahead(
180186
*segment, column, rowids, result, read_options, column_iterator, *read_ahead);
181187
}

‎be/test/service/point_query_exector_test.cpp‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,84 @@
2121
#include <gen_cpp/internal_service.pb.h>
2222
#include <gtest/gtest.h>
2323

24+
#include "cloud/config.h"
2425
#include "common/object_pool.h"
2526
#include "core/block/block.h"
27+
#include "cpp/sync_point.h"
2628
#include "exprs/vexpr.h"
2729
#include "runtime/descriptor_helper.h"
2830
#include "runtime/descriptors.h"
2931
#include "runtime/exec_env.h"
3032
#include "runtime/runtime_state.h"
3133
#include "service/point_query_executor.h"
34+
#include "storage/mow/mow_transform_test_base.h"
35+
#include "storage/segment/segment_read_ahead.h"
3236
#include "storage/tablet/tablet_schema.h"
37+
#include "util/defer_op.h"
3338

3439
namespace doris {
3540

41+
class PointQueryReadAheadTest : public MowTransformTestBase {};
42+
43+
TEST_F(PointQueryReadAheadTest, RowStoreFallsBackWhenReadAheadSwitchChanges) {
44+
auto schema = create_row_store_schema();
45+
TabletSharedPtr tablet;
46+
auto rowset = write_rowset(schema, 5101, 2, {{1, 11}, {2, 22}}, &tablet);
47+
ASSERT_NE(rowset, nullptr);
48+
const RowLocation location {rowset->rowset_id(), 0, 1};
49+
const std::string key = "key";
50+
OlapReaderStatistics expected_stats;
51+
std::string expected;
52+
ASSERT_TRUE(
53+
tablet->lookup_row_data(Slice(key), location, rowset, expected_stats, expected).ok());
54+
55+
const auto old_cloud_unique_id = config::cloud_unique_id;
56+
const bool old_read_ahead = config::enable_query_read_ahead;
57+
const bool old_async_write = config::enable_async_file_cache_write;
58+
auto* sync_point = SyncPoint::get_instance();
59+
Defer restore {[&] {
60+
sync_point->disable_processing();
61+
config::cloud_unique_id = old_cloud_unique_id;
62+
config::enable_query_read_ahead = old_read_ahead;
63+
config::enable_async_file_cache_write = old_async_write;
64+
}};
65+
config::cloud_unique_id = "PointQueryReadAheadTest";
66+
67+
for (int switch_index = 0; switch_index < 2; ++switch_index) {
68+
SCOPED_TRACE(switch_index);
69+
config::enable_query_read_ahead = true;
70+
config::enable_async_file_cache_write = true;
71+
ASSERT_TRUE(segment_v2::SegmentReadAhead::enabled());
72+
auto context = std::make_shared<io::FileRangeReadContext>(1024 * 1024);
73+
74+
// The request has passed enabled(). Close a switch after segment loading, immediately
75+
// before the row-store helper calls create_for_query() and observes the new value.
76+
bool switched = false;
77+
SyncPoint::CallbackGuard guard;
78+
sync_point->set_call_back(
79+
"BaseTablet::_load_segment",
80+
[&](auto&&) {
81+
switched = true;
82+
if (switch_index == 0) {
83+
config::enable_query_read_ahead = false;
84+
} else {
85+
config::enable_async_file_cache_write = false;
86+
}
87+
},
88+
&guard);
89+
sync_point->enable_processing();
90+
OlapReaderStatistics stats;
91+
std::string actual;
92+
const auto status = tablet->lookup_row_data_with_read_ahead(
93+
Slice(key), location, rowset, stats, actual, false, nullptr, context);
94+
sync_point->disable_processing();
95+
ASSERT_TRUE(status.ok()) << status;
96+
EXPECT_TRUE(switched);
97+
EXPECT_EQ(actual, expected);
98+
EXPECT_EQ(context->resident_bytes(), 0);
99+
}
100+
}
101+
36102
// Helper class for setting up Reusable objects to test LookupConnectionCache
37103
class ReusableTestHelper {
38104
public:

0 commit comments

Comments
 (0)