Skip to content

Commit

Permalink
Give each index a unique ID
Browse files Browse the repository at this point in the history
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 .
  • Loading branch information
Hannah Bast committed Jul 21, 2023
1 parent 0b74fa1 commit fc11809
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/engine/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ Awaitable<void> 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.
Expand Down
3 changes: 3 additions & 0 deletions src/index/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/index/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ class Index {

const std::string& getKbName() const;

const std::string& getIndexId() const;

NumNormalAndInternal numTriples() const;

size_t getNofTextRecords() const;
Expand Down
8 changes: 8 additions & 0 deletions src/index/IndexImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}

// ___________________________________________________________________________
Expand Down
3 changes: 3 additions & 0 deletions src/index/IndexImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit fc11809

Please sign in to comment.