Commit b4f11186 authored by jan.koester's avatar jan.koester
Browse files

test

parent 48e591ab
Loading
Loading
Loading
Loading
Loading
+1 −1
Changes for src/admin.cpp: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -621,7 +621,7 @@ namespace authdb {
                // probes every node — unreachable nodes cause long waits.
                decltype(pclient->get_cluster_status()) health;
                try {
                    std::unique_lock<std::mutex> lock(g_Cluster->getClientMutex(), std::try_to_lock);
                    std::unique_lock<std::timed_mutex> lock(g_Cluster->getClientMutex(), std::try_to_lock);
                    if (!lock.owns_lock()) {
                        json_object_object_add(jobj, "status", json_object_new_string("BUSY"));
                        json_object_object_add(jobj, "nodes_total", json_object_new_int(0));
+10 −1
Changes for src/backend.cpp: 10 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

#include <chrono>

#include "backends/file.h"
#include "backends/cluster.h"

@@ -67,8 +69,14 @@ void authdb::AuthBackend::write(const unsigned char* dest, size_t destsize){
}

void authdb::AuthBackend::lock(){
    _Lock.lock();
    if (!_Lock.try_lock_for(std::chrono::seconds(5)))
        throw AuthBackendError("backend lock timeout");
    try {
        _Api->lock();
    } catch (...) {
        _Lock.unlock();
        throw;
    }
}

void authdb::AuthBackend::unlock(){
@@ -105,6 +113,7 @@ authdb::AuthBackendLock::AuthBackendLock(AuthBackend &lock) : _Lock(lock){
    _Lock.lock();
}


authdb::AuthBackendLock::~AuthBackendLock(){
    _Lock.unlock();
}
+1 −1
Changes for src/backend.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ namespace authdb{
        AuthBackendApi           *_Api;
        const std::string            _Options;
        const std::string            _Domain;
        std::mutex                     _Lock;
        std::timed_mutex               _Lock;
        friend class                 AuthBackendLock;
    };

+4 −2
Changes for src/backends/cluster.cpp: 4 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -76,7 +76,8 @@ namespace authdb {
        if (client) {
            try {
                auto &cmtx = g_Cluster->getClientMutex();
                std::lock_guard<std::mutex> lock(cmtx);
                std::unique_lock<std::timed_mutex> lock(cmtx, std::chrono::seconds(5));
                if (!lock.owns_lock()) throw std::runtime_error("cluster client lock timeout");
                client->fetch_from_peers(dgid, 0, peer_data);
            } catch (const netplus::NetException &e) {
                std::cerr << "ClusterBackend::fetchFromCluster: fetch_from_peers failed: "
@@ -146,7 +147,8 @@ namespace authdb {
        if (client) {
            try {
                auto &cmtx = g_Cluster->getClientMutex();
                std::lock_guard<std::mutex> lock(cmtx);
                std::unique_lock<std::timed_mutex> lock(cmtx, std::chrono::seconds(5));
                if (!lock.owns_lock()) throw std::runtime_error("cluster client lock timeout");
                client->replicate_to_peers(dgid, 0, _Buffer.data(), _Buffer.size());
            } catch (const netplus::NetException &e) {
                std::cerr << "Cluster replicate failed: " << e.what() << std::endl;
+2 −2
Changes for src/cluster.h: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ namespace authdb {
        // Accessors for backend use
        paritypp::block_store &getStore() { return *store_; }
        std::unique_ptr<paritypp::client> &getClient() { return pclient_; }
        std::mutex &getClientMutex() { return client_mutex_; }
        std::timed_mutex &getClientMutex() { return client_mutex_; }

        // Push a session to the cluster (after local addSession)
        void pushSession(const SessionData &sess);
@@ -166,7 +166,7 @@ namespace authdb {
        std::unique_ptr<paritypp::server> server_;

        std::unique_ptr<paritypp::client> pclient_;
        std::mutex client_mutex_;
        std::timed_mutex client_mutex_;

        void server_loop();
    };