From 2872384b2f5d3f4d5150fbd2bde19f38bd95e73c Mon Sep 17 00:00:00 2001 From: Hannah Bast Date: Sat, 8 Jul 2023 12:45:10 +0200 Subject: [PATCH] Give each index a unique ID The ID is a string that can be obtained via the API with `cmd=get-index-id`. It is currently just a concatenation of the index name and several statistics on the number of triples (which is not perfect because an index that is different but has the same such statistics will get the same ID). This feature is useful for applications that are based on QLever and have an internal cache that depends on the index. When the index changes, the application should be able to notice this and with an index ID it can. For example, https://github.com/ad-freiburg/qlever-petrimaps . --- src/engine/Server.cpp | 4 ++++ src/index/Index.cpp | 3 +++ src/index/Index.h | 2 ++ src/index/IndexImpl.cpp | 8 ++++++++ src/index/IndexImpl.h | 3 +++ 5 files changed, 20 insertions(+) diff --git a/src/engine/Server.cpp b/src/engine/Server.cpp index d9d1547a38..dd7a606b59 100644 --- a/src/engine/Server.cpp +++ b/src/engine/Server.cpp @@ -314,6 +314,10 @@ Awaitable Server::process( } else if (auto cmd = checkParameter("cmd", "get-settings")) { logCommand(cmd, "get server settings"); response = createJsonResponse(RuntimeParameters().toMap(), request); + } else if (auto cmd = checkParameter("cmd", "get-index-id")) { + logCommand(cmd, "get index ID"); + response = createOkResponse(index_.getIndexId(), request, + ad_utility::MediaType::textPlain); } // Ping with or without messsage. diff --git a/src/index/Index.cpp b/src/index/Index.cpp index d5ef9071ed..92e59337d2 100644 --- a/src/index/Index.cpp +++ b/src/index/Index.cpp @@ -281,6 +281,9 @@ const std::string& Index::getTextName() const { return pimpl_->getTextName(); } // ____________________________________________________________________________ const std::string& Index::getKbName() const { return pimpl_->getKbName(); } +// ____________________________________________________________________________ +const std::string& Index::getIndexId() const { return pimpl_->getIndexId(); } + // ____________________________________________________________________________ Index::NumNormalAndInternal Index::numTriples() const { return pimpl_->numTriples(); diff --git a/src/index/Index.h b/src/index/Index.h index a25766112b..f9a009f5cf 100644 --- a/src/index/Index.h +++ b/src/index/Index.h @@ -239,6 +239,8 @@ class Index { const std::string& getKbName() const; + const std::string& getIndexId() const; + NumNormalAndInternal numTriples() const; size_t getNofTextRecords() const; diff --git a/src/index/IndexImpl.cpp b/src/index/IndexImpl.cpp index b04835c589..b6f68438e1 100644 --- a/src/index/IndexImpl.cpp +++ b/src/index/IndexImpl.cpp @@ -897,6 +897,14 @@ void IndexImpl::readConfiguration() { loadRequestedDataMember("num-subjects-normal", numSubjectsNormal_); loadRequestedDataMember("num-objects-normal", numObjectsNormal_); loadRequestedDataMember("num-triples-normal", numTriplesNormal_); + + // Compute unique ID for this index. + // + // TODO: This is a simplistic way. It would be better to incorporate bytes + // from the index files. + indexId_ = absl::StrCat("#", getKbName(), ".", numTriplesNormal_, ".", + numSubjectsNormal_, ".", numPredicatesNormal_, ".", + numObjectsNormal_); } // ___________________________________________________________________________ diff --git a/src/index/IndexImpl.h b/src/index/IndexImpl.h index fae83d376d..2280923a3c 100644 --- a/src/index/IndexImpl.h +++ b/src/index/IndexImpl.h @@ -146,6 +146,7 @@ class IndexImpl { size_t numPredicatesNormal_ = 0; size_t numObjectsNormal_ = 0; size_t numTriplesNormal_ = 0; + string indexId_; /** * @brief Maps pattern ids to sets of predicate ids. */ @@ -387,6 +388,8 @@ class IndexImpl { const string& getKbName() const { return pso_.metaData().getName(); } + const string& getIndexId() const { return indexId_; } + size_t getNofTextRecords() const { return textMeta_.getNofTextRecords(); } size_t getNofWordPostings() const { return textMeta_.getNofWordPostings(); } size_t getNofEntityPostings() const {