Unverified Commit f0761271 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Don't store hosts information on deamons

parent 32207909
Loading
Loading
Loading
Loading
+1 −26
Original line number Diff line number Diff line
@@ -45,11 +45,6 @@ private:
    std::string mountdir_;
    std::string metadir_;

    // hosts_
    std::string hosts_raw_; // raw hosts string, given when daemon is started. Used to give it to fs client
    std::map<uint64_t, std::string> hosts_;
    uint64_t host_id_; // my host number
    size_t host_size_;
    unsigned int rpc_port_;
    std::string rpc_addr_;
    std::string lookup_file_;
@@ -76,10 +71,6 @@ public:

    void operator=(FsData const&) = delete;

    // Utility member functions

    bool is_local_op(size_t recipient);

    // getter/setter

    const std::unordered_map<std::string, std::string>& hashmap() const;
@@ -120,22 +111,6 @@ public:

    void storage(const std::shared_ptr<ChunkStorage>& storage);

    const std::string& hosts_raw() const;

    void hosts_raw(const std::string& hosts_raw);

    const std::map<uint64_t, std::string>& hosts() const;

    void hosts(const std::map<uint64_t, std::string>& hosts);

    const uint64_t& host_id() const;

    void host_id(const uint64_t& host_id);

    size_t host_size() const;

    void host_size(size_t host_size);

    unsigned int rpc_port() const;

    void rpc_port(unsigned int rpc_port);
+0 −3
Original line number Diff line number Diff line
@@ -125,9 +125,6 @@ MERCURY_GEN_PROC(rpc_config_out_t, ((hg_const_string_t) (mountdir))
((hg_bool_t) (blocks_state)) \
((hg_uint32_t) (uid)) \
((hg_uint32_t) (gid)) \
((hg_const_string_t) (hosts_raw)) \
((hg_uint64_t) (host_id)) \
        ((hg_uint64_t) (host_size)) \
        ((hg_uint64_t) (rpc_port)) \
        ((hg_const_string_t) (lookup_file))
)
+0 −36
Original line number Diff line number Diff line
@@ -17,10 +17,6 @@
#include <daemon/backend/metadata/db.hpp>


bool FsData::is_local_op(const size_t recipient) {
    return recipient == host_id_;
}

// getter/setter

