Commit b5e7d06e authored by Ramon Nou's avatar Ramon Nou
Browse files

workaround

parent f16cdcd5
Loading
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -140,6 +140,10 @@ MalleableManager::connect_to_hosts(
        const vector<std::pair<std::string, std::string>>& hosts,
        bool is_shrink) {
    auto local_hostname = gkfs::rpc::get_my_hostname(true);
    // Use the daemon's own RPC URI as the primary identifier; it is always
    // unique even when multiple daemons share the same hostname (e.g. single
    // machine deployments without a rootdir_suffix).
    const auto& local_uri = RPC_DATA->self_addr_str();
    bool local_host_found = false;

    RPC_DATA->hosts_size(hosts.size());
@@ -182,9 +186,13 @@ MalleableManager::connect_to_hosts(
            }
        }

        if(!local_host_found && hostname == local_hostname) {
            GKFS_DATA->spdlogger()->debug("{}() Found local host: {}", __func__,
                                          hostname);
        // Prefer URI match: it is unique even when multiple daemons share a
        // hostname (single-machine deployments without --rootdir-suffix).
        // Fall back to hostname match for backward compatibility.
        if(!local_host_found &&
           (!local_uri.empty() ? (uri == local_uri) : (hostname == local_hostname))) {
            GKFS_DATA->spdlogger()->debug("{}() Found local host: {} (uri: {})",
                                          __func__, hostname, uri);
            RPC_DATA->local_host_id(id);
            local_host_found = true;
        }
@@ -194,13 +202,13 @@ MalleableManager::connect_to_hosts(
    if(!local_host_found) {
        if(is_shrink) {
            GKFS_DATA->spdlogger()->info(
                    "{}() Local host '{}' not found in hosts file. This node is being removed.",
                    __func__, local_hostname);
                    "{}() Local host '{}' (uri: '{}') not found in new hosts file. This node is being removed.",
                    __func__, local_hostname, local_uri);
            RPC_DATA->local_host_id(std::numeric_limits<uint64_t>::max());
        } else {
            auto err_msg = fmt::format(
                    "{}() Local host '{}' not found in hosts file. This should not happen.",
                    __func__, local_hostname);
                    "{}() Local host '{}' (uri: '{}') not found in hosts file. This should not happen.",
                    __func__, local_hostname, local_uri);
            throw runtime_error(err_msg);
        }
    }