Repository: tikv/tikv
File: components/tidb_query_executors/src/index_lookup_executor.rs (Rust)

Code before:
        assert_eq!(task.storage, MockStorage(region, expected_ranges.clone()));
        assert_eq!(task.key_ranges, expected_ranges);
        assert_eq!(iter.cursor_in_handle_orders, 5);
        assert!(iter.left_rows.is_empty());

        // leader found, in this case, the region start exceeds the point range
        // end of 14 but still before point range start of 15:
        // |------- region --------|
        //               |key(15)----- point_range_end(15)|
        // We need to get one range with [key(15), region_end)
        iter.accessor.assert_no_exceptions();
        let region = make_region(
            3,
            encode_cmp_key_and_push(14, 0u8),
            encode_cmp_key_and_push(15, 0u8),
        );
        iter.accessor
            .expect_find_region(encode_cmp_key(15), region.clone(), StateRole::Leader);
        iter.accessor.expect_get_local_region_storage(true);
        let task = block_on(iter.next_task()).unwrap();
        let mut expected_range = make_scan_key_range(15, 16);
        // The end key of the range should be the region end because the point range end
        // of handle 15 exceeds the region.
        expected_range.set_end(
            Key::from_encoded(region.get_end_key().to_vec())
                .into_raw()
                .unwrap(),
        );
        let expected_ranges = vec![expected_range];
        assert_eq!(task.storage, MockStorage(region, expected_ranges.clone()));
        assert_eq!(task.key_ranges, expected_ranges.clone());
        assert_eq!(iter.cursor_in_handle_orders, 6);
        assert!(iter.left_rows.is_empty());

        // region found, but not leader
        iter.accessor.assert_no_exceptions();
        let region = make_region(4, encode_cmp_key(17), encode_cmp_key(52));
        iter.accessor
            .expect_find_region(encode_cmp_key(19), region.clone(), StateRole::Follower);
        assert!(block_on(iter.next_task()).is_none());
        assert_eq!(iter.cursor_in_handle_orders, 8);
        // left rows should be filled with the left physical row indexes
        assert!(iter.left_rows[0].is_none());
        let left_rows = iter.left_rows[1].as_ref().unwrap();
        assert_eq!(left_rows.len(), 2);
        assert!(left_rows.contains(&9));
        assert!(left_rows.contains(&2));

        // region not found
        iter.accessor.assert_no_exceptions();
        iter.accessor

Review comment (suggestion):
Inconsistency in method usage: the production code uses `to_raw()` (which borrows) while the test code uses `into_raw()` (which takes ownership). For consistency and to avoid unnecessary cloning in tests, consider using `to_raw()` consistently throughout, or `into_raw()` if ownership transfer is intentional.
```suggestion
                .to_raw()
```

Code after:
        assert_eq!(task.storage, MockStorage(region, expected_ranges.clone()));
        assert_eq!(task.key_ranges, expected_ranges);
        assert_eq!(iter.cursor_in_handle_orders, 5);
        assert!(iter.left_rows.is_empty());

        // leader found, in this case, the region start exceeds the point range
        // end of 14 but still before point range start of 15:
        // |------- region --------|
        //               |key(15)----- point_range_end(15)|
        // We need to get one range with [key(15), region_end)
        iter.accessor.assert_no_exceptions();
        let region = make_region(
            3,
            encode_cmp_key_and_push(14, 0u8),
            encode_cmp_key_and_push(15, 0u8),
        );
        iter.accessor
            .expect_find_region(encode_cmp_key(15), region.clone(), StateRole::Leader);
        iter.accessor.expect_get_local_region_storage(true);
        let task = block_on(iter.next_task()).unwrap();
        let mut expected_range = make_scan_key_range(15, 16);
        // The end key of the range should be the region end because the point range end
        // of handle 15 exceeds the region.
        expected_range.set_end(
            Key::from_encoded(region.get_end_key().to_vec())
                .to_raw()
                .unwrap(),
        );
        let expected_ranges = vec![expected_range];
        assert_eq!(task.storage, MockStorage(region, expected_ranges.clone()));
        assert_eq!(task.key_ranges, expected_ranges.clone());
        assert_eq!(iter.cursor_in_handle_orders, 6);
        assert!(iter.left_rows.is_empty());

        // region found, but not leader
        iter.accessor.assert_no_exceptions();
        let region = make_region(4, encode_cmp_key(17), encode_cmp_key(52));
        iter.accessor
            .expect_find_region(encode_cmp_key(19), region.clone(), StateRole::Follower);
        assert!(block_on(iter.next_task()).is_none());
        assert_eq!(iter.cursor_in_handle_orders, 8);
        // left rows should be filled with the left physical row indexes
        assert!(iter.left_rows[0].is_none());
        let left_rows = iter.left_rows[1].as_ref().unwrap();
        assert_eq!(left_rows.len(), 2);
        assert!(left_rows.contains(&9));
        assert!(left_rows.contains(&2));

        // region not found
        iter.accessor.assert_no_exceptions();
        iter.accessor