Loading src/index.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ namespace authdb { RecordIndex::RecordIndex() : _revision(0), _valid(false) {} void RecordIndex::build(AuthBackend &backend) { std::unique_lock<std::shared_mutex> lock(_mutex); _nameIndex.clear(); _offsetIndex.clear(); Loading Loading @@ -95,6 +96,7 @@ namespace authdb { } void RecordIndex::addEntry(const uuid::uuid &uid, int type, const char *name, size_t offset) { std::unique_lock<std::shared_mutex> lock(_mutex); UuidTypeKey utk{uid, type}; _offsetIndex[utk] = offset; Loading @@ -105,6 +107,7 @@ namespace authdb { } void RecordIndex::removeEntry(const uuid::uuid &uid, int type) { std::unique_lock<std::shared_mutex> lock(_mutex); UuidTypeKey utk{uid, type}; _offsetIndex.erase(utk); Loading @@ -117,6 +120,7 @@ namespace authdb { } bool RecordIndex::findByName(int type, const char * /*fieldname*/, const std::string &name, uuid::uuid &out_uid) const { std::shared_lock<std::shared_mutex> lock(_mutex); NameKey nk{type, name}; auto it = _nameIndex.find(nk); if (it != _nameIndex.end()) { Loading @@ -127,6 +131,7 @@ namespace authdb { } bool RecordIndex::findByUuid(int type, const uuid::uuid &uid) const { std::shared_lock<std::shared_mutex> lock(_mutex); UuidTypeKey utk; utk.uid = uid; utk.type = type; Loading @@ -134,6 +139,7 @@ namespace authdb { } size_t RecordIndex::findOffset(const uuid::uuid &uid, int type) const { std::shared_lock<std::shared_mutex> lock(_mutex); UuidTypeKey utk; utk.uid = uid; utk.type = type; Loading @@ -144,6 +150,7 @@ namespace authdb { } void RecordIndex::listByType(int type, std::vector<uuid::uuid> &out) const { std::shared_lock<std::shared_mutex> lock(_mutex); for (auto &[key, offset] : _offsetIndex) { if (key.type == type) out.emplace_back(key.uid); Loading @@ -151,13 +158,20 @@ namespace authdb { } void RecordIndex::invalidate() { std::unique_lock<std::shared_mutex> lock(_mutex); _valid = false; } bool RecordIndex::valid() const { std::shared_lock<std::shared_mutex> lock(_mutex); return _valid; } size_t RecordIndex::revision() const { std::shared_lock<std::shared_mutex> lock(_mutex); return _revision; } RecordIndex &getIndex(const std::string &path) { std::lock_guard<std::mutex> guard(g_indexMapMutex); auto &ptr = g_indexMap[path]; Loading src/index.h +2 −1 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ namespace authdb { void invalidate(); bool valid() const; size_t revision() const { return _revision; } size_t revision() const; private: struct NameKey { Loading Loading @@ -100,6 +100,7 @@ namespace authdb { } }; mutable std::shared_mutex _mutex; std::unordered_map<NameKey, uuid::uuid, NameKeyHash> _nameIndex; std::unordered_map<UuidTypeKey, size_t, UuidTypeKeyHash> _offsetIndex; size_t _revision; Loading Loading
src/index.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ namespace authdb { RecordIndex::RecordIndex() : _revision(0), _valid(false) {} void RecordIndex::build(AuthBackend &backend) { std::unique_lock<std::shared_mutex> lock(_mutex); _nameIndex.clear(); _offsetIndex.clear(); Loading Loading @@ -95,6 +96,7 @@ namespace authdb { } void RecordIndex::addEntry(const uuid::uuid &uid, int type, const char *name, size_t offset) { std::unique_lock<std::shared_mutex> lock(_mutex); UuidTypeKey utk{uid, type}; _offsetIndex[utk] = offset; Loading @@ -105,6 +107,7 @@ namespace authdb { } void RecordIndex::removeEntry(const uuid::uuid &uid, int type) { std::unique_lock<std::shared_mutex> lock(_mutex); UuidTypeKey utk{uid, type}; _offsetIndex.erase(utk); Loading @@ -117,6 +120,7 @@ namespace authdb { } bool RecordIndex::findByName(int type, const char * /*fieldname*/, const std::string &name, uuid::uuid &out_uid) const { std::shared_lock<std::shared_mutex> lock(_mutex); NameKey nk{type, name}; auto it = _nameIndex.find(nk); if (it != _nameIndex.end()) { Loading @@ -127,6 +131,7 @@ namespace authdb { } bool RecordIndex::findByUuid(int type, const uuid::uuid &uid) const { std::shared_lock<std::shared_mutex> lock(_mutex); UuidTypeKey utk; utk.uid = uid; utk.type = type; Loading @@ -134,6 +139,7 @@ namespace authdb { } size_t RecordIndex::findOffset(const uuid::uuid &uid, int type) const { std::shared_lock<std::shared_mutex> lock(_mutex); UuidTypeKey utk; utk.uid = uid; utk.type = type; Loading @@ -144,6 +150,7 @@ namespace authdb { } void RecordIndex::listByType(int type, std::vector<uuid::uuid> &out) const { std::shared_lock<std::shared_mutex> lock(_mutex); for (auto &[key, offset] : _offsetIndex) { if (key.type == type) out.emplace_back(key.uid); Loading @@ -151,13 +158,20 @@ namespace authdb { } void RecordIndex::invalidate() { std::unique_lock<std::shared_mutex> lock(_mutex); _valid = false; } bool RecordIndex::valid() const { std::shared_lock<std::shared_mutex> lock(_mutex); return _valid; } size_t RecordIndex::revision() const { std::shared_lock<std::shared_mutex> lock(_mutex); return _revision; } RecordIndex &getIndex(const std::string &path) { std::lock_guard<std::mutex> guard(g_indexMapMutex); auto &ptr = g_indexMap[path]; Loading
src/index.h +2 −1 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ namespace authdb { void invalidate(); bool valid() const; size_t revision() const { return _revision; } size_t revision() const; private: struct NameKey { Loading Loading @@ -100,6 +100,7 @@ namespace authdb { } }; mutable std::shared_mutex _mutex; std::unordered_map<NameKey, uuid::uuid, NameKeyHash> _nameIndex; std::unordered_map<UuidTypeKey, size_t, UuidTypeKeyHash> _offsetIndex; size_t _revision; Loading