Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature](term info) add ram used function for term info reader #216

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core/CLucene/index/IndexReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ CL_NS_DEF(index)
_CLTHROWA(CL_ERR_UnsupportedOperation, "This reader does not support this method.");
}

int64_t IndexReader::getTermInfosRAMUsed() const {
_CLTHROWA(CL_ERR_UnsupportedOperation, "This reader does not support this method.");
}

bool IndexReader::isCurrent() {
_CLTHROWA(CL_ERR_UnsupportedOperation, "This reader does not support this method.");
}
Expand Down
1 change: 1 addition & 0 deletions src/core/CLucene/index/IndexReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ class CLUCENE_EXPORT IndexReader: public CL_NS(util)::NamedObject{
* current indexDivisor.
* @see #setTermInfosIndexDivisor */
int32_t getTermInfosIndexDivisor();
virtual int64_t getTermInfosRAMUsed() const;

/**
* Check whether this IndexReader is still using the
Expand Down
26 changes: 19 additions & 7 deletions src/core/CLucene/index/TermInfosReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,23 @@ void TermInfosReader::close() {
}
#endif
}
numBytesUsed -= (sizeof(Term) * indexTermsLength + sizeof(TermInfo) * indexTermsLength + sizeof(int64_t) * indexTermsLength);
//Delete the arrays
if (indexTerms) {
if (indexTerms != nullptr) {
for (int32_t i = 0; i < indexTermsLength; ++i) {
numBytesUsed -= indexTerms[i].textLength();
}
delete[] indexTerms;
indexTerms = NULL;
}
if (indexInfos) {
if (indexInfos != nullptr) {
numBytesUsed -= sizeof(TermInfo) * indexTermsLength;
_CLDELETE_ARRAY(indexInfos);
indexInfos = NULL;
}

//Delete the arrays
if (indexPointers) {
if (indexPointers != NULL) {
numBytesUsed -= sizeof(int64_t) * indexTermsLength;
_CLDELETE_ARRAY(indexPointers);
indexPointers = NULL;
}
Expand Down Expand Up @@ -324,9 +329,6 @@ void TermInfosReader::ensureIndexIsRead() {
SCOPED_LOCK_MUTEX(THIS_LOCK)

if (indexIsRead) return;

//https://jira.qianxin-inc.cn/browse/XHBUG-2921
//https://jira.qianxin-inc.cn/browse/XHBUG-3053
if (indexEnum == NULL) _CLTHROWA(CL_ERR_NullPointer, "indexEnum is NULL");

try {
Expand Down Expand Up @@ -360,6 +362,16 @@ void TermInfosReader::ensureIndexIsRead() {
if (!indexEnum->next()) break;
}
indexIsRead = true;
numBytesUsed = sizeof(Term) * indexTermsLength + sizeof(TermInfo) * indexTermsLength + sizeof(int64_t) * indexTermsLength;
for (int32_t i = 0; i < indexTermsLength; ++i) {
numBytesUsed += indexTerms[i].textLength();
}
if (indexInfos != NULL) {
numBytesUsed += sizeof(TermInfo) * indexTermsLength;
}
if (indexPointers != NULL) {
numBytesUsed += sizeof(int64_t) * indexTermsLength;
}
}
_CLFINALLY(indexEnum->close();
//Close and delete the IndexInput is. The close is done by the destructor.
Expand Down
8 changes: 8 additions & 0 deletions src/core/CLucene/index/_MultiSegmentReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ class MultiSegmentReader:public DirectoryIndexReader{
const char* getObjectName() const;

IndexVersion getIndexVersion() override;

int64_t getTermInfosRAMUsed() const override {
int64_t size = 0;
for (size_t i = 0; i < subReaders->length; i++) {
size += (*subReaders)[i]->getTermInfosRAMUsed();
}
return size;
}
};


Expand Down
4 changes: 4 additions & 0 deletions src/core/CLucene/index/_SegmentHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ class SegmentReader: public DirectoryIndexReader {

void initialize(SegmentInfo* si, int32_t readBufferSize, bool doOpenStores, bool doingReopen);

int64_t getTermInfosRAMUsed() const override {
return tis->getRAMUsed();
}

/**
* Create a clone from the initial TermVectorsReader and store it in the ThreadLocal.
* @return TermVectorsReader
Expand Down
10 changes: 8 additions & 2 deletions src/core/CLucene/index/_TermInfosReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ CL_NS_DEF(index)
int32_t indexDivisor;
int32_t totalIndexInterval;

DEFINE_MUTEX(THIS_LOCK)
int64_t numBytesUsed;

DEFINE_MUTEX(THIS_LOCK)

public:
/**
Expand Down Expand Up @@ -102,7 +104,11 @@ CL_NS_DEF(index)

/** Returns the TermInfo for a Term in the set, or null. */
TermInfo* get(const Term* term);
private:

int64_t getRAMUsed() const {
return numBytesUsed;
}
private:
/** Reads the term info index file or .tti file. */
void ensureIndexIsRead();

Expand Down
Loading