Coverage Report

Created: 2026-10-27 18:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/transform/changelog_derive.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include "storage/rowset/rowset_fwd.h"
21
#include "storage/transform/block_transform.h"
22
23
namespace doris {
24
struct RowsetWriterContext;
25
26
namespace segment_v2 {
27
28
// The changelog derive stages rebuild the load block into a full-width block
29
// over the changelog schema -- key + AFTER values, optional BEFORE values, and
30
// the TSO / LSN / op columns -- so the ordinary segment writers can write
31
// it like any DUP_KEYS block. build_transform_chain picks Plain (no historical
32
// probe) or Mow (with probe) via changelog_needs_historical_lookup().
33
34
// Whether the flush needs the historical key probe: a direct partial update or
35
// a requested BEFORE image. Decided per flush.
36
bool changelog_needs_historical_lookup(const RowsetWriterContext& context);
37
38
// Context for each flush that the base stage works out once and passes to
39
// derive(): the changelog/source schemas, the consumed LSN range, row count, and
40
// column layout [keys..., AFTER..., (BEFORE...), TSO, LSN, OP].
41
struct ChangelogDeriveContext {
42
    TabletSchemaSPtr changelog_schema;
43
    TabletSchemaSPtr source_schema;
44
    ConstAllocatedLsnVectorSharedPtr lsn_ids;
45
    size_t num_rows = 0;
46
    uint32_t changelog_tso_cid = 0;
47
    uint32_t changelog_lsn_cid = 0;
48
    uint32_t changelog_op_cid = 0;
49
    uint32_t normal_col_start = 0;
50
    uint32_t before_col_start = 0;
51
    std::vector<uint32_t> normal_source_cids;
52
    std::vector<uint32_t> value_source_cids;
53
    bool write_before = false;
54
};
55
56
// Base for the derive stages: apply() runs the setup steps (schema layout + LSN
57
// hand-off), then calls derive().
58
class ChangelogDeriveStage : public BlockTransform {
59
public:
60
    Status apply(TransformExecContext& ctx, Block* block) const final;
61
62
protected:
63
    virtual Status derive(TransformExecContext& ctx, Block* block,
64
                          const ChangelogDeriveContext& c) const = 0;
65
};
66
67
// No probe: DUP loads and full-row upserts without a BEFORE image. AFTER is the
68
// source columns as-is; op is APPEND, or DELETE from the row's own delete sign.
69
class PlainChangelogDeriveStage : public ChangelogDeriveStage {
70
public:
71
7
    std::string_view name() const override { return "PlainChangelogDerive"; }
72
73
protected:
74
    Status derive(TransformExecContext& ctx, Block* block,
75
                  const ChangelogDeriveContext& c) const override;
76
};
77
78
// With a probe: fixed/flexible partial update (rebuild AFTER from history)
79
// and/or the BEFORE image. It repeats the data chain's key probe on the same
80
// source block, but never marks the delete bitmap.
81
class MowChangelogDeriveStage : public ChangelogDeriveStage {
82
public:
83
11
    std::string_view name() const override { return "MowChangelogDerive"; }
84
85
protected:
86
    Status derive(TransformExecContext& ctx, Block* block,
87
                  const ChangelogDeriveContext& c) const override;
88
};
89
90
} // namespace segment_v2
91
} // namespace doris