Skip to content

Commit

Permalink
[Pick 2.0](inverted index) fix inverted index compound reader memory …
Browse files Browse the repository at this point in the history
…leak (#36384)

## Proposed changes

Issue Number: close #xxx

Pick from #36146
  • Loading branch information
airborne12 authored Jun 18, 2024
1 parent c43a20f commit f4dbf83
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
25 changes: 19 additions & 6 deletions be/src/olap/rowset/segment_v2/inverted_index_compound_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ DorisCompoundReader::DorisCompoundReader(lucene::store::Directory* d, const char
dir(d),
ram_dir(new lucene::store::RAMDirectory()),
file_name(name),
stream(nullptr),
entries(_CLNEW EntriesType(true, true)) {
bool success = false;
try {
Expand Down Expand Up @@ -209,6 +208,13 @@ void DorisCompoundReader::copyFile(const char* file, int64_t file_length, uint8_
}

DorisCompoundReader::~DorisCompoundReader() {
if (!_closed) {
try {
close();
} catch (CLuceneError& err) {
LOG(ERROR) << "DorisCompoundReader finalize error:" << err.what();
}
}
_CLDELETE(entries)
}

Expand Down Expand Up @@ -292,14 +298,21 @@ bool DorisCompoundReader::openInput(const char* name, lucene::store::IndexInput*
void DorisCompoundReader::close() {
std::lock_guard<std::mutex> wlock(_this_lock);
if (stream != nullptr) {
entries->clear();
stream->close();
_CLDELETE(stream)
}
ram_dir->close();
dir->close();
_CLDECDELETE(dir)
_CLDELETE(ram_dir)
if (entries != nullptr) {
entries->clear();
}
if (ram_dir) {
ram_dir->close();
_CLDELETE(ram_dir)
}
if (dir) {
dir->close();
_CLDECDELETE(dir)
}
_closed = true;
}

bool DorisCompoundReader::doDeleteFile(const char* /*name*/) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@

class CLuceneError;

namespace lucene {
namespace store {
namespace lucene::store {
class RAMDirectory;
} // namespace store
} // namespace lucene
} // namespace lucene::store

namespace doris {

Expand Down Expand Up @@ -66,6 +64,7 @@ class CLUCENE_EXPORT DorisCompoundReader : public lucene::store::Directory {
EntriesType* entries;

std::mutex _this_lock;
bool _closed = false;

protected:
/** Removes an existing file in the directory-> */
Expand Down

0 comments on commit f4dbf83

Please sign in to comment.