Skip to content

Commit

Permalink
4
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukang-Lian committed May 16, 2024
1 parent 3fd9824 commit cdfb62e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
9 changes: 9 additions & 0 deletions be/src/olap/base_tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <fmt/format.h>
#include <rapidjson/prettywriter.h>

#include <memory>

#include "common/status.h"
#include "olap/calc_delete_bitmap_executor.h"
#include "olap/delete_bitmap_calculator.h"
Expand All @@ -29,6 +31,8 @@
#include "olap/rowset/beta_rowset.h"
#include "olap/rowset/rowset.h"
#include "olap/rowset/rowset_reader.h"
#include "olap/rowset/segment_v2/segment.h"
#include "olap/segment_loader.h"
#include "olap/tablet_fwd.h"
#include "olap/txn_manager.h"
#include "service/point_query_executor.h"
Expand Down Expand Up @@ -548,6 +552,11 @@ Status BaseTablet::lookup_row_key(const Slice& encoded_key, bool with_seq_col,

for (auto id : picked_segments) {
Status s = segments[id]->lookup_row_key(encoded_key, with_seq_col, with_rowid, &loc);
SegmentCache::CacheKey cache_key(rs->rowset_id(), segments[id]->id());
auto cache_value = std::make_unique<SegmentCache::CacheValue>();
cache_value->segment = segments[id];
SegmentLoader::instance()->update_segment(cache_key, *cache_value);
cache_value.release();
if (s.is<KEY_NOT_FOUND>()) {
continue;
}
Expand Down
18 changes: 6 additions & 12 deletions be/src/olap/rowset/segment_v2/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,14 @@ Status Segment::_parse_footer(SegmentFooterPB* footer) {
return Status::OK();
}

Status Segment::_load_pk_bloom_filter(bool is_segment_use_cache) {
Status Segment::_load_pk_bloom_filter() {
DCHECK(_tablet_schema->keys_type() == UNIQUE_KEYS);
DCHECK(_pk_index_meta != nullptr);
DCHECK(_pk_index_reader != nullptr);
auto status = [this, is_segment_use_cache]() {
return _load_pk_bf_once.call([this, is_segment_use_cache] {
auto status = [this]() {
return _load_pk_bf_once.call([this] {
RETURN_IF_ERROR(_pk_index_reader->parse_bf(_file_reader, *_pk_index_meta));
_meta_mem_usage += _pk_index_reader->get_bf_memory_size();
if (is_segment_use_cache) {
SegmentCache::CacheKey cache_key(_rowset_id, _segment_id);
SegmentCache::CacheValue cache_value;
cache_value.segment = shared_from_this();
SegmentLoader::instance()->update_segment(cache_key, cache_value);
}
return Status::OK();
});
}();
Expand All @@ -313,9 +307,9 @@ void Segment::remove_from_segment_cache() const {
SegmentLoader::instance()->erase_segment(cache_key);
}

Status Segment::load_pk_index_and_bf(bool is_segment_use_cache) {
Status Segment::load_pk_index_and_bf() {
RETURN_IF_ERROR(load_index());
RETURN_IF_ERROR(_load_pk_bloom_filter(is_segment_use_cache));
RETURN_IF_ERROR(_load_pk_bloom_filter());
return Status::OK();
}

Expand Down Expand Up @@ -667,7 +661,7 @@ Status Segment::new_inverted_index_iterator(const TabletColumn& tablet_column,

Status Segment::lookup_row_key(const Slice& key, bool with_seq_col, bool with_rowid,
RowLocation* row_location) {
RETURN_IF_ERROR(load_pk_index_and_bf(true));
RETURN_IF_ERROR(load_pk_index_and_bf());
bool has_seq_col = _tablet_schema->has_sequence_col();
bool has_rowid = !_tablet_schema->cluster_key_idxes().empty();
size_t seq_col_length = 0;
Expand Down
4 changes: 2 additions & 2 deletions be/src/olap/rowset/segment_v2/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Segment : public std::enable_shared_from_this<Segment> {

Status load_index();

Status load_pk_index_and_bf(bool is_segment_use_cache = false);
Status load_pk_index_and_bf();

std::string min_key() {
DCHECK(_tablet_schema->keys_type() == UNIQUE_KEYS && _pk_index_meta != nullptr);
Expand Down Expand Up @@ -194,7 +194,7 @@ class Segment : public std::enable_shared_from_this<Segment> {
Status _open();
Status _parse_footer(SegmentFooterPB* footer);
Status _create_column_readers(const SegmentFooterPB& footer);
Status _load_pk_bloom_filter(bool is_segment_use_cache);
Status _load_pk_bloom_filter();
ColumnReader* _get_column_reader(const TabletColumn& col);

// Get Iterator which will read variant root column and extract with paths and types info
Expand Down
3 changes: 2 additions & 1 deletion be/src/olap/segment_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ Status SegmentLoader::load_segments(const BetaRowsetSharedPtr& rowset,
RETURN_IF_ERROR(rowset->load_segment(i, &segment));
if (use_cache && !config::disable_segment_cache) {
// memory of SegmentCache::CacheValue will be handled by SegmentCache
auto* cache_value = new SegmentCache::CacheValue();
auto cache_value = std::make_unique<SegmentCache::CacheValue>();
cache_value->segment = std::move(segment);
_segment_cache->insert(cache_key, *cache_value, cache_handle);
cache_value.release();
} else {
cache_handle->push_segment(std::move(segment));
}
Expand Down

0 comments on commit cdfb62e

Please sign in to comment.