Skip to content

Commit

Permalink
[fix](inverted index) Add missing memory usage calculation for BKD index
Browse files Browse the repository at this point in the history
  • Loading branch information
airborne12 committed Jan 22, 2025
1 parent 84c8f02 commit 2a15d39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
17 changes: 8 additions & 9 deletions be/src/olap/rowset/segment_v2/inverted_index_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,10 @@ Status InvertedIndexReader::handle_searcher_cache(
// TODO: handle null bitmap procedure in new format.
InvertedIndexQueryCacheHandle null_bitmap_cache_handle;
static_cast<void>(read_null_bitmap(io_ctx, stats, &null_bitmap_cache_handle, dir.get()));
RETURN_IF_ERROR(create_index_searcher(dir.release(), &searcher, mem_tracker.get(), type()));
auto* cache_value = new InvertedIndexSearcherCache::CacheValue(
std::move(searcher), mem_tracker->consumption(), UnixMillis());
size_t reader_size = 0;
RETURN_IF_ERROR(create_index_searcher(dir.release(), &searcher, type(), reader_size));
auto* cache_value = new InvertedIndexSearcherCache::CacheValue(std::move(searcher),
reader_size, UnixMillis());
InvertedIndexSearcherCache::instance()->insert(searcher_cache_key, cache_value,
inverted_index_cache_handle);
return Status::OK();
Expand All @@ -235,22 +236,20 @@ Status InvertedIndexReader::handle_searcher_cache(

Status InvertedIndexReader::create_index_searcher(lucene::store::Directory* dir,
IndexSearcherPtr* searcher,
MemTracker* mem_tracker,
InvertedIndexReaderType reader_type) {
SCOPED_CONSUME_MEM_TRACKER(mem_tracker);
InvertedIndexReaderType reader_type,
size_t& reader_size) {
auto index_searcher_builder =
DORIS_TRY(IndexSearcherBuilder::create_index_searcher_builder(reader_type));

auto searcher_result = DORIS_TRY(index_searcher_builder->get_index_searcher(dir));
*searcher = searcher_result;

// When the meta information has been read, the ioContext needs to be reset to prevent it from being used by other queries.
auto stream = static_cast<DorisCompoundReader*>(dir)->getDorisIndexInput();
auto* stream = static_cast<DorisCompoundReader*>(dir)->getDorisIndexInput();
stream->setIoContext(nullptr);
stream->setIndexFile(false);

// NOTE: before mem_tracker hook becomes active, we caculate reader memory size by hand.
mem_tracker->consume(index_searcher_builder->get_reader_size());
reader_size = index_searcher_builder->get_reader_size();
return Status::OK();
};

Expand Down
3 changes: 1 addition & 2 deletions be/src/olap/rowset/segment_v2/inverted_index_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ class InvertedIndexReader : public std::enable_shared_from_this<InvertedIndexRea
const io::IOContext* io_ctx, OlapReaderStatistics* stats);
std::string get_index_file_path();
static Status create_index_searcher(lucene::store::Directory* dir, IndexSearcherPtr* searcher,
MemTracker* mem_tracker,
InvertedIndexReaderType reader_type);
InvertedIndexReaderType reader_type, size_t& reader_size);

protected:
Status match_index_search(const io::IOContext* io_ctx, OlapReaderStatistics* stats,
Expand Down

0 comments on commit 2a15d39

Please sign in to comment.