const std::unordered_map<std::string, std::string>& FsData::hashmap() const {
@@ -99,38 +95,6 @@ void FsData::metadir(const std::string& metadir) {
    FsData::metadir_ = metadir;
}

const std::string& FsData::hosts_raw() const {
    return hosts_raw_;
}

void FsData::hosts_raw(const std::string& hosts_raw) {
    FsData::hosts_raw_ = hosts_raw;
}

const std::map<uint64_t, std::string>& FsData::hosts() const {
    return hosts_;
}

void FsData::hosts(const std::map<uint64_t, std::string>& hosts) {
    FsData::hosts_ = hosts;
}

const uint64_t& FsData::host_id() const {
    return host_id_;
}

void FsData::host_id(const uint64_t& host_id) {
    FsData::host_id_ = host_id;
}

size_t FsData::host_size() const {
    return host_size_;
}

void FsData::host_size(size_t host_size) {
    FsData::host_size_ = host_size;
}

unsigned int FsData::rpc_port() const {
    return rpc_port_;
}
+0 −3
Original line number Diff line number Diff line
@@ -34,9 +34,6 @@ static hg_return_t rpc_srv_fs_config(hg_handle_t handle) {
    out.blocks_state = static_cast<hg_bool_t>(ADAFS_DATA->blocks_state());
    out.uid = getuid();
    out.gid = getgid();
    out.hosts_raw = static_cast<hg_const_string_t>(ADAFS_DATA->hosts_raw().c_str());
    out.host_id = static_cast<hg_uint64_t>(ADAFS_DATA->host_id());
    out.host_size = static_cast<hg_uint64_t>(ADAFS_DATA->host_size());
    out.rpc_port = ADAFS_DATA->rpc_port();
    out.lookup_file = ADAFS_DATA->lookup_file().c_str();
    ADAFS_DATA->spdlogger()->debug("{}() Sending output configs back to library", __func__);
+0 −67
Original line number Diff line number Diff line
@@ -290,8 +290,6 @@ int main(int argc, const char* argv[]) {
            ("metadir,i", po::value<string>(), "metadata directory, if not set rootdir is used for metadata ")
            ("listen,l", po::value<string>(), "Address or interface to bind the daemon on. Default: local hostname")
            ("port,p", po::value<unsigned int>()->default_value(DEFAULT_RPC_PORT), "Port to bind the server on. Default: 4433")
            ("hostfile", po::value<string>(), "Path to the hosts_file for all fs participants")
            ("hosts,h", po::value<string>(), "Comma separated list of hosts_ for all fs participants")
            ("lookup-file,k", po::value<string>(), "Shared file used by deamons to register their enpoints. (Needs to be on a shared filesystem)")
            ("version,h", "print version and exit");
    po::variables_map vm;
@@ -333,75 +331,10 @@ int main(int argc, const char* argv[]) {
    }
    ADAFS_DATA->rpc_port(vm["port"].as<unsigned int>());

    // parse host parameters
    vector<string> hosts{};
    if (vm.count("hostfile")) {
        auto host_path = vm["hostfile"].as<string>();
        fstream host_file(host_path);
        if (host_file.is_open()) {
            for (string line; getline(host_file, line);) {
                if (line.at(0) != '#') {
                    auto subline = line.substr(0, line.find(' '));
                    hosts.push_back(subline);
                }
            }
        } else {
            cerr << "Hostfile path does not exist. Exiting ..." << endl;
            ADAFS_DATA->spdlogger()->error("{}() Hostfile path does not exist. Exiting ...", __func__);
            assert(host_file.is_open());
        }
    } else if (vm.count("hosts")) {
        // split comma separated host string
        boost::char_separator<char> sep(",");
        boost::tokenizer<boost::char_separator<char>> tok(vm["hosts"].as<string>(), sep);
        for (auto&& s : tok) {
            hosts.push_back(s);
        }
    }
    // convert host parameters into datastructures
    std::map<uint64_t, std::string> hostmap;
    auto hosts_raw = ""s;
    if (!hosts.empty()) {
        auto i = static_cast<uint64_t>(0);
        auto found_hostname = false;
        auto hostname = get_my_hostname(true);
        if (hostname.empty()) {
            cerr << "Unable to read the machine's hostname" << endl;
            ADAFS_DATA->spdlogger()->error("{}() Unable to read the machine's hostname", __func__);
            assert(!hostname.empty());
        }
        for (auto&& host : hosts) {
            hostmap[i] = host;
            hosts_raw += host + ","s;
            if (hostname == host) {
                ADAFS_DATA->host_id(i);
                found_hostname = true;
            }
            i++;
        }
        if (!found_hostname) {
            ADAFS_DATA->spdlogger()->error("{}() Hostname was not found in given parameters. Exiting ...", __func__);
            cerr << "Hostname was not found in given parameters. Exiting ..." << endl;
            assert(found_hostname);
        }
        hosts_raw = hosts_raw.substr(0, hosts_raw.size() - 1);
    } else {
        // single node mode
        ADAFS_DATA->spdlogger()->info("{}() Single node mode set to self", __func__);
        auto hostname = get_my_hostname(false);
        hostmap[0] = hostname;
        hosts_raw = hostname;
        ADAFS_DATA->host_id(0);
    }

    if (vm.count("lookup-file")) {
        ADAFS_DATA->lookup_file(vm["lookup-file"].as<string>());
    }

    ADAFS_DATA->hosts(hostmap);
    ADAFS_DATA->host_size(hostmap.size());
    ADAFS_DATA->hosts_raw(hosts_raw);

    ADAFS_DATA->spdlogger()->info("{}() Initializing environment", __func__);

    assert(vm.count("mountdir"));