Coverage Report

Created: 2026-05-14 18:41

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
450
PendingRowsetGuard::~PendingRowsetGuard() {
25
450
    if (_pending_rowset_set) {
26
137
        for (const auto& rowset_id : _rowset_ids) {
27
137
            _pending_rowset_set->remove(rowset_id);
28
137
        }
29
136
    }
30
450
}
31
32
PendingRowsetGuard::PendingRowsetGuard(const std::vector<RowsetId>& rowset_ids,
33
                                       PendingRowsetSet* set)
34
138
        : _rowset_ids(rowset_ids), _pending_rowset_set(set) {}
35
36
136
PendingRowsetGuard::PendingRowsetGuard(PendingRowsetGuard&& other) noexcept {
37
136
    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
136
    _rowset_ids = other._rowset_ids;
42
136
    _pending_rowset_set = other._pending_rowset_set;
43
136
    other._pending_rowset_set = nullptr;
44
136
}
45
46
107
PendingRowsetGuard& PendingRowsetGuard::operator=(PendingRowsetGuard&& other) noexcept {
47
107
    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
107
    _rowset_ids = other._rowset_ids;
52
107
    _pending_rowset_set = other._pending_rowset_set;
53
107
    other._pending_rowset_set = nullptr;
54
107
    return *this;
55
107
}
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
109
PendingRowsetGuard PendingRowsetSet::add(const RowsetId& rowset_id) {
73
109
    {
74
109
        std::lock_guard lock(_mtx);
75
109
        _set.insert(rowset_id);
76
109
    }
77
109
    return PendingRowsetGuard {std::vector<RowsetId> {rowset_id}, this};
78
109
}
79
80
29
PendingRowsetGuard PendingRowsetSet::add(const std::vector<RowsetId>& rowset_ids) {
81
29
    {
82
29
        std::lock_guard lock(_mtx);
83
30
        for (const auto& rowset_id : rowset_ids) {
84
30
            _set.insert(rowset_id);
85
30
        }
86
29
    }
87
29
    return PendingRowsetGuard {rowset_ids, this};
88
29
}
89
90
137
void PendingRowsetSet::remove(const RowsetId& rowset_id) {
91
137
    std::lock_guard lock(_mtx);
92
137
    _set.erase(rowset_id);
93
137
}
94
95
} // namespace doris