Commit 6bf3afab authored by jan.koester's avatar jan.koester
Browse files

test

parent 16706d07
Loading
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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();

@@ -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;

@@ -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);

@@ -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()) {
@@ -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;
@@ -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;
@@ -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);
@@ -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];
+2 −1
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ namespace authdb {
        void invalidate();
        bool valid() const;

        size_t revision() const { return _revision; }
        size_t revision() const;

    private:
        struct NameKey {
@@ -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;