Coverage Report

Created: 2024-11-20 12:56

/root/doris/be/src/olap/rowset/rowset.cpp
Line
Count
Source (jump to first uncovered line)
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 "olap/rowset/rowset.h"
19
20
#include <gen_cpp/olap_file.pb.h>
21
22
#include "io/cache/file_cache_manager.h"
23
#include "olap/olap_define.h"
24
#include "olap/segment_loader.h"
25
#include "olap/tablet_schema.h"
26
#include "util/time.h"
27
28
namespace doris {
29
30
Rowset::Rowset(const TabletSchemaSPtr& schema, const std::string& tablet_path,
31
               const RowsetMetaSharedPtr& rowset_meta)
32
44.8k
        : _tablet_path(tablet_path), _rowset_meta(rowset_meta), _refs_by_reader(0) {
33
44.8k
    _is_pending = true;
34
35
    // Generally speaking, as long as a rowset has a version, it can be considered not to be in a pending state.
36
    // However, if the rowset was created through ingesting binlogs, it will have a version but should still be
37
    // considered in a pending state because the ingesting txn has not yet been committed.
38
44.8k
    if (_rowset_meta->has_version() && _rowset_meta->start_version() > 0 &&
39
44.8k
        _rowset_meta->rowset_state() != COMMITTED) {
40
456
        _is_pending = false;
41
456
    }
42
43
44.8k
    if (_is_pending) {
44
44.4k
        _is_cumulative = false;
45
44.4k
    } else {
46
456
        Version version = _rowset_meta->version();
47
456
        _is_cumulative = version.first != version.second;
48
456
    }
49
    // build schema from RowsetMeta.tablet_schema or Tablet.tablet_schema
50
44.8k
    _schema = _rowset_meta->tablet_schema() ? _rowset_meta->tablet_schema() : schema;
51
44.8k
}
52
53
532
Status Rowset::load(bool use_cache) {
54
    // if the state is ROWSET_UNLOADING it means close() is called
55
    // and the rowset is already loaded, and the resource is not closed yet.
56
532
    if (_rowset_state_machine.rowset_state() == ROWSET_LOADED) {
57
136
        return Status::OK();
58
136
    }
59
396
    {
60
        // before lock, if rowset state is ROWSET_UNLOADING, maybe it is doing do_close in release
61
396
        std::lock_guard load_lock(_lock);
62
        // after lock, if rowset state is ROWSET_UNLOADING, it is ok to return
63
396
        if (_rowset_state_machine.rowset_state() == ROWSET_UNLOADED) {
64
            // first do load, then change the state
65
396
            RETURN_IF_ERROR(do_load(use_cache));
66
396
            RETURN_IF_ERROR(_rowset_state_machine.on_load());
67
396
        }
68
396
    }
69
    // load is done
70
396
    VLOG_CRITICAL << "rowset is loaded. " << rowset_id()
71
0
                  << ", rowset version:" << rowset_meta()->version()
72
0
                  << ", state from ROWSET_UNLOADED to ROWSET_LOADED. tabletid:"
73
0
                  << _rowset_meta->tablet_id();
74
396
    return Status::OK();
75
396
}
76
77
8
void Rowset::make_visible(Version version) {
78
8
    _is_pending = false;
79
8
    _rowset_meta->set_version(version);
80
8
    _rowset_meta->set_rowset_state(VISIBLE);
81
    // update create time to the visible time,
82
    // it's used to skip recently published version during compaction
83
8
    _rowset_meta->set_creation_time(UnixSeconds());
84
85
8
    if (_rowset_meta->has_delete_predicate()) {
86
0
        _rowset_meta->mutable_delete_predicate()->set_version(version.first);
87
0
    }
88
8
}
89
90
0
bool Rowset::check_rowset_segment() {
91
0
    std::lock_guard load_lock(_lock);
92
0
    return check_current_rowset_segment();
93
0
}
94
95
0
void Rowset::merge_rowset_meta(const RowsetMetaSharedPtr& other) {
96
0
    _rowset_meta->set_num_segments(num_segments() + other->num_segments());
97
0
    _rowset_meta->set_num_rows(num_rows() + other->num_rows());
98
0
    _rowset_meta->set_data_disk_size(data_disk_size() + other->data_disk_size());
99
0
    _rowset_meta->set_index_disk_size(index_disk_size() + other->index_disk_size());
100
0
    std::vector<KeyBoundsPB> key_bounds;
101
0
    other->get_segments_key_bounds(&key_bounds);
102
0
    for (auto key_bound : key_bounds) {
103
0
        _rowset_meta->add_segment_key_bounds(key_bound);
104
0
    }
105
0
}
106
107
} // namespace doris