Commit 3bf5fa3e authored by sevenuz's avatar sevenuz
Browse files

client: store RPC engines and hosts per engine in PreloadContext

rpc_engine_ becomes a vector of engines and hosts_ a vector of endpoint
vectors, one per engine, because an endpoint is only valid for the
engine whose lookup() created it. The existing accessors keep their
signatures and resolve through engine_index(), which is 0 for now, so
all call sites stay unchanged and behaviour is identical.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 0191d10e
Loading
Loading
Loading
Loading
+33 −3
Changes for include/client/preload_context.hpp: 33 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -127,7 +127,9 @@ private:
    std::vector<std::string> mountdir_components_;
    std::string mountdir_;

    std::vector<thallium::endpoint> hosts_;
    // daemon endpoints, one vector per RPC engine (an endpoint is only valid
    // for the engine whose lookup() created it): hosts_[engine][host]
    std::vector<std::vector<thallium::endpoint>> hosts_;
    thallium::endpoint proxy_host_;
    uint64_t local_host_id_;
    uint64_t fwd_host_id_;
@@ -159,8 +161,9 @@ private:
    std::shared_ptr<gkfs::messagepack::ClientMetrics> write_metrics_;
    std::shared_ptr<gkfs::messagepack::ClientMetrics> read_metrics_;

    // Thallium engines
    std::shared_ptr<thallium::engine> rpc_engine_;
    // Thallium engines: rpc_engines_ holds LIBGKFS_RPC_ENGINES engines
    // (default 1), ipc_engine_ is the single proxy engine
    std::vector<std::shared_ptr<thallium::engine>> rpc_engines_;
    std::shared_ptr<thallium::engine> ipc_engine_;


@@ -202,12 +205,23 @@ public:
    const std::string&
    cwd() const;

    /// endpoints of the calling thread's RPC engine (see engine_index())
    const std::vector<thallium::endpoint>&
    hosts() const;

    /// endpoints of RPC engine `engine_idx`
    const std::vector<thallium::endpoint>&
    hosts(std::size_t engine_idx) const;

    /// set the endpoints of RPC engine 0
    void
    hosts(const std::vector<thallium::endpoint>& addrs);

    /// set the endpoints of RPC engine `engine_idx`
    void
    hosts(std::size_t engine_idx, const std::vector<thallium::endpoint>& addrs);

    /// clear the endpoints of all RPC engines
    void
    clear_hosts();

@@ -371,12 +385,28 @@ public:
    const std::shared_ptr<gkfs::messagepack::ClientMetrics>
    read_metrics();

    /// RPC engine of the calling thread (see engine_index())
    std::shared_ptr<thallium::engine>
    rpc_engine();

    /// replace all RPC engines by `engine` (nullptr: drop all engines)
    void
    rpc_engine(std::shared_ptr<thallium::engine> engine);

    /// append one RPC engine to the pool
    void
    add_rpc_engine(std::shared_ptr<thallium::engine> engine);

    const std::vector<std::shared_ptr<thallium::engine>>&
    rpc_engines() const;

    std::size_t
    rpc_engine_count() const;

    /// index of the calling thread's RPC engine in [0, rpc_engine_count())
    std::size_t
    engine_index() const;

    std::shared_ptr<thallium::engine>
    ipc_engine();

+52 −4
Changes for src/client/preload_context.cpp: 52 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -254,16 +254,38 @@ PreloadContext::cwd() const {

const std::vector<thallium::endpoint>&
PreloadContext::hosts() const {
    return hosts_;
    return hosts(engine_index());
}

const std::vector<thallium::endpoint>&
PreloadContext::hosts(std::size_t engine_idx) const {
    static const std::vector<thallium::endpoint> no_hosts{};
    if(engine_idx >= hosts_.size()) {
        return no_hosts;
    }
    return hosts_[engine_idx];
}

void
PreloadContext::hosts(const std::vector<thallium::endpoint>& endpoints) {
    hosts_ = endpoints;
    hosts(0, endpoints);
}

void
PreloadContext::hosts(std::size_t engine_idx,
                      const std::vector<thallium::endpoint>& endpoints) {
    if(hosts_.size() <= engine_idx) {
        hosts_.resize(engine_idx + 1);
    }
    hosts_[engine_idx] = endpoints;
}

void
PreloadContext::clear_hosts() {
    // endpoints must be released before their engines are finalized
    for(auto& h : hosts_) {
        h.clear();
    }
    hosts_.clear();
}

@@ -790,12 +812,38 @@ PreloadContext::read_metrics() {

std::shared_ptr<thallium::engine>
PreloadContext::rpc_engine() {
    return rpc_engine_;
    if(rpc_engines_.empty()) {
        return nullptr;
    }
    return rpc_engines_[engine_index()];
}

void
PreloadContext::rpc_engine(std::shared_ptr<thallium::engine> engine) {
    rpc_engine_ = engine;
    rpc_engines_.clear();
    if(engine) {
        rpc_engines_.push_back(std::move(engine));
    }
}

void
PreloadContext::add_rpc_engine(std::shared_ptr<thallium::engine> engine) {
    rpc_engines_.push_back(std::move(engine));
}

const std::vector<std::shared_ptr<thallium::engine>>&
PreloadContext::rpc_engines() const {
    return rpc_engines_;
}

std::size_t
PreloadContext::rpc_engine_count() const {
    return rpc_engines_.size();
}

std::size_t
PreloadContext::engine_index() const {
    return 0;
}

std::shared_ptr<thallium::engine>