|
18 | 18 |
|
19 | 19 | #include <thread> |
20 | 20 |
|
| 21 | +<<<<<<< HEAD |
| 22 | +======= |
| 23 | +#include "base/testutil/assert.h" |
| 24 | +#include "base/testutil/id_generator.h" |
| 25 | +#include "base/testutil/sync_point.h" |
| 26 | +#include "base/utility/defer_op.h" |
| 27 | +>>>>>>> d70921f1e4 ([BugFix] FSE-v2 missed setting the schema for shared-data sorted schema change (#72235)) |
21 | 28 | #include "column/binary_column.h" |
22 | 29 | #include "column/datum_tuple.h" |
23 | 30 | #include "column/fixed_length_column.h" |
@@ -2765,4 +2772,128 @@ TEST_F(SchemaChangeBaseTabletReadSchemaTest, test_generated_column) { |
2765 | 2772 | ASSERT_EQ(3, row_count); |
2766 | 2773 | } |
2767 | 2774 |
|
| 2775 | +// Regression for the SortedSchemaChange path: DeltaWriter must not consult the schema |
| 2776 | +// service (which falls back to an FE RPC) because the schema-change task already holds |
| 2777 | +// the exact target schema. The fix passes the tablet schema directly into DeltaWriter, |
| 2778 | +// so the schema lookup -- and its FE RPC fallback -- is bypassed entirely. |
| 2779 | +TEST_F(SchemaChangeBaseTabletReadSchemaTest, test_sorted_schema_change_skips_schema_rpc) { |
| 2780 | + SyncPoint::GetInstance()->EnableProcessing(); |
| 2781 | + DeferOp restore([] { |
| 2782 | + SyncPoint::GetInstance()->ClearAllCallBacks(); |
| 2783 | + SyncPoint::GetInstance()->DisableProcessing(); |
| 2784 | + }); |
| 2785 | + |
| 2786 | + std::atomic_int rpc_invocations = 0; |
| 2787 | + SyncPoint::GetInstance()->SetCallBack( |
| 2788 | + "TableSchemaService::_fetch_schema_via_rpc::test_hook", |
| 2789 | + [&rpc_invocations](void* arg) { rpc_invocations.fetch_add(1, std::memory_order_relaxed); }); |
| 2790 | + |
| 2791 | + auto base_metadata = create_base_tablet_metadata(); |
| 2792 | + auto base_tablet_id = base_metadata->id(); |
| 2793 | + CHECK_OK(_tablet_manager->put_tablet_metadata(*base_metadata)); |
| 2794 | + |
| 2795 | + // Build an AGG_KEYS new tablet so SchemaChangeUtils::parse_request flips sc_sorting=true. |
| 2796 | + auto new_metadata = std::make_shared<TabletMetadata>(); |
| 2797 | + new_metadata->set_id(next_id()); |
| 2798 | + new_metadata->set_version(1); |
| 2799 | + auto new_schema = new_metadata->mutable_schema(); |
| 2800 | + new_schema->set_id(next_id()); |
| 2801 | + new_schema->set_num_short_key_columns(1); |
| 2802 | + new_schema->set_keys_type(AGG_KEYS); |
| 2803 | + new_schema->set_num_rows_per_row_block(65535); |
| 2804 | + { |
| 2805 | + auto c0 = new_schema->add_column(); |
| 2806 | + c0->set_unique_id(1); |
| 2807 | + c0->set_name("c0"); |
| 2808 | + c0->set_type("INT"); |
| 2809 | + c0->set_is_key(true); |
| 2810 | + c0->set_is_nullable(false); |
| 2811 | + } |
| 2812 | + { |
| 2813 | + auto c1 = new_schema->add_column(); |
| 2814 | + c1->set_unique_id(2); |
| 2815 | + c1->set_name("c1"); |
| 2816 | + c1->set_type("VARCHAR"); |
| 2817 | + c1->set_length(20); |
| 2818 | + c1->set_is_key(true); |
| 2819 | + c1->set_is_nullable(false); |
| 2820 | + } |
| 2821 | + { |
| 2822 | + auto c2_sum = new_schema->add_column(); |
| 2823 | + c2_sum->set_unique_id(9); |
| 2824 | + c2_sum->set_name("c2_sum"); |
| 2825 | + c2_sum->set_type("BIGINT"); |
| 2826 | + c2_sum->set_is_key(false); |
| 2827 | + c2_sum->set_is_nullable(true); |
| 2828 | + c2_sum->set_aggregation("SUM"); |
| 2829 | + } |
| 2830 | + CHECK_OK(_tablet_manager->put_tablet_metadata(*new_metadata)); |
| 2831 | + |
| 2832 | + int64_t version = 1; |
| 2833 | + int64_t txn_id = next_id(); |
| 2834 | + auto base_tablet_schema = TabletSchema::create(base_metadata->schema()); |
| 2835 | + auto base_schema = std::make_shared<VSchema>(ChunkHelper::convert_schema(base_tablet_schema)); |
| 2836 | + |
| 2837 | + auto col_c0 = Int32Column::create(); |
| 2838 | + auto col_c1 = BinaryColumn::create(); |
| 2839 | + auto col_c2 = Int32Column::create(); |
| 2840 | + auto col_c3 = Int32Column::create(); |
| 2841 | + auto col_c4 = Int32Column::create(); |
| 2842 | + col_c0->append_datum(Datum(1)); |
| 2843 | + col_c1->append_datum(Datum(Slice("row0"))); |
| 2844 | + col_c2->append_datum(Datum(100)); |
| 2845 | + col_c3->append_datum(Datum(1000)); |
| 2846 | + col_c4->append_datum(Datum(10)); |
| 2847 | + VChunk chunk0({std::move(col_c0), std::move(col_c1), std::move(col_c2), std::move(col_c3), std::move(col_c4)}, |
| 2848 | + base_schema); |
| 2849 | + uint32_t indexes[1] = {0}; |
| 2850 | + |
| 2851 | + ASSIGN_OR_ABORT(auto delta_writer, DeltaWriterBuilder() |
| 2852 | + .set_tablet_manager(_tablet_manager.get()) |
| 2853 | + .set_tablet_id(base_tablet_id) |
| 2854 | + .set_txn_id(txn_id) |
| 2855 | + .set_partition_id(_partition_id) |
| 2856 | + .set_mem_tracker(_mem_tracker.get()) |
| 2857 | + .set_schema_id(base_tablet_schema->id()) |
| 2858 | + .set_tablet_schema(base_tablet_schema) |
| 2859 | + .build()); |
| 2860 | + ASSERT_OK(delta_writer->open()); |
| 2861 | + ASSERT_OK(delta_writer->write(chunk0, indexes, sizeof(indexes) / sizeof(indexes[0]))); |
| 2862 | + ASSERT_OK(delta_writer->finish_with_txnlog()); |
| 2863 | + delta_writer->close(); |
| 2864 | + ASSERT_OK(TEST_publish_single_version(_tablet_manager.get(), base_tablet_id, version + 1, txn_id).status()); |
| 2865 | + version++; |
| 2866 | + |
| 2867 | + // Drop the BE schema cache so the only way DeltaWriter could resolve the new schema is |
| 2868 | + // an FE RPC. With the fix, the schema is preset and the lookup is skipped, so the hook |
| 2869 | + // above must observe zero invocations. |
| 2870 | + _tablet_manager->update_metacache_limit(0); |
| 2871 | + _tablet_manager->prune_metacache(); |
| 2872 | + |
| 2873 | + auto new_tablet_id = new_metadata->id(); |
| 2874 | + auto alter_txn_id = next_id(); |
| 2875 | + { |
| 2876 | + auto t_read_schema = create_base_tablet_read_schema(next_id()); |
| 2877 | + |
| 2878 | + TAlterTabletReqV2 request; |
| 2879 | + request.base_tablet_id = base_tablet_id; |
| 2880 | + request.new_tablet_id = new_tablet_id; |
| 2881 | + request.alter_version = version; |
| 2882 | + request.txn_id = alter_txn_id; |
| 2883 | + request.__set_base_tablet_read_schema(t_read_schema); |
| 2884 | + request.__set_base_table_column_names({"c0", "c1", "c6", "c2", "c4"}); |
| 2885 | + TAlterMaterializedViewParam mv_param; |
| 2886 | + mv_param.__set_column_name("c2_sum"); |
| 2887 | + mv_param.__set_origin_column_name("c2"); |
| 2888 | + request.__set_materialized_view_params({mv_param}); |
| 2889 | + |
| 2890 | + SchemaChangeHandler handler(_tablet_manager.get()); |
| 2891 | + ASSERT_OK(handler.process_alter_tablet(request)); |
| 2892 | + } |
| 2893 | + ASSERT_OK(publish_version_for_schema_change(new_tablet_id, version + 1, alter_txn_id)); |
| 2894 | + |
| 2895 | + EXPECT_EQ(0, rpc_invocations.load(std::memory_order_relaxed)) |
| 2896 | + << "SortedSchemaChange must not call the FE schema RPC when DeltaWriter is given a preset schema"; |
| 2897 | +} |
| 2898 | + |
2768 | 2899 | } // namespace starrocks::lake |
0 commit comments