Coverage Report

Created: 2026-06-04 13:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/rowset/pending_rowset_helper.cpp
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
#include "storage/rowset/pending_rowset_helper.h"
19
20
#include "storage/olap_common.h"
21
22
namespace doris {
23
24
451
PendingRowsetGuard::~PendingRowsetGuard() {
25
451
    if (_pending_rowset_set) {
26
140
        for (const auto& rowset_id : _rowset_ids) {
27
140
            _pending_rowset_set->remove(rowset_id);
28
140
        }
29
138
    }
30
451
}
31
32
PendingRowsetGuard::PendingRowsetGuard(const std::vector<RowsetId>& rowset_ids,
33
                                       PendingRowsetSet* set)
34
140
        : _rowset_ids(rowset_ids), _pending_rowset_set(set) {}
35
36
139
PendingRowsetGuard::PendingRowsetGuard(PendingRowsetGuard&& other) noexcept {
37
139
    CHECK(!_pending_rowset_set ||
38
0
          (_rowset_ids == other._rowset_ids && _pending_rowset_set == other._pending_rowset_set))
39
0
            << _rowset_ids.size() << ' ' << other._rowset_ids.size() << ' ' << _pending_rowset_set
40
0
            << ' ' << other._pending_rowset_set;
41
139
    _rowset_ids = other._rowset_ids;
42
139
    _pending_rowset_set = other._pending_rowset_set;
43
139
    other._pending_rowset_set = nullptr;
44
139
}
45
46
108
PendingRowsetGuard& PendingRowsetGuard::operator=(PendingRowsetGuard&& other) noexcept {
47
108
    CHECK(!_pending_rowset_set ||
48
0
          (_rowset_ids == other._rowset_ids && _pending_rowset_set == other._pending_rowset_set))
49
0
            << _rowset_ids.size() << ' ' << other._rowset_ids.size() << ' ' << _pending_rowset_set
50
0
            << ' ' << other._pending_rowset_set;
51
108
    _rowset_ids = other._rowset_ids;
52
108
    _pending_rowset_set = other._pending_rowset_set;
53
108
    other._pending_rowset_set = nullptr;
54
108
    return *this;
55
108
}
56
57
0
void PendingRowsetGuard::drop() {
58
0
    if (_pending_rowset_set) {
59
0
        for (const auto& rowset_id : _rowset_ids) {
60
0
            _pending_rowset_set->remove(rowset_id);
61
0
        }
62
0
    }
63
0
    _pending_rowset_set = nullptr;
64
0
    _rowset_ids = std::vector {RowsetId {}};
65
0
}
66
67
495
bool PendingRowsetSet::contains(const RowsetId& rowset_id) {
68
495
    std::lock_guard lock(_mtx);
69
495
    return _set.contains(rowset_id);
70
495
}
71
72
110
PendingRowsetGuard PendingRowsetSet::add(const RowsetId& rowset_id) {
73
110
    {
74
110
        std::lock_guard lock(_mtx);
75
110
        _set.insert(rowset_id);
76
110
    }
77
110
    return PendingRowsetGuard {std::vector<RowsetId> {rowset_id}, this};
78
110
}
79
80
30
PendingRowsetGuard PendingRowsetSet::add(const std::vector<RowsetId>& rowset_ids) {
81
30
    {
82
30
        std::lock_guard lock(_mtx);
83
32
        for (const auto& rowset_id : rowset_ids) {
84
32
            _set.insert(rowset_id);
85
32
        }
86
30
    }
87
30
    return PendingRowsetGuard {rowset_ids, this};
88
30
}
89
90
140
void PendingRowsetSet::remove(const RowsetId& rowset_id) {
91
140
    std::lock_guard lock(_mtx);
92
140
    _set.erase(rowset_id);
93
140
}
94
95
} // namespace doris