Commit 62e7e8f8 authored by Marc Vef's avatar Marc Vef
Browse files

Ignore self mode to be able to ignore na+sm during psm2

parent 33c711c1
Loading
Loading
Loading
Loading
+35 −22
Original line number Diff line number Diff line
@@ -216,7 +216,6 @@ void load_hosts() {
    ::mt19937 g(rd()); // seed the random generator
    ::shuffle(host_ids.begin(), host_ids.end(), g); // Shuffle hosts vector
    // lookup addresses and put abstract server addresses into rpc_addresses

    if (gkfs::config::ignore_self) {
        // preconditioner to be able to ignore localhost
        for (const auto& id: host_ids) {
@@ -227,40 +226,54 @@ void load_hosts() {
                break;
            }
        }
        // put into if

        if (local_host_found) {
            assert(hosts.size() > 1);
            addrs.resize(hosts.size() - 1);
            CTX->local_host_id(0);
            LOG(INFO, "Local host will be ignored with host size - 1.");
            if (local_host_id == 0)
                CTX->local_host_id(1);
            else
                CTX->local_host_id(0);
        } else {
            CTX->local_host_id(0);
        }
    }
        LOG(INFO, "Local id set to {} due to ignore self running", CTX->local_host_id());

    for (const auto& id: host_ids) {
        const auto& hostname = hosts.at(id).first;
        for (auto id: host_ids) {
            const auto& uri = hosts.at(id).second;
        auto id_tmp = id;
        if (gkfs::config::ignore_self) {
            if (local_host_found) {
                if (local_host_id == id)
                break;
                    continue;
                if (id > local_host_id)
                id_tmp--;
                    id--;
            }

            addrs[id] = lookup_endpoint(uri);

            LOG(DEBUG, "Found peer: {}", addrs[id].to_string());
        }
    } else {
        for (const auto& id: host_ids) {
            const auto& hostname = hosts.at(id).first;
            const auto& uri = hosts.at(id).second;

            addrs[id] = lookup_endpoint(uri);

            if (!local_host_found && hostname == local_hostname) {
                LOG(DEBUG, "Found local host: {}", hostname);
                CTX->local_host_id(id);
                local_host_found = true;
            }
        }

        addrs[id_tmp] = lookup_endpoint(uri);

        LOG(DEBUG, "Found peer: {}", addrs[id_tmp].to_string());
            LOG(DEBUG, "Found peer: {}", addrs[id].to_string());
        }

        if (!local_host_found) {
            LOG(WARNING, "Failed to find local host. Using host '0' as local host");
            CTX->local_host_id(0);
        }
    }

    CTX->hosts(addrs);
}