Commit 9ec4bace authored by Ramon Nou's avatar Ramon Nou
Browse files

fix(client): gate local bypass on daemon capabilities

parent c6b504e9
Loading
Loading
Loading
Loading
Loading
+7
Changes for include/client/preload_context.hpp: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@
#include <vector>
#include <string>
#include <mutex>
#include <shared_mutex>
#include <atomic>
#include <unordered_set>
#include <config.hpp>
@@ -197,6 +198,9 @@ private:
    std::shared_ptr<gkfs::cache::file::WriteSizeCache> write_size_cache_;
    bool use_write_size_cache_{false};
    bool local_bypass_{true};
    // Synchronizes direct I/O with topology reloads. Once a reload starts,
    // bypass stays disabled because fs_conf_ retains the original root.
    std::shared_mutex bypass_topology_mutex_;
    bool has_local_host_{false};
    bool cas_enabled_{false};
    size_t cas_min_size_{16384};
@@ -534,6 +538,9 @@ public:
    void
    local_bypass(bool enable);

    std::shared_mutex&
    bypass_topology_mutex();

    bool
    has_local_host() const;

+2 −1
Changes for src/client/preload.cpp: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -788,7 +788,8 @@ init_preload() {
    // The backend root is not known until lazy environment initialization
    // reads the hostfile. An empty root here does not imply memory storage.
    // load_hostfile() disables bypass for advertised memory backends too.
    if(gkfs::env::get_var_bool(gkfs::env::USE_MEM, false)) {
    if(gkfs::config::limbo_mode ||
       gkfs::env::get_var_bool(gkfs::env::USE_MEM, false)) {
        bypass_enabled = false;
    }
    CTX->local_bypass(bypass_enabled);
+5
Changes for src/client/preload_context.cpp: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -971,6 +971,11 @@ PreloadContext::local_bypass(bool enable) {
    local_bypass_ = enable;
}

std::shared_mutex&
PreloadContext::bypass_topology_mutex() {
    return bypass_topology_mutex_;
}

bool
PreloadContext::has_local_host() const {
    return has_local_host_;
+20
Changes for src/client/preload_util.cpp: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -220,14 +220,27 @@ load_hostfile(const std::string& path) {
            markers, false, false, true);
    bool memory_storage = false;
    bool disk_storage = false;
    bool direct_io_safe = !entries.empty();
    for(const auto& entry : entries) {
        bool memory_entry = false;
        unsigned direct_io_tokens = 0;
        bool direct_io_entry = false;
        for(std::size_t i = 12; i < entry.field_count(); ++i) {
            memory_entry |= entry.field(i) == "storage=memory";
            if(entry.field(i).compare(0, 10, "direct_io=") == 0) {
                ++direct_io_tokens;
                direct_io_entry = entry.field(i) == "direct_io=1";
            }
        }
        direct_io_safe &= direct_io_tokens == 1 && direct_io_entry;
        memory_storage |= memory_entry;
        disk_storage |= !memory_entry;
    }
    if(!direct_io_safe || gkfs::config::limbo_mode) {
        CTX->local_bypass(false);
        LOG(INFO,
            "Local chunk bypass disabled: daemon capability unsafe or unknown");
    }
    if(memory_storage && disk_storage) {
        throw runtime_error("Mixed memory and disk storage is unsupported");
    }
@@ -829,6 +842,13 @@ lookup_proxy_addr() {
 */
void
reload_client_topology() {
    // The original root is not part of the routing snapshot. Drain direct
    // operations and permanently fall back to RPC before any local host ID
    // can change, including on unsuccessful reload attempts.
    std::unique_lock<std::shared_mutex> bypass_lock(
            CTX->bypass_topology_mutex());
    CTX->local_bypass(false);
    LOG(INFO, "Local chunk bypass disabled after topology reload request");
    const auto path = gkfs::env::get_var(gkfs::env::HOSTS_FILE,
                                         gkfs::config::hostfile_path);

+4
Changes for src/client/rpc/forward_data.cpp: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -326,6 +326,8 @@ forward_data_helper(std::string rpc_tag,
pair<int, ssize_t>
forward_write(const string& path, const void* buf, const off64_t offset,
              const size_t write_size, const int8_t num_copies) {
    std::shared_lock<std::shared_mutex> bypass_lock(
            CTX->bypass_topology_mutex());

    if(gkfs::config::proxy::fwd_io && CTX->use_proxy()) {
        LOG(WARNING,
@@ -630,6 +632,8 @@ pair<int, ssize_t>
forward_read(const string& path, void* buf, const off64_t offset,
             const size_t read_size, const int8_t num_copies,
             std::set<gkfs::rpc::host_t>& failed) {
    std::shared_lock<std::shared_mutex> bypass_lock(
            CTX->bypass_topology_mutex());

    if(gkfs::config::proxy::fwd_io && CTX->use_proxy()) {
        LOG(WARNING,
Loading